コード例 #1
0
ファイル: AttackComponent.cs プロジェクト: navezof/Disarmed
    /**
     * 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;
        }
    }
コード例 #2
0
 // This function return false if the enemy is for any reason not targetable
 bool IsTargetable(PawnAI enemy)
 {
     if (enemy.GetHealth().IsDead() || enemy.GetHealth().IsKnockedDown() || enemy == currentTarget)
     {
         return(false);
     }
     return(true);
 }
コード例 #3
0
 /**
  * To get the next attacker, several check are made
  */
 PawnAI GetNextAttacker()
 {
     GetReadyAttackers();
     GetVisibleAttackers();
     GetPriorityAttackers();
     nextAttacker = GetClosestEnemy(priorityAttackers);
     return(nextAttacker);
 }
コード例 #4
0
 // We set the target of the dash
 public void Dash(PawnAI target)
 {
     bDashing = true;
     if (target == null)
     {
         EndDash();
         return;
     }
     currentTarget = target;
 }
コード例 #5
0
 /**
  * Iteration through the attackers, and gift of attack token
  *
  */
 void GiveAttackToken()
 {
     if (bToken == false)
     {
         return;
     }
     if (GetNextAttacker() != null)
     {
         nextAttacker.GetController().TakeToken();
         nextAttacker = null;
         bToken       = false;
     }
 }
コード例 #6
0
ファイル: AttackComponent.cs プロジェクト: navezof/Disarmed
 // 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();
     }
 }
コード例 #7
0
ファイル: PlayerController.cs プロジェクト: navezof/Disarmed
 void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         swipeStart = Input.mousePosition;
     }
     if (Input.GetMouseButtonUp(0))
     {
         swipeEnd = Input.mousePosition;
         if (IsSwipe())
         {
             target = pawn.GetDash().FindTarget(transform.position, swipeEnd);
             StoreInput(EInput.DASH);
         }
         else
         {
             TouchInput(swipeEnd);
         }
     }
 }
コード例 #8
0
    /**
     * Loop through a list of potential target, and find the one the closest to the player
     */
    public PawnAI GetClosestEnemy(List <PawnAI> potentialAttackers)
    {
        if (potentialAttackers.Count <= 0)
        {
            if (enemies.Length > 0)
            {
                return(null);
            }
            return(enemies[0]);
        }
        PawnAI bestTarget = potentialAttackers[0];

        foreach (PawnAI pawn in potentialAttackers)
        {
            if (Vector3.Distance(pawn.transform.position, player.transform.position) < Vector3.Distance(bestTarget.transform.position, player.transform.position))
            {
                bestTarget = pawn;
            }
        }
        return(bestTarget);
    }
コード例 #9
0
    /**
     * Last part of the selection process, from all the enemies selected, we chose the closest one
     *
     */
    PawnAI FindClosestTarget()
    {
        // Like earlier, if the list is empty, return here
        if (menacingTargets.Count <= 0)
        {
            return(null);
        }

        // Here a simpler loop, with a check on the distance of each menacing target
        PawnAI closest = menacingTargets[0];

        foreach (PawnAI enemy in menacingTargets)
        {
            if (Vector3.Distance(transform.position, enemy.transform.position) < Vector3.Distance(transform.position, closest.transform.position))
            {
                closest = enemy;
            }
        }
        currentTarget = closest;
        return(closest);
    }
コード例 #10
0
 // Take possession of a pawn
 public override void Possess(APawn pawnAI)
 {
     pawn = pawnAI as PawnAI;
 }