From 81591fcaf73d0d5f58568181105709081f22f004 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 16 Mar 2020 14:27:52 +0100 Subject: [PATCH] Make npcs attack again --- common/src/comp/inventory/item.rs | 14 ++++++ common/src/states/basic_melee.rs | 12 +++--- server/src/sys/terrain.rs | 72 ++++++++++++++++++++++--------- voxygen/src/anim/character/mod.rs | 2 + voxygen/src/anim/mod.rs | 2 + voxygen/src/hud/item_imgs.rs | 1 + voxygen/src/scene/figure/load.rs | 1 + 7 files changed, 76 insertions(+), 28 deletions(-) diff --git a/common/src/comp/inventory/item.rs b/common/src/comp/inventory/item.rs index fcad410845..7c168b205a 100644 --- a/common/src/comp/inventory/item.rs +++ b/common/src/comp/inventory/item.rs @@ -29,6 +29,8 @@ pub enum ToolKind { Staff, Shield, Debug(DebugKind), + /// This is an placeholder item, it is used by non-humanoid npcs to attack + Empty, } impl ToolData { @@ -97,6 +99,7 @@ impl ToolData { ], Possess => vec![], }, + Empty => vec![], } } } @@ -182,6 +185,17 @@ impl Asset for Item { } impl Item { + pub fn empty() -> Self { + Self { + name: "Empty Item".to_owned(), + description: "This item may grant abilities, but is invisible".to_owned(), + kind: ItemKind::Tool(ToolData { + kind: ToolKind::Empty, + equip_time_millis: 0, + }), + } + } + pub fn name(&self) -> &str { &self.name } pub fn description(&self) -> &str { &self.description } diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index 25dbe9bd6b..1f972e0594 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -44,13 +44,11 @@ impl CharacterBehavior for Data { }); } else if !self.exhausted { // Hit attempt - if let Some(tool) = unwrap_tool_data(data) { - data.updater.insert(data.entity, Attacking { - base_damage: self.base_damage, - applied: false, - hit_count: 0, - }); - } + data.updater.insert(data.entity, Attacking { + base_damage: self.base_damage, + applied: false, + hit_count: 0, + }); update.character = CharacterState::BasicMelee(Data { buildup_duration: self.buildup_duration, diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index 9a0f4eec07..2224afd53d 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -2,7 +2,7 @@ use super::SysTimer; use crate::{chunk_generator::ChunkGenerator, client::Client, Tick}; use common::{ assets, - comp::{self, item, Player, Pos}, + comp::{self, item, CharacterAbility, Item, ItemConfig, Player, Pos}, event::{EventBus, ServerEvent}, generation::EntityKind, msg::ServerMsg, @@ -12,7 +12,7 @@ use common::{ }; use rand::{seq::SliceRandom, Rng}; use specs::{Join, Read, ReadStorage, System, Write, WriteExpect, WriteStorage}; -use std::sync::Arc; +use std::{sync::Arc, time::Duration}; use vek::*; /// This system will handle loading generated chunks and unloading @@ -181,22 +181,50 @@ impl<'a> System<'a> for Sys { .expect("SPAWN_NPCS is nonempty")( ); let mut stats = comp::Stats::new(name, body); - let mut loadout = comp::Loadout { - active_item: main.map(|item| comp::ItemConfig { - item, - primary_ability: None, - secondary_ability: None, - block_ability: None, - dodge_ability: None, - }), - second_item: None, - shoulder: None, - chest: None, - belt: None, - hand: None, - pants: None, - foot: None, - }; + + let mut loadout = + if let Some(comp::ItemKind::Tool(tool)) = main.as_ref().map(|i| &i.kind) { + let mut abilities = tool.get_abilities(); + let mut ability_drain = abilities.drain(..); + + comp::Loadout { + active_item: main.map(|item| comp::ItemConfig { + item, + primary_ability: ability_drain.next(), + secondary_ability: ability_drain.next(), + block_ability: Some(comp::CharacterAbility::BasicBlock), + dodge_ability: Some(comp::CharacterAbility::Roll), + }), + second_item: None, + shoulder: None, + chest: None, + belt: None, + hand: None, + pants: None, + foot: None, + } + } else { + comp::Loadout { + active_item: Some(ItemConfig { + item: Item::empty(), + primary_ability: Some(CharacterAbility::BasicMelee { + buildup_duration: Duration::from_millis(50), + recover_duration: Duration::from_millis(50), + base_damage: 10, + }), + secondary_ability: None, + block_ability: None, + dodge_ability: None, + }), + second_item: None, + shoulder: None, + chest: None, + belt: None, + hand: None, + pants: None, + foot: None, + } + }; let mut scale = 1.0; @@ -220,9 +248,11 @@ impl<'a> System<'a> for Sys { loadout = comp::Loadout { active_item: Some(comp::ItemConfig { item: assets::load_expect_cloned("common.items.weapons.hammer_1"), - primary_ability: None, /* TODO: when implementing this, make sure - * to adjust the base damage (see todo - * below) */ + primary_ability: Some(CharacterAbility::BasicMelee { + buildup_duration: Duration::from_millis(800), + recover_duration: Duration::from_millis(200), + base_damage: 130, + }), secondary_ability: None, block_ability: None, dodge_ability: None, diff --git a/voxygen/src/anim/character/mod.rs b/voxygen/src/anim/character/mod.rs index 1fb83a2cbb..952d8f149f 100644 --- a/voxygen/src/anim/character/mod.rs +++ b/voxygen/src/anim/character/mod.rs @@ -236,6 +236,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr { ToolKind::Bow => 0.0, ToolKind::Dagger => 0.0, ToolKind::Debug(_) => 0.0, + ToolKind::Empty => 0.0, }, weapon_y: match ToolKind::Hammer { ToolKind::Sword(_) => -1.25, @@ -246,6 +247,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr { ToolKind::Bow => -2.0, ToolKind::Dagger => -2.0, ToolKind::Debug(_) => 0.0, + ToolKind::Empty => 0.0, }, } } diff --git a/voxygen/src/anim/mod.rs b/voxygen/src/anim/mod.rs index df32446f5c..c09fbc3e97 100644 --- a/voxygen/src/anim/mod.rs +++ b/voxygen/src/anim/mod.rs @@ -176,6 +176,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr { ToolKind::Bow => 0.0, ToolKind::Dagger => 0.0, ToolKind::Debug(_) => 0.0, + ToolKind::Empty => 0.0, }, weapon_y: match ToolKind::Hammer { // TODO: Inventory @@ -187,6 +188,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr { ToolKind::Bow => -2.0, ToolKind::Dagger => -2.0, ToolKind::Debug(_) => 0.0, + ToolKind::Empty => 0.0, }, } } diff --git a/voxygen/src/hud/item_imgs.rs b/voxygen/src/hud/item_imgs.rs index c35db25eab..863a5b4e8c 100644 --- a/voxygen/src/hud/item_imgs.rs +++ b/voxygen/src/hud/item_imgs.rs @@ -19,6 +19,7 @@ pub enum ItemKey { Utility(Utility), Consumable(Consumable), Ingredient(Ingredient), + Empty, } impl From<&Item> for ItemKey { fn from(item: &Item) -> Self { diff --git a/voxygen/src/scene/figure/load.rs b/voxygen/src/scene/figure/load.rs index 158b389bb4..2ecebb6cb3 100644 --- a/voxygen/src/scene/figure/load.rs +++ b/voxygen/src/scene/figure/load.rs @@ -636,6 +636,7 @@ pub fn mesh_main(item_kind: Option<&ItemKind>) -> Mesh { ToolKind::Bow => ("weapon.bow.simple-bow", Vec3::new(-1.0, -6.0, -2.0)), ToolKind::Staff => ("weapon.staff.wood-fire", Vec3::new(-1.0, -6.0, -3.0)), ToolKind::Debug(_) => ("weapon.debug_wand", Vec3::new(-1.5, -9.5, -4.0)), + ToolKind::Empty => return Mesh::new(), }, _ => return Mesh::new(), };