From 5514df330b47474e9b6d14269ae4dc3020b5eedc Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 5 Jan 2024 19:56:41 +0200 Subject: [PATCH 1/6] Add BuffDescriptor enum --- common/src/comp/buff.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index cef10d70c3..d0ccf30d76 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -175,6 +175,21 @@ pub enum BuffKind { Heatstroke, } +/// Tells how buffs influence the target +enum BuffDescriptor { + /// Simple positive buffs, like `BuffKind::Saturation` + SimplePositive, + /// Simple negative buffs, like `BuffKind::Bleeding` + SimpleNegative, + /// Buffs that require unusual data that can't be governed just by strength + /// and duration, like `BuffKind::Polymorhped` + Complex, + // For future additions, we may want to tell about non-obvious buffs, + // like Agility. + // Also maybe extend Complex to differentiate between Positive, Negative + // and Neutral buffs? +} + impl BuffKind { /// Checks if buff is buff or debuff. pub fn is_buff(self) -> bool { From f4939220ccccfe443e7eeb07de1dfd8ec75ce680 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 5 Jan 2024 20:15:59 +0200 Subject: [PATCH 2/6] Add BuffKind::differentiate --- common/src/comp/buff.rs | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index d0ccf30d76..bc3c8ca93c 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -165,18 +165,19 @@ pub enum BuffKind { /// Results from drinking a potion. /// Decreases the health gained from subsequent potions. PotionSickness, - /// Changed into another body. - Polymorphed, /// Slows movement speed and reduces energy reward. /// Both scales non-linearly to strength, 0.5 lead to movespeed reduction /// by 25% and energy reward reduced by 150%, 1.0 lead to MS reduction by /// 33.3% and energy reward reduced by 200%. Energy reward can't be /// reduced by more than 200%, to a minimum value of -100%. Heatstroke, + // Complex, non-obvious buffs + /// Changed into another body. + Polymorphed, } -/// Tells how buffs influence the target -enum BuffDescriptor { +/// Tells a little more about the buff kind than simple buff/debuff +pub enum BuffDescriptor { /// Simple positive buffs, like `BuffKind::Saturation` SimplePositive, /// Simple negative buffs, like `BuffKind::Bleeding` @@ -188,11 +189,14 @@ enum BuffDescriptor { // like Agility. // Also maybe extend Complex to differentiate between Positive, Negative // and Neutral buffs? + // For now, Complex is assumed to be neutral/non-obvious. } impl BuffKind { - /// Checks if buff is buff or debuff. - pub fn is_buff(self) -> bool { + /// Tells a little more about buff kind than simple buff/debuff + /// + /// Read more in [BuffDescriptor]. + pub fn differentiate(self) -> BuffDescriptor { match self { BuffKind::Regeneration | BuffKind::Saturation @@ -217,7 +221,7 @@ impl BuffKind { | BuffKind::Sunderer | BuffKind::Defiance | BuffKind::Bloodfeast - | BuffKind::Berserk => true, + | BuffKind::Berserk => BuffDescriptor::SimplePositive, BuffKind::Bleeding | BuffKind::Cursed | BuffKind::Burning @@ -228,8 +232,16 @@ impl BuffKind { | BuffKind::Poisoned | BuffKind::Parried | BuffKind::PotionSickness - | BuffKind::Polymorphed - | BuffKind::Heatstroke => false, + | BuffKind::Heatstroke => BuffDescriptor::SimpleNegative, + BuffKind::Polymorphed => BuffDescriptor::Complex, + } + } + + /// Checks if buff is buff or debuff. + pub fn is_buff(self) -> bool { + match self.differentiate() { + BuffDescriptor::SimplePositive => true, + BuffDescriptor::SimpleNegative | BuffDescriptor::Complex => false, } } From 18742bc7fba2b7995ee2dd2aae266f3a79b5bdc8 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 5 Jan 2024 21:36:09 +0200 Subject: [PATCH 3/6] Fix veloren-server compilation As veloren-server enables plugin feature automatically, it results in veloren-common-state inherit this feature, which enables common/state/plugin/mod.rs which asks for common::assets function that is enabled only if plugin feature is enabled, but because veloren-common-state doesn't depend on common::assets, this feature is kind of lost half-way. This commit fixes this by adding explicit optional dependency on common-assets in common-state that is enabled by plugin feature. --- Cargo.lock | 1 + common/assets/src/lib.rs | 10 +++++----- common/state/Cargo.toml | 3 ++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 07cfe7aa8c..86350ff101 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7088,6 +7088,7 @@ dependencies = [ "tracing", "vek 0.15.8", "veloren-common", + "veloren-common-assets", "veloren-common-base", "veloren-common-ecs", "veloren-common-net", diff --git a/common/assets/src/lib.rs b/common/assets/src/lib.rs index 952c196e9d..f6368a20c9 100644 --- a/common/assets/src/lib.rs +++ b/common/assets/src/lib.rs @@ -31,14 +31,14 @@ pub use walk::{walk_tree, Walk}; #[cfg(feature = "plugins")] lazy_static! { -/// The HashMap where all loaded assets are stored in. -static ref ASSETS: plugin_cache::CombinedCache = plugin_cache::CombinedCache::new().unwrap(); + /// The HashMap where all loaded assets are stored in. + static ref ASSETS: plugin_cache::CombinedCache = plugin_cache::CombinedCache::new().unwrap(); } #[cfg(not(feature = "plugins"))] lazy_static! { -/// The HashMap where all loaded assets are stored in. -static ref ASSETS: AssetCache = - AssetCache::with_source(fs::FileSystem::new().unwrap()); + /// The HashMap where all loaded assets are stored in. + static ref ASSETS: AssetCache = + AssetCache::with_source(fs::FileSystem::new().unwrap()); } #[cfg(feature = "hot-reloading")] diff --git a/common/state/Cargo.toml b/common/state/Cargo.toml index 2e71eb301d..a94ba64808 100644 --- a/common/state/Cargo.toml +++ b/common/state/Cargo.toml @@ -6,7 +6,7 @@ version = "0.10.0" [features] simd = ["vek/platform_intrinsics"] -plugins = ["toml", "tar", "wasmer", "wasmer-wasix-types", "bincode", "plugin-api", "serde"] +plugins = ["common-assets/plugins", "toml", "tar", "wasmer", "wasmer-wasix-types", "bincode", "plugin-api", "serde"] default = ["simd"] @@ -15,6 +15,7 @@ common = { package = "veloren-common", path = ".." } common-net = { package = "veloren-common-net", path = "../net" } common-ecs = { package = "veloren-common-ecs", path = "../ecs" } common-base = { package = "veloren-common-base", path = "../base" } +common-assets = { package = "veloren-common-assets", path = "../assets", optional = true} rayon = { workspace = true } num_cpus = "1.0" From 5aa30b017558065bdd5b227d796c69479b3ae5b6 Mon Sep 17 00:00:00 2001 From: juliancoffee Date: Fri, 5 Jan 2024 21:40:34 +0200 Subject: [PATCH 4/6] Warn about complex buffs when using /buff --- assets/voxygen/i18n/en/command.ftl | 3 +- common/src/comp/buff.rs | 7 +++ server/src/cmd.rs | 76 +++++++++++++++++++----------- 3 files changed, 57 insertions(+), 29 deletions(-) diff --git a/assets/voxygen/i18n/en/command.ftl b/assets/voxygen/i18n/en/command.ftl index cbc6007b08..b840ca39cd 100644 --- a/assets/voxygen/i18n/en/command.ftl +++ b/assets/voxygen/i18n/en/command.ftl @@ -64,6 +64,7 @@ command-battlemode-available-modes = Available modes: pvp, pve command-battlemode-same = Attempted to set the same battlemode command-battlemode-updated = New battlemode: { $battlemode } command-buff-unknown = Unknown buff: { $buff } +command-buff-complex = /buff doesn't work with this buff, use /buff_complex command-skillpreset-load-error = Error while loading presets command-skillpreset-broken = Skill preset is broken command-skillpreset-missing = Preset does not exist: { $preset } @@ -95,4 +96,4 @@ command-you-dont-exist = You do not exist, so you cannot use this command command-destroyed-tethers = All tethers destroyed! You are now free command-destroyed-no-tethers = You're not connected to any tethers command-dismounted = Dismounted -command-no-dismount = You're not riding or being ridden \ No newline at end of file +command-no-dismount = You're not riding or being ridden diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index bc3c8ca93c..70f9b47905 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -245,6 +245,13 @@ impl BuffKind { } } + pub fn is_simple(self) -> bool { + match self.differentiate() { + BuffDescriptor::SimplePositive | BuffDescriptor::SimpleNegative => true, + BuffDescriptor::Complex => false, + } + } + /// Checks if buff should queue. pub fn queues(self) -> bool { matches!(self, BuffKind::Saturation) } diff --git a/server/src/cmd.rs b/server/src/cmd.rs index d7c7ae24c2..8c559a80ee 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -4145,10 +4145,30 @@ fn handle_buff( let duration = duration.unwrap_or(1.0); let buffdata = BuffData::new(strength, Some(Secs(duration))); if buff != "all" { - cast_buff(&buff, buffdata, server, target) + let buffkind = parse_buffkind(&buff).ok_or_else(|| { + Content::localized_with_args("command-buff-unknown", [("buff", buff.clone())]) + })?; + + if buffkind.is_simple() { + cast_buff(buffkind, buffdata, server, target) + } else { + return Err(Content::localized_with_args("command-buff-complex", [( + "buff", buff, + )])); + } } else { - for kind in BUFF_PACK.iter() { - cast_buff(kind, buffdata, server, target)?; + for kind_key in BUFF_PACK.iter() { + let buffkind = parse_buffkind(kind_key).ok_or_else(|| { + Content::localized_with_args("command-buff-unknown", [( + "buff", + kind_key.to_owned(), + )]) + })?; + + // Execute only simple buffs, ignore complex + if buffkind.is_simple() { + cast_buff(buffkind, buffdata, server, target)?; + } } Ok(()) } @@ -4157,33 +4177,33 @@ fn handle_buff( } } -fn cast_buff(kind: &str, data: BuffData, server: &mut Server, target: EcsEntity) -> CmdResult<()> { - if let Some(buffkind) = parse_buffkind(kind) { - let ecs = &server.state.ecs(); - let mut buffs_all = ecs.write_storage::(); - let stats = ecs.read_storage::(); - let healths = ecs.read_storage::(); - let time = ecs.read_resource::