Example #1
0
 def interact(self, interactor):
     for trigger in self.triggers:
         if trigger.getType() == "Action":
             if trigger.getArea().collidepoint(interactor.getCenter()):
                 if trigger.getEffect() == "Area Change":
                     self.loadNewAreaFunc(trigger.getNewAreaXML(), trigger.getNewArea())
                     self.player.setPos(trigger.getPlayerPos())
                 elif trigger.getEffect() == "Battle":
                     if not trigger.trigger():
                         self.battle(trigger.getEnemies(), trigger.getBG(), trigger.getBGFar(), trigger.getRandom())
                 elif trigger.getEffect() == "Item":
                     if not trigger.trigger():
                         item = ItemFactory.createItem(*trigger.getItem())
                         self.player.getParent().getInventory().addItem(item)
                 elif trigger.getEffect() == "Quest Complete":
                     if not trigger.trigger():
                         self.questAction(
                             ["Complete", trigger.getQuestXML(), trigger.getQuest(), trigger.getObjective()]
                         )
                 else:
                     trigger.trigger(interactor, self.actors)
     if interactor.getID() == "Player":
         for NPC in self.NPCs:
             if NPC.getGameObject().getDistance(interactor) < 20 and NPC.getDialog() != None:
                 interactor.setTalking(NPC)
                 NPC.setTalking(True)
                 NPC.getGameObject().setMoving(False)
                 NPC.setState("Idle")
                 interactor.graphicObject.setState("Idle")
                 NPC.lookAt(interactor)
         for actor in self.actors:
             if actor.isPushable():
                 if interactor.getPushing() != None:
                     if interactor.getPushing() == actor:
                         interactor.getPushing().togglePushed()
                         interactor.setPushing(None)
                 else:
                     dx = actor.getMask().overlap_area(
                         interactor.getMask(),
                         (interactor.getX() - actor.getX() + 1, interactor.getY() - actor.getY()),
                     ) - actor.getMask().overlap_area(
                         interactor.getMask(),
                         (interactor.getX() - actor.getX() - 1, interactor.getY() - actor.getY()),
                     )
                     dy = actor.getMask().overlap_area(
                         interactor.getMask(),
                         (interactor.getX() - actor.getX(), interactor.getY() - actor.getY() + 1),
                     ) - actor.getMask().overlap_area(
                         interactor.getMask(),
                         (interactor.getX() - actor.getX(), interactor.getY() - actor.getY() - 1),
                     )
                     if dx != 0:
                         actor.togglePushed()
                         interactor.setPushing(actor)
                         interactor.setPushDir([True, False])
                     elif dy != 0:
                         actor.togglePushed()
                         interactor.setPushing(actor)
                         interactor.setPushDir([False, True])
Example #2
0
    def update(self, tick):
        if len(self.enemies) > 0 and config.Difficulty > 0:
            if self.timeToBattle >= 0:
                if self.player.getMoving():
                    self.timeToBattle -= tick
            else:
                bg = random.choice(self.battleBG)
                self.battle(self.enemies, bg[0], bg[1], True)
                if config.Difficulty == 1:
                    self.timeToBattle = 5 * random.random() + 10
                elif config.Difficulty == 5:
                    self.timeToBattle = 5 * random.random() + 5
                else:
                    self.timeToBattle = 5 * random.random() + 7.5

        self.player.update(tick, self.moveCheck)
        for actor in self.actors:
            actor.update(tick, self.moveCheck)
        for NPC in self.NPCs:
            NPC.update(tick, self.moveCheck)
        for trigger in self.triggers:
            if trigger.getType() == "Position":
                if trigger.getArea().collidepoint(self.player.getCenter()):
                    if trigger.getEffect() == "Area Change":
                        self.loadNewAreaFunc(trigger.getNewAreaXML(), trigger.getNewArea())
                        self.player.setPos(trigger.getPlayerPos())
                    elif trigger.getEffect() == "Battle":
                        if not trigger.trigger():
                            self.battle(trigger.getEnemies(), trigger.getBG(), trigger.getBGFar(), trigger.getRandom())
                    elif trigger.getEffect() == "Item":
                        if not trigger.trigger():
                            item = ItemFactory.createItem(*trigger.getItem())
                            self.player.getParent().getInventory().addItem(item)
                    elif trigger.getEffect() == "Quest Complete":
                        if not trigger.trigger():
                            self.questAction(
                                ["Complete", trigger.getQuestXML(), trigger.getQuest(), trigger.getObjective()]
                            )
                    else:
                        trigger.trigger(self.player, self.actors)
            elif trigger.getType() == "Object Position":
                for actor in self.actors:
                    if actor.isPushable():
                        if trigger.getArea().collidepoint(actor.getCenter()):
                            trigger.trigger(actor, self.actors)
                            actor.pushable = False
                            actor.togglePushed()
                            self.player.setPushing(None)
            if trigger.getEffect() == "SBSC":
                Pass = True
                for actor in self.actors:
                    if trigger.getNeededStates().__contains__(actor.getID()):
                        if actor.state != trigger.getState():
                            Pass = False
                if Pass:
                    trigger.trigger(self.player, self.actors)
            elif trigger.getEffect() == "TBSC":
                trigger.update(tick, self.actors)
Example #3
0
 def branchCheck(self, branch):
     if branch[0] == "QuestStart":
         return branch[1] + ":" + branch[2] in self.player.getParent().getQuests()
     elif branch[0] == "NotQuestStart":
         return branch[1] + ":" + branch[2] not in self.player.getParent().getQuests()
     elif branch[0] == "QuestObjComplete":
         if branch[1] + ":" + branch[2] in self.player.getParent().getQuests():
             return self.player.getParent().getQuests()[branch[1] + ":" + branch[2]].getObjectiveCompleted(branch[3])
         return False
     elif branch[0] == "Item":
         if self.player.getParent().getInventory().hasItem(ItemFactory.createItem(*branch[2:])) == None:
             return False
         else:
             if self.player.getParent().getInventory().hasItem(
                 ItemFactory.createItem(*branch[2:])
             ).getAmount() >= int(branch[1]):
                 return True
             else:
                 return False
     else:
         errors.warning("Unknown Branch: " + branch[0])
Example #4
0
 def trigger(self, Id):
     for trigger in self.triggers:
         if trigger.getID() == Id:
             if trigger.getEffect() == "Area Change":
                 self.loadNewAreaFunc(trigger.getNewAreaXML(), trigger.getNewArea())
                 self.player.setPos(trigger.getPlayerPos())
             elif trigger.getEffect() == "Battle":
                 if not trigger.trigger():
                     self.battle(trigger.getEnemies(), trigger.getBG(), trigger.getBGFar(), trigger.getRandom())
             elif trigger.getEffect() == "Item":
                 if not trigger.trigger():
                     item = ItemFactory.createItem(*trigger.getItem())
                     self.player.getParent().getInventory().addItem(item)
             elif trigger.getEffect() == "Quest Complete":
                 if not trigger.trigger():
                     self.questAction(
                         ["Complete", trigger.getQuestXML(), trigger.getQuest(), trigger.getObjective()]
                     )
             else:
                 trigger.trigger(self.player, self.actors)
Example #5
0
 def questAction(self, action):
     if action[0] == "Add":
         if action[1] + ":" + action[2] not in self.player.getParent().getQuests():
             quest = loadQuest(config.AssetPath + action[1], action[2])
             self.player.getParent().getQuests()[action[1] + ":" + action[2]] = quest
     elif action[0] == "Complete":
         if action[1] + ":" + action[2] in self.player.getParent().getQuests():
             quest = self.player.getParent().getQuests()[action[1] + ":" + action[2]]
             quest.completeObjective(action[3])
             if quest.getCompleted():
                 for reward in quest.getRewards():
                     key, val = reward.split(" ", 1)
                     if key == "Gold":
                         self.player.getParent().getInventory().addGold(int(val))
                     elif key == "Exp":
                         self.player.getParent().getBattleObject().addExp(int(val))
                     elif key == "Item":
                         item = ItemFactory.createItem(val.split(" "))
                         self.player.getParent().getInventory().addItem(item)
     else:
         errors.warning("Unknown Quest Action: " + action[0])
 def update_quality(self):
     for i, item in enumerate(self.items):
         item = ItemFactory.create_item(item)
         item.update()
         self.items[i] = item