def retreat(self, coward): w = World() for co in coward.combats: w.combats.remove(co) co.combatant1.combats.remove(co) co.combatant2.combats.remove(co) if co.combatant1.engaged == co: if co.combatant1.combats and co.combatant1 != coward: co.combatant1.engaged = co.combatant1.combats[0] co.combatant1.engaged.in_range_set_action(co.combatant1) else: co.combatant1.engaged = None if co.combatant2.engaged == co: if co.combatant2.combats and co.combatant2 != coward: co.combatant2.engaged = co.combatant2.combats[0] co.combatant2.engaged.in_range_set_action(co.combatant2) else: co.combatant2.engaged = None choices = [] choices.extend(libsigma.open_exits(coward.location)) selection = random.choice(choices) libsigma.report(libsigma.SELF | libsigma.ROOM, "$actor $verb to turn tail and run away!", coward, ("manage", "manages")) libsigma.run_command(coward, "go " + libsigma.dir2txt(selection))
def handle_death(self): w = World() del w.denizens[self.id] libsigma.report(libsigma.ROOM, self.epitaph, self) #corpse=pickle.loads(items_source[CORPSE_REFERENCE]) #self.location.contents.append(corpse) #libsigma.transfer_money(self.money,self,corpse) self.location.characters.remove(self)
def cast(self,speaker,target): target= speaker if not target else target intel=speaker.effective_stat("intelligence",self.applicable_bonuses()) disc=int(speaker.effective_stat("discipline",self.applicable_bonuses()) * .75) value=int(min((5+disc) + random.randint(0,intel),45)) target.HP+=value libsigma.report(libsigma.SELF | libsigma.ROOM, "A faint aura washes over $actor!",target) target.send_line("You have gained " + str(value) +" HP!") pass
def engage_combatants(self): self.combatants[0].engaged=self libsigma.report(libsigma.SELF|libsigma.ROOM, "$actor $verb advancing toward $direct!",self.combatants[0],("are","is"),self.combatants[1]) self.send_combat_statuses() if not self.combatants[1].engaged: libsigma.report(libsigma.SELF|libsigma.ROOM, "$actor $verb for the attack!",self.combatants[0],("ready","readies")) self.send_combat_statuses() self.combatants[1].engaged = self
def handle_close(self): # Shunt output to parent (avoids recursion in simultaneous logouts) self.parent.send = lambda s: None if self.parent.location: libsigma.report(libsigma.ROOM, "$actor has left the game.", self.parent) self.parent.location.characters.remove(self.parent) w = World() if self.parent in w.players: a = Archive() a.save(self.parent) w.players.remove(self.parent) log("NETWORK", "Client at %s closed connection" % self.addr[0]) self.parent.socket = None self.close()
def task_execute(): w = World() for current in w.populators: if w.denizens.has_key(current.instance) and 'mobile' in current.flags: active_denizen = w.denizens[current.instance] choices = [None] choices.extend(libsigma.open_exits(active_denizen.location)) selection = random.choice(choices) if active_denizen.engaged: selection=None if (selection != None): if active_denizen.location.altmsg[selection]!=None: libsigma.report(libsigma.ROOM, "$actor just went " + active_denizen.location.altmsg[selection] + ".", active_denizen ) elif (libsigma.dir2txt(selection) =='leave'): libsigma.report(libsigma.ROOM, "$actor just went out.", active_denizen) elif (libsigma.dir2txt(selection) == 'enter'): libsigma.report(libsigma.ROOM, "$actor just went in.", active_denizen) else: libsigma.report(libsigma.ROOM, "$actor just went " + libsigma.dir2txt(selection) + ".", active_denizen) libsigma.enter_room(active_denizen, active_denizen.location.exits[selection]) libsigma.report(libsigma.ROOM, "$actor has entered the room.", active_denizen)
def process_commands(): while len(command_queue) > 0: speaker, message = command_queue.pop(0) prompt = True if speaker.state == STATE_NAME: if message.lower() == "new": speaker.state = STATE_CONFIG_NAME else: a = Archive() name = message.strip() if a.load(name, speaker): speaker.state = STATE_PASSWORD else: speaker.send_line("I do not know that name.", 2) elif speaker.state == STATE_PASSWORD: password = encrypt_password(message) if password == speaker.password: # Do a dupe check to ensure no double logins # before entering STATE_PLAYING w = World() dupe = False for p in w.players: if p.name == speaker.name: dupe = True speaker.send_line("That name is already active.", 2) speaker.reset() speaker.state = STATE_NAME break if not dupe: log("LOGIN", "User <%s> logged in at %s" % (speaker.name, time_string())) speaker.state = STATE_PLAYING # Add player to master players list w.players.append(speaker) # Insert player into default start room and "look" libsigma.enter_room(speaker, w.rooms[options["default_start"]]) libsigma.report(libsigma.ROOM, "$actor has entered the game.", speaker) speaker.send_line("", 2) libsigma.queue_command(speaker, "look") prompt = False else: speaker.send_line("Incorrect password.", 2) speaker.reset() speaker.state = STATE_NAME elif speaker.state == STATE_CONFIG_NAME: name = message.strip() a = Archive() if a.find(name): speaker.send_line("That name is already taken. Please choose another.", breaks=2) elif not valid_name(name): speaker.send_line("You cannot go by that name here.", breaks=2) else: speaker.name=name speaker.state=STATE_CONFIG_PASSWORD elif speaker.state == STATE_CONFIG_PASSWORD: if not valid_password(message): speaker.send_line("Please make your password at least five simple characters.", breaks=2) else: speaker.password = encrypt_password(message) speaker.state=STATE_CONFIG_CHAR creation.send_options(speaker) elif speaker.state == STATE_CONFIG_CHAR: if not creation.check_choice(speaker, message.lstrip()): speaker.send_line("Please make a valid choice.") if creation.is_configured(speaker): for stat in stats: if speaker.stats[stat]==DEFAULT_STAT: speaker.stats[stat]=3 libsigma.add_points(speaker,5) speaker.state = STATE_PLAYING w = World() w.players.append(speaker) libsigma.enter_room(speaker, w.rooms[options["default_start"]]) libsigma.report(libsigma.ROOM, "$actor has entered the game.", speaker) speaker.send_line("", 2) libsigma.queue_command(speaker, "look") speaker.HP=speaker.max_HP else: creation.send_options(speaker) elif speaker.state == STATE_PLAYING: if not run_command(speaker, message): speaker.send_line("What?") if speaker.socket and prompt: speaker.send_prompt()
def task_execute(): # moves all combats through states through its lifecycle w = World() for c in w.combats[:]: if c.combatant1_action == COMBAT_ACTION_RETREATING: retreat = True for co in c.combatant1.combats: if not co.is_retreat_successful(c.combatant1): c.combatant1.send_line( "You try to retreat, but cannot get away from " + (co.combatant1.name if co.combatant1 != c.combatant1 else c.combatant2.name) + "!") retreat = False if retreat: c.retreat(c.combatant1) continue if c.combatant2_action == COMBAT_ACTION_RETREATING: retreat = True for co in c.combatant2.combats: if not co.is_retreat_successful(c.combatant2): c.combatant2.send_line( "You try to retreat, but cannot get away from " + (co.combatant1.name if co.combatant1 != c.combatant1 else c.combatant2.name) + "!") retreat = False if retreat: c.retreat(c.combatant2) continue if c.combat_state == COMBAT_STATE_INITIALIZING: # Initializing is defined as a combat that has just begun. c.engage_combatants() c.combat_state = COMBAT_STATE_ENGAGING elif c.combat_state == COMBAT_STATE_ENGAGING: c.range = c.evaluate_range() libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor and $direct clash into combat at " + libsigma.val2txt(c.range, range_match_val, range_match_txt) + " range!", c.combatant1, None, c.combatant2) c.send_combat_statuses() c.in_range_set_action() c.queue_strikes() c.combat_state = COMBAT_STATE_FIGHTING break elif c.combat_state == COMBAT_STATE_FIGHTING: # Strange case when strike queue is empty at this point if not c.strike_queue: c.combat_state = COMBAT_STATE_INTERMISSION break striker, defender = c.strike_queue[0] striker_action = c.get_action(striker) defender_action = c.get_action(defender) striker_preferred_range = c.get_preferred_range(striker) ## roll for hit -- Agility if striker_action == COMBAT_ACTION_ATTACKING: ammo = None can_strike = False if not striker.active_stance.weapon_type in ammo_weapons: can_strike = True else: for w in striker.equipped_weapon: if w.ammo: if ammo_requirements[ striker.active_stance. weapon_type] == w.ammo.ammo_type: can_strike = True ammo = w if can_strike: striker_effective_agil = int( striker.stats["agility"] * balance_multiplier[striker.balance]) defender_effective_agil = int( defender.stats["agility"] * balance_multiplier[defender.balance]) agil_diff = striker_effective_agil - defender_effective_agil percent_success = min(max(agil_diff * 3 + 75, 40), 98) roll_for_hit = libsigma.d100() if roll_for_hit <= percent_success: #hit damage = calculate_damage(striker, defender, c.range, ammo) if (striker.active_stance.weapon_type in ammo_weapons): libsigma.transfer_item(ammo, striker.equipped_weapon, c.get_discard(striker), 1) libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor successfully $verb $direct for " + str(damage) + " damage!", striker, ("hit", "hits"), defender) if (defender.HP - damage) <= 0: libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor $verb victorious over $direct!", striker, ("are", "is"), defender) c.release(striker) defender.HP -= damage striker_roll_for_balance = libsigma.d100() defender_roll_for_balance = libsigma.d100() if striker_roll_for_balance < striker.active_stance.balance[ "HitIncreasePercent"]: striker.balance += striker.active_stance.balance[ "HitIncreaseAmount"] if defender_roll_for_balance < defender.active_stance.balance[ "HitReceivedIncreasePercent"]: defender.balance += defender.active_stance.balance[ "HitReceivedIncreaseAmount"] else: #miss if (striker.active_stance.weapon_type in ammo_weapons): libsigma.transfer_item(ammo, striker.equipped_weapon, striker.location.contents, 1, True) libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor $verb in an attempt to attack $direct!", striker, ("miss", "misses"), defender) striker_roll_for_balance = libsigma.d100() defender_roll_for_balance = libsigma.d100() if striker_roll_for_balance < striker.active_stance.balance[ "MissIncreasePercent"]: striker.balance += striker.active_stance.balance[ "MissIncreaseAmount"] if defender_roll_for_balance < defender.active_stance.balance[ "DodgeIncreasePercent"]: defender.balance += defender.active_stance.balance[ "DodgeIncreaseAmount"] else: libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor $verb at $direct, unable to attack!", striker, ("glare", "glares"), defender) elif striker_action == COMBAT_ACTION_IDLE: libsigma.report(libsigma.SELF | libsigma.ROOM, "$actor $verb at $direct, unable to attack!", striker, ("glare", "glares"), defender) if type(striker) == entities.Denizen: if striker.preferred_weapon_range < c.range: libsigma.run_command(striker, "advance") else: libsigma.run_command(striker, "withdraw") elif striker_action == COMBAT_ACTION_ADVANCING: if striker_action == defender_action: c.range = c.evaluate_range() libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor and $direct $verb into " + libsigma.val2txt( c.range, range_match_val, range_match_txt) + " range!", striker, ("close", "close"), defender) c.in_range_set_action() c.strike_queue = [] c.churn = 0 else: agil_diff = striker.stats["agility"] - defender.stats[ "agility"] range_request_diff = striker_preferred_range - c.range percent_success = min( max( 4 * agil_diff + 10 * range_request_diff + 50 + (20 * c.churn), 5), 95) roll_for_range = libsigma.d100() if roll_for_range <= percent_success: c.range = striker_preferred_range c.churn = 0 libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor $verb into " + libsigma.val2txt( c.range, range_match_val, range_match_txt) + " range with $direct!", striker, ("close", "closes"), defender) c.in_range_set_action() c.strike_queue = [] else: c.churn += 1 libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor $verb to close into a closer range with $direct, but cannot!", striker, ("try", "tries"), defender) elif striker_action == COMBAT_ACTION_WITHDRAWING: if striker_action == defender_action: c.range = c.evaluate_range() libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor and $direct $verb into " + libsigma.val2txt( c.range, range_match_val, range_match_txt) + " range!", striker, ("drop", "drop"), defender) c.in_range_set_action() c.strike_queue = [] c.churn = 0 else: agil_diff = striker.stats["agility"] - defender.stats[ "agility"] range_request_diff = c.range - striker_preferred_range percent_success = min( max( 4 * agil_diff + 10 * range_request_diff + 50 + (20 * c.churn), 5), 95) roll_for_range = libsigma.d100() if roll_for_range <= percent_success: c.range = striker_preferred_range c.churn = 0 libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor $verb to " + libsigma.val2txt( c.range, range_match_val, range_match_txt) + " range with $direct!", striker, ("withdraw", "withdraws"), defender) c.in_range_set_action() c.strike_queue = [] else: c.churn += 1 libsigma.report( libsigma.SELF | libsigma.ROOM, "$actor $verb to withdraw to a further range with $direct, but cannot!", striker, ("try", "tries"), defender) striker.send_combat_status() defender.send_combat_status() if c.strike_queue: c.strike_queue = c.strike_queue[1:] if not c.strike_queue: c.combat_state = COMBAT_STATE_INTERMISSION elif c.combat_state == COMBAT_STATE_INTERMISSION: c.queue_strikes() c.combat_state = COMBAT_STATE_FIGHTING
def task_execute(): # moves all combats through states through its lifecycle w = World() for c in w.combats[:]: if c.combatant1_action==COMBAT_ACTION_RETREATING: retreat=True for co in c.combatant1.combats: if not co.is_retreat_successful(c.combatant1): c.combatant1.send_line("You try to retreat, but cannot get away from " + (co.combatant1.name if co.combatant1!=c.combatant1 else c.combatant2.name) + "!") retreat=False if retreat: c.retreat(c.combatant1) continue if c.combatant2_action==COMBAT_ACTION_RETREATING: retreat=True for co in c.combatant2.combats: if not co.is_retreat_successful(c.combatant2): c.combatant2.send_line("You try to retreat, but cannot get away from " + (co.combatant1.name if co.combatant1!=c.combatant1 else c.combatant2.name) + "!") retreat=False if retreat: c.retreat(c.combatant2) continue if c.combat_state==COMBAT_STATE_INITIALIZING: # Initializing is defined as a combat that has just begun. c.engage_combatants() c.combat_state = COMBAT_STATE_ENGAGING elif c.combat_state == COMBAT_STATE_ENGAGING: c.range=c.evaluate_range() libsigma.report(libsigma.SELF | libsigma.ROOM,"$actor and $direct clash into combat at " + libsigma.val2txt(c.range,range_match_val,range_match_txt) +" range!",c.combatant1,None,c.combatant2) c.send_combat_statuses() c.in_range_set_action() c.queue_strikes() c.combat_state=COMBAT_STATE_FIGHTING break elif c.combat_state == COMBAT_STATE_FIGHTING: # Strange case when strike queue is empty at this point if not c.strike_queue: c.combat_state = COMBAT_STATE_INTERMISSION break striker, defender = c.strike_queue[0] striker_action=c.get_action(striker) defender_action=c.get_action(defender) striker_preferred_range=c.get_preferred_range(striker) ## roll for hit -- Agility if striker_action==COMBAT_ACTION_ATTACKING: ammo=None can_strike=False if not striker.active_stance.weapon_type in ammo_weapons: can_strike=True else: for w in striker.equipped_weapon: if w.ammo: if ammo_requirements[striker.active_stance.weapon_type] == w.ammo.ammo_type: can_strike=True ammo=w if can_strike: striker_effective_agil=int(striker.stats["agility"]*balance_multiplier[striker.balance]) defender_effective_agil=int(defender.stats["agility"]*balance_multiplier[defender.balance]) agil_diff= striker_effective_agil - defender_effective_agil percent_success=min(max(agil_diff * 3 + 75, 40), 98) roll_for_hit=libsigma.d100() if roll_for_hit <= percent_success: #hit damage = calculate_damage(striker, defender,c.range,ammo) if(striker.active_stance.weapon_type in ammo_weapons): libsigma.transfer_item(ammo,striker.equipped_weapon,c.get_discard(striker),1) libsigma.report(libsigma.SELF | libsigma.ROOM,"$actor successfully $verb $direct for " + str(damage) +" damage!", striker,("hit","hits"), defender) if (defender.HP - damage) <= 0: libsigma.report(libsigma.SELF | libsigma.ROOM, "$actor $verb victorious over $direct!",striker,("are","is"),defender) c.release(striker) defender.HP -= damage striker_roll_for_balance=libsigma.d100() defender_roll_for_balance=libsigma.d100() if striker_roll_for_balance<striker.active_stance.balance["HitIncreasePercent"]: striker.balance += striker.active_stance.balance["HitIncreaseAmount"] if defender_roll_for_balance<defender.active_stance.balance["HitReceivedIncreasePercent"]: defender.balance += defender.active_stance.balance["HitReceivedIncreaseAmount"] else: #miss if(striker.active_stance.weapon_type in ammo_weapons): libsigma.transfer_item(ammo,striker.equipped_weapon,striker.location.contents,1,True) libsigma.report(libsigma.SELF | libsigma.ROOM,"$actor $verb in an attempt to attack $direct!" ,striker,("miss","misses"),defender) striker_roll_for_balance=libsigma.d100() defender_roll_for_balance=libsigma.d100() if striker_roll_for_balance<striker.active_stance.balance["MissIncreasePercent"]: striker.balance += striker.active_stance.balance["MissIncreaseAmount"] if defender_roll_for_balance<defender.active_stance.balance["DodgeIncreasePercent"]: defender.balance += defender.active_stance.balance["DodgeIncreaseAmount"] else: libsigma.report(libsigma.SELF | libsigma.ROOM,"$actor $verb at $direct, unable to attack!", striker, ("glare", "glares"), defender) elif striker_action==COMBAT_ACTION_IDLE: libsigma.report(libsigma.SELF | libsigma.ROOM,"$actor $verb at $direct, unable to attack!", striker, ("glare", "glares"), defender) if type(striker)==entities.Denizen: if striker.preferred_weapon_range < c.range: libsigma.run_command(striker, "advance") else: libsigma.run_command(striker, "withdraw") elif striker_action==COMBAT_ACTION_ADVANCING: if striker_action==defender_action: c.range=c.evaluate_range() libsigma.report(libsigma.SELF| libsigma.ROOM, "$actor and $direct $verb into " + libsigma.val2txt(c.range, range_match_val, range_match_txt) + " range!",striker,("close", "close"), defender) c.in_range_set_action() c.strike_queue=[] c.churn=0 else: agil_diff=striker.stats["agility"] - defender.stats["agility"] range_request_diff=striker_preferred_range - c.range percent_success=min(max(4*agil_diff+10*range_request_diff + 50 + (20*c.churn), 5), 95) roll_for_range=libsigma.d100() if roll_for_range <= percent_success: c.range=striker_preferred_range c.churn=0 libsigma.report(libsigma.SELF| libsigma.ROOM, "$actor $verb into " + libsigma.val2txt(c.range, range_match_val, range_match_txt) + " range with $direct!",striker,("close", "closes"), defender) c.in_range_set_action() c.strike_queue=[] else: c.churn+=1 libsigma.report(libsigma.SELF| libsigma.ROOM, "$actor $verb to close into a closer range with $direct, but cannot!",striker,("try", "tries"), defender) elif striker_action==COMBAT_ACTION_WITHDRAWING: if striker_action==defender_action: c.range=c.evaluate_range() libsigma.report(libsigma.SELF| libsigma.ROOM, "$actor and $direct $verb into " + libsigma.val2txt(c.range, range_match_val, range_match_txt) + " range!",striker,("drop", "drop"), defender) c.in_range_set_action() c.strike_queue=[] c.churn=0 else: agil_diff=striker.stats["agility"] - defender.stats["agility"] range_request_diff= c.range-striker_preferred_range percent_success=min(max(4*agil_diff+10*range_request_diff + 50 + (20*c.churn), 5), 95) roll_for_range=libsigma.d100() if roll_for_range <= percent_success: c.range=striker_preferred_range c.churn=0 libsigma.report(libsigma.SELF| libsigma.ROOM, "$actor $verb to " + libsigma.val2txt(c.range, range_match_val, range_match_txt) + " range with $direct!",striker,("withdraw", "withdraws"), defender) c.in_range_set_action() c.strike_queue=[] else: c.churn+=1 libsigma.report(libsigma.SELF| libsigma.ROOM, "$actor $verb to withdraw to a further range with $direct, but cannot!",striker,("try", "tries"), defender) striker.send_combat_status() defender.send_combat_status() if c.strike_queue: c.strike_queue = c.strike_queue[1:] if not c.strike_queue: c.combat_state = COMBAT_STATE_INTERMISSION elif c.combat_state == COMBAT_STATE_INTERMISSION: c.queue_strikes() c.combat_state=COMBAT_STATE_FIGHTING
def process_commands(): while len(command_queue) > 0: speaker, message = command_queue.pop(0) prompt = True if speaker.state == STATE_NAME: if message.lower() == "new": speaker.state = STATE_CONFIG_NAME else: a = Archive() name = message.strip() if a.load(name, speaker): speaker.state = STATE_PASSWORD else: speaker.send_line("I do not know that name.", 2) elif speaker.state == STATE_PASSWORD: password = encrypt_password(message) if password == speaker.password: # Do a dupe check to ensure no double logins # before entering STATE_PLAYING w = World() dupe = False for p in w.players: if p.name == speaker.name: dupe = True speaker.send_line("That name is already active.", 2) speaker.reset() speaker.state = STATE_NAME break if not dupe: log( "LOGIN", "User <%s> logged in at %s" % (speaker.name, time_string())) speaker.state = STATE_PLAYING # Add player to master players list w.players.append(speaker) # Insert player into default start room and "look" libsigma.enter_room(speaker, w.rooms[options["default_start"]]) libsigma.report(libsigma.ROOM, "$actor has entered the game.", speaker) speaker.send_line("", 2) libsigma.queue_command(speaker, "look") prompt = False else: speaker.send_line("Incorrect password.", 2) speaker.reset() speaker.state = STATE_NAME elif speaker.state == STATE_CONFIG_NAME: name = message.strip() a = Archive() if a.find(name): speaker.send_line( "That name is already taken. Please choose another.", breaks=2) elif not valid_name(name): speaker.send_line("You cannot go by that name here.", breaks=2) else: speaker.name = name speaker.state = STATE_CONFIG_PASSWORD elif speaker.state == STATE_CONFIG_PASSWORD: if not valid_password(message): speaker.send_line( "Please make your password at least five simple characters.", breaks=2) else: speaker.password = encrypt_password(message) speaker.state = STATE_CONFIG_CHAR creation.send_options(speaker) elif speaker.state == STATE_CONFIG_CHAR: if not creation.check_choice(speaker, message.lstrip()): speaker.send_line("Please make a valid choice.") if creation.is_configured(speaker): for stat in stats: if speaker.stats[stat] == DEFAULT_STAT: speaker.stats[stat] = 3 libsigma.add_points(speaker, 5) speaker.state = STATE_PLAYING w = World() w.players.append(speaker) libsigma.enter_room(speaker, w.rooms[options["default_start"]]) libsigma.report(libsigma.ROOM, "$actor has entered the game.", speaker) speaker.send_line("", 2) libsigma.queue_command(speaker, "look") speaker.HP = speaker.max_HP else: creation.send_options(speaker) elif speaker.state == STATE_PLAYING: if not run_command(speaker, message): speaker.send_line("What?") if speaker.socket and prompt: speaker.send_prompt()
def cast(self,speaker,target): libsigma.report(libsigma.SELF | libsigma.ROOM, "$actor $verb slightly more agitated than before.",speaker,('appear','appears')) speaker.send_line("You have successfully cast Adrenaline!") pass