Working on turnbased combat
This commit is contained in:
parent
b79421f624
commit
ea7a3c83d7
5 changed files with 40 additions and 16 deletions
|
|
@ -1428,6 +1428,7 @@ class CmdOpen(ObjManipCommand):
|
||||||
help_category = "Building"
|
help_category = "Building"
|
||||||
|
|
||||||
new_obj_lockstring = "control:id({id}) or perm(Admin);delete:id({id}) or perm(Admin)"
|
new_obj_lockstring = "control:id({id}) or perm(Admin);delete:id({id}) or perm(Admin)"
|
||||||
|
|
||||||
# a custom member method to chug out exits and do checks
|
# a custom member method to chug out exits and do checks
|
||||||
def create_exit(self, exit_name, location, destination, exit_aliases=None, typeclass=None):
|
def create_exit(self, exit_name, location, destination, exit_aliases=None, typeclass=None):
|
||||||
"""
|
"""
|
||||||
|
|
@ -2054,7 +2055,6 @@ class CmdTypeclass(COMMAND_DEFAULT_CLASS):
|
||||||
help_category = "Building"
|
help_category = "Building"
|
||||||
|
|
||||||
def _generic_search(self, query, typeclass_path):
|
def _generic_search(self, query, typeclass_path):
|
||||||
|
|
||||||
caller = self.caller
|
caller = self.caller
|
||||||
if typeclass_path:
|
if typeclass_path:
|
||||||
# make sure we search the right database table
|
# make sure we search the right database table
|
||||||
|
|
@ -3267,7 +3267,6 @@ class ScriptEvMore(EvMore):
|
||||||
)
|
)
|
||||||
|
|
||||||
for script in scripts:
|
for script in scripts:
|
||||||
|
|
||||||
nextrep = script.time_until_next_repeat()
|
nextrep = script.time_until_next_repeat()
|
||||||
if nextrep is None:
|
if nextrep is None:
|
||||||
nextrep = script.db._paused_time
|
nextrep = script.db._paused_time
|
||||||
|
|
@ -3738,7 +3737,6 @@ class CmdTeleport(COMMAND_DEFAULT_CLASS):
|
||||||
use_destination="intoexit" not in self.switches,
|
use_destination="intoexit" not in self.switches,
|
||||||
move_type="teleport",
|
move_type="teleport",
|
||||||
):
|
):
|
||||||
|
|
||||||
if obj_to_teleport == caller:
|
if obj_to_teleport == caller:
|
||||||
caller.msg(f"Teleported to {destination}.")
|
caller.msg(f"Teleported to {destination}.")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
#
|
#
|
||||||
# Sets up a combat area for testing twitch combat. Requires developer or superuser perm.
|
# Sets up a combat area for testing twitch combat. Requires developer or superuser perm.
|
||||||
#
|
#
|
||||||
# Run from in-game as batchcmd evadventure.batchscripts.combat_demo
|
# To use, first add the batchscripts/ folder to your settings file:
|
||||||
|
#
|
||||||
|
# BASE_BATCH_PROCESS_PATHS += ["evadventure.batchscripts"]
|
||||||
|
#
|
||||||
|
# Run from in-game as batchcmd combat_demo
|
||||||
#
|
#
|
||||||
|
|
||||||
# start from limbo
|
# start from limbo
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,11 @@
|
||||||
#
|
#
|
||||||
# Sets up a combat area for testing turnbased combat.
|
# Sets up a combat area for testing turnbased combat.
|
||||||
#
|
#
|
||||||
# Run from in-game as `batchcode evadventure.batchscripts.combat_demo`
|
# First add mygame/server/conf/settings.py:
|
||||||
|
#
|
||||||
|
# BASE_BATCH_PROCESS_PATHS += ["evadventure.batchscripts"]
|
||||||
|
#
|
||||||
|
# Run from in-game as `batchcode combat_demo`
|
||||||
#
|
#
|
||||||
|
|
||||||
# HEADER
|
# HEADER
|
||||||
|
|
@ -17,7 +21,7 @@ from evennia.contrib.tutorials.evadventure.rooms import EvAdventureRoom
|
||||||
|
|
||||||
# Make the player an EvAdventureCharacter
|
# Make the player an EvAdventureCharacter
|
||||||
player = caller # caller is injected by the batchcode runner, it's the one running this script
|
player = caller # caller is injected by the batchcode runner, it's the one running this script
|
||||||
player.swap_typeclass(EvAdventureCharacter, clean_attributes=True)
|
player.swap_typeclass(EvAdventureCharacter)
|
||||||
|
|
||||||
# add the Turnbased cmdset
|
# add the Turnbased cmdset
|
||||||
player.cmdset.add(TurnCombatCmdSet, persistent=True)
|
player.cmdset.add(TurnCombatCmdSet, persistent=True)
|
||||||
|
|
|
||||||
|
|
@ -387,16 +387,30 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
|
||||||
# -----------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
def _get_combathandler(caller):
|
def _get_combathandler(caller, turn_timeout=30, flee_time=3, combathandler_key="combathandler"):
|
||||||
turn_length = 30
|
"""
|
||||||
flee_timeout = 3
|
Get the combat handler for the caller's location. If it doesn't exist, create it.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
caller (EvAdventureCharacter or EvAdventureNPC): The character/NPC to get the
|
||||||
|
combat handler for.
|
||||||
|
turn_timeout (int): After this time, the turn will roll around.
|
||||||
|
flee_time (int): How many turns it takes to flee.
|
||||||
|
|
||||||
|
"""
|
||||||
return EvAdventureTurnbasedCombatHandler.get_or_create_combathandler(
|
return EvAdventureTurnbasedCombatHandler.get_or_create_combathandler(
|
||||||
caller.location,
|
caller.location,
|
||||||
attributes=[("turn_length", turn_length), ("flee_timeout", flee_timeout)],
|
interval=turn_timeout,
|
||||||
|
attributes=[("flee_time", flee_time)],
|
||||||
|
combathandler_key=combathandler_key,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _queue_action(caller, raw_string, **kwargs):
|
def _queue_action(caller, raw_string, **kwargs):
|
||||||
|
"""
|
||||||
|
Goto-function that queue the action with the CombatHandler. This always returns
|
||||||
|
to the top-level combat menu "node_combat"
|
||||||
|
"""
|
||||||
action_dict = kwargs["action_dict"]
|
action_dict = kwargs["action_dict"]
|
||||||
_get_combathandler(caller).queue_action(caller, action_dict)
|
_get_combathandler(caller).queue_action(caller, action_dict)
|
||||||
return "node_combat"
|
return "node_combat"
|
||||||
|
|
@ -707,6 +721,9 @@ class CmdTurnAttack(Command):
|
||||||
key = "attack"
|
key = "attack"
|
||||||
aliases = ["hit", "turnbased combat"]
|
aliases = ["hit", "turnbased combat"]
|
||||||
|
|
||||||
|
turn_timeout = 30 # seconds
|
||||||
|
flee_time = 3 # rounds
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
super().parse()
|
super().parse()
|
||||||
self.args = self.args.strip()
|
self.args = self.args.strip()
|
||||||
|
|
@ -731,14 +748,13 @@ class CmdTurnAttack(Command):
|
||||||
self.msg("PvP combat is not allowed here!")
|
self.msg("PvP combat is not allowed here!")
|
||||||
return
|
return
|
||||||
|
|
||||||
combathandler = EvAdventureTurnbasedCombatHandler.get_or_create_combathandler(
|
combathandler = _get_combathandler(self.caller, self.turn_timeout, self.flee_time)
|
||||||
self.caller.location
|
|
||||||
)
|
|
||||||
|
|
||||||
# add combatants to combathandler. this can be done safely over and over
|
# add combatants to combathandler. this can be done safely over and over
|
||||||
combathandler.add_combatant(self.caller)
|
combathandler.add_combatant(self.caller)
|
||||||
combathandler.queue_action(self.caller, {"key": "attack", "target": target})
|
combathandler.queue_action(self.caller, {"key": "attack", "target": target})
|
||||||
combathandler.add_combatant(target)
|
combathandler.add_combatant(target)
|
||||||
|
target.msg("|rYou are attacked by {self.caller.get_display_name(self.caller)}!|n")
|
||||||
combathandler.start_combat()
|
combathandler.start_combat()
|
||||||
|
|
||||||
# build and start the menu
|
# build and start the menu
|
||||||
|
|
@ -753,7 +769,7 @@ class CmdTurnAttack(Command):
|
||||||
"node_combat": node_combat,
|
"node_combat": node_combat,
|
||||||
},
|
},
|
||||||
startnode="node_combat",
|
startnode="node_combat",
|
||||||
combathandler=self.combathandler,
|
combathandler=combathandler,
|
||||||
# cmdset_mergetype="Union",
|
# cmdset_mergetype="Union",
|
||||||
persistent=True,
|
persistent=True,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -287,7 +287,7 @@ class _BaseTwitchCombatCommand(Command):
|
||||||
rhs = " ".join(rhs)
|
rhs = " ".join(rhs)
|
||||||
self.lhs, self.rhs = lhs.strip(), rhs.strip()
|
self.lhs, self.rhs = lhs.strip(), rhs.strip()
|
||||||
|
|
||||||
def get_or_create_combathandler(self, target=None, combathandler_name="combathandler"):
|
def get_or_create_combathandler(self, target=None, combathandler_key="combathandler"):
|
||||||
"""
|
"""
|
||||||
Get or create the combathandler assigned to this combatant.
|
Get or create the combathandler assigned to this combatant.
|
||||||
|
|
||||||
|
|
@ -298,7 +298,9 @@ class _BaseTwitchCombatCommand(Command):
|
||||||
self.msg("You can't attack that!")
|
self.msg("You can't attack that!")
|
||||||
raise InterruptCommand()
|
raise InterruptCommand()
|
||||||
|
|
||||||
EvAdventureCombatTwitchHandler.get_or_create_combathandler(target)
|
EvAdventureCombatTwitchHandler.get_or_create_combathandler(
|
||||||
|
target, combathandler_key=combathandler_key
|
||||||
|
)
|
||||||
return EvAdventureCombatTwitchHandler.get_or_create_combathandler(self.caller)
|
return EvAdventureCombatTwitchHandler.get_or_create_combathandler(self.caller)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue