2020-12-01 00:28:00 +00:00
|
|
|
use crate::{
|
|
|
|
comp::{
|
2021-01-26 00:31:06 +00:00
|
|
|
Beam, Body, CharacterState, ControlAction, Controller, ControllerInputs, Energy, Health,
|
2021-02-07 16:57:41 +00:00
|
|
|
Inventory, LoadoutManip, Melee, Ori, PhysicsState, Pos, StateUpdate, Stats, Vel,
|
2020-12-01 00:28:00 +00:00
|
|
|
},
|
|
|
|
resources::DeltaTime,
|
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;
|
|
|
|
|
|
|
|
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) }
|
|
|
|
fn manipulate_loadout(&self, data: &JoinData, _loadout_manip: LoadoutManip) -> 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) }
|
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),
|
|
|
|
ControlAction::LoadoutManip(loadout_manip) => {
|
|
|
|
self.manipulate_loadout(data, loadout_manip)
|
|
|
|
},
|
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),
|
2020-12-01 00:28:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// fn init(data: &JoinData) -> CharacterState;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// 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,
|
|
|
|
pub dt: &'a DeltaTime,
|
|
|
|
pub controller: &'a Controller,
|
|
|
|
pub inputs: &'a ControllerInputs,
|
|
|
|
pub health: &'a Health,
|
|
|
|
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,
|
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,
|
|
|
|
pub energy: RestrictedMut<'a, Energy>,
|
|
|
|
pub inventory: RestrictedMut<'a, Inventory>,
|
|
|
|
pub controller: &'a mut Controller,
|
|
|
|
pub health: &'a Health,
|
|
|
|
pub body: &'a Body,
|
|
|
|
pub physics: &'a PhysicsState,
|
|
|
|
pub melee_attack: Option<&'a Melee>,
|
|
|
|
pub beam: Option<&'a Beam>,
|
|
|
|
pub stat: &'a Stats,
|
|
|
|
}
|
2020-12-01 00:28:00 +00:00
|
|
|
|
|
|
|
impl<'a> JoinData<'a> {
|
2021-02-22 20:30:53 +00:00
|
|
|
pub fn new(j: &'a JoinStruct<'a>, updater: &'a LazyUpdate, dt: &'a DeltaTime) -> 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,
|
|
|
|
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,
|
2020-12-01 00:28:00 +00:00
|
|
|
updater,
|
|
|
|
dt,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|