Ran black on branc

This commit is contained in:
Griatch 2019-12-16 20:31:42 +01:00
parent 6effb6f456
commit 4ea6209123
230 changed files with 7108 additions and 2395 deletions

View file

@ -291,7 +291,9 @@ def spend_action(character, actions, action_name=None):
character.db.combat_actionsleft -= actions # Use up actions.
if character.db.combat_actionsleft < 0:
character.db.combat_actionsleft = 0 # Can't have fewer than 0 actions
character.db.combat_turnhandler.turn_end_check(character) # Signal potential end of turn.
character.db.combat_turnhandler.turn_end_check(
character
) # Signal potential end of turn.
"""
@ -394,7 +396,9 @@ class TBBasicTurnHandler(DefaultScript):
self.db.fighters = ordered_by_roll
# Announce the turn order.
self.obj.msg_contents("Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters))
self.obj.msg_contents(
"Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters)
)
# Start first fighter's turn.
self.start_turn(self.db.fighters[0])
@ -409,7 +413,9 @@ class TBBasicTurnHandler(DefaultScript):
"""
for fighter in self.db.fighters:
combat_cleanup(fighter) # Clean up the combat attributes for every fighter.
self.obj.db.combat_turnhandler = None # Remove reference to turn handler in location
self.obj.db.combat_turnhandler = (
None
) # Remove reference to turn handler in location
def at_repeat(self):
"""
@ -427,7 +433,9 @@ class TBBasicTurnHandler(DefaultScript):
currentchar, "all", action_name="disengage"
) # Spend all remaining actions.
return
elif self.db.timer <= 10 and not self.db.timeout_warning_given: # 10 seconds left
elif (
self.db.timer <= 10 and not self.db.timeout_warning_given
): # 10 seconds left
# Warn the current character if they're about to time out.
currentchar.msg("WARNING: About to time out!")
self.db.timeout_warning_given = True
@ -439,7 +447,9 @@ class TBBasicTurnHandler(DefaultScript):
Args:
character (obj): Character to initialize for combat.
"""
combat_cleanup(character) # Clean up leftover combat attributes beforehand, just in case.
combat_cleanup(
character
) # Clean up leftover combat attributes beforehand, just in case.
character.db.combat_actionsleft = (
0
) # Actions remaining - start of turn adds to this, turn ends when it reaches 0
@ -488,13 +498,17 @@ class TBBasicTurnHandler(DefaultScript):
defeated_characters = 0
for fighter in self.db.fighters:
if fighter.db.HP == 0:
defeated_characters += 1 # Add 1 for every fighter with 0 HP left (defeated)
defeated_characters += (
1
) # Add 1 for every fighter with 0 HP left (defeated)
if defeated_characters == (
len(self.db.fighters) - 1
): # If only one character isn't defeated
for fighter in self.db.fighters:
if fighter.db.HP != 0:
LastStanding = fighter # Pick the one fighter left with HP remaining
LastStanding = (
fighter
) # Pick the one fighter left with HP remaining
self.obj.msg_contents("Only %s remains! Combat is over!" % LastStanding)
self.stop() # Stop this script and end combat.
return
@ -503,11 +517,15 @@ class TBBasicTurnHandler(DefaultScript):
currentchar = self.db.fighters[self.db.turn]
self.db.turn += 1 # Go to the next in the turn order.
if self.db.turn > len(self.db.fighters) - 1:
self.db.turn = 0 # Go back to the first in the turn order once you reach the end.
self.db.turn = (
0
) # Go back to the first in the turn order once you reach the end.
newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning.
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
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):
@ -571,7 +589,9 @@ class CmdFight(Command):
if is_in_combat(self.caller): # Already in a fight
self.caller.msg("You're already in a fight!")
return
for thing in here.contents: # Test everything in the room to add it to the fight.
for (
thing
) in here.contents: # Test everything in the room to add it to the fight.
if thing.db.HP: # If the object has HP...
fighters.append(thing) # ...then add it to the fight.
if len(fighters) <= 1: # If you're the only able fighter in the room
@ -666,7 +686,9 @@ 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.
spend_action(
self.caller, "all", action_name="pass"
) # Spend all remaining actions.
class CmdDisengage(Command):
@ -697,8 +719,12 @@ class CmdDisengage(Command):
self.caller.msg("You can only do that on your turn.")
return
self.caller.location.msg_contents("%s disengages, ready to stop fighting." % self.caller)
spend_action(self.caller, "all", action_name="disengage") # Spend all remaining actions.
self.caller.location.msg_contents(
"%s disengages, ready to stop fighting." % self.caller
)
spend_action(
self.caller, "all", action_name="disengage"
) # Spend all remaining actions.
"""
The action_name kwarg sets the character's last action to "disengage", which is checked by
the turn handler script to see if all fighters have disengaged.
@ -750,7 +776,9 @@ class CmdCombatHelp(CmdHelp):
# tips on combat when used in a fight with no arguments.
def func(self):
if is_in_combat(self.caller) and not self.args: # In combat and entered 'help' alone
if (
is_in_combat(self.caller) and not self.args
): # In combat and entered 'help' alone
self.caller.msg(
"Available combat commands:|/"
+ "|wAttack:|n Attack a target, attempting to deal damage.|/"

View file

@ -55,7 +55,13 @@ in your game and using it as-is.
"""
from random import randint
from evennia import DefaultCharacter, Command, default_cmds, DefaultScript, DefaultObject
from evennia import (
DefaultCharacter,
Command,
default_cmds,
DefaultScript,
DefaultObject,
)
from evennia.commands.default.help import CmdHelp
"""
@ -270,7 +276,8 @@ def resolve_attack(attacker, defender, attack_value=None, defense_value=None):
)
else:
attacker.location.msg_contents(
"%s's %s bounces harmlessly off %s!" % (attacker, attackers_weapon, defender)
"%s's %s bounces harmlessly off %s!"
% (attacker, attackers_weapon, defender)
)
apply_damage(defender, damage_value)
# If defender HP is reduced to 0 or less, call at_defeat.
@ -342,7 +349,9 @@ def spend_action(character, actions, action_name=None):
character.db.combat_actionsleft -= actions # Use up actions.
if character.db.combat_actionsleft < 0:
character.db.combat_actionsleft = 0 # Can't have fewer than 0 actions
character.db.combat_turnhandler.turn_end_check(character) # Signal potential end of turn.
character.db.combat_turnhandler.turn_end_check(
character
) # Signal potential end of turn.
"""
@ -391,7 +400,9 @@ class TBEquipTurnHandler(DefaultScript):
self.db.fighters = ordered_by_roll
# Announce the turn order.
self.obj.msg_contents("Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters))
self.obj.msg_contents(
"Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters)
)
# Start first fighter's turn.
self.start_turn(self.db.fighters[0])
@ -406,7 +417,9 @@ class TBEquipTurnHandler(DefaultScript):
"""
for fighter in self.db.fighters:
combat_cleanup(fighter) # Clean up the combat attributes for every fighter.
self.obj.db.combat_turnhandler = None # Remove reference to turn handler in location
self.obj.db.combat_turnhandler = (
None
) # Remove reference to turn handler in location
def at_repeat(self):
"""
@ -424,7 +437,9 @@ class TBEquipTurnHandler(DefaultScript):
currentchar, "all", action_name="disengage"
) # Spend all remaining actions.
return
elif self.db.timer <= 10 and not self.db.timeout_warning_given: # 10 seconds left
elif (
self.db.timer <= 10 and not self.db.timeout_warning_given
): # 10 seconds left
# Warn the current character if they're about to time out.
currentchar.msg("WARNING: About to time out!")
self.db.timeout_warning_given = True
@ -436,7 +451,9 @@ class TBEquipTurnHandler(DefaultScript):
Args:
character (obj): Character to initialize for combat.
"""
combat_cleanup(character) # Clean up leftover combat attributes beforehand, just in case.
combat_cleanup(
character
) # Clean up leftover combat attributes beforehand, just in case.
character.db.combat_actionsleft = (
0
) # Actions remaining - start of turn adds to this, turn ends when it reaches 0
@ -485,13 +502,17 @@ class TBEquipTurnHandler(DefaultScript):
defeated_characters = 0
for fighter in self.db.fighters:
if fighter.db.HP == 0:
defeated_characters += 1 # Add 1 for every fighter with 0 HP left (defeated)
defeated_characters += (
1
) # Add 1 for every fighter with 0 HP left (defeated)
if defeated_characters == (
len(self.db.fighters) - 1
): # If only one character isn't defeated
for fighter in self.db.fighters:
if fighter.db.HP != 0:
LastStanding = fighter # Pick the one fighter left with HP remaining
LastStanding = (
fighter
) # Pick the one fighter left with HP remaining
self.obj.msg_contents("Only %s remains! Combat is over!" % LastStanding)
self.stop() # Stop this script and end combat.
return
@ -500,11 +521,15 @@ class TBEquipTurnHandler(DefaultScript):
currentchar = self.db.fighters[self.db.turn]
self.db.turn += 1 # Go to the next in the turn order.
if self.db.turn > len(self.db.fighters) - 1:
self.db.turn = 0 # Go back to the first in the turn order once you reach the end.
self.db.turn = (
0
) # Go back to the first in the turn order once you reach the end.
newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning.
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
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):
@ -710,7 +735,9 @@ class CmdFight(Command):
if is_in_combat(self.caller): # Already in a fight
self.caller.msg("You're already in a fight!")
return
for thing in here.contents: # Test everything in the room to add it to the fight.
for (
thing
) in here.contents: # Test everything in the room to add it to the fight.
if thing.db.HP: # If the object has HP...
fighters.append(thing) # ...then add it to the fight.
if len(fighters) <= 1: # If you're the only able fighter in the room
@ -805,7 +832,9 @@ 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.
spend_action(
self.caller, "all", action_name="pass"
) # Spend all remaining actions.
class CmdDisengage(Command):
@ -836,8 +865,12 @@ class CmdDisengage(Command):
self.caller.msg("You can only do that on your turn.")
return
self.caller.location.msg_contents("%s disengages, ready to stop fighting." % self.caller)
spend_action(self.caller, "all", action_name="disengage") # Spend all remaining actions.
self.caller.location.msg_contents(
"%s disengages, ready to stop fighting." % self.caller
)
spend_action(
self.caller, "all", action_name="disengage"
) # Spend all remaining actions.
"""
The action_name kwarg sets the character's last action to "disengage", which is checked by
the turn handler script to see if all fighters have disengaged.
@ -889,7 +922,9 @@ class CmdCombatHelp(CmdHelp):
# tips on combat when used in a fight with no arguments.
def func(self):
if is_in_combat(self.caller) and not self.args: # In combat and entered 'help' alone
if (
is_in_combat(self.caller) and not self.args
): # In combat and entered 'help' alone
self.caller.msg(
"Available combat commands:|/"
+ "|wAttack:|n Attack a target, attempting to deal damage.|/"
@ -980,7 +1015,9 @@ class CmdUnwield(Command):
else:
old_weapon = self.caller.db.wielded_weapon
self.caller.db.wielded_weapon = None
self.caller.location.msg_contents("%s lowers %s." % (self.caller, old_weapon))
self.caller.location.msg_contents(
"%s lowers %s." % (self.caller, old_weapon)
)
class CmdDon(Command):
@ -1056,7 +1093,9 @@ class CmdDoff(Command):
else:
old_armor = self.caller.db.worn_armor
self.caller.db.worn_armor = None
self.caller.location.msg_contents("%s removes %s." % (self.caller, old_armor))
self.caller.location.msg_contents(
"%s removes %s." % (self.caller, old_armor)
)
class BattleCmdSet(default_cmds.CharacterCmdSet):

View file

@ -360,7 +360,9 @@ def spend_action(character, actions, action_name=None):
character.db.combat_actionsleft -= actions # Use up actions.
if character.db.combat_actionsleft < 0:
character.db.combat_actionsleft = 0 # Can't have fewer than 0 actions
character.db.combat_turnhandler.turn_end_check(character) # Signal potential end of turn.
character.db.combat_turnhandler.turn_end_check(
character
) # Signal potential end of turn.
def spend_item_use(item, user):
@ -381,7 +383,9 @@ def spend_item_use(item, user):
if item.db.item_uses > 0: # Has uses remaining
# Inform the player
user.msg("%s has %i uses remaining." % (item.key.capitalize(), item.db.item_uses))
user.msg(
"%s has %i uses remaining." % (item.key.capitalize(), item.db.item_uses)
)
else: # All uses spent
@ -390,13 +394,19 @@ def spend_item_use(item, user):
user.msg("%s has no uses remaining." % item.key.capitalize())
else: # If item is consumable
if item.db.item_consumable == True: # If the value is 'True', just destroy the item
if (
item.db.item_consumable == True
): # If the value is 'True', just destroy the item
user.msg("%s has been consumed." % item.key.capitalize())
item.delete() # Delete the spent item
else: # If a string, use value of item_consumable to spawn an object in its place
residue = spawn({"prototype": item.db.item_consumable})[0] # Spawn the residue
residue.location = item.location # Move the residue to the same place as the item
residue = spawn({"prototype": item.db.item_consumable})[
0
] # Spawn the residue
residue.location = (
item.location
) # Move the residue to the same place as the item
user.msg("After using %s, you are left with %s." % (item, residue))
item.delete() # Delete the spent item
@ -491,7 +501,9 @@ def add_condition(character, turnchar, condition, duration):
# The first value is the remaining turns - the second value is whose turn to count down on.
character.db.conditions.update({condition: [duration, turnchar]})
# Tell everyone!
character.location.msg_contents("%s gains the '%s' condition." % (character, condition))
character.location.msg_contents(
"%s gains the '%s' condition." % (character, condition)
)
"""
@ -577,13 +589,17 @@ class TBItemsCharacter(DefaultCharacter):
if self.db.hp + to_heal > self.db.max_hp:
to_heal = self.db.max_hp - self.db.hp # Cap healing to max HP
self.db.hp += to_heal
self.location.msg_contents("%s regains %i HP from Regeneration." % (self, to_heal))
self.location.msg_contents(
"%s regains %i HP from Regeneration." % (self, to_heal)
)
# Poisoned: does 4 to 8 damage at the start of character's turn
if "Poisoned" in self.db.conditions:
to_hurt = randint(POISON_RATE[0], POISON_RATE[1]) # Deal damage
apply_damage(self, to_hurt)
self.location.msg_contents("%s takes %i damage from being Poisoned." % (self, to_hurt))
self.location.msg_contents(
"%s takes %i damage from being Poisoned." % (self, to_hurt)
)
if self.db.hp <= 0:
# Call at_defeat if poison defeats the character
at_defeat(self)
@ -596,7 +612,9 @@ class TBItemsCharacter(DefaultCharacter):
# Paralyzed: Have no actions in combat.
if is_in_combat(self) and "Paralyzed" in self.db.conditions:
self.db.combat_actionsleft = 0
self.location.msg_contents("%s is Paralyzed, and can't act this turn!" % self)
self.location.msg_contents(
"%s is Paralyzed, and can't act this turn!" % self
)
self.db.combat_turnhandler.turn_end_check(self)
def at_update(self):
@ -671,7 +689,9 @@ class TBItemsTurnHandler(DefaultScript):
self.db.fighters = ordered_by_roll
# Announce the turn order.
self.obj.msg_contents("Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters))
self.obj.msg_contents(
"Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters)
)
# Start first fighter's turn.
self.start_turn(self.db.fighters[0])
@ -686,7 +706,9 @@ class TBItemsTurnHandler(DefaultScript):
"""
for fighter in self.db.fighters:
combat_cleanup(fighter) # Clean up the combat attributes for every fighter.
self.obj.db.combat_turnhandler = None # Remove reference to turn handler in location
self.obj.db.combat_turnhandler = (
None
) # Remove reference to turn handler in location
def at_repeat(self):
"""
@ -704,7 +726,9 @@ class TBItemsTurnHandler(DefaultScript):
currentchar, "all", action_name="disengage"
) # Spend all remaining actions.
return
elif self.db.timer <= 10 and not self.db.timeout_warning_given: # 10 seconds left
elif (
self.db.timer <= 10 and not self.db.timeout_warning_given
): # 10 seconds left
# Warn the current character if they're about to time out.
currentchar.msg("WARNING: About to time out!")
self.db.timeout_warning_given = True
@ -716,7 +740,9 @@ class TBItemsTurnHandler(DefaultScript):
Args:
character (obj): Character to initialize for combat.
"""
combat_cleanup(character) # Clean up leftover combat attributes beforehand, just in case.
combat_cleanup(
character
) # Clean up leftover combat attributes beforehand, just in case.
character.db.combat_actionsleft = (
0
) # Actions remaining - start of turn adds to this, turn ends when it reaches 0
@ -765,13 +791,17 @@ class TBItemsTurnHandler(DefaultScript):
defeated_characters = 0
for fighter in self.db.fighters:
if fighter.db.HP == 0:
defeated_characters += 1 # Add 1 for every fighter with 0 HP left (defeated)
defeated_characters += (
1
) # Add 1 for every fighter with 0 HP left (defeated)
if defeated_characters == (
len(self.db.fighters) - 1
): # If only one character isn't defeated
for fighter in self.db.fighters:
if fighter.db.HP != 0:
LastStanding = fighter # Pick the one fighter left with HP remaining
LastStanding = (
fighter
) # Pick the one fighter left with HP remaining
self.obj.msg_contents("Only %s remains! Combat is over!" % LastStanding)
self.stop() # Stop this script and end combat.
return
@ -780,13 +810,17 @@ class TBItemsTurnHandler(DefaultScript):
currentchar = self.db.fighters[self.db.turn]
self.db.turn += 1 # Go to the next in the turn order.
if self.db.turn > len(self.db.fighters) - 1:
self.db.turn = 0 # Go back to the first in the turn order once you reach the end.
self.db.turn = (
0
) # Go back to the first in the turn order once you reach the end.
newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning.
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
self.obj.msg_contents(
"%s's turn ends - %s's turn begins!" % (currentchar, newchar)
)
self.start_turn(newchar) # Start the new character's turn.
# Count down condition timers.
@ -854,7 +888,9 @@ class CmdFight(Command):
if is_in_combat(self.caller): # Already in a fight
self.caller.msg("You're already in a fight!")
return
for thing in here.contents: # Test everything in the room to add it to the fight.
for (
thing
) in here.contents: # Test everything in the room to add it to the fight.
if thing.db.HP: # If the object has HP...
fighters.append(thing) # ...then add it to the fight.
if len(fighters) <= 1: # If you're the only able fighter in the room
@ -953,7 +989,9 @@ 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.
spend_action(
self.caller, "all", action_name="pass"
) # Spend all remaining actions.
class CmdDisengage(Command):
@ -984,8 +1022,12 @@ class CmdDisengage(Command):
self.caller.msg("You can only do that on your turn.")
return
self.caller.location.msg_contents("%s disengages, ready to stop fighting." % self.caller)
spend_action(self.caller, "all", action_name="disengage") # Spend all remaining actions.
self.caller.location.msg_contents(
"%s disengages, ready to stop fighting." % self.caller
)
spend_action(
self.caller, "all", action_name="disengage"
) # Spend all remaining actions.
"""
The action_name kwarg sets the character's last action to "disengage", which is checked by
the turn handler script to see if all fighters have disengaged.
@ -1037,7 +1079,9 @@ class CmdCombatHelp(CmdHelp):
# tips on combat when used in a fight with no arguments.
def func(self):
if is_in_combat(self.caller) and not self.args: # In combat and entered 'help' alone
if (
is_in_combat(self.caller) and not self.args
): # In combat and entered 'help' alone
self.caller.msg(
"Available combat commands:|/"
+ "|wAttack:|n Attack a target, attempting to deal damage.|/"
@ -1175,7 +1219,9 @@ def itemfunc_heal(item, user, target, **kwargs):
to_heal = target.db.max_hp - target.db.hp # Cap healing to max HP
target.db.hp += to_heal
user.location.msg_contents("%s uses %s! %s regains %i HP!" % (user, item, target, to_heal))
user.location.msg_contents(
"%s uses %s! %s regains %i HP!" % (user, item, target, to_heal)
)
def itemfunc_add_condition(item, user, target, **kwargs):
@ -1235,7 +1281,10 @@ def itemfunc_cure_condition(item, user, target, **kwargs):
for key in target.db.conditions:
if key in to_cure:
# If condition specified in to_cure, remove it.
item_msg += "%s no longer has the '%s' condition. " % (str(target), str(key))
item_msg += "%s no longer has the '%s' condition. " % (
str(target),
str(key),
)
del target.db.conditions[key]
user.location.msg_contents(item_msg)
@ -1261,7 +1310,9 @@ def itemfunc_attack(item, user, target, **kwargs):
return False # Returning false aborts the item use
if not target:
user.msg("You have to specify a target to use %s! (use <item> = <target>)" % item)
user.msg(
"You have to specify a target to use %s! (use <item> = <target>)" % item
)
return False
if target == user:
@ -1445,7 +1496,9 @@ AMULET_OF_MIGHT = {
"desc": "The one who holds this amulet can call upon its power to gain great strength.",
"item_func": "add_condition",
"item_selfonly": True,
"item_kwargs": {"conditions": [("Damage Up", 3), ("Accuracy Up", 3), ("Defense Up", 3)]},
"item_kwargs": {
"conditions": [("Damage Up", 3), ("Accuracy Up", 3), ("Defense Up", 3)]
},
}
AMULET_OF_WEAKNESS = {
@ -1453,5 +1506,7 @@ AMULET_OF_WEAKNESS = {
"desc": "The one who holds this amulet can call upon its power to gain great weakness. It's not a terribly useful artifact.",
"item_func": "add_condition",
"item_selfonly": True,
"item_kwargs": {"conditions": [("Damage Down", 3), ("Accuracy Down", 3), ("Defense Down", 3)]},
"item_kwargs": {
"conditions": [("Damage Down", 3), ("Accuracy Down", 3), ("Defense Down", 3)]
},
}

View file

@ -61,7 +61,13 @@ in your game and using it as-is.
"""
from random import randint
from evennia import DefaultCharacter, Command, default_cmds, DefaultScript, create_object
from evennia import (
DefaultCharacter,
Command,
default_cmds,
DefaultScript,
create_object,
)
from evennia.commands.default.muxcommand import MuxCommand
from evennia.commands.default.help import CmdHelp
@ -312,7 +318,9 @@ def spend_action(character, actions, action_name=None):
character.db.combat_actionsleft -= actions # Use up actions.
if character.db.combat_actionsleft < 0:
character.db.combat_actionsleft = 0 # Can't have fewer than 0 actions
character.db.combat_turnhandler.turn_end_check(character) # Signal potential end of turn.
character.db.combat_turnhandler.turn_end_check(
character
) # Signal potential end of turn.
"""
@ -417,7 +425,9 @@ class TBMagicTurnHandler(DefaultScript):
self.db.fighters = ordered_by_roll
# Announce the turn order.
self.obj.msg_contents("Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters))
self.obj.msg_contents(
"Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters)
)
# Start first fighter's turn.
self.start_turn(self.db.fighters[0])
@ -432,7 +442,9 @@ class TBMagicTurnHandler(DefaultScript):
"""
for fighter in self.db.fighters:
combat_cleanup(fighter) # Clean up the combat attributes for every fighter.
self.obj.db.combat_turnhandler = None # Remove reference to turn handler in location
self.obj.db.combat_turnhandler = (
None
) # Remove reference to turn handler in location
def at_repeat(self):
"""
@ -450,7 +462,9 @@ class TBMagicTurnHandler(DefaultScript):
currentchar, "all", action_name="disengage"
) # Spend all remaining actions.
return
elif self.db.timer <= 10 and not self.db.timeout_warning_given: # 10 seconds left
elif (
self.db.timer <= 10 and not self.db.timeout_warning_given
): # 10 seconds left
# Warn the current character if they're about to time out.
currentchar.msg("WARNING: About to time out!")
self.db.timeout_warning_given = True
@ -462,7 +476,9 @@ class TBMagicTurnHandler(DefaultScript):
Args:
character (obj): Character to initialize for combat.
"""
combat_cleanup(character) # Clean up leftover combat attributes beforehand, just in case.
combat_cleanup(
character
) # Clean up leftover combat attributes beforehand, just in case.
character.db.combat_actionsleft = (
0
) # Actions remaining - start of turn adds to this, turn ends when it reaches 0
@ -511,13 +527,17 @@ class TBMagicTurnHandler(DefaultScript):
defeated_characters = 0
for fighter in self.db.fighters:
if fighter.db.HP == 0:
defeated_characters += 1 # Add 1 for every fighter with 0 HP left (defeated)
defeated_characters += (
1
) # Add 1 for every fighter with 0 HP left (defeated)
if defeated_characters == (
len(self.db.fighters) - 1
): # If only one character isn't defeated
for fighter in self.db.fighters:
if fighter.db.HP != 0:
LastStanding = fighter # Pick the one fighter left with HP remaining
LastStanding = (
fighter
) # Pick the one fighter left with HP remaining
self.obj.msg_contents("Only %s remains! Combat is over!" % LastStanding)
self.stop() # Stop this script and end combat.
return
@ -526,11 +546,15 @@ class TBMagicTurnHandler(DefaultScript):
currentchar = self.db.fighters[self.db.turn]
self.db.turn += 1 # Go to the next in the turn order.
if self.db.turn > len(self.db.fighters) - 1:
self.db.turn = 0 # Go back to the first in the turn order once you reach the end.
self.db.turn = (
0
) # Go back to the first in the turn order once you reach the end.
newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning.
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
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):
@ -594,7 +618,9 @@ class CmdFight(Command):
if is_in_combat(self.caller): # Already in a fight
self.caller.msg("You're already in a fight!")
return
for thing in here.contents: # Test everything in the room to add it to the fight.
for (
thing
) in here.contents: # Test everything in the room to add it to the fight.
if thing.db.HP: # If the object has HP...
fighters.append(thing) # ...then add it to the fight.
if len(fighters) <= 1: # If you're the only able fighter in the room
@ -689,7 +715,9 @@ 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.
spend_action(
self.caller, "all", action_name="pass"
) # Spend all remaining actions.
class CmdDisengage(Command):
@ -720,8 +748,12 @@ class CmdDisengage(Command):
self.caller.msg("You can only do that on your turn.")
return
self.caller.location.msg_contents("%s disengages, ready to stop fighting." % self.caller)
spend_action(self.caller, "all", action_name="disengage") # Spend all remaining actions.
self.caller.location.msg_contents(
"%s disengages, ready to stop fighting." % self.caller
)
spend_action(
self.caller, "all", action_name="disengage"
) # Spend all remaining actions.
"""
The action_name kwarg sets the character's last action to "disengage", which is checked by
the turn handler script to see if all fighters have disengaged.
@ -786,11 +818,17 @@ class CmdLearnSpell(Command):
if len(spell_to_learn) == 1: # If one match, extract the string
spell_to_learn = spell_to_learn[0]
if spell_to_learn not in self.caller.db.spells_known: # If the spell isn't known...
caller.db.spells_known.append(spell_to_learn) # ...then add the spell to the character
if (
spell_to_learn not in self.caller.db.spells_known
): # If the spell isn't known...
caller.db.spells_known.append(
spell_to_learn
) # ...then add the spell to the character
caller.msg("You learn the spell '%s'!" % spell_to_learn)
return
if spell_to_learn in self.caller.db.spells_known: # Already has the spell specified
if (
spell_to_learn in self.caller.db.spells_known
): # Already has the spell specified
caller.msg("You already know the spell '%s'!" % spell_to_learn)
"""
You will almost definitely want to replace this with your own system
@ -908,7 +946,9 @@ class CmdCast(MuxCommand):
# If not in combat and the spell isn't a non-combat spell, error ms and return.
if spelldata["noncombat_spell"] == False and is_in_combat(caller) == False:
caller.msg("You can't use the spell '%s' outside of combat." % spell_to_cast)
caller.msg(
"You can't use the spell '%s' outside of combat." % spell_to_cast
)
return
# If spell takes no targets and one is given, give error message and return
@ -1014,7 +1054,9 @@ class CmdRest(Command):
self.caller.db.hp = self.caller.db.max_hp # Set current HP to maximum
self.caller.db.mp = self.caller.db.max_mp # Set current MP to maximum
self.caller.location.msg_contents("%s rests to recover HP and MP." % self.caller)
self.caller.location.msg_contents(
"%s rests to recover HP and MP." % self.caller
)
# You'll probably want to replace this with your own system for recovering HP and MP.
@ -1066,7 +1108,9 @@ class CmdCombatHelp(CmdHelp):
# tips on combat when used in a fight with no arguments.
def func(self):
if is_in_combat(self.caller) and not self.args: # In combat and entered 'help' alone
if (
is_in_combat(self.caller) and not self.args
): # In combat and entered 'help' alone
self.caller.msg(
"Available combat commands:|/"
+ "|wAttack:|n Attack a target, attempting to deal damage.|/"

View file

@ -101,7 +101,13 @@ in your game and using it as-is.
"""
from random import randint
from evennia import DefaultCharacter, DefaultObject, Command, default_cmds, DefaultScript
from evennia import (
DefaultCharacter,
DefaultObject,
Command,
default_cmds,
DefaultScript,
)
from evennia.commands.default.help import CmdHelp
"""
@ -259,7 +265,9 @@ def at_defeat(defeated):
defeated.location.msg_contents("%s has been defeated!" % defeated)
def resolve_attack(attacker, defender, attack_type, attack_value=None, defense_value=None):
def resolve_attack(
attacker, defender, attack_type, attack_value=None, defense_value=None
):
"""
Resolves an attack and outputs the result.
@ -482,7 +490,9 @@ def spend_action(character, actions, action_name=None):
character.db.combat_actionsleft -= actions # Use up actions.
if character.db.combat_actionsleft < 0:
character.db.combat_actionsleft = 0 # Can't have fewer than 0 actions
character.db.combat_turnhandler.turn_end_check(character) # Signal potential end of turn.
character.db.combat_turnhandler.turn_end_check(
character
) # Signal potential end of turn.
def combat_status_message(fighter):
@ -515,7 +525,9 @@ def combat_status_message(fighter):
range_obj.append(thing)
if engaged_obj:
status_msg += "|/Engaged targets: %s" % ", ".join(obj.key for obj in engaged_obj)
status_msg += "|/Engaged targets: %s" % ", ".join(
obj.key for obj in engaged_obj
)
if reach_obj:
status_msg += "|/Reach targets: %s" % ", ".join(obj.key for obj in reach_obj)
if range_obj:
@ -574,7 +586,9 @@ class TBRangeTurnHandler(DefaultScript):
self.db.fighters = ordered_by_roll
# Announce the turn order.
self.obj.msg_contents("Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters))
self.obj.msg_contents(
"Turn order is: %s " % ", ".join(obj.key for obj in self.db.fighters)
)
# Start first fighter's turn.
self.start_turn(self.db.fighters[0])
@ -588,8 +602,12 @@ class TBRangeTurnHandler(DefaultScript):
Called at script termination.
"""
for thing in self.obj.contents:
combat_cleanup(thing) # Clean up the combat attributes for every object in the room.
self.obj.db.combat_turnhandler = None # Remove reference to turn handler in location
combat_cleanup(
thing
) # Clean up the combat attributes for every object in the room.
self.obj.db.combat_turnhandler = (
None
) # Remove reference to turn handler in location
def at_repeat(self):
"""
@ -607,7 +625,9 @@ class TBRangeTurnHandler(DefaultScript):
currentchar, "all", action_name="disengage"
) # Spend all remaining actions.
return
elif self.db.timer <= 10 and not self.db.timeout_warning_given: # 10 seconds left
elif (
self.db.timer <= 10 and not self.db.timeout_warning_given
): # 10 seconds left
# Warn the current character if they're about to time out.
currentchar.msg("WARNING: About to time out!")
self.db.timeout_warning_given = True
@ -672,7 +692,9 @@ class TBRangeTurnHandler(DefaultScript):
Args:
character (obj): Character to initialize for combat.
"""
combat_cleanup(character) # Clean up leftover combat attributes beforehand, just in case.
combat_cleanup(
character
) # Clean up leftover combat attributes beforehand, just in case.
character.db.combat_actionsleft = (
0
) # Actions remaining - start of turn adds to this, turn ends when it reaches 0
@ -720,13 +742,17 @@ class TBRangeTurnHandler(DefaultScript):
defeated_characters = 0
for fighter in self.db.fighters:
if fighter.db.HP == 0:
defeated_characters += 1 # Add 1 for every fighter with 0 HP left (defeated)
defeated_characters += (
1
) # Add 1 for every fighter with 0 HP left (defeated)
if defeated_characters == (
len(self.db.fighters) - 1
): # If only one character isn't defeated
for fighter in self.db.fighters:
if fighter.db.HP != 0:
LastStanding = fighter # Pick the one fighter left with HP remaining
LastStanding = (
fighter
) # Pick the one fighter left with HP remaining
self.obj.msg_contents("Only %s remains! Combat is over!" % LastStanding)
self.stop() # Stop this script and end combat.
return
@ -735,11 +761,15 @@ class TBRangeTurnHandler(DefaultScript):
currentchar = self.db.fighters[self.db.turn]
self.db.turn += 1 # Go to the next in the turn order.
if self.db.turn > len(self.db.fighters) - 1:
self.db.turn = 0 # Go back to the first in the turn order once you reach the end.
self.db.turn = (
0
) # Go back to the first in the turn order once you reach the end.
newchar = self.db.fighters[self.db.turn] # Note the new character
self.db.timer = TURN_TIMEOUT + self.time_until_next_repeat() # Reset the timer.
self.db.timeout_warning_given = False # Reset the timeout warning.
self.obj.msg_contents("%s's turn ends - %s's turn begins!" % (currentchar, newchar))
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):
@ -876,7 +906,9 @@ class TBRangeObject(DefaultObject):
if dropper.location.db.combat_turnhandler:
# Object joins the range field
self.db.combat_range = {}
dropper.location.db.combat_turnhandler.join_rangefield(self, anchor_obj=dropper)
dropper.location.db.combat_turnhandler.join_rangefield(
self, anchor_obj=dropper
)
def at_before_get(self, getter):
"""
@ -958,7 +990,8 @@ class TBRangeObject(DefaultObject):
return False
if get_range(giver, getter) > 0: # Too far away from target
giver.msg(
"You aren't close enough to give things to %s! (see: help approach)" % getter
"You aren't close enough to give things to %s! (see: help approach)"
% getter
)
return False
return True
@ -1019,7 +1052,9 @@ class CmdFight(Command):
if is_in_combat(self.caller): # Already in a fight
self.caller.msg("You're already in a fight!")
return
for thing in here.contents: # Test everything in the room to add it to the fight.
for (
thing
) in here.contents: # Test everything in the room to add it to the fight.
if thing.db.HP: # If the object has HP...
fighters.append(thing) # ...then add it to the fight.
if len(fighters) <= 1: # If you're the only able fighter in the room
@ -1144,7 +1179,11 @@ class CmdShoot(Command):
in_melee = []
for target in attacker.db.combat_range:
# Object is engaged and has HP
if get_range(attacker, defender) == 0 and target.db.hp and target != self.caller:
if (
get_range(attacker, defender) == 0
and target.db.hp
and target != self.caller
):
in_melee.append(target) # Add to list of targets in melee
if len(in_melee) > 0:
@ -1294,7 +1333,9 @@ 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.
spend_action(
self.caller, "all", action_name="pass"
) # Spend all remaining actions.
class CmdDisengage(Command):
@ -1325,8 +1366,12 @@ class CmdDisengage(Command):
self.caller.msg("You can only do that on your turn.")
return
self.caller.location.msg_contents("%s disengages, ready to stop fighting." % self.caller)
spend_action(self.caller, "all", action_name="disengage") # Spend all remaining actions.
self.caller.location.msg_contents(
"%s disengages, ready to stop fighting." % self.caller
)
spend_action(
self.caller, "all", action_name="disengage"
) # Spend all remaining actions.
"""
The action_name kwarg sets the character's last action to "disengage", which is checked by
the turn handler script to see if all fighters have disengaged.
@ -1397,7 +1442,9 @@ class CmdCombatHelp(CmdHelp):
# tips on combat when used in a fight with no arguments.
def func(self):
if is_in_combat(self.caller) and not self.args: # In combat and entered 'help' alone
if (
is_in_combat(self.caller) and not self.args
): # In combat and entered 'help' alone
self.caller.msg(
"Available combat commands:|/"
+ "|wAttack:|n Attack an engaged target, attempting to deal damage.|/"