Running item actions


I am using a MOSS-like object action design…

Let me ask my question with an example, Axe is an ObjectType, among its list of actions, it has a “ChopTree” action. This action can be used when the axe is equipped by a character.

Which style do you think is better for executing this action:

1- When the axe is equipped by a character, it adds the “ChopTree” action into the character actions list, and any script that wants to execute the action calls character.runAction(“ChopTree”).
Note axe must be equipped first.

2- Any script that wants to execute the action runs character.runItemAction(“Axe”, “ChopTree”). It basically looks for the axe in the character equipments and runs the “ChopTree” action on the axe.
Note axe must be equipped first.

Might sound stupid but just am curious to know which approach you may choose :slightly_smiling_face:

Player or mob?

Suppose a mob.

And what is it that wants the axe to cut the tree?

I think if you think of the use-case from a game logic perspective then it might be obvious how this works. Like, what wanted the tree cut? How did it know? When was the axe equipped and by what? …and so on.

Because (1) versus (2) to me is 100% the product of those other choices.

Mob AI in the GetWoodTask.

Hope this make sense

    private static Task<GameObject> createGetWoodTask() {
        return sequence()
                // Check if we can get wood
                        .addChild(new Invert<>(HasItem.withName(WOOD, 5)))
                        .addChild(new SetVar<>("chopTree", BlacksmithAI::findChopTree))
                .addChild(new RunItemAction<>(ChopTree.class, Axe.class, (object, item, chopTree)


RunItemAction is the part my question comes from!


With this setup, it seems reasonable to use either approach but grafting the actions into the mob’s available actions seems like an unnecessary step. The AI knows that it has equipped the axe and can therefore run that axe’s actions.

…it also seems the least amount of work which means you can change your mind later without having really wasted any time.

If you ever get to the point where you deal with action chaining, the AI might simply initiate a “have this mob chop this tree” task that then performs the prerequisite of finding an item in the inventory that can chop, equipping it, then chopping. And even still, the thing chopping also knows to equip it.

The simpler option does let the game cheat unless the axe already knows it can’t work without being equipped first. But that may be a side-benefit. Who knows.

1 Like

Is this some library you are using or did you craft your own?

I craft my own. Afaik MOSS action library is not released to the public yet.

1 Like

It’s available to patrons. Its very cool so far.