protected override void Death() { base.Death(); Loc.GetTileController().OnEntityLeaving(); AIManager.Instance.OnBotDeath(this); }
/// <summary> /// set anim false generally means move entity to one place instantly without move cost (e.g. by skill effect). /// </summary> /// <param name="targetLoc"></param> /// <param name="isInstance"></param> public virtual int MoveToTile(Location targetLoc, int moveCost, bool isInstance = false) { if (targetLoc == Loc) { return(0); } // Calculate movement path if (!isInstance) { Stack <Location> path = GridManager.Instance.Nav.GetPath(Loc, targetLoc); if (path.Count * moveCost > ActionPoints) { return(0); } MovePath = path.ToArray(); } if (isInstance) { Loc.GetTileController().OnEntityLeaving(); Loc = targetLoc; Loc.GetTileController().OnEntityEntering(Hash); AnimationManager.Instance.AddAnimClip(new MoveInstantAnimClip(Hash, targetLoc, 0.2f)); AnimationManager.Instance.PlayOnce(); } else { int stepID = 0, passedCount = 0; for (int i = 0; i < MovePath.Length; i++) { if (MovePath[i].GetTileController().HasImpacts || i == MovePath.Length - 1) { if (stepID * moveCost > ActionPoints) { OnMovedEvent?.Invoke(i); return(i); } SubMoveToTile(passedCount, stepID); stepID = 0; passedCount = i + 1; continue; } stepID++; } // AP cost ImpactActionPoints(passedCount * moveCost, true); } int movementSteps = isInstance ? 0 : MovePath.Length; // Pass move condition OnMovedEvent?.Invoke(movementSteps); return(movementSteps); }
public virtual void SubMoveToTile(int passedCount, int stepID) { //Debug.Log("pass: "******", step: " + stepID); Location[] subPath = MovePath.Skip(passedCount).Take(stepID + 1).ToArray(); //Debug.Log("mov: " + MovePath.Length + ", sub: " + subPath.Length); Loc.GetTileController().OnEntityLeaving(); Loc = subPath[stepID]; Loc.GetTileController().OnEntityEntering(Hash); AnimationManager.Instance.AddAnimClip(new MovePathAnimClip(Hash, subPath, 0.2f)); }
public void MoveToLocation(Location targetLoc, bool isWorldMap, bool isInstance) { if (targetLoc == Loc) { return; } if (!isInstance) { TileNavigation nav = isWorldMap ? WorldMapManager.Instance.Nav : GridManager.Instance.Nav; if (!nav.HasPath(Loc, targetLoc)) { return; } Stack <Location> path = nav.GetPath(Loc, targetLoc); MovePath = path.ToArray(); } if (isWorldMap) { Loc = targetLoc; } else { Loc.GetTileController().OnEntityLeaving(); Loc = targetLoc; Loc.GetTileController().OnEntityEntering(Hash); } if (isInstance) { AnimationManager.Instance.AddAnimClip(new MoveInstantAnimClip(Hash, targetLoc, 0.2f)); } else { AnimationManager.Instance.AddAnimClip(new MovePathAnimClip(Hash, MovePath, 0.2f)); } AnimationManager.Instance.PlayOnce(); }