__init__.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. # Stolen Dignity 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. #Quest info
  9. QUEST_NUMBER,QUEST_NAME,QUEST_DESCRIPTION = 386,"StolenDignity","Stolen Dignity"
  10. qn = "386_StolenDignity"
  11. #Variables
  12. DROP_RATE=15*Config.RATE_QUEST_DROP
  13. REQUIRED_ORE=100 #how many items will be paid for a game (affects onkill sounds too)
  14. #Quest items
  15. SI_ORE = 6363
  16. #Rewards
  17. REWARDS=[5529]+range(5532,5540)+range(5541,5549)+[8331]+range(8341,8343)+[8346]+[8349]+range(8712,8723)
  18. #Messages
  19. error_1 = "Low_level.htm"
  20. start = "Start.htm"
  21. starting = "Starting.htm"
  22. starting2 = "Starting2.htm"
  23. binfo1 = "Bingo_howto.htm"
  24. bingo = "Bingo_start.htm"
  25. bingo0 = "Bingo_starting.htm"
  26. ext_msg = "Quest aborted"
  27. #NPCs
  28. WK_ROMP = 30843
  29. #Mobs
  30. MOBS = [ 20670,20671,20954,20956,20958,20959,20960,20964,20969,20967,20970,20971,20974,20975,21001,21003,21005,21020,21021,21089,21108,21110,21113,21114,21116 ]
  31. MOB={
  32. 20670:14,
  33. 20671:14,
  34. 20954:11,
  35. 20956:13,
  36. 20958:13,
  37. 20959:13,
  38. 20960:11,
  39. 20964:13,
  40. 20969:19,
  41. 20967:18,
  42. 20970:18,
  43. 20971:18,
  44. 20974:28,
  45. 20975:28,
  46. 21001:14,
  47. 21003:18,
  48. 21005:14,
  49. 21020:16,
  50. 21021:15,
  51. 21089:13,
  52. 21108:19,
  53. 21110:18,
  54. 21113:25,
  55. 21114:23,
  56. 21116:25
  57. }
  58. MAX = 100
  59. #templates
  60. number = ["second","third","fourth","fifth","sixth"]
  61. header = "<html><body>Warehouse Freightman Romp:<br><br>"
  62. link = "<a action=\"bypass -h Quest 386_StolenDignity "
  63. middle = "<br><br>Your selection thus far: <br><br><table border=1 width=120 hieght=64>"
  64. footer = "</table></body></html>"
  65. loser = "Wow! How unlucky can you get? Your choices are highlighted in red below. As you can see, your choices didn't make a single line! Losing this badly is actually quite rare!<br><br>You look so sad, I feel bad for you... Wait here...<br><br>.<br><br>.<br><br>.<br><br>Take this... I hope it will bring you better luck in the future.<br><br>"
  66. winner = "Excellent! As you can see, you've formed three lines! Congratulations! As promised, I'll give you some unclaimed merchandise from the warehouse. Wait here...<br><br>.<br><br>.<br><br>.<br><br>Whew, it's dusty! OK, here you go. Do you like it?<br><br>"
  67. average = "Hum. Well, your choices are highlighted in red below. As you can see your choices didn't formed three lines... but you were near, so don't be sad. You can always get another few infernium ores and try again. Better luck in the future!<br><br>"
  68. def partial(st) :
  69. html = " number:<br><br>"
  70. for z in range(1,10) :
  71. html += link+str(z)+"\">"+str(z)+"</a>&nbsp;&nbsp;&nbsp;&nbsp;"
  72. html += middle
  73. chosen = st.get("chosen").split()
  74. for y in range(0,7,3) :
  75. html +="<tr>"
  76. for x in range(3) :
  77. html+="<td align=center>"+chosen[x+y]+"</td>"
  78. html +="</tr>"
  79. html += footer
  80. return html
  81. def result(st) :
  82. chosen = st.get("chosen").split()
  83. grid = st.get("grid").split()
  84. html = "<table border=1 width=120 height=64>"
  85. for y in range(0,7,3) :
  86. html +="<tr>"
  87. for x in range(3) :
  88. html+="<td align=center>"
  89. if grid[x+y] == chosen[x+y] :
  90. html+="<font color=\"FF0000\"> "+grid[x+y]+" </font>"
  91. else :
  92. html+=grid[x+y]
  93. html+="</td>"
  94. html +="</tr>"
  95. html += footer
  96. return html
  97. class Quest (JQuest) :
  98. def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
  99. def onEvent (self,event,st) :
  100. htmltext = event
  101. if event == "yes" :
  102. htmltext = starting
  103. st.setState(State.STARTED)
  104. st.set("cond","1")
  105. st.playSound("ItemSound.quest_accept")
  106. elif event == "binfo" :
  107. htmltext = binfo1
  108. elif event == "0" :
  109. htmltext = ext_msg
  110. st.exitQuest(1)
  111. elif event == "bingo" :
  112. if st.getQuestItemsCount(SI_ORE) >= REQUIRED_ORE :
  113. st.takeItems(SI_ORE,REQUIRED_ORE)
  114. htmltext = bingo0
  115. grid = range(1,10) #random.sample(xrange(1,10),9) ... damn jython that makes me think that inefficient stuff
  116. for i in range(len(grid)-1, 0, -1) :
  117. j = self.getRandom(8)
  118. grid[i], grid[j] = grid[j], grid[i]
  119. for i in range(len(grid)): grid[i]=str(grid[i])
  120. st.set("chosen","? ? ? ? ? ? ? ? ?")
  121. st.set("grid"," ".join(grid))
  122. st.set("playing","1")
  123. else :
  124. htmltext = "You don't have required items"
  125. else :
  126. for i in range(1,10) :
  127. if event == str(i) :
  128. if st.getInt("playing"):
  129. chosen = st.get("chosen").split()
  130. grid = st.get("grid").split()
  131. if chosen.count("?") >= 3 :
  132. chosen[grid.index(str(i))]=str(i)
  133. st.set("chosen"," ".join(chosen))
  134. if chosen.count("?")==3 :
  135. htmltext = header
  136. row = col = diag = 0
  137. for i in range(3) :
  138. if ''.join(chosen[3*i:3*i+3]).isdigit() : row += 1
  139. if ''.join(chosen[i:9:3]).isdigit() : col += 1
  140. if ''.join(chosen[0:9:4]).isdigit() : diag += 1
  141. if ''.join(chosen[2:7:2]).isdigit() : diag += 1
  142. if (col + row + diag) == 3 :
  143. htmltext += winner
  144. st.giveItems(REWARDS[self.getRandom(len(REWARDS))],4)
  145. st.playSound("ItemSound.quest_finish")
  146. elif (diag + row + col) == 0 :
  147. htmltext += loser
  148. st.giveItems(REWARDS[self.getRandom(len(REWARDS))],10)
  149. st.playSound("ItemSound.quest_jackpot")
  150. else :
  151. htmltext += average
  152. st.playSound("ItemSound.quest_giveup")
  153. htmltext += result(st)
  154. for var in ["chosen","grid","playing"]:
  155. st.unset(var)
  156. else :
  157. htmltext = header+"Select your "+number[8-chosen.count("?")]+partial(st)
  158. else:
  159. htmltext = Quest.getNoQuestMsg(player)
  160. return htmltext
  161. def onTalk (self,npc,player):
  162. htmltext = Quest.getNoQuestMsg(player)
  163. st = self.getQuestState(player, True)
  164. if not st : return htmltext
  165. npcId = npc.getId()
  166. id = st.getState()
  167. if id == State.CREATED :
  168. st.set("cond","0")
  169. if player.getLevel() < 58 :
  170. st.exitQuest(1)
  171. htmltext = error_1
  172. else :
  173. htmltext = start
  174. elif id == State.STARTED :
  175. if st.getQuestItemsCount(SI_ORE) >= REQUIRED_ORE :
  176. htmltext = bingo
  177. else :
  178. htmltext = starting2
  179. return htmltext
  180. def onKill(self,npc,player,isPet):
  181. partyMember = self.getRandomPartyMemberState(player, State.STARTED)
  182. if not partyMember : return
  183. st = partyMember.getQuestState(qn)
  184. numItems,chance = divmod(MOB[npc.getId()]*Config.RATE_QUEST_DROP,MAX)
  185. prevItems = st.getQuestItemsCount(SI_ORE)
  186. if self.getRandom(MAX) < chance :
  187. numItems = numItems + 1
  188. if numItems != 0 :
  189. st.giveItems(SI_ORE,int(numItems))
  190. if int(prevItems+numItems)/REQUIRED_ORE > int(prevItems)/REQUIRED_ORE :
  191. st.playSound("ItemSound.quest_middle")
  192. else :
  193. st.playSound("ItemSound.quest_itemget")
  194. return
  195. # Quest class and state definition
  196. QUEST = Quest(QUEST_NUMBER, str(QUEST_NUMBER)+"_"+QUEST_NAME, QUEST_DESCRIPTION)
  197. # Quest NPC starter initialization
  198. QUEST.addStartNpc(WK_ROMP)
  199. # Quest initialization
  200. QUEST.addTalkId(WK_ROMP)
  201. for i in MOBS :
  202. QUEST.addKillId(i)