Skip to content

Commit

Permalink
fix: Fixes buffs don't start/stop properly. Streamlines constructor a…
Browse files Browse the repository at this point in the history
…nd Add/Remove buffs. (#2082)
  • Loading branch information
mark1145 authored Jan 25, 2025
1 parent c8f13b2 commit d5160bd
Show file tree
Hide file tree
Showing 50 changed files with 651 additions and 616 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Server;
using Server.Engines.BuffIcons;
using Server.Network;
using Server.Tests;
using Server.Tests.Network;
Expand All @@ -14,29 +15,29 @@ public class BuffIconPacketTests
[InlineData(0x2048u, BuffIcon.Disguised, 500102, 300203, null, 9000)]
public void TestAddBuffIcon(uint mob, BuffIcon iconID, int titleCliloc, int secondaryCliloc, string args, int ts)
{
var timeSpan = new TimeSpan(ts);
var expected = new AddBuffPacket(
(Serial)mob, iconID, titleCliloc, secondaryCliloc, args, timeSpan
).Compile();
var timeSpan = new TimeSpan(ts);
var expected = new AddBuffPacket(
(Serial)mob, iconID, titleCliloc, secondaryCliloc, args, timeSpan
).Compile();

var ns = PacketTestUtilities.CreateTestNetState();
ns.SendAddBuffPacket((Serial)mob, iconID, titleCliloc, secondaryCliloc, args, (int)timeSpan.TotalMilliseconds);
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendAddBuffPacket((Serial)mob, iconID, titleCliloc, secondaryCliloc, args, (int)timeSpan.TotalMilliseconds);

var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
}

[Fact]
public void TestRemoveBuffIcon()
{
Serial m = (Serial)0x1024;
var buffIcon = BuffIcon.Disguised;
var expected = new RemoveBuffPacket(m, buffIcon).Compile();
Serial m = (Serial)0x1024;
var buffIcon = BuffIcon.Disguised;
var expected = new RemoveBuffPacket(m, buffIcon).Compile();

var ns = PacketTestUtilities.CreateTestNetState();
ns.SendRemoveBuffPacket(m, buffIcon);
var ns = PacketTestUtilities.CreateTestNetState();
ns.SendRemoveBuffPacket(m, buffIcon);

var result = ns.SendPipe.Reader.AvailableToRead();
AssertThat.Equal(result, expected);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Server.Engines.BuffIcons;

namespace Server.Network

Check notice on line 4 in Projects/UOContent.Tests/Tests/Network/Packets/BuffIconPackets.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Namespace does not correspond to file location

Namespace does not correspond to file location, must be: 'UOContent.Tests.Tests.Network.Packets'
{
Expand All @@ -11,9 +12,7 @@ public AddBuffPacket(Serial m, BuffInfo info)
info.TitleCliloc,
info.SecondaryCliloc,
info.Args,
info.TimeStart != 0 ?
TimeSpan.FromMilliseconds(info.TimeStart + (long)info.TimeLength.TotalMilliseconds - Core.TickCount) :
TimeSpan.Zero
info.Duration
)
{
}
Expand Down
192 changes: 192 additions & 0 deletions Projects/UOContent/Engines/BuffIcons/BuffIcon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
namespace Server.Engines.BuffIcons;

public enum BuffIcon : short
{
DismountPrevention = 0x3E9,
NoRearm = 0x3EA,
//Currently, no 0x3EB or 0x3EC
NightSight = 0x3ED, //*
DeathStrike,
EvilOmen,
HonoredDebuff,
AchievePerfection,
DivineFury, //*
EnemyOfOne, //*
HidingAndOrStealth, //*
ActiveMeditation, //*
BloodOathCaster, //*
BloodOathCurse, //*
CorpseSkin, //*
Mindrot, //*
PainSpike, //*
Strangle,
GiftOfRenewal, //*
AttuneWeapon, //*
Thunderstorm, //*
EssenceOfWind, //*
EtherealVoyage, //*
GiftOfLife, //*
ArcaneEmpowerment, //*
MortalStrike,
ReactiveArmor, //*
Protection, //*
ArchProtection,
MagicReflection, //*
Incognito, //*
Disguised,
AnimalForm,
Polymorph,
Invisibility, //*
Paralyze, //*
Poison,
Bleed,
Clumsy, //*
FeebleMind, //*
Weaken, //*
Curse, //*
MassCurse,
Agility, //*
Cunning, //*
Strength, //*
Bless, //*
Sleep,
StoneForm,
SpellPlague,
Berserk,
MassSleep,
Fly,
Inspire,
Invigorate,
Resilience,
Perseverance,
TribulationTarget,
DespairTarget,
FishPie = 0x426,
HitLowerAttack,
HitLowerDefense,
DualWield,
Block,
DefenseMastery,
DespairCaster,
Healing,
SpellFocusingBuff,
SpellFocusingDebuff,
RageFocusingDebuff,
RageFocusingBuff,
Warding,
TribulationCaster,
ForceArrow,
Disarm,
Surge,
Feint,
TalonStrike,
PsychicAttack,
ConsecrateWeapon,
GrapesOfWrath,
EnemyOfOneDebuff,
HorrificBeast,
LichForm,
VampiricEmbrace,
CurseWeapon,
ReaperForm,
ImmolatingWeapon,
Enchant,
HonorableExecution,
Confidence,
Evasion,
CounterAttack,
LightningStrike,
MomentumStrike,
OrangePetals,
RoseOfTrinsic,
PoisonImmunity,
Veterinary,
Perfection,
Honored,
ManaPhase,
FanDancerFanFire,
Rage,
Webbing,
MedusaStone,
TrueFear,
AuraOfNausea,
HowlOfCacophony,
GazeDespair,
HiryuPhysicalResistance,
RuneBeetleCorruption,
BloodwormAnemia,
RotwormBloodDisease,
SkillUseDelay,
FactionStatLoss,
HeatOfBattleStatus,
CriminalStatus,
ArmorPierce,
SplinteringEffect,
SwingSpeedDebuff,
WraithForm,
CityTradeDeal = 0x466,
HumilityDebuff = 0x467,
Spirituality,
Humility,
// Skill Masteries
Rampage,
Stagger, // Debuff
Toughness,
Thrust,
Pierce, // Debuff
PlayingTheOdds,
FocusedEye,
Onslaught, // Debuff
ElementalFury,
ElementalFuryDebuff, // Debuff
CalledShot,
Knockout,
SavingThrow,
Conduit,
EtherealBurst,
MysticWeapon,
ManaShield,
AnticipateHit,
Warcry,
Shadow,
WhiteTigerForm,
Bodyguard,
HeightenedSenses,
Tolerance,
DeathRay,
DeathRayDebuff,
Intuition,
EnchantedSummoning,
ShieldBash,
Whispering,
CombatTraining,
InjectedStrikeDebuff,
InjectedStrike,
UnknownTomato,
PlayingTheOddsDebuff,
DragonTurtleDebuff,
Boarding,
Potency,
ThrustDebuff,
FistsOfFury, // 1169
BarrabHemolymphConcentrate,
JukariBurnPoiltice,
KurakAmbushersEssence,
BarakoDraftOfMight,
UraliTranceTonic,
SakkhraProphylaxis, // 1175
Sparks,
Swarm,
BoneBreaker,
Unknown2,
SwarmImmune,
BoneBreakerImmune,
UnknownGoblin,
UnknownRedDrop,
UnknownStar,
FeintDebuff,
CaddelliteInfused,
PotionGloriousFortune,
MysticalPolymorphTotem,
UnknownDebuff,
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Buffers;
using Server.Network;

namespace Server.Network;
namespace Server.Engines.BuffIcons;

public static class BuffIconPackets
{
Expand Down
66 changes: 66 additions & 0 deletions Projects/UOContent/Engines/BuffIcons/BuffInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using ModernUO.CodeGeneratedEvents;
using Server.Mobiles;

namespace Server.Engines.BuffIcons;

public class BuffInfo
{
private TimerExecutionToken _timerToken;

public BuffInfo(
BuffIcon iconID, int titleCliloc, TimeSpan duration = default, TextDefinition args = null,
bool retainThroughDeath = false
) : this(iconID, titleCliloc, titleCliloc + 1, duration, args, retainThroughDeath)
{
}

public BuffInfo(
BuffIcon iconID, int titleCliloc, int secondaryCliloc, TimeSpan duration = default, TextDefinition args = null,
bool retainThroughDeath = false
)
{
ID = iconID;
TitleCliloc = titleCliloc;
SecondaryCliloc = secondaryCliloc;
Duration = duration;
Args = args;
RetainThroughDeath = retainThroughDeath;
}

public static bool Enabled { get; private set; }

public BuffIcon ID { get; }

public int TitleCliloc { get; }

public int SecondaryCliloc { get; }

public DateTime StartTime { get; private set; }

public TimeSpan Duration { get; }

public bool RetainThroughDeath { get; }

public TextDefinition Args { get; }

public static void Configure()
{
Enabled = ServerConfiguration.GetOrUpdateSetting("buffIcons.enable", Core.ML);
}

public void StartTimer(PlayerMobile m)
{
if (Duration != TimeSpan.Zero)
{
StartTime = Core.Now;
var id = ID;
Timer.StartTimer(Duration, () => m.RemoveBuff(id), out _timerToken);
}
}

public void StopTimer()
{
_timerToken.Cancel();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using ModernUO.Serialization;
using Server.Engines.BuffIcons;
using Server.Mobiles;

namespace Server.Items;

Check notice on line 7 in Projects/UOContent/Items/Skill Items/Magical/Potions/InvisibilityPotion.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Namespace does not correspond to file location

Namespace does not correspond to file location, must be: 'Server.Items.Skill_Items.Magical.Potions'

Expand Down Expand Up @@ -57,8 +59,11 @@ public static void Hide(Mobile m)

m.Hidden = true;

BuffInfo.RemoveBuff(m, BuffIcon.HidingAndOrStealth);
BuffInfo.AddBuff(m, new BuffInfo(BuffIcon.Invisibility, 1075825)); // Invisibility/Invisible
if (m is PlayerMobile pm)
{
pm.RemoveBuff(BuffIcon.HidingAndOrStealth);
pm.AddBuff(new BuffInfo(BuffIcon.Invisibility, 1075825)); // Invisibility/Invisible
}

RemoveTimer(m);

Expand Down
Loading

0 comments on commit d5160bd

Please sign in to comment.