Hunter's Mood Variations in TADS 3

I know ADV3 doesn’t do anything like this, but I don’t know if ADV3Lite does. So, submitted for your approval is my current code for accomplishing the goal of monitoring and changing actor moods in TADS, including a MoodFuse class that will change an actor’s mood after a certain duration, and a modification to TopicEntry that allows required moods on a topic to topic basis. Keep in mind that I haven’t tested this code a shit ton, but here it is. Also, blind, so format sucks LMAO.

.



class Mood: object
name = ‘’
desc = ‘’
severity = 0 // -1 = hostile, 0 = neutral, +1 = friendly
;

neutral: Mood
name = ‘neutral’
desc = ‘calm and balanced’
severity = 0
;

friendly: Mood
name = ‘friendly’
desc = ‘warm and welcoming’
severity = 1
;

hostile: Mood
name = ‘hostile’
desc = ‘aggressive or suspicious’
severity = -1
;

modify Actor
currentMood = neutral
previousMood = nil
moodFuse = nil

setMood(mood, duration = nil)
{
    if (!mood.ofKind(Mood)) return;

    if (currentMood != mood)
    {
        previousMood = currentMood;
        currentMood = mood;
        onMoodChange(mood);

        if (duration != nil)
        {
            if (moodFuse != nil)
                moodFuse.cancel();

            else moodFuse = new MoodFuse(self, mood, duration);
        }
    }
}

onMoodChange(newMood)
{

#ifdef __DEBUG
“<>'s mood changes from <<previousMood.name>> to <<newMood.name>>.\n”;
#endif
}

// Optional method for getting a mood-affected greeting
getGreeting()
{
switch(currentMood)
{
case hostile:
return ‘What do you want?’;
case friendly:
return ‘Hey there, friend!’;
default:
return ‘Hello.’;
}
}


;

class MoodFuse: Fuse
actor = nil
mood = nil

construct(actor, mood, duration)
{
self.actor = actor;
self.mood = mood
inherited(actor, duration);
}

execute()
{
if (actor != nil)
{
actor.setMood(mood);
actor.moodFuse = nil; // clear the reference
}
}


;

modify TopicEntry
moodRequirement = nil

isActive()
{
if (!inherited()) return nil;
if (moodRequirement == nil || !moodRequirement.ofKind(Mood)) return true;
else return(getActor().currentMood == moodRequirement);
}


;

\`\`\`
2 Likes

Note to self, never publish code you edit at midnight to the forums. MoodFuse works now.

How does this differ from ActorStates that I think would work for what you want in adv3lite?