1
0
Fork 0

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)]
pub struct MeleeWeapon {
pub struct Weapon {
pub range: Option<i32>,
pub attribute: WeaponAttribute,
pub damage_n_dice: i32,
pub damage_die_type: i32,

View File

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

View File

@ -3,8 +3,8 @@ use ::specs::prelude::*;
use crate::colors;
use crate::components::{
Attributes, EquipmentSlot, Equipped, HungerClock, HungerState, MeleeWeapon, Name,
NaturalAttackDefense, Pools, Skill, Skills, WantsToMelee, WeaponAttribute, Wearable,
Attributes, EquipmentSlot, Equipped, HungerClock, HungerState, Name, NaturalAttackDefense,
Pools, Skill, Skills, WantsToMelee, Weapon, WeaponAttribute, Wearable,
};
use crate::effects::{add_effect, EffectType, Targets};
use crate::game_log::GameLog;
@ -25,7 +25,7 @@ impl<'a> System<'a> for MeleeCombatSystem {
ReadStorage<'a, Pools>,
WriteExpect<'a, RandomNumberGenerator>,
ReadStorage<'a, Equipped>,
ReadStorage<'a, MeleeWeapon>,
ReadStorage<'a, Weapon>,
ReadStorage<'a, Wearable>,
ReadStorage<'a, NaturalAttackDefense>,
);
@ -65,7 +65,8 @@ impl<'a> System<'a> for MeleeCombatSystem {
let target_name = names.get(wants_melee.target).unwrap();
// 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,
hit_bonus: 0,
damage_n_dice: 1,

View File

@ -534,7 +534,8 @@ pub fn spawn_named_item(
slot: EquipmentSlot::Melee,
});
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,
damage_n_dice: n_dice,
damage_die_type: die_type,

View File

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