diff options
author | metamuffin <metamuffin@disroot.org> | 2024-06-18 10:17:40 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-06-23 19:20:50 +0200 |
commit | 20a978e4f91e03588bf89d2426ee215f176b1ac7 (patch) | |
tree | b99bd5b52dbd7cc31cec9bfcf79a197184f72a40 /server/src/game.rs | |
parent | 9bdb81bb34bd6a7e33c47d6fcb3dced1c5bda991 (diff) | |
download | hurrycurry-20a978e4f91e03588bf89d2426ee215f176b1ac7.tar hurrycurry-20a978e4f91e03588bf89d2426ee215f176b1ac7.tar.bz2 hurrycurry-20a978e4f91e03588bf89d2426ee215f176b1ac7.tar.zst |
passive recipes work
Diffstat (limited to 'server/src/game.rs')
-rw-r--r-- | server/src/game.rs | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/server/src/game.rs b/server/src/game.rs index f207e8f6..14d096e1 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -1,5 +1,5 @@ use crate::{ - interaction::{interact, Out}, + interaction::{interact, tick_tile, Out}, protocol::{ItemID, ItemIndex, PacketC, PacketS, PlayerID, RecipeIndex, TileIndex}, recipes::Gamedata, }; @@ -22,7 +22,6 @@ pub struct Tile { kind: TileIndex, items: Vec<ItemID>, active: Option<ActiveRecipe>, - last_active: bool, } struct Player { @@ -205,6 +204,12 @@ impl Game { info!("left {:?}", tile.items); self.packet_out.push_back(PacketC::ConsumeItem { id, pos }); } + Out::SetActive(progress) => { + self.packet_out.push_back(PacketC::SetActive { + tile: pos, + progress, + }); + } }, ); } @@ -214,14 +219,40 @@ impl Game { pub fn tick(&mut self, dt: f32) { for (&pos, tile) in &mut self.tiles { - if let Some(active) = &mut tile.active { - active.progress += dt / self.data.recipes[active.recipe].action.duration(); - self.packet_out.push_back(PacketC::SetActive { - tile: pos, - progress: Some(active.progress), - }); - } - tile.last_active = tile.active.is_some() + let items = tile.items.iter().map(|e| self.items[e]).collect::<Vec<_>>(); + tick_tile( + dt, + &self.data, + tile.kind, + &mut tile.active, + items, + |out| match out { + Out::Take(_) | Out::Put => { + unreachable!() + } + Out::Produce(kind) => { + info!("produce"); + let id = self.item_id_counter; + self.item_id_counter += 1; + self.items.insert(id, kind); + tile.items.push(id); + self.packet_out + .push_back(PacketC::ProduceItem { id, pos, kind }); + } + Out::Consume(index) => { + info!("consume"); + let id = tile.items.remove(index); + info!("left {:?}", tile.items); + self.packet_out.push_back(PacketC::ConsumeItem { id, pos }); + } + Out::SetActive(progress) => { + self.packet_out.push_back(PacketC::SetActive { + tile: pos, + progress, + }); + } + }, + ); } } } @@ -231,7 +262,6 @@ impl From<TileIndex> for Tile { Self { kind, items: vec![], - last_active: false, active: None, } } |