def release(self, victor): w = World() w.combats.remove(self) self.combatant1.combats.remove(self) self.combatant2.combats.remove(self) for combatant in [self.combatant1, self.combatant2]: if combatant.engaged == self: if combatant.combats: combatant.engaged = self.combatant1.combats[0] combatant.engaged.in_range_set_action(combatant) else: combatant.engaged = None victor_discard = self.get_discard(victor) loser = self.get_opponent(victor) for d in victor_discard: if d.stackable: d_a = 0 for a in range(d.quantity): roll = libsigma.d100() if roll <= 75: d_a += 1 libsigma.transfer_item(d, victor_discard, victor.contents, d_a) victor.send_line("You recover " + str(d_a) + " of " + d.name + "!") else: roll = libsigma.d100() if roll <= 80: libsigma.transfer_item(d, self.victor_discard, victor.contents) victor.send_line("You recover " + d.name + "!")
def evaluate_range(self): #if self.combatants[0].preferred_weapon_range==self.combatants[1].preferred_weapon_range: if self.get_preferred_range(self.combatants[0]) == self.get_preferred_range(self.combatants[1]): return self.get_preferred_range(self.combatants[0]) else: #set up chance to make it to desired range according to combatant1 #TODO: Will have to be rewritten when bonsuses come on... #this is a real simple implementation anyway agil_diff=self.combatants[0].stats["agility"] - self.combatants[1].stats["agility"] range_request_diff= self.get_preferred_range(self.combatants[0]) - self.get_preferred_range(self.combatants[1]) percent_success=min(max(4*agil_diff+10*range_request_diff + 50, 5), 95) roll_for_range=libsigma.d100() # libsigma.report(libsigma.SELF|libsigma.ROOM, "Roll was: " + str(roll_for_range) + " and threshold for success for $actor was: " + str(percent_success),c.combatant1 ) if roll_for_range <= percent_success: return self.get_preferred_range(self.combatants[0]) else: return self.get_preferred_range(self.combatants[1])
def queue_strikes(self): #TODO: Section needs work. Defaults to attack, need to do more checks if self.combatant1_action == COMBAT_ACTION_ATTACKING and self.combatant2_action != COMBAT_ACTION_ATTACKING: self.strike_queue.append((self.combatant1, self.combatant2)) self.strike_queue.append((self.combatant2, self.combatant1)) return elif self.combatant2_action == COMBAT_ACTION_ATTACKING and self.combatant1_action != COMBAT_ACTION_ATTACKING: self.strike_queue.append((self.combatant2, self.combatant1)) self.strike_queue.append((self.combatant1, self.combatant2)) return else: agil_diff = self.combatant1.stats["agility"] - self.combatant2.stats["agility"] percent_success = min(max(agil_diff * 5 + 50, 20), 80) roll_for_first_strike = libsigma.d100() if roll_for_first_strike <= percent_success: self.strike_queue.append((self.combatant1, self.combatant2)) self.strike_queue.append((self.combatant2, self.combatant1)) else: self.strike_queue.append((self.combatant2, self.combatant1)) self.strike_queue.append((self.combatant1, self.combatant2))
def queue_strikes(self): #TODO: Section needs work. Defaults to attack, need to do more checks if self.combatant1_action == COMBAT_ACTION_ATTACKING and self.combatant2_action != COMBAT_ACTION_ATTACKING: self.strike_queue.append((self.combatant1, self.combatant2)) self.strike_queue.append((self.combatant2, self.combatant1)) return elif self.combatant2_action == COMBAT_ACTION_ATTACKING and self.combatant1_action != COMBAT_ACTION_ATTACKING: self.strike_queue.append((self.combatant2, self.combatant1)) self.strike_queue.append((self.combatant1, self.combatant2)) return else: agil_diff = self.combatant1.stats[ "agility"] - self.combatant2.stats["agility"] percent_success = min(max(agil_diff * 5 + 50, 20), 80) roll_for_first_strike = libsigma.d100() if roll_for_first_strike <= percent_success: self.strike_queue.append((self.combatant1, self.combatant2)) self.strike_queue.append((self.combatant2, self.combatant1)) else: self.strike_queue.append((self.combatant2, self.combatant1)) self.strike_queue.append((self.combatant1, self.combatant2))
def evaluate_range(self): #if self.combatants[0].preferred_weapon_range==self.combatants[1].preferred_weapon_range: if self.get_preferred_range( self.combatants[0]) == self.get_preferred_range( self.combatants[1]): return self.get_preferred_range(self.combatants[0]) else: #set up chance to make it to desired range according to combatant1 #TODO: Will have to be rewritten when bonsuses come on... #this is a real simple implementation anyway agil_diff = self.combatants[0].stats["agility"] - self.combatants[ 1].stats["agility"] range_request_diff = self.get_preferred_range( self.combatants[0]) - self.get_preferred_range( self.combatants[1]) percent_success = min( max(4 * agil_diff + 10 * range_request_diff + 50, 5), 95) roll_for_range = libsigma.d100() # libsigma.report(libsigma.SELF|libsigma.ROOM, "Roll was: " + str(roll_for_range) + " and threshold for success for $actor was: " + str(percent_success),c.combatant1 ) if roll_for_range <= percent_success: return self.get_preferred_range(self.combatants[0]) else: return self.get_preferred_range(self.combatants[1])
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