public void UpdateTargetList() { List <BaseEntity> list = Facepunch.Pool.GetList <BaseEntity>(); Vis.Entities <BaseEntity>(base.transform.position, this.searchRange, list, 133120, QueryTriggerInteraction.Collide); foreach (BaseEntity baseEntity in list) { if (!(baseEntity is BasePlayer)) { continue; } BasePlayer basePlayer = baseEntity as BasePlayer; if (basePlayer.IsDead() || basePlayer is Scientist || !this.VisibilityTest(baseEntity)) { continue; } bool flag = false; foreach (BradleyAPC.TargetInfo targetInfo in this.targetList) { if (targetInfo.entity != baseEntity) { continue; } targetInfo.lastSeenTime = UnityEngine.Time.time; flag = true; goto Label0; } Label0: if (flag) { continue; } BradleyAPC.TargetInfo targetInfo1 = Facepunch.Pool.Get <BradleyAPC.TargetInfo>(); targetInfo1.Setup(baseEntity, UnityEngine.Time.time); this.targetList.Add(targetInfo1); } for (int i = this.targetList.Count - 1; i >= 0; i--) { BradleyAPC.TargetInfo item = this.targetList[i]; BasePlayer basePlayer1 = item.entity as BasePlayer; if (item.entity == null || UnityEngine.Time.time - item.lastSeenTime > this.memoryDuration || basePlayer1.IsDead()) { this.targetList.Remove(item); Facepunch.Pool.Free <BradleyAPC.TargetInfo>(ref item); } } Facepunch.Pool.FreeList <BaseEntity>(ref list); this.targetList.Sort(new Comparison <BradleyAPC.TargetInfo>(this.SortTargets)); }
public void AddOrUpdateTarget(BaseEntity ent, Vector3 pos, float damageFrom = 0f) { BradleyAPC.TargetInfo targetInfo; if (!(ent is BasePlayer)) { return; } BradleyAPC.TargetInfo targetInfo1 = null; foreach (BradleyAPC.TargetInfo targetInfo2 in this.targetList) { if (targetInfo2.entity != ent) { continue; } targetInfo1 = targetInfo2; if (targetInfo1 == null) { targetInfo1 = Facepunch.Pool.Get <BradleyAPC.TargetInfo>(); targetInfo1.Setup(ent, UnityEngine.Time.time - 1f); this.targetList.Add(targetInfo1); } targetInfo1.lastSeenPosition = pos; targetInfo = targetInfo1; targetInfo.damageReceivedFrom += damageFrom; return; } if (targetInfo1 == null) { targetInfo1 = Facepunch.Pool.Get <BradleyAPC.TargetInfo>(); targetInfo1.Setup(ent, UnityEngine.Time.time - 1f); this.targetList.Add(targetInfo1); } targetInfo1.lastSeenPosition = pos; targetInfo = targetInfo1; targetInfo.damageReceivedFrom += damageFrom; }
public void UpdateMovement_Hunt() { float single; if (Interface.CallHook("OnBradleyApcHunt", this) != null) { return; } if (this.patrolPath == null) { return; } BradleyAPC.TargetInfo item = this.targetList[0]; if (item.IsValid()) { if (this.HasPath() && item.IsVisible()) { if (this.currentPath.Count > 1) { Vector3 vector3 = this.currentPath[this.currentPathIndex]; this.ClearPath(); this.currentPath.Add(vector3); this.finalDestination = vector3; this.currentPathIndex = 0; return; } } else if (UnityEngine.Time.time > this.nextEngagementPathTime && !this.HasPath() && !item.IsVisible()) { bool flag = false; BasePathNode closestToPoint = this.patrolPath.GetClosestToPoint(base.transform.position); List <BasePathNode> list = Facepunch.Pool.GetList <BasePathNode>(); if (this.GetEngagementPath(ref list)) { flag = true; closestToPoint = list[list.Count - 1]; } BasePathNode basePathNode = null; List <BasePathNode> basePathNodes = Facepunch.Pool.GetList <BasePathNode>(); this.patrolPath.GetNodesNear(item.lastSeenPosition, ref basePathNodes, 30f); Stack <BasePathNode> basePathNodes1 = null; float single1 = Single.PositiveInfinity; float single2 = this.mainTurretEyePos.localPosition.y; foreach (BasePathNode basePathNode1 in basePathNodes) { Stack <BasePathNode> basePathNodes2 = new Stack <BasePathNode>(); if (!item.entity.IsVisible(basePathNode1.transform.position + new Vector3(0f, single2, 0f), Single.PositiveInfinity) || !AStarPath.FindPath(closestToPoint, basePathNode1, out basePathNodes2, out single) || single >= single1) { continue; } basePathNodes1 = basePathNodes2; single1 = single; basePathNode = basePathNode1; } if (basePathNodes1 != null) { this.currentPath.Clear(); if (flag) { for (int i = 0; i < list.Count - 1; i++) { this.currentPath.Add(list[i].transform.position); } } foreach (BasePathNode basePathNode2 in basePathNodes1) { this.currentPath.Add(basePathNode2.transform.position); } this.currentPathIndex = -1; this.pathLooping = false; this.finalDestination = basePathNode.transform.position; } Facepunch.Pool.FreeList <BasePathNode>(ref basePathNodes); Facepunch.Pool.FreeList <BasePathNode>(ref list); this.nextEngagementPathTime = UnityEngine.Time.time + 5f; } } }
public int SortTargets(BradleyAPC.TargetInfo t1, BradleyAPC.TargetInfo t2) { float priorityScore = t2.GetPriorityScore(this); return(priorityScore.CompareTo(t1.GetPriorityScore(this))); }