Esempio n. 1
0
 def onEvent (self,event,st) :
     htmltext = event
     name = st.getPlayer().getName()
     if event == "Klump_AcceptQuest.htm": # quest accepted
         st.setState(State.STARTED)
         st.playSound("ItemSound.quest_accept")
         st.set("cond","1")
     elif event == "Klump_ExitQuest.htm": # quest finished
         st.playSound("ItemSound.quest_finish")
         st.exitQuest(1)
     elif event == "Klump_QuestInProgress.htm": # does player have 50 gems or not, different progress dialogs
         if st.getQuestItemsCount(RED_GEM) >= 50 :
             htmltext = "Klump_QuestInProgress_Have50Gems.htm" # this dialog allows playing
     elif event == "Klump_PlayBegin.htm":
         if st.getQuestItemsCount(RED_GEM) < 50:    # Not enough gems!!
             return "Klump_NoGems.htm"
         # on play begin remove 50 red gems
         st.takeItems(RED_GEM,50) # take gems ...
         self.games[name] = [0,0,0,0,0]
     elif event == "Klump_PlayField.htm":
         # get vars
         card1,card2,card3,card4,card5 = self.games[name]
         prize = 0
         link1 = link2 = link3 = link4 = link5 = prizestr = ""
         # if all cards are open, game ends and prize is given
         if card1 and card2 and card3 and card4 and card5 : # Game ends
             # make array of card indexes and sort it
             ca = self.games[name]
             ca.sort()
             # now in sorted array all equal elements are near each other, for example [5,5, 3,3, 2] or [5, 4,4, 3,2]
             # this makes much easier conditions checking
             match = []
             for i in range(len(ca)-1) :
                 if ca[i] == ca[i+1] :
                     prize += 1
                     if not ca[i] in match :
                         match.append(ca[i])
             if len(match) == 2 :
                 prize += 3
             # prize = 1 : 1 pair (XX). 4 variants [XX---] [-XX--] [--XX-] [---XX]
             # prize = 2 : 3 cards (XXX). 3 variants [XXX--] [-XXX-] [--XXX]
             # prize = 3 : 4 cards (XXXX). 2 variants [XXXX-] [-XXXX]
             # prize = 4 : 5 cards (XXXXX). 1 variant [XXXXX]
             # prize = 5 : 2 pairs (XXYY). 3 variants [XXYY-] [XX-YY] [-XXYY]
             # prize = 6 : Fullhouse (XXXYY). 2 variants [XXXYY] [YYXXX]
             link1 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_QuestInProgress.htm\">Play again.</a><br>"
             prizestr = REWARDS_TEXT[prize]
         else : # game still in progress, display links
           link1 = "Put the first card face up.<br>"
           link2 = "Put the second card face up.<br>"
           link3 = "Put the third card face up.<br>"
           link4 = "Put the fourth card face up.<br>"
           link5 = "Put the fifth card face up.<br>"
           if card1 == 0: link1 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard1.htm\">Put the first card face up.</a><br>"
           if card2 == 0: link2 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard2.htm\">Put the second card face up.</a><br>"
           if card3 == 0: link3 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard3.htm\">Put the third card face up.</a><br>"
           if card4 == 0: link4 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard4.htm\">Put the fourth card face up.</a><br>"
           if card5 == 0: link5 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard5.htm\">Put the fifth card face up.</a><br>"
         htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/Klump_PlayField.htm")
         htmltext = htmltext.replace("CARD1",CARD_VALUES[card1]).replace("CARD2",CARD_VALUES[card2]).replace("CARD3",CARD_VALUES[card3]).replace("CARD4",CARD_VALUES[card4]).replace("CARD5",CARD_VALUES[card5])
         htmltext = htmltext.replace("LINK1",link1).replace("LINK2",link2).replace("LINK3",link3).replace("LINK4",link4).replace("LINK5",link5).replace("PRIZE",prizestr)
         if prize :
             for item,amt in REWARDS[prize] :
                 st.rewardItems(item,amt)
     elif event.startswith("Klump_openCard") : # 'Open' card
         num = int(event[14])
         self.games[name][num-1] = st.getRandom(14) + 1 # generate index of random card, except index 0, which means 'card is closed'
         htmltext = self.onEvent("Klump_PlayField.htm",st)
     return htmltext
Esempio n. 2
0
 def onEvent(self, event, st):
     htmltext = event
     name = st.getPlayer().getName()
     if event == "Klump_AcceptQuest.htm":  # quest accepted
         st.setState(State.STARTED)
         st.playSound("ItemSound.quest_accept")
         st.set("cond", "1")
     elif event == "Klump_ExitQuest.htm":  # quest finished
         st.playSound("ItemSound.quest_finish")
         st.exitQuest(1)
     elif event == "Klump_QuestInProgress.htm":  # does player have 50 gems or not, different progress dialogs
         if st.getQuestItemsCount(RED_GEM) >= 50:
             htmltext = "Klump_QuestInProgress_Have50Gems.htm"  # this dialog allows playing
     elif event == "Klump_PlayBegin.htm":
         if st.getQuestItemsCount(RED_GEM) < 50:  # Not enough gems!!
             return "Klump_NoGems.htm"
         # on play begin remove 50 red gems
         st.takeItems(RED_GEM, 50)  # take gems ...
         self.games[name] = [0, 0, 0, 0, 0]
     elif event == "Klump_PlayField.htm":
         # get vars
         card1, card2, card3, card4, card5 = self.games[name]
         prize = 0
         link1 = link2 = link3 = link4 = link5 = prizestr = ""
         # if all cards are open, game ends and prize is given
         if card1 and card2 and card3 and card4 and card5:  # Game ends
             # make array of card indexes and sort it
             ca = self.games[name]
             ca.sort()
             # now in sorted array all equal elements are near each other, for example [5,5, 3,3, 2] or [5, 4,4, 3,2]
             # this makes much easier conditions checking
             match = []
             for i in range(len(ca) - 1):
                 if ca[i] == ca[i + 1]:
                     prize += 1
                     if not ca[i] in match:
                         match.append(ca[i])
             if len(match) == 2:
                 prize += 3
             # prize = 1 : 1 pair (XX). 4 variants [XX---] [-XX--] [--XX-] [---XX]
             # prize = 2 : 3 cards (XXX). 3 variants [XXX--] [-XXX-] [--XXX]
             # prize = 3 : 4 cards (XXXX). 2 variants [XXXX-] [-XXXX]
             # prize = 4 : 5 cards (XXXXX). 1 variant [XXXXX]
             # prize = 5 : 2 pairs (XXYY). 3 variants [XXYY-] [XX-YY] [-XXYY]
             # prize = 6 : Fullhouse (XXXYY). 2 variants [XXXYY] [YYXXX]
             link1 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_QuestInProgress.htm\">Play again.</a><br>"
             prizestr = REWARDS_TEXT[prize]
         else:  # game still in progress, display links
             link1 = "Put the first card face up.<br>"
             link2 = "Put the second card face up.<br>"
             link3 = "Put the third card face up.<br>"
             link4 = "Put the fourth card face up.<br>"
             link5 = "Put the fifth card face up.<br>"
             if card1 == 0:
                 link1 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard1.htm\">Put the first card face up.</a><br>"
             if card2 == 0:
                 link2 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard2.htm\">Put the second card face up.</a><br>"
             if card3 == 0:
                 link3 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard3.htm\">Put the third card face up.</a><br>"
             if card4 == 0:
                 link4 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard4.htm\">Put the fourth card face up.</a><br>"
             if card5 == 0:
                 link5 = "<a action=\"bypass -h Quest 662_AGameOfCards Klump_openCard5.htm\">Put the fifth card face up.</a><br>"
         htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" +
                                                  qn +
                                                  "/Klump_PlayField.htm")
         htmltext = htmltext.replace("CARD1", CARD_VALUES[card1]).replace(
             "CARD2", CARD_VALUES[card2]).replace(
                 "CARD3", CARD_VALUES[card3]).replace(
                     "CARD4",
                     CARD_VALUES[card4]).replace("CARD5",
                                                 CARD_VALUES[card5])
         htmltext = htmltext.replace("LINK1", link1).replace(
             "LINK2", link2).replace("LINK3", link3).replace(
                 "LINK4", link4).replace("LINK5",
                                         link5).replace("PRIZE", prizestr)
         if prize:
             for item, amt in REWARDS[prize]:
                 st.rewardItems(item, amt)
     elif event.startswith("Klump_openCard"):  # 'Open' card
         num = int(event[14])
         self.games[name][num - 1] = st.getRandom(
             14
         ) + 1  # generate index of random card, except index 0, which means 'card is closed'
         htmltext = self.onEvent("Klump_PlayField.htm", st)
     return htmltext
Esempio n. 3
0
 def onAdvEvent (self,event,npc,player):
   st = player.getQuestState(qn)
   if not st: return
   htmltext = event
   npcId = str(npc.getNpcId())
   if event == "30182-05.htm" :
       st.playSound("ItemSound.quest_accept")
       st.setState(State.STARTED)
       st.set("cond","1")
   elif event == npcId + "-08.htm" :
       st.playSound("ItemSound.quest_finish")
       st.exitQuest(1)
   elif event == npcId + "-11.htm" :
       if st.getQuestItemsCount(Medal) >= 10 :
           st.takeItems(Medal,10)
           self.generateBoard(player,10)
       else :
           htmltext = npcId + "-12.htm"
   elif event == npcId + "-13.htm" :
       if st.getQuestItemsCount(Medal) >= 100 :
           st.takeItems(Medal,100)
           self.generateBoard(player,100)
       else :
           htmltext = npcId + "-12.htm"
   elif event.startswith("select_1-") : #first pick
       selection = int(event[9])
       self.gameStatus[player.getName()][1].append(selection)
       htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/" + npcId + "-14.htm")
       htmltext = self.fillBoard(player,htmltext)
   elif event.startswith("select_2-") : #pick #2-5
       selection = int(event[9])
       guess = self.gameStatus[player.getName()][1]
       num_guesses = len(guess)
       if selection in guess : #already chose that number!
           htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/" + npcId + "-" + str(14+2*num_guesses) + ".htm")
       else :
           self.gameStatus[player.getName()][1].append(selection)
           num_guesses += 1
           htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/" + npcId + "-" + str(11+2*num_guesses) + ".htm")
       htmltext = self.fillBoard(player,htmltext)
   elif event.startswith("select_3-") : #pick #6
       selection = int(event[9])
       guess = self.gameStatus[player.getName()][1]
       if selection in guess : #already chose that number!
           htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/" + npcId + "-26.htm")
           htmltext = self.fillBoard(player,htmltext)
       else :
           self.gameStatus[player.getName()][1].append(selection)
           wins = self.checkWin(player)
           bet = self.gameStatus[player.getName()][2]
           if wins == 3 :
               item = self.getReward(eval("Rewards_"+str(bet)+"_Win"))
               st.giveItems(item,1)
               htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/" + npcId + "-23.htm")
           elif wins == 0 :
               item = self.getReward(eval("Rewards_"+str(bet)+"_Lose"))
               if item == 2437 : st.giveItems(2463,1)
               st.giveItems(item,1)
               htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/" + npcId + "-25.htm")
           else :
               htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" + qn + "/" + npcId + "-24.htm")
           guess = self.gameStatus[player.getName()][1]
           for i in range(9) :
              num = self.gameStatus[player.getName()][0][i]
              htmltext = htmltext.replace("<?Cell"+str(i+1)+"?>",str(num))
              if num in guess :
                  htmltext = htmltext.replace("<?FontColor"+str(i+1)+"?>","ff0000")
              else :
                  htmltext = htmltext.replace("<?FontColor"+str(i+1)+"?>","ffffff")
   return htmltext
Esempio n. 4
0
 def onAdvEvent(self, event, npc, player):
     st = player.getQuestState(qn)
     if not st: return
     htmltext = event
     npcId = str(npc.getNpcId())
     if event == "30182-05.htm":
         st.playSound("ItemSound.quest_accept")
         st.setState(State.STARTED)
         st.set("cond", "1")
     elif event == npcId + "-08.htm":
         st.playSound("ItemSound.quest_finish")
         st.exitQuest(1)
     elif event == npcId + "-11.htm":
         if st.getQuestItemsCount(Medal) >= 10:
             st.takeItems(Medal, 10)
             self.generateBoard(player, 10)
         else:
             htmltext = npcId + "-12.htm"
     elif event == npcId + "-13.htm":
         if st.getQuestItemsCount(Medal) >= 100:
             st.takeItems(Medal, 100)
             self.generateBoard(player, 100)
         else:
             htmltext = npcId + "-12.htm"
     elif event.startswith("select_1-"):  #first pick
         selection = int(event[9])
         self.gameStatus[player.getName()][1].append(selection)
         htmltext = HtmCache.getInstance().getHtm("data/scripts/quests/" +
                                                  qn + "/" + npcId +
                                                  "-14.htm")
         htmltext = self.fillBoard(player, htmltext)
     elif event.startswith("select_2-"):  #pick #2-5
         selection = int(event[9])
         guess = self.gameStatus[player.getName()][1]
         num_guesses = len(guess)
         if selection in guess:  #already chose that number!
             htmltext = HtmCache.getInstance().getHtm(
                 "data/scripts/quests/" + qn + "/" + npcId + "-" +
                 str(14 + 2 * num_guesses) + ".htm")
         else:
             self.gameStatus[player.getName()][1].append(selection)
             num_guesses += 1
             htmltext = HtmCache.getInstance().getHtm(
                 "data/scripts/quests/" + qn + "/" + npcId + "-" +
                 str(11 + 2 * num_guesses) + ".htm")
         htmltext = self.fillBoard(player, htmltext)
     elif event.startswith("select_3-"):  #pick #6
         selection = int(event[9])
         guess = self.gameStatus[player.getName()][1]
         if selection in guess:  #already chose that number!
             htmltext = HtmCache.getInstance().getHtm(
                 "data/scripts/quests/" + qn + "/" + npcId + "-26.htm")
             htmltext = self.fillBoard(player, htmltext)
         else:
             self.gameStatus[player.getName()][1].append(selection)
             wins = self.checkWin(player)
             bet = self.gameStatus[player.getName()][2]
             if wins == 3:
                 item = self.getReward(eval("Rewards_" + str(bet) + "_Win"))
                 st.giveItems(item, 1)
                 htmltext = HtmCache.getInstance().getHtm(
                     "data/scripts/quests/" + qn + "/" + npcId + "-23.htm")
             elif wins == 0:
                 item = self.getReward(eval("Rewards_" + str(bet) +
                                            "_Lose"))
                 if item == 2437: st.giveItems(2463, 1)
                 st.giveItems(item, 1)
                 htmltext = HtmCache.getInstance().getHtm(
                     "data/scripts/quests/" + qn + "/" + npcId + "-25.htm")
             else:
                 htmltext = HtmCache.getInstance().getHtm(
                     "data/scripts/quests/" + qn + "/" + npcId + "-24.htm")
             guess = self.gameStatus[player.getName()][1]
             for i in range(9):
                 num = self.gameStatus[player.getName()][0][i]
                 htmltext = htmltext.replace("<?Cell" + str(i + 1) + "?>",
                                             str(num))
                 if num in guess:
                     htmltext = htmltext.replace(
                         "<?FontColor" + str(i + 1) + "?>", "ff0000")
                 else:
                     htmltext = htmltext.replace(
                         "<?FontColor" + str(i + 1) + "?>", "ffffff")
     return htmltext