public void ProcessEntities(float deltaTime) { foreach (var p in playerRepository.Players.Values) { if (p.Velocity.Equals(Vector2.Zero)) { continue; } p.Position.X += p.Velocity.X * p.Speed * deltaTime; p.Position.Y += p.Velocity.Y * p.Speed * deltaTime; if (p.OldPosition.X == p.Position.X && p.OldPosition.Y == p.Position.Y) { continue; } var entityPositionMesageData = new EntityPositionMessageData(); entityPositionMesageData.Uid = p.Client.PersistentId; entityPositionMesageData.X = p.Position.X; entityPositionMesageData.Y = p.Position.Y; outgoingMessageService.Send(entityPositionMesageData, playerRepository.GetPlayersConnection(new List <Player>(playerRepository.Players.Values))); p.OldPosition.X = p.Position.X; p.OldPosition.Y = p.Position.Y; System.Console.WriteLine(p.Position.X + " " + p.Position.Y); } }
public void Handle(NetConnection sender, SNMessageData messageData) { if (!(sender.Tag is PlayerClient)) { return; } var client = (PlayerClient)sender.Tag; var selectCharacterMessageData = (SelectCharacterMessageData)messageData; if (!IsAccountCharacter(client.PersistentId, selectCharacterMessageData.CharacterId, out Character character)) { return; } var characterSelectedMessageData = new CharacterSelectedMessageData(); characterSelectedMessageData.Character = character; outgoingMessageService.Send(characterSelectedMessageData, sender); var player = new Player(client, character); playerRepository.Add(player); sender.Tag = player; // Send already connected players positions entitiesProcessor.NewPlayerConnected(player); }
public void SendDirection(IOutgoingMessageService <ZoneClientNetPeer> outgoingMessageService) { var direction = new Vector2(xAxisInput.Value, yAxisInput.Value); if (direction.X != 0 && direction.Y != 0) { direction.Normalize(); } if (!previousDirection.Equals(direction)) { if (i < 10) { var playerDirectionMessageData = new PlayerDirectionMessageData(); playerDirectionMessageData.X = direction.X; playerDirectionMessageData.Y = direction.Y; outgoingMessageService.Send(playerDirectionMessageData); System.Console.WriteLine(position); //i++; } } previousDirection = direction; }
public void Handle(NetConnection sender, SNMessageData messageData) { var characterSelectedMessageData = (CharacterSelectedMessageData)messageData; var gameScene = serviceProvider.GetService <GameScene>(); Core.Scene = gameScene; gameScene.LoadCharacter(characterSelectedMessageData.Character); var characterLoadedMessageData = new CharacterLoadedMessageData(); outgoingMessageService.Send(characterLoadedMessageData); }
public void Handle(NetConnection sender, SNMessageData messageData) { if (!(sender.Tag is PlayerClient)) { return; } var client = (PlayerClient)sender.Tag; var sendCharactersMessageData = new SendCharactersMessageData(); sendCharactersMessageData.Characters = GetCharacters(client.PersistentId); outgoingMessageService.Send(sendCharactersMessageData, sender); }
public void Handle(NetConnection sender, NetIncomingMessage message) { if (!(sender.Tag is Player)) { return; } var player = (Player)sender.Tag; playerRepository.Delete(player.Client.PersistentId); clientRepository.Delete(player.Client.PersistentId); var characterDisconnectedMessageData = new CharacterDisconnectedMessageData(); characterDisconnectedMessageData.Character = player.Character; outgoingMessageService.Send(characterDisconnectedMessageData, playerRepository.GetPlayersConnection(new List <Player>(playerRepository.Players.Values))); }
private void RequestCharacters() { var requestCharactersMessageData = new RequestCharactersMessageData(); outgoingMessageService.Send(requestCharactersMessageData); }