private static void Reload(PlayerMobile from, INinjaWeapon weapon, INinjaAmmo ammo) { if (weapon.UsesRemaining < MaxUses) { var need = Math.Min(MaxUses - weapon.UsesRemaining, ammo.UsesRemaining); if (need > 0) { if (weapon.Poison != null && (ammo.Poison == null || weapon.Poison.Level > ammo.Poison.Level)) { from.SendLocalizedMessage(1070767); // Loaded projectile is stronger, unload it first } else { if (weapon.UsesRemaining > 0) { if (weapon.Poison == null && ammo.Poison != null || weapon.Poison != null && ammo.Poison != null && weapon.Poison.Level != ammo.Poison.Level) { Unload(from, weapon); need = Math.Min(MaxUses, ammo.UsesRemaining); } } var poisonneeded = Math.Min(MaxUses - weapon.PoisonCharges, ammo.PoisonCharges); weapon.UsesRemaining += need; weapon.PoisonCharges += poisonneeded; if (weapon.PoisonCharges > 0) { weapon.Poison = ammo.Poison; } ammo.PoisonCharges -= poisonneeded; ammo.UsesRemaining -= need; if (ammo.UsesRemaining < 1) { ((Item)ammo).Delete(); } else if (ammo.PoisonCharges < 1) { ammo.Poison = null; } } } // "else" here would mean they targeted "ammo" with 0 uses. undefined behavior. } else { from.SendLocalizedMessage(weapon.FullWeaponMessage); } }
private static void Unload(Mobile from, INinjaWeapon weapon) { if (weapon.UsesRemaining > 0) { INinjaAmmo ammo = Activator.CreateInstance(weapon.AmmoType, new object[] { weapon.UsesRemaining }) as INinjaAmmo; ammo.Poison = weapon.Poison; ammo.PoisonCharges = weapon.PoisonCharges; from.AddToBackpack((Item)ammo); weapon.UsesRemaining = 0; weapon.PoisonCharges = 0; weapon.Poison = null; } }
private static void Reload(PlayerMobile from, INinjaWeapon weapon, INinjaAmmo ammo) { if (weapon.UsesRemaining < MaxUses) { int need = Math.Min((MaxUses - weapon.UsesRemaining), ammo.UsesRemaining); if (need > 0) { if (weapon.Poison != null && (ammo.Poison == null || weapon.Poison.Level > ammo.Poison.Level)) { from.SendLocalizedMessage(1070767); // Loaded projectile is stronger, unload it first } else { if (weapon.UsesRemaining > 0) { if ((weapon.Poison == null && ammo.Poison != null) || ((weapon.Poison != null && ammo.Poison != null) && weapon.Poison.Level != ammo.Poison.Level)) { Unload(from, weapon); need = Math.Min(MaxUses, ammo.UsesRemaining); } } int poisonneeded = Math.Min((MaxUses - weapon.PoisonCharges), ammo.PoisonCharges); weapon.UsesRemaining += need; weapon.PoisonCharges += poisonneeded; if (weapon.PoisonCharges > 0) { weapon.Poison = ammo.Poison; } ammo.PoisonCharges -= poisonneeded; ammo.UsesRemaining -= need; if (ammo.UsesRemaining < 1) { ((Item)ammo).Delete(); } else if (ammo.PoisonCharges < 1) { ammo.Poison = null; } } }// "else" here would mean they targeted "ammo" with 0 uses. undefined behavior. } else { from.SendLocalizedMessage(weapon.FullWeaponMessage); } }