Fixed animal loadouts and /spawn

This commit is contained in:
Joshua Barretto 2020-07-07 02:21:14 +01:00
parent d1cdb6ea55
commit 3cfd8bdd3c
6 changed files with 60 additions and 48 deletions

View File

@ -448,7 +448,7 @@ impl Tool {
energy_cost: 0,
buildup_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(1000),
base_healthchange: -3,
base_healthchange: -2,
range: 5.0,
max_angle: 60.0,
}],

View File

@ -5,6 +5,7 @@ use crate::{
CharacterAbility, ItemConfig, Loadout,
},
};
use std::time::Duration;
/// Builder for character Loadouts, containing weapon and armour items belonging
/// to a character, along with some helper methods for loading Items and
@ -61,6 +62,40 @@ impl LoadoutBuilder {
)))
}
/// Default animal configuration
pub fn animal() -> Self {
Self(Loadout {
active_item: Some(ItemConfig {
item: assets::load_expect_cloned("common.items.weapons.empty"),
ability1: Some(CharacterAbility::BasicMelee {
energy_cost: 10,
buildup_duration: Duration::from_millis(600),
recover_duration: Duration::from_millis(100),
base_healthchange: -6,
range: 5.0,
max_angle: 80.0,
}),
ability2: None,
ability3: None,
block_ability: None,
dodge_ability: None,
}),
second_item: None,
shoulder: None,
chest: None,
belt: None,
hand: None,
pants: None,
foot: None,
back: None,
ring: None,
neck: None,
lantern: None,
head: None,
tabard: None,
})
}
/// Get the default [ItemConfig](../comp/struct.ItemConfig.html) for a tool
/// (weapon). This information is required for the `active` and `second`
/// weapon items in a loadout. If some customisation to the item's

View File

@ -118,7 +118,7 @@ impl<'a> System<'a> for Sys {
const LISTEN_DIST: f32 = 16.0;
const SEARCH_DIST: f32 = 48.0;
const SIGHT_DIST: f32 = 128.0;
const MIN_ATTACK_DIST: f32 = 3.25;
const MIN_ATTACK_DIST: f32 = 3.5;
let scale = scales.get(entity).map(|s| s.0).unwrap_or(1.0);
@ -266,10 +266,10 @@ impl<'a> System<'a> for Sys {
let dist_sqrd = pos.0.distance_squared(tgt_pos.0);
if dist_sqrd < (MIN_ATTACK_DIST * scale).powf(2.0) {
// Close-range attack
/*inputs.move_dir = Vec2::from(tgt_pos.0 - pos.0)
.try_normalized()
.unwrap_or(Vec2::unit_y())
* 0.7;*/
inputs.move_dir = Vec2::from(tgt_pos.0 - pos.0)
.try_normalized()
.unwrap_or(Vec2::unit_y())
* 0.1;
match tactic {
Tactic::Melee | Tactic::Staff => inputs.primary.set_state(true),

View File

@ -111,6 +111,7 @@ impl<'a> System<'a> for Sys {
{
// Weapon gives base damage
let mut healthchange = attack.base_healthchange as f32;
let mut knockback = attack.knockback;
// TODO: remove this, either it will remain unused or be used as a temporary
// gameplay balance
@ -130,6 +131,7 @@ impl<'a> System<'a> for Sys {
.unwrap_or(false))
{
healthchange = 0.0;
knockback = 0.0;
}
if rand::random() {
@ -143,14 +145,16 @@ impl<'a> System<'a> for Sys {
healthchange *= 1.0 - BLOCK_EFFICIENCY
}
server_emitter.emit(ServerEvent::Damage {
uid: *uid_b,
change: HealthChange {
amount: healthchange as i32,
cause: HealthSource::Attack { by: *uid },
},
});
if attack.knockback != 0.0 {
if healthchange != 0.0 {
server_emitter.emit(ServerEvent::Damage {
uid: *uid_b,
change: HealthChange {
amount: healthchange as i32,
cause: HealthSource::Attack { by: *uid },
},
});
}
if knockback != 0.0 {
local_emitter.emit(LocalEvent::ApplyForce {
entity: b,
force: attack.knockback

View File

@ -16,6 +16,7 @@ use common::{
terrain::TerrainChunkSize,
util::Dir,
vol::RectVolSize,
LoadoutBuilder,
};
use rand::Rng;
use specs::{Builder, Entity as EcsEntity, Join, WorldExt};
@ -543,7 +544,7 @@ fn handle_spawn(
.create_npc(
pos,
comp::Stats::new(get_npc_name(id).into(), body),
comp::Loadout::default(),
LoadoutBuilder::animal().build(),
body,
)
.with(comp::Vel(vel))

View File

@ -9,6 +9,7 @@ use common::{
npc::NPC_NAMES,
state::TerrainChanges,
terrain::TerrainGrid,
LoadoutBuilder,
};
use rand::Rng;
use specs::{Join, Read, ReadStorage, System, Write, WriteExpect, WriteStorage};
@ -136,9 +137,9 @@ impl<'a> System<'a> for Sys {
energy_cost: 0,
buildup_duration: Duration::from_millis(0),
recover_duration: Duration::from_millis(400),
base_healthchange: -2,
range: 3.5,
max_angle: 60.0,
base_healthchange: -6,
range: 5.0,
max_angle: 80.0,
}),
ability2: None,
ability3: None,
@ -214,36 +215,7 @@ impl<'a> System<'a> for Sys {
head: None,
tabard: None,
},
_ => comp::Loadout {
active_item: Some(comp::ItemConfig {
item: assets::load_expect_cloned("common.items.weapons.empty"),
ability1: Some(CharacterAbility::BasicMelee {
energy_cost: 10,
buildup_duration: Duration::from_millis(800),
recover_duration: Duration::from_millis(200),
base_healthchange: -2,
range: 3.5,
max_angle: 60.0,
}),
ability2: None,
ability3: None,
block_ability: None,
dodge_ability: None,
}),
second_item: None,
shoulder: None,
chest: None,
belt: None,
hand: None,
pants: None,
foot: None,
back: None,
ring: None,
neck: None,
lantern: None,
head: None,
tabard: None,
},
_ => LoadoutBuilder::animal().build(),
};
let mut scale = entity.scale;