diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/client-lib/src/lib.rs | 3 | ||||
-rw-r--r-- | server/protocol/src/lib.rs | 1 | ||||
-rw-r--r-- | server/src/entity/conveyor.rs | 1 | ||||
-rw-r--r-- | server/src/entity/item_portal.rs | 1 | ||||
-rw-r--r-- | server/src/interaction.rs | 15 | ||||
-rw-r--r-- | server/src/server.rs | 40 |
6 files changed, 57 insertions, 4 deletions
diff --git a/server/client-lib/src/lib.rs b/server/client-lib/src/lib.rs index 38b328b9..b4cb0724 100644 --- a/server/client-lib/src/lib.rs +++ b/server/client-lib/src/lib.rs @@ -35,6 +35,7 @@ pub struct Involvement { pub position: f32, pub speed: f32, pub recipe: RecipeIndex, + pub player: Option<PlayerID>, pub warn: bool, } @@ -141,10 +142,12 @@ impl Game { PacketC::SetProgress { item, position, + player, speed, warn, } => { self.get_item(item).as_mut().unwrap().active = Some(Involvement { + player, speed, warn, position, diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 055b41c6..33873a33 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -189,6 +189,7 @@ pub enum PacketC { item: ItemLocation, }, SetProgress { + player: Option<PlayerID>, item: ItemLocation, position: f32, speed: f32, diff --git a/server/src/entity/conveyor.rs b/server/src/entity/conveyor.rs index 4efbd385..e8ff34d7 100644 --- a/server/src/entity/conveyor.rs +++ b/server/src/entity/conveyor.rs @@ -72,6 +72,7 @@ impl Entity for Conveyor { &c.game.data, true, Some(to.kind), + None, &mut to.item, ItemLocation::Tile(self.to), &mut from.item, diff --git a/server/src/entity/item_portal.rs b/server/src/entity/item_portal.rs index 99b9d57a..8eda7a3c 100644 --- a/server/src/entity/item_portal.rs +++ b/server/src/entity/item_portal.rs @@ -39,6 +39,7 @@ impl Entity for ItemPortal { &c.game.data, true, Some(to.kind), + None, &mut to.item, ItemLocation::Tile(self.to), &mut from.item, diff --git a/server/src/interaction.rs b/server/src/interaction.rs index 4b8fbda5..db4e92a7 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -16,7 +16,7 @@ */ use hurrycurry_client_lib::{Involvement, Item}; -use hurrycurry_protocol::{Gamedata, ItemLocation, PacketC, Recipe, Score, TileIndex}; +use hurrycurry_protocol::{Gamedata, ItemLocation, PacketC, PlayerID, Recipe, Score, TileIndex}; use log::{info, warn}; use std::collections::VecDeque; @@ -24,6 +24,7 @@ pub fn interact( data: &Gamedata, edge: bool, tile: Option<TileIndex>, + player: Option<PlayerID>, this: &mut Option<Item>, this_loc: ItemLocation, other: &mut Option<Item>, @@ -54,6 +55,7 @@ pub fn interact( *other = outputs[0].map(|kind| Item { kind, active: None }); *this = outputs[1].map(|kind| Item { kind, active: None }); produce( + player, this_had_item, other_had_item, this, @@ -65,6 +67,7 @@ pub fn interact( ); } else { packet_out.push_back(PacketC::SetProgress { + player, item: this_loc, position: active.position, speed: active.speed, @@ -92,6 +95,7 @@ pub fn interact( if item.kind == *input && item.active.is_none() { info!("start active recipe {ri:?}"); item.active = Some(Involvement { + player, recipe: ri, speed: *speed, position: 0., @@ -109,6 +113,7 @@ pub fn interact( } else { info!("start active recipe {ri:?}"); item.active = Some(Involvement { + player, recipe: ri, speed: *speed, position: 0., @@ -122,6 +127,7 @@ pub fn interact( to: this_loc, }); packet_out.push_back(PacketC::SetProgress { + player, item: this_loc, position: 0., speed: *speed, @@ -153,6 +159,7 @@ pub fn interact( score.instant_recipes += 1; *score_changed = true; produce( + player, this_had_item, other_had_item, this, @@ -239,6 +246,7 @@ pub fn tick_slot( score.passive_recipes += 1; *score_changed = true; packet_out.push_back(PacketC::SetProgress { + player: None, warn: false, item: slot_loc, position: 1., @@ -257,6 +265,7 @@ pub fn tick_slot( if a.speed != prev_speed { packet_out.push_back(PacketC::SetProgress { + player: None, position: a.position, speed: a.speed, warn: a.warn, @@ -273,12 +282,14 @@ pub fn tick_slot( { if *input == item.kind { item.active = Some(Involvement { + player: None, recipe: ri, position: 0., warn: *warn, speed: *speed, }); packet_out.push_back(PacketC::SetProgress { + player: None, position: 0., speed: *speed, warn: *warn, @@ -294,6 +305,7 @@ pub fn tick_slot( } fn produce( + player: Option<PlayerID>, this_had_item: bool, other_had_item: bool, this: &Option<Item>, @@ -307,6 +319,7 @@ fn produce( *score_changed = true; if this_had_item { packet_out.push_back(PacketC::SetProgress { + player, item: this_loc, position: 1., speed: 0., diff --git a/server/src/server.rs b/server/src/server.rs index 47cfdcf4..6a310254 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -23,7 +23,7 @@ use crate::{ ConnectionID, }; use anyhow::{anyhow, bail, Context, Result}; -use hurrycurry_client_lib::{Game, Item, Player, Tile}; +use hurrycurry_client_lib::{Game, Involvement, Item, Player, Tile}; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, movement::MovementBase, @@ -160,7 +160,23 @@ impl GameServerExt for Game { out.push(PacketC::SetItem { location: ItemLocation::Player(id), item: Some(item.kind), - }) + }); + if let Some(Involvement { + player, + position, + speed, + warn, + .. + }) = item.active + { + out.push(PacketC::SetProgress { + player, + item: ItemLocation::Player(id), + position, + speed, + warn, + }); + } } if let Some((message, timeout)) = &player.communicate_persist { out.push(PacketC::Communicate { @@ -185,7 +201,23 @@ impl GameServerExt for Game { out.push(PacketC::SetItem { location: ItemLocation::Tile(tile), item: Some(item.kind), - }) + }); + if let Some(Involvement { + player, + position, + speed, + warn, + .. + }) = item.active + { + out.push(PacketC::SetProgress { + player, + item: ItemLocation::Tile(tile), + position, + speed, + warn, + }); + } } } out.push(PacketC::Score(self.score.clone())); @@ -448,6 +480,7 @@ impl Server { &self.game.data, edge, None, + Some(pid), &mut this.item, ItemLocation::Player(base_pid), &mut other.item, @@ -468,6 +501,7 @@ impl Server { &self.game.data, edge, Some(tile.kind), + Some(pid), &mut tile.item, ItemLocation::Tile(pos), &mut player.item, |