From 0456d3cbed023b8e8994b97233113176d0a180dc Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sun, 22 Mar 2020 16:25:47 +0100 Subject: [PATCH] Better staff M1, random +1 damage, better attackrange,angle impl --- common/src/comp/ability.rs | 8 +++++++- common/src/comp/inventory/item.rs | 30 +++++++++++++++--------------- common/src/states/basic_melee.rs | 14 ++++++++++++-- common/src/states/climb.rs | 2 +- common/src/states/dash_melee.rs | 1 + common/src/sys/combat.rs | 18 +++++++++++++++--- server/src/sys/terrain.rs | 13 +++++++++---- 7 files changed, 60 insertions(+), 26 deletions(-) diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index d2f0a56272..cd3c489900 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -13,6 +13,8 @@ pub enum CharacterAbility { buildup_duration: Duration, recover_duration: Duration, base_damage: u32, + range: f32, + max_angle: f32, }, BasicRanged { recover_duration: Duration, @@ -95,11 +97,15 @@ impl From<&CharacterAbility> for CharacterState { buildup_duration, recover_duration, base_damage, + range, + max_angle, } => CharacterState::BasicMelee(basic_melee::Data { exhausted: false, buildup_duration: *buildup_duration, recover_duration: *recover_duration, base_damage: *base_damage, + range: *range, + max_angle: *max_angle, }), CharacterAbility::BasicRanged { recover_duration, @@ -129,7 +135,7 @@ impl From<&CharacterAbility> for CharacterState { }), CharacterAbility::BasicBlock => CharacterState::BasicBlock, CharacterAbility::Roll => CharacterState::Roll(roll::Data { - remaining_duration: Duration::from_millis(600), + remaining_duration: Duration::from_millis(300), }), CharacterAbility::TimedCombo { buildup_duration, diff --git a/common/src/comp/inventory/item.rs b/common/src/comp/inventory/item.rs index 117a501845..3b95c04e6f 100644 --- a/common/src/comp/inventory/item.rs +++ b/common/src/comp/inventory/item.rs @@ -68,28 +68,24 @@ impl ToolData { use ToolKind::*; match self.kind { - Sword(_) => vec![ - // BasicMelee { - // buildup_duration: Duration::from_millis(100), - // recover_duration: Duration::from_millis(500), - // base_damage: 6, - // }, - TripleStrike { base_damage: 7 }, - DashMelee { - buildup_duration: Duration::from_millis(500), - recover_duration: Duration::from_millis(500), - base_damage: 20, - }, - ], + Sword(_) => vec![TripleStrike { base_damage: 7 }, DashMelee { + buildup_duration: Duration::from_millis(500), + recover_duration: Duration::from_millis(500), + base_damage: 20, + }], Axe(_) => vec![BasicMelee { buildup_duration: Duration::from_millis(700), recover_duration: Duration::from_millis(100), base_damage: 8, + range: 3.5, + max_angle: 30.0, }], Hammer(_) => vec![BasicMelee { buildup_duration: Duration::from_millis(700), recover_duration: Duration::from_millis(300), base_damage: 10, + range: 3.5, + max_angle: 60.0, }], Bow(_) => vec![BasicRanged { projectile: Projectile { @@ -113,12 +109,16 @@ impl ToolData { buildup_duration: Duration::from_millis(100), recover_duration: Duration::from_millis(400), base_damage: 5, + range: 3.5, + max_angle: 60.0, }], Staff(_) => vec![ BasicMelee { - buildup_duration: Duration::from_millis(400), + buildup_duration: Duration::from_millis(0), recover_duration: Duration::from_millis(300), - base_damage: 7, + base_damage: 3, + range: 10.0, + max_angle: 45.0, }, BasicRanged { projectile: Projectile { diff --git a/common/src/states/basic_melee.rs b/common/src/states/basic_melee.rs index e006a6b2da..01778be4f4 100644 --- a/common/src/states/basic_melee.rs +++ b/common/src/states/basic_melee.rs @@ -5,7 +5,7 @@ use crate::{ }; use std::time::Duration; -#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize, Eq, Hash)] +#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)] pub struct Data { /// How long until state should deal damage pub buildup_duration: Duration, @@ -13,6 +13,10 @@ pub struct Data { pub recover_duration: Duration, /// Base damage pub base_damage: u32, + /// Max range + pub range: f32, + /// Max angle (45.0 will give you a 90.0 angle window) + pub max_angle: f32, /// Whether the attack can deal more damage pub exhausted: bool, } @@ -32,13 +36,15 @@ impl CharacterBehavior for Data { .unwrap_or_default(), recover_duration: self.recover_duration, base_damage: self.base_damage, + range: self.range, + max_angle: self.max_angle, exhausted: false, }); } else if !self.exhausted { // Hit attempt data.updater.insert(data.entity, Attacking { base_damage: self.base_damage, - max_angle: 75_f32.to_radians(), + max_angle: self.max_angle.to_radians(), applied: false, hit_count: 0, }); @@ -47,6 +53,8 @@ impl CharacterBehavior for Data { buildup_duration: self.buildup_duration, recover_duration: self.recover_duration, base_damage: self.base_damage, + range: self.range, + max_angle: self.max_angle, exhausted: true, }); } else if self.recover_duration != Duration::default() { @@ -58,6 +66,8 @@ impl CharacterBehavior for Data { .checked_sub(Duration::from_secs_f32(data.dt.0)) .unwrap_or_default(), base_damage: self.base_damage, + range: self.range, + max_angle: self.max_angle, exhausted: true, }); } else { diff --git a/common/src/states/climb.rs b/common/src/states/climb.rs index c98a26dbfc..c14326f7d4 100644 --- a/common/src/states/climb.rs +++ b/common/src/states/climb.rs @@ -22,7 +22,7 @@ impl CharacterBehavior for Data { fn behavior(&self, data: &JoinData) -> StateUpdate { let mut update = StateUpdate::from(data); - if let Err(_) = update.energy.try_change_by(-5, EnergySource::Climb) { + if let Err(_) = update.energy.try_change_by(-8, EnergySource::Climb) { update.character = CharacterState::Idle {}; } diff --git a/common/src/states/dash_melee.rs b/common/src/states/dash_melee.rs index 2fbc2016e1..22223a66fa 100644 --- a/common/src/states/dash_melee.rs +++ b/common/src/states/dash_melee.rs @@ -27,6 +27,7 @@ impl CharacterBehavior for Data { if self.initialize { update.vel.0 = data.inputs.look_dir * 20.0; + update.ori.0 = data.vel.0.normalized(); } if self.buildup_duration != Duration::default() && data.physics.touch_entity.is_none() { diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index dab3766b5a..18bb3eb9fd 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -1,7 +1,7 @@ use crate::{ comp::{ - Attacking, Body, CharacterState, Controller, HealthChange, HealthSource, Ori, Pos, Scale, - Stats, + Agent, Attacking, Body, CharacterState, Controller, HealthChange, HealthSource, Ori, Pos, + Scale, Stats, }, event::{EventBus, ServerEvent}, sync::Uid, @@ -25,6 +25,7 @@ impl<'a> System<'a> for Sys { ReadStorage<'a, Pos>, ReadStorage<'a, Ori>, ReadStorage<'a, Scale>, + ReadStorage<'a, Agent>, ReadStorage<'a, Controller>, ReadStorage<'a, Body>, ReadStorage<'a, Stats>, @@ -41,6 +42,7 @@ impl<'a> System<'a> for Sys { positions, orientations, scales, + agents, controllers, bodies, stats, @@ -50,12 +52,13 @@ impl<'a> System<'a> for Sys { ) { let mut server_emitter = server_bus.emitter(); // Attacks - for (entity, uid, pos, ori, scale_maybe, _, _attacker_stats, attack) in ( + for (entity, uid, pos, ori, scale_maybe, agent_maybe, _, _attacker_stats, attack) in ( &entities, &uids, &positions, &orientations, scales.maybe(), + agents.maybe(), &controllers, &stats, &mut attacking_storage, @@ -100,6 +103,15 @@ impl<'a> System<'a> for Sys { // Weapon gives base damage let mut dmg = attack.base_damage; + // NPCs do less damage: + if agent_maybe.is_some() { + dmg = (dmg / 2).max(1); + } + + if rand::random() { + dmg += 1; + } + // Block if character_b.is_block() && ori_b.0.angle_between(pos.0 - pos_b.0) < BLOCK_ANGLE.to_radians() / 2.0 diff --git a/server/src/sys/terrain.rs b/server/src/sys/terrain.rs index efe6265b93..557e9549c6 100644 --- a/server/src/sys/terrain.rs +++ b/server/src/sys/terrain.rs @@ -198,16 +198,19 @@ impl<'a> System<'a> for Sys { item, primary_ability: ability_drain.next(), secondary_ability: ability_drain.next(), - block_ability: Some(comp::CharacterAbility::BasicBlock), + block_ability: None, dodge_ability: Some(comp::CharacterAbility::Roll), }) } else { Some(ItemConfig { + // We need the empty item so npcs can attack item: Item::empty(), primary_ability: Some(CharacterAbility::BasicMelee { - buildup_duration: Duration::from_millis(50), - recover_duration: Duration::from_millis(50), - base_damage: 1, + buildup_duration: Duration::from_millis(0), + recover_duration: Duration::from_millis(300), + base_damage: 2, + range: 3.5, + max_angle: 60.0, }), secondary_ability: None, block_ability: None, @@ -301,6 +304,8 @@ impl<'a> System<'a> for Sys { buildup_duration: Duration::from_millis(800), recover_duration: Duration::from_millis(200), base_damage: 13, + range: 3.5, + max_angle: 60.0, }), secondary_ability: None, block_ability: None,