From 3cfd8bdd3cee7e14ed05604a77cdb545bd8468cb Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 7 Jul 2020 02:21:14 +0100 Subject: [PATCH] Fixed animal loadouts and /spawn --- common/src/comp/inventory/item/tool.rs | 2 +- common/src/loadout_builder.rs | 35 ++++++++++++++++++++++++ common/src/sys/agent.rs | 10 +++---- common/src/sys/combat.rs | 20 ++++++++------ server/src/cmd.rs | 3 +- server/src/sys/terrain.rs | 38 ++++---------------------- 6 files changed, 60 insertions(+), 48 deletions(-) diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 443859c859..2f2dc32f81 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -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, }], diff --git a/common/src/loadout_builder.rs b/common/src/loadout_builder.rs index 76562e8d90..48df447299 100644 --- a/common/src/loadout_builder.rs +++ b/common/src/loadout_builder.rs @@ -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 diff --git a/common/src/sys/agent.rs b/common/src/sys/agent.rs index cd2e1208c2..5fcfd5d47a 100644 --- a/common/src/sys/agent.rs +++ b/common/src/sys/agent.rs @@ -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), diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index 1882b5c390..f0e84e65bb 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -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 diff --git a/server/src/cmd.rs b/server/src/cmd.rs index 8e7f3517e7..3f6bac7169 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -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)) diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 54d01b0596..5a3b9c6a36 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -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;