mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
moving CharacterState interpreting methods to character_state.rs
This commit is contained in:
parent
93045ba1ee
commit
0b07b14093
@ -1,8 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
combat::Attack,
|
combat::Attack,
|
||||||
comp::{tool::ToolKind, Density, Energy, InputAttr, InputKind, Ori, Pos, Vel},
|
comp::{tool::ToolKind, ControlAction, Density, Energy, InputAttr, InputKind, Ori, Pos, Vel},
|
||||||
event::{LocalEvent, ServerEvent},
|
event::{LocalEvent, ServerEvent},
|
||||||
states::{behavior::JoinData, utils::StageSection, *},
|
states::{
|
||||||
|
self,
|
||||||
|
behavior::{CharacterBehavior, JoinData},
|
||||||
|
utils::StageSection,
|
||||||
|
*,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use specs::{Component, DerefFlaggedStorage, VecStorage};
|
use specs::{Component, DerefFlaggedStorage, VecStorage};
|
||||||
@ -216,6 +221,82 @@ impl CharacterState {
|
|||||||
// Check if state is the same without looking at the inner data
|
// Check if state is the same without looking at the inner data
|
||||||
std::mem::discriminant(self) == std::mem::discriminant(other)
|
std::mem::discriminant(self) == std::mem::discriminant(other)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn execute_behavior(&self, j: &JoinData) -> StateUpdate {
|
||||||
|
match &self {
|
||||||
|
CharacterState::Idle => states::idle::Data.behavior(&j),
|
||||||
|
CharacterState::Talk => states::talk::Data.behavior(&j),
|
||||||
|
CharacterState::Climb(data) => data.behavior(&j),
|
||||||
|
CharacterState::Glide(data) => data.behavior(&j),
|
||||||
|
CharacterState::GlideWield => states::glide_wield::Data.behavior(&j),
|
||||||
|
CharacterState::Stunned(data) => data.behavior(&j),
|
||||||
|
CharacterState::Sit => states::sit::Data::behavior(&states::sit::Data, &j),
|
||||||
|
CharacterState::Dance => states::dance::Data::behavior(&states::dance::Data, &j),
|
||||||
|
CharacterState::Sneak => states::sneak::Data::behavior(&states::sneak::Data, &j),
|
||||||
|
CharacterState::BasicBlock(data) => data.behavior(&j),
|
||||||
|
CharacterState::Roll(data) => data.behavior(&j),
|
||||||
|
CharacterState::Wielding => states::wielding::Data.behavior(&j),
|
||||||
|
CharacterState::Equipping(data) => data.behavior(&j),
|
||||||
|
CharacterState::ComboMelee(data) => data.behavior(&j),
|
||||||
|
CharacterState::BasicMelee(data) => data.behavior(&j),
|
||||||
|
CharacterState::BasicRanged(data) => data.behavior(&j),
|
||||||
|
CharacterState::Boost(data) => data.behavior(&j),
|
||||||
|
CharacterState::DashMelee(data) => data.behavior(&j),
|
||||||
|
CharacterState::LeapMelee(data) => data.behavior(&j),
|
||||||
|
CharacterState::SpinMelee(data) => data.behavior(&j),
|
||||||
|
CharacterState::ChargedMelee(data) => data.behavior(&j),
|
||||||
|
CharacterState::ChargedRanged(data) => data.behavior(&j),
|
||||||
|
CharacterState::RepeaterRanged(data) => data.behavior(&j),
|
||||||
|
CharacterState::Shockwave(data) => data.behavior(&j),
|
||||||
|
CharacterState::BasicBeam(data) => data.behavior(&j),
|
||||||
|
CharacterState::BasicAura(data) => data.behavior(&j),
|
||||||
|
CharacterState::Blink(data) => data.behavior(&j),
|
||||||
|
CharacterState::BasicSummon(data) => data.behavior(&j),
|
||||||
|
CharacterState::SelfBuff(data) => data.behavior(&j),
|
||||||
|
CharacterState::SpriteSummon(data) => data.behavior(&j),
|
||||||
|
CharacterState::UseItem(data) => data.behavior(&j),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_action(&self, j: &JoinData, action: ControlAction) -> StateUpdate {
|
||||||
|
match &self {
|
||||||
|
CharacterState::Idle => states::idle::Data.handle_event(&j, action),
|
||||||
|
CharacterState::Talk => states::talk::Data.handle_event(&j, action),
|
||||||
|
CharacterState::Climb(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::Glide(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::GlideWield => states::glide_wield::Data.handle_event(&j, action),
|
||||||
|
CharacterState::Stunned(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::Sit => states::sit::Data::handle_event(&states::sit::Data, &j, action),
|
||||||
|
CharacterState::Dance => {
|
||||||
|
states::dance::Data::handle_event(&states::dance::Data, &j, action)
|
||||||
|
},
|
||||||
|
CharacterState::Sneak => {
|
||||||
|
states::sneak::Data::handle_event(&states::sneak::Data, &j, action)
|
||||||
|
},
|
||||||
|
CharacterState::BasicBlock(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::Roll(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::Wielding => states::wielding::Data.handle_event(&j, action),
|
||||||
|
CharacterState::Equipping(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::ComboMelee(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::BasicMelee(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::BasicRanged(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::Boost(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::DashMelee(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::LeapMelee(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::SpinMelee(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::ChargedMelee(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::ChargedRanged(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::RepeaterRanged(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::Shockwave(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::BasicBeam(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::BasicAura(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::Blink(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::BasicSummon(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::SelfBuff(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::SpriteSummon(data) => data.handle_event(&j, action),
|
||||||
|
CharacterState::UseItem(data) => data.handle_event(&j, action),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CharacterState {
|
impl Default for CharacterState {
|
||||||
|
@ -5,17 +5,14 @@ use specs::{
|
|||||||
|
|
||||||
use common::{
|
use common::{
|
||||||
comp::{
|
comp::{
|
||||||
self, inventory::item::MaterialStatManifest, Beam, Body, CharacterState, Combo,
|
self, inventory::item::MaterialStatManifest, Beam, Body, CharacterState, Combo, Controller,
|
||||||
ControlAction, Controller, Density, Energy, Health, Inventory, InventoryManip, Mass, Melee,
|
Density, Energy, Health, Inventory, InventoryManip, Mass, Melee, Mounting, Ori,
|
||||||
Mounting, Ori, PhysicsState, Poise, PoiseState, Pos, SkillSet, StateUpdate, Stats, Vel,
|
PhysicsState, Poise, PoiseState, Pos, SkillSet, StateUpdate, Stats, Vel,
|
||||||
},
|
},
|
||||||
event::{Emitter, EventBus, LocalEvent, ServerEvent},
|
event::{Emitter, EventBus, LocalEvent, ServerEvent},
|
||||||
outcome::Outcome,
|
outcome::Outcome,
|
||||||
resources::DeltaTime,
|
resources::DeltaTime,
|
||||||
states::{
|
states::behavior::{JoinData, JoinStruct},
|
||||||
self,
|
|
||||||
behavior::{CharacterBehavior, JoinData, JoinStruct},
|
|
||||||
},
|
|
||||||
terrain::TerrainGrid,
|
terrain::TerrainGrid,
|
||||||
uid::Uid,
|
uid::Uid,
|
||||||
};
|
};
|
||||||
@ -272,14 +269,13 @@ impl<'a> System<'a> for Sys {
|
|||||||
&read_data.dt,
|
&read_data.dt,
|
||||||
&read_data.msm,
|
&read_data.msm,
|
||||||
);
|
);
|
||||||
let mut state_update = <Sys>::handle_action_of_current_state(action, &j);
|
let state_update = j.character.handle_action(&j, action);
|
||||||
|
<Sys>::publish_state_update(
|
||||||
<Sys>::emit_state_updates(
|
&mut join_struct,
|
||||||
&mut server_emitter,
|
state_update,
|
||||||
&mut local_emitter,
|
&mut local_emitter,
|
||||||
&mut state_update,
|
&mut server_emitter,
|
||||||
);
|
);
|
||||||
<Sys>::incorporate_update(&mut join_struct, state_update, &mut server_emitter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mounted occurs after control actions have been handled
|
// Mounted occurs after control actions have been handled
|
||||||
@ -299,105 +295,27 @@ impl<'a> System<'a> for Sys {
|
|||||||
&read_data.msm,
|
&read_data.msm,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut state_update = <Sys>::execute_behavior_of_current_state(&j);
|
let state_update = j.character.execute_behavior(&j);
|
||||||
|
<Sys>::publish_state_update(
|
||||||
<Sys>::emit_state_updates(&mut server_emitter, &mut local_emitter, &mut state_update);
|
&mut join_struct,
|
||||||
<Sys>::incorporate_update(&mut join_struct, state_update, &mut server_emitter);
|
state_update,
|
||||||
|
&mut local_emitter,
|
||||||
|
&mut server_emitter,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Sys {
|
impl Sys {
|
||||||
fn execute_behavior_of_current_state(j: &JoinData) -> StateUpdate {
|
fn publish_state_update(
|
||||||
match j.character {
|
join: &mut JoinStruct,
|
||||||
CharacterState::Idle => states::idle::Data.behavior(&j),
|
mut state_update: StateUpdate,
|
||||||
CharacterState::Talk => states::talk::Data.behavior(&j),
|
|
||||||
CharacterState::Climb(data) => data.behavior(&j),
|
|
||||||
CharacterState::Glide(data) => data.behavior(&j),
|
|
||||||
CharacterState::GlideWield => states::glide_wield::Data.behavior(&j),
|
|
||||||
CharacterState::Stunned(data) => data.behavior(&j),
|
|
||||||
CharacterState::Sit => states::sit::Data::behavior(&states::sit::Data, &j),
|
|
||||||
CharacterState::Dance => states::dance::Data::behavior(&states::dance::Data, &j),
|
|
||||||
CharacterState::Sneak => states::sneak::Data::behavior(&states::sneak::Data, &j),
|
|
||||||
CharacterState::BasicBlock(data) => data.behavior(&j),
|
|
||||||
CharacterState::Roll(data) => data.behavior(&j),
|
|
||||||
CharacterState::Wielding => states::wielding::Data.behavior(&j),
|
|
||||||
CharacterState::Equipping(data) => data.behavior(&j),
|
|
||||||
CharacterState::ComboMelee(data) => data.behavior(&j),
|
|
||||||
CharacterState::BasicMelee(data) => data.behavior(&j),
|
|
||||||
CharacterState::BasicRanged(data) => data.behavior(&j),
|
|
||||||
CharacterState::Boost(data) => data.behavior(&j),
|
|
||||||
CharacterState::DashMelee(data) => data.behavior(&j),
|
|
||||||
CharacterState::LeapMelee(data) => data.behavior(&j),
|
|
||||||
CharacterState::SpinMelee(data) => data.behavior(&j),
|
|
||||||
CharacterState::ChargedMelee(data) => data.behavior(&j),
|
|
||||||
CharacterState::ChargedRanged(data) => data.behavior(&j),
|
|
||||||
CharacterState::RepeaterRanged(data) => data.behavior(&j),
|
|
||||||
CharacterState::Shockwave(data) => data.behavior(&j),
|
|
||||||
CharacterState::BasicBeam(data) => data.behavior(&j),
|
|
||||||
CharacterState::BasicAura(data) => data.behavior(&j),
|
|
||||||
CharacterState::Blink(data) => data.behavior(&j),
|
|
||||||
CharacterState::BasicSummon(data) => data.behavior(&j),
|
|
||||||
CharacterState::SelfBuff(data) => data.behavior(&j),
|
|
||||||
CharacterState::SpriteSummon(data) => data.behavior(&j),
|
|
||||||
CharacterState::UseItem(data) => data.behavior(&j),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_action_of_current_state(action: ControlAction, j: &JoinData) -> StateUpdate {
|
|
||||||
match j.character {
|
|
||||||
CharacterState::Idle => states::idle::Data.handle_event(&j, action),
|
|
||||||
CharacterState::Talk => states::talk::Data.handle_event(&j, action),
|
|
||||||
CharacterState::Climb(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::Glide(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::GlideWield => states::glide_wield::Data.handle_event(&j, action),
|
|
||||||
CharacterState::Stunned(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::Sit => states::sit::Data::handle_event(&states::sit::Data, &j, action),
|
|
||||||
CharacterState::Dance => {
|
|
||||||
states::dance::Data::handle_event(&states::dance::Data, &j, action)
|
|
||||||
},
|
|
||||||
CharacterState::Sneak => {
|
|
||||||
states::sneak::Data::handle_event(&states::sneak::Data, &j, action)
|
|
||||||
},
|
|
||||||
CharacterState::BasicBlock(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::Roll(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::Wielding => states::wielding::Data.handle_event(&j, action),
|
|
||||||
CharacterState::Equipping(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::ComboMelee(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::BasicMelee(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::BasicRanged(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::Boost(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::DashMelee(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::LeapMelee(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::SpinMelee(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::ChargedMelee(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::ChargedRanged(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::RepeaterRanged(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::Shockwave(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::BasicBeam(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::BasicAura(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::Blink(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::BasicSummon(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::SelfBuff(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::SpriteSummon(data) => data.handle_event(&j, action),
|
|
||||||
CharacterState::UseItem(data) => data.handle_event(&j, action),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn emit_state_updates(
|
|
||||||
server_emitter: &mut Emitter<ServerEvent>,
|
|
||||||
local_emitter: &mut Emitter<LocalEvent>,
|
local_emitter: &mut Emitter<LocalEvent>,
|
||||||
state_update: &mut StateUpdate,
|
server_emitter: &mut Emitter<ServerEvent>,
|
||||||
) {
|
) {
|
||||||
local_emitter.append(&mut state_update.local_events);
|
local_emitter.append(&mut state_update.local_events);
|
||||||
server_emitter.append(&mut state_update.server_events);
|
server_emitter.append(&mut state_update.server_events);
|
||||||
}
|
|
||||||
|
|
||||||
fn incorporate_update(
|
|
||||||
join: &mut JoinStruct,
|
|
||||||
mut state_update: StateUpdate,
|
|
||||||
server_emitter: &mut Emitter<ServerEvent>,
|
|
||||||
) {
|
|
||||||
// TODO: if checking equality is expensive use optional field in StateUpdate
|
// TODO: if checking equality is expensive use optional field in StateUpdate
|
||||||
if *join.char_state != state_update.character {
|
if *join.char_state != state_update.character {
|
||||||
*join.char_state = state_update.character
|
*join.char_state = state_update.character
|
||||||
|
Loading…
Reference in New Issue
Block a user