Make scripts/objects lists use EvMore. Change EvMore to not justify by default.

This commit is contained in:
Griatch 2020-01-11 15:49:12 +01:00
parent b5aee2c41e
commit 69d85bd184
221 changed files with 2190 additions and 6810 deletions

View file

@ -291,9 +291,7 @@ 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.
"""
@ -396,9 +394,7 @@ 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])
@ -413,9 +409,7 @@ 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):
"""
@ -433,9 +427,7 @@ 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
@ -447,9 +439,7 @@ 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
@ -498,17 +488,13 @@ 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
@ -517,15 +503,11 @@ 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):
@ -589,9 +571,7 @@ 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
@ -686,9 +666,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.
spend_action(self.caller, "all", action_name="pass") # Spend all remaining actions.
class CmdDisengage(Command):
@ -719,12 +697,8 @@ 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.
@ -776,9 +750,7 @@ 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,13 +55,7 @@ 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
"""
@ -276,8 +270,7 @@ 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.
@ -349,9 +342,7 @@ 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.
"""
@ -400,9 +391,7 @@ 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])
@ -417,9 +406,7 @@ 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):
"""
@ -437,9 +424,7 @@ 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
@ -451,9 +436,7 @@ 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
@ -502,17 +485,13 @@ 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
@ -521,15 +500,11 @@ 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):
@ -735,9 +710,7 @@ 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
@ -832,9 +805,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.
spend_action(self.caller, "all", action_name="pass") # Spend all remaining actions.
class CmdDisengage(Command):
@ -865,12 +836,8 @@ 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.
@ -922,9 +889,7 @@ 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.|/"
@ -1015,9 +980,7 @@ 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):
@ -1093,9 +1056,7 @@ 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,9 +360,7 @@ 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):
@ -383,9 +381,7 @@ 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
@ -394,19 +390,13 @@ 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
@ -501,9 +491,7 @@ 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))
"""
@ -589,17 +577,13 @@ 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)
@ -612,9 +596,7 @@ 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):
@ -689,9 +671,7 @@ 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])
@ -706,9 +686,7 @@ 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):
"""
@ -726,9 +704,7 @@ 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
@ -740,9 +716,7 @@ 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
@ -791,17 +765,13 @@ 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
@ -810,17 +780,13 @@ 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.
@ -888,9 +854,7 @@ 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
@ -989,9 +953,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.
spend_action(self.caller, "all", action_name="pass") # Spend all remaining actions.
class CmdDisengage(Command):
@ -1022,12 +984,8 @@ 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.
@ -1079,9 +1037,7 @@ 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.|/"
@ -1219,9 +1175,7 @@ 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):
@ -1281,10 +1235,7 @@ 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)
@ -1310,9 +1261,7 @@ 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:
@ -1496,9 +1445,7 @@ 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 = {
@ -1506,7 +1453,5 @@ 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,13 +61,7 @@ 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
@ -318,9 +312,7 @@ 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.
"""
@ -425,9 +417,7 @@ 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])
@ -442,9 +432,7 @@ 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):
"""
@ -462,9 +450,7 @@ 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
@ -476,9 +462,7 @@ 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
@ -527,17 +511,13 @@ 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
@ -546,15 +526,11 @@ 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):
@ -618,9 +594,7 @@ 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
@ -715,9 +689,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.
spend_action(self.caller, "all", action_name="pass") # Spend all remaining actions.
class CmdDisengage(Command):
@ -748,12 +720,8 @@ 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.
@ -818,17 +786,11 @@ 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
@ -946,9 +908,7 @@ 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
@ -1054,9 +1014,7 @@ 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.
@ -1108,9 +1066,7 @@ 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,13 +101,7 @@ 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
"""
@ -265,9 +259,7 @@ 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.
@ -490,9 +482,7 @@ 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):
@ -525,9 +515,7 @@ 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:
@ -586,9 +574,7 @@ 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])
@ -602,12 +588,8 @@ 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):
"""
@ -625,9 +607,7 @@ 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
@ -692,9 +672,7 @@ 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
@ -742,17 +720,13 @@ 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
@ -761,15 +735,11 @@ 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):
@ -906,9 +876,7 @@ 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):
"""
@ -990,8 +958,7 @@ 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
@ -1052,9 +1019,7 @@ 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
@ -1179,11 +1144,7 @@ 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:
@ -1333,9 +1294,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.
spend_action(self.caller, "all", action_name="pass") # Spend all remaining actions.
class CmdDisengage(Command):
@ -1366,12 +1325,8 @@ 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.
@ -1442,9 +1397,7 @@ 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.|/"