Better climbing, fireball impl

This commit is contained in:
timokoesters 2020-03-24 20:09:23 +01:00
parent ea2500e7ab
commit 58585e0810
8 changed files with 14 additions and 123 deletions

View File

@ -17,12 +17,7 @@ pub enum CharacterAbility {
max_angle: f32, max_angle: f32,
}, },
BasicRanged { BasicRanged {
prepare_duration: Duration, energy_cost: u32,
recover_duration: Duration,
projectile: Projectile,
projectile_body: Body,
},
CastFireball {
prepare_duration: Duration, prepare_duration: Duration,
recover_duration: Duration, recover_duration: Duration,
projectile: Projectile, projectile: Projectile,
@ -70,11 +65,11 @@ impl CharacterAbility {
.try_change_by(-300, EnergySource::Ability) .try_change_by(-300, EnergySource::Ability)
.is_ok() .is_ok()
}, },
CharacterAbility::CastFireball { .. } => { CharacterAbility::BasicRanged { energy_cost, .. } => {
!data.physics.in_fluid !data.physics.in_fluid
&& update && update
.energy .energy
.try_change_by(-500, EnergySource::Ability) .try_change_by(-(*energy_cost as i32), EnergySource::Ability)
.is_ok() .is_ok()
}, },
_ => true, _ => true,
@ -127,6 +122,7 @@ impl From<&CharacterAbility> for CharacterState {
recover_duration, recover_duration,
projectile, projectile,
projectile_body, projectile_body,
energy_cost: _,
} => CharacterState::BasicRanged(basic_ranged::Data { } => CharacterState::BasicRanged(basic_ranged::Data {
exhausted: false, exhausted: false,
prepare_timer: Duration::default(), prepare_timer: Duration::default(),
@ -135,18 +131,6 @@ impl From<&CharacterAbility> for CharacterState {
projectile: projectile.clone(), projectile: projectile.clone(),
projectile_body: *projectile_body, projectile_body: *projectile_body,
}), }),
CharacterAbility::CastFireball {
prepare_duration,
recover_duration,
projectile,
projectile_body,
} => CharacterState::CastFireball(cast_fireball::Data {
exhausted: false,
prepare_duration: *prepare_duration,
recover_duration: *recover_duration,
projectile: projectile.clone(),
projectile_body: *projectile_body,
}),
CharacterAbility::Boost { duration, only_up } => CharacterState::Boost(boost::Data { CharacterAbility::Boost { duration, only_up } => CharacterState::Boost(boost::Data {
duration: *duration, duration: *duration,
only_up: *only_up, only_up: *only_up,

View File

@ -52,8 +52,6 @@ pub enum CharacterState {
BasicMelee(basic_melee::Data), BasicMelee(basic_melee::Data),
/// A basic ranged attack (e.g. bow) /// A basic ranged attack (e.g. bow)
BasicRanged(basic_ranged::Data), BasicRanged(basic_ranged::Data),
/// Cast a fireball
CastFireball(cast_fireball::Data),
/// A force will boost you into a direction for some duration /// A force will boost you into a direction for some duration
Boost(boost::Data), Boost(boost::Data),
/// Dash forward and then attack /// Dash forward and then attack
@ -72,7 +70,6 @@ impl CharacterState {
CharacterState::Wielding CharacterState::Wielding
| CharacterState::BasicMelee(_) | CharacterState::BasicMelee(_)
| CharacterState::BasicRanged(_) | CharacterState::BasicRanged(_)
| CharacterState::CastFireball(_)
| CharacterState::DashMelee(_) | CharacterState::DashMelee(_)
| CharacterState::TripleStrike(_) | CharacterState::TripleStrike(_)
| CharacterState::TimedCombo(_) | CharacterState::TimedCombo(_)
@ -92,7 +89,6 @@ impl CharacterState {
match self { match self {
CharacterState::BasicMelee(_) CharacterState::BasicMelee(_)
| CharacterState::BasicRanged(_) | CharacterState::BasicRanged(_)
| CharacterState::CastFireball(_)
| CharacterState::TimedCombo(_) | CharacterState::TimedCombo(_)
| CharacterState::DashMelee(_) | CharacterState::DashMelee(_)
| CharacterState::TripleStrike(_) => true, | CharacterState::TripleStrike(_) => true,

View File

@ -89,6 +89,7 @@ impl ToolData {
max_angle: 60.0, max_angle: 60.0,
}], }],
Bow(_) => vec![BasicRanged { Bow(_) => vec![BasicRanged {
energy_cost: 0,
prepare_duration: Duration::from_millis(100), prepare_duration: Duration::from_millis(100),
recover_duration: Duration::from_millis(300), recover_duration: Duration::from_millis(300),
projectile: Projectile { projectile: Projectile {
@ -127,6 +128,7 @@ impl ToolData {
max_angle: 45.0, max_angle: 45.0,
}, },
BasicRanged { BasicRanged {
energy_cost: 0,
prepare_duration: Duration::from_millis(300), prepare_duration: Duration::from_millis(300),
recover_duration: Duration::from_millis(100), recover_duration: Duration::from_millis(100),
projectile: Projectile { projectile: Projectile {
@ -145,7 +147,8 @@ impl ToolData {
}, },
projectile_body: Body::Object(object::Body::BoltFire), projectile_body: Body::Object(object::Body::BoltFire),
}, },
CastFireball { BasicRanged {
energy_cost: 400,
prepare_duration: Duration::from_millis(800), prepare_duration: Duration::from_millis(800),
recover_duration: Duration::from_millis(300), recover_duration: Duration::from_millis(300),
projectile: Projectile { projectile: Projectile {
@ -180,6 +183,7 @@ impl ToolData {
}, },
], ],
Possess => vec![BasicRanged { Possess => vec![BasicRanged {
energy_cost: 0,
prepare_duration: Duration::from_millis(300), prepare_duration: Duration::from_millis(300),
recover_duration: Duration::from_millis(300), recover_duration: Duration::from_millis(300),
projectile: Projectile { projectile: Projectile {

View File

@ -1,85 +0,0 @@
use crate::{
comp::{Body, CharacterState, LightEmitter, Projectile, StateUpdate},
event::ServerEvent,
states::utils::*,
sys::character_behavior::*,
};
use std::time::Duration;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Data {
/// How long we need to wait before we fire
pub prepare_duration: Duration,
/// How long the state has until exiting
pub recover_duration: Duration,
/// Projectile
pub projectile: Projectile,
/// Projectile
pub projectile_body: Body,
/// Whether the attack fired already
pub exhausted: bool,
}
impl CharacterBehavior for Data {
fn behavior(&self, data: &JoinData) -> StateUpdate {
let mut update = StateUpdate::from(data);
handle_move(data, &mut update);
handle_jump(data, &mut update);
if self.prepare_duration != Duration::default() {
// Prepare
update.character = CharacterState::CastFireball(Data {
prepare_duration: self
.prepare_duration
.checked_sub(Duration::from_secs_f32(data.dt.0))
.unwrap_or_default(),
recover_duration: self.recover_duration,
projectile: self.projectile.clone(),
projectile_body: self.projectile_body,
exhausted: false,
});
} else if !self.exhausted {
// Fire
let mut projectile = self.projectile.clone();
projectile.set_owner(*data.uid);
update.server_events.push_front(ServerEvent::Shoot {
entity: data.entity,
dir: data.inputs.look_dir,
body: self.projectile_body,
light: Some(LightEmitter {
col: (0.72, 0.11, 0.11).into(),
..Default::default()
}),
projectile,
gravity: None,
});
update.character = CharacterState::CastFireball(Data {
prepare_duration: Duration::default(),
recover_duration: self.recover_duration,
projectile: self.projectile.clone(),
projectile_body: self.projectile_body,
exhausted: true,
});
} else if self.recover_duration != Duration::default() {
// Recovery
update.character = CharacterState::CastFireball(Data {
prepare_duration: Duration::default(),
recover_duration: self
.recover_duration
.checked_sub(Duration::from_secs_f32(data.dt.0))
.unwrap_or_default(),
projectile: self.projectile.clone(),
projectile_body: self.projectile_body,
exhausted: true,
});
return update;
} else {
// Done
update.character = CharacterState::Wielding;
}
update
}
}

View File

@ -26,8 +26,11 @@ impl CharacterBehavior for Data {
update.character = CharacterState::Idle {}; update.character = CharacterState::Idle {};
} }
// If no wall is in front of character ... // If no wall is in front of character or we stopped holding space:
if data.physics.on_wall.is_none() || data.physics.on_ground { if data.physics.on_wall.is_none()
|| data.physics.on_ground
|| !data.inputs.jump.is_pressed()
{
if data.inputs.jump.is_pressed() { if data.inputs.jump.is_pressed() {
// They've climbed atop something, give them a boost // They've climbed atop something, give them a boost
update update

View File

@ -2,7 +2,6 @@ pub mod basic_block;
pub mod basic_melee; pub mod basic_melee;
pub mod basic_ranged; pub mod basic_ranged;
pub mod boost; pub mod boost;
pub mod cast_fireball;
pub mod climb; pub mod climb;
pub mod dash_melee; pub mod dash_melee;
pub mod equipping; pub mod equipping;

View File

@ -183,7 +183,6 @@ impl<'a> System<'a> for Sys {
CharacterState::TripleStrike(data) => data.behavior(&j), CharacterState::TripleStrike(data) => data.behavior(&j),
CharacterState::BasicMelee(data) => data.behavior(&j), CharacterState::BasicMelee(data) => data.behavior(&j),
CharacterState::BasicRanged(data) => data.behavior(&j), CharacterState::BasicRanged(data) => data.behavior(&j),
CharacterState::CastFireball(data) => data.behavior(&j),
CharacterState::Boost(data) => data.behavior(&j), CharacterState::Boost(data) => data.behavior(&j),
CharacterState::DashMelee(data) => data.behavior(&j), CharacterState::DashMelee(data) => data.behavior(&j),
CharacterState::TimedCombo(data) => data.behavior(&j), CharacterState::TimedCombo(data) => data.behavior(&j),

View File

@ -488,15 +488,6 @@ impl FigureMgr {
skeleton_attr, skeleton_attr,
) )
}, },
CharacterState::CastFireball(_) => {
anim::character::ShootAnimation::update_skeleton(
&target_base,
(active_tool_kind, time),
state.state_time,
&mut state_animation_rate,
skeleton_attr,
)
},
CharacterState::Boost(_) => { CharacterState::Boost(_) => {
anim::character::AttackAnimation::update_skeleton( anim::character::AttackAnimation::update_skeleton(
&target_base, &target_base,