## Summary - Refactors the poison system to separate `Index` (globally unique ID) from `Level` (tier within a family), enabling multiple poison families (Standard, Darkglow, Parasitic) to coexist without collisions - Implements Darkglow and Parasitic poison special effects from Mondain's Legacy: Darkglow boosts damage by 10% when attacker is ranged, Parasitic heals the attacker for damage dealt in melee range - Fixes several bugs: `Register()` crashing on duplicate `Level` values across families, `IncreaseLevel()` crossing family boundaries, `InfectiousStrike` and `NinjaWeapons` stripping poison family via level-based lookups, and `ArchCure`/`CleansingWinds` using raw `Level + 1` instead of `IncreaseLevel()` ## Changes **`Projects/Server/Poison.cs`** — Adds `PoisonFamily` enum and abstract `Family` property. Adds `Index` as unique identifier. Fixes `Register()` to check `Index` uniqueness (not `Level`) and validate the new poison's name (not the existing one's). Fixes `IncreaseLevel()` to use `Index + 1`, naturally respecting family boundaries via Index gaps. Replaces linear name lookup with `Dictionary`-based `PoisonsByName`. **`Projects/UOContent/Misc/Poison.cs`** — Adds `family` parameter to `PoisonImpl`. Implements Darkglow effect (10% damage boost when `From` >1 tile, cliloc 1072850) and Parasitic effect (heals `From` for damage dealt within 1 tile, cliloc 1060203) in `PoisonTimer.OnTick()`. Renames `m_` fields to `_` convention. **`Projects/UOContent/Misc/PoisonKinds.cs`** — New file. Moves poison registration out of `PoisonImpl` into `PoisonKinds.Configure()`. Adds `PoisonFamily` to Darkglow/Parasitic registrations. Provides extension properties (`Lesser`, `Deadly`, `LesserDarkglow`, etc.), `GetPoison(int level)` (standard-only), `GetPoisonByFamilyAndLevel()`, and `IsDarkglow`/`IsParasitic` instance helpers. **`Projects/UOContent/Items/Weapons/Abilities/InfectiousStrike.cs`** — Family-aware poison scaling: Darkglow caps at Deadly (Poisoning/33.3), Parasitic caps at Lethal (Poisoning/25), Standard unchanged. Level bump uses `IncreaseLevel()` with family boundary check. **`Projects/UOContent/Items/Skill Items/Ninjitsu/NinjaWeapons.cs`** — EvilOmen level bump uses `Poison.IncreaseLevel()` instead of `Poison.GetPoison(Level + 1)`. **`Projects/UOContent/Spells/Fourth/ArchCure.cs`** and **`CleansingWindsSpell.cs`** — Replace `poison.Level + 1` with `Poison.IncreaseLevel(poison).Level` for family-safe cure chance calculation. **`Projects/Server/Serialization/SerializationExtensions.cs`** — Serializes/deserializes `Index` instead of `Level`. **`DarkglowPotion.cs`** / **`ParasiticPotion.cs`** — Point to actual Darkglow/Parasitic poisons instead of placeholder `Greater`. **`PotionKeg.cs`** / **`BasePotion.cs`** — Adds Darkglow, Parasitic, Invisibility, and FlintsPungentBrew to `PotionEffect` enum and keg label support. ## Test plan - [ ] `dotnet build` compiles cleanly (verified, 0 warnings 0 errors) - [ ] Verify `PoisonKinds.Configure()` registers all poisons without throwing (Register bug fix) - [ ] Standard poison behavior unchanged — PoisonField, PoisonSpell, SerpentArrow, SavageShaman, TrappableContainer all use `GetPoison(int level)` which now correctly filters to Standard family - [ ] Darkglow: poison tick deals +10% damage when attacker is >1 tile away, sends "Darkglow poison increases your damage!" message - [ ] Parasitic: poison tick heals attacker for damage dealt when within 1 tile, sends heal message - [ ] InfectiousStrike preserves poison family and respects family-specific skill scaling - [ ] EvilOmen + NinjaWeapons level bump stays within poison family - [ ] ArchCure/CleansingWinds cure chance calculations work correctly across all poison families - [ ] Serialization round-trips correctly using Index
357 lines
10 KiB
C#
357 lines
10 KiB
C#
using System;
|
|
using Server.ContextMenus;
|
|
using Server.Mobiles;
|
|
using Server.SkillHandlers;
|
|
using Server.Spells.Chivalry;
|
|
using Server.Spells.Necromancy;
|
|
using Server.Spells.Ninjitsu;
|
|
using Server.Targeting;
|
|
|
|
/*
|
|
* There really was no prettier way to do this, other than the one
|
|
* suggestion to make a rigged baseninjaweapon class that bypasses its
|
|
* own serialization, due to the way these weapons were originaly coded.
|
|
*/
|
|
|
|
namespace Server.Items;
|
|
|
|
public interface INinjaAmmo : IUsesRemaining
|
|
{
|
|
int PoisonCharges { get; set; }
|
|
Poison Poison { get; set; }
|
|
}
|
|
|
|
public interface INinjaWeapon : IUsesRemaining
|
|
{
|
|
int NoFreeHandMessage { get; }
|
|
int EmptyWeaponMessage { get; }
|
|
int RecentlyUsedMessage { get; }
|
|
int FullWeaponMessage { get; }
|
|
int WrongAmmoMessage { get; }
|
|
Type AmmoType { get; }
|
|
int PoisonCharges { get; set; }
|
|
Poison Poison { get; set; }
|
|
int WeaponDamage { get; }
|
|
int WeaponMinRange { get; }
|
|
int WeaponMaxRange { get; }
|
|
|
|
void AttackAnimation(Mobile from, Mobile to);
|
|
}
|
|
|
|
public static class NinjaWeapon
|
|
{
|
|
private const int MaxUses = 10;
|
|
|
|
public static void AttemptShoot(PlayerMobile from, INinjaWeapon weapon)
|
|
{
|
|
if (CanUseWeapon(from, weapon))
|
|
{
|
|
from.BeginTarget(weapon.WeaponMaxRange, false, TargetFlags.Harmful, OnTarget, weapon);
|
|
}
|
|
}
|
|
|
|
private static void Shoot(PlayerMobile from, Mobile target, INinjaWeapon weapon)
|
|
{
|
|
if (from == target || !CanUseWeapon(from, weapon) || !from.CanBeHarmful(target))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (weapon.WeaponMinRange == 0 || !from.InRange(target, weapon.WeaponMinRange))
|
|
{
|
|
from.NinjaWepCooldown = true;
|
|
|
|
from.Direction = from.GetDirectionTo(target);
|
|
|
|
from.RevealingAction();
|
|
|
|
weapon.AttackAnimation(from, target);
|
|
|
|
ConsumeUse(weapon);
|
|
|
|
if (CombatCheck(from, target))
|
|
{
|
|
Timer.StartTimer(TimeSpan.FromSeconds(1.0), () => OnHit(from, target, weapon));
|
|
}
|
|
|
|
Timer.StartTimer(TimeSpan.FromSeconds(2.5), () => from.NinjaWepCooldown = false);
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1063303); // Your target is too close!
|
|
}
|
|
}
|
|
|
|
private static void Unload(Mobile from, INinjaWeapon weapon)
|
|
{
|
|
if (weapon.UsesRemaining > 0)
|
|
{
|
|
var ammo = weapon.AmmoType.CreateInstance<Item>(weapon.UsesRemaining);
|
|
|
|
if (ammo is INinjaAmmo ninaAmmo)
|
|
{
|
|
ninaAmmo.Poison = weapon.Poison;
|
|
ninaAmmo.PoisonCharges = weapon.PoisonCharges;
|
|
}
|
|
|
|
from.AddToBackpack(ammo);
|
|
|
|
weapon.UsesRemaining = 0;
|
|
weapon.PoisonCharges = 0;
|
|
weapon.Poison = null;
|
|
}
|
|
}
|
|
|
|
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 ConsumeUse(INinjaWeapon weapon)
|
|
{
|
|
if (weapon.UsesRemaining > 0)
|
|
{
|
|
weapon.UsesRemaining--;
|
|
|
|
if (weapon.UsesRemaining < 1)
|
|
{
|
|
weapon.PoisonCharges = 0;
|
|
weapon.Poison = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static bool CanUseWeapon(PlayerMobile from, INinjaWeapon weapon)
|
|
{
|
|
if (WeaponIsValid(weapon, from))
|
|
{
|
|
if (weapon.UsesRemaining > 0)
|
|
{
|
|
if (!from.NinjaWepCooldown)
|
|
{
|
|
if (BasePotion.HasFreeHand(from))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
from.SendLocalizedMessage(weapon.NoFreeHandMessage);
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(weapon.RecentlyUsedMessage);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(weapon.EmptyWeaponMessage);
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
private static bool CombatCheck(Mobile attacker, Mobile defender) /* mod'd from baseweapon */
|
|
{
|
|
var defWeapon = defender.Weapon as BaseWeapon;
|
|
|
|
var atkSkill = defender.Skills.Ninjitsu;
|
|
// Skill defSkill = defender.Skills[defWeapon.Skill];
|
|
|
|
var atSkillValue = attacker.Skills.Ninjitsu.Value;
|
|
var defSkillValue = defWeapon?.GetDefendSkillValue(attacker, defender) ?? 0.0;
|
|
|
|
if (defSkillValue <= -20.0)
|
|
{
|
|
defSkillValue = -19.9;
|
|
}
|
|
|
|
double attackValue = AosAttributes.GetValue(attacker, AosAttribute.AttackChance);
|
|
|
|
attackValue += DivineFurySpell.GetAttackBonus(attacker);
|
|
|
|
if (AnimalForm.UnderTransformation(attacker, typeof(GreyWolf)) ||
|
|
AnimalForm.UnderTransformation(attacker, typeof(BakeKitsune)))
|
|
{
|
|
attackValue += 20;
|
|
}
|
|
|
|
if (HitLower.IsUnderAttackEffect(attacker))
|
|
{
|
|
attackValue -= 25;
|
|
}
|
|
|
|
if (attackValue > 45)
|
|
{
|
|
attackValue = 45;
|
|
}
|
|
|
|
attackValue = (atSkillValue + 20.0) * (100 + attackValue);
|
|
|
|
double defenseValue = AosAttributes.GetValue(defender, AosAttribute.DefendChance);
|
|
|
|
defenseValue -= DivineFurySpell.GetDefendMalus(defender);
|
|
|
|
if (HitLower.IsUnderDefenseEffect(defender))
|
|
{
|
|
defenseValue -= 25;
|
|
}
|
|
|
|
var refBonus = 0;
|
|
|
|
if (Block.GetBonus(defender, ref refBonus))
|
|
{
|
|
defenseValue += refBonus;
|
|
}
|
|
|
|
if (Discordance.GetEffect(attacker, ref refBonus))
|
|
{
|
|
defenseValue -= refBonus;
|
|
}
|
|
|
|
if (defenseValue > 45)
|
|
{
|
|
defenseValue = 45;
|
|
}
|
|
|
|
defenseValue = (defSkillValue + 20.0) * (100 + defenseValue);
|
|
|
|
var chance = attackValue / (defenseValue * 2.0);
|
|
|
|
if (chance < 0.02)
|
|
{
|
|
chance = 0.02;
|
|
}
|
|
|
|
return attacker.CheckSkill(atkSkill.SkillName, chance);
|
|
}
|
|
|
|
private static void OnHit(Mobile from, Mobile target, INinjaWeapon weapon)
|
|
{
|
|
if (!from.CanBeHarmful(target))
|
|
{
|
|
return;
|
|
}
|
|
|
|
from.DoHarmful(target);
|
|
|
|
AOS.Damage(target, from, weapon.WeaponDamage, 100, 0, 0, 0, 0);
|
|
|
|
if (weapon.Poison != null && weapon.PoisonCharges > 0)
|
|
{
|
|
if (EvilOmenSpell.EndEffect(target))
|
|
{
|
|
target.ApplyPoison(from, Poison.IncreaseLevel(weapon.Poison));
|
|
}
|
|
else
|
|
{
|
|
target.ApplyPoison(from, weapon.Poison);
|
|
}
|
|
|
|
weapon.PoisonCharges--;
|
|
|
|
if (weapon.PoisonCharges < 1)
|
|
{
|
|
weapon.Poison = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private static void OnTarget(Mobile from, object targeted, INinjaWeapon weapon)
|
|
{
|
|
if (from is PlayerMobile player && WeaponIsValid(weapon, from))
|
|
{
|
|
if (targeted is Mobile mobile)
|
|
{
|
|
Shoot(player, mobile, weapon);
|
|
}
|
|
else if (targeted.GetType() == weapon.AmmoType)
|
|
{
|
|
Reload(player, weapon, (INinjaAmmo)targeted);
|
|
}
|
|
else
|
|
{
|
|
player.SendLocalizedMessage(weapon.WrongAmmoMessage);
|
|
}
|
|
}
|
|
}
|
|
|
|
private static bool WeaponIsValid(INinjaWeapon weapon, Mobile from) =>
|
|
weapon is Item item && !item.Deleted && item.RootParent == from;
|
|
|
|
public class LoadEntry : ContextMenuEntry
|
|
{
|
|
public LoadEntry(int entry) : base(entry, 0)
|
|
{
|
|
}
|
|
|
|
public override void OnClick(Mobile from, IEntity target)
|
|
{
|
|
if (target is INinjaWeapon weapon && WeaponIsValid(weapon, from))
|
|
{
|
|
from.BeginTarget(10, false, TargetFlags.Harmful, OnTarget, weapon);
|
|
}
|
|
}
|
|
}
|
|
|
|
public class UnloadEntry : ContextMenuEntry
|
|
{
|
|
public UnloadEntry(int entry, bool enabled) : base(entry, 0) => Enabled = enabled;
|
|
|
|
public override void OnClick(Mobile from, IEntity target)
|
|
{
|
|
if (target is INinjaWeapon weapon && WeaponIsValid(weapon, from))
|
|
{
|
|
Unload(from, weapon);
|
|
}
|
|
}
|
|
}
|
|
}
|