Advertisement
Guest User

Untitled

a guest
Dec 10th, 2023
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. import time
  2. from l2jorion.game.model.quest import State
  3. from l2jorion.game.model.quest import QuestState
  4. from l2jorion.game.model.quest.jython import QuestJython as JQuest
  5.  
  6. # Constants for item IDs
  7. ORB_OF_WATER = 9998
  8. ORB_OF_FIRE = 9999
  9. ORB_OF_WIND = 10000
  10. ORB_OF_EARTH = 10001
  11. STONE_OF_VALOR = 10002
  12.  
  13. # Constants for NPC IDs
  14. QUEST_NPC_ID = 70737
  15. SYLPH_IDS = [57000, 57001, 57002, 57003]
  16.  
  17. # DROPLIST for items
  18. DROPLIST = {
  19. 57000: [ORB_OF_WIND, 100],
  20. 57001: [ORB_OF_EARTH, 100],
  21. 57002: [ORB_OF_FIRE, 100],
  22. 57003: [ORB_OF_WATER, 100],
  23. }
  24.  
  25. class Quest(JQuest):
  26.  
  27. def __init__(self, id, name, descr):
  28. JQuest.__init__(self, id, name, descr)
  29.  
  30. def onEvent(self, event, st):
  31. htmltext = event
  32. if event == "70737-03.htm":
  33. st.set("cond", "1")
  34. st.set("last_completion_time", str(time.time())) # Store completion time
  35. st.setState(STARTED)
  36. st.playSound("ItemSound.quest_accept")
  37. elif event == "70737-06.htm":
  38. st.exitQuest(1)
  39. st.playSound("ItemSound.quest_finish")
  40. return htmltext
  41.  
  42. def onTalk(self, npc, player):
  43. htmltext = "<html><body>You are either not carrying out your quest or don't meet the criteria.</body></html>"
  44.  
  45. st = player.getQuestState(qn)
  46. if not st:
  47. return htmltext
  48.  
  49. npcId = npc.getNpcId()
  50. id = st.getState()
  51.  
  52. if id == CREATED:
  53. st.set("cond", "0")
  54. if st.getInt("cond") == 0:
  55. if player.getLevel() < 76:
  56. htmltext = "70737-01.htm"
  57. st.exitQuest(1)
  58. else:
  59. htmltext = "70737-02.htm"
  60. else:
  61. water = st.getQuestItemsCount(ORB_OF_WATER)
  62. fire = st.getQuestItemsCount(ORB_OF_FIRE)
  63. wind = st.getQuestItemsCount(ORB_OF_WIND)
  64. earth = st.getQuestItemsCount(ORB_OF_EARTH)
  65.  
  66. if water == fire == wind == earth == 0:
  67. htmltext = "70737-04.htm"
  68. if npcId == QUEST_NPC_ID and st.getQuestItemsCount(ORB_OF_WATER) and st.getQuestItemsCount(
  69. ORB_OF_FIRE) and st.getQuestItemsCount(ORB_OF_WIND) and st.getQuestItemsCount(ORB_OF_EARTH):
  70. htmltext = "70737-05.htm"
  71. st.giveItems(STONE_OF_VALOR, 1)
  72. st.takeItems(ORB_OF_WATER, -1)
  73. st.takeItems(ORB_OF_FIRE, -1)
  74. st.takeItems(ORB_OF_WIND, -1)
  75. st.takeItems(ORB_OF_EARTH, -1)
  76. return htmltext
  77.  
  78. def onKill(self, npc, player, isPet):
  79. st = player.getQuestState(qn)
  80. if not st:
  81. return
  82. if st.getState() != STARTED:
  83. return
  84.  
  85. item, chance = DROPLIST[npc.getNpcId()]
  86. if st.getRandom(100) > 1:
  87. st.giveItems(item, 1)
  88. st.playSound("ItemSound.quest_itemget")
  89. return
  90.  
  91. # Check if the quest can be repeated
  92. if not self.can_repeat(st):
  93. remaining_time = self.get_time_remaining(st)
  94. if remaining_time:
  95. htmltext = f"<html><body>You can repeat this quest after {remaining_time} passed!</body></html>"
  96. return htmltext
  97.  
  98. return htmltext
  99.  
  100. def can_repeat(self, st):
  101. last_completion_time_str = st.get("last_completion_time")
  102. if last_completion_time_str:
  103. last_completion_time = float(last_completion_time_str)
  104. current_time = time.time()
  105. cooldown_duration = 24 * 60 * 60 # 24 hours in seconds
  106. return current_time - last_completion_time >= cooldown_duration
  107. return True
  108.  
  109.  
  110. # Constants for quest states
  111. QUEST_STATE_START = State('Start', QUEST)
  112. QUEST_STATE_STARTING = State('Starting', QUEST)
  113. QUEST_STATE_STARTED = State('Started', QUEST)
  114. QUEST_STATE_COMPLETED = State('Completed', QUEST)
  115.  
  116. # Set initial state for the quest
  117. QUEST.setInitialState(QUEST_STATE_START)
  118.  
  119. # Add NPCs and IDs to the quest
  120. QUEST.addStartNpc(QUEST_NPC_ID)
  121. QUEST.addTalkId(QUEST_NPC_ID)
  122. QUEST.addKillId(*SYLPH_IDS)
  123.  
  124. # Add drops for quest items
  125. QUEST_STATE_STARTED.addQuestDrop(57002, ORB_OF_FIRE, 1)
  126. QUEST_STATE_STARTED.addQuestDrop(57003, ORB_OF_WATER, 1)
  127. QUEST_STATE_STARTED.addQuestDrop(57000, ORB_OF_WIND, 1)
  128. QUEST_STATE_STARTED.addQuestDrop(57001, ORB_OF_EARTH, 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement