Merge branch 'crabman/disable-buff-stacking' into 'master'

Disable selfbuff stacking

See merge request veloren/veloren!4163
This commit is contained in:
Samuel Keiffer 2023-11-05 19:18:12 +00:00
commit 08171b378c
4 changed files with 31 additions and 1 deletions

View File

@ -64,6 +64,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improved running, wielding, and riding animations - Improved running, wielding, and riding animations
- Fixed offset of items carried on backs when wearing cloaks and backpacks - Fixed offset of items carried on backs when wearing cloaks and backpacks
- Linearize light colors on the CPU rather than in shaders on the GPU - Linearize light colors on the CPU rather than in shaders on the GPU
- You can no longer stack self buffs
### Removed ### Removed
- Medium and large potions from all loot tables - Medium and large potions from all loot tables

View File

@ -955,6 +955,8 @@ pub enum CharacterAbility {
buff_strength: f32, buff_strength: f32,
buff_duration: Option<Secs>, buff_duration: Option<Secs>,
energy_cost: f32, energy_cost: f32,
#[serde(default = "default_true")]
enforced_limit: bool,
#[serde(default)] #[serde(default)]
combo_cost: u32, combo_cost: u32,
combo_scaling: Option<ScalingKind>, combo_scaling: Option<ScalingKind>,
@ -1604,6 +1606,7 @@ impl CharacterAbility {
ref mut buff_strength, ref mut buff_strength,
buff_duration: _, buff_duration: _,
ref mut energy_cost, ref mut energy_cost,
enforced_limit: _,
combo_cost: _, combo_cost: _,
combo_scaling: _, combo_scaling: _,
meta: _, meta: _,
@ -2255,6 +2258,9 @@ impl CharacterAbility {
} }
} }
/// Small helper for #[serde(default)] booleans
fn default_true() -> bool { true }
impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState { impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState {
fn from((ability, ability_info, data): (&CharacterAbility, AbilityInfo, &JoinData)) -> Self { fn from((ability, ability_info, data): (&CharacterAbility, AbilityInfo, &JoinData)) -> Self {
match ability { match ability {
@ -2831,6 +2837,7 @@ impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState {
energy_cost: _, energy_cost: _,
combo_cost, combo_cost,
combo_scaling, combo_scaling,
enforced_limit,
meta: _, meta: _,
} => CharacterState::SelfBuff(self_buff::Data { } => CharacterState::SelfBuff(self_buff::Data {
static_data: self_buff::StaticData { static_data: self_buff::StaticData {
@ -2843,6 +2850,7 @@ impl From<(&CharacterAbility, AbilityInfo, &JoinData<'_>)> for CharacterState {
combo_cost: *combo_cost, combo_cost: *combo_cost,
combo_scaling: *combo_scaling, combo_scaling: *combo_scaling,
combo_on_use: data.combo.map_or(0, |c| c.counter()), combo_on_use: data.combo.map_or(0, |c| c.counter()),
enforced_limit: *enforced_limit,
ability_info, ability_info,
}, },
timer: Duration::default(), timer: Duration::default(),

View File

@ -476,6 +476,7 @@ pub enum BuffCategory {
FromActiveAura(Uid, AuraKey), FromActiveAura(Uid, AuraKey),
RemoveOnAttack, RemoveOnAttack,
RemoveOnLoadoutChange, RemoveOnLoadoutChange,
SelfBuff,
} }
#[derive(Clone, Debug, Serialize, Deserialize)] #[derive(Clone, Debug, Serialize, Deserialize)]

View File

@ -36,6 +36,9 @@ pub struct StaticData {
/// This is the amount of combo held by the entity when this character state /// This is the amount of combo held by the entity when this character state
/// was entered /// was entered
pub combo_on_use: u32, pub combo_on_use: u32,
/// Controls whether `SelfBuff`s that were previously applied should be
/// removed
pub enforced_limit: bool,
/// What key is used to press ability /// What key is used to press ability
pub ability_info: AbilityInfo, pub ability_info: AbilityInfo,
} }
@ -77,13 +80,15 @@ impl CharacterBehavior for Data {
entity: data.entity, entity: data.entity,
change: -(combo_consumption as i32), change: -(combo_consumption as i32),
}); });
let scaling_factor = self.static_data.combo_scaling.map_or(1.0, |cs| { let scaling_factor = self.static_data.combo_scaling.map_or(1.0, |cs| {
cs.factor( cs.factor(
self.static_data.combo_on_use as f32, self.static_data.combo_on_use as f32,
self.static_data.combo_cost as f32, self.static_data.combo_cost as f32,
) )
}); });
let buff_cat_ids = if self
let mut buff_cat_ids = if self
.static_data .static_data
.ability_info .ability_info
.ability .ability
@ -93,6 +98,21 @@ impl CharacterBehavior for Data {
} else { } else {
Vec::new() Vec::new()
}; };
// Remove previous selfbuffs if we should
if self.static_data.enforced_limit {
buff_cat_ids.push(BuffCategory::SelfBuff);
output_events.emit_server(ServerEvent::Buff {
entity: data.entity,
buff_change: BuffChange::RemoveByCategory {
all_required: vec![BuffCategory::SelfBuff],
any_required: vec![],
none_required: vec![],
},
});
}
// Creates buff // Creates buff
let buff = Buff::new( let buff = Buff::new(
self.static_data.buff_kind, self.static_data.buff_kind,