2021-03-02 19:26:45 +00:00
|
|
|
use crate::{
|
|
|
|
combat::{Attack, AttackEffect, CombatEffect, CombatRequirement, GroupTarget},
|
2021-03-14 15:19:22 +00:00
|
|
|
comp::{beam, CharacterState, Ori, Pos, StateUpdate},
|
2021-03-02 19:26:45 +00:00
|
|
|
event::ServerEvent,
|
|
|
|
states::{
|
|
|
|
behavior::{CharacterBehavior, JoinData},
|
|
|
|
utils::*,
|
|
|
|
},
|
|
|
|
uid::Uid,
|
|
|
|
};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use std::time::Duration;
|
|
|
|
use vek::*;
|
|
|
|
|
|
|
|
/// Separated out to condense update portions of character state
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct StaticData {
|
|
|
|
/// How long until state should deal damage or heal
|
|
|
|
pub buildup_duration: Duration,
|
|
|
|
/// How long the state has until exiting
|
|
|
|
pub recover_duration: Duration,
|
|
|
|
/// How long each beam segment persists for
|
|
|
|
pub beam_duration: Duration,
|
|
|
|
/// Base healing per tick
|
|
|
|
pub heal: f32,
|
|
|
|
/// Ticks of healing per second
|
|
|
|
pub tick_rate: f32,
|
|
|
|
/// Max range
|
|
|
|
pub range: f32,
|
|
|
|
/// Max angle (45.0 will give you a 90.0 angle window)
|
|
|
|
pub max_angle: f32,
|
|
|
|
/// Energy consumed per second for heal ticks
|
|
|
|
pub energy_cost: f32,
|
|
|
|
/// What key is used to press ability
|
|
|
|
pub ability_info: AbilityInfo,
|
2021-03-03 04:56:09 +00:00
|
|
|
/// Used to specify the beam to the frontend
|
|
|
|
pub specifier: beam::FrontendSpecifier,
|
2021-03-02 19:26:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct Data {
|
|
|
|
/// Struct containing data that does not change over the course of the
|
|
|
|
/// character state
|
|
|
|
pub static_data: StaticData,
|
|
|
|
/// Timer for each stage
|
|
|
|
pub timer: Duration,
|
|
|
|
/// What section the character stage is in
|
|
|
|
pub stage_section: StageSection,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CharacterBehavior for Data {
|
|
|
|
fn behavior(&self, data: &JoinData) -> StateUpdate {
|
|
|
|
let mut update = StateUpdate::from(data);
|
|
|
|
|
|
|
|
handle_move(data, &mut update, 0.4);
|
|
|
|
handle_jump(data, &mut update);
|
|
|
|
if !ability_key_is_pressed(data, self.static_data.ability_info.key) {
|
|
|
|
handle_interrupt(data, &mut update, false);
|
|
|
|
match update.character {
|
|
|
|
CharacterState::HealingBeam(_) => {},
|
|
|
|
_ => {
|
|
|
|
return update;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match self.stage_section {
|
|
|
|
StageSection::Buildup => {
|
|
|
|
if self.timer < self.static_data.buildup_duration {
|
|
|
|
// Build up
|
|
|
|
update.character = CharacterState::HealingBeam(Data {
|
|
|
|
timer: self
|
|
|
|
.timer
|
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
|
|
|
.unwrap_or_default(),
|
|
|
|
..*self
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Creates beam
|
|
|
|
data.updater.insert(data.entity, beam::Beam {
|
|
|
|
hit_entities: Vec::<Uid>::new(),
|
|
|
|
tick_dur: Duration::from_secs_f32(1.0 / self.static_data.tick_rate),
|
|
|
|
timer: Duration::default(),
|
|
|
|
});
|
|
|
|
// Build up
|
|
|
|
update.character = CharacterState::HealingBeam(Data {
|
|
|
|
timer: Duration::default(),
|
|
|
|
stage_section: StageSection::Cast,
|
|
|
|
..*self
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StageSection::Cast => {
|
2021-03-13 00:38:20 +00:00
|
|
|
if
|
|
|
|
/* ability_key_is_pressed(data, self.static_data.ability_info.key) */
|
2021-03-14 15:19:22 +00:00
|
|
|
input_is_pressed(data, self.static_data.ability_info) {
|
2021-03-02 19:26:45 +00:00
|
|
|
let speed =
|
|
|
|
self.static_data.range / self.static_data.beam_duration.as_secs_f32();
|
|
|
|
let heal = AttackEffect::new(
|
|
|
|
Some(GroupTarget::InGroup),
|
|
|
|
CombatEffect::Heal(self.static_data.heal),
|
|
|
|
)
|
2021-03-02 22:19:38 +00:00
|
|
|
.with_requirement(CombatRequirement::Energy(self.static_data.energy_cost))
|
|
|
|
.with_requirement(CombatRequirement::Combo(1));
|
2021-03-02 19:26:45 +00:00
|
|
|
let attack = Attack::default().with_effect(heal);
|
|
|
|
|
|
|
|
let properties = beam::Properties {
|
|
|
|
attack,
|
|
|
|
angle: self.static_data.max_angle.to_radians(),
|
|
|
|
speed,
|
|
|
|
duration: self.static_data.beam_duration,
|
|
|
|
owner: Some(*data.uid),
|
2021-03-03 04:56:09 +00:00
|
|
|
specifier: self.static_data.specifier,
|
2021-03-02 19:26:45 +00:00
|
|
|
};
|
|
|
|
// Gets offsets
|
2021-03-03 05:18:01 +00:00
|
|
|
let body_offsets = Vec3::new(
|
|
|
|
(data.body.radius() + 1.0) * data.inputs.look_dir.x,
|
|
|
|
(data.body.radius() + 1.0) * data.inputs.look_dir.y,
|
|
|
|
data.body.eye_height() * 0.6,
|
|
|
|
);
|
2021-03-02 19:26:45 +00:00
|
|
|
let pos = Pos(data.pos.0 + body_offsets);
|
|
|
|
// Create beam segment
|
|
|
|
update.server_events.push_front(ServerEvent::BeamSegment {
|
|
|
|
properties,
|
|
|
|
pos,
|
|
|
|
ori: Ori::from(data.inputs.look_dir),
|
|
|
|
});
|
|
|
|
update.character = CharacterState::HealingBeam(Data {
|
|
|
|
timer: self
|
|
|
|
.timer
|
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
|
|
|
.unwrap_or_default(),
|
|
|
|
..*self
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
update.character = CharacterState::HealingBeam(Data {
|
|
|
|
timer: Duration::default(),
|
|
|
|
stage_section: StageSection::Recover,
|
|
|
|
..*self
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
StageSection::Recover => {
|
|
|
|
if self.timer < self.static_data.recover_duration {
|
|
|
|
update.character = CharacterState::HealingBeam(Data {
|
|
|
|
timer: self
|
|
|
|
.timer
|
|
|
|
.checked_add(Duration::from_secs_f32(data.dt.0))
|
|
|
|
.unwrap_or_default(),
|
|
|
|
..*self
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
// Done
|
|
|
|
update.character = CharacterState::Wielding;
|
|
|
|
// Make sure attack component is removed
|
|
|
|
data.updater.remove::<beam::Beam>(data.entity);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
// If it somehow ends up in an incorrect stage section
|
|
|
|
update.character = CharacterState::Wielding;
|
|
|
|
// Make sure attack component is removed
|
|
|
|
data.updater.remove::<beam::Beam>(data.entity);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
update
|
|
|
|
}
|
|
|
|
}
|