class Guard: def __init__(self): self.combativeness = CombatComponent(health=10.0, power=0.5) self.mouth = DialogueComponent(color=(0xff, 0x99, 0x99)) self.appearance = BodyComponent(path="data/guard.png") self.combativeness.add_attack_hook(self.on_attack) self.combativeness.add_ignore_hook(self.on_ignore) # Whether this guard is hostile yet. self.hostile = False # Greet the player. self.mouth.say('Greetings,\ncitizen.\nAnything\nto report?') def reward(self, player): pass def engage(self, player): self.combativeness.take_turn(player) player.enter_menu() def on_attack(self, player): if not self.hostile: self.mouth.say('Assault!') self.hostile = True else: self.mouth.say('Not on my watch!') def on_ignore(self, player): if not self.hostile: self.mouth.farewell('Have a nice\nday, citizen.') self.combativeness.skip_turn() self.combativeness.surrender() else: self.mouth.say('Trying to run,\nare you?!') def follow(self, player): if self.hostile: self.mouth.say('Get back here!') def suffer(self, player, option): if self.combativeness.handle_option(option, player): # The option was handled by the combat component. return else: if option == 'Advice': # The player has asked about the local news. self.mouth.farewell("I'd watch\nthe shadows\nif I were\nyou.") self.combativeness.skip_turn() self.combativeness.surrender() player.pass_time() elif option == 'Proselytizers': # The player has no money to give. self.mouth.farewell( "We guards\ndon't meddle\nwith the\nchurch.") self.combativeness.skip_turn() self.combativeness.surrender() player.pass_time() def is_dead(self): return self.combativeness.is_done() and \ self.mouth.is_done() def get_options(self, player): if self.combativeness.is_done(): return [] options = ['Advice', 'Proselytizers'] self.combativeness.add_options(options) return options def draw(self, window): self.appearance.draw(window) self.mouth.draw(window) def tick(self): self.mouth.tick()
class Jyesula: def __init__(self): self.combativeness = CombatComponent(health=100, power=1) self.mouth = DialogueComponent(color=(0xff, 0, 0)) self.appearance = BodyComponent(path="data/jyesula.png") self.pacified = False self.combativeness.add_attack_hook(self.on_attack) self.combativeness.add_ignore_hook(self.on_ignore) self.combativeness.add_death_hook(self.on_death) self.mouth.say('Ah. Jauld.') def reward(self, player): pass def engage(self, player): self.combativeness.take_turn(player) player.enter_menu() def follow(self, player): pass def draw(self, window): self.appearance.draw(window) self.mouth.draw(window) def tick(self): self.mouth.tick() def on_attack(self, player): messages = ['Hmm...', 'No, child.', 'Be wise.'] self.mouth.say(messages[random.randint(0, len(messages) - 1)]) def on_ignore(self, player): self.mouth.farewell('Adieu,\ncomrade.') self.combativeness.skip_turn() self.combativeness.surrender() def on_death(self, player): self.mouth.farewell('Killed by...\nyou...') def suffer(self, player, option): if self.combativeness.handle_option(option, player): # The option was handled by the combat component. return elif option == 'Lettre': self.mouth.farewell( 'I have no\ntime to read.\nPlease take\ncare of it.') self.combativeness.skip_turn() self.combativeness.surrender() player.pass_time() elif option == 'Pester': self.mouth.farewell('I must away,\nJauld.') self.combativeness.skip_turn() self.combativeness.surrender() player.pass_time() def is_dead(self): return self.combativeness.is_done() and \ self.mouth.is_done() def get_options(self, player): if self.combativeness.is_done(): return [] options = ['Lettre', 'Pester'] self.combativeness.add_options(options) return options
class Proselytizer(object): def __init__(self): self.combativeness = CombatComponent(health=2.0, power=0.5) self.mouth = DialogueComponent(color=(0x40, 0x40, 0xe0)) self.appearance = BodyComponent(path='data/proselytizer.png') self.combativeness.add_attack_hook(self.on_attack) self.combativeness.add_ignore_hook(self.on_ignore) self.combativeness.add_death_hook(self.on_death) # Greet the player. self.mouth.say('Dost thou\nhave a\ndonation?') def reward(self, player): player.gain_money(random.randint(0, 3)) def engage(self, player): self.combativeness.take_turn(player) player.enter_menu() def follow(self, player): self.mouth.say('A donation!') def draw(self, window): self.appearance.draw(window) self.mouth.draw(window) def tick(self): self.mouth.tick() def on_attack(self, player): self.mouth.say('The gods\ncurse thee!') def on_ignore(self, player): pass def on_death(self, player): self.mouth.farewell('Thou hast\nsinned...') def suffer(self, player, option): if self.combativeness.handle_option(option, player): # The option was handled by the combat component. return elif option == 'Donate': self.mouth.farewell( 'We thank\nyou. May the\ngods be on\nyour side.') player.lose_money(1) self.combativeness.skip_turn() self.combativeness.surrender() player.pass_time() elif option == 'Turn out pockets': # The player has no money to give. self.mouth.farewell('Be blessed,\npoor one.') self.combativeness.skip_turn() self.combativeness.surrender() player.pass_time() def is_dead(self): return self.combativeness.is_done() and \ self.mouth.is_done() def get_options(self, player): if self.combativeness.is_done(): return [] if player.money > 0: options = ['Donate'] else: options = ['Turn out pockets'] self.combativeness.add_options(options) return options
class Rat: def __init__(self): self.combativeness = CombatComponent(health=1.0, power=0.5) self.mouth = DialogueComponent(color=(0x80, 0x80, 0)) self.appearance = BodyComponent(path="data/rat.png") self.pacified = False self.combativeness.add_attack_hook(self.on_attack) self.combativeness.add_ignore_hook(self.on_ignore) self.combativeness.add_death_hook(self.on_death) self.mouth.say('*sniff*!\n *sniff*!') def reward(self, player): pass def engage(self, player): self.combativeness.take_turn(player) player.enter_menu() def follow(self, player): if self.pacified: self.mouth.say('*sniff*...') else: self.mouth.say('*squarrr*!') def draw(self, window): self.appearance.draw(window) self.mouth.draw(window) def tick(self): self.mouth.tick() def on_attack(self, player): self.mouth.say('*squeaky\nsqueak*!') self.pacified = False def on_ignore(self, player): self.mouth.say('*squeeeak*!') def on_death(self, player): self.mouth.farewell('*squoo*...') def suffer(self, player, option): if self.combativeness.handle_option(option, player): # The option was handled by the combat component. return elif option == 'Back away slowly': if self.pacified: self.mouth.farewell('...') self.combativeness.skip_turn() self.combativeness.surrender() else: self.mouth.say('*SQUEEEAK!*') player.pass_time() elif option == 'Bide': self.mouth.say('... *squeak*?') self.pacified = True player.pass_time() def is_dead(self): return self.combativeness.is_done() and \ self.mouth.is_done() def get_options(self, player): if self.combativeness.is_done(): return [] options = ['Back away slowly', 'Bide'] self.combativeness.add_options(options) return options