Make npcs attack again

This commit is contained in:
timokoesters 2020-03-16 14:27:52 +01:00
parent 1279f70184
commit 81591fcaf7
7 changed files with 76 additions and 28 deletions

View File

@ -29,6 +29,8 @@ pub enum ToolKind {
Staff, Staff,
Shield, Shield,
Debug(DebugKind), Debug(DebugKind),
/// This is an placeholder item, it is used by non-humanoid npcs to attack
Empty,
} }
impl ToolData { impl ToolData {
@ -97,6 +99,7 @@ impl ToolData {
], ],
Possess => vec![], Possess => vec![],
}, },
Empty => vec![],
} }
} }
} }
@ -182,6 +185,17 @@ impl Asset for Item {
} }
impl 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 name(&self) -> &str { &self.name }
pub fn description(&self) -> &str { &self.description } pub fn description(&self) -> &str { &self.description }

View File

@ -44,13 +44,11 @@ impl CharacterBehavior for Data {
}); });
} else if !self.exhausted { } else if !self.exhausted {
// Hit attempt // Hit attempt
if let Some(tool) = unwrap_tool_data(data) { data.updater.insert(data.entity, Attacking {
data.updater.insert(data.entity, Attacking { base_damage: self.base_damage,
base_damage: self.base_damage, applied: false,
applied: false, hit_count: 0,
hit_count: 0, });
});
}
update.character = CharacterState::BasicMelee(Data { update.character = CharacterState::BasicMelee(Data {
buildup_duration: self.buildup_duration, buildup_duration: self.buildup_duration,

View File

@ -2,7 +2,7 @@ use super::SysTimer;
use crate::{chunk_generator::ChunkGenerator, client::Client, Tick}; use crate::{chunk_generator::ChunkGenerator, client::Client, Tick};
use common::{ use common::{
assets, assets,
comp::{self, item, Player, Pos}, comp::{self, item, CharacterAbility, Item, ItemConfig, Player, Pos},
event::{EventBus, ServerEvent}, event::{EventBus, ServerEvent},
generation::EntityKind, generation::EntityKind,
msg::ServerMsg, msg::ServerMsg,
@ -12,7 +12,7 @@ use common::{
}; };
use rand::{seq::SliceRandom, Rng}; use rand::{seq::SliceRandom, Rng};
use specs::{Join, Read, ReadStorage, System, Write, WriteExpect, WriteStorage}; use specs::{Join, Read, ReadStorage, System, Write, WriteExpect, WriteStorage};
use std::sync::Arc; use std::{sync::Arc, time::Duration};
use vek::*; use vek::*;
/// This system will handle loading generated chunks and unloading /// This system will handle loading generated chunks and unloading
@ -181,22 +181,50 @@ impl<'a> System<'a> for Sys {
.expect("SPAWN_NPCS is nonempty")( .expect("SPAWN_NPCS is nonempty")(
); );
let mut stats = comp::Stats::new(name, body); let mut stats = comp::Stats::new(name, body);
let mut loadout = comp::Loadout {
active_item: main.map(|item| comp::ItemConfig { let mut loadout =
item, if let Some(comp::ItemKind::Tool(tool)) = main.as_ref().map(|i| &i.kind) {
primary_ability: None, let mut abilities = tool.get_abilities();
secondary_ability: None, let mut ability_drain = abilities.drain(..);
block_ability: None,
dodge_ability: None, comp::Loadout {
}), active_item: main.map(|item| comp::ItemConfig {
second_item: None, item,
shoulder: None, primary_ability: ability_drain.next(),
chest: None, secondary_ability: ability_drain.next(),
belt: None, block_ability: Some(comp::CharacterAbility::BasicBlock),
hand: None, dodge_ability: Some(comp::CharacterAbility::Roll),
pants: None, }),
foot: None, 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; let mut scale = 1.0;
@ -220,9 +248,11 @@ impl<'a> System<'a> for Sys {
loadout = comp::Loadout { loadout = comp::Loadout {
active_item: Some(comp::ItemConfig { active_item: Some(comp::ItemConfig {
item: assets::load_expect_cloned("common.items.weapons.hammer_1"), item: assets::load_expect_cloned("common.items.weapons.hammer_1"),
primary_ability: None, /* TODO: when implementing this, make sure primary_ability: Some(CharacterAbility::BasicMelee {
* to adjust the base damage (see todo buildup_duration: Duration::from_millis(800),
* below) */ recover_duration: Duration::from_millis(200),
base_damage: 130,
}),
secondary_ability: None, secondary_ability: None,
block_ability: None, block_ability: None,
dodge_ability: None, dodge_ability: None,

View File

@ -236,6 +236,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr {
ToolKind::Bow => 0.0, ToolKind::Bow => 0.0,
ToolKind::Dagger => 0.0, ToolKind::Dagger => 0.0,
ToolKind::Debug(_) => 0.0, ToolKind::Debug(_) => 0.0,
ToolKind::Empty => 0.0,
}, },
weapon_y: match ToolKind::Hammer { weapon_y: match ToolKind::Hammer {
ToolKind::Sword(_) => -1.25, ToolKind::Sword(_) => -1.25,
@ -246,6 +247,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr {
ToolKind::Bow => -2.0, ToolKind::Bow => -2.0,
ToolKind::Dagger => -2.0, ToolKind::Dagger => -2.0,
ToolKind::Debug(_) => 0.0, ToolKind::Debug(_) => 0.0,
ToolKind::Empty => 0.0,
}, },
} }
} }

View File

@ -176,6 +176,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr {
ToolKind::Bow => 0.0, ToolKind::Bow => 0.0,
ToolKind::Dagger => 0.0, ToolKind::Dagger => 0.0,
ToolKind::Debug(_) => 0.0, ToolKind::Debug(_) => 0.0,
ToolKind::Empty => 0.0,
}, },
weapon_y: match ToolKind::Hammer { weapon_y: match ToolKind::Hammer {
// TODO: Inventory // TODO: Inventory
@ -187,6 +188,7 @@ impl<'a> From<&'a comp::humanoid::Body> for SkeletonAttr {
ToolKind::Bow => -2.0, ToolKind::Bow => -2.0,
ToolKind::Dagger => -2.0, ToolKind::Dagger => -2.0,
ToolKind::Debug(_) => 0.0, ToolKind::Debug(_) => 0.0,
ToolKind::Empty => 0.0,
}, },
} }
} }

View File

@ -19,6 +19,7 @@ pub enum ItemKey {
Utility(Utility), Utility(Utility),
Consumable(Consumable), Consumable(Consumable),
Ingredient(Ingredient), Ingredient(Ingredient),
Empty,
} }
impl From<&Item> for ItemKey { impl From<&Item> for ItemKey {
fn from(item: &Item) -> Self { fn from(item: &Item) -> Self {

View File

@ -636,6 +636,7 @@ pub fn mesh_main(item_kind: Option<&ItemKind>) -> Mesh<FigurePipeline> {
ToolKind::Bow => ("weapon.bow.simple-bow", Vec3::new(-1.0, -6.0, -2.0)), 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::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::Debug(_) => ("weapon.debug_wand", Vec3::new(-1.5, -9.5, -4.0)),
ToolKind::Empty => return Mesh::new(),
}, },
_ => return Mesh::new(), _ => return Mesh::new(),
}; };