Mercurial > sypikslang
view gamelib/mission.py @ 11:7fc7396aeccb
Fill in license
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Sun, 06 May 2012 14:50:23 +0200 |
parents | 9f8def7d70d0 |
children | c0966997e0c5 |
line wrap: on
line source
# -*- coding: utf-8 -*- # vim:fileencoding=utf-8 ai ts=4 sts=4 et sw=4 from product import DoomsdayVirus, MachineGun, TeslaGun class Mission(object): """Base class for the mission objects. Missions have a name, short description (for list displays) and long description (which may contain clues about approaches)""" NAME = "Generic Mission" SHORT_DESCRIPTION = None LONG_DESCRIPTION = None available = True def attempt(self, equipment, state): """Attempt the mission with the given equipment list. Returns a tuple (success, message). Updates the game state with the results of the mission.""" return False, "You can't succceed at this mission" class RansomChina(Mission): NAME = "Hold China to ransom" SHORT_DESCRIPTION = "Surely a path to riches and fame" LONG_DESCRIPTION = "Holding China to ransom. The rewards for" \ " successfully threatening the largest country in the world" \ " are great, but the risks are significant. Without " \ "some serious firepower, the chances of success are small." def __init__(self): # Track prior approaches to this mission self._prior_attempts = [] def attempt(self, equipment, state): failures = [] for item in equipment: if isinstance(item, DoomsdayVirus) and \ item not in self._prior_attempts: self._prior_attempts.add(item) state.money += 1000000 state.reputation += 1 return True, "Trembling at the threat of your " \ " doomsday virus, the chinese government pays the ransom" elif isinstance(item, DoomsdayVirus): state.reputation -= 1 failures.append("'Hah, we've developed an antidote to your" " virus, doctor'. You cannot threaten us with that" " again'") else: failures.append("You fail to inspire fear with your %s" % item.name) return False, "\n".join(failures) class RobBank(Mission): NAME = "Rob the local bank" SHORT_DESCRIPTION = "A trivial challenge, but easy money" LONG_DESCRIPTION = "The security guards and local police are of minor" \ " concern. Walk in, clean out the vault, walk out. Couldn't be" \ " simpler." def attempt(self, equipment, state): failures = [] for item in equipment: if isinstance(item, DoomsdayVirus): if state.reputation < 10: failures.append("The clerk doesn't realise the threat of" " the vial you hold, and, although watching him" " die in agony would be statisfying, you decide" " it's not worth wasting this on something so" " trivial") else: state.money + 1000 return True, "Holding up a bank with only a small vial" \ " of clear liquid. Now that is power." elif isinstance(item, MachineGun) or isinstance(item, TeslaGun): state.money += 1000 return True, "The threat of your weapons is enough to" \ " inspire an impressive level of cooperation" else: failures.append("You fail to inspire fear with your %s" % item.name) return False, 0, "\n".join(failures) class DestroyMountRushmore(Mission): NAME = "Destroy Mount Rushmore" SHORT_DESCRIPTION = "Monuments to other people? Intolerable" LONG_DESCRIPTION = "While potentially expensive, destroying" \ " major monument is a good way to secure your reputation." def attempt(self, equipment, state): if not self.available: return True, "You send a team to kick over the rubble." self.available = False state.reputation += 100 return True, "Mount Rushmore is remarkably easy to destroy."