diff options
author | metamuffin <metamuffin@disroot.org> | 2024-07-02 00:59:11 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-07-02 00:59:11 +0200 |
commit | 5fde584021fa0d073d068ab7edde44aff6098bed (patch) | |
tree | a744285b7fc26abb07f3c23f3849907c4922b21f | |
parent | 8ee3eca5d6de0b950881783821d1be86cd0586d5 (diff) | |
download | hurrycurry-5fde584021fa0d073d068ab7edde44aff6098bed.tar hurrycurry-5fde584021fa0d073d068ab7edde44aff6098bed.tar.bz2 hurrycurry-5fde584021fa0d073d068ab7edde44aff6098bed.tar.zst |
passive recipes in player slot
-rw-r--r-- | server/src/customer/mod.rs | 2 | ||||
-rw-r--r-- | server/src/game.rs | 28 | ||||
-rw-r--r-- | server/src/interaction.rs | 2 | ||||
-rw-r--r-- | test-client/main.ts | 4 |
4 files changed, 30 insertions, 6 deletions
diff --git a/server/src/customer/mod.rs b/server/src/customer/mod.rs index 9e0dd797..c29b4852 100644 --- a/server/src/customer/mod.rs +++ b/server/src/customer/mod.rs @@ -118,7 +118,7 @@ impl DemandState { id, PacketS::Join { name: faker::name::fr_fr::Name().fake(), - character: -1 - (random::<i16>() as i32), + character: -1 - (random::<u16>() as i32), }, )); let chair = self.select_chair().ok_or(anyhow!("no free chair found"))?; diff --git a/server/src/game.rs b/server/src/game.rs index 274a1917..711b66b5 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -18,7 +18,7 @@ use crate::{ customer::DemandState, data::Gamedata, - interaction::{interact, tick_tile, InteractEffect, TickEffect}, + interaction::{interact, tick_slot, InteractEffect, TickEffect}, protocol::{ ItemIndex, ItemLocation, Message, PacketC, PacketS, PlayerID, RecipeIndex, TileIndex, }, @@ -449,7 +449,7 @@ impl Game { } for (&pos, tile) in &mut self.tiles { - if let Some(effect) = tick_tile(dt, &self.data, Some(tile.kind), &mut tile.item) { + if let Some(effect) = tick_slot(dt, &self.data, Some(tile.kind), &mut tile.item) { match effect { TickEffect::Progress(warn) => self.packet_out.push_back(PacketC::SetProgress { warn, @@ -472,6 +472,30 @@ impl Game { } } + for (&pid, player) in &mut self.players { + if let Some(effect) = tick_slot(dt, &self.data, None, &mut player.item) { + match effect { + TickEffect::Progress(warn) => self.packet_out.push_back(PacketC::SetProgress { + warn, + item: ItemLocation::Player(pid), + progress: player + .item + .as_ref() + .unwrap() + .active + .as_ref() + .map(|i| i.progress), + }), + TickEffect::Produce => { + self.packet_out.push_back(PacketC::SetItem { + location: ItemLocation::Player(pid), + item: player.item.as_ref().map(|i| i.kind), + }); + } + } + } + } + return self.end.map(|t| t < Instant::now()).unwrap_or_default(); } } diff --git a/server/src/interaction.rs b/server/src/interaction.rs index adbd3b43..85df9925 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -235,7 +235,7 @@ pub enum TickEffect { Progress(bool), Produce, } -pub fn tick_tile( +pub fn tick_slot( dt: f32, data: &Gamedata, tile: Option<TileIndex>, diff --git a/test-client/main.ts b/test-client/main.ts index 580ff755..70c07212 100644 --- a/test-client/main.ts +++ b/test-client/main.ts @@ -121,7 +121,7 @@ function get_item_location(loc: ItemLocation): PlayerData | TileData { function send(p: PacketS) { ws.send(JSON.stringify(p)) } function packet(p: PacketC) { - if (!["position", "set_active", "update_map"].includes(p.type)) + if (!["position", "set_progress", "update_map"].includes(p.type)) console.log(p); switch (p.type) { case "init": @@ -173,7 +173,7 @@ function packet(p: PacketC) { const slot = get_item_location(p.location) if (slot.item !== undefined && slot.item !== null) items_removed.add(slot.item) slot.item = undefined - if (p.item !== undefined && p.item !== null) slot.item = { kind: p.item, x: slot.position.x, y: slot.position.y } + if (p.item !== undefined && p.item !== null) slot.item = { kind: p.item, x: slot.position.x, y: slot.position.y, tracking: slot.position } break; } case "set_progress": { |