public void NewPath(Entity owner, MovementBehavior movement, List <LayerTile> path, bool recalculate) { if (!recalculate) { movement.SetPath(path); //We synchro the path for other to visualize it var message = networkService.CreateServerMessage(); message.Write(MOVE); message.Write(owner.Name); //if the path was accepted, we will send it path = movement.path; message.Write(path.Count); foreach (LayerTile tile in path) { message.Write(tile.X); message.Write(tile.Y); Trace.WriteLine("X: " + tile.X + ", Y:" + tile.Y); } networkService.SendToClients(message, DeliveryMethod.ReliableOrdered); } else { movement.ForcePath(path); } }
private void CalculatePathDStar(WorldObject sel, LayerTile end) { if (sel != null && !sel.IsDestroyed() && !sel.IsActionBlocking()) { Trace.WriteLine("calculating path"); MovementBehavior per = sel.Owner.FindComponent <MovementBehavior>(); LayerTile start = map.GetTileByWorldPosition(sel.GetCenteredPosition()); DStarLite dstar = sel.Owner.FindComponent <DStarLite>(); if (dstar != null && per != null) { List <LayerTile> dPath = dstar.DStar(start, end); Trace.WriteLine("path: " + dPath.Count.ToString()); per.SetPath(dPath); } } }
private void CalculatePath(MovementBehavior per) { Trace.WriteLine("calculating path"); LayerTile start = map.GetTileByWorldPosition(selectedWO.GetCenteredPosition()); WaveServices.TaskScheduler.CreateTask(async() => { List <LayerTile> dPath = AStar.Astar(currentTile, start); Trace.WriteLine("path: " + dPath.Count.ToString()); await WaveServices.Dispatcher.RunOnWaveThread( () => { if (!selectedWO.IsDestroyed() && !selectedWO.IsActionBlocking()) { per.SetPath(dPath); } } ); }); }
protected override void Update(TimeSpan gameTime) { if (!active) { return; } currentTile = Map.map.GetTileByWorldPosition(GetMousePosition()); //If the wo is inside other (p.e: a cottage) we deselect it if (selectedWO != null && (selectedWO.GetAction() == ActionEnum.Inside || selectedWO.IsDestroyed())) { selectedWO = null; ui.ClearActionButtons(); lastActionTile = null; } if (ui.MouseOverGUI()) { return; } //If we are selecting something we own if (selectedWO != null && selectedWO.player == this) { if (currentTile != null) { currentMobile = Map.map.GetMobile(currentTile.X, currentTile.Y); currentWO = Map.map.GetWorldObject(currentTile.X, currentTile.Y); //If we are not creating a path if (!readingTiles && selectedWO.IsMobile()) { //But we want to start a new path if (keysBehavior.IsCommandExecuted(CommandEnum.StartPath)) { if (!selectedWO.IsActionBlocking() && map.Adjacent(currentTile, map.GetTileByWorldPosition(selectedWO.GetCenteredPosition()))) { //Start path readingTiles = true; path.Add(Map.map.GetTileByWorldPosition(selectedWO.GetCenteredPosition())); } } } if (readingTiles && keysBehavior.IsCommandExecuted(CommandEnum.AddTile)) { AddTile(); } if (readingTiles && keysBehavior.IsCommandExecuted(CommandEnum.FinishPath)) { //Right button no longer pressed, set path MovementBehavior per = selectedWO.Owner.FindComponent <MovementBehavior>(); if (path.Count > 2 && per != null) { per.SetPath(path); } readingTiles = false; path.Clear(); } if (keysBehavior.IsCommandExecuted(CommandEnum.ActInTile)) { readingTiles = false; path.Clear(); if (ui.optionsAlreadyShown && currentTile == lastActionTile && selectedWO.IsMobile() && !selectedWO.IsActionBlocking()) { for (int i = 0; i < ui.actions.Count; i++) { if (ui.actions[i].text == "Move") { ui.actions[i].buttonAction(null, null); break; } } lastActionTile = null; } else { HandleAction(); } } //Shortcuts for vicious ones if (keysBehavior.IsCommandExecuted(CommandEnum.Chop)) { Chop(); } if (keysBehavior.IsCommandExecuted(CommandEnum.Fight)) { Fight(); } if (keysBehavior.IsCommandExecuted(CommandEnum.Build)) { Build(); } if (keysBehavior.IsCommandExecuted(CommandEnum.Heal)) { Heal(); } if (keysBehavior.IsCommandExecuted(CommandEnum.Train)) { Train(); } //Cottage shortcuts Cottage cottage = selectedWO.Owner.FindComponent <Cottage>(); if (cottage != null) { if (keysBehavior.IsCommandExecuted(CommandEnum.CottageOne)) { cottage.ExitPerson(1, currentTile); } if (keysBehavior.IsCommandExecuted(CommandEnum.CottageTwo)) { cottage.ExitPerson(2, currentTile); } if (keysBehavior.IsCommandExecuted(CommandEnum.CottageThree)) { cottage.ExitPerson(3, currentTile); } if (keysBehavior.IsCommandExecuted(CommandEnum.CottageFour)) { cottage.ExitPerson(4, currentTile); } if (keysBehavior.IsCommandExecuted(CommandEnum.CottageFive)) { cottage.ExitPerson(5, currentTile); } if (keysBehavior.IsCommandExecuted(CommandEnum.CottageSix)) { cottage.ExitPerson(6, currentTile); } } //Update cottage info any ui.UpdateCottageUI(cottage); } if (keysBehavior.IsCommandExecuted(CommandEnum.Stop)) { selectedWO.Stop(); } if (keysBehavior.IsCommandExecuted(CommandEnum.Destroy)) { Destroy(); } } //Select if (keysBehavior.IsCommandExecuted(CommandEnum.Select)) { lastActionTile = null; Select(); } }