ModernUO/Projects/UOContent/Spells/Chivalry/NobleSacrifice.cs
Kamron Batman e1e30998ba
fix: Adds ReadType/Write(Type) and improves type referencing (#1172)
## Changes
* Improves type hashing by introducing xxHash3 (64bit)
* Removes individual `tdb` files in favor of a single `SerializedTypes.db` file. This file is only used to identify a type that is being deserialized, which doesn't exist.
* Adds duplicate type alias detection
* Adds `AssemblyHandler.FindTypeByHash`

View changed files whitespaces: https://github.com/modernuo/ModernUO/pull/1172/files?diff=split&w=1

## SerializedTypes.db
The serialized types file is used to get back the original name of a type in case it no longer exists in code. This can easily be necessary if a class is renamed in code and no `TypeAlias` is provided.

### Format
byte[4] - version
byte[4] - count
--array--
byte[8] - xxHash
byte[1] - flag, 0 - null, 1 - not null
byte[n] - Full class name in UTF8

### Example
<img width="472" alt="SerializedTypes_Example" src="https://user-images.githubusercontent.com/3953314/195255429-31d24293-6bd1-419e-811b-07874dd0f78d.png">

## Benchmarks
Serialized 500 Type fields. The 8192bytes comes from the _ConcurrentQueue_ that would later be used for SerializedTypes.
Note that the queue is never cleared, so it's size grew considerably.
```cs
|               Method |     Mean |    Error |   StdDev | Allocated |
|--------------------- |---------:|---------:|---------:|----------:|
|      BenchmarkXXHash | 18.44 us | 0.278 us | 0.260 us |    8192 B |
| BenchmarkTypeStrings | 25.09 us | 0.292 us | 0.259 us |         - |
```

TODO:
* Add support in the Serialization Generator for `ReadType()` and `Write(Type)`
* Remove `SetTypeRef` from Serialization Generator
2022-10-11 22:17:22 -07:00

178 lines
6.9 KiB
C#

using System;
using Server.Collections;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Spells.Fourth;
using Server.Spells.Mysticism;
using Server.Spells.Necromancy;
namespace Server.Spells.Chivalry
{
public class NobleSacrificeSpell : PaladinSpell
{
private static readonly SpellInfo _info = new(
"Noble Sacrifice",
"Dium Prostra",
-1,
9002
);
public NobleSacrificeSpell(Mobile caster, Item scroll = null) : base(caster, scroll, _info)
{
}
public override TimeSpan CastDelayBase => TimeSpan.FromSeconds(1.5);
public override double RequiredSkill => 65.0;
public override int RequiredMana => 20;
public override int RequiredTithing => 30;
public override int MantraNumber => 1060725; // Dium Prostra
public override bool BlocksMovement => false;
public override void OnCast()
{
if (CheckSequence())
{
var eable = Caster.GetMobilesInRange(3);
using var pool = PooledRefQueue<Mobile>.Create();
foreach (var m in eable)
{
if (m is not BaseCreature { IsAnimatedDead: true } && Caster != m && m.InLOS(Caster) &&
Caster.CanBeBeneficial(m, false, true) && m is not Golem)
{
pool.Enqueue(m);
}
}
eable.Free();
Caster.PlaySound(0x244);
Caster.FixedParticles(0x3709, 1, 30, 9965, 5, 7, EffectLayer.Waist);
Caster.FixedParticles(0x376A, 1, 30, 9502, 5, 3, EffectLayer.Waist);
/* Attempts to Resurrect, Cure and Heal all targets in a radius around the caster.
* If any target is successfully assisted, the Paladin's current
* Hit Points, Mana and Stamina are set to 1.
* Amount of damage healed is affected by the Caster's Karma, from 8 to 24 hit points.
*/
var sacrifice = false;
// TODO: Is there really a resurrection chance?
var resChance = 0.1 + 0.9 * Caster.Karma / 10000;
while (pool.Count > 0)
{
var m = pool.Dequeue();
if (!m.Alive)
{
if (m.Region?.IsPartOf("Khaldun") == true)
{
// The veil of death in this area is too strong and resists thy efforts to restore life.
Caster.SendLocalizedMessage(1010395);
}
else if (resChance > Utility.RandomDouble())
{
m.FixedParticles(0x375A, 1, 15, 5005, 5, 3, EffectLayer.Head);
m.CloseGump<ResurrectGump>();
m.SendGump(new ResurrectGump(m, Caster));
sacrifice = true;
}
}
else
{
bool sendEffect = false;
if (m.Poisoned && m.CurePoison(Caster))
{
Caster.DoBeneficial(m);
if (Caster != m)
{
Caster.SendLocalizedMessage(1010058); // You have cured the target of all poisons!
}
m.SendLocalizedMessage(1010059); // You have been cured of all poisons.
sendEffect = true;
sacrifice = true;
}
if (m.Hits < m.HitsMax)
{
var toHeal = Math.Clamp(ComputePowerValue(10) + Utility.RandomMinMax(0, 2), 8, 24);
Caster.DoBeneficial(m);
m.Heal(toHeal, Caster);
sendEffect = true;
}
var mod = m.GetStatMod("[Magic] Str Curse");
if (mod?.Offset < 0)
{
m.RemoveStatMod("[Magic] Str Curse");
sendEffect = true;
}
mod = m.GetStatMod("[Magic] Dex Curse");
if (mod?.Offset < 0)
{
m.RemoveStatMod("[Magic] Dex Curse");
sendEffect = true;
}
mod = m.GetStatMod("[Magic] Int Curse");
if (mod?.Offset < 0)
{
m.RemoveStatMod("[Magic] Int Curse");
sendEffect = true;
}
if (m.Paralyzed)
{
m.Paralyzed = false;
sendEffect = true;
}
sendEffect = EvilOmenSpell.EndEffect(m) || sendEffect;
sendEffect = StrangleSpell.RemoveCurse(m) || sendEffect;
sendEffect = CorpseSkinSpell.RemoveCurse(m) || sendEffect;
sendEffect = CurseSpell.RemoveEffect(m) || sendEffect;
sendEffect = MortalStrike.EndWound(m) || sendEffect;
sendEffect = MindRotSpell.ClearMindRotScalar(m) || sendEffect;
sendEffect = BloodOathSpell.RemoveCurse(m) || sendEffect;
sendEffect = SpellPlagueSpell.RemoveEffect(m) || sendEffect;
// TODO: Move these into their respective end effect methods
BuffInfo.RemoveBuff(m, BuffIcon.Clumsy);
BuffInfo.RemoveBuff(m, BuffIcon.FeebleMind);
BuffInfo.RemoveBuff(m, BuffIcon.Weaken);
BuffInfo.RemoveBuff(m, BuffIcon.Curse);
BuffInfo.RemoveBuff(m, BuffIcon.MassCurse);
BuffInfo.RemoveBuff(m, BuffIcon.MortalStrike);
BuffInfo.RemoveBuff(m, BuffIcon.Strangle);
BuffInfo.RemoveBuff(m, BuffIcon.EvilOmen);
if (sendEffect)
{
m.FixedParticles(0x375A, 1, 15, 5005, 5, 3, EffectLayer.Head);
sacrifice = true;
}
}
}
if (sacrifice)
{
Caster.PlaySound(Caster.Body.IsFemale ? 0x150 : 0x423);
Caster.Hits = 1;
Caster.Stam = 1;
Caster.Mana = 1;
}
}
FinishSequence();
}
}
}