Attacks can now reward energy.

This commit is contained in:
Sam 2021-01-26 12:58:52 -05:00
parent c3408c084c
commit 6d509932db
4 changed files with 37 additions and 32 deletions

View File

@ -9,7 +9,8 @@ use crate::{
slot::EquipSlot,
},
skills::{SkillGroupKind, SkillSet},
Body, BuffKind, Health, HealthChange, HealthSource, Inventory, Stats,
Body, BuffKind, EnergyChange, EnergySource, Health, HealthChange, HealthSource, Inventory,
Stats,
},
effect,
event::ServerEvent,
@ -66,6 +67,7 @@ impl Attack {
pub fn apply_attack(
&self,
target_group: GroupTarget,
attacker_entity: EcsEntity,
target_entity: EcsEntity,
inventory: Option<&Inventory>,
uid: Uid,
@ -99,6 +101,15 @@ impl Attack {
});
}
},
AttackEffect::EnergyReward(ec) => {
server_events.push(ServerEvent::EnergyChange {
entity: attacker_entity,
change: EnergyChange {
amount: *ec as i32,
source: EnergySource::HitEnemy,
},
});
},
}
}
}
@ -146,8 +157,8 @@ pub enum AttackEffect {
//Heal(f32),
//Buff(effect::BuffEffect),
Knockback(Knockback),
/*EnergyChange(f32),
*Lifesteal(f32), */
EnergyReward(u32),
//Lifesteal(f32),
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)]

View File

@ -1,9 +1,6 @@
use crate::{
combat::{Attack, AttackEffect, DamageComponent},
comp::{
CharacterState, EnergyChange, EnergySource, MeleeAttack, PoiseChange, PoiseSource,
StateUpdate,
},
comp::{CharacterState, MeleeAttack, PoiseChange, PoiseSource, StateUpdate},
states::{
behavior::{CharacterBehavior, JoinData},
utils::*,
@ -101,8 +98,10 @@ impl CharacterBehavior for Data {
strength: self.static_data.knockback,
direction: KnockbackDir::Away,
});
let energy = AttackEffect::EnergyReward(50);
let damage = DamageComponent::new(damage, Some(GroupTarget::OutOfGroup))
.with_effect(knockback);
.with_effect(knockback)
.with_effect(energy);
let attack = Attack::default().with_damage(damage).with_crit(0.5, 1.3);
// Hit attempt
@ -156,17 +155,6 @@ impl CharacterBehavior for Data {
},
}
// Grant energy on successful hit
if let Some(attack) = data.melee_attack {
if attack.applied && attack.hit_count > 0 {
data.updater.remove::<MeleeAttack>(data.entity);
update.energy.change_by(EnergyChange {
amount: 50,
source: EnergySource::HitEnemy,
});
}
}
update
}
}

View File

@ -191,8 +191,14 @@ impl CharacterBehavior for Data {
strength: self.static_data.stage_data[stage_index].knockback,
direction: KnockbackDir::Away,
});
let energy = self.static_data.max_energy_gain.min(
self.static_data.initial_energy_gain
+ self.combo * self.static_data.energy_increase,
);
let energy = AttackEffect::EnergyReward(energy);
let damage = DamageComponent::new(damage, Some(GroupTarget::OutOfGroup))
.with_effect(knockback);
.with_effect(knockback)
.with_effect(energy);
let attack = Attack::default().with_damage(damage).with_crit(0.5, 1.3);
data.updater.insert(data.entity, MeleeAttack {
@ -287,10 +293,6 @@ impl CharacterBehavior for Data {
// Grant energy on successful hit
if let Some(attack) = data.melee_attack {
if attack.applied && attack.hit_count > 0 {
let energy = self.static_data.max_energy_gain.min(
self.static_data.initial_energy_gain
+ self.combo * self.static_data.energy_increase,
) as i32;
update.character = CharacterState::ComboMelee(Data {
static_data: self.static_data.clone(),
stage: self.stage,
@ -300,10 +302,6 @@ impl CharacterBehavior for Data {
next_stage: self.next_stage,
});
data.updater.remove::<MeleeAttack>(data.entity);
update.energy.change_by(EnergyChange {
amount: energy,
source: EnergySource::HitEnemy,
});
}
}

View File

@ -129,10 +129,18 @@ impl<'a> System<'a> for Sys {
let dir = Dir::new((pos_b.0 - pos.0).try_normalized().unwrap_or(*ori.0));
let server_events =
attack
.attack
.apply_attack(target_group, b, inventory_b_maybe, *uid, dir);
let server_events = attack.attack.apply_attack(
target_group,
entity,
b,
inventory_b_maybe,
*uid,
dir,
);
if !server_events.is_empty() {
attack.hit_count += 1;
}
for event in server_events {
server_emitter.emit(event);