diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee1820f7a..b384bb6f29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,8 +25,9 @@ - [Fix][pull3274]: Traceback when creating objects with initial nattributes (InspectorCaracal) - [Fix][issue3272]: Make sure `ScriptHandler.add` does not fail if passed an - instantiated script. -- Docs: Lots of Typo fixes (iLPdev) + instantiated script. (Volund) +- [Fix][pull3322]: Fix `BaseOption.display` to always return a string. +- Docs: Lots of Typo fixes (iLPdev, InspectorCaracal) - Beginner tutorial: Cleanup and starting earlier with explaining how to add to the default cmdsets. @@ -40,6 +41,7 @@ [pull3197]: https://github.com/evennia/evennia/pull/3197 [pull3313]: https://github.com/evennia/evennia/pull/3313 [pull3281]: https://github.com/evennia/evennia/pull/3281 +[pull3322]: https://github.com/evennia/evennia/pull/3322 [issue3272]: https://github.com/evennia/evennia/issues/3272 [issue3273]: https://github.com/evennia/evennia/issues/3273 diff --git a/evennia/contrib/tutorials/evadventure/ai.py b/evennia/contrib/tutorials/evadventure/ai.py index 6b08917d6e..37dd3d5ce4 100644 --- a/evennia/contrib/tutorials/evadventure/ai.py +++ b/evennia/contrib/tutorials/evadventure/ai.py @@ -115,6 +115,9 @@ class AIHandler: Add to typeclass with @lazyproperty: class NPC(DefaultCharacter): + + ai_states = {...} + # ... @lazyproperty @@ -126,10 +129,10 @@ class AIHandler: def __init__(self, obj): self.obj = obj - if hasattr(self, "AI_STATES"): - # load AI dict from typeclass core if it exists - allows for setting it - # on the typeclass directly. - self.add_aidict(self.AI_STATES) + if hasattr(self, "ai_states"): + # since we're not setting `force=True` here, we won't overwrite any existing / + # customized dicts. + self.add_aidict(self.ai_states) def __str__(self): return f"AIHandler for {self.obj}. Current state: {self.state}" @@ -282,14 +285,19 @@ class AIHandler: ) return self.obj.attributes.add("ai_transitions", value, category="ai") - def add_aidict(self, aidict): + def add_aidict(self, aidict, force=False): """ - Add an AI dictionary to the AI handler. + Add an AI dictionary to the AI handler, if one doesn't already exist. Args: aidict (dict): AI dictionary to add. + force (bool, optional): Force adding the AI dictionary, even if one already exists on + this handler. """ + if not force and self.states and self.transitions: + return + aidict = self._validate_ai_dict(aidict) self.states = aidict["states"] self.transitions = aidict["transitions"]