diff --git a/GameJam2017/NoobFight.Contract/Map/IActiveTile.cs b/GameJam2017/NoobFight.Contract/Map/IActiveTile.cs index ee5f442..93731f3 100644 --- a/GameJam2017/NoobFight.Contract/Map/IActiveTile.cs +++ b/GameJam2017/NoobFight.Contract/Map/IActiveTile.cs @@ -12,7 +12,7 @@ public interface IActiveTile void OnAttack(IWorldManipulator manipulator, IEntity entity); - void OnClick(IWorldManipulator manipulator, IEntity entity, Vector2 clickPosition); + void OnClick(IWorldManipulator manipulator, IEntity entity); void OnCollision(IWorldManipulator manipulator, IEntity entity); } diff --git a/GameJam2017/NoobFight.Contract/Simulation/ISimulation.cs b/GameJam2017/NoobFight.Contract/Simulation/ISimulation.cs index dc38445..51a2098 100644 --- a/GameJam2017/NoobFight.Contract/Simulation/ISimulation.cs +++ b/GameJam2017/NoobFight.Contract/Simulation/ISimulation.cs @@ -19,7 +19,7 @@ public interface ISimulation void Update(GameTime gameTime); - IPlayer CreateLocalPlayer(string name, string textureName); + IPlayer CreateLocalPlayer(long id, string name, string textureName); void InsertPlayer(IPlayer player); diff --git a/GameJam2017/NoobFight.Core/Map/Tiles/ActiveTile.cs b/GameJam2017/NoobFight.Core/Map/Tiles/ActiveTile.cs index a90e82a..090f1e6 100644 --- a/GameJam2017/NoobFight.Core/Map/Tiles/ActiveTile.cs +++ b/GameJam2017/NoobFight.Core/Map/Tiles/ActiveTile.cs @@ -33,5 +33,6 @@ public virtual void OnClick(IWorldManipulator manipulator, IEntity entity) { } + } } diff --git a/GameJam2017/NoobFight.Core/Map/Tiles/PortalTile.cs b/GameJam2017/NoobFight.Core/Map/Tiles/PortalTile.cs index 6473185..d079722 100644 --- a/GameJam2017/NoobFight.Core/Map/Tiles/PortalTile.cs +++ b/GameJam2017/NoobFight.Core/Map/Tiles/PortalTile.cs @@ -24,10 +24,5 @@ public override void OnClick(IWorldManipulator manipulator, IEntity entity) manipulator.ChangeArea(((IPlayer)entity), this.Property.destinationarea); } } - - public override void OnClick(IWorldManipulator manipulator, IEntity entity, Vector2 clickPosition) - { - - } } } diff --git a/GameJam2017/NoobFight.Core/Simulation/Events/AreaChangedEvent.cs b/GameJam2017/NoobFight.Core/Simulation/Events/AreaChangedEvent.cs index 2ebce9b..648b712 100644 --- a/GameJam2017/NoobFight.Core/Simulation/Events/AreaChangedEvent.cs +++ b/GameJam2017/NoobFight.Core/Simulation/Events/AreaChangedEvent.cs @@ -54,7 +54,7 @@ public override byte[] Serialize() using (MemoryStream ms = new MemoryStream()) using (BinaryWriter bw = new BinaryWriter(ms)) { - bw.Write(Player.ID); + bw.Write(Player.PlayerID); bw.Write(DestinationArea); return ms.ToArray(); } diff --git a/GameJam2017/NoobFight.Core/Simulation/Events/ClickEvent.cs b/GameJam2017/NoobFight.Core/Simulation/Events/ClickEvent.cs index 7bd5f87..9d7a399 100644 --- a/GameJam2017/NoobFight.Core/Simulation/Events/ClickEvent.cs +++ b/GameJam2017/NoobFight.Core/Simulation/Events/ClickEvent.cs @@ -9,8 +9,8 @@ namespace NoobFight.Core.Simulation.Events public class ClickEvent : WorldEvent { private IEntity entity; - private IActiveTile tile; - private Vector2 clickPosition; + private IActiveTile activeTile; + private IPlayer player; public override WorldEventType EventType => WorldEventType.Click; @@ -22,9 +22,25 @@ public ClickEvent() { } + public ClickEvent(IPlayer player, IEntity entity) + { + this.player = player; + this.entity = entity; + } + + public ClickEvent(IPlayer player, IActiveTile activeTile) + { + this.player = player; + this.activeTile = activeTile; + } + public override void Dispatch(IWorld world, ISimulation simulation) { - tile.OnClick(world.CreateNewManipulator(), entity, clickPosition); + if (this.activeTile != null) + activeTile.OnClick(world.CreateNewManipulator(), player); + + if (this.entity != null) + entity.OnClick(world.CreateNewManipulator(), player); } public override byte[] Serialize() @@ -40,11 +56,5 @@ public override void Deserialize(byte[] payload) { } - public ClickEvent(IActiveTile BlockType, IEntity entity, Vector2 clickPosition) - { - tile = BlockType; - this.entity = entity; - this.clickPosition = clickPosition; - } } } diff --git a/GameJam2017/NoobFight.Core/Simulation/World.cs b/GameJam2017/NoobFight.Core/Simulation/World.cs index 7274043..e1f2608 100644 --- a/GameJam2017/NoobFight.Core/Simulation/World.cs +++ b/GameJam2017/NoobFight.Core/Simulation/World.cs @@ -106,7 +106,7 @@ public IWorldManipulator CreateNewManipulator() public IPlayer FindPlayerById(long playerid) { - return _players.First(i => i.ID == playerid); + return _players.First(i => i.PlayerID == playerid); } public void Resume() diff --git a/GameJam2017/NoobFight.Server/Program.cs b/GameJam2017/NoobFight.Server/Program.cs index 1deb3c4..504d328 100644 --- a/GameJam2017/NoobFight.Server/Program.cs +++ b/GameJam2017/NoobFight.Server/Program.cs @@ -51,12 +51,14 @@ static void Main(string[] args) private static void StartWorld(Client client, StartWorldRequest message) { - var world = simulation.Worlds.FirstOrDefault(i => i.Players.Count() > 0 && i.Players.Any(p => p.ID == client.ID)); + var world = simulation.Worlds.FirstOrDefault(i => i.Players.Count() > 0 && i.Players.Any(p => p.PlayerID == client.ID)); if (world != null) { var mapstart = new StartWorldMessage("Hallo"); - world.Start(MapGenerator.CreateMap(mapstart.MapName)); + var map = new Map(mapstart.MapName); + map.Load(); + world.Start(map); foreach (var player in world.Players.OfType()) { @@ -70,7 +72,7 @@ private static void CreateWorld(Client client, CreateWorldRequestMessage message var world = simulation.CreateNewWorld(message.Mode, message.WorldName); world.AddEventCallback = SendEvent; - var player = simulation.Players.First(i => i.ID == client.ID); + var player = simulation.Players.First(i => i.PlayerID == client.ID); world.AddPlayer(player); var joinmessage = new PlayerJoinResponseMessage(client.ID, player.Name, player.TextureName); diff --git a/GameJam2017/NoobFight/Components/NetworkComponent.cs b/GameJam2017/NoobFight/Components/NetworkComponent.cs index 6117747..6649998 100644 --- a/GameJam2017/NoobFight/Components/NetworkComponent.cs +++ b/GameJam2017/NoobFight/Components/NetworkComponent.cs @@ -51,12 +51,17 @@ public NetworkComponent(NoobFight game) : base(game) } - private void StartWorld(Client client, StartWorldMessage message) + public void StartWorld(Client client, StartWorldMessage message) { var map = new Map(message.MapName); map.Load(); Game.SimulationComponent.World.Start(map); } + public void StartWorld() + { + client.writeStream(new StartWorldRequest()); + } + private void UpdateEntity(Client client, EntityDataUpdateMessage entitydata) { @@ -86,14 +91,14 @@ private void PlayerJoin(Client client, PlayerJoinResponseMessage message) if (Game.SimulationComponent.Player.Id == message.Id) { - Game.SimulationComponent.World.Manipulator.AddPlayer(Game.SimulationComponent.Player); + Game.SimulationComponent.World.AddPlayer(Game.SimulationComponent.Player); Game.ScreenManager.NavigateToScreen(new LobbyScreen(Game.ScreenManager)); return; } var player = new RemotePlayer(client, message.Nick, message.TextureName);//TODO: texturename Game.SimulationComponent.Simulation.InsertPlayer(player); - Game.SimulationComponent.World.Manipulator.AddPlayer(player); + Game.SimulationComponent.World.AddPlayer(player); } @@ -105,7 +110,7 @@ private void ConnectedPlayersResp(Client arg1, ConnectedPlayersResponseMessage m private void PlayerLoginResponse(Client client, PlayerLoginResponseMessage message) { - Game.SimulationComponent.Player = Game.SimulationComponent.Simulation.CreateLocalPlayer(Nick, TextureName); + Game.SimulationComponent.Player = Game.SimulationComponent.Simulation.CreateLocalPlayer(message.PlayerId, Nick, TextureName); client.writeStream(new WorldListRequestMessage()); playerLoaded.Set(); } @@ -133,6 +138,18 @@ public void JoinWorld(string worldName) worldLoaded.Set(); client.writeStream(new PlayerJoinRequestMessage(worldName)); } + public void CreateWorld(string name, GameMode mode) + { + client.writeStream(new CreateWorldRequestMessage(name, mode)); + } + + private void CreateWorld(Client client, CreateWorldResponseMessage message) + { + if (client.Connected == false) + throw new NotSupportedException(); + Game.SimulationComponent.World = Game.SimulationComponent.Simulation.CreateNewWorld(message.Mode, message.WorldName); + worldLoaded.Set(); + } public void Disconnect() { diff --git a/GameJam2017/NoobFight/Components/SimulationComponent.cs b/GameJam2017/NoobFight/Components/SimulationComponent.cs index 076eb98..05809a5 100644 --- a/GameJam2017/NoobFight/Components/SimulationComponent.cs +++ b/GameJam2017/NoobFight/Components/SimulationComponent.cs @@ -30,8 +30,8 @@ public void CreateSinglePlayerSimulation(GameMode gamemode, string texturename,s { Simulation = new Simulation(SimulationMode.Single); World = Simulation.CreateNewWorld(gamemode, "Default World"); - Player = Simulation.CreateLocalPlayer( "Hallo", texturename); ; - World.Manipulator.AddPlayer(Player); + Player = Simulation.CreateLocalPlayer(1, "Hallo", texturename); ; + World.AddPlayer(Player); var map = new Map(mapname); map.Load(); World.Start(map);