fix: make climbing cost stamina

This commit is contained in:
timokoesters 2020-02-24 19:17:16 +01:00
parent 2fa902270e
commit 31f3aae75c
15 changed files with 81 additions and 45 deletions

View File

@ -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...

View File

@ -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.

View File

@ -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<LocalEvent>,
pub server_events: VecDeque<ServerEvent>,
}

View File

@ -15,6 +15,7 @@ pub enum EnergySource {
LevelUp,
Regen,
Revive,
Climb,
Unknown,
}

View File

@ -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(),

View File

@ -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(),

View File

@ -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() {

View File

@ -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(),

View File

@ -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(),
};

View File

@ -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(),
};

View File

@ -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(),
};

View File

@ -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(),
};

View File

@ -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(),
};

View File

@ -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);
}

View File

@ -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