mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
spawn objects by name
This commit is contained in:
parent
f6e24d8161
commit
85281e7e54
@ -27,7 +27,7 @@ pub enum Body {
|
||||
PotionGreen,
|
||||
PotionRed,
|
||||
Crate,
|
||||
Tent,
|
||||
Tent,
|
||||
}
|
||||
|
||||
impl Body {
|
||||
@ -63,5 +63,5 @@ const ALL_OBJECTS: [Body; 26] = [
|
||||
Body::PotionBlue,
|
||||
Body::PotionGreen,
|
||||
Body::Crate,
|
||||
Body::Tent,
|
||||
Body::Tent,
|
||||
];
|
||||
|
@ -3,6 +3,7 @@
|
||||
//! and provide a handler function.
|
||||
|
||||
use crate::Server;
|
||||
use common::comp::object::Body;
|
||||
use common::{
|
||||
comp,
|
||||
msg::ServerMsg,
|
||||
@ -134,7 +135,7 @@ lazy_static! {
|
||||
ChatCommand::new(
|
||||
"object",
|
||||
"{}",
|
||||
"/object : Spawn a random object",
|
||||
"/object [Name]: Spawn an object",
|
||||
handle_object,
|
||||
),
|
||||
];
|
||||
@ -312,7 +313,7 @@ fn handle_spawn(server: &mut Server, entity: EcsEntity, args: String, action: &C
|
||||
let (opt_align, opt_id, opt_amount) = scan_fmt!(&args, action.arg_fmt, String, NpcKind, String);
|
||||
// This should be just an enum handled with scan_fmt!
|
||||
let opt_agent = alignment_to_agent(&opt_align.unwrap_or(String::new()), entity);
|
||||
|
||||
let objtype = scan_fmt!(&args, action.arg_fmt, String);
|
||||
// Make sure the amount is either not provided or a valid value
|
||||
let opt_amount = opt_amount
|
||||
.map_or(Some(1), |a| a.parse().ok())
|
||||
@ -450,7 +451,8 @@ fn handle_killnpcs(server: &mut Server, entity: EcsEntity, _args: String, _actio
|
||||
server.clients.notify(entity, ServerMsg::Chat(text));
|
||||
}
|
||||
|
||||
fn handle_object(server: &mut Server, entity: EcsEntity, _args: String, _action: &ChatCommand) {
|
||||
fn handle_object(server: &mut Server, entity: EcsEntity, args: String, _action: &ChatCommand) {
|
||||
let obj_type = scan_fmt!(&args, _action.arg_fmt, String);
|
||||
let pos = server
|
||||
.state
|
||||
.ecs()
|
||||
@ -458,12 +460,37 @@ fn handle_object(server: &mut Server, entity: EcsEntity, _args: String, _action:
|
||||
.get(entity)
|
||||
.copied();
|
||||
if let Some(pos) = pos {
|
||||
let object_type = match objtype {
|
||||
"Tent" => comp::object::Body::Tent,
|
||||
"Bomb" => comp::object::Body::Bomb,
|
||||
"_" => None
|
||||
};
|
||||
server.create_object(pos, object_type).build()
|
||||
let obj_type = match obj_type.as_ref().map(String::as_str) {
|
||||
Some("Scarecrow") => comp::object::Body::Scarecrow,
|
||||
Some("Cauldron") => comp::object::Body::Cauldron,
|
||||
Some("Chest_Vines") => comp::object::Body::ChestVines,
|
||||
Some("Chest") => comp::object::Body::Chest,
|
||||
Some("Chest_Dark") => comp::object::Body::ChestDark,
|
||||
Some("Chest_Demon") => comp::object::Body::ChestDemon,
|
||||
Some("Chest_Gold") => comp::object::Body::ChestGold,
|
||||
Some("Chest_Light") => comp::object::Body::ChestLight,
|
||||
Some("Chest_Open") => comp::object::Body::ChestOpen,
|
||||
Some("Chest_Skull") => comp::object::Body::ChestSkull,
|
||||
Some("Pumpkin_1") => comp::object::Body::Pumpkin1,
|
||||
Some("Pumpkin_2") => comp::object::Body::Pumpkin2,
|
||||
Some("Pumpkin_3") => comp::object::Body::Pumpkin3,
|
||||
Some("Pumpkin_4") => comp::object::Body::Pumpkin4,
|
||||
Some("Pumpkin_5") => comp::object::Body::Pumpkin5,
|
||||
Some("Campfire") => comp::object::Body::Campfire,
|
||||
Some("Lantern_Ground") => comp::object::Body::LanternGround,
|
||||
Some("Lantern_Ground_Open") => comp::object::Body::LanternGroundOpen,
|
||||
Some("Lantern_Standing_2") => comp::object::Body::LanternStanding2,
|
||||
Some("Lantern_Standing") => comp::object::Body::LanternStanding,
|
||||
Some("Potion_Blue") => comp::object::Body::PotionBlue,
|
||||
Some("Potion_Green") => comp::object::Body::PotionGreen,
|
||||
Some("Potion_Red") => comp::object::Body::PotionRed,
|
||||
Some("Crate") => comp::object::Body::Crate,
|
||||
Some("Tent") => comp::object::Body::Tent,
|
||||
Some("Bomb") => comp::object::Body::Bomb,
|
||||
Some(&_) => (return),
|
||||
None => (return),
|
||||
};
|
||||
server.create_object(pos, obj_type).build();
|
||||
server
|
||||
.clients
|
||||
.notify(entity, ServerMsg::Chat(format!("Spawned object.")));
|
||||
|
@ -547,7 +547,7 @@ impl FigureModelCache {
|
||||
object::Body::PotionBlue => ("object/potion_blue.vox", Vec3::new(-2.0, -2.0, 0.0)),
|
||||
object::Body::PotionGreen => ("object/potion_green.vox", Vec3::new(-2.0, -2.0, 0.0)),
|
||||
object::Body::Crate => ("object/crate.vox", Vec3::new(-7.0, -7.0, 0.0)),
|
||||
object::Body::Tent => ("object/tent.vox", Vec3::new(-18.5, -19.5, 0.0)),
|
||||
object::Body::Tent => ("object/tent.vox", Vec3::new(-18.5, -19.5, 0.0)),
|
||||
};
|
||||
Self::load_mesh(name, offset)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user