Example #1
0
    /**
     * Main function of this class
     *
     */
    public void Attack(APawn newTarget)
    {
        // The target should be passed to the function, but if the target is null, the closest one to the player is requested from the Swarmcontroller
        if (newTarget == null)
        {
            target = SwarmController.GetSwarmController().GetClosestEnemy(pawn);
        }
        else
        {
            target = newTarget;
        }

        // Setting the status of the pawn
        pawn.SetStatus(APawn.EStatus.ATTACKING);
        // If the pawn is an AI, the threat level of this AI is incrased
        if (pawn is PawnAI)
        {
            PawnAI ai = pawn as PawnAI;
            ai.AddThreat(1);
        }

        transform.LookAt(target.transform);

        // Animator values are set
        pawn.GetAnimator().SetInteger("cAttackIndex", currentAttackIndex);
        pawn.GetAnimator().SetInteger("cRange", GetRange());
        pawn.GetAnimator().SetTrigger("Attack");

        // In order to launch different animation, the animation index is modified here. If it exceed the max number of attack it goes back to zero
        currentAttackIndex++;
        if (currentAttackIndex > maxAttackIndex)
        {
            currentAttackIndex = 0;
        }
    }
Example #2
0
 public override EState Run()
 {
     controller.GetPawn().GetAttack().Attack(SwarmController.GetSwarmController().GetPlayer());
     controller.bToken = false;
     controller.GetPawn().bHasAttacked = true;
     return(EState.SUCCESS);
 }
Example #3
0
    /**
     * When looking for a target, we first check all the possible/targetables enemies
     */
    void FindPotentialTarget(Vector3 playerPosition, Vector3 swipeEnd)
    {
        // First emptying list previously made
        potentialTargets.Clear();

        // To make it simpler, all the position are replace in the screen
        Vector3 swipeVector = swipeEnd - Camera.main.WorldToScreenPoint(playerPosition);

        swipeVector.Normalize();

        // We are asking the swarmcontroller (who knows all the enemies) a list of enemies and iterate through it
        foreach (PawnAI enemy in SwarmController.GetSwarmController().GetAllEnemies())
        {
            if (IsTargetable(enemy))
            {
                // Like earlier, we convert the world point to screen point
                Vector3 enemyVector = Camera.main.WorldToScreenPoint(enemy.transform.position) - Camera.main.WorldToScreenPoint(playerPosition);
                // We calculate the angle between the swipe and the enemy...
                float angle = Vector3.Angle(swipeVector, enemyVector);
                // the distance between them...
                float distance = Vector3.Distance(playerPosition, enemy.transform.position);
                // and if the angle is between half a cone, and withing distance, a potential target is added to the list
                if (angle < targetingConeAngle / 2 && distance < targetingConeLength)
                {
                    potentialTargets.Add(enemy);
                }
            }
        }
    }
Example #4
0
 public override bool Try()
 {
     if (Vector3.Distance(controller.transform.position, SwarmController.GetSwarmController().GetPlayer().transform.position) > distance)
     {
         return(bInvert ? true : false);
     }
     return(bInvert ? false : true);
 }
Example #5
0
    protected override void Start()
    {
        base.Start();

        // Similar to the PawnAI, the controller is possessed here.
        controller = GetComponent <AIController>();
        controller.Possess(this);

        attack.SetTarget(SwarmController.GetSwarmController().GetPlayer());
    }
Example #6
0
 // Called at the end of an animation
 void EndAttack()
 {
     if (pawn.controller.nextInput == PlayerController.EInput.NONE)
     {
         currentAttackIndex = 0;
     }
     pawn.SetStatus(APawn.EStatus.IDLE);
     if (pawn.controller is AIController)
     {
         PawnAI ai = pawn as PawnAI;
         ai.AddThreat(-1);
         SwarmController.GetSwarmController().TakeToken();
     }
 }
Example #7
0
 void Start()
 {
     player = SwarmController.GetSwarmController().GetPlayer();
 }