__init__.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. # Legacy of Insolence version 0.1
  2. # by DrLecter
  3. import sys
  4. from com.l2jserver import Config
  5. from com.l2jserver.gameserver.model.quest import State
  6. from com.l2jserver.gameserver.model.quest import QuestState
  7. from com.l2jserver.gameserver.model.quest import Quest as JQuest
  8. qn = "372_LegacyOfInsolence"
  9. # 1- Variables: Maybe you would like to change something here:
  10. # If a non-zero value is set here, recipes will be 100% instead of 60%
  11. # (default setting matches retail rewards)
  12. ALT_RP_100=0
  13. # Cummulative chances to get: [ "3 recipes", "4000 adena", "2 recipes", max_chance]
  14. # Default is: 1%,2%,2% (read give_reward method downwards if something isn't clear)
  15. # In order to make special rewards harder to get, you could set max_chance to 1000, or slt
  16. REWARD_RATE = [1,3,5,100]
  17. # 2- Quest info: You prolly won't need to change this
  18. QUEST_NUMBER,QUEST_NAME,QUEST_DESCRIPTION = 372, "LegacyOfInsolence", "Legacy of Insolence"
  19. # 3- Quest specific definitions: Don't mess with it unless you know what you're doing
  20. #Quest items: Papyrus
  21. RE_PAP,BL_PAP,BK_PAP,WH_PAP=range(5966,5970)
  22. # Collectibles:
  23. COLLECTION = {
  24. "Rev":range(5972,5979), #Revelations of the Seals
  25. "Anc":range(5979,5984), #Ancient Epics
  26. "Imp":range(5984,5989), #Imperial Genealogy
  27. "ToI":range(5989,6002) #ToI Blueprints
  28. }
  29. #name:[boots,gloves,helm],
  30. REWARD={
  31. "DarkCryst":[5525,5508,5496],
  32. "Tallum": [5526,5509,5497],
  33. "Nightmare":[5527,5514,5502],
  34. "Majestic": [5528,5515,5503],
  35. "Wald_DarkCryst":[5368,5392,5426,5525,5508,5496], # Walderal includes recipes
  36. "Wald_Tallum": [5370,5394,5428,5526,5509,5497], # Walderal includes recipes
  37. "Wald_Nightmare":[5380,5404,5430,5527,5514,5502], # Walderal includes recipes
  38. "Wald_Majestic": [5382,5406,5432,5528,5515,5503], # Walderal includes recipes
  39. }
  40. #Recipes for 100% option
  41. RECIPES=[5368,5392,5426,5370,5394,5428,5380,5404,5430,5382,5406,5432]
  42. #NPCs Area
  43. WALDERAL,DESMOND,CLAUDIA,PATRIN,HOLLY=30844,30855,31001,30929,30839
  44. #Npc: ("Needed Collectibles","Reward recipes")
  45. NPC = {
  46. WALDERAL: ("ToI"), #Well, this guy is special
  47. DESMOND: ("Rev","Majestic"),
  48. CLAUDIA: ("Rev","Nightmare"),
  49. PATRIN: ("Anc","Tallum"),
  50. HOLLY: ("Imp","DarkCryst")
  51. }
  52. #Mobs & Drop
  53. CORRUPT_SAGE,ERIN_EDIUNCE,HALLATE_INSP,PLATINUM_OVL,PLATINUM_PRE,MESSENGER_A1,MESSENGER_A2=20817,20821,20825,20829,21069,21062,21063
  54. # This drop distribution should match retail.
  55. MOB = {
  56. CORRUPT_SAGE:[RE_PAP,35],
  57. ERIN_EDIUNCE:[RE_PAP,40],
  58. HALLATE_INSP:[RE_PAP,45],
  59. PLATINUM_OVL:[BL_PAP,40],
  60. PLATINUM_PRE:[BK_PAP,25],
  61. MESSENGER_A1:[WH_PAP,25],
  62. MESSENGER_A2:[WH_PAP,25]
  63. }
  64. #Helpers
  65. def check_n_take(st,collection) :
  66. result = False
  67. coll2check = COLLECTION[collection]
  68. dec = 2**len(coll2check)
  69. for i in range(len(coll2check)) :
  70. if st.getQuestItemsCount(coll2check[i]) > 0 :
  71. dec = dec >> 1
  72. if dec == 1 :
  73. for k in range(len(coll2check)) :
  74. st.takeItems(coll2check[k], 1)
  75. result = True
  76. return result
  77. def give_reward(st,reward) :
  78. luck = st.getQuest().getRandom(REWARD_RATE[-1])
  79. prize = REWARD[reward]
  80. if ALT_RP_100 != 0 :
  81. for i in range(len(prize)) :
  82. if prize[i] in RECIPES: # dont want to change keys materials, just recipes
  83. prize[i]+=1
  84. if luck < REWARD_RATE[0] : # best reward: all items from collection
  85. for j in prize :
  86. st.giveItems(j,1)
  87. elif luck < REWARD_RATE[1] : # worst reward: 4000a
  88. st.giveItems(57,4000)
  89. elif luck < REWARD_RATE[2] : # quite nice : 2 recipes
  90. for k in range(2) :
  91. l = st.getQuest().getRandom(len(prize))
  92. st.giveItems(prize[l],1)
  93. del prize[l]
  94. else : # ordinary reward: 1 recipe or mat
  95. st.giveItems(prize[st.getQuest().getRandom(len(prize))],1)
  96. class Quest (JQuest) :
  97. def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
  98. def onEvent (self,event,st) :
  99. id = st.getState()
  100. htmltext = event
  101. if event == "30844-6.htm":
  102. st.set("cond","1")
  103. st.setState(State.STARTED)
  104. st.playSound("ItemSound.quest_accept")
  105. elif event == "30844-7.htm" :
  106. st.playSound("ItemSound.quest_finish")
  107. st.exitQuest(1)
  108. elif event == "30844-9.htm" :
  109. st.set("cond","2")
  110. elif len(event) == 5 and int(event) in NPC.keys() :
  111. if event == "30844" :
  112. htmltext = "30844-2.htm"
  113. else :
  114. if check_n_take(st,NPC[int(event)][0]) :
  115. give_reward(st,NPC[int(event)][1])
  116. htmltext = event+"-2.htm"
  117. else :
  118. htmltext = event+"-3.htm"
  119. elif event in REWARD.keys() :
  120. if check_n_take(st,"ToI") :
  121. give_reward(st,event)
  122. htmltext = "30844-11.htm"
  123. else :
  124. htmltext = "30844-12.htm"
  125. return htmltext
  126. def onTalk (self,npc,player):
  127. htmltext = Quest.getNoQuestMsg(player)
  128. st = self.getQuestState(player, True)
  129. if not st : return htmltext
  130. npcId = npc.getId()
  131. id = st.getState()
  132. if npcId != WALDERAL and id != State.STARTED : return htmltext
  133. if id == State.CREATED :
  134. st.set("cond","0")
  135. htmltext = "30844-4.htm"
  136. if player.getLevel() < 59 :
  137. st.exitQuest(1)
  138. htmltext = "30844-5.htm"
  139. elif id == State.STARTED :
  140. htmltext = str(npcId)+"-1.htm"
  141. return htmltext
  142. def onKill(self,npc,player,isPet) :
  143. partyMember = self.getRandomPartyMemberState(player,State.STARTED)
  144. if not partyMember : return
  145. st = partyMember.getQuestState(qn)
  146. npcId = npc.getId()
  147. item,chance=MOB[npcId]
  148. chance*=Config.RATE_QUEST_DROP
  149. chance = int(chance)
  150. numItems,chance = divmod(chance,100)
  151. if self.getRandom(100) < chance :
  152. numItems = numItems + 1
  153. if numItems :
  154. st.giveItems(item,numItems)
  155. st.playSound("ItemSound.quest_itemget")
  156. return
  157. # Quest class and state definition
  158. QUEST = Quest(QUEST_NUMBER, str(QUEST_NUMBER)+"_"+QUEST_NAME, QUEST_DESCRIPTION)
  159. QUEST.addStartNpc(WALDERAL)
  160. for i in NPC.keys() :
  161. QUEST.addTalkId(i)
  162. for i in MOB.keys() :
  163. QUEST.addKillId(i)