encounter_system #2

Merged
amber merged 3 commits from encounter_system into ambyPlayground 2024-01-13 04:51:18 +00:00
3 changed files with 68 additions and 3 deletions
Showing only changes of commit d399af040d - Show all commits

View File

@ -100,6 +100,7 @@ class CmdRP(EncounterCommand):
"Free-form text input (for describing your actions in RP)"
energy_cost = 0
key = "rp"
arg_regex = None
aliases = [">"]
help_category = "Encounter"
@ -118,11 +119,56 @@ class CmdFlee(EncounterCommand):
super().handler().msg_all(f"{self.caller.key} left the encounter")
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):
def at_cmdset_creation(self):
self.add(CmdPass)
self.add(CmdRP)
self.add(CmdFlee)
self.add(CmdOOC)
self.add(CmdPose)
# Encounter-related character commands

View File

@ -27,3 +27,12 @@ class Character(ClothedCharacter):
return False
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

View File

@ -68,6 +68,10 @@ class EncounterHandler(DefaultScript):
for char in self.db.characters.values():
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):
caller = cmd.caller
cmdname = cmd.key
@ -80,9 +84,15 @@ class EncounterHandler(DefaultScript):
caller.msg("You do not have enough energy remaining")
caller.msg(f"You have: {self.db.turn_energy}, but need {energy}")
else:
self.pre_say(caller)
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)")
return False
def has_default_target(self, caller):
if (len(self.db.characters) == 2) and (caller in self.db.characters.values()):