def act(self, action=None): if self.health <= 0: return self.update() self.classUpdate(self) if action == None: input.inputFromOptions("turn", self.actions).activate() else: action.activate()
def init(self): # THREE STEPS: class, difficulty, mode # initialize player's class (e.g. mage) output.say("What class do you want to play?") class_name = input.inputFromOptions("class", classes.get_classes()) # base stats self.stats = classes.get_stats(class_name) # abilities for level 1 self.abilities = self.abilities + classes.get_abilities(class_name) # abilities for higher levels self.levelBonus.abilities = classes.get_levelBonus(class_name) # extra states (i.e. stealth or mana) self.states = classes.get_states(class_name) # extra inspect (i.e. "Stealthed" or "Mana 100/100") self.classInspect = classes.get_classInspect(class_name) # update at the end of each turn (i.e. set stealth to false or regen mana) self.classUpdate = classes.get_classUpdate(class_name) # update at the end of each turn of combat (i.e. regen mana for mage) self.combatUpdate = classes.get_combatUpdate(class_name) # get difficulty before outputting class info output.proclaim("What difficulty level do you want?") difficulty = input.inputFromOptions( "difficulty", ["easy", "normal", "hard", "expert", "master", "torment"], debug=True) if difficulty == "debug": self.debug() output.bellow("GOD MODE ENABLED.") output.say("What difficulty level do you want?") difficulty = input.inputFromOptions( "difficulty", ["easy", "normal", "hard", "expert", "master", "torment"]) modifier = { "easy": 1.2, "normal": 1.0, "hard": 0.9, "expert": 0.8, "master": 0.7, "torment": 0.6 }[difficulty] self.stats.health.difficultyModifier = modifier self.stats.strength.difficultyModifier = modifier self.stats.armor.difficultyModifier = modifier self.health = self.stats.health.getValue() # output class information output.proclaim(classes.get_classIntro(class_name))
def activate(self): output.proclaim(self.message) output.say("You have " + str(self.player.inventory.gold) + " gold.") while True: choice = input.inputFromOptions( "buy", ["leave", "sell"] + self.wares, self.itemString, self.itemValid, "Please buy an item you can afford.") if choice == "leave": break elif choice == "sell": self.sell() else: # Check whether the player can afford multiple of the item; if they can, offer buying more than one. canAfford = self.player.inventory.gold // choice.buyCost cost = choice.buyCost if canAfford < 2: self.player.inventory.addItem(copy.deepcopy(choice)) output.say("Purchased " + str(choice) + " for " + str(choice.buyCost) + " gold!") else: output.say( "How many do you want to buy? You can afford between 1 and " + str(canAfford) + ".") number = input.getInt("amount", 1, canAfford) numberedCopy = copy.deepcopy(choice) numberedCopy.number = number cost *= number self.player.inventory.addItem(numberedCopy) output.say("Purchased " + str(numberedCopy) + " for " + str(cost) + " gold!") self.player.inventory.removeGold(cost) output.say("Now you have " + str(self.player.inventory.gold) + " gold.")
def activate(self): output.proclaim("-- " + self.name + " --") if self.autoGive: self.given = True if not self.given: output.proclaim(self.openerText) while True: choice = input.inputFromOptions("quest", ["decline", "accept"]) if choice == "accept": self.given = True break elif choice == "decline": output.say("Are you sure you want to decline the quest?") if input.yesNo(): break return player = globals.get_player() if self.completionCheck(player): output.proclaim(self.completeText) output.exclaim("You have completed the quest " + self.name + "!") self.rewards.activate() self.condition = lambda player: False player.completedQuests[self.name] = True else: output.proclaim(self.incompleteText)
def activate(self): choice = input.inputFromOptions( "talk", ["back"] + self.npcs, lambda npc: npc if npc == "back" else str(npc.getName())) if choice == "back": return choice.activate()
def attack(self, target): ability = input.inputFromOptions( "attack", self.abilities, lambda ability: str(ability), lambda ability: ability.available(self), "That ability is not available right now.") output.separate() self.gear.proc(target) ability.activate(self, target) self.combatUpdate(self)
def activate(self): output.proclaim(self.message) if len(self.locations) > 1: choice = input.inputFromOptions("go", ["stay"] + self.locations) if choice != "stay": self.player.changeLocation(choice) else: if input.yesNo(): self.player.changeLocation(self.locations[0])
def activate( self, optionalArgument1=None, optionalArgument2=None ): # optionalArgument1 and optionalArgument2 are so Use can pass as an ability (caster, target) while True: use = input.inputFromOptions( self.name, ["back"] + self.player.inventory.getUsableItems()) if use == "back": break use.activate(self.player)
def activate(self): output.say("Toggle any of the following settings.") while True: option = input.inputFromOptions( "option", ["back"] + list(self.player.settings), lambda setting: setting if setting == "back" else str( setting) + " = " + str(self.player.settings[setting])) if option == "back": break self.player.settings[option] = not self.player.settings[option] output.proclaim( str(option).capitalize() + " toggled to " + str(self.player.settings[option]) + ".")
def activate(self): output.proclaim(self.greeting) if len(self.locations) == 0: return output.say("You have " + str(self.player.inventory.gold) + " gold.") location = input.inputFromOptions( self.name, self.locations, lambda location: self.locationToString(location[0], location[1]), lambda location: self.player.inventory.gold >= location[1], "Please select an option that you can afford.") if location[0].name != self.player.location.name: # If the player chooses to travel to a new location, move them and charge them. self.player.inventory.removeGold(location[1]) self.player.changeLocation(location[0])
def activate(self): output.proclaim(self.name + ":") output.say(self.opener) quests = self.getQuests() if len(quests) == 0: return output.proclaim("Quests:") choice = input.inputFromOptions( "quest", ["back"] + quests, lambda quest: quest if quest == "back" else str(quest.getName())) if choice == "back": return choice.activate()
def addBonus(self): stats = self.player.stats.getStats() output.say("Which stat do you want to boost for " + str(self.duration) + " turns?") while True: stat = input.inputFromOptions( "shrine", stats, lambda stat: stat.name + " by " + output.formatNumber( self.amounts[stats.index(stat)] * stat.difficultyModifier) + ", currently at " + str(stat) + ".") index = stats.index(stat) output.say("Are you sure you want to boost " + stat.name + " by " + output.formatNumber(self.amounts[index] * stat.difficultyModifier) + " for " + str(self.duration) + " turns?") if input.yesNo(): self.player.addEffect(self.buffs[index]( "shrine bonus", self.duration, self.amounts[index] * stat.difficultyModifier)) return
def activate(self): stats = self.player.stats.getStats() output.say("Which stat do you want to boost?") while True: stat = input.inputFromOptions( self.name, stats, lambda stat: stat.name + " by " + str( self.bonuses[stat.name] * stat.difficultyModifier) + ", currently at " + str(stat) + ".") output.say("Are you sure you want to boost " + str(stat.name) + " by " + str(self.bonuses[stat.name] * stat.difficultyModifier) + "?") if input.yesNo(): stat.add(self.bonuses[stat.name]) break if len(self.abilities) > 0 and self.player.level == self.abilities[0][ 2]: # check if level is correct output.exclaim("You learn a new ability: " + str(self.abilities[0][0]).upper() + "!") output.declare(self.abilities[0][1]) # ability description self.player.abilities.append(self.abilities[0][0]) self.abilities.pop(0)
def sell(self): if len(self.player.inventory.items) == 0: output.say("You don't have anything you can sell.") return while True: output.say("What do you want to sell? You have " + str(self.player.inventory.gold) + " gold.") choice = input.inputFromOptions( "sell", ["back"] + self.player.inventory.items, lambda choice: "sell " + str(choice) + " for " + str( choice.sellCost) + " gold" + (" each" if choice.number > 1 else "") if isinstance(choice, item.Item) else str(choice)) if choice == "back": break if choice.number == 1: self.player.inventory.removeItem(choice) self.player.inventory.addGold(choice.sellCost) else: output.say("How many do you want to sell?") number = input.getInt("amount", 1, choice.number) self.player.inventory.removeItem(choice, number) self.player.inventory.addGold(choice.sellCost * number)
def activate(self): if len(self.shops) == 1: self.shops[0].activate() else: input.inputFromOptions("visit", self.shops).activate()
def activate(self): input.inputFromOptions("menu", self.options).activate()