Add debug mode item giving speed boost in look_dir on click

This commit is contained in:
timokoesters 2019-08-28 22:47:52 +02:00
parent af780acc84
commit e4ca33de5b
No known key found for this signature in database
GPG Key ID: CD80BE9AAEE78097
15 changed files with 130 additions and 48 deletions

Binary file not shown.

View File

@ -181,6 +181,11 @@ impl Client {
// Can't fail // Can't fail
} }
pub fn activate_inventory_slot(&mut self, x: usize) {
self.postbox
.send_message(ClientMsg::ActivateInventorySlot(x))
}
pub fn swap_inventory_slots(&mut self, a: usize, b: usize) { pub fn swap_inventory_slots(&mut self, a: usize, b: usize) {
self.postbox self.postbox
.send_message(ClientMsg::SwapInventorySlots(a, b)) .send_message(ClientMsg::SwapInventorySlots(a, b))

View File

@ -7,8 +7,8 @@ pub struct Controller {
pub move_dir: Vec2<f32>, pub move_dir: Vec2<f32>,
pub look_dir: Vec3<f32>, pub look_dir: Vec3<f32>,
pub jump: bool, pub jump: bool,
pub attack: bool, pub main: bool,
pub block: bool, pub alt: bool,
pub roll: bool, pub roll: bool,
pub glide: bool, pub glide: bool,
pub respawn: bool, pub respawn: bool,

View File

@ -76,6 +76,11 @@ pub enum ConsumptionEffect {
Xp(i32), Xp(i32),
} }
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Debug {
Teleport,
}
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Item { pub enum Item {
Tool { Tool {
@ -91,6 +96,7 @@ pub enum Item {
effect: ConsumptionEffect, effect: ConsumptionEffect,
}, },
Ingredient, Ingredient,
Debug(Debug),
} }
impl Item { impl Item {
@ -100,6 +106,7 @@ impl Item {
Item::Armor { kind, .. } => kind.name(), Item::Armor { kind, .. } => kind.name(),
Item::Consumable { .. } => "<consumable>", Item::Consumable { .. } => "<consumable>",
Item::Ingredient => "<ingredient>", Item::Ingredient => "<ingredient>",
Item::Debug(_) => "Debugging item",
} }
} }
@ -109,6 +116,7 @@ impl Item {
Item::Armor { .. } => "armour", Item::Armor { .. } => "armour",
Item::Consumable { .. } => "consumable", Item::Consumable { .. } => "consumable",
Item::Ingredient => "ingredient", Item::Ingredient => "ingredient",
Item::Debug(_) => "debug",
} }
} }

View File

@ -2,7 +2,7 @@
pub mod item; pub mod item;
// Reexports // Reexports
pub use self::item::{Item, Tool}; pub use self::item::{Debug, Item, Tool};
use specs::{Component, HashMapStorage, NullStorage}; use specs::{Component, HashMapStorage, NullStorage};
use specs_idvs::IDVStorage; use specs_idvs::IDVStorage;
@ -21,13 +21,25 @@ impl Inventory {
self.slots.len() self.slots.len()
} }
pub fn insert(&mut self, item: Item) -> Option<Item> { pub fn push(&mut self, item: Item) -> Option<Item> {
match self.slots.iter_mut().find(|slot| slot.is_none()) { match self.slots.iter_mut().find(|slot| slot.is_none()) {
Some(slot) => { Some(slot) => {
let old = slot.take();
*slot = Some(item); *slot = Some(item);
None old
} }
None => Some(item), None => None,
}
}
pub fn insert(&mut self, cell: usize, item: Option<Item>) -> Option<Item> {
match self.slots.get_mut(cell) {
Some(slot) => {
let old = slot.take();
*slot = item;
old
}
None => None,
} }
} }
@ -60,28 +72,25 @@ impl Default for Inventory {
slots: vec![None; 24], slots: vec![None; 24],
}; };
inventory.insert(Item::Tool { inventory.push(Item::Debug(Debug::Teleport));
inventory.push(Item::Tool {
kind: Tool::Daggers, kind: Tool::Daggers,
power: 10, power: 10,
}); });
inventory.insert(Item::Tool { inventory.push(Item::Tool {
kind: Tool::Sword, kind: Tool::Sword,
power: 10, power: 10,
}); });
inventory.insert(Item::Tool { inventory.push(Item::Tool {
kind: Tool::Axe, kind: Tool::Axe,
power: 10, power: 10,
}); });
inventory.insert(Item::Tool { inventory.push(Item::Tool {
kind: Tool::Hammer, kind: Tool::Hammer,
power: 10, power: 10,
}); });
inventory.insert(Item::Tool {
kind: Tool::Bow,
power: 10,
});
for _ in 0..10 { for _ in 0..10 {
inventory.insert(Item::default()); inventory.push(Item::default());
} }
inventory inventory

View File

@ -6,6 +6,7 @@ use vek::*;
pub enum LocalEvent { pub enum LocalEvent {
Jump(EcsEntity), Jump(EcsEntity),
Boost { entity: EcsEntity, vel: Vec3<f32> },
LandOnGround { entity: EcsEntity, vel: Vec3<f32> }, LandOnGround { entity: EcsEntity, vel: Vec3<f32> },
} }

View File

@ -30,6 +30,7 @@ pub enum ClientMsg {
vel: comp::Vel, vel: comp::Vel,
ori: comp::Ori, ori: comp::Ori,
}, },
ActivateInventorySlot(usize),
SwapInventorySlots(usize, usize), SwapInventorySlots(usize, usize),
DropInventorySlot(usize), DropInventorySlot(usize),
PickUp(u64), PickUp(u64),

View File

@ -334,6 +334,15 @@ impl State {
vel.0.z = HUMANOID_JUMP_ACCEL; vel.0.z = HUMANOID_JUMP_ACCEL;
} }
} }
LocalEvent::Boost {
entity,
vel: extra_vel,
} => {
if let Some(vel) = velocities.get_mut(entity) {
vel.0 += extra_vel;
}
}
} }
} }
} }

View File

@ -87,9 +87,9 @@ impl<'a> System<'a> for Sys {
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.5; Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.5;
if rand::random::<f32>() < 0.05 { if rand::random::<f32>() < 0.05 {
controller.attack = true; controller.main = true;
} else { } else {
controller.attack = false; controller.main = false;
} }
} else if dist < SIGHT_DIST { } else if dist < SIGHT_DIST {
controller.move_dir = controller.move_dir =

View File

@ -4,8 +4,8 @@ use super::{
}; };
use crate::{ use crate::{
comp::{ comp::{
ActionState::*, Body, CharacterState, Controller, MovementState::*, PhysicsState, Stats, item, ActionState::*, Body, CharacterState, Controller, Item, MovementState::*,
Vel, PhysicsState, Stats, Vel,
}, },
event::{EventBus, LocalEvent, ServerEvent}, event::{EventBus, LocalEvent, ServerEvent},
}; };
@ -96,7 +96,7 @@ impl<'a> System<'a> for Sys {
} }
// Wield // Wield
if controller.attack if controller.main
&& character.action == Idle && character.action == Idle
&& (character.movement == Stand || character.movement == Run) && (character.movement == Stand || character.movement == Run)
{ {
@ -105,33 +105,46 @@ impl<'a> System<'a> for Sys {
}; };
} }
// Attack match stats.equipment.main {
if controller.attack Some(Item::Tool { .. }) => {
&& (character.movement == Stand // Attack
|| character.movement == Run if controller.main
|| character.movement == Jump) && (character.movement == Stand
{ || character.movement == Run
// TODO: Check if wield ability exists || character.movement == Jump)
if let Wield { time_left } = character.action { {
if time_left == Duration::default() { // TODO: Check if wield ability exists
character.action = Attack { if let Wield { time_left } = character.action {
time_left: ATTACK_DURATION, if time_left == Duration::default() {
applied: false, character.action = Attack {
time_left: ATTACK_DURATION,
applied: false,
};
}
}
}
// Block
if controller.alt
&& (character.movement == Stand || character.movement == Run)
&& (character.action == Idle || character.action.is_wield())
{
character.action = Block {
time_left: Duration::from_secs(5),
}; };
} else if !controller.alt && character.action.is_block() {
character.action = Idle;
} }
} }
} Some(Item::Debug(item::Debug::Teleport)) => {
if controller.main {
// Block local_emitter.emit(LocalEvent::Boost {
if controller.block entity,
&& (character.movement == Stand || character.movement == Run) vel: controller.look_dir * 10.0,
&& (character.action == Idle || character.action.is_wield()) });
{ }
character.action = Block { }
time_left: Duration::from_secs(5), _ => {}
};
} else if !controller.block && character.action.is_block() {
character.action = Idle;
} }
// Roll // Roll

View File

@ -712,6 +712,37 @@ impl Server {
} }
_ => {} _ => {}
}, },
ClientMsg::ActivateInventorySlot(x) => {
let item_opt = state
.ecs()
.write_storage::<comp::Inventory>()
.get_mut(entity)
.and_then(|inv| inv.remove(x));
if let Some(item) = item_opt {
match item {
comp::Item::Tool { .. } | comp::Item::Debug(_) => {
if let Some(stats) = state
.ecs()
.write_storage::<comp::Stats>()
.get_mut(entity)
{
state
.ecs()
.write_storage::<comp::Inventory>()
.get_mut(entity)
.map(|inv| {
inv.insert(x, stats.equipment.main.take())
});
stats.equipment.main = Some(item);
}
}
_ => {}
}
state.write_component(entity, comp::InventoryUpdate);
}
}
ClientMsg::SwapInventorySlots(a, b) => { ClientMsg::SwapInventorySlots(a, b) => {
state state
.ecs() .ecs()
@ -757,7 +788,7 @@ impl Server {
}), }),
ecs.write_storage::<comp::Inventory>().get_mut(entity), ecs.write_storage::<comp::Inventory>().get_mut(entity),
) { ) {
if inv.insert(item).is_none() { if inv.push(item).is_none() {
Some(item_entity) Some(item_entity)
} else { } else {
None None

View File

@ -153,7 +153,7 @@ impl<'a> Widget for Bag<'a> {
let selected_slot = match state.selected_slot { let selected_slot = match state.selected_slot {
Some(a) => { Some(a) => {
if a == i { if a == i {
event = Some(Event::HudEvent(HudEvent::DropInventorySlot(i))); event = Some(Event::HudEvent(HudEvent::ActivateInventorySlot(i)));
} else { } else {
event = Some(Event::HudEvent(HudEvent::SwapInventorySlots(a, i))); event = Some(Event::HudEvent(HudEvent::SwapInventorySlots(a, i)));
} }

View File

@ -162,6 +162,7 @@ pub enum Event {
ToggleShortcutNumbers(ShortcutNumbers), ToggleShortcutNumbers(ShortcutNumbers),
UiScale(ScaleChange), UiScale(ScaleChange),
CharacterSelection, CharacterSelection,
ActivateInventorySlot(usize),
SwapInventorySlots(usize, usize), SwapInventorySlots(usize, usize),
DropInventorySlot(usize), DropInventorySlot(usize),
Logout, Logout,

View File

@ -321,6 +321,7 @@ impl FigureModelCache {
Tool::Bow => ("weapon.hammer.rusty_2h", Vec3::new(-2.5, -5.5, -4.0)), Tool::Bow => ("weapon.hammer.rusty_2h", Vec3::new(-2.5, -5.5, -4.0)),
Tool::Staff => ("weapon.axe.rusty_2h", Vec3::new(-2.5, -6.5, -2.0)), Tool::Staff => ("weapon.axe.rusty_2h", Vec3::new(-2.5, -6.5, -2.0)),
}, },
Item::Debug(_) => ("weapon.debug_wand", Vec3::new(-2.5, -6.5, -2.0)),
_ => ("figure.empty", Vec3::default()), _ => ("figure.empty", Vec3::default()),
}; };
Self::load_mesh(name, offset) Self::load_mesh(name, offset)

View File

@ -152,7 +152,7 @@ impl PlayState for SessionState {
client.place_block(pos, self.selected_block); client.place_block(pos, self.selected_block);
} }
} else { } else {
self.controller.attack = state self.controller.main = state
} }
} }
@ -176,7 +176,7 @@ impl PlayState for SessionState {
client.remove_block(pos); client.remove_block(pos);
} }
} else { } else {
self.controller.block = state; self.controller.alt = state;
} }
} }
Event::InputUpdate(GameInput::Roll, state) => { Event::InputUpdate(GameInput::Roll, state) => {
@ -376,6 +376,9 @@ impl PlayState for SessionState {
global_state.settings.graphics.max_fps = fps; global_state.settings.graphics.max_fps = fps;
global_state.settings.save_to_file_warn(); global_state.settings.save_to_file_warn();
} }
HudEvent::ActivateInventorySlot(x) => {
self.client.borrow_mut().activate_inventory_slot(x)
}
HudEvent::SwapInventorySlots(a, b) => { HudEvent::SwapInventorySlots(a, b) => {
self.client.borrow_mut().swap_inventory_slots(a, b) self.client.borrow_mut().swap_inventory_slots(a, b)
} }