mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add debug mode item giving speed boost in look_dir on click
This commit is contained in:
parent
155605841b
commit
6e1c78e5d5
BIN
assets/voxygen/voxel/weapon/debug_wand.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/weapon/debug_wand.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -181,6 +181,11 @@ impl Client {
|
||||
// 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) {
|
||||
self.postbox
|
||||
.send_message(ClientMsg::SwapInventorySlots(a, b))
|
||||
|
@ -7,8 +7,8 @@ pub struct Controller {
|
||||
pub move_dir: Vec2<f32>,
|
||||
pub look_dir: Vec3<f32>,
|
||||
pub jump: bool,
|
||||
pub attack: bool,
|
||||
pub block: bool,
|
||||
pub main: bool,
|
||||
pub alt: bool,
|
||||
pub roll: bool,
|
||||
pub glide: bool,
|
||||
pub respawn: bool,
|
||||
|
@ -76,6 +76,11 @@ pub enum ConsumptionEffect {
|
||||
Xp(i32),
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Debug {
|
||||
Teleport,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||
pub enum Item {
|
||||
Tool {
|
||||
@ -91,6 +96,7 @@ pub enum Item {
|
||||
effect: ConsumptionEffect,
|
||||
},
|
||||
Ingredient,
|
||||
Debug(Debug),
|
||||
}
|
||||
|
||||
impl Item {
|
||||
@ -100,6 +106,7 @@ impl Item {
|
||||
Item::Armor { kind, .. } => kind.name(),
|
||||
Item::Consumable { .. } => "<consumable>",
|
||||
Item::Ingredient => "<ingredient>",
|
||||
Item::Debug(_) => "Debugging item",
|
||||
}
|
||||
}
|
||||
|
||||
@ -109,6 +116,7 @@ impl Item {
|
||||
Item::Armor { .. } => "armour",
|
||||
Item::Consumable { .. } => "consumable",
|
||||
Item::Ingredient => "ingredient",
|
||||
Item::Debug(_) => "debug",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
pub mod item;
|
||||
|
||||
// Reexports
|
||||
pub use self::item::{Item, Tool};
|
||||
pub use self::item::{Debug, Item, Tool};
|
||||
|
||||
use specs::{Component, HashMapStorage, NullStorage};
|
||||
use specs_idvs::IDVStorage;
|
||||
@ -21,13 +21,25 @@ impl Inventory {
|
||||
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()) {
|
||||
Some(slot) => {
|
||||
let old = slot.take();
|
||||
*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],
|
||||
};
|
||||
|
||||
inventory.insert(Item::Tool {
|
||||
inventory.push(Item::Debug(Debug::Teleport));
|
||||
inventory.push(Item::Tool {
|
||||
kind: Tool::Daggers,
|
||||
power: 10,
|
||||
});
|
||||
inventory.insert(Item::Tool {
|
||||
inventory.push(Item::Tool {
|
||||
kind: Tool::Sword,
|
||||
power: 10,
|
||||
});
|
||||
inventory.insert(Item::Tool {
|
||||
inventory.push(Item::Tool {
|
||||
kind: Tool::Axe,
|
||||
power: 10,
|
||||
});
|
||||
inventory.insert(Item::Tool {
|
||||
inventory.push(Item::Tool {
|
||||
kind: Tool::Hammer,
|
||||
power: 10,
|
||||
});
|
||||
inventory.insert(Item::Tool {
|
||||
kind: Tool::Bow,
|
||||
power: 10,
|
||||
});
|
||||
for _ in 0..10 {
|
||||
inventory.insert(Item::default());
|
||||
inventory.push(Item::default());
|
||||
}
|
||||
|
||||
inventory
|
||||
|
@ -6,6 +6,7 @@ use vek::*;
|
||||
|
||||
pub enum LocalEvent {
|
||||
Jump(EcsEntity),
|
||||
Boost { entity: EcsEntity, vel: Vec3<f32> },
|
||||
LandOnGround { entity: EcsEntity, vel: Vec3<f32> },
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,7 @@ pub enum ClientMsg {
|
||||
vel: comp::Vel,
|
||||
ori: comp::Ori,
|
||||
},
|
||||
ActivateInventorySlot(usize),
|
||||
SwapInventorySlots(usize, usize),
|
||||
DropInventorySlot(usize),
|
||||
PickUp(u64),
|
||||
|
@ -334,6 +334,15 @@ impl State {
|
||||
vel.0.z = HUMANOID_JUMP_ACCEL;
|
||||
}
|
||||
}
|
||||
|
||||
LocalEvent::Boost {
|
||||
entity,
|
||||
vel: extra_vel,
|
||||
} => {
|
||||
if let Some(vel) = velocities.get_mut(entity) {
|
||||
vel.0 += extra_vel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,9 +87,9 @@ impl<'a> System<'a> for Sys {
|
||||
Vec2::<f32>::from(target_pos.0 - pos.0).normalized() * 0.5;
|
||||
|
||||
if rand::random::<f32>() < 0.05 {
|
||||
controller.attack = true;
|
||||
controller.main = true;
|
||||
} else {
|
||||
controller.attack = false;
|
||||
controller.main = false;
|
||||
}
|
||||
} else if dist < SIGHT_DIST {
|
||||
controller.move_dir =
|
||||
|
@ -4,8 +4,8 @@ use super::{
|
||||
};
|
||||
use crate::{
|
||||
comp::{
|
||||
ActionState::*, Body, CharacterState, Controller, MovementState::*, PhysicsState, Stats,
|
||||
Vel,
|
||||
item, ActionState::*, Body, CharacterState, Controller, Item, MovementState::*,
|
||||
PhysicsState, Stats, Vel,
|
||||
},
|
||||
event::{EventBus, LocalEvent, ServerEvent},
|
||||
};
|
||||
@ -96,7 +96,7 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
|
||||
// Wield
|
||||
if controller.attack
|
||||
if controller.main
|
||||
&& character.action == Idle
|
||||
&& (character.movement == Stand || character.movement == Run)
|
||||
{
|
||||
@ -105,33 +105,46 @@ impl<'a> System<'a> for Sys {
|
||||
};
|
||||
}
|
||||
|
||||
// Attack
|
||||
if controller.attack
|
||||
&& (character.movement == Stand
|
||||
|| character.movement == Run
|
||||
|| character.movement == Jump)
|
||||
{
|
||||
// TODO: Check if wield ability exists
|
||||
if let Wield { time_left } = character.action {
|
||||
if time_left == Duration::default() {
|
||||
character.action = Attack {
|
||||
time_left: ATTACK_DURATION,
|
||||
applied: false,
|
||||
match stats.equipment.main {
|
||||
Some(Item::Tool { .. }) => {
|
||||
// Attack
|
||||
if controller.main
|
||||
&& (character.movement == Stand
|
||||
|| character.movement == Run
|
||||
|| character.movement == Jump)
|
||||
{
|
||||
// TODO: Check if wield ability exists
|
||||
if let Wield { time_left } = character.action {
|
||||
if time_left == Duration::default() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Block
|
||||
if controller.block
|
||||
&& (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.block && character.action.is_block() {
|
||||
character.action = Idle;
|
||||
Some(Item::Debug(item::Debug::Teleport)) => {
|
||||
if controller.main {
|
||||
local_emitter.emit(LocalEvent::Boost {
|
||||
entity,
|
||||
vel: controller.look_dir * 10.0,
|
||||
});
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
// Roll
|
||||
|
@ -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) => {
|
||||
state
|
||||
.ecs()
|
||||
@ -757,7 +788,7 @@ impl Server {
|
||||
}),
|
||||
ecs.write_storage::<comp::Inventory>().get_mut(entity),
|
||||
) {
|
||||
if inv.insert(item).is_none() {
|
||||
if inv.push(item).is_none() {
|
||||
Some(item_entity)
|
||||
} else {
|
||||
None
|
||||
|
@ -153,7 +153,7 @@ impl<'a> Widget for Bag<'a> {
|
||||
let selected_slot = match state.selected_slot {
|
||||
Some(a) => {
|
||||
if a == i {
|
||||
event = Some(Event::HudEvent(HudEvent::DropInventorySlot(i)));
|
||||
event = Some(Event::HudEvent(HudEvent::ActivateInventorySlot(i)));
|
||||
} else {
|
||||
event = Some(Event::HudEvent(HudEvent::SwapInventorySlots(a, i)));
|
||||
}
|
||||
|
@ -162,6 +162,7 @@ pub enum Event {
|
||||
ToggleShortcutNumbers(ShortcutNumbers),
|
||||
UiScale(ScaleChange),
|
||||
CharacterSelection,
|
||||
ActivateInventorySlot(usize),
|
||||
SwapInventorySlots(usize, usize),
|
||||
DropInventorySlot(usize),
|
||||
Logout,
|
||||
|
@ -321,6 +321,7 @@ impl FigureModelCache {
|
||||
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)),
|
||||
},
|
||||
Item::Debug(_) => ("weapon.debug_wand", Vec3::new(-2.5, -6.5, -2.0)),
|
||||
_ => ("figure.empty", Vec3::default()),
|
||||
};
|
||||
Self::load_mesh(name, offset)
|
||||
|
@ -152,7 +152,7 @@ impl PlayState for SessionState {
|
||||
client.place_block(pos, self.selected_block);
|
||||
}
|
||||
} else {
|
||||
self.controller.attack = state
|
||||
self.controller.main = state
|
||||
}
|
||||
}
|
||||
|
||||
@ -176,7 +176,7 @@ impl PlayState for SessionState {
|
||||
client.remove_block(pos);
|
||||
}
|
||||
} else {
|
||||
self.controller.block = state;
|
||||
self.controller.alt = state;
|
||||
}
|
||||
}
|
||||
Event::InputUpdate(GameInput::Roll, state) => {
|
||||
@ -376,6 +376,9 @@ impl PlayState for SessionState {
|
||||
global_state.settings.graphics.max_fps = fps;
|
||||
global_state.settings.save_to_file_warn();
|
||||
}
|
||||
HudEvent::ActivateInventorySlot(x) => {
|
||||
self.client.borrow_mut().activate_inventory_slot(x)
|
||||
}
|
||||
HudEvent::SwapInventorySlots(a, b) => {
|
||||
self.client.borrow_mut().swap_inventory_slots(a, b)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user