summaryrefslogtreecommitdiff
path: root/server/client-lib/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-12-23 15:37:11 +0100
committermetamuffin <metamuffin@disroot.org>2024-12-23 15:37:11 +0100
commit1a9f7e9a20bff0fbc854454f131d4bc546e73e72 (patch)
tree7be16db47cd819177ae73d42af7b59c37593060a /server/client-lib/src
parentbd71cd120fa4d8caf4987fd9c76838ccbeec19f7 (diff)
downloadhurrycurry-1a9f7e9a20bff0fbc854454f131d4bc546e73e72.tar
hurrycurry-1a9f7e9a20bff0fbc854454f131d4bc546e73e72.tar.bz2
hurrycurry-1a9f7e9a20bff0fbc854454f131d4bc546e73e72.tar.zst
two-handed server
Diffstat (limited to 'server/client-lib/src')
-rw-r--r--server/client-lib/src/lib.rs21
1 files changed, 12 insertions, 9 deletions
diff --git a/server/client-lib/src/lib.rs b/server/client-lib/src/lib.rs
index 5d5e55d5..54c7cd6e 100644
--- a/server/client-lib/src/lib.rs
+++ b/server/client-lib/src/lib.rs
@@ -20,8 +20,7 @@ pub mod network;
pub mod spatial_index;
use hurrycurry_protocol::{
- glam::IVec2, movement::MovementBase, Gamedata, ItemIndex, ItemLocation, Message,
- MessageTimeout, PacketC, PlayerClass, PlayerID, RecipeIndex, Score, TileIndex,
+ glam::IVec2, movement::MovementBase, Gamedata, Hand, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, PlayerClass, PlayerID, RecipeIndex, Score, TileIndex
};
use spatial_index::SpatialIndex;
use std::{
@@ -54,8 +53,8 @@ pub struct Player {
pub name: String,
pub class: PlayerClass,
pub character: i32,
- pub interacting: Option<IVec2>,
- pub item: Option<Item>,
+ pub interacting: Option<(IVec2, Hand)>,
+ pub items: [Option<Item>; 2],
pub communicate_persist: Option<(Message, MessageTimeout)>,
pub movement: MovementBase,
@@ -95,7 +94,7 @@ impl Game {
character,
class,
interacting: None,
- item: None,
+ items: [const { None }; 2],
communicate_persist: None,
movement: MovementBase::new(position),
},
@@ -200,9 +199,11 @@ impl Game {
}
for player in self.players.values_mut() {
- if let Some(item) = &mut player.item {
- if let Some(active) = &mut item.active {
- active.position += active.speed;
+ for item in &mut player.items {
+ if let Some(item) = item {
+ if let Some(active) = &mut item.active {
+ active.position += active.speed;
+ }
}
}
}
@@ -226,7 +227,9 @@ impl Game {
pub fn get_item(&mut self, location: ItemLocation) -> &mut Option<Item> {
match location {
ItemLocation::Tile(pos) => &mut self.tiles.get_mut(&pos).unwrap().item,
- ItemLocation::Player(pid) => &mut self.players.get_mut(&pid).unwrap().item,
+ ItemLocation::Player(pid, hand) => {
+ &mut self.players.get_mut(&pid).unwrap().items[hand.index()]
+ }
}
}
}