diff options
Diffstat (limited to 'server/src/entity/mod.rs')
-rw-r--r-- | server/src/entity/mod.rs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs index 8055b50d..c8424934 100644 --- a/server/src/entity/mod.rs +++ b/server/src/entity/mod.rs @@ -23,16 +23,16 @@ pub mod environment_effect; pub mod item_portal; pub mod player_portal; -use crate::data::ItemTileRegistry; +use crate::{data::ItemTileRegistry, scoreboard::ScoreboardStore}; use anyhow::{anyhow, Result}; -use campaign::Map; +use campaign::{Gate, GateCondition, Map}; use conveyor::Conveyor; use customers::Customers; use environment_effect::{EnvironmentController, EnvironmentEffect, EnvironmentEffectController}; use hurrycurry_client_lib::Game; use hurrycurry_protocol::{ glam::{IVec2, Vec2}, - PacketC, PacketS, + PacketC, PacketS, PlayerID, }; use item_portal::ItemPortal; use player_portal::PlayerPortal; @@ -48,12 +48,21 @@ pub struct EntityContext<'a> { pub packet_in: &'a mut VecDeque<PacketS>, pub score_changed: &'a mut bool, pub load_map: &'a mut Option<String>, + pub scoreboard: &'a ScoreboardStore, pub dt: f32, } pub trait Entity { fn tick(&mut self, c: EntityContext<'_>) -> Result<()>; fn destructor(&mut self, _c: EntityContext<'_>) {} + fn interact( + &mut self, + _c: EntityContext<'_>, + _pos: Option<IVec2>, + _player: PlayerID, + ) -> Result<bool> { + Ok(false) + } } // macro_rules! entities { @@ -104,6 +113,10 @@ pub enum EntityDecl { }, EnvironmentEffect(EnvironmentEffect), Environment(Vec<String>), + Gate { + location: Option<IVec2>, + condition: GateCondition, + }, } pub fn construct_entity( @@ -113,7 +126,9 @@ pub fn construct_entity( ) -> Result<DynEntity> { Ok(match decl.to_owned() { EntityDecl::ItemPortal { from, to } => Box::new(ItemPortal { - from: from.or(pos).ok_or(anyhow!("Item portal start without start"))?, + from: from + .or(pos) + .ok_or(anyhow!("Item portal start without start"))?, to, }), EntityDecl::PlayerPortal { from, to } => Box::new(PlayerPortal { @@ -149,6 +164,16 @@ pub fn construct_entity( .ok_or(anyhow!("no location"))?, name, }), + EntityDecl::Gate { + condition, + location, + } => Box::new(Gate { + condition, + unlocked: false, + location: location.or(pos).ok_or(anyhow!("no location"))?, + blocker_tile: reg.register_tile("fence".to_string()), + active: true, + }), EntityDecl::Customers {} => Box::new(Customers::new()?), EntityDecl::EnvironmentEffect(config) => Box::new(EnvironmentEffectController::new(config)), EntityDecl::Environment(names) => Box::new(EnvironmentController(names)), |