Beispiel #1
0
    public override void Invoke()
    {
        switch (curr)
        {
        case Behavior.Idle:
            _behave.Idle();
            break;

        case Behavior.MoveTo:
            _behave.MoveTo(targetPos, speed, threshold);
            break;

        case Behavior.MoveAwayFrom:
            _behave.MoveFrom(targetPos, speed, threshold + 1);
            break;

        case Behavior.Feed:
            _behave.Feed(target);
            break;

        case Behavior.Attack:
            _behave.MeleeAttack(targetPos);
            break;

        case Behavior.Ranged:
            _behave.RangedAttack(targetPos, speed);
            break;

        case Behavior.Socialize:
            _behave.Socialize();
            break;

        case Behavior.Custom:
            custom.InvokeBehavior();
            break;
        }
    }
    /// <summary>
    /// Each protocol is of the format:
    ///     void X()
    ///     {
    ///         if (Behavior()){
    ///             if (Behavior())
    ///             {
    ///                 ...
    ///             }
    ///         }
    ///     }
    /// </summary>
    #region Aggro Protocols
    /// NEEDS A LOT OF POLISH
    // Melee()
    // move to and make a melee attack on
    // some creature or enemy or bush
    /// <summary>
    /// If the target is outside of our range, move to it and attack. Else, attack.
    /// </summary>
    public void Melee(GameObject target)
    {
        #region Get Nearest + Null Check
        var     weakest = Checks.WeakestCreature();
        Vector2 pos;
        if (target != null)
        {
            pos = target.transform.position;
        }
        else if (weakest != null)
        {
            pos = Checks.WeakestCreature().transform.position;
        }
        else
        {
            return;
        }
        #endregion


        if (Behaviour.MoveTo(pos, AiData.Speed, 1.0f))
        {
            if (CheckThreshold(pos, AiData.MeleeAttackThreshold))
            {
                Behaviour.MeleeAttack(pos);
            }
        }
    }