mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Add optional argument to /get_items
This commit is contained in:
parent
846c3a9a0b
commit
63826d1a50
@ -72,6 +72,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
- The /give_item command can now specify the amount of items. Syntax is now `/give_item <name> [num]`
|
||||||
- Brighter / higher contrast main-map
|
- Brighter / higher contrast main-map
|
||||||
- Removed highlighting of non-collectible sprites
|
- Removed highlighting of non-collectible sprites
|
||||||
- Fixed /give_exp ignoring player argument
|
- Fixed /give_exp ignoring player argument
|
||||||
|
@ -123,6 +123,28 @@ impl Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_amount(&mut self, give_amount: u32) -> Result<(), assets::Error> {
|
||||||
|
use ItemKind::*;
|
||||||
|
match self.kind {
|
||||||
|
Consumable { ref mut amount, .. } => {
|
||||||
|
*amount = give_amount;
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Utility { ref mut amount, .. } => {
|
||||||
|
*amount = give_amount;
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Ingredient { ref mut amount, .. } => {
|
||||||
|
*amount = give_amount;
|
||||||
|
Ok(())
|
||||||
|
},
|
||||||
|
Tool { .. } | Lantern { .. } | Armor { .. } => {
|
||||||
|
// Tools and armor don't stack
|
||||||
|
Err(assets::Error::InvalidType)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str { &self.name }
|
pub fn name(&self) -> &str { &self.name }
|
||||||
|
|
||||||
pub fn description(&self) -> &str { &self.description }
|
pub fn description(&self) -> &str { &self.description }
|
||||||
|
@ -95,9 +95,9 @@ lazy_static! {
|
|||||||
pub static ref CHAT_COMMANDS: Vec<ChatCommand> = vec![
|
pub static ref CHAT_COMMANDS: Vec<ChatCommand> = vec![
|
||||||
ChatCommand::new(
|
ChatCommand::new(
|
||||||
"give_item",
|
"give_item",
|
||||||
"{d}",
|
"{} {d}",
|
||||||
"/give_item <path to item>\n\
|
"/give_item <path to item> [num]\n\
|
||||||
Example: common/items/debug/boost",
|
Example items: common/items/apple, common/items/debug/boost",
|
||||||
true,
|
true,
|
||||||
handle_give,),
|
handle_give,),
|
||||||
ChatCommand::new(
|
ChatCommand::new(
|
||||||
@ -285,25 +285,68 @@ fn handle_give(
|
|||||||
client: EcsEntity,
|
client: EcsEntity,
|
||||||
target: EcsEntity,
|
target: EcsEntity,
|
||||||
args: String,
|
args: String,
|
||||||
_action: &ChatCommand,
|
action: &ChatCommand,
|
||||||
) {
|
) {
|
||||||
if let Ok(item) = assets::load_cloned(&args) {
|
if let (Some(item_name), give_amount_opt) = scan_fmt_some!(&args, action.arg_fmt, String, u32) {
|
||||||
server
|
let give_amount = give_amount_opt.unwrap_or(1);
|
||||||
.state
|
if let Ok(item) = assets::load_cloned(&item_name) {
|
||||||
.ecs()
|
let mut item: Item = item;
|
||||||
.write_storage::<comp::Inventory>()
|
if let Ok(()) = item.set_amount(give_amount.min(2000)) {
|
||||||
.get_mut(target)
|
server
|
||||||
.map(|inv| inv.push(item));
|
.state
|
||||||
let _ = server
|
.ecs()
|
||||||
.state
|
.write_storage::<comp::Inventory>()
|
||||||
.ecs()
|
.get_mut(target)
|
||||||
.write_storage::<comp::InventoryUpdate>()
|
.map(|inv| {
|
||||||
.insert(
|
if inv.push(item).is_some() {
|
||||||
target,
|
server.notify_client(
|
||||||
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Given),
|
client,
|
||||||
|
ServerMsg::private(format!(
|
||||||
|
"Player inventory full. Gave 0 of {} items.",
|
||||||
|
give_amount
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// This item can't stack. Give each item in a loop.
|
||||||
|
server
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.write_storage::<comp::Inventory>()
|
||||||
|
.get_mut(target)
|
||||||
|
.map(|inv| {
|
||||||
|
for i in 0..give_amount {
|
||||||
|
if inv.push(item.clone()).is_some() {
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ServerMsg::private(format!(
|
||||||
|
"Player inventory full. Gave {} of {} items.",
|
||||||
|
i, give_amount
|
||||||
|
)),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
let _ = server
|
||||||
|
.state
|
||||||
|
.ecs()
|
||||||
|
.write_storage::<comp::InventoryUpdate>()
|
||||||
|
.insert(
|
||||||
|
target,
|
||||||
|
comp::InventoryUpdate::new(comp::InventoryUpdateEvent::Given),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
server.notify_client(
|
||||||
|
client,
|
||||||
|
ServerMsg::private(format!("Invalid item: {}", item_name)),
|
||||||
);
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
server.notify_client(client, ServerMsg::private(String::from("Invalid item!")));
|
server.notify_client(client, ServerMsg::private(String::from(action.help_string)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user