void ClosestEnemyUnit() { float dis = 0; foreach (TroopActorNetworked T in op.allTroopActors) { if (m_tank == null && T.team != m_team && T.rankState != RankState.dead) { if (Vector3.Distance(m_currentMarker.transform.position, T.transform.position) < 20f) { if (dis == 0 || Vector3.Distance(m_currentMarker.transform.position, T.transform.position) < dis) { dis = Vector3.Distance(m_currentMarker.transform.position, T.transform.position); m_tank = T; } } } } if (m_tank != null) { if (Vector3.Distance(m_currentMarker.transform.position, m_tank.transform.position) > 20f) { m_tank = null; } } }
public Transform AllocateTarget(TroopActorNetworked ta) { foreach (FormationPositionNetworked fp in formationPositions) { if (fp.assignedUnit.rankState == RankState.dead) { fp.taken = false; } if (!fp.taken) { fp.assignedUnit = ta; fp.taken = true; return(fp.fromPos); } } FormationPositionNetworked newFP = new FormationPositionNetworked(); { GameObject newFormPos = new GameObject("dad"); GameObject trackedFormPos = Instantiate(newFormPos, NextFormPos() + positionOffset, transform.rotation); Destroy(newFormPos); trackedFormPos.name = "Formation Position " + formationPositions.Count + 1; if (!moveTarget) { CreateMoveTarget(); } trackedFormPos.transform.parent = moveTarget.transform; newFP.fromPos = trackedFormPos.transform; newFP.taken = true; newFP.assignedUnit = ta; formationPositions.Add(newFP); return(newFP.fromPos); } }
void AssignToGeneral(TroopActorNetworked ta) { rankState = RankState.FollowingGeneral; myGeneral = ta; if (moveTarget) { Destroy(moveTarget); } moveTarget = ta.AllocateTarget(this).gameObject; }
bool withinRange(GunSettingsNetworked gun, TroopActorNetworked troop) { if (Vector3.Distance(troop.transform.position, transform.position) > gun.attackRangeMin && Vector3.Distance(troop.transform.position, transform.position) < gun.attackRangeMax) { return(true); } else { return(false); } }
void AttackTarget() { if (targetToAttack.rankState != RankState.dead) { AttackSelectedEnemy(targetToAttack); } else { attackType = AttackType.AUTO; Move(); targetToAttack = null; } }
bool CanHitTarget(TroopActorNetworked checkThis) { bool canHit = false; foreach (UnitClasses uc in strengths) { if (checkThis.unitClass == uc) { canHit = true; } } return(canHit); }
private void OnTriggerEnter(Collider other) { TroopActorNetworked currentActor = other.GetComponent <TroopActorNetworked>(); if (currentActor) { if (other.GetComponent <TroopActorNetworked>().team == Team.TEAM1) { team1unitsInZone.Add(other.GetComponent <TroopActorNetworked>()); } else if (other.GetComponent <TroopActorNetworked>().team == Team.TEAM2) { team2unitsInZone.Add(other.GetComponent <TroopActorNetworked>()); } } }
public void PromoteToGeneral(TroopActorNetworked ta) { ta.OnBecomeGeneral.Invoke(); ta.rankState = RankState.IsGeneral; ta.moveTarget = null; if (ta.team == Team.TEAM1) { op.team1Generals.Add(ta); } if (ta.team == Team.TEAM2) { op.team2Generals.Add(ta); } }
void SpawnObject() { TroopActorNetworked ta = ObjectToSpawnAvaliable(); lastSpawnedObject = ta.gameObject; if (ta.gameObject.activeInHierarchy == false) { ta.gameObject.SetActive(true); } //ta.SetHealth(ta.maxHealth); ta.rankState = RankState.LookingForGeneral; ta.transform.position = spawnPoint.position; }
TroopActorNetworked ClosestGeneral() { float dis = 0f; TroopActorNetworked closestAlly = null; foreach (TroopActorNetworked ta in op.allTroopActors) { if (ta.rankState != RankState.dead) { if ((dis == 0f || Vector3.Distance(ta.transform.position, transform.position) < dis) && ta != this && ta.team == team && ta.rankState == RankState.IsGeneral) { dis = Vector3.Distance(ta.transform.position, transform.position); closestAlly = ta; } } } return(closestAlly); }
TroopActorNetworked ClosestEnemy(GunSettingsNetworked gun) { float dis = 0f; TroopActorNetworked closestEnemy = null; foreach (TroopActorNetworked ta in op.allTroopActors) { if (ta.rankState != RankState.dead) { if ((dis == 0f || Vector3.Distance(ta.transform.position, transform.position) < dis) && EnemyInRange(ta.transform, gun) && ta != this && ta.team != team) { dis = Vector3.Distance(ta.transform.position, transform.position); closestEnemy = ta; } } } return(closestEnemy); }
public void Die(TroopActorNetworked ta) { ta.onDie.Invoke(); if (ta.rankState == RankState.IsGeneral) { if (ClosestAlly()) { ta.PromoteToGeneral(ClosestAlly()); } ta.rankState = RankState.dead; if (moveTarget) { Destroy(moveTarget.gameObject); } } ta.rankState = RankState.dead; if (ta.team == Team.TEAM1) { op.team1Generals.Remove(ta); } if (ta.team == Team.TEAM2) { op.team2Generals.Remove(ta); } if (!GeneralsRemaining()) { Invoke("Victory", 2f); if (team == Team.TEAM1) { FindObjectOfType <FindWinner>().TriggerTeam2Win(); } else { FindObjectOfType <FindWinner>().TriggerTeam1Win(); } } }
void AttackSelectedEnemy(TroopActorNetworked troopToAttack) { foreach (GunSettingsNetworked gun in guns) { if (troopToAttack && withinRange(gun, troopToAttack)) { gun.attackTarget = ClosestEnemy(gun); gun.turret.rotation = Quaternion.Slerp(gun.turret.rotation, Quaternion.LookRotation(gun.attackTarget.transform.position - gun.turret.position), gun.turretAimSpeed * Time.deltaTime); gun.turret.localEulerAngles = new Vector3(0, gun.turret.localEulerAngles.y, 0); gun.barrel.rotation = Quaternion.Slerp(gun.barrel.rotation, Quaternion.LookRotation(gun.attackTarget.transform.position - gun.barrel.position), gun.barrelAimSpeed * Time.deltaTime); gun.barrel.localEulerAngles = new Vector3(gun.barrel.localEulerAngles.x, 0, 0); gun.m_gunTimer -= Time.deltaTime; if (gun.m_gunTimer < Time.deltaTime) { ResetGunTimer(gun); Fire(gun); } } } }
// Update is called once per frame void Update() { try { m_controller = InputManager.Devices[0]; } catch (System.Exception) { return; } if (m_generals.Count == 0) { Destroy(currentSelectionCircle); } QuickSelect(); if (isClient && !isServer) { if (m_controller.Action1.WasPressed) { m_generals[tankIndex].moveTarget.transform.position = m_nmn.m_currentMarker.transform.position; m_generals[tankIndex].CmdUpdateMoveTargetPosition(m_nmn.m_currentMarker.transform.position, m_nmn.m_currentMarker.transform.rotation); } } else { if (m_controller.Action1.WasPressed) { m_generals[tankIndex].RpcUpdateMoveTargetPosition(m_nmn.m_currentMarker.transform.position, m_nmn.m_currentMarker.transform.rotation); } } if (m_controller.DPadLeft.WasPressed && m_generals.Count > 1) { //destory the currect circle if (currentSelectionCircle != null) { Destroy(currentSelectionCircle); } CheckGeneralState(false, true); } if (m_controller.DPadRight.WasPressed && m_generals.Count > 1) { //destory the currect circle if (currentSelectionCircle != null) { Destroy(currentSelectionCircle); } CheckGeneralState(true, false); } if (m_nmn.m_tank != null && m_controller.Action1.WasPressed && !m_nmn.m_airStrikeState) { UnitToAttack = m_nmn.m_tank; } else if (m_nmn.m_tank == null && m_controller.Action1.WasPressed && !m_nmn.m_airStrikeState) { UnitToAttack = null; m_generals[tankIndex].targetToAttack = null; m_generals[tankIndex].SetAttackType(AttackType.AUTO); foreach (TroopActorNetworked T in m_op.allTroopActors) { if (T.myGeneral == m_generals[tankIndex]) { T.targetToAttack = null; T.SetAttackType(AttackType.AUTO); } } m_generals[tankIndex].moveTarget.transform.position = m_nmn.m_currentMarker.transform.position; m_generals[tankIndex].moveTarget.transform.rotation = m_nmn.m_currentMarker.transform.rotation; } SquadGangAttackSelectedUnit(); if (currentSelectionCircle != null && tankIndex >= 0 && m_generals.Count > 0) { currentSelectionCircle.transform.position = m_generals[tankIndex].transform.position; } }