private void HandleActionMessage(String address, AbstractMessage message) { Player currentPlayer = controller.GetPlayer(IPAddress.Parse(address)); BattleEngine battleEngine = BattleEngine.GetInstance(); ActionMessage actionMessage = (ActionMessage)message; UpdateMessage updateMesssage = new UpdateMessage(); // Valide o jogador: Caso não seja o turno do jogador, descarte a mensagem if (currentPlayer.Name != battleEngine.ActualPlayer) { return; } actionMessage.PlayerName = currentPlayer.Name; if (actionMessage is ActionMessageFinish) { ActionMessageFinish finishMessage = (ActionMessageFinish)actionMessage; battleEngine.LastAction = LastAction.Passed; } else if (actionMessage is ActionMessageWalk) { ActionMessageWalk walkMessage = (ActionMessageWalk)actionMessage; walkMessage.Actor = battleEngine.ActualCharacter.RootName; battleEngine.ActualCharacterHasWalked = true; battleEngine.LastAction = LastAction.Walked; } else if (actionMessage is ActionMessageAttack) { ActionMessageAttack attackMessage = (ActionMessageAttack)actionMessage; attackMessage.Actor = battleEngine.ActualCharacter.RootName; AttackEvent attackEvent = battleEngine.ProcessAttack(attackMessage.TargetPlayer, attackMessage.Target); attackMessage.Damage = attackEvent.Damage; attackMessage.CounterAttack = attackEvent.CounterAttack; attackMessage.CounterDamage = attackEvent.CounterDamage; battleEngine.LastAction = LastAction.Attacked; } actionMessage.PlayerName = currentPlayer.Name; updateMesssage.Action = actionMessage; controller.Server.SendToAll(updateMesssage); foreach (Player player in controller.GetPlayers()) { player.Ready = false; } }
private void HandleUpdateMessage(String address, AbstractMessage message) { GameScreen gameScreen = GameScreen.GetInstance(); UpdateMessage updateMessage = (UpdateMessage)message; Player player = controller.GetPlayer(updateMessage.Action.PlayerName); Character character = null; if (updateMessage.Action is ActionMessageWalk) { ActionMessageWalk walkMessage = (ActionMessageWalk)updateMessage.Action; character = player.GetCharacter(walkMessage.Actor); controller.SupressUpdate(); gameScreen.MoveCharacter(character, walkMessage.Point); controller.ReleaseUpdate(); IInputHandler handler = gameScreen.Handlers.Peek(); handler.Watch(character); handler.SetTrigger(Trigger.SendConfirmUpdate); } else if (updateMessage.Action is ActionMessageAttack) { ActionMessageAttack attackMessage = (ActionMessageAttack)updateMessage.Action; character = player.GetCharacter(attackMessage.Actor); Player targetPlayer = controller.GetPlayer(attackMessage.TargetPlayer); Character target = targetPlayer.GetCharacter(attackMessage.Target); controller.SupressUpdate(); gameScreen.DoBattle(character, target, attackMessage.Damage, attackMessage.CounterAttack, attackMessage.CounterDamage); IInputHandler handler = gameScreen.Handlers.Peek(); handler.Watch(character); handler.Watch(target); handler.SetTrigger(Trigger.SendConfirmUpdate); controller.ReleaseUpdate(); } else if (updateMessage.Action is ActionMessageFinish) { gameScreen.ActualTurn = null; ConfirmUpdateMessage confirmUpdateMessage = new ConfirmUpdateMessage(); confirmUpdateMessage.ConfirmationType = ConfirmationType.UpdateMessage; Controller.GetInstance().Client.SendData(confirmUpdateMessage); } }
public void Update(float passedTime) { bool isReady = true; gameScreen.InfoBox.Update(passedTime); gameScreen.ChatBox.Update(passedTime); if (watchedCharacters.Count != 0) { foreach (Character watchedCharacter in watchedCharacters) { if (!watchedCharacter.IsIdle() || watchedCharacter.HealthVariation.IsVisible() || watchedCharacter.DrawingAffects || watchedCharacter.Target != null) { isReady = false; break; } } if (isReady) { if (trigger == Trigger.SendConfirmUpdate) { SendConfirmUpdateMessage(ConfirmationType.UpdateMessage); gameScreen.ActualTurn = null; } else if (trigger == Trigger.SendConfirmAffects) { SendConfirmUpdateMessage(ConfirmationType.AffectsMessage); } else if (trigger == Trigger.TriggerActionBox) { FillOptions(); } watchedCharacters.Clear(); trigger = Trigger.DoNothing; } } if (KeyboardManager.Manager.TypedKeys.Contains(Keys.Space)) { ChatInputHandler chatInputHandler = new ChatInputHandler(gameScreen); gameScreen.ChatBox.ChatInputHandler = chatInputHandler; gameScreen.Handlers.Push(chatInputHandler); gameScreen.ChatBox.Show(); return; } if (gameScreen.ActionBox.IsVisible) { if (KeyboardManager.Manager.TypedKeys.Contains(Keys.Escape)) { gameScreen.ActionBox.ClearOptions(); gameScreen.ActionBox.AddOption(GameScreen.ACTIONBOX_CONTINUE); gameScreen.ActionBox.AddOption(GameScreen.ACTIONBOX_EXIT); } if (KeyboardManager.Manager.TypedKeys.Contains(Keys.Down)) { gameScreen.ActionBox.Selection++; } if (KeyboardManager.Manager.TypedKeys.Contains(Keys.Up)) { gameScreen.ActionBox.Selection--; } if (KeyboardManager.Manager.TypedKeys.Contains(Keys.Enter)) { HideSelectedCharacter(); selectedOption = gameScreen.ActionBox.SelectedValue; switch (gameScreen.ActionBox.SelectedValue) { case GameScreen.ACTIONBOX_WALK: HandleActionWalk(); break; case GameScreen.ACTIONBOX_ATTACK: HandleActionAttack(); break; case GameScreen.ACTIONBOX_WAIT: HandleActionNext(); break; case GameScreen.ACTIONBOX_FINISH: HandleActionNext(); break; case GameScreen.ACTIONBOX_EXIT: HandleActionExit(); break; case GameScreen.ACTIONBOX_CONTINUE: HandleActionContinue(); break; } } } else { gameScreen.MapCursor.IsVisible = isReady; if (isReady && KeyboardManager.Manager.TypedKeys.Contains(Keys.Escape)) { if (gameScreen.SelectedCharacter != null) { gameScreen.ClearTileMarks(); gameScreen.MapCursor.IsVisible = false; gameScreen.Camera.FocusOn(gameScreen.SelectedCharacter.MapLocation); } else { gameScreen.ActionBox.ClearOptions(); gameScreen.ActionBox.AddOption(GameScreen.ACTIONBOX_EXIT); gameScreen.ActionBox.AddOption(GameScreen.ACTIONBOX_CONTINUE); } FillOptions(); } if (isReady && KeyboardManager.Manager.TypedKeys.Contains(Keys.Up)) { Point location = gameScreen.MapCursor.MapLocation; if (gameScreen.TileMarks[location.X, location.Y] != null) { gameScreen.TileMarks[location.X, location.Y].Selected = false; } location.Y--; gameScreen.MapCursor.MapLocation = location; if (gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y] != null) { gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y].Selected = true; } gameScreen.Camera.FocusOn(gameScreen.MapCursor.MapLocation); } if (isReady && KeyboardManager.Manager.TypedKeys.Contains(Keys.Down)) { Point location = gameScreen.MapCursor.MapLocation; if (gameScreen.TileMarks[location.X, location.Y] != null) { gameScreen.TileMarks[location.X, location.Y].Selected = false; } location.Y++; gameScreen.MapCursor.MapLocation = location; if (gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y] != null) { gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y].Selected = true; } gameScreen.Camera.FocusOn(gameScreen.MapCursor.MapLocation); } if (isReady && KeyboardManager.Manager.TypedKeys.Contains(Keys.Right)) { Point location = gameScreen.MapCursor.MapLocation; if (gameScreen.TileMarks[location.X, location.Y] != null) { gameScreen.TileMarks[location.X, location.Y].Selected = false; } location.X++; gameScreen.MapCursor.MapLocation = location; if (gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y] != null) { gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y].Selected = true; } gameScreen.Camera.FocusOn(gameScreen.MapCursor.MapLocation); } if (isReady && KeyboardManager.Manager.TypedKeys.Contains(Keys.Left)) { Point location = gameScreen.MapCursor.MapLocation; if (gameScreen.TileMarks[location.X, location.Y] != null) { gameScreen.TileMarks[location.X, location.Y].Selected = false; } location.X--; gameScreen.MapCursor.MapLocation = location; if (gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y] != null) { gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y].Selected = true; } gameScreen.Camera.FocusOn(gameScreen.MapCursor.MapLocation); } if (isReady && KeyboardManager.Manager.TypedKeys.Contains(Keys.Enter)) { if (gameScreen.TileMarks[gameScreen.MapCursor.MapLocation.X, gameScreen.MapCursor.MapLocation.Y] != null) { AbstractMessage message = null; Point target = gameScreen.MapCursor.MapLocation; switch (selectedOption) { case GameScreen.ACTIONBOX_ATTACK: message = new ActionMessageAttack(); ((ActionMessageAttack)message).TargetPlayer = Controller.GetInstance().GetRemotePlayer().Name; ((ActionMessageAttack)message).Target = gameScreen.MapEngine.Map.Objects[target.X, target.Y].RootName; break; case GameScreen.ACTIONBOX_WALK: message = new ActionMessageWalk(); ((ActionMessageWalk)message).Point = target; break; } gameScreen.ClearTileMarks(); Controller.GetInstance().Client.SendData(message); } } } }