Merge pull request 'update to encounter system' (#1) from encounter_system into main
Reviewed-on: #1
This commit is contained in:
commit
863f140d15
|
@ -100,6 +100,7 @@ class CmdRP(EncounterCommand):
|
||||||
"Free-form text input (for describing your actions in RP)"
|
"Free-form text input (for describing your actions in RP)"
|
||||||
energy_cost = 0
|
energy_cost = 0
|
||||||
key = "rp"
|
key = "rp"
|
||||||
|
arg_regex = None
|
||||||
aliases = [">"]
|
aliases = [">"]
|
||||||
help_category = "Encounter"
|
help_category = "Encounter"
|
||||||
|
|
||||||
|
@ -118,11 +119,56 @@ class CmdFlee(EncounterCommand):
|
||||||
super().handler().msg_all(f"{self.caller.key} left the encounter")
|
super().handler().msg_all(f"{self.caller.key} left the encounter")
|
||||||
super().handler().remove_character(self.caller)
|
super().handler().remove_character(self.caller)
|
||||||
|
|
||||||
|
class CmdOOC(EncounterCommand):
|
||||||
|
"Say something out-of-character"
|
||||||
|
energy_cost = 0
|
||||||
|
key = "("
|
||||||
|
arg_regex = None
|
||||||
|
|
||||||
|
def func(self):
|
||||||
|
super().handler().msg_all(f"({self.caller}: {self.args.strip()})")
|
||||||
|
|
||||||
|
class CmdPose(EncounterCommand):
|
||||||
|
"""
|
||||||
|
strike a pose
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
pose <pose text>
|
||||||
|
pose's <pose text>
|
||||||
|
|
||||||
|
Example:
|
||||||
|
pose is standing by the wall, smiling.
|
||||||
|
-> others will see:
|
||||||
|
Tom is standing by the wall, smiling.
|
||||||
|
|
||||||
|
Describe an action being taken. The pose text will
|
||||||
|
automatically begin with your name.
|
||||||
|
"""
|
||||||
|
key = "pose"
|
||||||
|
aliases = [":", "emote"]
|
||||||
|
locks = "cmd:all()"
|
||||||
|
arg_regex = None
|
||||||
|
energy_cost = 0
|
||||||
|
def parse(self):
|
||||||
|
args = self.args
|
||||||
|
if args and not args[0] in ["'", ",", ":"]:
|
||||||
|
args = " %s" % args.strip()
|
||||||
|
self.args = args
|
||||||
|
def func(self):
|
||||||
|
if super().can_perform():
|
||||||
|
if not self.args:
|
||||||
|
self.msg("What do you want to do?")
|
||||||
|
else:
|
||||||
|
msg = f"{self.caller.name}{self.args}"
|
||||||
|
super().handler().msg_all_rich((msg, {'type':'pose'}), self.caller)
|
||||||
|
|
||||||
class SetEncounterSpecial(CmdSet):
|
class SetEncounterSpecial(CmdSet):
|
||||||
def at_cmdset_creation(self):
|
def at_cmdset_creation(self):
|
||||||
self.add(CmdPass)
|
self.add(CmdPass)
|
||||||
self.add(CmdRP)
|
self.add(CmdRP)
|
||||||
self.add(CmdFlee)
|
self.add(CmdFlee)
|
||||||
|
self.add(CmdOOC)
|
||||||
|
self.add(CmdPose)
|
||||||
|
|
||||||
# Encounter-related character commands
|
# Encounter-related character commands
|
||||||
|
|
||||||
|
@ -131,7 +177,7 @@ class CmdEngage(Command):
|
||||||
Initiates an encounter with the selected target
|
Initiates an encounter with the selected target
|
||||||
"""
|
"""
|
||||||
key = "engage"
|
key = "engage"
|
||||||
aliases = ["encounter"]
|
aliases = ["encounter", "fight"]
|
||||||
def func(self):
|
def func(self):
|
||||||
if not self.args:
|
if not self.args:
|
||||||
self.caller.msg("Usage: engage <target>")
|
self.caller.msg("Usage: engage <target>")
|
||||||
|
@ -139,6 +185,9 @@ class CmdEngage(Command):
|
||||||
target = self.caller.search(self.args)
|
target = self.caller.search(self.args)
|
||||||
if not target:
|
if not target:
|
||||||
return
|
return
|
||||||
|
if target == self.caller:
|
||||||
|
self.caller.msg("You can't initiate an encounter with yourself!")
|
||||||
|
return
|
||||||
if target.ndb.encounter_handler:
|
if target.ndb.encounter_handler:
|
||||||
target.ndb.encounter_handler.add_character(self.caller)
|
target.ndb.encounter_handler.add_character(self.caller)
|
||||||
target.ndb.encounter_handler.msg_all(f"{self.caller} joins the encounter")
|
target.ndb.encounter_handler.msg_all(f"{self.caller} joins the encounter")
|
||||||
|
|
|
@ -27,3 +27,12 @@ class Character(ClothedCharacter):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def at_pre_say(self, speech):
|
||||||
|
if self.ndb.encounter_handler:
|
||||||
|
if self.ndb.encounter_handler.is_turn(self):
|
||||||
|
self.ndb.encounter_handler.msg_all(f"{self} says, \"{speech}\"")
|
||||||
|
else:
|
||||||
|
self.ndb.encounter_handler.pre_say(self)
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return speech
|
||||||
|
|
|
@ -13,8 +13,6 @@ class EncounterHandler(DefaultScript):
|
||||||
def at_script_creation(self):
|
def at_script_creation(self):
|
||||||
# When initiating the encounter
|
# When initiating the encounter
|
||||||
self.key = f"encounter_handler_{random.randint(1, 1000)}"
|
self.key = f"encounter_handler_{random.randint(1, 1000)}"
|
||||||
self.desc = "Handles an encounter"
|
|
||||||
self.persistent = True
|
|
||||||
|
|
||||||
self.db.characters = {}
|
self.db.characters = {}
|
||||||
self.db.turns = []
|
self.db.turns = []
|
||||||
|
@ -34,15 +32,11 @@ class EncounterHandler(DefaultScript):
|
||||||
del character.ndb.encounter_handler
|
del character.ndb.encounter_handler
|
||||||
character.revoke_encounter_cmdset()
|
character.revoke_encounter_cmdset()
|
||||||
|
|
||||||
def at_start(self):
|
|
||||||
# When initializing or rebooting
|
|
||||||
for character in self.db.characters.values():
|
|
||||||
self._init_character(character)
|
|
||||||
|
|
||||||
def at_stop(self):
|
def at_stop(self):
|
||||||
# When deinitializing or rebooting
|
# When deinitializing
|
||||||
for character in list(self.db.characters.values()):
|
for character in list(self.db.characters.values()):
|
||||||
self._cleanup_character(character)
|
self._cleanup_character(character)
|
||||||
|
self.delete()
|
||||||
|
|
||||||
def add_character(self, character):
|
def add_character(self, character):
|
||||||
# Adds a character to the encounter
|
# Adds a character to the encounter
|
||||||
|
@ -58,16 +52,19 @@ class EncounterHandler(DefaultScript):
|
||||||
if len(self.db.characters) == 1:
|
if len(self.db.characters) == 1:
|
||||||
char = list(self.db.characters.values())[0]
|
char = list(self.db.characters.values())[0]
|
||||||
char.msg("You are no longer in an encounter.")
|
char.msg("You are no longer in an encounter.")
|
||||||
self._cleanup_character(char)
|
self.at_stop()
|
||||||
self.stop()
|
|
||||||
elif not self.db.characters:
|
elif not self.db.characters:
|
||||||
self.stop()
|
self.at_stop()
|
||||||
|
|
||||||
def msg_all(self, message):
|
def msg_all(self, message):
|
||||||
# Sends text to all players in the encounter
|
# Sends text to all players in the encounter
|
||||||
for char in self.db.characters.values():
|
for char in self.db.characters.values():
|
||||||
char.msg(message)
|
char.msg(message)
|
||||||
|
|
||||||
|
def msg_all_rich(self, text, obj):
|
||||||
|
for char in self.db.characters.values():
|
||||||
|
char.msg(text = text, from_obj = obj)
|
||||||
|
|
||||||
def can_act(self, cmd):
|
def can_act(self, cmd):
|
||||||
caller = cmd.caller
|
caller = cmd.caller
|
||||||
cmdname = cmd.key
|
cmdname = cmd.key
|
||||||
|
@ -80,10 +77,16 @@ class EncounterHandler(DefaultScript):
|
||||||
caller.msg("You do not have enough energy remaining")
|
caller.msg("You do not have enough energy remaining")
|
||||||
caller.msg(f"You have: {self.db.turn_energy}, but need {energy}")
|
caller.msg(f"You have: {self.db.turn_energy}, but need {energy}")
|
||||||
else:
|
else:
|
||||||
caller.msg("(It's not your turn yet!)")
|
self.pre_say(caller)
|
||||||
caller.msg("(You can talk out-of-character using parentheses)")
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def is_turn(self, char):
|
||||||
|
return self.db.turns[self.db.turn_index] == char.id
|
||||||
|
|
||||||
|
def pre_say(self, caller):
|
||||||
|
caller.msg("(It's not your turn yet!)")
|
||||||
|
caller.msg("(You can talk out-of-character using parentheses)")
|
||||||
|
|
||||||
def has_default_target(self, caller):
|
def has_default_target(self, caller):
|
||||||
if (len(self.db.characters) == 2) and (caller in self.db.characters.values()):
|
if (len(self.db.characters) == 2) and (caller in self.db.characters.values()):
|
||||||
keys = list(self.db.characters.keys())
|
keys = list(self.db.characters.keys())
|
||||||
|
|
Loading…
Reference in New Issue