Some minor adjustments for pep8.
This commit is contained in:
parent
005923ee72
commit
59f491eab4
1 changed files with 192 additions and 169 deletions
|
|
@ -51,6 +51,8 @@ from evennia.commands.default.help import CmdHelp
|
|||
COMBAT FUNCTIONS START HERE
|
||||
----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
|
||||
def roll_init(character):
|
||||
"""
|
||||
Rolls a number between 1-1000 to determine initiative.
|
||||
|
|
@ -77,6 +79,7 @@ def roll_init(character):
|
|||
"""
|
||||
return randint(1, 1000)
|
||||
|
||||
|
||||
def get_attack(attacker, defender):
|
||||
"""
|
||||
Returns a value for an attack roll.
|
||||
|
|
@ -101,6 +104,7 @@ def get_attack(attacker, defender):
|
|||
attack_value = randint(1, 100)
|
||||
return attack_value
|
||||
|
||||
|
||||
def get_defense(attacker, defender):
|
||||
"""
|
||||
Returns a value for defense, which an attack roll must equal or exceed in order
|
||||
|
|
@ -124,6 +128,7 @@ def get_defense(attacker, defender):
|
|||
defense_value = 50
|
||||
return defense_value
|
||||
|
||||
|
||||
def get_damage(attacker, defender):
|
||||
"""
|
||||
Returns a value for damage to be deducted from the defender's HP after abilities
|
||||
|
|
@ -147,6 +152,7 @@ def get_damage(attacker, defender):
|
|||
damage_value = randint(15, 25)
|
||||
return damage_value
|
||||
|
||||
|
||||
def apply_damage(defender, damage):
|
||||
"""
|
||||
Applies damage to a target, reducing their HP by the damage amount to a
|
||||
|
|
@ -161,6 +167,7 @@ def apply_damage(defender, damage):
|
|||
if defender.db.hp <= 0:
|
||||
defender.db.hp = 0
|
||||
|
||||
|
||||
def resolve_attack(attacker, defender, attack_value=None, defense_value=None):
|
||||
"""
|
||||
Resolves an attack and outputs the result.
|
||||
|
|
@ -192,6 +199,7 @@ def resolve_attack(attacker, defender, attack_value=None, defense_value=None):
|
|||
if defender.db.hp <= 0:
|
||||
attacker.location.msg_contents("%s has been defeated!" % defender)
|
||||
|
||||
|
||||
def combat_cleanup(character):
|
||||
"""
|
||||
Cleans up all the temporary combat-related attributes on a character.
|
||||
|
|
@ -207,6 +215,7 @@ def combat_cleanup(character):
|
|||
if attr.key[:7] == "combat_": # If the attribute name starts with 'combat_'...
|
||||
character.attributes.remove(key=attr.key) # ...then delete it!
|
||||
|
||||
|
||||
def is_in_combat(character):
|
||||
"""
|
||||
Returns true if the given character is in combat.
|
||||
|
|
@ -221,6 +230,7 @@ def is_in_combat(character):
|
|||
return True
|
||||
return False
|
||||
|
||||
|
||||
def is_turn(character):
|
||||
"""
|
||||
Returns true if it's currently the given character's turn in combat.
|
||||
|
|
@ -237,6 +247,7 @@ def is_turn(character):
|
|||
return True
|
||||
return False
|
||||
|
||||
|
||||
def spend_action(character, actions, action_name=None):
|
||||
"""
|
||||
Spends a character's available combat actions and checks for end of turn.
|
||||
|
|
@ -266,6 +277,7 @@ CHARACTER TYPECLASS
|
|||
----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
|
||||
class BattleCharacter(DefaultCharacter):
|
||||
"""
|
||||
A character able to participate in turn-based combat. Has attributes for current
|
||||
|
|
@ -286,6 +298,7 @@ class BattleCharacter(DefaultCharacter):
|
|||
You may want to expand this to include various 'stats' that
|
||||
can be changed at creation and factor into combat calculations.
|
||||
"""
|
||||
|
||||
def at_before_move(self, destination):
|
||||
"""
|
||||
Called just before starting to move this object to
|
||||
|
|
@ -311,11 +324,14 @@ class BattleCharacter(DefaultCharacter):
|
|||
return False
|
||||
return True
|
||||
|
||||
|
||||
"""
|
||||
----------------------------------------------------------------------------
|
||||
COMMANDS START HERE
|
||||
----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
|
||||
class CmdFight(Command):
|
||||
"""
|
||||
Starts a fight with everyone in the same room as you.
|
||||
|
|
@ -354,9 +370,11 @@ class CmdFight(Command):
|
|||
here.db.Combat_TurnHandler.join_fight(self.caller) # Join the fight!
|
||||
return
|
||||
here.msg_contents("%s starts a fight!" % self.caller)
|
||||
here.scripts.add("contrib.turnbattle.TurnHandler") # Add a turn handler script to the room, which starts combat.
|
||||
# Add a turn handler script to the room, which starts combat.
|
||||
here.scripts.add("contrib.turnbattle.TurnHandler")
|
||||
# Remember you'll have to change the path to the script if you copy this code to your own modules!
|
||||
|
||||
|
||||
class CmdAttack(Command):
|
||||
"""
|
||||
Attacks another character.
|
||||
|
|
@ -405,6 +423,7 @@ class CmdAttack(Command):
|
|||
resolve_attack(attacker, defender)
|
||||
spend_action(self.caller, 1, action_name="attack") # Use up one action.
|
||||
|
||||
|
||||
class CmdPass(Command):
|
||||
"""
|
||||
Passes on your turn.
|
||||
|
|
@ -435,6 +454,7 @@ class CmdPass(Command):
|
|||
self.caller.location.msg_contents("%s takes no further action, passing the turn." % self.caller)
|
||||
spend_action(self.caller, 'all', action_name="pass") # Spend all remaining actions.
|
||||
|
||||
|
||||
class CmdDisengage(Command):
|
||||
"""
|
||||
Passes your turn and attempts to end combat.
|
||||
|
|
@ -470,6 +490,7 @@ class CmdDisengage(Command):
|
|||
the turn handler script to see if all fighters have disengaged.
|
||||
"""
|
||||
|
||||
|
||||
class CmdRest(Command):
|
||||
"""
|
||||
Recovers damage.
|
||||
|
|
@ -497,6 +518,7 @@ class CmdRest(Command):
|
|||
You'll probably want to replace this with your own system for recovering HP.
|
||||
"""
|
||||
|
||||
|
||||
class CmdCombatHelp(CmdHelp):
|
||||
"""
|
||||
View help or a list of topics
|
||||
|
|
@ -521,6 +543,7 @@ class CmdCombatHelp(CmdHelp):
|
|||
else:
|
||||
super(CmdCombatHelp, self).func() # Call the default help command
|
||||
|
||||
|
||||
class BattleCmdSet(default_cmds.CharacterCmdSet):
|
||||
"""
|
||||
This command set includes all the commmands used in the battle system.
|
||||
|
|
@ -538,12 +561,14 @@ class BattleCmdSet(default_cmds.CharacterCmdSet):
|
|||
self.add(CmdDisengage())
|
||||
self.add(CmdCombatHelp())
|
||||
|
||||
|
||||
"""
|
||||
----------------------------------------------------------------------------
|
||||
SCRIPTS START HERE
|
||||
----------------------------------------------------------------------------
|
||||
"""
|
||||
|
||||
|
||||
class TurnHandler(DefaultScript):
|
||||
"""
|
||||
This is the script that handles the progression of combat through turns.
|
||||
|
|
@ -614,7 +639,6 @@ class TurnHandler(DefaultScript):
|
|||
currentchar.msg("WARNING: About to time out!")
|
||||
self.db.timeout_warning_given = True
|
||||
|
||||
|
||||
def initialize_for_combat(self, character):
|
||||
"""
|
||||
Prepares a character for combat when starting or entering a fight.
|
||||
|
|
@ -656,7 +680,7 @@ class TurnHandler(DefaultScript):
|
|||
for fighter in self.db.fighters:
|
||||
if fighter.db.Combat_LastAction != "disengage": # If a character has done anything but disengage
|
||||
disengage_check = False
|
||||
if disengage_check == True: # All characters have disengaged
|
||||
if disengage_check: # All characters have disengaged
|
||||
self.obj.msg_contents("All fighters have disengaged! Combat is over!")
|
||||
self.stop() # Stop this script and end combat.
|
||||
return
|
||||
|
|
@ -685,7 +709,6 @@ class TurnHandler(DefaultScript):
|
|||
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
|
||||
self.start_turn(newchar) # Start the new character's turn.
|
||||
|
||||
|
||||
def turn_end_check(self, character):
|
||||
"""
|
||||
Tests to see if a character's turn is over, and cycles to the next turn if it is.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue