From 31f3aae75c18efd61dfc84eb626ef6e682e0c471 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 24 Feb 2020 19:17:16 +0100 Subject: [PATCH] fix: make climbing cost stamina --- assets/common/items/debug/boost.ron | 12 ++++++++---- assets/common/items/debug/possess.ron | 12 ++++++++---- common/src/comp/character_state.rs | 8 ++++++-- common/src/comp/energy.rs | 1 + common/src/states/basic_attack.rs | 1 + common/src/states/basic_block.rs | 1 + common/src/states/climb.rs | 23 +++++++++++++++-------- common/src/states/glide.rs | 11 ++++++----- common/src/states/idle.rs | 5 ++--- common/src/states/roll.rs | 10 ++++++---- common/src/states/sit.rs | 11 ++++++----- common/src/states/wielded.rs | 1 + common/src/states/wielding.rs | 10 ++++++---- common/src/sys/character_state.rs | 18 +++++++++++++----- common/src/sys/phys.rs | 2 +- 15 files changed, 81 insertions(+), 45 deletions(-) diff --git a/assets/common/items/debug/boost.ron b/assets/common/items/debug/boost.ron index c32d38c69a..6ff45a1d78 100644 --- a/assets/common/items/debug/boost.ron +++ b/assets/common/items/debug/boost.ron @@ -2,10 +2,14 @@ Item( name: "Weightless Rod", description: "The sky is the limit.", kind: Tool( - kind: Debug(Boost), - equip_time_millis: 0, - attack_buildup_millis: 0, - attack_recover_millis: 0, + ToolData ( + kind: Debug(Boost), + equip_time_millis: 0, + attack_buildup_millis: 0, + attack_recover_millis: 0, + range: 0, + base_damage: 0, + ) ), ) // And the ground is pretty hard at maximum velocity... diff --git a/assets/common/items/debug/possess.ron b/assets/common/items/debug/possess.ron index e568ece69b..4d223e4506 100644 --- a/assets/common/items/debug/possess.ron +++ b/assets/common/items/debug/possess.ron @@ -2,10 +2,14 @@ Item( name: "Rod of Possession", description: "It's fixed on my branch.", kind: Tool( - kind: Debug(Possess), - equip_time_millis: 0, - attack_buildup_millis: 0, - attack_recover_millis: 0, + ToolData ( + kind: Debug(Possess), + equip_time_millis: 0, + attack_buildup_millis: 0, + attack_recover_millis: 0, + range: 3, + base_damage: 10, + ) ), ) // ... as zesterer always uses to tell us. diff --git a/common/src/comp/character_state.rs b/common/src/comp/character_state.rs index 6cd5178a20..8f6c95c028 100644 --- a/common/src/comp/character_state.rs +++ b/common/src/comp/character_state.rs @@ -1,5 +1,7 @@ use crate::{ - comp::{AbilityPool, Body, ControllerInputs, Ori, PhysicsState, Pos, Stats, ToolData, Vel}, + comp::{ + AbilityPool, Body, ControllerInputs, Energy, Ori, PhysicsState, Pos, Stats, ToolData, Vel, + }, event::{LocalEvent, ServerEvent}, state::DeltaTime, states::*, @@ -7,7 +9,7 @@ use crate::{ }; use serde::{Deserialize, Serialize}; use specs::{Component, Entity, FlaggedStorage, HashMapStorage, LazyUpdate, VecStorage}; -use std::{collections::VecDeque, time::Duration}; +use std::collections::VecDeque; pub struct EcsStateData<'a> { pub entity: &'a Entity, @@ -19,6 +21,7 @@ pub struct EcsStateData<'a> { pub dt: &'a DeltaTime, pub inputs: &'a ControllerInputs, pub stats: &'a Stats, + pub energy: &'a Energy, pub body: &'a Body, pub physics: &'a PhysicsState, pub ability_pool: &'a AbilityPool, @@ -30,6 +33,7 @@ pub struct StateUpdate { pub pos: Pos, pub vel: Vel, pub ori: Ori, + pub energy: Energy, pub local_events: VecDeque, pub server_events: VecDeque, } diff --git a/common/src/comp/energy.rs b/common/src/comp/energy.rs index 8cf2d9224e..e53fbe5a48 100644 --- a/common/src/comp/energy.rs +++ b/common/src/comp/energy.rs @@ -15,6 +15,7 @@ pub enum EnergySource { LevelUp, Regen, Revive, + Climb, Unknown, } diff --git a/common/src/states/basic_attack.rs b/common/src/states/basic_attack.rs index 91eaabc790..d633d988d8 100644 --- a/common/src/states/basic_attack.rs +++ b/common/src/states/basic_attack.rs @@ -31,6 +31,7 @@ impl StateHandler for State { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, character: *ecs_data.character, local_events: VecDeque::new(), server_events: VecDeque::new(), diff --git a/common/src/states/basic_block.rs b/common/src/states/basic_block.rs index e3ee63f18f..fb91ce76a0 100644 --- a/common/src/states/basic_block.rs +++ b/common/src/states/basic_block.rs @@ -20,6 +20,7 @@ impl StateHandler for State { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, character: *ecs_data.character, local_events: VecDeque::new(), server_events: VecDeque::new(), diff --git a/common/src/states/climb.rs b/common/src/states/climb.rs index a105a30323..8c73c9b31b 100644 --- a/common/src/states/climb.rs +++ b/common/src/states/climb.rs @@ -1,9 +1,13 @@ -use crate::comp::{CharacterState, EcsStateData, StateUpdate}; -use crate::states::StateHandler; -use crate::sys::phys::GRAVITY; +use crate::{ + comp::{CharacterState, EcsStateData, EnergySource, StateUpdate}, + states::StateHandler, + sys::phys::GRAVITY, +}; use std::collections::VecDeque; -use vek::vec::{Vec2, Vec3}; -use vek::Lerp; +use vek::{ + vec::{Vec2, Vec3}, + Lerp, +}; const HUMANOID_CLIMB_ACCEL: f32 = 5.0; const CLIMB_SPEED: f32 = 5.0; @@ -12,9 +16,7 @@ const CLIMB_SPEED: f32 = 5.0; pub struct State; impl StateHandler for State { - fn new(_ecs_data: &EcsStateData) -> Self { - Self {} - } + fn new(_ecs_data: &EcsStateData) -> Self { Self {} } fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate { let mut update = StateUpdate { @@ -22,10 +24,15 @@ impl StateHandler for State { vel: *ecs_data.vel, ori: *ecs_data.ori, character: *ecs_data.character, + energy: *ecs_data.energy, local_events: VecDeque::new(), server_events: VecDeque::new(), }; + if let Err(_) = update.energy.try_change_by(-5, EnergySource::Climb) { + update.character = CharacterState::Idle(None); + } + // If no wall is in front of character ... if ecs_data.physics.on_wall.is_none() || ecs_data.physics.on_ground { if ecs_data.inputs.jump.is_pressed() { diff --git a/common/src/states/glide.rs b/common/src/states/glide.rs index 87048bb068..ba0d4f8bea 100644 --- a/common/src/states/glide.rs +++ b/common/src/states/glide.rs @@ -1,5 +1,7 @@ -use crate::comp::{CharacterState, EcsStateData, StateUpdate}; -use crate::states::StateHandler; +use crate::{ + comp::{CharacterState, EcsStateData, StateUpdate}, + states::StateHandler, +}; use std::collections::VecDeque; use vek::{Vec2, Vec3}; @@ -12,15 +14,14 @@ const GLIDE_SPEED: f32 = 45.0; pub struct State; impl StateHandler for State { - fn new(_ecs_data: &EcsStateData) -> Self { - Self {} - } + fn new(_ecs_data: &EcsStateData) -> Self { Self {} } fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate { let mut update = StateUpdate { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, character: *ecs_data.character, local_events: VecDeque::new(), server_events: VecDeque::new(), diff --git a/common/src/states/idle.rs b/common/src/states/idle.rs index f9934be701..b07456e891 100644 --- a/common/src/states/idle.rs +++ b/common/src/states/idle.rs @@ -7,9 +7,7 @@ use crate::states::StateHandler; pub struct State; impl StateHandler for State { - fn new(_ecs_data: &EcsStateData) -> Self { - Self {} - } + fn new(_ecs_data: &EcsStateData) -> Self { Self {} } fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate { let mut update = StateUpdate { @@ -17,6 +15,7 @@ impl StateHandler for State { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, local_events: VecDeque::new(), server_events: VecDeque::new(), }; diff --git a/common/src/states/roll.rs b/common/src/states/roll.rs index f1596f8189..14223b0e10 100644 --- a/common/src/states/roll.rs +++ b/common/src/states/roll.rs @@ -1,7 +1,8 @@ -use crate::comp::{CharacterState, EcsStateData, ItemKind::Tool, StateUpdate, ToolData}; -use crate::states::StateHandler; -use std::collections::VecDeque; -use std::time::Duration; +use crate::{ + comp::{CharacterState, EcsStateData, ItemKind::Tool, StateUpdate, ToolData}, + states::StateHandler, +}; +use std::{collections::VecDeque, time::Duration}; use vek::Vec3; const ROLL_SPEED: f32 = 17.0; @@ -31,6 +32,7 @@ impl StateHandler for State { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, local_events: VecDeque::new(), server_events: VecDeque::new(), }; diff --git a/common/src/states/sit.rs b/common/src/states/sit.rs index 34e3f44150..1da5fb6df3 100644 --- a/common/src/states/sit.rs +++ b/common/src/states/sit.rs @@ -1,15 +1,15 @@ use super::utils::*; -use crate::comp::{CharacterState, EcsStateData, StateUpdate}; -use crate::states::StateHandler; +use crate::{ + comp::{CharacterState, EcsStateData, StateUpdate}, + states::StateHandler, +}; use std::collections::VecDeque; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub struct State; impl StateHandler for State { - fn new(_ecs_data: &EcsStateData) -> Self { - Self {} - } + fn new(_ecs_data: &EcsStateData) -> Self { Self {} } fn handle(&self, ecs_data: &EcsStateData) -> StateUpdate { let mut update = StateUpdate { @@ -17,6 +17,7 @@ impl StateHandler for State { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, local_events: VecDeque::new(), server_events: VecDeque::new(), }; diff --git a/common/src/states/wielded.rs b/common/src/states/wielded.rs index 73d09ca2ec..545a38dca6 100644 --- a/common/src/states/wielded.rs +++ b/common/src/states/wielded.rs @@ -31,6 +31,7 @@ impl StateHandler for State { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, local_events: VecDeque::new(), server_events: VecDeque::new(), }; diff --git a/common/src/states/wielding.rs b/common/src/states/wielding.rs index d2e3bd289e..e3271ee958 100644 --- a/common/src/states/wielding.rs +++ b/common/src/states/wielding.rs @@ -1,8 +1,9 @@ use super::utils::*; -use crate::comp::{CharacterState, EcsStateData, ItemKind::Tool, StateUpdate, ToolData}; -use crate::states::StateHandler; -use std::collections::VecDeque; -use std::time::Duration; +use crate::{ + comp::{CharacterState, EcsStateData, ItemKind::Tool, StateUpdate, ToolData}, + states::StateHandler, +}; +use std::{collections::VecDeque, time::Duration}; #[derive(Clone, Copy, Default, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] pub struct State { @@ -31,6 +32,7 @@ impl StateHandler for State { pos: *ecs_data.pos, vel: *ecs_data.vel, ori: *ecs_data.ori, + energy: *ecs_data.energy, local_events: VecDeque::new(), server_events: VecDeque::new(), }; diff --git a/common/src/sys/character_state.rs b/common/src/sys/character_state.rs index 4d44334320..a87a7b92ab 100644 --- a/common/src/sys/character_state.rs +++ b/common/src/sys/character_state.rs @@ -1,7 +1,7 @@ use crate::{ comp::{ - AbilityPool, Body, CharacterState, Controller, EcsStateData, Mounting, Ori, PhysicsState, - Pos, Stats, Vel, + AbilityPool, Body, CharacterState, Controller, EcsStateData, Energy, Mounting, Ori, + PhysicsState, Pos, Stats, Vel, }, event::{EventBus, LocalEvent, ServerEvent}, state::DeltaTime, @@ -11,10 +11,11 @@ use crate::{ use specs::{Entities, Join, LazyUpdate, Read, ReadStorage, System, WriteStorage}; /// ## Character State System -/// #### Calls updates to `CharacterState`s. Acts on tuples of ( `CharacterState`, `Pos`, `Vel`, and `Ori` ). +/// #### Calls updates to `CharacterState`s. Acts on tuples of ( +/// `CharacterState`, `Pos`, `Vel`, and `Ori` ). /// -/// _System forms `EcsStateData` tuples and passes those to `ActionState` `update()` fn, -/// then does the same for `MoveState` `update`_ +/// _System forms `EcsStateData` tuples and passes those to `ActionState` +/// `update()` fn, then does the same for `MoveState` `update`_ pub struct Sys; impl<'a> System<'a> for Sys { @@ -29,6 +30,7 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Pos>, WriteStorage<'a, Vel>, WriteStorage<'a, Ori>, + WriteStorage<'a, Energy>, ReadStorage<'a, Controller>, ReadStorage<'a, Stats>, ReadStorage<'a, Body>, @@ -37,6 +39,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Uid>, ReadStorage<'a, Mounting>, ); + fn run( &mut self, ( @@ -50,6 +53,7 @@ impl<'a> System<'a> for Sys { mut positions, mut velocities, mut orientations, + mut energies, controllers, stats, bodies, @@ -66,6 +70,7 @@ impl<'a> System<'a> for Sys { pos, vel, ori, + energy, controller, stats, body, @@ -78,6 +83,7 @@ impl<'a> System<'a> for Sys { &mut positions, &mut velocities, &mut orientations, + &mut energies, &controllers, &stats, &bodies, @@ -113,6 +119,7 @@ impl<'a> System<'a> for Sys { pos, vel, ori, + energy, dt: &dt, inputs, stats, @@ -126,6 +133,7 @@ impl<'a> System<'a> for Sys { *pos = state_update.pos; *vel = state_update.vel; *ori = state_update.ori; + *energy = state_update.energy; local_bus.emitter().append(&mut state_update.local_events); server_bus.emitter().append(&mut state_update.server_events); } diff --git a/common/src/sys/phys.rs b/common/src/sys/phys.rs index d57f0af012..8df26f2390 100644 --- a/common/src/sys/phys.rs +++ b/common/src/sys/phys.rs @@ -9,7 +9,7 @@ use crate::{ use specs::{Entities, Join, Read, ReadExpect, ReadStorage, System, WriteStorage}; use vek::*; -pub const GRAVITY: f32 = 9.81 * 7.0; +pub const GRAVITY: f32 = 9.81 * 10.0; const BOUYANCY: f32 = 0.0; // Friction values used for linear damping. They are unitless quantities. The // value of these quantities must be between zero and one. They represent the