Refactor MeleeWeapon to handle both melee and ranged weapons

This commit is contained in:
Timothy Warren 2022-01-31 09:55:56 -05:00
parent 92316bde1b
commit b514eec669
5 changed files with 12 additions and 9 deletions

View File

@ -150,7 +150,8 @@ pub struct Equipped {
} }
#[derive(Component, ConvertSaveload, Clone)] #[derive(Component, ConvertSaveload, Clone)]
pub struct MeleeWeapon { pub struct Weapon {
pub range: Option<i32>,
pub attribute: WeaponAttribute, pub attribute: WeaponAttribute,
pub damage_n_dice: i32, pub damage_n_dice: i32,
pub damage_die_type: i32, pub damage_die_type: i32,

View File

@ -115,7 +115,7 @@ fn init_state() -> State {
LootTable, LootTable,
MagicItem, MagicItem,
MagicMapper, MagicMapper,
MeleeWeapon, Weapon,
MoveMode, MoveMode,
MyTurn, MyTurn,
Name, Name,

View File

@ -3,8 +3,8 @@ use ::specs::prelude::*;
use crate::colors; use crate::colors;
use crate::components::{ use crate::components::{
Attributes, EquipmentSlot, Equipped, HungerClock, HungerState, MeleeWeapon, Name, Attributes, EquipmentSlot, Equipped, HungerClock, HungerState, Name, NaturalAttackDefense,
NaturalAttackDefense, Pools, Skill, Skills, WantsToMelee, WeaponAttribute, Wearable, Pools, Skill, Skills, WantsToMelee, Weapon, WeaponAttribute, Wearable,
}; };
use crate::effects::{add_effect, EffectType, Targets}; use crate::effects::{add_effect, EffectType, Targets};
use crate::game_log::GameLog; use crate::game_log::GameLog;
@ -25,7 +25,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
ReadStorage<'a, Pools>, ReadStorage<'a, Pools>,
WriteExpect<'a, RandomNumberGenerator>, WriteExpect<'a, RandomNumberGenerator>,
ReadStorage<'a, Equipped>, ReadStorage<'a, Equipped>,
ReadStorage<'a, MeleeWeapon>, ReadStorage<'a, Weapon>,
ReadStorage<'a, Wearable>, ReadStorage<'a, Wearable>,
ReadStorage<'a, NaturalAttackDefense>, ReadStorage<'a, NaturalAttackDefense>,
); );
@ -65,7 +65,8 @@ impl<'a> System<'a> for MeleeCombatSystem {
let target_name = names.get(wants_melee.target).unwrap(); let target_name = names.get(wants_melee.target).unwrap();
// Define the basic unarmed attack -- overridden by wielding check below if a weapon is equipped // Define the basic unarmed attack -- overridden by wielding check below if a weapon is equipped
let mut weapon_info = MeleeWeapon { let mut weapon_info = Weapon {
range: None,
attribute: WeaponAttribute::Might, attribute: WeaponAttribute::Might,
hit_bonus: 0, hit_bonus: 0,
damage_n_dice: 1, damage_n_dice: 1,

View File

@ -534,7 +534,8 @@ pub fn spawn_named_item(
slot: EquipmentSlot::Melee, slot: EquipmentSlot::Melee,
}); });
let (n_dice, die_type, bonus) = parse_dice_string(&weapon.base_damage); let (n_dice, die_type, bonus) = parse_dice_string(&weapon.base_damage);
let mut wpn = MeleeWeapon { let mut wpn = Weapon {
range: None,
attribute: WeaponAttribute::Might, attribute: WeaponAttribute::Might,
damage_n_dice: n_dice, damage_n_dice: n_dice,
damage_die_type: die_type, damage_die_type: die_type,

View File

@ -94,7 +94,7 @@ pub fn save_game(ecs: &mut World) {
LootTable, LootTable,
MagicItem, MagicItem,
MagicMapper, MagicMapper,
MeleeWeapon, Weapon,
MoveMode, MoveMode,
MyTurn, MyTurn,
Name, Name,
@ -228,7 +228,7 @@ pub fn load_game(ecs: &mut World) {
LootTable, LootTable,
MagicItem, MagicItem,
MagicMapper, MagicMapper,
MeleeWeapon, Weapon,
MoveMode, MoveMode,
MyTurn, MyTurn,
Name, Name,