diff options
author | metamuffin <metamuffin@disroot.org> | 2024-09-04 23:41:19 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-09-04 23:41:19 +0200 |
commit | e33e82e87e1e63aa4bc1e599171f61c5c1fa9f15 (patch) | |
tree | 91ffcf384db6b6905369b2337f2da0b3ff32d588 | |
parent | b93beb93360257c1a2e1330dfb1a2f184c59b879 (diff) | |
download | hurrycurry-e33e82e87e1e63aa4bc1e599171f61c5c1fa9f15.tar hurrycurry-e33e82e87e1e63aa4bc1e599171f61c5c1fa9f15.tar.bz2 hurrycurry-e33e82e87e1e63aa4bc1e599171f61c5c1fa9f15.tar.zst |
player in progress packet
-rw-r--r-- | pixel-client/src/game.rs | 2 | ||||
-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 | ||||
-rw-r--r-- | test-client/protocol.ts | 2 |
8 files changed, 60 insertions, 5 deletions
diff --git a/pixel-client/src/game.rs b/pixel-client/src/game.rs index 5239a002..fb81ba90 100644 --- a/pixel-client/src/game.rs +++ b/pixel-client/src/game.rs @@ -348,11 +348,13 @@ impl Game { item, position, speed, + player, warn, } => { self.get_item(item).as_mut().unwrap().active = Some(Involvement { position, speed, + player, warn, recipe: RecipeIndex(0), }); 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, diff --git a/test-client/protocol.ts b/test-client/protocol.ts index 16cfec2c..9c322a09 100644 --- a/test-client/protocol.ts +++ b/test-client/protocol.ts @@ -53,7 +53,7 @@ export type PacketC = | { type: "movement_sync" } // Your movement is difference on the server, you should update your position from a `position` packet | { type: "move_item", from: ItemLocation, to: ItemLocation } // Item moved | { type: "set_item", location: ItemLocation, item?: ItemIndex } // the item contained in a tile or player changed - | { type: "set_progress", item: ItemLocation, position: number, speed: number, warn: boolean } // A tile is doing something. position goes from 0 to 1, speed unit is in 1 per second + | { type: "set_progress", item: ItemLocation, position: number, speed: number, warn: boolean, player?: PlayerID } // A tile is doing something. position goes from 0 to 1, speed unit is in 1 per second | { type: "clear_progress", item: ItemLocation } | { type: "update_map", tile: Vec2, kind: TileIndex | null, neighbors: [TileIndex | null] } // A map tile was changed | { type: "communicate", player: PlayerID, message?: Message, timeout?: MessageTimeout } // A player wants to communicate something, message is null when cleared |