mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Attack effects can now have requirements.
This commit is contained in:
parent
c77f263cd1
commit
46dbb8aef4
@ -137,35 +137,40 @@ impl Attack {
|
||||
.filter(|e| e.target.map_or(true, |t| t == target_group))
|
||||
.filter(|e| !(matches!(e.target, Some(GroupTarget::OutOfGroup)) && target_dodging))
|
||||
{
|
||||
match effect.effect {
|
||||
AttackEffect::Knockback(kb) => {
|
||||
let impulse = kb.calculate_impulse(dir);
|
||||
if !impulse.is_approx_zero() {
|
||||
server_events.push(ServerEvent::Knockback {
|
||||
entity: target_entity,
|
||||
impulse,
|
||||
if match &effect.requirement {
|
||||
Some(CombatRequirement::AnyDamage) => accumulated_damage != 0.0,
|
||||
None => true,
|
||||
} {
|
||||
match effect.effect {
|
||||
AttackEffect::Knockback(kb) => {
|
||||
let impulse = kb.calculate_impulse(dir);
|
||||
if !impulse.is_approx_zero() {
|
||||
server_events.push(ServerEvent::Knockback {
|
||||
entity: target_entity,
|
||||
impulse,
|
||||
});
|
||||
}
|
||||
},
|
||||
AttackEffect::EnergyReward(ec) => {
|
||||
server_events.push(ServerEvent::EnergyChange {
|
||||
entity: attacker_entity,
|
||||
change: EnergyChange {
|
||||
amount: ec as i32,
|
||||
source: EnergySource::HitEnemy,
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
AttackEffect::EnergyReward(ec) => {
|
||||
server_events.push(ServerEvent::EnergyChange {
|
||||
entity: attacker_entity,
|
||||
change: EnergyChange {
|
||||
amount: ec as i32,
|
||||
source: EnergySource::HitEnemy,
|
||||
},
|
||||
});
|
||||
},
|
||||
AttackEffect::Buff(b) => {
|
||||
if thread_rng().gen::<f32>() < b.chance {
|
||||
server_events.push(ServerEvent::Buff {
|
||||
entity: target_entity,
|
||||
buff_change: BuffChange::Add(
|
||||
b.to_buff(attacker_uid, accumulated_damage),
|
||||
),
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
AttackEffect::Buff(b) => {
|
||||
if thread_rng().gen::<f32>() < b.chance {
|
||||
server_events.push(ServerEvent::Buff {
|
||||
entity: target_entity,
|
||||
buff_change: BuffChange::Add(
|
||||
b.to_buff(attacker_uid, accumulated_damage),
|
||||
),
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
server_events
|
||||
@ -198,11 +203,21 @@ impl DamageComponent {
|
||||
pub struct EffectComponent {
|
||||
target: Option<GroupTarget>,
|
||||
effect: AttackEffect,
|
||||
requirement: Option<CombatRequirement>,
|
||||
}
|
||||
|
||||
impl EffectComponent {
|
||||
pub fn new(target: Option<GroupTarget>, effect: AttackEffect) -> Self {
|
||||
Self { target, effect }
|
||||
Self {
|
||||
target,
|
||||
effect,
|
||||
requirement: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_requirement(mut self, requirement: CombatRequirement) -> Self {
|
||||
self.requirement = Some(requirement);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
@ -215,6 +230,11 @@ pub enum AttackEffect {
|
||||
//Lifesteal(f32),
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub enum CombatRequirement {
|
||||
AnyDamage,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
pub enum DamageSource {
|
||||
Buff(BuffKind),
|
||||
|
@ -1,5 +1,7 @@
|
||||
use crate::{
|
||||
combat::{Attack, AttackEffect, CombatBuff, DamageComponent},
|
||||
combat::{
|
||||
Attack, AttackEffect, CombatBuff, CombatRequirement, DamageComponent, EffectComponent,
|
||||
},
|
||||
comp::{CharacterState, MeleeAttack, PoiseChange, PoiseSource, StateUpdate},
|
||||
states::{
|
||||
behavior::{CharacterBehavior, JoinData},
|
||||
@ -99,12 +101,16 @@ impl CharacterBehavior for Data {
|
||||
direction: KnockbackDir::Away,
|
||||
});
|
||||
let energy = AttackEffect::EnergyReward(50);
|
||||
let energy = EffectComponent::new(None, energy)
|
||||
.with_requirement(CombatRequirement::AnyDamage);
|
||||
let buff = AttackEffect::Buff(CombatBuff::default_melee());
|
||||
let damage = DamageComponent::new(damage, Some(GroupTarget::OutOfGroup))
|
||||
.with_effect(knockback)
|
||||
.with_effect(energy)
|
||||
.with_effect(buff);
|
||||
let attack = Attack::default().with_damage(damage).with_crit(0.5, 1.3);
|
||||
let attack = Attack::default()
|
||||
.with_damage(damage)
|
||||
.with_crit(0.5, 1.3)
|
||||
.with_effect(energy);
|
||||
|
||||
// Hit attempt
|
||||
data.updater.insert(data.entity, MeleeAttack {
|
||||
|
@ -1,5 +1,7 @@
|
||||
use crate::{
|
||||
combat::{Attack, AttackEffect, CombatBuff, DamageComponent},
|
||||
combat::{
|
||||
Attack, AttackEffect, CombatBuff, CombatRequirement, DamageComponent, EffectComponent,
|
||||
},
|
||||
comp::{
|
||||
CharacterState, EnergyChange, EnergySource, MeleeAttack, PoiseChange, PoiseSource,
|
||||
StateUpdate,
|
||||
@ -196,12 +198,16 @@ impl CharacterBehavior for Data {
|
||||
+ self.combo * self.static_data.energy_increase,
|
||||
);
|
||||
let energy = AttackEffect::EnergyReward(energy);
|
||||
let energy = EffectComponent::new(None, energy)
|
||||
.with_requirement(CombatRequirement::AnyDamage);
|
||||
let buff = AttackEffect::Buff(CombatBuff::default_melee());
|
||||
let damage = DamageComponent::new(damage, Some(GroupTarget::OutOfGroup))
|
||||
.with_effect(knockback)
|
||||
.with_effect(energy)
|
||||
.with_effect(buff);
|
||||
let attack = Attack::default().with_damage(damage).with_crit(0.5, 1.3);
|
||||
let attack = Attack::default()
|
||||
.with_damage(damage)
|
||||
.with_crit(0.5, 1.3)
|
||||
.with_effect(energy);
|
||||
|
||||
data.updater.insert(data.entity, MeleeAttack {
|
||||
attack,
|
||||
|
Loading…
Reference in New Issue
Block a user