evennia.contrib.tutorials.evadventure.combat_base

EvAdventure Base combat utilities.

This establishes the basic building blocks for combat:

  • CombatFailure - exception for combat-specific errors.

  • CombatAction (and subclasses) - classes encompassing all the working around an action. They are initialized from ‘action-dicts** - dictionaries with all the relevant data for the particular invocation

  • CombatHandler - base class for running a combat. Exactly how this is used depends on the type of combat intended (twitch- or turn-based) so many details of this will be implemented in child classes.


exception evennia.contrib.tutorials.evadventure.combat_base.CombatFailure[源代码]

基类:RuntimeError

Some failure during combat actions.

class evennia.contrib.tutorials.evadventure.combat_base.CombatAction(combathandler, combatant, action_dict)[源代码]

基类:object

Parent class for all actions.

This represents the executable code to run to perform an action. It is initialized from an ‘action-dict’, a set of properties stored in the action queue by each combatant.

__init__(combathandler, combatant, action_dict)[源代码]

Each key-value pair in the action-dict is stored as a property on this class for later access.

参数
  • combatant (EvAdventureCharacter, EvAdventureNPC) – The combatant performing the action.

  • action_dict (dict) – A dict containing all properties to initialize on this class. This should not be any keys with _ prefix, since these are used internally by the class.

msg(message, broadcast=True)[源代码]

Convenience route to the combathandler msg-sender mechanism.

参数

message (str) – Message to send; use $You() and $You(other.key) to refer to the combatant doing the action and other combatants, respectively.

can_use()[源代码]

Called to determine if the action is usable with the current settings. This does not actually perform the action.

返回

bool – If this action can be used at this time.

execute()[源代码]

Perform the action as the combatant. Should normally make use of the properties stored on the class during initialization.

post_execute()[源代码]

Called after execution.

class evennia.contrib.tutorials.evadventure.combat_base.CombatActionHold(combathandler, combatant, action_dict)[源代码]

基类:evennia.contrib.tutorials.evadventure.combat_base.CombatAction

Action that does nothing.

action_dict = {
        "key": "hold"
    }
class evennia.contrib.tutorials.evadventure.combat_base.CombatActionAttack(combathandler, combatant, action_dict)[源代码]

基类:evennia.contrib.tutorials.evadventure.combat_base.CombatAction

A regular attack, using a wielded weapon.

action-dict = {
        "key": "attack",
        "target": Character/Object
    }
execute()[源代码]

Perform the action as the combatant. Should normally make use of the properties stored on the class during initialization.

class evennia.contrib.tutorials.evadventure.combat_base.CombatActionStunt(combathandler, combatant, action_dict)[源代码]

基类:evennia.contrib.tutorials.evadventure.combat_base.CombatAction

Perform a stunt the grants a beneficiary (can be self) advantage on their next action against a target. Whenever performing a stunt that would affect another negatively (giving them disadvantage against an ally, or granting an advantage against them, we need to make a check first. We don’t do a check if giving an advantage to an ally or ourselves.

action_dict = {
       "key": "stunt",
       "recipient": Character/NPC,
       "target": Character/NPC,
       "advantage": bool,  # if False, it's a disadvantage
       "stunt_type": Ability,  # what ability (like STR, DEX etc) to use to perform this stunt.
       "defense_type": Ability, # what ability to use to defend against (negative) effects of
        this stunt.
    }
execute()[源代码]

Perform the action as the combatant. Should normally make use of the properties stored on the class during initialization.

class evennia.contrib.tutorials.evadventure.combat_base.CombatActionUseItem(combathandler, combatant, action_dict)[源代码]

基类:evennia.contrib.tutorials.evadventure.combat_base.CombatAction

Use an item in combat. This is meant for one-off or limited-use items (so things like scrolls and potions, not swords and shields). If this is some sort of weapon or spell rune, we refer to the item to determine what to use for attack/defense rolls.

action_dict = {
        "key": "use",
        "item": Object
        "target": Character/NPC/Object/None
    }
execute()[源代码]

Perform the action as the combatant. Should normally make use of the properties stored on the class during initialization.

class evennia.contrib.tutorials.evadventure.combat_base.CombatActionWield(combathandler, combatant, action_dict)[源代码]

基类:evennia.contrib.tutorials.evadventure.combat_base.CombatAction

Wield a new weapon (or spell) from your inventory. This will swap out the one you are currently wielding, if any.

action_dict = {
        "key": "wield",
        "item": Object
    }
execute()[源代码]

Perform the action as the combatant. Should normally make use of the properties stored on the class during initialization.

class evennia.contrib.tutorials.evadventure.combat_base.EvAdventureCombatBaseHandler(*args, **kwargs)[源代码]

基类:evennia.scripts.scripts.DefaultScript

This script is created when a combat starts. It ‘ticks’ the combat and tracks all sides of it.

action_classes = {'attack': <class 'evennia.contrib.tutorials.evadventure.combat_base.CombatActionAttack'>, 'hold': <class 'evennia.contrib.tutorials.evadventure.combat_base.CombatActionHold'>, 'stunt': <class 'evennia.contrib.tutorials.evadventure.combat_base.CombatActionStunt'>, 'use': <class 'evennia.contrib.tutorials.evadventure.combat_base.CombatActionUseItem'>, 'wield': <class 'evennia.contrib.tutorials.evadventure.combat_base.CombatActionWield'>}
fallback_action_dict

AttributeProperty.

classmethod get_or_create_combathandler(obj, **kwargs)[源代码]

Get or create a combathandler on obj.

参数

obj (any) – The Typeclassed entity to store the CombatHandler Script on. This could be a location (for turn-based combat) or a Character (for twitch-based combat).

关键字参数
  • combathandler_key (str) – They key name for the script. Will be ‘combathandler’ by default.

  • **kwargs – Arguments to the Script, if it is created.

msg(message, combatant=None, broadcast=True, location=None)[源代码]

Central place for sending messages to combatants. This allows for adding any combat-specific text-decoration in one place.

参数
  • message (str) – The message to send.

  • combatant (Object) – The ‘You’ in the message, if any.

  • broadcast (bool) – If False, combatant must be included and will be the only one to see the message. If True, send to everyone in the location.

  • location (Object, optional) – If given, use this as the location to send broadcast messages to. If not, use self.obj as that location.

提示

If combatant is given, use $You/you() markup to create a message that looks different depending on who sees it. Use $You(combatant_key) to refer to other combatants.

get_combat_summary(combatant)[源代码]

Get a ‘battle report’ - an overview of the current state of combat from the perspective of one of the sides.

参数

combatant (EvAdventureCharacter, EvAdventureNPC) – The combatant to get.

返回

EvTable – A table representing the current state of combat.

Example:

Goblin shaman (Perfect)

Gregor (Hurt) Goblin brawler(Hurt) Bob (Perfect) vs Goblin grunt 1 (Hurt)

Goblin grunt 2 (Perfect) Goblin grunt 3 (Wounded)

get_sides(combatant)[源代码]

Get a listing of the two ‘sides’ of this combat, from the perspective of the provided combatant. The sides don’t need to be balanced.

参数

combatant (Character or NPC) – The one whose sides are to determined.

返回

tuple – A tuple of lists (allies, enemies), from the perspective of combatant.

注解

The sides are found by checking PCs vs NPCs. PCs can normally not attack other PCs, so are naturally allies. If the current room has the allow_pvp Attribute set, then _all_ other combatants (PCs and NPCs alike) are considered valid enemies (one could expand this with group mechanics).

give_advantage(recipient, target)[源代码]

Let a benefiter gain advantage against the target.

参数
  • recipient (Character or NPC) – The one to gain the advantage. This may or may not be the same entity that creates the advantage in the first place.

  • target (Character or NPC) – The one against which the target gains advantage. This could (in principle) be the same as the benefiter (e.g. gaining advantage on some future boost)

give_disadvantage(recipient, target)[源代码]

Let an affected party gain disadvantage against a target.

参数
  • recipient (Character or NPC) – The one to get the disadvantage.

  • target (Character or NPC) – The one against which the target gains disadvantage, usually

  • enemy. (an) –

has_advantage(combatant, target)[源代码]

Check if a given combatant has advantage against a target.

参数
  • combatant (Character or NPC) – The one to check if they have advantage

  • target (Character or NPC) – The target to check advantage against.

has_disadvantage(combatant, target)[源代码]

Check if a given combatant has disadvantage against a target.

参数
  • combatant (Character or NPC) – The one to check if they have disadvantage

  • target (Character or NPC) – The target to check disadvantage against.

queue_action(action_dict, combatant=None)[源代码]

Queue an action by adding the new actiondict.

参数
  • action_dict (dict) – A dict describing the action class by name along with properties.

  • combatant (EvAdventureCharacter, EvAdventureNPC, optional) – A combatant queueing the action.

execute_next_action(combatant)[源代码]

Perform a combatant’s next action.

参数

combatant (EvAdventureCharacter, EvAdventureNPC) – The combatant performing and action.

start_combat()[源代码]

Start combat.

check_stop_combat()[源代码]

Check if this combat should be aborted, whatever this means for the particular the particular combat type.

关键字参数

kwargs – Any extra keyword args used.

返回

bool – If True, the stop_combat method should be called.

stop_combat()[源代码]

Stop combat. This should also do all cleanup.

exception DoesNotExist

基类:evennia.scripts.scripts.DefaultScript.DoesNotExist

exception MultipleObjectsReturned

基类:evennia.scripts.scripts.DefaultScript.MultipleObjectsReturned

path = 'evennia.contrib.tutorials.evadventure.combat_base.EvAdventureCombatBaseHandler'
typename = 'EvAdventureCombatBaseHandler'