Skip to content

Commit

Permalink
feat: Simplifies honorable execution
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Jan 26, 2025
1 parent d5160bd commit d7c8cda
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 87 deletions.
18 changes: 7 additions & 11 deletions Projects/UOContent/Items/Aquarium/Aquarium.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,25 +551,21 @@ public int FoodNumber() =>

public virtual void KillFish(int amount)
{
var toKill = new List<BaseFish>();
using var toKill = PooledRefList<Item>.Create();

for (var i = 0; i < Items.Count; i++)
{
if (Items[i] is BaseFish)
if (Items[i] is BaseFish { Dead: false } fish)
{
var fish = (BaseFish)Items[i];

if (!fish.Dead)
{
toKill.Add(fish);
}
toKill.Add(fish);
}
}

while (amount > 0 && toKill.Count > 0)
toKill.Shuffle();

for (var i = 0; i < amount; i++)
{
var kill = toKill.TakeRandomElement();
kill.Kill();
(toKill[i] as BaseFish)!.Kill();

amount -= 1;
LiveCreatures = Math.Max(LiveCreatures - 1, 0);
Expand Down
101 changes: 25 additions & 76 deletions Projects/UOContent/Spells/Bushido/HonorableExecution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void OnHit(Mobile attacker, Mobile defender, int damage)

var swingBonus = Math.Max(1, (int)(bushido / 720.0));

timer = new HonorableExecutionTimer(attacker, swingBonus);
timer = new HonorableExecutionTimer(TimeSpan.FromSeconds(20.0), attacker, swingBonus: swingBonus);

(attacker as PlayerMobile)?.AddBuff(
new BuffInfo(
Expand All @@ -56,23 +56,20 @@ public override void OnHit(Mobile attacker, Mobile defender, int damage)
}
else
{
var mods = new List<object>
{
new ResistanceMod(ResistanceType.Physical, "PhysicalResistHonorableExecution", -40),
new ResistanceMod(ResistanceType.Fire, "FireResistHonorableExecution", -40),
new ResistanceMod(ResistanceType.Cold, "ColdResistHonorableExecution", -40),
new ResistanceMod(ResistanceType.Poison, "PoisonResistHonorableExecution", -40),
new ResistanceMod(ResistanceType.Energy, "EnergyResistHonorableExecution", -40)
};
attacker.AddResistanceMod(new ResistanceMod(ResistanceType.Physical, "PhysicalResistHonorableExecution", -40));
attacker.AddResistanceMod(new ResistanceMod(ResistanceType.Fire, "FireResistHonorableExecution", -40));
attacker.AddResistanceMod(new ResistanceMod(ResistanceType.Cold, "ColdResistHonorableExecution", -40));
attacker.AddResistanceMod(new ResistanceMod(ResistanceType.Poison, "PoisonResistHonorableExecution", -40));
attacker.AddResistanceMod(new ResistanceMod(ResistanceType.Energy, "EnergyResistHonorableExecution", -40));

var resSpells = attacker.Skills.MagicResist.Value;

if (resSpells > 0.0)
{
mods.Add(new DefaultSkillMod(SkillName.MagicResist, "MagicResistHonorableExecution", true, -resSpells));
attacker.AddSkillMod(new DefaultSkillMod(SkillName.MagicResist, "MagicResistHonorableExecution", true, -resSpells));
}

timer = new HonorableExecutionTimer(attacker, mods);
timer = new HonorableExecutionTimer(TimeSpan.FromSeconds(7.0), attacker, penalty: true);

if (Core.HS)
{
Expand Down Expand Up @@ -101,9 +98,9 @@ public override void OnHit(Mobile attacker, Mobile defender, int damage)
CheckGain(attacker);
}

public static int GetSwingBonus(Mobile target) => _table.TryGetValue(target, out var info) ? info.m_SwingBonus : 0;
public static int GetSwingBonus(Mobile target) => _table.TryGetValue(target, out var info) ? info._swingBonus : 0;

public static bool IsUnderPenalty(Mobile target) => _table.TryGetValue(target, out var info) && info.m_Penalty;
public static bool IsUnderPenalty(Mobile target) => _table.TryGetValue(target, out var info) && info._penalty;

public static void RemovePenalty(Mobile target)
{
Expand All @@ -115,81 +112,33 @@ public static void RemovePenalty(Mobile target)

private class HonorableExecutionTimer : Timer
{
public readonly Mobile m_Mobile;
public readonly List<object> m_Mods;
public readonly bool m_Penalty;
public readonly int m_SwingBonus;

public HonorableExecutionTimer(Mobile from, List<object> mods) : this(TimeSpan.FromSeconds(7.0), from, 0, mods, mods != null)
{
}
public readonly Mobile _from;
public readonly bool _penalty;
public readonly int _swingBonus;

public HonorableExecutionTimer(Mobile from, int swingBonus) : this(TimeSpan.FromSeconds(20.0), from, swingBonus)
public HonorableExecutionTimer(TimeSpan duration, Mobile from, int swingBonus = 0, bool penalty = false) : base(duration)
{
}

public HonorableExecutionTimer(
TimeSpan duration, Mobile from, int swingBonus, List<object> mods = null, bool penalty = false
) : base(duration)
{
m_Mobile = from;
m_SwingBonus = swingBonus;
m_Mods = mods;
m_Penalty = penalty;

Apply();
_from = from;
_swingBonus = swingBonus;
_penalty = penalty;
}

protected override void OnTick()
{
m_Mobile?.Delta(MobileDelta.WeaponDamage);
RemovePenalty(m_Mobile);
}

public void Apply()
{
if (m_Mods == null)
{
return;
}

for (var i = 0; i < m_Mods.Count; ++i)
{
var mod = m_Mods[i];

if (mod is ResistanceMod resistanceMod)
{
m_Mobile.AddResistanceMod(resistanceMod);
}
else if (mod is SkillMod skillMod)
{
m_Mobile.AddSkillMod(skillMod);
}
}
_from?.Delta(MobileDelta.WeaponDamage);
RemovePenalty(_from);
}

public void Clear()
{
Stop();

if (m_Mods == null)
{
return;
}

for (var i = 0; i < m_Mods.Count; ++i)
{
var mod = m_Mods[i];

if (mod is ResistanceMod resistanceMod)
{
m_Mobile?.RemoveResistanceMod(resistanceMod);
}
else if (mod is SkillMod skillMod)
{
m_Mobile?.RemoveSkillMod(skillMod);
}
}
_from.RemoveResistanceMod("PhysicalResistHonorableExecution");
_from.RemoveResistanceMod("FireResistHonorableExecution");
_from.RemoveResistanceMod("ColdResistHonorableExecution");
_from.RemoveResistanceMod("PoisonResistHonorableExecution");
_from.RemoveResistanceMod("EnergyResistHonorableExecution");
_from.RemoveSkillMod("MagicResistHonorableExecution");
}
}
}

0 comments on commit d7c8cda

Please sign in to comment.