mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Support quantity + use Enum for autocompletion + Address comments
This commit is contained in:
parent
0692562533
commit
a4bd47f340
@ -1,29 +1,35 @@
|
|||||||
({
|
({
|
||||||
"debug": [
|
"debug": [
|
||||||
"common.items.debug.admin_back",
|
("common.items.debug.admin_back",1),
|
||||||
"common.items.debug.admin_black_hole",
|
("common.items.debug.admin_black_hole",1),
|
||||||
"common.items.debug.admin_stick",
|
("common.items.debug.admin_stick",1),
|
||||||
"common.items.debug.admin_sword",
|
("common.items.debug.admin_sword",1),
|
||||||
"common.items.debug.admin",
|
("common.items.debug.admin",1),
|
||||||
"common.items.debug.cultist_belt",
|
("common.items.debug.cultist_belt",1),
|
||||||
"common.items.debug.cultist_boots",
|
("common.items.debug.cultist_boots",1),
|
||||||
"common.items.debug.cultist_chest_blue",
|
("common.items.debug.cultist_chest_blue",1),
|
||||||
"common.items.debug.cultist_hands_blue",
|
("common.items.debug.cultist_hands_blue",1),
|
||||||
"common.items.debug.cultist_legs_blue",
|
("common.items.debug.cultist_legs_blue",1),
|
||||||
"common.items.debug.cultist_shoulder_blue",
|
("common.items.debug.cultist_shoulder_blue",1),
|
||||||
"common.items.debug.dungeon_purple",
|
("common.items.debug.dungeon_purple",1),
|
||||||
],
|
],
|
||||||
"cultist": [
|
"cultist": [
|
||||||
"common.items.armor.cultist.chest",
|
("common.items.armor.cultist.chest",1),
|
||||||
"common.items.armor.cultist.pants",
|
("common.items.armor.cultist.pants",1),
|
||||||
"common.items.armor.cultist.hand",
|
("common.items.armor.cultist.hand",1),
|
||||||
"common.items.armor.cultist.foot",
|
("common.items.armor.cultist.foot",1),
|
||||||
"common.items.armor.cultist.shoulder",
|
("common.items.armor.cultist.shoulder",1),
|
||||||
"common.items.armor.cultist.belt",
|
("common.items.armor.cultist.belt",1),
|
||||||
"common.items.weapons.hammer.cultist_purp_2h-0",
|
("common.items.weapons.hammer.cultist_purp_2h-0",1),
|
||||||
"common.items.weapons.staff.cultist_staff",
|
("common.items.weapons.staff.cultist_staff",1),
|
||||||
"common.items.weapons.sword.cultist",
|
("common.items.weapons.sword.cultist",1),
|
||||||
"common.items.weapons.bow.velorite",
|
("common.items.weapons.bow.velorite",1),
|
||||||
"common.items.weapons.axe.malachite_axe-0",
|
("common.items.weapons.axe.malachite_axe-0",1),
|
||||||
|
("common.items.weapons.sceptre.sceptre_velorite_0",1),
|
||||||
|
],
|
||||||
|
"potions": [
|
||||||
|
("common.items.consumable.potion_minor", 100),
|
||||||
|
("common.items.consumable.potion_med", 100),
|
||||||
|
("common.items.consumable.potion_big", 100),
|
||||||
]
|
]
|
||||||
})
|
})
|
@ -1,6 +1,8 @@
|
|||||||
use crate::{assets, comp, npc, terrain};
|
use crate::{assets, comp, npc, terrain};
|
||||||
|
use assets::AssetExt;
|
||||||
use hashbrown::HashMap;
|
use hashbrown::HashMap;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Display},
|
fmt::{self, Display},
|
||||||
path::Path,
|
path::Path,
|
||||||
@ -155,6 +157,14 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
|||||||
ChatCommand::World,
|
ChatCommand::World,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
||||||
|
pub struct KitManifest(pub HashMap<String, Vec<(String, u32)>>);
|
||||||
|
impl assets::Asset for KitManifest {
|
||||||
|
type Loader = assets::RonLoader;
|
||||||
|
|
||||||
|
const EXTENSION: &'static str = "ron";
|
||||||
|
}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
pub static ref CHAT_SHORTCUTS: HashMap<char, ChatCommand> = [
|
pub static ref CHAT_SHORTCUTS: HashMap<char, ChatCommand> = [
|
||||||
('f', ChatCommand::Faction),
|
('f', ChatCommand::Faction),
|
||||||
@ -224,6 +234,14 @@ lazy_static! {
|
|||||||
items.sort();
|
items.sort();
|
||||||
items
|
items
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static ref KITS: Vec<String> = {
|
||||||
|
if let Ok(kits) = KitManifest::load("server.manifests.kits") {
|
||||||
|
kits.read().0.keys().cloned().collect()
|
||||||
|
} else {
|
||||||
|
Vec::new()
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChatCommand {
|
impl ChatCommand {
|
||||||
@ -358,7 +376,7 @@ impl ChatCommand {
|
|||||||
ChatCommand::Kill => cmd(vec![], "Kill yourself", NoAdmin),
|
ChatCommand::Kill => cmd(vec![], "Kill yourself", NoAdmin),
|
||||||
ChatCommand::KillNpcs => cmd(vec![], "Kill the NPCs", Admin),
|
ChatCommand::KillNpcs => cmd(vec![], "Kill the NPCs", Admin),
|
||||||
ChatCommand::Kit => cmd(
|
ChatCommand::Kit => cmd(
|
||||||
vec![Any("kit_name", Required)],
|
vec![Enum("kit_name", KITS.to_vec(), Required)],
|
||||||
"Place a set of items into your inventory.",
|
"Place a set of items into your inventory.",
|
||||||
Admin,
|
Admin,
|
||||||
),
|
),
|
||||||
|
@ -38,10 +38,8 @@ use common_sys::state::{BuildAreaError, BuildAreas};
|
|||||||
use core::{convert::TryFrom, ops::Not, time::Duration};
|
use core::{convert::TryFrom, ops::Not, time::Duration};
|
||||||
use hashbrown::HashSet;
|
use hashbrown::HashSet;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use world::util::Sampler;
|
use world::util::Sampler;
|
||||||
|
|
||||||
@ -1406,14 +1404,6 @@ fn handle_kill_npcs(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Serialize, Deserialize, Clone)]
|
|
||||||
struct KitManifest(HashMap<String, Vec<String>>);
|
|
||||||
impl assets::Asset for KitManifest {
|
|
||||||
type Loader = assets::RonLoader;
|
|
||||||
|
|
||||||
const EXTENSION: &'static str = "ron";
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_kit(
|
fn handle_kit(
|
||||||
server: &mut Server,
|
server: &mut Server,
|
||||||
_client: EcsEntity,
|
_client: EcsEntity,
|
||||||
@ -1423,28 +1413,33 @@ fn handle_kit(
|
|||||||
) -> CmdResult<()> {
|
) -> CmdResult<()> {
|
||||||
let kit_name = scan_fmt!(&args, &action.arg_fmt(), String);
|
let kit_name = scan_fmt!(&args, &action.arg_fmt(), String);
|
||||||
if let Ok(name) = kit_name {
|
if let Ok(name) = kit_name {
|
||||||
if let Ok(kits) = KitManifest::load("server.manifests.kits") {
|
if let Ok(kits) = common::cmd::KitManifest::load("server.manifests.kits") {
|
||||||
let kits = kits.read();
|
let kits = kits.read();
|
||||||
if let Some(kit) = kits.0.get(&name) {
|
if let Some(kit) = kits.0.get(&name) {
|
||||||
for item_id in kit.iter() {
|
if let (Some(mut target_inventory), mut target_inv_update) = (
|
||||||
if let Ok(item) = comp::Item::new_from_asset(item_id) {
|
server
|
||||||
server
|
.state()
|
||||||
.state()
|
.ecs()
|
||||||
.ecs()
|
.write_storage::<comp::Inventory>()
|
||||||
.write_storage::<comp::Inventory>()
|
.get_mut(target),
|
||||||
.get_mut(target)
|
server.state.ecs().write_storage::<comp::InventoryUpdate>(),
|
||||||
.map(|mut inv| inv.push(item));
|
) {
|
||||||
let _ = server
|
for (item_id, quantity) in kit.iter() {
|
||||||
.state
|
if let Ok(mut item) = comp::Item::new_from_asset(item_id) {
|
||||||
.ecs()
|
let _ = item.set_amount(*quantity);
|
||||||
.write_storage::<comp::InventoryUpdate>()
|
let (_, _) = (
|
||||||
.insert(
|
target_inventory.push(item),
|
||||||
target,
|
target_inv_update.insert(
|
||||||
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Debug),
|
target,
|
||||||
|
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Debug),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err("Could not get inventory".to_string())
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
} else {
|
} else {
|
||||||
Err(format!("Kit '{}' not found", name))
|
Err(format!("Kit '{}' not found", name))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user