Add natural attack types, completing section 5.8

This commit is contained in:
Timothy Warren 2022-01-04 11:29:23 -05:00
parent 2785eb10f1
commit 83647ae28d
3 changed files with 46 additions and 7 deletions

View File

@ -8,7 +8,7 @@ use crate::components::{
use crate::game_log::GameLog;
use crate::gamesystem::skill_bonus;
use crate::particle_system::ParticleBuilder;
use crate::{EquipmentSlot, Position, WeaponAttribute};
use crate::{EquipmentSlot, NaturalAttackDefense, Position, WeaponAttribute};
pub struct MeleeCombatSystem {}
@ -30,6 +30,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
ReadStorage<'a, Equipped>,
ReadStorage<'a, MeleeWeapon>,
ReadStorage<'a, Wearable>,
ReadStorage<'a, NaturalAttackDefense>,
);
fn run(&mut self, data: Self::SystemData) {
@ -49,6 +50,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
equipped_items,
meleeweapons,
wearables,
natural,
) = data;
for (entity, wants_melee, name, attacker_attributes, attacker_skills, attacker_pools) in (
@ -76,6 +78,23 @@ impl<'a> System<'a> for MeleeCombatSystem {
damage_bonus: 0,
};
if let Some(nat) = natural.get(entity) {
if !nat.attacks.is_empty() {
let attack_index = if nat.attacks.len() == 1 {
0
} else {
rng.roll_dice(1, nat.attacks.len() as i32) as usize - 1
};
let attk = &nat.attacks[attack_index];
weapon_info.hit_bonus = attk.hit_bonus;
weapon_info.damage_n_dice = attk.damage_n_dice;
weapon_info.damage_die_type = attk.damage_die_type;
weapon_info.damage_bonus = attk.damage_bonus;
}
}
for (wielded, melee) in (&equipped_items, &meleeweapons).join() {
if wielded.owner == entity && wielded.slot == EquipmentSlot::Melee {
weapon_info = melee.clone();
@ -110,11 +129,10 @@ impl<'a> System<'a> for MeleeCombatSystem {
}
}
// let base_armor_class = match natural.get(wants_melee.target) {
// None => 10,
// Some(nat) = nat.armor_class.unwrap_or(10);
// };
let base_armor_class = 10;
let base_armor_class = match natural.get(wants_melee.target) {
None => 10,
Some(nat) => nat.armor_class.unwrap_or(10),
};
let armor_quickness_bonus = target_attributes.quickness.bonus;
let armor_skill_bonus = skill_bonus(Skill::Defense, &*target_skills);
let armor_item_bonus = armor_item_bonus_f as i32;

View File

@ -18,7 +18,7 @@ pub struct Mob {
pub hp: Option<i32>,
pub mana: Option<i32>,
pub equipped: Option<Vec<String>>,
pub natural: Option<MobNature>,
pub natural: Option<MobNatural>,
}
#[derive(Deserialize, Debug)]

View File

@ -383,6 +383,27 @@ pub fn spawn_named_mob(
dirty: true,
});
if let Some(na) = &mob_template.natural {
let mut nature = NaturalAttackDefense {
armor_class: na.armor_class,
attacks: Vec::new(),
};
if let Some(attacks) = &na.attacks {
for nattack in attacks.iter() {
let (n, d, b) = parse_dice_string(&nattack.damage);
let attack = NaturalAttack {
name: nattack.name.clone(),
hit_bonus: nattack.hit_bonus,
damage_n_dice: n,
damage_die_type: d,
damage_bonus: b,
};
nature.attacks.push(attack);
}
}
eb = eb.with(nature);
}
let new_mob = eb.build();
// Are they weilding anything?