Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] fix: Cleans up spell system & fixes bugs #831

Draft
wants to merge 33 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
15ee854
WIP
kamronbatman Oct 16, 2021
a9dae7e
WIP
kamronbatman Oct 17, 2021
5f16fb2
More spell cleanup
kamronbatman Oct 18, 2021
846fa14
Cleans up comments
kamronbatman Oct 18, 2021
c644244
Changes to UOML
kamronbatman Oct 18, 2021
4235645
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Oct 24, 2021
a905063
Fixes spell plague. Cleans up other code
kamronbatman Oct 24, 2021
d72732c
Converts to using pooled ref queue
kamronbatman Oct 24, 2021
95254a3
Adds cleansing winds. Fixes mindrot
kamronbatman Oct 28, 2021
f20323d
Adds sleep spell
kamronbatman Oct 29, 2021
4ed6973
Cleanup
kamronbatman Oct 29, 2021
3d78442
Adds mass sleep spell
kamronbatman Oct 29, 2021
bef8ae3
Cleanup
kamronbatman Oct 29, 2021
0b71e6e
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Nov 1, 2021
53d3c33
WIP
kamronbatman Nov 7, 2021
223af1b
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Nov 12, 2021
f39dcbc
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Nov 14, 2021
74243f6
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Nov 15, 2021
bf64b9e
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Nov 15, 2021
e07f8d0
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Nov 15, 2021
9352ae7
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Dec 1, 2021
25cc77b
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Dec 3, 2021
389cdd7
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Dec 24, 2021
6e5b656
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Dec 24, 2021
b64d9ee
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Dec 24, 2021
10a0025
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Jan 11, 2022
c311540
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman May 10, 2022
724c8f8
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Jul 17, 2022
44272da
Cleanup
kamronbatman Jul 17, 2022
4d95f56
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Jul 17, 2022
d68451d
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Jul 17, 2022
c7b6a43
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Jul 17, 2022
28f0b21
Merge branch 'main' into kbatman/cleanup_ninjas
kamronbatman Jul 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Projects/UOContent/Misc/AOS.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using ModernUO.Serialization;
using Server.Items;
using Server.Mobiles;
using Server.Spells;
using Server.Spells.Fifth;
using Server.Spells.Mysticism;
using Server.Spells.Ninjitsu;
using Server.Spells.Seventh;

Expand Down Expand Up @@ -215,9 +217,14 @@ public static int Damage(
}

m.Damage(totalDamage, from);

// TODO: Move all of this somewhere else
SleepSpell.EndSleep(m);

return totalDamage;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Fix(ref int val)
{
if (val < 0)
Expand Down Expand Up @@ -555,6 +562,35 @@ public static int GetValue(Mobile m, AosAttribute attribute)
}
}

if (attribute == AosAttribute.CastSpeed)
{
if (SleepSpell.UnderEffect(m))
{
value -= 2;
}
}
else if (attribute == AosAttribute.CastRecovery)
{
if (SleepSpell.UnderEffect(m))
{
value -= 3;
}
}
else if (attribute == AosAttribute.WeaponSpeed)
{
if (SleepSpell.UnderEffect(m))
{
value -= 45;
}
}
else if (attribute == AosAttribute.AttackChance)
{
if (SleepSpell.UnderEffect(m))
{
value -= 45;
}
}

return value;
}

Expand Down
4 changes: 4 additions & 0 deletions Projects/UOContent/Spells/Base/SpellHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,8 @@ public static void Damage(
DoLeech(damageGiven, from, target);
}

Mysticism.SpellPlagueSpell.OnMobileDamaged(target);

WeightOverloading.DFA = DFAlgorithm.Standard;
}
else
Expand Down Expand Up @@ -1172,6 +1174,8 @@ protected override void OnTick()
bcTarg.OnDamagedBySpell(m_From);
}

Mysticism.SpellPlagueSpell.OnMobileDamaged(m_Target);

m_Spell?.RemoveDelayedDamageContext(m_Target);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Projects/UOContent/Spells/Initializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ public static void Configure()
// Register(678, typeof(HealingStoneSpell));
// Register(679, typeof(PurgeMagicSpell));
// Register(680, typeof(EnchantSpell));
// Register(681, typeof(SleepSpell));
Register(681, typeof(SleepSpell));
Register(682, typeof(EagleStrikeSpell));
Register(683, typeof(AnimatedWeaponSpell));
Register(684, typeof(StoneFormSpell));
// Register(685, typeof(SpellTriggerSpell));
// Register(686, typeof(MassSleepSpell));
Register(686, typeof(MassSleepSpell));
Register(687, typeof(CleansingWindsSpell));
Register(688, typeof(BombardSpell));
Register(689, typeof(SpellPlagueSpell));
Expand Down
8 changes: 4 additions & 4 deletions Projects/UOContent/Spells/Mysticism/CleansingWindsSpell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ public static int RemoveCurses(Mobile m)
{
var curseLevel = 0;

// if (SleepSpell.EndSleep(m))
// {
// curseLevel += 2;
// }
if (SleepSpell.EndSleep(m))
{
curseLevel += 2;
}

if (EvilOmenSpell.EndEffect(m))
{
Expand Down
276 changes: 276 additions & 0 deletions Projects/UOContent/Spells/Mysticism/EnchantSpell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
using Server.Gumps;
using Server.Items;
using Server.Spells.Spellweaving;
using System;
using System.Collections.Generic;
using Server.Network;

namespace Server.Spells.Mysticism
{
public class EnchantSpell : MysticSpell
{
public override SpellCircle Circle => SpellCircle.Second;
public override bool ClearHandsOnCast => false;

private static readonly Dictionary<Mobile, EnchantmentTimer> _table = new();

private BaseWeapon _weapon;
private AosWeaponAttribute _weaponAttribute;

private static readonly SpellInfo _info = new(
"Enchant", "In Ort Ylem",
230,
9022,
Reagent.SpidersSilk,
Reagent.MandrakeRoot,
Reagent.SulfurousAsh
);

public EnchantSpell(Mobile caster, Item scroll) : base(caster, scroll, _info)
{
}

public EnchantSpell(Mobile caster, Item scroll, BaseWeapon weapon, AosWeaponAttribute attribute)
: base(caster, scroll, _info)
{
_weapon = weapon;
_weaponAttribute = attribute;
}

public override bool CheckCast()
{
if (_weapon == null)
{
if (Caster.Weapon is not BaseWeapon wep)
{
Caster.SendLocalizedMessage(501078); // You must be holding a weapon.
}
else
{
Caster.CloseGump<EnchantSpellGump>();
_weapon = wep;

EnchantSpellGump gump = new EnchantSpellGump(Caster, this);
Caster.SendGump(gump);

Timer.StartTimer(TimeSpan.FromSeconds(30), () =>
{
if (Caster.CloseGump<EnchantSpellGump>())
{
FinishSequence();
}
});
}

return false;
}

return CanEnchantWeapon(Caster, _weapon);
}

private static bool CanEnchantWeapon(Mobile m, BaseWeapon weapon)
{
if (IsUnderSpellEffects(m, weapon))
{
m.SendLocalizedMessage(501775); // This spell is already in effect.
}
else if (ImmolatingWeaponSpell.IsImmolating(weapon) || weapon.Consecrated)
{
m.SendLocalizedMessage(1080128); // You cannot use this ability while your weapon is enchanted.
}
else if (weapon.FocusWeilder != null)
{
m.SendLocalizedMessage(1080446); // You cannot enchant an item that is under the effects of the ninjitsu focus attack ability.
}
else if (weapon.WeaponAttributes.HitLightning > 0 || weapon.WeaponAttributes.HitFireball > 0
|| weapon.WeaponAttributes.HitHarm > 0
|| weapon.WeaponAttributes.HitMagicArrow > 0
|| weapon.WeaponAttributes.HitDispel > 0)
{
m.SendLocalizedMessage(1080127); // This weapon already has a hit spell effect and cannot be enchanted.
}
else
{
return true;
}

return false;
}

public override void OnCast()
{
if (CanEnchantWeapon(Caster, _weapon) && CheckSequence() && Caster.Weapon == _weapon)
{
Caster.PlaySound(0x64E);
Caster.FixedEffect(0x36CB, 1, 9, 1915, 0);

int prim = (int)Caster.Skills[CastSkill].Value;
int sec = (int)Caster.Skills[DamageSkill].Value;

int value = 60 * (prim + sec) / 240;
double duration = (prim + sec) / 2.0 + 30.0;
bool malus;

Enhancement.SetValue(Caster, _weaponAttribute, value, "EnchantSpell");

if (prim >= 80 && sec >= 80 && _weapon.Attributes.SpellChanneling == 0)
{
Enhancement.SetValue(Caster, AosAttribute.SpellChanneling, 1, "EnchantSpell");
Enhancement.SetValue(Caster, AosAttribute.CastSpeed, -1, "EnchantSpell");
malus = true;
}

_table[Caster] = new EnchantmentTimer(Caster, _weapon, _weaponAttribute, value, malus, duration);

int loc = _weaponAttribute switch
{
AosWeaponAttribute.HitFireball => 1060420,
AosWeaponAttribute.HitHarm => 1060421,
AosWeaponAttribute.HitMagicArrow => 1060426,
AosWeaponAttribute.HitDispel => 1060417,
_ => 1060423 // AosWeaponAttribute.HitLightning
};

BuffInfo.AddBuff(Caster, new BuffInfo(BuffIcon.Enchant, 1080126, loc, TimeSpan.FromSeconds(duration), Caster, value.ToString()));

_weapon.EnchantedWeilder = Caster;
_weapon.InvalidateProperties();
}

FinishSequence();
}

public static bool IsUnderSpellEffects(Mobile m, BaseWeapon weapon) =>
_table != null && _table.TryGetValue(m, out var timer) && timer._weapon == weapon;

public static AosWeaponAttribute BonusAttribute(Mobile m) =>
_table != null && _table.TryGetValue(m, out var timer) ? timer._weaponAttribute : AosWeaponAttribute.HitColdArea;

public static int BonusValue(Mobile m) =>
_table != null && _table.TryGetValue(m, out var timer) ? timer._attributeValue : 0;

public static bool CastingMalus(Mobile m, BaseWeapon weapon) =>
_table != null && _table.TryGetValue(m, out var timer) && timer._castingMalus;

public static bool RemoveEnchantment(Mobile caster, BaseWeapon weapon = null)
{
if (_table == null || !_table.Remove(caster, out var timer) || weapon != null && timer._weapon != weapon)
{
return false;
}

timer.Stop();

caster.SendLocalizedMessage(1115273); // The enchantment on your weapon has expired.
caster.PlaySound(0x1E6);

Enhancement.RemoveMobile(caster);

weapon?.InvalidateProperties();
BuffInfo.RemoveBuff(caster, BuffIcon.Enchant);

return true;
}

public static void OnWeaponRemoved(BaseWeapon wep, Mobile from)
{
if (IsUnderSpellEffects(from, wep))
{
RemoveEnchantment(from);
}

wep.EnchantedWeilder = null;
}

private class EnchantmentTimer : Timer
{
private readonly Mobile _owner;
public readonly BaseWeapon _weapon;
public readonly bool _castingMalus;
public readonly AosWeaponAttribute _weaponAttribute;
public readonly int _attributeValue;

public EnchantmentTimer(Mobile owner, BaseWeapon wep, AosWeaponAttribute attribute, int value, bool malus, double duration)
: base(TimeSpan.FromSeconds(duration))
{
_owner = owner;
_weapon = wep;
_weaponAttribute = attribute;
_attributeValue = value;
_castingMalus = malus;

Start();
}

protected override void OnTick()
{
if (_weapon != null)
{
_weapon.EnchantedWeilder = null;
}

RemoveEnchantment(_owner);
}
}

public class EnchantSpellGump : Gump
{
private readonly Mobile _caster;
private readonly EnchantSpell _spell;

public EnchantSpellGump(Mobile caster, EnchantSpell spell) : base(20, 20)
{
_spell = spell;
_caster = caster;

AddBackground(0, 0, 260, 187, 3600);
AddAlphaRegion(5, 15, 242, 170);

AddImageTiled(220, 15, 30, 162, 10464);

AddItem(0, 3, 6882);
AddItem(-8, 170, 6880);
AddItem(185, 3, 6883);
AddItem(192, 170, 6881);

AddHtmlLocalized(20, 22, 150, 16, 1080133, 0x07FF); // Select Enchant

AddButton(20, 50, 9702, 9703, 1);
AddHtmlLocalized(45, 50, 200, 16, 1079705, 0x07FF); // Hit Lighting

AddButton(20, 75, 9702, 9703, 2);
AddHtmlLocalized(45, 75, 200, 16, 1079703, 0x07FF); // Hit Fireball

AddButton(20, 100, 9702, 9703, 3);
AddHtmlLocalized(45, 100, 200, 16, 1079704, 0x07FF); // Hit Harm

AddButton(20, 125, 9702, 9703, 4);
AddHtmlLocalized(45, 125, 200, 16, 1079706, 0x07FF); // Hit Magic Arrow

AddButton(20, 150, 9702, 9703, 5);
AddHtmlLocalized(45, 150, 200, 16, 1079702, 0x07FF); // Hit Dispel
}

public override void OnResponse(NetState sender, RelayInfo info)
{
if (info.ButtonID is < 1 or > 5)
{
_caster.SendLocalizedMessage(1080132); // You decide not to enchant your weapon.
return;
}

AosWeaponAttribute attr = info.ButtonID switch
{
2 => AosWeaponAttribute.HitFireball,
3 => AosWeaponAttribute.HitHarm,
4 => AosWeaponAttribute.HitMagicArrow,
5 => AosWeaponAttribute.HitDispel,
_ => AosWeaponAttribute.HitLightning
};

_spell._weaponAttribute = attr;
_spell.Cast();
}
}
}
}
2 changes: 1 addition & 1 deletion Projects/UOContent/Spells/Mysticism/HailStormSpell.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Server.Collections;
using Server.Collections;

namespace Server.Spells.Mysticism
{
Expand Down
Loading