private void ExitCottage(object sender, IncomingMessage receivedMessage) { Entity cottage = networkedScene.EntityManager.Find(receivedMessage.ReadString()); if (cottage != null && !cottage.IsDisposed) { Cottage cot = cottage.FindComponent <Cottage>(); int number = receivedMessage.ReadInt32(); if (cot != null && !cot.UnderConstruction()) { LayerTile aux = Map.map.GetTileByMapCoordinates(receivedMessage.ReadInt32(), receivedMessage.ReadInt32()); cot.ExitPerson(number, aux); } } }
/** * <summary> * Assumes selectedWO is not null. Checks all posible actions between selectedWO and any of the mouse tile WOs * </summary> */ private void HandleAction() { //We can't do anything if we are moving (you'd better not modify that) if (!selectedWO.IsActionBlocking()) { ui.ClearActionButtons(); //As always, when handling actions we must save the instances at the moment //If you remove this lines, when a person tries to exit a cottage, for example, //the tile for exit will be the currentTile below the button at the moment it is pressed (which will probably be null), and not the tile that was selected WorldObject currentWO = null; WorldObject currentMobile = null; LayerTile currentTile = this.currentTile; if (fog == null || fog.IsVisible(currentTile.X, currentTile.Y)) { currentWO = this.currentWO; currentMobile = this.currentMobile; } else if (fog.IsPartiallyVisible(currentTile.X, currentTile.Y)) { currentWO = fog.GetRevealedWO(currentTile.X, currentTile.Y); } foreach (ActionBehavior act in selectedWO.allActions) { if (act.CanShowButton(currentMobile)) { ui.AddAction(act.GetCommandName(currentMobile), () => HandleMovementAction(currentMobile, currentTile, act)); } if (act.CanShowButton(currentWO)) { ui.AddAction(act.GetCommandName(currentWO), () => HandleMovementAction(currentWO, currentTile, act)); } } if (selectedWO.IsMobile()) { //A button to move if "we see" the tile is free if ((currentWO == null || currentWO.IsTraversable(selectedWO)) && (currentMobile == null || currentMobile.IsTraversable(selectedWO))) { ui.AddAction("Move", () => CalculatePathDStar(selectedWO, currentTile)); } } Cottage cottage = selectedWO.Owner.FindComponent <Cottage>(); if (cottage != null) { for (int i = 0; i < cottage.GetPeople().Count; i++) { //Careful with event handlers, actions in loops, because the i variable wont work int aux = i; WorldObject peopleInside = cottage.GetPeople()[aux]; if ((currentMobile == null || currentMobile.IsTraversable(peopleInside)) && (currentWO == null || currentWO.IsTraversable(peopleInside))) { ui.AddAction(string.Format("Exit cottage {0}: {1}", aux + 1, cottage.GetPeople()[aux].GetWoName()), () => cottage.ExitPerson(aux + 1, currentTile)); } } } if (ui.actions.Count == 1) { //if there is only an action, we directly execute it ui.ExecuteAction(0); } else if (ui.actions.Count > 1) { for (int i = 0; i < ui.actions.Count; i++) { //Careful with event handlers, actions in loops, because the i variable wont work int aux = i; if (i >= ui.buttons.Count) { //We have less buttons than actions, create a new one ui.CreateActionButton(); } ui.UpdateActionButton(aux); } ui.optionsAlreadyShown = true; lastActionTile = currentTile; WaveServices.Layout.PerformLayout(Owner.Scene); } } }
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(); } }