More fixes for turnbased evadventure combat.
This commit is contained in:
parent
49bc60f52d
commit
6a4f293ab9
2 changed files with 84 additions and 26 deletions
|
|
@ -436,13 +436,13 @@ class EvAdventureCombatHandler(DefaultScript):
|
||||||
}
|
}
|
||||||
|
|
||||||
# how many actions can be queued at a time (per combatant)
|
# how many actions can be queued at a time (per combatant)
|
||||||
max_action_queue_size = 1
|
max_action_queue_size = AttributeProperty(1, autocreate=False)
|
||||||
|
|
||||||
# fallback action if not selecting anything
|
|
||||||
fallback_action_dict = {"key": "hold"}
|
|
||||||
|
|
||||||
# how many turns you must be fleeing before escaping
|
# how many turns you must be fleeing before escaping
|
||||||
flee_timeout = 5
|
flee_timeout = AttributeProperty(3, autocreate=False)
|
||||||
|
|
||||||
|
# fallback action if not selecting anything
|
||||||
|
fallback_action_dict = AttributeProperty({"key": "hold"}, autocreate=False)
|
||||||
|
|
||||||
# persistent storage
|
# persistent storage
|
||||||
|
|
||||||
|
|
@ -522,6 +522,8 @@ class EvAdventureCombatHandler(DefaultScript):
|
||||||
# clean up twitch cmdset if it exists
|
# clean up twitch cmdset if it exists
|
||||||
combatant.cmdset.remove(TwitchCombatCmdSet)
|
combatant.cmdset.remove(TwitchCombatCmdSet)
|
||||||
# clean up menu if it exists
|
# clean up menu if it exists
|
||||||
|
if combatant.ndb._evmenu:
|
||||||
|
combatant.ndb._evmenu.close_menu()
|
||||||
|
|
||||||
def start_combat(self, **kwargs):
|
def start_combat(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
@ -778,7 +780,9 @@ class EvAdventureCombatHandler(DefaultScript):
|
||||||
self.execute_full_turn()
|
self.execute_full_turn()
|
||||||
|
|
||||||
|
|
||||||
def get_or_create_combathandler(location, combat_tick=3, combathandler_name="combathandler"):
|
def get_or_create_combathandler(
|
||||||
|
location, combat_tick=3, flee_timeout=5, combathandler_name="combathandler"
|
||||||
|
):
|
||||||
"""
|
"""
|
||||||
Joins or continues combat. This is a access function that will either get the
|
Joins or continues combat. This is a access function that will either get the
|
||||||
combathandler on the current room or create a new one.
|
combathandler on the current room or create a new one.
|
||||||
|
|
@ -811,6 +815,9 @@ def get_or_create_combathandler(location, combat_tick=3, combathandler_name="com
|
||||||
persistent=True,
|
persistent=True,
|
||||||
autostart=False,
|
autostart=False,
|
||||||
)
|
)
|
||||||
|
if combathandler.flee_timeout != flee_timeout:
|
||||||
|
combathandler.flee_timeout = flee_timeout
|
||||||
|
|
||||||
return combathandler
|
return combathandler
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -859,7 +866,9 @@ class _CmdCombatBase(Command):
|
||||||
combathandler = getattr(self, "_combathandler", None)
|
combathandler = getattr(self, "_combathandler", None)
|
||||||
if not combathandler:
|
if not combathandler:
|
||||||
self._combathandler = combathandler = get_or_create_combathandler(
|
self._combathandler = combathandler = get_or_create_combathandler(
|
||||||
self.caller.location, combat_tick=self.combat_tick
|
self.caller.location,
|
||||||
|
combat_tick=self.combat_tick,
|
||||||
|
flee_timeout=self.flee_timeout,
|
||||||
)
|
)
|
||||||
return combathandler
|
return combathandler
|
||||||
|
|
||||||
|
|
@ -1241,9 +1250,10 @@ def _step_wizard(caller, raw_string, **kwargs):
|
||||||
E.g. Stunt boost -> Choose ability to boost -> Choose recipient -> Choose target -> queue
|
E.g. Stunt boost -> Choose ability to boost -> Choose recipient -> Choose target -> queue
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
caller.msg(f"_step_wizard kwargs: {kwargs}")
|
||||||
steps = kwargs.get("steps", [])
|
steps = kwargs.get("steps", [])
|
||||||
nsteps = len(steps)
|
nsteps = len(steps)
|
||||||
istep = kwargs.get("istep", 0)
|
istep = kwargs.get("istep", -1)
|
||||||
# one of abort, back, forward
|
# one of abort, back, forward
|
||||||
step_direction = kwargs.get("step", "forward")
|
step_direction = kwargs.get("step", "forward")
|
||||||
|
|
||||||
|
|
@ -1255,16 +1265,16 @@ def _step_wizard(caller, raw_string, **kwargs):
|
||||||
# step back in wizard
|
# step back in wizard
|
||||||
if istep <= 0:
|
if istep <= 0:
|
||||||
return "node_combat"
|
return "node_combat"
|
||||||
istep = kwargs["istep"] = max(0, istep - 1)
|
istep = kwargs["istep"] = istep - 1
|
||||||
return steps[istep], kwargs
|
return steps[istep], kwargs
|
||||||
case _:
|
case _:
|
||||||
# forward (default)
|
# forward (default)
|
||||||
if istep >= nsteps:
|
if istep >= nsteps - 1:
|
||||||
# we are already at end of wizard - queue action!
|
# we are already at end of wizard - queue action!
|
||||||
return _queue_action(caller, raw_string, **kwargs)
|
return _queue_action(caller, raw_string, **kwargs)
|
||||||
else:
|
else:
|
||||||
# step forward
|
# step forward
|
||||||
istep = kwargs["istep"] = min(nsteps - 1, istep + 1)
|
istep = kwargs["istep"] = istep + 1
|
||||||
return steps[istep], kwargs
|
return steps[istep], kwargs
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1285,7 +1295,7 @@ def node_choose_enemy_target(caller, raw_string, **kwargs):
|
||||||
"""
|
"""
|
||||||
Choose an enemy as a target for an action
|
Choose an enemy as a target for an action
|
||||||
"""
|
"""
|
||||||
text = "Choose a target."
|
text = "Choose an enemy to target."
|
||||||
action_dict = kwargs["action_dict"]
|
action_dict = kwargs["action_dict"]
|
||||||
|
|
||||||
combathandler = _get_combathandler(caller)
|
combathandler = _get_combathandler(caller)
|
||||||
|
|
@ -1294,7 +1304,10 @@ def node_choose_enemy_target(caller, raw_string, **kwargs):
|
||||||
options = [
|
options = [
|
||||||
{
|
{
|
||||||
"desc": target.get_display_name(caller),
|
"desc": target.get_display_name(caller),
|
||||||
"goto": (_step_wizard, {"action_dict": {**action_dict, **{"target": target}}}),
|
"goto": (
|
||||||
|
_step_wizard,
|
||||||
|
{**kwargs, **{"action_dict": {**action_dict, **{"target": target}}}},
|
||||||
|
),
|
||||||
}
|
}
|
||||||
for target in enemies
|
for target in enemies
|
||||||
]
|
]
|
||||||
|
|
@ -1306,7 +1319,7 @@ def node_choose_allied_target(caller, raw_string, **kwargs):
|
||||||
"""
|
"""
|
||||||
Choose an enemy as a target for an action
|
Choose an enemy as a target for an action
|
||||||
"""
|
"""
|
||||||
text = "Choose a target."
|
text = "Choose an ally to target."
|
||||||
action_dict = kwargs["action_dict"]
|
action_dict = kwargs["action_dict"]
|
||||||
|
|
||||||
combathandler = _get_combathandler(caller)
|
combathandler = _get_combathandler(caller)
|
||||||
|
|
@ -1318,7 +1331,14 @@ def node_choose_allied_target(caller, raw_string, **kwargs):
|
||||||
"desc": "Yourself",
|
"desc": "Yourself",
|
||||||
"goto": (
|
"goto": (
|
||||||
_step_wizard,
|
_step_wizard,
|
||||||
{"action_dict": {**action_dict, **{"target": caller, "recipient": caller}}},
|
{
|
||||||
|
**kwargs,
|
||||||
|
**{
|
||||||
|
"action_dict": {
|
||||||
|
**{**action_dict, **{"target": caller, "recipient": caller}}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
@ -1328,7 +1348,15 @@ def node_choose_allied_target(caller, raw_string, **kwargs):
|
||||||
"desc": target.get_display_name(caller),
|
"desc": target.get_display_name(caller),
|
||||||
"goto": (
|
"goto": (
|
||||||
_step_wizard,
|
_step_wizard,
|
||||||
{"action_dict": {**action_dict, **{"target": target, "recipient": target}}},
|
{
|
||||||
|
**kwargs,
|
||||||
|
**{
|
||||||
|
"action_dict": {
|
||||||
|
**action_dict,
|
||||||
|
**{"target": target, "recipient": target},
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
for target in allies
|
for target in allies
|
||||||
|
|
@ -1350,10 +1378,15 @@ def node_choose_ability(caller, raw_string, **kwargs):
|
||||||
"desc": abi.value,
|
"desc": abi.value,
|
||||||
"goto": (
|
"goto": (
|
||||||
_step_wizard,
|
_step_wizard,
|
||||||
{"action_dict": {**action_dict, **{"stunt_type": abi, "defense_type": abi}}},
|
{
|
||||||
|
**kwargs,
|
||||||
|
**{
|
||||||
|
"action_dict": {**action_dict, **{"stunt_type": abi, "defense_type": abi}},
|
||||||
|
},
|
||||||
|
},
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
for abiname, abi in (
|
for abi in (
|
||||||
Ability.STR,
|
Ability.STR,
|
||||||
Ability.DEX,
|
Ability.DEX,
|
||||||
Ability.CON,
|
Ability.CON,
|
||||||
|
|
@ -1378,10 +1411,13 @@ def node_choose_use_item(caller, raw_string, **kwargs):
|
||||||
options = [
|
options = [
|
||||||
{
|
{
|
||||||
"desc": item.get_display_name(caller),
|
"desc": item.get_display_name(caller),
|
||||||
"goto": (_step_wizard, {**action_dict, **{"item": item}}),
|
"goto": (_step_wizard, {**kwargs, **{**action_dict, **{"item": item}}}),
|
||||||
}
|
}
|
||||||
for item in self.caller.equipment.get_usable_objects_from_backpack()
|
for item in caller.equipment.get_usable_objects_from_backpack()
|
||||||
]
|
]
|
||||||
|
if not options:
|
||||||
|
text = "There are no usable items in your inventory!"
|
||||||
|
|
||||||
options.extend(_get_default_wizard_options(caller, **kwargs))
|
options.extend(_get_default_wizard_options(caller, **kwargs))
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
@ -1397,10 +1433,13 @@ def node_choose_wield_item(caller, raw_string, **kwargs):
|
||||||
options = [
|
options = [
|
||||||
{
|
{
|
||||||
"desc": item.get_display_name(caller),
|
"desc": item.get_display_name(caller),
|
||||||
"goto": (_step_wizard, {**action_dict, **{"item": item}}),
|
"goto": (_step_wizard, {**kwargs, **{**action_dict, **{"item": item}}}),
|
||||||
}
|
}
|
||||||
for item in self.caller.equipment.get_wieldable_objects_from_backpack()
|
for item in caller.equipment.get_wieldable_objects_from_backpack()
|
||||||
]
|
]
|
||||||
|
if not options:
|
||||||
|
text = "There are no items in your inventory that you can wield!"
|
||||||
|
|
||||||
options.extend(_get_default_wizard_options(caller, **kwargs))
|
options.extend(_get_default_wizard_options(caller, **kwargs))
|
||||||
return text, options
|
return text, options
|
||||||
|
|
||||||
|
|
@ -1455,7 +1494,7 @@ def node_combat(caller, raw_string, **kwargs):
|
||||||
"goto": (
|
"goto": (
|
||||||
_step_wizard,
|
_step_wizard,
|
||||||
{
|
{
|
||||||
"steps": ["node_choose_item", "node_choose_allied_target"],
|
"steps": ["node_choose_use_item", "node_choose_allied_target"],
|
||||||
"action_dict": {"key": "use", "item": None, "target": None},
|
"action_dict": {"key": "use", "item": None, "target": None},
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -1482,7 +1521,7 @@ def node_combat(caller, raw_string, **kwargs):
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"desc": "flee!",
|
"desc": "flee!",
|
||||||
"goto": (_queue_action, {"flee": {"key": "flee"}}),
|
"goto": (_queue_action, {"action_dict": {"key": "flee"}}),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"desc": "hold, doing nothing",
|
"desc": "hold, doing nothing",
|
||||||
|
|
@ -1563,7 +1602,7 @@ class CmdTurnAttack(_CmdTurnCombatBase):
|
||||||
},
|
},
|
||||||
startnode="node_combat",
|
startnode="node_combat",
|
||||||
combathandler=self.combathandler,
|
combathandler=self.combathandler,
|
||||||
cmdset_mergetype="Union",
|
# cmdset_mergetype="Union",
|
||||||
persistent=True,
|
persistent=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -362,6 +362,21 @@ class CmdEvMenuNode(Command):
|
||||||
def get_help(self):
|
def get_help(self):
|
||||||
return "Menu commands are explained within the menu."
|
return "Menu commands are explained within the menu."
|
||||||
|
|
||||||
|
def _update_aliases(self, menu):
|
||||||
|
"""Add aliases to make sure to override defaults if we defined we want it."""
|
||||||
|
|
||||||
|
new_aliases = [_CMD_NOMATCH]
|
||||||
|
if menu.auto_quit and "quit" not in self.aliases:
|
||||||
|
new_aliases.extend(["q", "quit"])
|
||||||
|
if menu.auto_look and "look" not in self.aliases:
|
||||||
|
new_aliases.extend(["l", "look"])
|
||||||
|
if menu.auto_help and "help" not in self.aliases:
|
||||||
|
new_aliases.extend(["h", "help"])
|
||||||
|
if len(new_aliases) > 1:
|
||||||
|
self.set_aliases(new_aliases)
|
||||||
|
|
||||||
|
self.msg(f"aliases: {self.aliases}")
|
||||||
|
|
||||||
def func(self):
|
def func(self):
|
||||||
"""
|
"""
|
||||||
Implement all menu commands.
|
Implement all menu commands.
|
||||||
|
|
@ -382,7 +397,8 @@ class CmdEvMenuNode(Command):
|
||||||
saved_options[2]["startnode_input"] = startnode_input
|
saved_options[2]["startnode_input"] = startnode_input
|
||||||
MenuClass = saved_options[0]
|
MenuClass = saved_options[0]
|
||||||
# this will create a completely new menu call
|
# this will create a completely new menu call
|
||||||
MenuClass(caller, *saved_options[1], **saved_options[2])
|
menu = MenuClass(caller, *saved_options[1], **saved_options[2])
|
||||||
|
# self._update_aliases(menu)
|
||||||
return True
|
return True
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
@ -408,6 +424,9 @@ class CmdEvMenuNode(Command):
|
||||||
err
|
err
|
||||||
) # don't give the session as a kwarg here, direct to original
|
) # don't give the session as a kwarg here, direct to original
|
||||||
raise EvMenuError(err)
|
raise EvMenuError(err)
|
||||||
|
|
||||||
|
# self._update_aliases(menu)
|
||||||
|
|
||||||
# we must do this after the caller with the menu has been correctly identified since it
|
# we must do this after the caller with the menu has been correctly identified since it
|
||||||
# can be either Account, Object or Session (in the latter case this info will be
|
# can be either Account, Object or Session (in the latter case this info will be
|
||||||
# superfluous).
|
# superfluous).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue