public static void CancelOrders(GameUnit unit) { if (OrderList.ContainsKey(unit)) { //OrderList[ent].Clear(); var unitOrders = OrderList[unit]; var cancList = CanceledOrderList.ContainsKey(unit) ? CanceledOrderList[unit] : new List <UnitOrder>(); cancList.AddRange(unitOrders); CanceledOrderList[unit] = cancList; } if (!unit.IsMoving) { return; } var tilePos = unit.CurrentTilePosition; tilePos.Index = ChunkUtil.GetDovvner(tilePos.Index); AddOrder(unit, new List <UnitOrder> { new UnitOrder(unit, tilePos, OrderTypes.MoveOrder) }); unit.CanceledOrders = true; }
public Vector3Int GetFreePosAnyLvl() { var emptySlots = new List <Vector3Int>(); for (var i = 0; i < IndexMas[1].Length; i++) { for (var j = 0; j < IndexMas[1][i].Length; j++) { for (int z = 1; z < ChunkManager.MaxGroundsLvls; z++) { if (IndexMas[1][i][j] != -1 || !ChunkUtil.IsGround(ChunkNumber, ChunkUtil.GetDovvner(new Vector3Int(i, j, z)))) { continue; } emptySlots.Add(new Vector3Int(i, j, z)); } } } if (emptySlots.Count == 0) { return(new Vector3Int(0, 0, 0)); } var range = Random.Range(0, emptySlots.Count); return(emptySlots[range]); }
public virtual void KillSelf() { if (Destroyed) { return; } var chunk = ChunkManager.GetChunkByNum(ChunkNumber); chunk.SetIndex(CurrentPos, -1); chunk.RemoveObject(CurrentPos); var ent = chunk.GetGameObjectByIndex(ChunkUtil.GetDovvner(CurrentPos)); if (ent != null) { Coloring.RecolorObject(ent.CurrentPos); } Destroy(gameObject); if (SecondaryGroundLvL.isSecondaryGroup(Group)) { SecondaryGroundLvL.RemovePos(ChunkNumber, CurrentPos); } Destroyed = true; }
public static bool AttackToIndex(GameUnit unit, Vector3Int posTarget) { var goodNeighbour = AI_Calculation.GetNearestNeighbour(unit.ChunkNumber, unit.CurrentPos, posTarget); if (goodNeighbour == Vector3Int.zero || !PathCalcManager.IsReaching(ChunkUtil.GetDovvner(unit.CurrentPos), goodNeighbour)) { return(false); } var path = PresetPath(unit, goodNeighbour); if (path == null) { return(false); } path.Add(new TilePosition( Util.Get3DPosByIndex(posTarget.x, posTarget.y, posTarget.z + 1) , posTarget)); // Debug.Log("Attack order from: " + ent); GameOrderManager.DoOrder(unit, path, OrderTypes.AttackOrder); return(true); }
public static void CastAbility(GameUnit unit, Vector3Int posTarget, Ability ability) { if (unit == null) { return; } if (posTarget == Vector3Int.zero) { return; } var goodNeighbour = AI_Calculation.FindFreePosNearPos(unit.ChunkNumber, ChunkUtil.GetUpper(posTarget), false); if (goodNeighbour == Vector3Int.zero) { Debug.Log("Neighbour is zero"); return; } var neighDist = Util.GetDistanceFromTo(goodNeighbour, posTarget); var dist = Util.GetDistanceFromTo(unit.CurrentPos, posTarget); if (dist > 1) { if (neighDist > 1) { Debug.Log("Error. Cant reach target"); return; } MoveToIndex(unit, ChunkUtil.GetDovvner(goodNeighbour)); } GameOrderManager.AddCastAbilityOrder(unit, new TilePosition(ChunkUtil.GetUpper(posTarget)), ability); }
public static Vector3Int GetNearestNeighbour(int chunkNumber, Vector3Int myPos, Vector3Int pos) { var list = GetGoodNeighbors(chunkNumber, pos); var minDist = -1; var p = new Vector3Int(); foreach (var point in list) { var dist = GetDistTo(myPos, point, true); if (minDist != -1 && dist > minDist) { continue; } if ((ChunkUtil.IsAnyEntity(chunkNumber, ChunkUtil.GetUpper(point)) && myPos != ChunkUtil.GetUpper(point)) || !ChunkUtil.IsCanStayHere(chunkNumber, ChunkUtil.GetDovvner(point)) || !PathCalcManager.IsReaching(ChunkUtil.GetDovvner(myPos), ChunkUtil.GetDovvner(point)) ) { continue; } minDist = dist; p = point; } return(p); }
public static void CalculatePoint(Vector3Int pos) { if (!_preCalculated) { return; } var groundPos = ChunkUtil.GetDovvner(pos); var neighbourPoints = new Vector3Int[4]; neighbourPoints[0] = new Vector3Int(pos.x + 1, pos.y, pos.z - 1); neighbourPoints[1] = new Vector3Int(pos.x - 1, pos.y, pos.z - 1); neighbourPoints[2] = new Vector3Int(pos.x, pos.y + 1, pos.z - 1); neighbourPoints[3] = new Vector3Int(pos.x, pos.y - 1, pos.z - 1); var chunk = ChunkManager.CurrentChunk; foreach (var point in neighbourPoints) { if (!chunk.IsMapPos(point)) { continue; } OnElementCalculate(point.x, point.y, point.z); var ent = chunk.GetGameObjectByIndex(point); if (ent != null) { ent.PathInt = ReachMasInts[point.z][point.x][point.y]; } } OnElementCalculate(groundPos.x, groundPos.y, groundPos.z); }
public GameItem SetupItem(GameEntity ent, string name, Vector3Int pos, Player owner) { var index = Loader.GetIndexByName(name); var npc = LuaNpcGetter.GetNpcById(index); ent.Owner = owner; ent.OriginalName = name; ent.name = name; var item = ent as GameItem; var evoTo = LuaNpcGetter.GetEvolutionTo(npc); if (evoTo.Length > 0) { if (!UnitEvolution.IsHasSoloEvolution(name)) { UnitEvolution.AddToSoloDict(name, evoTo); } if (item != null) { item.SoloEvolution = true; } } var evoCross = LuaNpcGetter.GetNpcEvoCrossing(npc); if (evoCross.Keys.Count > 0) { foreach (var pair in evoCross) { UnitEvolution.AddToStackDict(name, pair.Key, pair.Value); if (!string.Equals(pair.Key, name, StringComparison.OrdinalIgnoreCase)) { UnitEvolution.AddToStackDict(pair.Key, name, pair.Value); } } } if (GroupUtil.IsItem(ent.Group)) { SecondaryGroundLvL.SetGroundEnt(ChunkNumber, pos, item); } if (GroupUtil.isBuilding(ent.Group)) { ChunkManager.AddVision(ent); } ItemEvents.OnCreateItem(item, firstCreate); Coloring.RecolorObject(ChunkUtil.GetDovvner(ent.CurrentPos)); return(item); }
public static bool MoveTo(GameUnit unit, Vector3Int vecTo) { var indexPos = ChunkUtil.GetDovvner(vecTo); var pos3D = Util.Get3DPosByIndex(vecTo); return(MoveExecutor.Execute(new UnitOrder ( unit, new TilePosition(pos3D, indexPos), OrderTypes.MoveOrder ))); }
public static bool IsAttackUnitInMemoryPos(GameUnit unit, GameUnit attackTarget) { if (!unit.IsMoving) { return(false); } var pos = unit.MovingPath.LastOrDefault(); if (pos == null) { return(false); } return(ChunkUtil.GetDovvner(attackTarget.CurrentPos) == pos.Index); }
public static void Update(GameUnit unit) { if (unit == null || unit.gameObject == null) { return; } if (!timeDict.ContainsKey(unit)) { timeDict[unit] = 0; } timeDict[unit] += Time.deltaTime; if (timeDict[unit] < TIME_AI) { return; } timeDict[unit] = 0; var _ai_state = ""; if (AI_Calculation.IsNearEnemy(unit, enemyRadiusCheck)) { var p = new Vector3Int(-1, -1, -1); var path = unit.MovingPath.ToArray().LastOrDefault(); if (path != null) { p = path.Index; } var enemy = AI_Calculation.GetNearEnemy(unit, enemyRadiusCheck); if (!unit.IsMoving || (p != new Vector3Int(-1, -1, -1) && p != ChunkUtil.GetDovvner(enemy.CurrentPos))) { SimpleOrderManager.AttackTarget(unit, enemy as GameUnit); } _ai_state = "AttackEnemy"; } // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (AI_DEBUG && _ai_state != "") { Debug.LogError(unit + " State: " + _ai_state); } }
public GameUnit SetupUnit(GameEntity ent, string name, Vector3Int pos, Player owner) { var index = Loader.GetIndexByName(name); var npc = LuaNpcGetter.GetNpcById(index); ent.Owner = owner; ent.OriginalName = name; ent.name = name; var unit = ent as GameUnit; var evoTo = LuaNpcGetter.GetEvolutionTo(npc); if (evoTo.Length > 0) { if (!UnitEvolution.IsHasSoloEvolution(name)) { UnitEvolution.AddToSoloDict(name, evoTo); } if (unit != null) { unit.SoloEvolution = true; } } var evoCross = LuaNpcGetter.GetNpcEvoCrossing(npc); if (evoCross.Keys.Count > 0) { foreach (var pair in evoCross) { UnitEvolution.AddToStackDict(name, pair.Key, pair.Value); if (!string.Equals(pair.Key, name, StringComparison.OrdinalIgnoreCase)) { UnitEvolution.AddToStackDict(pair.Key, name, pair.Value); } } } ChunkManager.AddVision(ent); UnitEvents.OnUnitSpawned(unit); Coloring.RecolorObject(ChunkUtil.GetDovvner(ent.CurrentPos)); return(unit); }
public virtual bool IsTimeForPickupItem(GameUnit unit) { if (SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, unit.CurrentPos)) { return(false); } var item = SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, unit.CurrentPos); return(item != null && item.CanBePickuped && !item.SoloEvolution && item.Group == "item" && unit.pickUped == null && TreeGroup.IsPickableTreeLog(item) && unit.GroupObj.GetLairPos() != ChunkUtil.GetDovvner(unit.CurrentPos)); }
static List <TilePosition> PresetPath(GameUnit unit, Vector3Int posTarget) { var indexes = unit.PathFindObj.FindPath(ChunkUtil.GetDovvner(unit.CurrentPos), posTarget); // Debug.Log("Path = " + indexes); if (indexes == null) { var chunk = ChunkManager.GetChunkByNum(unit.ChunkNumber); chunk.ReindexTiles(); return(null); } var lastOrDefault = unit.MovingPath.LastOrDefault(); if (lastOrDefault != null && lastOrDefault.Index == posTarget) { return(null); } //Removing first point in some case if (unit.MovingPath.Count > 0 && unit.MovingPath[0].Index != unit.CurrentPos && indexes.Contains(unit.MovingPath[0].Index)) { indexes = indexes.Where(t => t != ChunkUtil.GetDovvner(unit.CurrentPos)).ToList(); } CancelOrders(unit); var path = (from ind in indexes let pos3D = Util.Get3DPosByIndex(ind.x, ind.y, ind.z + 1) select new TilePosition(pos3D, ind)).ToList(); unit.IsMoving = true; unit.MovingPath = path; return(path); }
public static void MoveToIndex(GameUnit unit, Vector3Int posTarget) { if (posTarget == Vector3Int.zero) { return; } var ent = ChunkManager.CurrentChunk.GetGameObjectByIndex(posTarget); var pos = posTarget; if (ent == null || !GroupUtil.IsGround(ent.Group)) { pos = ChunkUtil.GetDovvner(pos); } var path = PresetPath(unit, pos); if (path == null) { return; } GameOrderManager.DoOrder(unit, path, OrderTypes.MoveOrder); }
static void HidingColor(GameEntity ent, GameEntity eUP) { var check = false; if (eUP == null) { var friends = AI_Calculation.GetGoodNeighbors (ChunkManager.CurrentChunk.ChunkNumber, ent.CurrentPos); foreach (var friend in friends) { var fUP = ChunkManager.CurrentChunk.GetGameObjectByIndex (ChunkUtil.GetUpper(friend)); if (fUP != null && !IsHided(fUP)) { check = true; } } } else { check = !IsHided(eUP); } if (!check) { var spD = ent.GetComponent <SpriteRenderer>(); spD.color = static_nonVisionColor; } else { Coloring.RecolorObject(ent, true); Coloring.RecolorObject(ChunkUtil.GetUpper(ent.CurrentPos), true); Coloring.RecolorObject(ChunkUtil.GetDovvner(ent.CurrentPos), true); } }
public override void KillSelf() { if (Destroyed) { return; } var chunk = ChunkManager.GetChunkByNum(ChunkNumber); chunk.SetIndex(CurrentPos, -1); chunk.RemoveObject(CurrentPos); if (pickUped != null) { ItemEvents.OnDeathDropItem(pickUped, this); } ClickManager.RemoveChosing(gameObject); GameMoveManager.CancelAllOrders(this); if (GroupUtil.isCreatureGroup(Group)) { GameOrderManager.RemoveMarks(this); //SimpleOrderManager.CancelOrders(this); if (MovingPath != null) { MovingPath.Clear(); } } if (SecondaryGroundLvL.isSecondaryGroup(Group)) { SecondaryGroundLvL.RemovePos(ChunkNumber, CurrentPos); } if (FlagManager.IsFlagAtPos(CurrentPos)) { FlagManager.RemoveFlag(CurrentPos); } ProgressUnitBar.RemoveProgressBar(this); CreatureGroupManager.RemoveEntFromGroup(this); BuildingsGroupManager.RemoveBuildingFromGroup(this); RemoveAbilities(); if (research != null) { var sameBuilds = BuildingsGroupManager.GetAllInChunkWithName(ChunkNumber, OriginalName); if (sameBuilds.Count == 0) { Owner.RemoveResearch(research); } } Coloring.RecolorObject(ChunkUtil.GetDovvner(CurrentPos)); Owner.foodCount -= foodCost; Owner.foodMax -= foodGive; if (gameObject != null) { Destroy(gameObject); } Destroyed = true; }
public static bool AttackTarget(GameUnit unit, GameUnit target) { return(AttackToIndex(unit, ChunkUtil.GetDovvner(target.CurrentPos))); }
public static GameEntity InitObject(int chunkNumber, string name, Vector3Int vecInt, int index, Table npc, Player owner) { var chunk = GetChunkByNum(chunkNumber); if (chunk == null) { return(null); } var vec = Util.Get3DPosByIndex(vecInt.x, vecInt.y, vecInt.z); var vecIntPos = new Vector3Int(vecInt.x, vecInt.y, vecInt.z); var prefab = Loader.GetPrefabByIndex(index); var obj = Instantiate(prefab, vec + prefab.transform.position, new Quaternion()); if (IsGroupVVithName(prefab.name)) { var trans = GetGroupVVithName(prefab.name); obj.transform.SetParent(trans); } else { var o = new GameObject { name = prefab.name }; o.transform.SetParent(BATYAtrans); Groups.Add(o); obj.transform.SetParent(o.transform); } var group = LuaNpcGetter.GetNpcGroup(npc); Stats stats = null; if (!GroupUtil.IsGround(group)) { stats = LuaNpcGetter.GetStatsFromTable(npc); obj.layer = 9; if (staticFogEnabled) { obj.AddComponent <FogCoverable>(); } } var abilities = new List <Ability>(); if (!GroupUtil.IsGround(group)) { if (!GroupUtil.IsItem(group) && staticFogEnabled) { var spRend = obj.GetComponent <SpriteRenderer>(); if (spRend != null) { spRend.enabled = false; } } if (!GroupUtil.IsNeutral(group) && !GroupUtil.IsItem(group)) { var npcAbilitiesNames = LuaNpcGetter.GetNpcAbilitiesNames(npc); foreach (var KV in npcAbilitiesNames) { var ability = LuaAbilitiesGetter.GetAbility(KV.Value); ability.Owner = owner; abilities.Add(ability); } } } GameEntity ent; if (GroupUtil.IsGround(group)) { ent = obj.AddComponent <GameEntity>(); ent.Init(chunkNumber, vecIntPos, false, index); ent.Group = group; chunk.SetIndex(vecIntPos, index); obj.layer = 8; chunk.IndexMas[vecInt.z][vecInt.x][vecInt.y] = index; chunk.Ground[vecInt.z][vecInt.x][vecInt.y] = ent; } else if (GroupUtil.IsItem(group)) { var item = obj.AddComponent <GameItem>(); item.Init(chunkNumber, vecIntPos, false, index, stats); item.Group = group; var npcModifiersNames = LuaNpcGetter.GetNpcModifiersNames(npc); item.ModifierNamesList.AddRange(npcModifiersNames); ent = item; } else { var unit = obj.AddComponent <GameUnit>(); unit.Init(chunkNumber, vecIntPos, false, index, stats); unit.Group = group; var soundVolume = LuaNpcGetter.GetNpcSoundVolume(npc); var soundByIndex = Loader.GetSoundByIndex(index, soundVolume); unit.GameAudio = soundByIndex; unit.itemDrop = LuaNpcGetter.GetNpcItemDrop(npc); CreatureGroupManager.Init(unit); if (GroupUtil.isBuilding(group)) { var researchName = LuaNpcGetter.GetNpcResearch(npc); if (researchName.Length > 0) { var research = ResearchManager.SetupResearch(researchName); unit.research = research; owner.AddResearch(research); AbilityBar_HTML.Update(); } BuildingsGroupManager.Init(unit); } foreach (var ab in abilities) { unit.AddAbility(ab); } ent = unit; chunk.IndexMas[vecInt.z][vecInt.x][vecInt.y] = index; chunk.Ground[vecInt.z][vecInt.x][vecInt.y] = ent; } ent.OriginalName = name; ent.ExtraPos = prefab.transform.position; ent.foodCost = LuaNpcGetter.GetNpcFoodCost(npc); ent.foodGive = LuaNpcGetter.GetNpcFoodGive(npc); owner.foodCount += ent.foodCost; owner.foodMax += ent.foodGive; ent.goldDrop = LuaNpcGetter.GetNpcGoldDrop(npc); //obj.name = prefab.name + "_" + vecInt.z + "_" + vecInt.x + "_" + vecInt.y; PathCalcManager.CalculatePoint(vecInt); PathCalcManager.CalculatePoint(ChunkUtil.GetDovvner(vecInt)); return(ent); }
public static void OnMoveUpdate(GameUnit unit) { if (PauseMenu_HTML.IsPaused) { return; } if (unit.MovingPath.Count == 0 && unit.transform.position != unit.Current3Dpos) { var dist = Util.GetDistanceFromTo(unit.transform.position, unit.Current3Dpos); if (dist > 0.5f) { var tilePos = unit.CurrentTilePosition; tilePos.Index = ChunkUtil.GetDovvner(tilePos.Index); AddOrder(unit, new List <UnitOrder> { new UnitOrder(unit, tilePos, OrderTypes.MoveOrder) }); } else { unit.IsMoving = false; } } if (unit.MovingPath.Count > 0 && !OrderList.ContainsKey(unit)) { GameOrderManager.DoOrder(unit, unit.MovingPath, OrderTypes.AttackOrder); } if (!OrderList.ContainsKey(unit)) { return; } var orders = OrderList[unit].ToArray(); if (orders.Length == 0) { return; } var order = orders[0]; var succ = CallOrderByType(order); if (succ) { var cancList = CanceledOrderList.ContainsKey(unit) ? CanceledOrderList[unit] : new List <UnitOrder>(); cancList.Add(order); CanceledOrderList[unit] = cancList; } if (CanceledOrderList.ContainsKey(unit) && OrderList[unit].Count == CanceledOrderList[unit].Count) { unit.State = EventManager.InProgressEvents.Stay; SimpleOrderManager.CancelOrders(unit); } }
private static Collection <PathNode> GetNeighbours(PathNode pathNode, Vector3Int goal) { var result = new Collection <PathNode>(); // Соседними точками являются соседние по стороне клетки. Vector3Int[] neighbourPoints = new Vector3Int[4]; neighbourPoints[0] = new Vector3Int(pathNode.Position.x + 1, pathNode.Position.y, pathNode.Position.z); neighbourPoints[1] = new Vector3Int(pathNode.Position.x - 1, pathNode.Position.y, pathNode.Position.z); neighbourPoints[2] = new Vector3Int(pathNode.Position.x, pathNode.Position.y + 1, pathNode.Position.z); neighbourPoints[3] = new Vector3Int(pathNode.Position.x, pathNode.Position.y - 1, pathNode.Position.z); var chunk = ChunkManager.CurrentChunk; foreach (var point in neighbourPoints) { // Проверяем, что не вышли за границы карты. if (point.x < 0 || point.x >= chunk.MapSize) { continue; } if (point.y < 0 || point.y >= chunk.MapSize) { continue; } if (ChunkUtil.IsStairsIndex(chunk.ChunkNumber, ChunkUtil.GetUpper(point))) { var p = ChunkUtil.GetUpper(point); point.Set(p.x, p.y, p.z); } else if (!ChunkUtil.IsAnyEntity(chunk.ChunkNumber, point) && ChunkUtil.IsStairsIndex(chunk.ChunkNumber, pathNode.Position)) { var p = ChunkUtil.GetDovvner(point); point.Set(p.x, p.y, p.z); } if (point.z < 0 || point.z >= ChunkManager.MaxGroundsLvls) { continue; } // Проверяем, что по клетке можно ходить. if (IsInvalidPath(point) ) { continue; } // Заполняем данные для точки маршрута. var neighbourNode = new PathNode() { Position = point, CameFrom = pathNode, PathLengthFromStart = pathNode.PathLengthFromStart + GetDistanceBetweenNeighbours(), HeuristicEstimatePathLength = GetHeuristicPathLength(point, goal) }; result.Add(neighbourNode); } return(result); }
private const float MinDist = 0.05f; //0.05f //False if countinue moving private static bool DoMove(UnitOrder order) { var ent = order.GetUnit(); var moveTo = order.GetTo(); if (ent == null) { return(true); } var vec = ((moveTo.Pos3D + ent.ExtraPos) - ent.transform.position); //var idealVec = (moveTo.Pos3D - Util.Get3DPosByIndex(ent.CurrentPos)).normalized; if (Mathf.Abs(vec.x) <= MinDist && Mathf.Abs(vec.y) <= MinDist) { ent.transform.position = moveTo.Pos3D + ent.ExtraPos; ent.MovingTo = null; var upperIndexFrom = ent.CurrentPos; var upperIndexTo = ChunkUtil.GetUpper(moveTo.Index); var chunk = ChunkManager.GetChunkByNum(ent.ChunkNumber); chunk.MoveFromTo(upperIndexFrom, upperIndexTo); ent.CurrentPos = upperIndexTo; if (upperIndexFrom != upperIndexTo) { PathCalcManager.CalculatePoint(upperIndexFrom); } GameOrderManager.RemoveMark(ent, moveTo.Index); return(true); } if (ChunkUtil.GetDovvner(ent.CurrentPos) != order.GetTo().Index&& PathFind.IsInvalidPath(order.GetTo().Index)) { SimpleOrderManager.CancelOrders(ent); } ent.State = EventManager.InProgressEvents.Move; ent.MovingTo = moveTo; var speedMod = GameMoveManager.StaticMoveSpeed; var moveSpeed = ent.EntStats.MoveSpeed; var modVec = MultVector(vec, new Vector3(speedMod, speedMod, 1f)); var speedVec = MultVector(modVec, new Vector3(moveSpeed, moveSpeed, 1f)) // vec * speedMod * Time.deltaTime; if (Mathf.Abs(vec.x) <= MinDist * 3 && Mathf.Abs(vec.y) <= MinDist * 3) { speedVec *= 3; } ent.transform.Translate(speedVec); return(false); }
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); } }