Page 1 of 1

Add PlayerMeleeHitArg.MeleeAction

Posted: Sat Mar 19, 2022 3:02 pm
by NearHuscarl
I'd like to have a way to know what melee action is being performed. Is the attacker doing a single punch, a combo or a knock out. Below is an example in code:

Code: Select all

public enum MeleeAction { Attack1, Attack2, Attack3 }

public struct PlayerMeleeHitArg
{
    public readonly int ObjectID;
    public readonly IObject HitObject;
    public readonly Vector2 HitPosition;
    public readonly bool IsPlayer;
    public readonly float HitDamage;
    // new property
    public readonly MeleeAction MeleeAction;

    public PlayerMeleeHitArg(int objectID, IObject hitObject, Vector2 hitPosition, bool isPlayer, float hitDamage, MeleeAction meleeAction);
}

Code: Select all

Events.PlayerMeleeActionCallback.Start(OnPlayerMeleeAction);

// ...

private static void OnPlayerMeleeAction(IPlayer attacker, PlayerMeleeHitArg[] args)
{
    foreach (var arg in args)
    {
        if (arg.MeleeAction == MeleeAction.Attack1) { /* ... */ }
        if (arg.MeleeAction == MeleeAction.Attack2) { /* ... */ }
        if (arg.MeleeAction == MeleeAction.Attack3) { /* Activate powerup... */ }
    }
}