Healing staff

This commit is contained in:
timokoesters 2020-03-24 22:03:11 +01:00
parent f0ce088810
commit 2117bb05d0
9 changed files with 63 additions and 29 deletions

View File

@ -12,9 +12,10 @@ use std::time::Duration;
#[derive(Clone, PartialEq, Debug, Serialize, Deserialize)]
pub enum CharacterAbility {
BasicMelee {
energy_cost: u32,
buildup_duration: Duration,
recover_duration: Duration,
base_damage: u32,
base_healthchange: i32,
range: f32,
max_angle: f32,
},
@ -69,6 +70,13 @@ impl CharacterAbility {
.try_change_by(-300, EnergySource::Ability)
.is_ok()
},
CharacterAbility::BasicMelee { energy_cost, .. } => {
!data.physics.in_fluid
&& update
.energy
.try_change_by(-(*energy_cost as i32), EnergySource::Ability)
.is_ok()
},
CharacterAbility::BasicRanged { energy_cost, .. } => {
!data.physics.in_fluid
&& update
@ -110,14 +118,15 @@ impl From<&CharacterAbility> for CharacterState {
CharacterAbility::BasicMelee {
buildup_duration,
recover_duration,
base_damage,
base_healthchange,
range,
max_angle,
energy_cost: _,
} => CharacterState::BasicMelee(basic_melee::Data {
exhausted: false,
buildup_duration: *buildup_duration,
recover_duration: *recover_duration,
base_damage: *base_damage,
base_healthchange: *base_healthchange,
range: *range,
max_angle: *max_angle,
}),

View File

@ -127,7 +127,7 @@ impl Component for CharacterState {
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Attacking {
pub base_damage: u32,
pub base_healthchange: i32,
pub range: f32,
pub max_angle: f32,
pub applied: bool,

View File

@ -76,16 +76,18 @@ impl ToolData {
base_damage: 20,
}],
Axe(_) => vec![BasicMelee {
energy_cost: 0,
buildup_duration: Duration::from_millis(700),
recover_duration: Duration::from_millis(100),
base_damage: 8,
base_healthchange: -8,
range: 3.5,
max_angle: 30.0,
}],
Hammer(_) => vec![BasicMelee {
energy_cost: 0,
buildup_duration: Duration::from_millis(700),
recover_duration: Duration::from_millis(300),
base_damage: 10,
base_healthchange: -10,
range: 3.5,
max_angle: 60.0,
}],
@ -112,21 +114,19 @@ impl ToolData {
projectile_gravity: Some(Gravity(0.1)),
}],
Dagger(_) => vec![BasicMelee {
energy_cost: 0,
buildup_duration: Duration::from_millis(100),
recover_duration: Duration::from_millis(400),
base_damage: 5,
base_healthchange: -5,
range: 3.5,
max_angle: 60.0,
}],
Staff(_) => vec![
//Intended behaviour for the healing sceptre: M1 -> Heal a single target (not a
// projectile, just a heal for the target.) Optional: Green flash of the healed
// target. M2: Heal everyone around the caster, including the
// caster
Staff(StaffKind::BasicStaff) => vec![
BasicMelee {
energy_cost: 0,
buildup_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(300),
base_damage: 1,
base_healthchange: -1,
range: 10.0,
max_angle: 45.0,
},
@ -185,6 +185,24 @@ impl ToolData {
projectile_gravity: None,
},
],
Staff(StaffKind::Sceptre) => vec![
BasicMelee {
energy_cost: 0,
buildup_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(300),
base_healthchange: -1,
range: 10.0,
max_angle: 45.0,
},
BasicMelee {
energy_cost: 350,
buildup_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(1000),
base_healthchange: 15,
range: 10.0,
max_angle: 45.0,
},
],
Shield(_) => vec![BasicBlock],
Debug(kind) => match kind {
DebugKind::Boost => vec![

View File

@ -11,8 +11,8 @@ pub struct Data {
pub buildup_duration: Duration,
/// How long the state has until exiting
pub recover_duration: Duration,
/// Base damage
pub base_damage: u32,
/// Base damage (negative) or healing (positive)
pub base_healthchange: i32,
/// Max range
pub range: f32,
/// Max angle (45.0 will give you a 90.0 angle window)
@ -35,7 +35,7 @@ impl CharacterBehavior for Data {
.checked_sub(Duration::from_secs_f32(data.dt.0))
.unwrap_or_default(),
recover_duration: self.recover_duration,
base_damage: self.base_damage,
base_healthchange: self.base_healthchange,
range: self.range,
max_angle: self.max_angle,
exhausted: false,
@ -43,7 +43,7 @@ impl CharacterBehavior for Data {
} else if !self.exhausted {
// Hit attempt
data.updater.insert(data.entity, Attacking {
base_damage: self.base_damage,
base_healthchange: self.base_healthchange,
range: self.range,
max_angle: self.max_angle.to_radians(),
applied: false,
@ -53,7 +53,7 @@ impl CharacterBehavior for Data {
update.character = CharacterState::BasicMelee(Data {
buildup_duration: self.buildup_duration,
recover_duration: self.recover_duration,
base_damage: self.base_damage,
base_healthchange: self.base_healthchange,
range: self.range,
max_angle: self.max_angle,
exhausted: true,
@ -66,7 +66,7 @@ impl CharacterBehavior for Data {
.recover_duration
.checked_sub(Duration::from_secs_f32(data.dt.0))
.unwrap_or_default(),
base_damage: self.base_damage,
base_healthchange: self.base_healthchange,
range: self.range,
max_angle: self.max_angle,
exhausted: true,

View File

@ -53,7 +53,7 @@ impl CharacterBehavior for Data {
} else if !self.exhausted {
// Hit attempt
data.updater.insert(data.entity, Attacking {
base_damage: self.base_damage,
base_healthchange: -(self.base_damage as i32),
range: 3.5,
max_angle: 180_f32.to_radians(),
applied: false,

View File

@ -52,7 +52,7 @@ impl CharacterBehavior for Data {
else if !self.stage_exhausted {
// Swing hits
data.updater.insert(data.entity, Attacking {
base_damage: self.base_damage * (self.stage as u32 + 1),
base_healthchange: -((self.base_damage * (self.stage as u32 + 1)) as i32),
range: 3.5,
max_angle: 75_f32.to_radians(),
applied: false,

View File

@ -91,7 +91,7 @@ impl CharacterBehavior for Data {
// Try to deal damage in second half of stage
data.updater.insert(data.entity, Attacking {
base_damage: dmg,
base_healthchange: -(dmg as i32),
range: 3.5,
max_angle: 180_f32.to_radians(),
applied: false,

View File

@ -99,28 +99,33 @@ impl<'a> System<'a> for Sys {
&& ori2.angle_between(pos_b2 - pos2) < attack.max_angle + (rad_b / pos2.distance(pos_b2)).atan()
{
// Weapon gives base damage
let mut dmg = attack.base_damage;
let mut healthchange = attack.base_healthchange;
// NPCs do less damage:
if agent_maybe.is_some() {
dmg = (dmg / 2).max(1);
if healthchange > 0 {
healthchange = (healthchange / 2).max(1);
}
if healthchange < 0 {
healthchange = (healthchange / 2).min(-1);
}
}
if rand::random() {
dmg += 1;
healthchange = (healthchange as f32 * 1.2) as i32;
}
// Block
if character_b.is_block()
&& ori_b.0.angle_between(pos.0 - pos_b.0) < BLOCK_ANGLE.to_radians() / 2.0
{
dmg = (dmg as f32 * (1.0 - BLOCK_EFFICIENCY)) as u32
healthchange = (healthchange as f32 * (1.0 - BLOCK_EFFICIENCY)) as i32
}
server_emitter.emit(ServerEvent::Damage {
uid: *uid_b,
change: HealthChange {
amount: -(dmg as i32),
amount: healthchange,
cause: HealthSource::Attack { by: *uid },
},
});

View File

@ -207,9 +207,10 @@ impl<'a> System<'a> for Sys {
// We need the empty item so npcs can attack
item: Item::empty(),
ability1: Some(CharacterAbility::BasicMelee {
energy_cost: 0,
buildup_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(300),
base_damage: 2,
base_healthchange: -2,
range: 3.5,
max_angle: 60.0,
}),
@ -303,9 +304,10 @@ impl<'a> System<'a> for Sys {
"common.items.weapons.zweihander_sword_0",
),
ability1: Some(CharacterAbility::BasicMelee {
energy_cost: 0,
buildup_duration: Duration::from_millis(800),
recover_duration: Duration::from_millis(200),
base_damage: 13,
base_healthchange: -13,
range: 3.5,
max_angle: 60.0,
}),