From ec3a7d18988915b108ca563c4eb681a65db5a172 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 1 Jun 2023 14:51:19 +0100 Subject: [PATCH 1/2] Make items vanish after 5 minutes --- common/net/src/synced_components.rs | 5 +++++ common/src/comp/misc.rs | 13 ++++++++---- server/src/state_ext.rs | 11 ++++++++-- server/src/sys/object.rs | 19 ++++++++++++----- voxygen/src/scene/figure/mod.rs | 33 +++++++++++++++++++++++------ 5 files changed, 63 insertions(+), 18 deletions(-) diff --git a/common/net/src/synced_components.rs b/common/net/src/synced_components.rs index 63b5fc1e5e..f83f9c6e15 100644 --- a/common/net/src/synced_components.rs +++ b/common/net/src/synced_components.rs @@ -64,6 +64,7 @@ macro_rules! synced_components { combo: Combo, active_abilities: ActiveAbilities, can_build: CanBuild, + object: Object, } }; } @@ -253,3 +254,7 @@ impl NetSync for ActiveAbilities { impl NetSync for CanBuild { const SYNC_FROM: SyncFrom = SyncFrom::ClientEntity; } + +impl NetSync for Object { + const SYNC_FROM: SyncFrom = SyncFrom::AnyEntity; +} diff --git a/common/src/comp/misc.rs b/common/src/comp/misc.rs index 968c894ff7..c803ec64e9 100644 --- a/common/src/comp/misc.rs +++ b/common/src/comp/misc.rs @@ -1,9 +1,10 @@ use super::item::Reagent; -use crate::uid::Uid; +use crate::{resources::Time, uid::Uid}; use serde::{Deserialize, Serialize}; -use specs::Component; +use specs::{Component, DerefFlaggedStorage}; +use std::time::Duration; -#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum Object { Bomb { owner: Option, @@ -12,8 +13,12 @@ pub enum Object { owner: Option, reagent: Reagent, }, + DeleteAfter { + spawned_at: Time, + timeout: Duration, + }, } impl Component for Object { - type Storage = specs::VecStorage; + type Storage = DerefFlaggedStorage>; } diff --git a/server/src/state_ext.rs b/server/src/state_ext.rs index a15f4fdbac..db45966106 100644 --- a/server/src/state_ext.rs +++ b/server/src/state_ext.rs @@ -19,7 +19,7 @@ use common::{ self, item::{ItemKind, MaterialStatManifest}, skills::{GeneralSkill, Skill}, - ChatType, Group, Inventory, Item, LootOwner, Player, Poise, Presence, PresenceKind, + ChatType, Group, Inventory, Item, LootOwner, Object, Player, Poise, Presence, PresenceKind, }, effect::Effect, link::{Link, LinkHandle}, @@ -40,7 +40,7 @@ use specs::{ saveload::MarkerAllocator, Builder, Entity as EcsEntity, EntityBuilder as EcsEntityBuilder, Join, WorldExt, }; -use std::time::Instant; +use std::time::{Duration, Instant}; use tracing::{trace, warn}; use vek::*; @@ -366,6 +366,8 @@ impl StateExt for State { // Only if merging items fails do we give up and create a new item } + let spawned_at = *self.ecs().read_resource::