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 bool Execute(UnitOrder order) { var ability = order.GetAbilityToCast(); if (ability == null) { return(true); } var unit = order.GetUnit(); var target = ChunkManager.GetChunkByNum(unit.ChunkNumber).GetGameObjectByIndex(order.GetTo().Index); ability.CurrentCooldown = ability.GetCooldown(); var succ = ability.OnSpellStart(unit, target as GameUnit); if (ability.PostCurrent >= 0) { ability.CurrentCooldown = ability.PostCurrent; ability.PostCurrent = -1; } return(succ); }
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 bool AttackTo(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 chunk = ChunkManager.GetChunkByNum(ent.ChunkNumber); var attackedObj = chunk.GetGameObjectByIndex(ChunkUtil.GetUpper(moveTo.Index)); if (attackedObj == null) { return(MoveTo(ent)); } var attackedEnt = attackedObj.GetComponent <GameUnit>(); if (attackedEnt == null) { return(true); } if (attackedEnt.Owner == ent.Owner) { return(MoveTo(ent)); } UnitBar_HTML.SetupUnitBar(attackedEnt); ent.State = EventManager.InProgressEvents.Attack; if (!ent.AlreadyAttacked && Mathf.Abs(vec.x) <= MinDist && Mathf.Abs(vec.y) <= MinDist) { // ent.transform.position = ent.Current3Dpos; ent.AlreadyAttacked = true; attackedEnt.DealDamage(ent.UpgradedStats.Dmg, ent); return(false); } if (ent.AlreadyAttacked) { var checkMove = MoveTo(ent); if (checkMove) { ent.AlreadyAttacked = false; } return(false); } ent.MovingTo = moveTo; var moveSpeed = GameMoveManager.StaticMoveSpeed; var speedVec = vec * moveSpeed / 2f * Time.deltaTime; ent.transform.Translate(speedVec); return(false); }