mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Merge branch 'angel/add-spawn-training-dummy' into 'master'
Added spawning test dummy See merge request veloren/veloren!1142
This commit is contained in:
commit
3e830aa0ca
@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- Ability to wield 2 × 1h weapons and shields (Note: 1h weapons & shields are not currently avaliable, see [!1095](https://gitlab.com/veloren/veloren/-/merge_requests/1095) for more info)
|
||||
- Zoomable Map
|
||||
- M2 attack for hammer
|
||||
- Spawnable training dummies
|
||||
|
||||
### Changed
|
||||
|
||||
|
BIN
assets/voxygen/voxel/object/training_dummy.vox
(Stored with Git LFS)
Normal file
BIN
assets/voxygen/voxel/object/training_dummy.vox
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -32,6 +32,11 @@ impl TabComplete for ArgumentSpec {
|
||||
.filter(|string| string.starts_with(part))
|
||||
.map(|c| c.to_string())
|
||||
.collect(),
|
||||
ArgumentSpec::Boolean(_, part, _) => vec!["true", "false"]
|
||||
.iter()
|
||||
.filter(|string| string.starts_with(part))
|
||||
.map(|c| c.to_string())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ pub enum ChatCommand {
|
||||
Build,
|
||||
Debug,
|
||||
DebugColumn,
|
||||
Dummy,
|
||||
Explosion,
|
||||
Faction,
|
||||
GiveExp,
|
||||
@ -81,6 +82,7 @@ pub static CHAT_COMMANDS: &[ChatCommand] = &[
|
||||
ChatCommand::Build,
|
||||
ChatCommand::Debug,
|
||||
ChatCommand::DebugColumn,
|
||||
ChatCommand::Dummy,
|
||||
ChatCommand::Explosion,
|
||||
ChatCommand::Faction,
|
||||
ChatCommand::GiveExp,
|
||||
@ -191,6 +193,7 @@ impl ChatCommand {
|
||||
"Prints some debug information about a column",
|
||||
NoAdmin,
|
||||
),
|
||||
ChatCommand::Dummy => cmd(vec![], "Spawns a training dummy", NoAdmin),
|
||||
ChatCommand::Explosion => cmd(
|
||||
vec![Float("radius", 5.0, Required)],
|
||||
"Explodes the ground around you",
|
||||
@ -321,6 +324,7 @@ impl ChatCommand {
|
||||
Enum("alignment", ALIGNMENTS.clone(), Required),
|
||||
Enum("entity", ENTITIES.clone(), Required),
|
||||
Integer("amount", 1, Optional),
|
||||
Boolean("ai", "true".to_string(), Optional),
|
||||
],
|
||||
"Spawn a test entity",
|
||||
Admin,
|
||||
@ -370,6 +374,7 @@ impl ChatCommand {
|
||||
ChatCommand::Build => "build",
|
||||
ChatCommand::Debug => "debug",
|
||||
ChatCommand::DebugColumn => "debug_column",
|
||||
ChatCommand::Dummy => "dummy",
|
||||
ChatCommand::Explosion => "explosion",
|
||||
ChatCommand::Faction => "faction",
|
||||
ChatCommand::GiveExp => "give_exp",
|
||||
@ -433,6 +438,7 @@ impl ChatCommand {
|
||||
ArgumentSpec::Message(_) => "{/.*/}",
|
||||
ArgumentSpec::SubCommand => "{} {/.*/}",
|
||||
ArgumentSpec::Enum(_, _, _) => "{}",
|
||||
ArgumentSpec::Boolean(_, _, _) => "{}",
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(" ")
|
||||
@ -514,6 +520,11 @@ pub enum ArgumentSpec {
|
||||
/// * Predefined string completions
|
||||
/// * whether it's optional
|
||||
Enum(&'static str, Vec<String>, Requirement),
|
||||
/// The argument is likely a boolean. The associated values are
|
||||
/// * label
|
||||
/// * suggested tab-completion
|
||||
/// * whether it's optional
|
||||
Boolean(&'static str, String, Requirement),
|
||||
}
|
||||
|
||||
impl ArgumentSpec {
|
||||
@ -569,6 +580,13 @@ impl ArgumentSpec {
|
||||
format! {"[{}]", label}
|
||||
}
|
||||
},
|
||||
ArgumentSpec::Boolean(label, _, req) => {
|
||||
if &Requirement::Required == req {
|
||||
format!("<{}>", label)
|
||||
} else {
|
||||
format!("[{}]", label)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,6 +56,7 @@ pub enum Body {
|
||||
ArrowSnake = 50,
|
||||
CampfireLit = 51,
|
||||
BoltFireBig = 52,
|
||||
TrainingDummy = 53,
|
||||
}
|
||||
|
||||
impl Body {
|
||||
@ -65,7 +66,7 @@ impl Body {
|
||||
}
|
||||
}
|
||||
|
||||
pub const ALL_OBJECTS: [Body; 53] = [
|
||||
pub const ALL_OBJECTS: [Body; 54] = [
|
||||
Body::Arrow,
|
||||
Body::Bomb,
|
||||
Body::Scarecrow,
|
||||
@ -119,6 +120,7 @@ pub const ALL_OBJECTS: [Body; 53] = [
|
||||
Body::BoltFire,
|
||||
Body::BoltFireBig,
|
||||
Body::ArrowSnake,
|
||||
Body::TrainingDummy,
|
||||
];
|
||||
|
||||
impl Body {
|
||||
@ -177,6 +179,7 @@ impl Body {
|
||||
Body::BoltFire => "bolt_fire",
|
||||
Body::BoltFireBig => "bolt_fire_big",
|
||||
Body::ArrowSnake => "arrow_snake",
|
||||
Body::TrainingDummy => "training_dummy",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -66,6 +66,7 @@ fn get_handler(cmd: &ChatCommand) -> CommandHandler {
|
||||
ChatCommand::Build => handle_build,
|
||||
ChatCommand::Debug => handle_debug,
|
||||
ChatCommand::DebugColumn => handle_debug_column,
|
||||
ChatCommand::Dummy => handle_spawn_training_dummy,
|
||||
ChatCommand::Explosion => handle_explosion,
|
||||
ChatCommand::Faction => handle_faction,
|
||||
ChatCommand::GiveExp => handle_give_exp,
|
||||
@ -497,8 +498,15 @@ fn handle_spawn(
|
||||
args: String,
|
||||
action: &ChatCommand,
|
||||
) {
|
||||
match scan_fmt_some!(&args, &action.arg_fmt(), String, npc::NpcBody, String) {
|
||||
(Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount) => {
|
||||
match scan_fmt_some!(
|
||||
&args,
|
||||
&action.arg_fmt(),
|
||||
String,
|
||||
npc::NpcBody,
|
||||
String,
|
||||
String
|
||||
) {
|
||||
(Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount, opt_ai) => {
|
||||
if let Some(alignment) = parse_alignment(target, &opt_align) {
|
||||
let amount = opt_amount
|
||||
.and_then(|a| a.parse().ok())
|
||||
@ -506,6 +514,8 @@ fn handle_spawn(
|
||||
.unwrap_or(1)
|
||||
.min(10);
|
||||
|
||||
let ai = opt_ai.unwrap_or_else(|| "true".to_string());
|
||||
|
||||
match server.state.read_component_cloned::<comp::Pos>(target) {
|
||||
Some(pos) => {
|
||||
let agent =
|
||||
@ -524,7 +534,7 @@ fn handle_spawn(
|
||||
|
||||
let body = body();
|
||||
|
||||
let new_entity = server
|
||||
let mut entity_base = server
|
||||
.state
|
||||
.create_npc(
|
||||
pos,
|
||||
@ -534,9 +544,13 @@ fn handle_spawn(
|
||||
)
|
||||
.with(comp::Vel(vel))
|
||||
.with(comp::MountState::Unmounted)
|
||||
.with(agent.clone())
|
||||
.with(alignment)
|
||||
.build();
|
||||
.with(alignment);
|
||||
|
||||
if ai == "true" {
|
||||
entity_base = entity_base.with(agent.clone());
|
||||
}
|
||||
|
||||
let new_entity = entity_base.build();
|
||||
|
||||
if let Some(uid) = server.state.ecs().uid_from_entity(new_entity) {
|
||||
server.notify_client(
|
||||
@ -568,6 +582,47 @@ fn handle_spawn(
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_spawn_training_dummy(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
target: EcsEntity,
|
||||
_args: String,
|
||||
_action: &ChatCommand,
|
||||
) {
|
||||
match server.state.read_component_cloned::<comp::Pos>(target) {
|
||||
Some(pos) => {
|
||||
let vel = Vec3::new(
|
||||
rand::thread_rng().gen_range(-2.0, 3.0),
|
||||
rand::thread_rng().gen_range(-2.0, 3.0),
|
||||
10.0,
|
||||
);
|
||||
|
||||
let body = comp::Body::Object(comp::object::Body::TrainingDummy);
|
||||
|
||||
let mut stats = comp::Stats::new("Training Dummy".to_string(), body);
|
||||
|
||||
// Level 0 will prevent exp gain from kill
|
||||
stats.level.set_level(0);
|
||||
|
||||
server
|
||||
.state
|
||||
.create_npc(pos, stats, comp::Loadout::default(), body)
|
||||
.with(comp::Vel(vel))
|
||||
.with(comp::MountState::Unmounted)
|
||||
.build();
|
||||
|
||||
server.notify_client(
|
||||
client,
|
||||
ChatType::CommandInfo.server_msg("Spawned a training dummy"),
|
||||
);
|
||||
},
|
||||
None => server.notify_client(
|
||||
client,
|
||||
ChatType::CommandError.server_msg("You have no position!"),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_players(
|
||||
server: &mut Server,
|
||||
client: EcsEntity,
|
||||
|
@ -23,6 +23,10 @@ pub fn handle_damage(server: &Server, uid: Uid, change: HealthChange) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handle an entity dying. If it is a player, it will send a message to all
|
||||
/// other players. If the entity that killed it had stats, then give it exp for
|
||||
/// the kill. Experience given is equal to the level of the entity that was
|
||||
/// killed times 10.
|
||||
pub fn handle_destroy(server: &mut Server, entity: EcsEntity, cause: HealthSource) {
|
||||
let state = server.state_mut();
|
||||
|
||||
|
@ -3020,6 +3020,7 @@ pub fn mesh_object(
|
||||
Body::ArrowSnake => ("weapon.projectile.snake-arrow", Vec3::new(-1.5, -6.5, 0.0)),
|
||||
Body::BoltFire => ("weapon.projectile.fire-bolt-0", Vec3::new(-3.0, -5.5, -3.0)),
|
||||
Body::BoltFireBig => ("weapon.projectile.fire-bolt-1", Vec3::new(-6.0, -6.0, -6.0)),
|
||||
Body::TrainingDummy => ("object.training_dummy", Vec3::new(-7.0, -5.0, 0.0)),
|
||||
};
|
||||
load_mesh(name, offset, generate_mesh)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user