diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-19 22:52:37 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:21:49 +0200 |
commit | 6ca76cc0568f3d60b280f11ae07a34303c317f34 (patch) | |
tree | ac867e47b3fb4b6ed99189cb302b2741b107d272 /server/src/game.rs | |
parent | 3dc8cc2abb4e6a7be8237b86dab6ebed75fa43cb (diff) | |
download | hurrycurry-6ca76cc0568f3d60b280f11ae07a34303c317f34.tar hurrycurry-6ca76cc0568f3d60b280f11ae07a34303c317f34.tar.bz2 hurrycurry-6ca76cc0568f3d60b280f11ae07a34303c317f34.tar.zst |
implement customer communication
Diffstat (limited to 'server/src/game.rs')
-rw-r--r-- | server/src/game.rs | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/server/src/game.rs b/server/src/game.rs index 228d7048..225455bf 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -1,7 +1,7 @@ use crate::{ data::Gamedata, interaction::{interact, tick_tile, InteractEffect, TickEffect}, - protocol::{ItemIndex, PacketC, PacketS, PlayerID, RecipeIndex, TileIndex}, + protocol::{ItemIndex, Message, PacketC, PacketS, PlayerID, RecipeIndex, TileIndex}, }; use anyhow::{anyhow, bail, Result}; use glam::{IVec2, Vec2}; @@ -36,6 +36,7 @@ pub struct Player { pub position: Vec2, pub interacting: Option<IVec2>, pub item: Option<Item>, + pub communicate: Option<Message>, } pub struct Game { @@ -80,12 +81,18 @@ impl Game { character: player.character, name: player.name.clone(), item: player.item.as_ref().map(|i| i.kind), - }) + }); + if let Some(c) = &player.communicate { + out.push(PacketC::Communicate { + player: id, + message: Some(c.to_owned()), + }) + } } for (&tile, tdata) in &self.tiles { out.push(PacketC::UpdateMap { pos: tile, - neighbours: [ + neighbors: [ self.tiles.get(&(tile + IVec2::NEG_Y)).map(|e| e.kind), self.tiles.get(&(tile + IVec2::NEG_X)).map(|e| e.kind), self.tiles.get(&(tile + IVec2::Y)).map(|e| e.kind), @@ -116,6 +123,7 @@ impl Game { } else { self.data.chef_spawn }, + communicate: None, interacting: None, name: name.clone(), }, @@ -151,6 +159,11 @@ impl Game { PacketS::Position { pos, rot } => { self.packet_out .push_back(PacketC::Position { player, pos, rot }); + let player = self + .players + .get_mut(&player) + .ok_or(anyhow!("player does not exist"))?; + player.position = pos; } PacketS::Collide { player, force } => { self.packet_out @@ -224,6 +237,14 @@ impl Game { player.interacting = if edge { Some(pos) } else { None }; } + PacketS::Communicate { message } => { + info!("{player} message {message:?}"); + if let Some(player) = self.players.get_mut(&player) { + player.communicate = message.clone() + } + self.packet_out + .push_back(PacketC::Communicate { player, message }) + } } Ok(()) } |