hazelmud/commands/encounter/__init__.py

42 lines
1.6 KiB
Python
Raw Permalink Normal View History

from commands.command import Command
class EncounterCommand(Command):
energy_cost = 1
allow_self_target = False
def handler(self):
return self.caller.ndb.encounter_handler
def can_perform(self):
# Returns whether the caller is having their turn and if they have enough energy
# to make this action
return self.handler().can_act(self)
def has_target(self):
# Targeting code:
# Looks for the suggested target
# If none is found but there is only one other character in the encounter,
# default to that other character
# Else ask player for clarification
if self.target:
self.target = self.caller.search(self.target)
if not self.target:
default_target = self.handler().has_default_target(self.caller)
if default_target:
self.caller.msg("Defaulting to other character in encounter")
self.target = default_target
else:
self.caller.msg(f"Who are you trying to {self.key}?")
self.target = None
else:
default_target = self.handler().has_default_target(self.caller)
if default_target:
self.target = default_target
else:
self.caller.msg(f"Who are you trying to {self.key}?")
self.target = None
if self.caller == self.target and not self.allow_self_target:
self.msg(f"You aren't supposed to {self.key} yourself!")
return self.target