Mercurial > sypikslang
diff gamelib/missions.py @ 138:14917385a0fd
Better handling of mission results and turn-end messages.
author | Jeremy Thurgood <firxen@gmail.com> |
---|---|
date | Thu, 10 May 2012 22:33:26 +0200 |
parents | fb8037bc22f1 |
children | f1efd252e8b0 |
line wrap: on
line diff
--- a/gamelib/missions.py Thu May 10 20:56:40 2012 +0200 +++ b/gamelib/missions.py Thu May 10 22:33:26 2012 +0200 @@ -3,7 +3,7 @@ from random import randint -from gamelib.constants import SUCCESS, FAILURE, GAME_WIN, NEW_MILESTONE, M_VALS +from gamelib.constants import SUCCESS, FAILURE, GAME_WIN, M_VALS from gamelib.schematics import cat @@ -13,17 +13,30 @@ This is an exception so we can throw it from inside helper methods. """ - def __init__(self, outcome, msg, money=0, rep=0): + def __init__(self, outcome, msg, money=0, rep=0, **special): self.outcome = outcome self.money = money self.reputation = rep self.text = msg + self.special = special self.applied = False + @property + def loot(self): + loot = {} + if self.money != 0: + loot['money'] = self.money + if self.reputation != 0: + loot['rep'] = self.reputation + loot.update(self.special) + loot.pop('new_milestone', None) # This one's special. + return loot + def apply(self, state): if not self.applied: state.money += self.money state.reputation += self.reputation + state.apply_mission_special(self.special) self.applied = True else: raise RuntimeError('attempted to apply result twice') @@ -92,15 +105,15 @@ return False return True - def fail(self, msg=None, money=0, rep=0): + def fail(self, msg=None, money=0, rep=0, **special): if msg is None: msg = self.GENERIC_FAILURE - raise Result(FAILURE, msg, money=money, rep=rep) + raise Result(FAILURE, msg, money=money, rep=rep, **special) - def succeed(self, msg=None, money=0, rep=0): + def succeed(self, msg=None, money=0, rep=0, **special): if msg is None: msg = self.GENERIC_SUCCESS - raise Result(SUCCESS, msg, money=money, rep=rep) + raise Result(SUCCESS, msg, money=money, rep=rep, **special) def categorise_equipment(self, equipment): # Categorise equipment for easier decision-making. @@ -385,11 +398,12 @@ def attempt_with(self, categorised, state): if all(c in categorised for c in (cat.MIND_CONTROL, cat.HAND_WEAPON)): self.data['completed'] = True - raise Result(NEW_MILESTONE, "Guns and persuasion, that's" - " all you need. It's early days still, but you're" - " finally out of that pokey basement and have some" - " elbow room to work with. Next step: the city!", - money=randint(1000, 2000), rep=randint(5, 15)) + self.succeed( + "Guns and persuasion, that's all you need. It's early days" + " still, but you're finally out of that pokey basement and" + " have some elbow room to work with. Next step: the city!", + money=randint(1000, 2000), rep=randint(5, 15), + new_milestone="neighbourhood") if cat.HAND_WEAPON in categorised: self.succeed(