Working on turnbased combat

This commit is contained in:
Griatch 2023-05-11 20:29:45 +02:00
parent b79421f624
commit ea7a3c83d7
5 changed files with 40 additions and 16 deletions

View file

@ -1428,6 +1428,7 @@ class CmdOpen(ObjManipCommand):
help_category = "Building"
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
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"
def _generic_search(self, query, typeclass_path):
caller = self.caller
if typeclass_path:
# make sure we search the right database table
@ -3267,7 +3267,6 @@ class ScriptEvMore(EvMore):
)
for script in scripts:
nextrep = script.time_until_next_repeat()
if nextrep is None:
nextrep = script.db._paused_time
@ -3738,7 +3737,6 @@ class CmdTeleport(COMMAND_DEFAULT_CLASS):
use_destination="intoexit" not in self.switches,
move_type="teleport",
):
if obj_to_teleport == caller:
caller.msg(f"Teleported to {destination}.")
else:

View file

@ -2,7 +2,11 @@
#
# 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

View file

@ -2,7 +2,11 @@
#
# 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
@ -17,7 +21,7 @@ from evennia.contrib.tutorials.evadventure.rooms import EvAdventureRoom
# Make the player an EvAdventureCharacter
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
player.cmdset.add(TurnCombatCmdSet, persistent=True)

View file

@ -387,16 +387,30 @@ class EvAdventureTurnbasedCombatHandler(EvAdventureCombatBaseHandler):
# -----------------------------------------------------------------------------------
def _get_combathandler(caller):
turn_length = 30
flee_timeout = 3
def _get_combathandler(caller, turn_timeout=30, flee_time=3, combathandler_key="combathandler"):
"""
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(
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):
"""
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"]
_get_combathandler(caller).queue_action(caller, action_dict)
return "node_combat"
@ -707,6 +721,9 @@ class CmdTurnAttack(Command):
key = "attack"
aliases = ["hit", "turnbased combat"]
turn_timeout = 30 # seconds
flee_time = 3 # rounds
def parse(self):
super().parse()
self.args = self.args.strip()
@ -731,14 +748,13 @@ class CmdTurnAttack(Command):
self.msg("PvP combat is not allowed here!")
return
combathandler = EvAdventureTurnbasedCombatHandler.get_or_create_combathandler(
self.caller.location
)
combathandler = _get_combathandler(self.caller, self.turn_timeout, self.flee_time)
# add combatants to combathandler. this can be done safely over and over
combathandler.add_combatant(self.caller)
combathandler.queue_action(self.caller, {"key": "attack", "target": target})
combathandler.add_combatant(target)
target.msg("|rYou are attacked by {self.caller.get_display_name(self.caller)}!|n")
combathandler.start_combat()
# build and start the menu
@ -753,7 +769,7 @@ class CmdTurnAttack(Command):
"node_combat": node_combat,
},
startnode="node_combat",
combathandler=self.combathandler,
combathandler=combathandler,
# cmdset_mergetype="Union",
persistent=True,
)

View file

@ -287,7 +287,7 @@ class _BaseTwitchCombatCommand(Command):
rhs = " ".join(rhs)
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.
@ -298,7 +298,9 @@ class _BaseTwitchCombatCommand(Command):
self.msg("You can't attack that!")
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)