private Gunner FindMinHPTargetInList(GameObject[] spaceShipList, float refAngle, float fanAngle, Vector3 from, float minDist) { if (spaceShipList == null) { return(null); } float halfAngle = fanAngle * 0.5f; float minHP = float.MaxValue; Gunner targetCtrl = null; foreach (GameObject spcShip in spaceShipList) { SpaceShipCtrl ctrl = spcShip.GetComponent <SpaceShipCtrl>(); if ((ctrl.Position - from).magnitude < minDist) { continue; } SpaceShip_GhostCtrl ghost = ctrl as SpaceShip_GhostCtrl; if (ghost != null) { if (ghost.Visible == false) { continue; } } if (refAngle == 0) { if (0 <= ctrl.AngleFromPlanetUp && (halfAngle > ctrl.AngleFromPlanetUp || 360f - halfAngle < ctrl.AngleFromPlanetUp)) { if (ctrl.CurHP < minHP) { targetCtrl = ctrl; minHP = ctrl.CurHP; } } } else { if (refAngle - halfAngle <= ctrl.AngleFromPlanetUp && refAngle + halfAngle > ctrl.AngleFromPlanetUp) { if (ctrl.CurHP < minHP) { targetCtrl = ctrl; minHP = ctrl.CurHP; } } } } return(targetCtrl); }
private Gunner FindBossTargetInList(GameObject[] spaceShipList, float refAngle, float fanAngle, Vector3 from, float minDist) { if (spaceShipList == null) { return(null); } float halfAngle = fanAngle * 0.5f; foreach (GameObject spcShip in spaceShipList) { SpaceShipCtrl ctrl = spcShip.GetComponent <SpaceShipCtrl>(); if ((ctrl.Position - from).magnitude < minDist) { continue; } SpaceShip_GhostCtrl ghost = ctrl as SpaceShip_GhostCtrl; if (ghost != null) { if (ghost.Visible == false) { continue; } } if (refAngle == 0) { if (0 <= ctrl.AngleFromPlanetUp && (halfAngle > ctrl.AngleFromPlanetUp || 360f - halfAngle < ctrl.AngleFromPlanetUp)) { if (ctrl.SpaceShipType == MobType.ZombieShip || ctrl.SpaceShipType == MobType.BattleShip || ctrl.SpaceShipType == MobType.GhostShip) { return(ctrl); } } } else { if (refAngle - halfAngle <= ctrl.AngleFromPlanetUp && refAngle + halfAngle > ctrl.AngleFromPlanetUp) { if (ctrl.SpaceShipType == MobType.ZombieShip || ctrl.SpaceShipType == MobType.BattleShip || ctrl.SpaceShipType == MobType.GhostShip) { return(ctrl); } } } } return(null); }