Controlling the attack style with a reactor

The Basic Melee Attack motion allows you to setup multiple attack styles. Each of these attack styles can be associated with an animation. This allows your characters to have a lot of different attack styles.

By default, an attack will use a single attack style whose “form” matches the Default Form set by the weapon set and held in the Actor Core’s list of states.

However, right before the character swings his weapon he’ll send a pre-attack message. If you intercept this message with a reactor, you can change which attack style the character actually uses.

In this example, I’ll use a Unity Event Proxy Reactor to send the pre-attack message to a custom function on a custom component.

To catch the pre-attack message, we look for the Message ID 1100 (which means pre-attack).

Using the Unity Event, we redirect the message to a function on a custom component we created and added to the character.

The code for the component is pretty simple:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
using UnityEngine;
using com.ootii.Actors.Combat;
using com.ootii.Reactors;

namespace com.ootii.Demos
{
    public class AllPacks_CustomPC : MonoBehaviour
    {
        /// Allows us to choose the attack style we'll attack with
        public void SelectAttackStyle(ReactorAction rAction)
        {
            if (rAction == null || rAction.Message == null) { return; }

            CombatMessage lCombatMessage = rAction.Message as CombatMessage;
            if (lCombatMessage == null) { return; }

            lCombatMessage.StyleIndex = 1;
        }
    }
}

You can see the SelectAttackStyle() function gets the ReactorAction and looks at its Message property. If that message is a CombatMessage, we can change the StyleIndex property.

This index is the new attack style index we’ll use to attack with. In this example, I’m forcing it to index 1 (the second attack style). However, you could run logic that randomly chooses an attack style index, looks at the defender’s stance to select the index, or any number of things.

You can code the SelectAttackStyle() function as you see fit.

When the function ends, the Basic Melee Attack will use the index to find the right attack style and execute it.

Leave a Reply