using UnityEngine;
///
/// Describes a weapon's attack characteristics.
/// All combat goes through this so we can easily add more weapon types later.
///
[System.Serializable]
public class Weapon
{
public string Name;
/// Number of dice to roll for damage.
public int DamageDiceCount;
/// Faces on each damage die (e.g. 4 for d4).
public int DamageDiceFaces;
/// Flat bonus added on top of the dice roll.
public int DamageBonus;
///
/// Base hit-chance (0-1). Multiplied by attacker advantage when attacking.
/// Default fists: 0.65 base. Can be tuned per weapon in the future.
///
public float BaseHitChance;
/// Melee reach in world-units.
public float MeleeRange;
public Weapon(string name, int diceCount, int diceFaces, int damageBonus = 0,
float baseHitChance = 0.65f, float meleeRange = 1.5f)
{
Name = name;
DamageDiceCount = diceCount;
DamageDiceFaces = diceFaces;
DamageBonus = damageBonus;
BaseHitChance = baseHitChance;
MeleeRange = meleeRange;
}
/// Roll the damage dice and return the result.
public int RollDamage()
{
int total = DamageBonus;
for (int i = 0; i < DamageDiceCount; i++)
total += Random.Range(1, DamageDiceFaces + 1);
return Mathf.Max(1, total); // Always deal at least 1 damage
}
///
/// Attempt to hit a target.
/// is a 0-1 multiplier on top of BaseHitChance.
/// 1.0 = full chance, 0.5 = halved, 1.5 = boosted (capped at 0.95 to never guarantee a hit).
///
public bool TryHit(float attackerAdvantage = 1f)
{
float chance = Mathf.Clamp(BaseHitChance * attackerAdvantage, 0.05f, 0.95f);
return Random.value <= chance;
}
// ---- Preset factories ----
/// Default unarmed fists: 1d4 damage, 65 % base hit chance.
public static Weapon Fists() => new Weapon("Fists", 1, 4, 0, 0.65f, 1.5f);
}