public static bool Execute(UnitOrder order) { //Debug.Log("Executing to pos - " + order.GetTo().Index); var index = ChunkUtil.GetUpper(order.GetTo().Index); var chunkNumber = order.GetUnit().ChunkNumber; var chunk = ChunkManager.GetChunkByNum(chunkNumber); if (order.GetUnit().CurrentPos != index && ChunkUtil.IsAnyEntity(chunkNumber, index)) { var obj = chunk.GetGameObjectByIndex(index); if (obj == null) { return(GameMoveManager.CancelPathVVay(order.GetUnit())); //return false; } var underEnt = obj.GetComponent <GameEntity>(); if (underEnt.Owner != order.GetUnit().Owner) { return(AttackTo(order)); } //Debug.Log("Cancel attacking"); return(GameMoveManager.CancelPathVVay(order.GetUnit())); //return false; } //Debug.Log("Moving to: " + order.GetTo().Index); return(MoveExecutor.Execute(order)); }
public static GameItem SpawnItem(string itemName, Vector3Int pos, Player owner) { if (owner == null) { owner = PlayersManager.Empty; } GameEntity ent = null; var chunk = ChunkManager.CurrentChunk; if (ChunkUtil.IsAnyEntity(chunk.ChunkNumber, pos)) { ent = chunk.GetGameObjectByIndex(pos); } if (!SecondaryGroundLvL.IsEmptyPos(chunk.ChunkNumber, pos)) { SecondaryGroundLvL.GetGroundEnt(chunk.ChunkNumber, pos).KillSelf(); } var item = chunk.SetupItem(itemName, pos, owner); SecondaryGroundLvL.SetGroundEnt(chunk.ChunkNumber, pos, item); chunk.SetIndex(pos, -1); chunk.SetObjectAtPos(pos, null); if (ent != null) { chunk.SetIndex(pos, ent.PrefabIndex); chunk.SetObjectAtPos(pos, ent); } return(item); }
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 bool IsInvalidPoint(int chunkNumber, Vector3Int point) { return((point.z + 1 < ChunkManager.MaxGroundsLvls && ChunkUtil.IsAnyEntity(chunkNumber, ChunkUtil.GetUpper(point))) || ChunkUtil.IsGround(chunkNumber, point) || ChunkUtil.IsEntity(chunkNumber, point)); }
public static bool IsInvalidPath(Vector3Int point) { var chunkNumber = ChunkManager.CurrentChunk.ChunkNumber; return((point.z + 1 < ChunkManager.MaxGroundsLvls && ChunkUtil.IsAnyEntity(chunkNumber, ChunkUtil.GetUpper(point))) || ChunkUtil.IsMarkedIndex(chunkNumber, point) || ChunkUtil.IsEntity(chunkNumber, point)); }
public virtual bool IsTimeForDeliverItem(GameUnit unit) { var lairPos = ChunkUtil.GetUpper(unit.GroupObj.GetLairPos()); if (unit.pickUped == null || !unit.GroupObj.IsSetUpedLairPos(unit) || (ChunkUtil.IsAnyEntity(unit.ChunkNumber, lairPos) && unit.CurrentPos != lairPos)) { return(false); } if (!SecondaryGroundLvL.IsEmptyPos(unit.ChunkNumber, lairPos)) { return(ItemGroup.IsCanBeStacked(unit.pickUped.OriginalName, SecondaryGroundLvL.GetGroundEnt(unit.ChunkNumber, lairPos).OriginalName)); } return(true); }
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); }
public static void RecolorObject(GameEntity ent, bool trueCall) { if (ent == null || ((Recolor.IsHided(ent) && !trueCall) && ChunkManager.staticFogEnabled)) { return; } var mod = 3f; var upper = ChunkUtil.GetUpper(ent.CurrentPos); if ((ChunkUtil.IsAnyEntity(ent.ChunkNumber, upper) || !SecondaryGroundLvL.IsEmptyPos(ent.ChunkNumber, upper)) && ent.CurrentPos.z + 1 != ChunkManager.MaxGroundsLvls) { mod += 2.5f; } var i = 1f / ((ent.CurrentPos.z + mod) * 0.3f); var color = new Color(i, i, i); if (ChunkUtil.IsEntity(ent.ChunkNumber, upper) && ent.CurrentPos.z + 1 != ChunkManager.MaxGroundsLvls) { var chunk = ChunkManager.GetChunkByNum(ent.ChunkNumber); var upperEnt = chunk.GetGameObjectByIndex(upper); if (upperEnt != null) { if (TreeGroup.IsTreeGroup(upperEnt.Group)) { color.r = 0.5f; color.b = 0.7f; color.g = 0.3f; } else if (upperEnt.Group == "rock") { color.r = 0.3f; color.b = 0.7f; color.g = 0.2f; } else if (upperEnt is GameUnit) { var unit = upperEnt as GameUnit; if (unit.IsEnemy(PlayersManager.GetMyPlayer())) { color.r = 1; color.b = 0.3f; color.g = 0.3f; } else { color.r = 0.1f; color.b = 0.1f; color.g = 0.6f; } } else { color.r = 0.1f; color.b = 0.1f; color.g = 0.6f; } } } if (!GroupUtil.isCreatureGroup(ent.Group) && !GroupUtil.isBuilding(ent.Group)) { var spriteRenderer = ent.GetComponent <SpriteRenderer>(); spriteRenderer.color = color; } }
void RghtClickedOnGameObject(GameObject obj) { if (_choosed) { var from = _choosedObj.GetComponent <GameUnit>(); if (from == null || !from.IsMy()) { return; } var to = obj.GetComponent <GameEntity>(); if (to == null) { return; } if (!GroupUtil.isCreatureGroup(from.Group)) { return; } if (!FieldOfView.IsVisible(to) && !GroupUtil.IsGround(to.Group)) { ClickedOnSpace(); return; } Vector3Int f; if (from.MovingTo != null) { f = from.MovingTo.Index; } else { f = from.CurrentPos; f.z--; } //Cant move ? if (from.UpgradedStats.MoveSpeed <= 0f) { SimpleOrderManager.CancelOrders(from); ErrorBar_HTML.SetupError("This unit can`t move!"); return; } //Attack var t = to.CurrentPos; var buildingCheck = false; if (ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(t))) { var underGround = ChunkManager.CurrentChunk.GetGameObjectByIndex(ChunkUtil.GetUpper(t)); var underEnt = underGround.GetComponent <GameEntity>(); if (SecondaryGroundLvL.isSecondaryGroup(underEnt.Group)) { buildingCheck = true; } if (!GroupUtil.IsGround(underEnt.Group) && underEnt.Owner != PlayersManager.GetMyPlayer()) { var underP = underEnt.CurrentPos; underP.z++; if (!ChunkManager.CurrentChunk.IsMapPos(underP) || !ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(underEnt.CurrentPos))) { if (from.UpgradedStats.Dmg > 0) { SimpleOrderManager.AttackToIndex(from, t); } else if (from.UpgradedStats.Dmg == 0) { ErrorBar_HTML.SetupError("This unit can`t attack!"); } return; } } } //Cancel or Move if ((ChunkUtil.IsAnyEntity(from.ChunkNumber, ChunkUtil.GetUpper(t)) || !PathCalcManager.IsReaching(f, t)) && !buildingCheck) { ErrorBar_HTML.SetupError("Can`t reach that place!"); SimpleOrderManager.CancelOrders(from); } else if (ChunkUtil.IsCanStayHere(from.ChunkNumber, t) || buildingCheck) { SimpleOrderManager.MoveToIndex(from, t); } } else { var clicked = obj.GetComponent <GameEntity>(); if (clicked == null) { return; } var pos = clicked.CurrentPos; if (FlagManager.IsFlagAtPos(pos)) { FlagManager.RemoveFlag(pos); } else { FlagManager.SetupFlag(pos); } } }
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); } }