public static bool IsNearEnt(int chunkNumber, Vector3Int pos) { var neighbourPoints = new Vector3Int[8]; neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z); neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z); neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z); neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z); var chunk = ChunkManager.GetChunkByNum(chunkNumber); return((from point in neighbourPoints where chunk.IsMapPos(point) && ChunkUtil.IsEntity(chunkNumber, point) select ChunkUtil.GetIndex(chunkNumber, point)).Any( index => index > 0)); }
public static List <GameUnit> GetNearUnits(int chunkNumber, GameEntity ent, Vector3Int pos) { var neighbourPoints = new Vector3Int[4]; neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z); neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z); neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z); neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z); var chunk = ChunkManager.GetChunkByNum(chunkNumber); return((from point in neighbourPoints where chunk.IsMapPos(point) let index = ChunkUtil.GetIndex(chunkNumber, point) where index > 0 && ChunkUtil.IsEntity(chunkNumber, point) select chunk.GetGameObjectByIndex(point) as GameUnit into obj where obj != null select obj).ToList()); }
public static GameEntity GetNearFriendUnit(int chunkNumber, GameEntity ent, Vector3Int pos) { var neighbourPoints = new Vector3Int[4]; neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z); neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z); neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z); neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z); var chunk = ChunkManager.GetChunkByNum(chunkNumber); return((from point in neighbourPoints where chunk.IsMapPos(point) let index = ChunkUtil.GetIndex(chunkNumber, point) where index > 0 && ChunkUtil.IsEntity(chunkNumber, point) select chunk.GetGameObjectByIndex(point) into obj where obj != null select obj.GetComponent <GameEntity>()).FirstOrDefault(entEnemy => Equals(entEnemy.Owner, ent.Owner))); }
public static GameEntity GetNearEnemy(GameEntity ent, int radius) { var chunkNumber = ent.ChunkNumber; var chunk = ChunkManager.GetChunkByNum(chunkNumber); var pos = ent.CurrentPos; var neighbourPoints = new Vector3Int[8]; for (var i = 0; i < radius; i++) { neighbourPoints[0] = new Vector3Int(pos.x + i, pos.y, pos.z); neighbourPoints[1] = new Vector3Int(pos.x - i, pos.y, pos.z); neighbourPoints[2] = new Vector3Int(pos.x, pos.y + i, pos.z); neighbourPoints[3] = new Vector3Int(pos.x, pos.y - i, pos.z); neighbourPoints[4] = new Vector3Int(pos.x + i, pos.y + i, pos.z); neighbourPoints[5] = new Vector3Int(pos.x - i, pos.y - i, pos.z); neighbourPoints[6] = new Vector3Int(pos.x - i, pos.y + i, pos.z); neighbourPoints[7] = new Vector3Int(pos.x + i, pos.y - i, pos.z); var enemy = (from point in neighbourPoints where chunk.IsMapPos(point) let index = ChunkUtil.GetIndex(chunkNumber, point) where index > 0 && ChunkUtil.IsEntity(chunkNumber, point) select chunk.GetGameObjectByIndex(point) into obj where obj != null select obj.GetComponent <GameEntity>()).FirstOrDefault(entEnemy => !Equals(entEnemy.Owner, ent.Owner)); if (enemy != null) { return(enemy); } } return(null); }
public static void Update(AbstractGameObject unit) { var EvolutionTime = unit.EvolutionTime; if (unit.State != EventManager.InProgressEvents.Stay) { ProgressUnitBar.RemoveProgressBar(unit); if (stackTarget.ContainsKey(unit)) { var target = stackTarget[unit]; var progressName = ProgressUnitBar.ProgressName.GroupEvolution; ProgressUnitBar.RemoveProgressBar(target, progressName); stackTarget.Remove(unit); stackTarget.Remove(target); } return; } var chunk = ChunkManager.GetChunkByNum(unit.ChunkNumber); //Solo evolution if (unit.SoloEvolution) { var progressName = ProgressUnitBar.ProgressName.SoloEvolution; var pos = unit.CurrentPos; if (!SecondaryGroundLvL.IsEmptyPos(chunk.ChunkNumber, pos) && ChunkUtil.IsAnyEntity(chunk.ChunkNumber, pos)) { ProgressUnitBar.RemoveProgressBar(unit, progressName); return; } ProgressUnitBar.Setup(unit, progressName, EvolutionTime); if (!ProgressUnitBar.IsReady(unit) || !ProgressUnitBar.IsThisProgressName(unit, progressName)) { return; } // Debug.Log("Original name = " + unit.OriginalName); if (SoloEvolutionDict.ContainsKey(unit.OriginalName) || unit.EvolutionNext.Length > 0) { var evoName = ""; evoName = unit.EvolutionNext.Length == 0 ? SoloEvolutionDict[unit.OriginalName] : unit.EvolutionNext; if (evoName.Length > 0) { // Debug.Log("Evolution name = " + evoName); var prevIndex = ChunkUtil.GetIndex(chunk.ChunkNumber, pos); var prevEnt = chunk.GetGameObjectByIndex(pos); var check = unit.PrefabIndex == prevIndex; unit.KillSelf(); if (!SecondaryGroundLvL.IsEmptyPos(chunk.ChunkNumber, pos)) { SecondaryGroundLvL.GetGroundEnt(chunk.ChunkNumber, pos).KillSelf(); SecondaryGroundLvL.RemovePos(chunk.ChunkNumber, pos); } var ent = chunk.PreSetupObject(evoName, pos, unit.Owner); if (GroupUtil.isBuilding(ent.Group) || GroupUtil.IsItem(ent.Group)) { chunk.SetupItem(ent, evoName, pos, unit.Owner); } else { chunk.SetupUnit(ent, evoName, pos, unit.Owner); } } } } //Group evolution else if (stackResult.ContainsKey(unit.OriginalName)) { var progressName = ProgressUnitBar.ProgressName.GroupEvolution; var friends = AI_Calculation.GetNearFriendUnits(chunk.ChunkNumber, unit, unit.CurrentPos); GameEntity target = null; if (stackTarget.ContainsKey(unit)) { target = stackTarget[unit]; } if (target != null && !friends.Contains(target as GameUnit)) { ProgressUnitBar.RemoveProgressBar(target, progressName); target = null; stackTarget.Remove(unit); } foreach (var obj in friends) { if (obj.Destroyed) { continue; } if (!stackResult[unit.OriginalName].ContainsKey(obj.OriginalName)) { continue; } if (obj.State != EventManager.InProgressEvents.Stay) { continue; } stackTarget[unit] = obj; target = obj; break; } if (target == null) { return; } ProgressUnitBar.Setup(unit, progressName, EvolutionTime); //EvolutionTimeList[target] = EvolutionTimeList[ent]; // UpdateProgressBar(target); if (!ProgressUnitBar.IsReady(unit) || !ProgressUnitBar.IsThisProgressName(unit, progressName)) { return; } var evoName = stackResult[unit.OriginalName][target.OriginalName]; var pos = unit.CurrentPos; var owner = unit.Owner; unit.KillSelf(); target.KillSelf(); var evoUnit = chunk.SetupUnit(evoName, pos, owner); QuestManager.OnEvolution(evoUnit); Coloring.RecolorObject(ChunkUtil.GetDovvner(unit.CurrentPos)); Coloring.RecolorObject(ChunkUtil.GetDovvner(target.CurrentPos)); UnitEvents.OnEvolution(evoUnit); PathCalcManager.CalculatePoint(ChunkUtil.GetDovvner(pos)); PathCalcManager.CalculatePoint(pos); } }