/** * 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; } }
// 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); }
/** * To get the next attacker, several check are made */ PawnAI GetNextAttacker() { GetReadyAttackers(); GetVisibleAttackers(); GetPriorityAttackers(); nextAttacker = GetClosestEnemy(priorityAttackers); return(nextAttacker); }
// We set the target of the dash public void Dash(PawnAI target) { bDashing = true; if (target == null) { EndDash(); return; } currentTarget = target; }
/** * 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; } }
// 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(); } }
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); } } }
/** * 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); }
/** * 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); }
// Take possession of a pawn public override void Possess(APawn pawnAI) { pawn = pawnAI as PawnAI; }