def attack(self): defense_roll = nodes.dice(game.state.home_node.processor + game.player.defense) attack_roll = nodes.dice(self.power) if attack_roll > defense_roll: damage = attack_roll - defense_roll + 1 terminal.add_line("<MAGENTA>COMBAT:<LIGHTGREY> %s attacks you for <LIGHTRED>%i<LIGHTGREY> damage!" % (self.name, damage)) game.player.lose_hp(damage, self.name) else: terminal.add_line("<MAGENTA>COMBAT:<LIGHTGREY> %s misses you!" % (self.name))
def add_npc(self, npc): if npc not in self.npcs: self.npcs.append(npc) log.debug("adding NPC %s to %s", npc.name, self.ip_addr) self.warn_root("'%s' has logged into this node" % npc.name) if self.user and not game.player.engaged: game.player.engaged = True terminal.add_line("A foe has connected to a system you are on!") terminal.add_line("If you don't know what to do, try running '<LIGHTGREEN>help combat<LIGHTGREY>' for advice")
def defeated(self): terminal.add_line("<MAGENTA>COMBAT:<LIGHTGREY> you defeat %s in cybercombat!" % (self.name)) self.state = 'dead' self.go_to(None) self.delay = 10000 if random.randint(0,2) == 0: program = random.choice(['attack', 'defense', 'hacking', 'stealth']) if getattr(game.player, program) < self.power: terminal.add_line("<LIGHTGREEN>PROGRAM:<LIGHTGREY> you salved a <WHITE>Rating %i %s<LIGHTGREY> program off your foe!" % (self.power, program)) setattr(game.player, program, self.power)
def start(*args): log.debug("Starting up") import draw, hud, gameprompt, terminal, nodes, commands, npc fire('setup') fire('clear') while state.running: try: fire('tick') fire('prompt') except GameShutdown: raise except Exception, e: log.exception(e) terminal.add_line('<LIGHTRED>INTERNAL EXCEPTION: %s' % repr(e)) continue
def defend(self,counter=False): attack_roll = nodes.dice(game.state.home_node.processor + game.player.attack) defense_roll = nodes.dice(self.power) if counter: counter = 'counter' else: counter = '' if attack_roll > defense_roll: damage = attack_roll - defense_roll + 1 terminal.add_line("<MAGENTA>COMBAT:<LIGHTGREY> you %sattack %s for <LIGHTRED>%i<LIGHTGREY> damage!" % (counter, self.name, damage)) self.hp -= damage if self.hp <= 0: self.defeated() else: terminal.add_line("<MAGENTA>COMBAT:<LIGHTGREY> you %sattack %s, but miss!" % (counter, self.name))
def purge(self, npc): terminal.add_line("<YELLOW>PURGED<LIGHTGREY> from %s (%s) by %s." % (self.name, self.ip_addr, npc.name)) if self == game.state.home_node: game.player.lose_hp(game.player.hp, npc.name) else: if self not in game.state.tunnels: return idx = game.state.tunnels.index(self) lost = len(game.state.tunnels)- idx game.state.tunnels = game.state.tunnels[:idx] dumpshock = 1 + (lost/2) game.player.lose_hp(dumpshock, npc.name) terminal.add_line("You suffer <LIGHTRED>%s<LIGHTGREY> condition damage from dumpshock." % (dumpshock, )) if idx == 0: game.state.current_node = game.state.home_node else: game.state.current_node = game.state.tunnels[-1]
def scan_files(self): if self.rolled_loot: terminal.add_line("This node has already been scanned for files.") return 0 if self.user != 'root': raise ForbiddenError() self.rolled_loot = True nothing = True time = 0 for i in range(self.storage): time += 15 if random.randint(0,2) == 0: nothing = False program = random.choice(['attack', 'defense', 'hacking', 'stealth']) rating = max(1, random.randint(self.security - 2, self.security)) if getattr(game.player, program) < rating: terminal.add_line("<LIGHTGREEN>PROGRAM:<LIGHTGREY> you found a <WHITE>Rating %i %s<LIGHTGREY> program on the node!" % (rating, program)) setattr(game.player, program, rating) else: terminal.add_line("<LIGHTGREEN>PROGRAM:<LIGHTGREY> you find a Rating %i %s program, but it's of no use to you" % (rating, program)) if nothing: terminal.add_line("You find nothing of interest!") return time
for corp in C.corp_names: corps[corp] = Faction(key=corp, name=corp + " Security", competence=random.uniform(0.5, 1.5), members = random.randint(2, 4)) corps['bbeg'] = Faction(key='bbeg', name="Shadow Team", competence=1.7, members = 4) @game.on('tick') def npc_tick(): for faction in corps.values(): faction.tick() @game.on('time_taken') def npc_time(t): #hardcoding time try: faction = corps['bbeg'] for npc in faction.members: npc.delay -= t while npc.delay < 0: npc.act() faction.spawn_clock -= t if faction.spawn_clock < 0: faction.spawn_clock = 23 * 60 + random.randint(0, 120) faction.competence += random.uniform(0.1, 0.2) faction.spawn_member() except game.GameShutdown, e: raise except Exception, e: terminal.add_line('<LIGHTRED>INTERNAL EXCEPTION (NPC): %s' % repr(e))
def warn_root(self, msg): if self.user == 'root': terminal.add_line('<YELLOW>WARNING:<LIGHTGREY>%s (%s): %s' % (self.name, self.ip_addr, msg))