2020-12-01 00:28:00 +00:00
|
|
|
use crate::{
|
|
|
|
comp::{
|
2021-03-21 18:22:14 +00:00
|
|
|
self, item::MaterialStatManifest, Beam, Body, CharacterState, Combo, ControlAction,
|
2021-03-23 09:51:53 +00:00
|
|
|
Controller, ControllerInputs, Density, Energy, Health, InputAttr, InputKind, Inventory,
|
|
|
|
InventoryAction, Mass, Melee, Ori, PhysicsState, Pos, SkillSet, StateUpdate, Stats, Vel,
|
2020-12-01 00:28:00 +00:00
|
|
|
},
|
|
|
|
resources::DeltaTime,
|
2021-06-03 22:42:50 +00:00
|
|
|
terrain::TerrainGrid,
|
2020-12-13 17:11:55 +00:00
|
|
|
uid::Uid,
|
2020-12-01 00:28:00 +00:00
|
|
|
};
|
|
|
|
use specs::{
|
|
|
|
hibitset,
|
|
|
|
storage::{PairedStorage, SequentialRestriction},
|
2021-01-07 20:25:12 +00:00
|
|
|
DerefFlaggedStorage, Entity, LazyUpdate,
|
2020-12-01 00:28:00 +00:00
|
|
|
};
|
|
|
|
use specs_idvs::IdvStorage;
|
2021-03-21 16:09:16 +00:00
|
|
|
use vek::*;
|
2020-12-01 00:28:00 +00:00
|
|
|
|
|
|
|
pub trait CharacterBehavior {
|
|
|
|
fn behavior(&self, data: &JoinData) -> StateUpdate;
|
|
|
|
// Impl these to provide behavior for these inputs
|
2021-02-08 17:31:17 +00:00
|
|
|
fn swap_equipped_weapons(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
2021-03-01 22:40:42 +00:00
|
|
|
fn manipulate_loadout(&self, data: &JoinData, _inv_action: InventoryAction) -> StateUpdate {
|
2021-02-07 02:15:29 +00:00
|
|
|
StateUpdate::from(data)
|
|
|
|
}
|
2020-12-01 00:28:00 +00:00
|
|
|
fn wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
|
|
|
fn glide_wield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
|
|
|
fn unwield(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
|
|
|
fn sit(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
|
|
|
fn dance(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
|
|
|
fn sneak(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
|
|
|
fn stand(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
2021-01-31 20:29:50 +00:00
|
|
|
fn talk(&self, data: &JoinData) -> StateUpdate { StateUpdate::from(data) }
|
2021-03-21 16:09:16 +00:00
|
|
|
fn start_input(
|
|
|
|
&self,
|
|
|
|
data: &JoinData,
|
|
|
|
input: InputKind,
|
2021-03-21 03:28:13 +00:00
|
|
|
target_entity: Option<Uid>,
|
2021-03-21 16:09:16 +00:00
|
|
|
select_pos: Option<Vec3<f32>>,
|
|
|
|
) -> StateUpdate {
|
2021-03-05 06:09:56 +00:00
|
|
|
let mut update = StateUpdate::from(data);
|
2021-03-21 03:28:13 +00:00
|
|
|
update.queued_inputs.insert(input, InputAttr {
|
|
|
|
select_pos,
|
|
|
|
target_entity,
|
|
|
|
});
|
2021-03-05 06:09:56 +00:00
|
|
|
update
|
|
|
|
}
|
2021-03-12 04:53:25 +00:00
|
|
|
fn cancel_input(&self, data: &JoinData, input: InputKind) -> StateUpdate {
|
|
|
|
let mut update = StateUpdate::from(data);
|
|
|
|
update.removed_inputs.push(input);
|
|
|
|
update
|
|
|
|
}
|
2020-12-01 00:28:00 +00:00
|
|
|
fn handle_event(&self, data: &JoinData, event: ControlAction) -> StateUpdate {
|
|
|
|
match event {
|
2021-02-08 17:31:17 +00:00
|
|
|
ControlAction::SwapEquippedWeapons => self.swap_equipped_weapons(data),
|
2021-03-01 22:40:42 +00:00
|
|
|
ControlAction::InventoryAction(inv_action) => self.manipulate_loadout(data, inv_action),
|
2020-12-01 00:28:00 +00:00
|
|
|
ControlAction::Wield => self.wield(data),
|
|
|
|
ControlAction::GlideWield => self.glide_wield(data),
|
|
|
|
ControlAction::Unwield => self.unwield(data),
|
|
|
|
ControlAction::Sit => self.sit(data),
|
|
|
|
ControlAction::Dance => self.dance(data),
|
|
|
|
ControlAction::Sneak => self.sneak(data),
|
|
|
|
ControlAction::Stand => self.stand(data),
|
2021-01-31 20:29:50 +00:00
|
|
|
ControlAction::Talk => self.talk(data),
|
2021-03-21 16:09:16 +00:00
|
|
|
ControlAction::StartInput {
|
|
|
|
input,
|
2021-03-21 03:28:13 +00:00
|
|
|
target_entity,
|
2021-03-21 16:09:16 +00:00
|
|
|
select_pos,
|
2021-03-21 03:28:13 +00:00
|
|
|
} => self.start_input(data, input, target_entity, select_pos),
|
2021-03-12 04:53:25 +00:00
|
|
|
ControlAction::CancelInput(input) => self.cancel_input(data, input),
|
2020-12-01 00:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Read-Only Data sent from Character Behavior System to behavior fn's
|
|
|
|
pub struct JoinData<'a> {
|
|
|
|
pub entity: Entity,
|
|
|
|
pub uid: &'a Uid,
|
|
|
|
pub character: &'a CharacterState,
|
|
|
|
pub pos: &'a Pos,
|
|
|
|
pub vel: &'a Vel,
|
|
|
|
pub ori: &'a Ori,
|
2021-03-23 09:51:53 +00:00
|
|
|
pub mass: &'a Mass,
|
|
|
|
pub density: &'a Density,
|
2020-12-01 00:28:00 +00:00
|
|
|
pub dt: &'a DeltaTime,
|
|
|
|
pub controller: &'a Controller,
|
|
|
|
pub inputs: &'a ControllerInputs,
|
2021-03-22 17:37:15 +00:00
|
|
|
pub health: Option<&'a Health>,
|
2020-12-01 00:28:00 +00:00
|
|
|
pub energy: &'a Energy,
|
2021-01-08 19:12:09 +00:00
|
|
|
pub inventory: &'a Inventory,
|
2020-12-01 00:28:00 +00:00
|
|
|
pub body: &'a Body,
|
|
|
|
pub physics: &'a PhysicsState,
|
2021-02-02 18:02:40 +00:00
|
|
|
pub melee_attack: Option<&'a Melee>,
|
2020-12-01 00:28:00 +00:00
|
|
|
pub updater: &'a LazyUpdate,
|
2020-12-07 03:35:29 +00:00
|
|
|
pub stats: &'a Stats,
|
2021-04-14 15:35:34 +00:00
|
|
|
pub skill_set: &'a SkillSet,
|
2021-02-23 20:29:27 +00:00
|
|
|
pub msm: &'a MaterialStatManifest,
|
2021-02-27 23:01:07 +00:00
|
|
|
pub combo: &'a Combo,
|
2021-03-21 18:22:14 +00:00
|
|
|
pub alignment: Option<&'a comp::Alignment>,
|
2021-06-03 22:42:50 +00:00
|
|
|
pub terrain: &'a TerrainGrid,
|
2020-12-01 00:28:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type RestrictedMut<'a, C> = PairedStorage<
|
|
|
|
'a,
|
|
|
|
'a,
|
|
|
|
C,
|
2021-01-07 20:25:12 +00:00
|
|
|
&'a mut DerefFlaggedStorage<C, IdvStorage<C>>,
|
2020-12-01 00:28:00 +00:00
|
|
|
&'a hibitset::BitSet,
|
|
|
|
SequentialRestriction,
|
|
|
|
>;
|
|
|
|
|
2021-02-22 20:30:53 +00:00
|
|
|
pub struct JoinStruct<'a> {
|
|
|
|
pub entity: Entity,
|
|
|
|
pub uid: &'a Uid,
|
|
|
|
pub char_state: RestrictedMut<'a, CharacterState>,
|
|
|
|
pub pos: &'a mut Pos,
|
|
|
|
pub vel: &'a mut Vel,
|
|
|
|
pub ori: &'a mut Ori,
|
2021-03-23 09:51:53 +00:00
|
|
|
pub mass: &'a Mass,
|
|
|
|
pub density: &'a mut Density,
|
2021-02-22 20:30:53 +00:00
|
|
|
pub energy: RestrictedMut<'a, Energy>,
|
|
|
|
pub inventory: RestrictedMut<'a, Inventory>,
|
|
|
|
pub controller: &'a mut Controller,
|
2021-03-22 17:37:15 +00:00
|
|
|
pub health: Option<&'a Health>,
|
2021-02-22 20:30:53 +00:00
|
|
|
pub body: &'a Body,
|
|
|
|
pub physics: &'a PhysicsState,
|
|
|
|
pub melee_attack: Option<&'a Melee>,
|
|
|
|
pub beam: Option<&'a Beam>,
|
|
|
|
pub stat: &'a Stats,
|
2021-04-14 15:35:34 +00:00
|
|
|
pub skill_set: &'a SkillSet,
|
2021-02-27 23:01:07 +00:00
|
|
|
pub combo: &'a Combo,
|
2021-03-21 18:22:14 +00:00
|
|
|
pub alignment: Option<&'a comp::Alignment>,
|
2021-06-03 22:42:50 +00:00
|
|
|
pub terrain: &'a TerrainGrid,
|
2021-02-22 20:30:53 +00:00
|
|
|
}
|
2020-12-01 00:28:00 +00:00
|
|
|
|
|
|
|
impl<'a> JoinData<'a> {
|
2021-02-23 20:29:27 +00:00
|
|
|
pub fn new(
|
|
|
|
j: &'a JoinStruct<'a>,
|
|
|
|
updater: &'a LazyUpdate,
|
|
|
|
dt: &'a DeltaTime,
|
|
|
|
msm: &'a MaterialStatManifest,
|
|
|
|
) -> Self {
|
2020-12-01 00:28:00 +00:00
|
|
|
Self {
|
2021-02-22 20:30:53 +00:00
|
|
|
entity: j.entity,
|
|
|
|
uid: j.uid,
|
|
|
|
character: j.char_state.get_unchecked(),
|
|
|
|
pos: j.pos,
|
|
|
|
vel: j.vel,
|
|
|
|
ori: j.ori,
|
2021-03-23 09:51:53 +00:00
|
|
|
mass: j.mass,
|
|
|
|
density: j.density,
|
2021-02-22 20:30:53 +00:00
|
|
|
energy: j.energy.get_unchecked(),
|
|
|
|
inventory: j.inventory.get_unchecked(),
|
|
|
|
controller: j.controller,
|
|
|
|
inputs: &j.controller.inputs,
|
|
|
|
health: j.health,
|
|
|
|
body: j.body,
|
|
|
|
physics: j.physics,
|
|
|
|
melee_attack: j.melee_attack,
|
|
|
|
stats: j.stat,
|
2021-04-14 15:35:34 +00:00
|
|
|
skill_set: j.skill_set,
|
2020-12-01 00:28:00 +00:00
|
|
|
updater,
|
|
|
|
dt,
|
2021-02-23 20:29:27 +00:00
|
|
|
msm,
|
2021-02-27 23:01:07 +00:00
|
|
|
combo: j.combo,
|
2021-03-21 18:22:14 +00:00
|
|
|
alignment: j.alignment,
|
2021-06-03 22:42:50 +00:00
|
|
|
terrain: j.terrain,
|
2020-12-01 00:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|