public bool KillObjectByAlias(string alias) { PoolSlot slot = mObjPool.UsedList(); while (slot != null) { ObjectBase obj = slot.Content as ObjectBase; if (obj == null) { slot = slot.NextSlot; continue; } if (!string.Equals(obj.GetAlias(), alias)) { slot = slot.NextSlot; continue; } if (!typeof(BuildObj).IsAssignableFrom(obj.GetType())) { slot = slot.NextSlot; continue; } BattleUnit unit = obj as BattleUnit; unit.Die(new AttackerAttr(unit)); slot = slot.NextSlot; } return(true); }
/// 搜索掉落物的目标(超出distance距离以外的最近的道具目标); public Pick SearchPickTarget(ObjectBase startObj, float distance) { Pick nearestObj = null; float minDis = float.MaxValue; PoolSlot slot = mObjPool.UsedList(); while (slot != null) { Pick unit = slot.Content as Pick; if (unit == null || unit == startObj || (unit.GetCurPickTableItem().resID != ZombiesStageModule.PickId && unit.GetCurPickTableItem().resID != 26)) { slot = slot.NextSlot; continue; } float dis = Vector3.Distance(unit.GetPosition(), startObj.GetPosition()); //大于最小距离 if (dis >= distance) { if (dis < minDis) { minDis = dis; nearestObj = unit; } } slot = slot.NextSlot; } return(nearestObj); }
public ArrayList SearchBattleUnit(Vector2f center, float radius) { Rectanglef rect = new Rectanglef(new Vector2f(center.x - radius, center.y - radius), new Vector2f(center.x + radius, center.y + radius)); ArrayList objs = new ArrayList(); PoolSlot slot = mObjPool.UsedList(); while (slot != null) { BattleUnit unit = slot.Content as BattleUnit; if (unit == null) { slot = slot.NextSlot; continue; } Vector3f pos = unit.GetPosition3f(); if (Geometryalgorithm2d.point_in_rectangle(new Vector2f(pos.x, pos.z), rect)) { objs.Add(unit); } slot = slot.NextSlot; } return(objs); }
public List <T> SearchObjsByAlias <T>(string alias) where T : ObjectBase { List <T> re = new List <T>(); PoolSlot slot = mObjPool.UsedList(); while (slot != null) { T obj = slot.Content as T; if (obj == null) { slot = slot.NextSlot; continue; } if (!string.Equals(obj.GetAlias(), alias)) { slot = slot.NextSlot; continue; } re.Add(obj); slot = slot.NextSlot; } return(re); }
public Pool(int maxCount = 1000) { if (maxCount < 0) { maxCount = 1000; } mMaxCount = maxCount; mSlot = new PoolSlot[mMaxCount]; for (int i = 0; i < mMaxCount; i++) { mSlot[i] = new PoolSlot(); mSlot[i].Index = i; mSlot[i].PreSlot = null; mSlot[i].NextSlot = null; mSlot[i].Content = null; mSlot[i].Used = false; if (mFreeList != null) { mFreeList.PreSlot = mSlot[i]; mSlot[i].NextSlot = mFreeList; mFreeList = mSlot[i]; } else { mFreeList = mSlot[i]; } } }
public void Clear() { mFreeList = null; mUsedList = null; for (int i = 0; i < mMaxCount; i++) { mSlot[i].Index = i; mSlot[i].PreSlot = null; mSlot[i].NextSlot = null; mSlot[i].Content = null; mSlot[i].Used = false; if (mFreeList != null) { mFreeList.PreSlot = mSlot[i]; mSlot[i].NextSlot = mFreeList; mFreeList = mSlot[i]; } else { mFreeList = mSlot[i]; } } }
//搜索区域内的 BattleUnit public ArrayList SearchObject(SceneShapeRect shape, int searchType, bool ignoreDead = true) { ArrayList objs = new ArrayList(); PoolSlot slot = mObjPool.UsedList(); while (slot != null) { ObjectBase unit = slot.Content as ObjectBase; if (unit == null) { slot = slot.NextSlot; continue; } if (!ObjectType.IsCanSearch(searchType, unit.Type)) { slot = slot.NextSlot; continue; } Vector3 pos = unit.GetPosition(); if (shape.contains(new Vector2(pos.x, pos.z))) { objs.Add(unit); } slot = slot.NextSlot; } if (!ignoreDead) { for (int i = 0; i < mWaitDestoryObjects.Count; ++i) { ObjectBase obj = mWaitDestoryObjects[i]; if (obj == null) { continue; } if (!ObjectType.IsCanSearch(searchType, obj.Type)) { continue; } Vector3 pos = obj.GetPosition(); if (shape.contains(new Vector2(pos.x, pos.z))) { objs.Add(obj); } } } return(objs); }
public bool Remove(int index) { if (index < 0 || index >= mMaxCount) { return(false); } if (mSlot[index] == null) { return(false); } PoolSlot slot = mSlot[index]; if (!slot.Used) { return(false); } PoolSlot preSlot = slot.PreSlot; PoolSlot nextSlot = slot.NextSlot; if (preSlot != null) { preSlot.NextSlot = nextSlot; } if (nextSlot != null) { nextSlot.PreSlot = preSlot; } if (mUsedList == slot) { mUsedList = slot.NextSlot; } slot.Used = false; slot.NextSlot = null; slot.PreSlot = null; slot.Content = null; if (mFreeList != null) { mFreeList.PreSlot = slot; slot.NextSlot = mFreeList; mFreeList = slot; } else { mFreeList = slot; } mCount--; return(true); }
//搜索一个自动瞄准的目标 public BattleUnit SearchAutoAimEnemy(BattleUnit owner, float distance) { BattleUnit nearestObj = null; float minDis = distance; PoolSlot slot = mObjPool.UsedList(); while (slot != null) { BattleUnit unit = slot.Content as BattleUnit; if (unit == null) { slot = slot.NextSlot; continue; } if (unit == owner) { slot = slot.NextSlot; continue; } if (!unit.isAlive()) { slot = slot.NextSlot; continue; } if (!owner.IsEnemy(unit)) { slot = slot.NextSlot; continue; } float dis = Vector3.Distance(unit.GetPosition(), owner.GetPosition()); //小于最大距离 if (dis <= distance) { if (dis < minDis) { minDis = dis; nearestObj = unit; } } slot = slot.NextSlot; } return(nearestObj); }
public int Put(object obj) { if (obj == null) { return(-1); } if (mFreeList == null) { return(-1); } PoolSlot useSlot = mFreeList; mFreeList = useSlot.NextSlot; if (mFreeList != null) { mFreeList.PreSlot = null; } useSlot.Used = true; useSlot.NextSlot = null; useSlot.PreSlot = null; useSlot.Content = obj; if (mUsedList != null) { mUsedList.PreSlot = useSlot; useSlot.NextSlot = mUsedList; mUsedList = useSlot; } else { mUsedList = useSlot; } mCount++; return(useSlot.Index); }
public bool RemoveObjectByAlias(string alias) { PoolSlot slot = mObjPool.UsedList(); while (slot != null) { ObjectBase obj = slot.Content as ObjectBase; if (obj == null) { slot = slot.NextSlot; continue; } if (string.Equals(obj.GetAlias(), alias)) { RemoveObject(obj.InstanceID); } slot = slot.NextSlot; } return(true); }
public void Update(uint elapsed) { for (int i = 0; i < mWaitDestoryObjects.Count; ++i) { ObjectBase obj = mWaitDestoryObjects[i]; if (obj == null) { continue; } if (!obj.UpdateDestroy(elapsed)) { mWaitDestoryObjects.RemoveAt(i); mDestoryObjects.Add(obj); break; } } PoolSlot slot = mObjPool.UsedList(); while (slot != null) { ObjectBase obj = slot.Content as ObjectBase; if (obj == null) { slot = slot.NextSlot; continue; } if (!obj.Update(elapsed)) { if (obj.IsDestroyWaiting()) { mWaitDestoryObjects.Add(obj); } else { mDestoryObjects.Add(obj); } slot = slot.NextSlot; mObjPool.Remove((int)obj.InstanceID); continue; } slot = slot.NextSlot; } for (int i = 0; i < mDestoryObjects.Count; ++i) { ObjectBase obj = mDestoryObjects[i]; if (obj == null) { continue; } obj.Destroy(); } mDestoryObjects.Clear(); }