fix: Converts ethics system to generic entity persistence (#1824)

### Summary

Converts ethics system to entity persistence and removes the persistence item.


### TODO

1. The enable/disable toggle doesn't propagate to all code that does Ethics checks (notoriety, pvp, etc).
2. We need commands to remove them from an ethic.
This commit is contained in:
Kamron Batman 2024-06-16 10:26:09 -07:00 • committed by GitHub
parent f87c8f73ab
commit 20596e52fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 1327 additions and 1338 deletions

View file

@ -1,35 +1,44 @@
using ModernUO.Serialization;
using Server.Factions;
namespace Server.Ethics.Evil
namespace Server.Ethics.Evil;
[SerializationGenerator(0, false)]
public sealed partial class EvilEthic : Ethic
{
public sealed class EvilEthic : Ethic
public override EthicDefinition Definition => new(
0x455,
"Evil",
"(Evil)",
"I am evil incarnate",
[
new UnholySense(),
new UnholyItem(),
new SummonFamiliar(),
new VileBlade(),
new Blight(),
new UnholyShield(),
new UnholySteed(),
new UnholyWord()
]
);
public EvilEthic()
{
public EvilEthic()
if (!RegisterEthic(this))
{
m_Definition = new EthicDefinition(
0x455,
"Evil",
"(Evil)",
"I am evil incarnate",
new Power[]
{
new UnholySense(),
new UnholyItem(),
new SummonFamiliar(),
new VileBlade(),
new Blight(),
new UnholyShield(),
new UnholySteed(),
new UnholyWord()
}
);
Delete();
}
}
public override bool IsEligible(Mobile mob)
public override bool IsEligible(Mobile mob) => Faction.Find(mob) is Minax or Shadowlords;
[AfterDeserialization]
private void AfterDeserialization()
{
if (!RegisterEthic(this))
{
var fac = Faction.Find(mob);
return fac is Minax or Shadowlords;
Delete();
}
}
}

View file

@ -1,92 +1,75 @@
using ModernUO.Serialization;
using Server.Ethics;
namespace Server.Mobiles
namespace Server.Mobiles;
[SerializationGenerator(0, false)]
public partial class UnholySteed : BaseMount
{
public class UnholySteed : BaseMount
public override string DefaultName => "a dark steed";
[Constructible]
public UnholySteed() : base(0x74, 0x3EA7, AIType.AI_Melee, FightMode.Aggressor)
{
public override string DefaultName => "a dark steed";
SetStr(496, 525);
SetDex(86, 105);
SetInt(86, 125);
[Constructible]
public UnholySteed() : base(0x74, 0x3EA7, AIType.AI_Melee, FightMode.Aggressor)
SetHits(298, 315);
SetDamage(16, 22);
SetDamageType(ResistanceType.Physical, 40);
SetDamageType(ResistanceType.Fire, 40);
SetDamageType(ResistanceType.Energy, 20);
SetResistance(ResistanceType.Physical, 55, 65);
SetResistance(ResistanceType.Fire, 30, 40);
SetResistance(ResistanceType.Cold, 30, 40);
SetResistance(ResistanceType.Poison, 30, 40);
SetResistance(ResistanceType.Energy, 20, 30);
SetSkill(SkillName.MagicResist, 25.1, 30.0);
SetSkill(SkillName.Tactics, 97.6, 100.0);
SetSkill(SkillName.Wrestling, 80.5, 92.5);
Fame = 14000;
Karma = -14000;
VirtualArmor = 60;
Tamable = false;
ControlSlots = 1;
}
public override int StepsMax => 6400;
public override string CorpseName => "an unholy corpse";
public override bool IsDispellable => false;
public override bool IsBondable => false;
public override FoodType FavoriteFood => FoodType.FruitsAndVeggies | FoodType.GrainsAndHay;
private static MonsterAbility[] _abilities = { MonsterAbilities.FireBreath };
public override MonsterAbility[] GetMonsterAbilities() => _abilities;
public override string ApplyNameSuffix(string suffix)
{
if (suffix.Length == 0)
{
SetStr(496, 525);
SetDex(86, 105);
SetInt(86, 125);
SetHits(298, 315);
SetDamage(16, 22);
SetDamageType(ResistanceType.Physical, 40);
SetDamageType(ResistanceType.Fire, 40);
SetDamageType(ResistanceType.Energy, 20);
SetResistance(ResistanceType.Physical, 55, 65);
SetResistance(ResistanceType.Fire, 30, 40);
SetResistance(ResistanceType.Cold, 30, 40);
SetResistance(ResistanceType.Poison, 30, 40);
SetResistance(ResistanceType.Energy, 20, 30);
SetSkill(SkillName.MagicResist, 25.1, 30.0);
SetSkill(SkillName.Tactics, 97.6, 100.0);
SetSkill(SkillName.Wrestling, 80.5, 92.5);
Fame = 14000;
Karma = -14000;
VirtualArmor = 60;
Tamable = false;
ControlSlots = 1;
return base.ApplyNameSuffix(Ethic.Evil.Definition.Adjunct.String);
}
public UnholySteed(Serial serial) : base(serial)
return base.ApplyNameSuffix($"{suffix} {Ethic.Evil.Definition.Adjunct.String}");
}
public override void OnDoubleClick(Mobile from)
{
if (Ethic.Find(from) != Ethic.Evil)
{
from.SendMessage("You may not ride this steed.");
}
public override int StepsMax => 6400;
public override string CorpseName => "an unholy corpse";
public override bool IsDispellable => false;
public override bool IsBondable => false;
public override FoodType FavoriteFood => FoodType.FruitsAndVeggies | FoodType.GrainsAndHay;
private static MonsterAbility[] _abilities = { MonsterAbilities.FireBreath };
public override MonsterAbility[] GetMonsterAbilities() => _abilities;
public override string ApplyNameSuffix(string suffix)
else
{
if (suffix.Length == 0)
{
return base.ApplyNameSuffix(Ethic.Evil.Definition.Adjunct.String);
}
return base.ApplyNameSuffix($"{suffix} {Ethic.Evil.Definition.Adjunct.String}");
}
public override void OnDoubleClick(Mobile from)
{
if (Ethic.Find(from) != Ethic.Evil)
{
from.SendMessage("You may not ride this steed.");
}
else
{
base.OnDoubleClick(from);
}
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
base.OnDoubleClick(from);
}
}
}

View file

@ -2,82 +2,81 @@ using System;
using Server.Spells;
using Server.Targeting;
namespace Server.Ethics.Evil
{
public sealed class Blight : Power
{
public Blight() =>
m_Definition = new PowerDefinition(
15,
"Blight",
"Velgo Ontawl",
""
);
namespace Server.Ethics.Evil;
public override void BeginInvoke(Player from)
public sealed class Blight : Power
{
public Blight() =>
Definition = new PowerDefinition(
15,
"Blight",
"Velgo Ontawl",
""
);
public override void BeginInvoke(Player from)
{
from.Mobile.BeginTarget(12, true, TargetFlags.None, Power_OnTarget, from);
from.Mobile.SendMessage("Where do you wish to blight?");
}
private void Power_OnTarget(Mobile fromMobile, object obj, Player from)
{
if (obj is not IPoint3D p)
{
from.Mobile.BeginTarget(12, true, TargetFlags.None, Power_OnTarget, from);
from.Mobile.SendMessage("Where do you wish to blight?");
return;
}
private void Power_OnTarget(Mobile fromMobile, object obj, Player from)
if (!CheckInvoke(from))
{
if (obj is not IPoint3D p)
return;
}
var powerFunctioned = false;
SpellHelper.GetSurfaceTop(ref p);
foreach (var mob in from.Mobile.GetMobilesInRange(6))
{
if (mob == from.Mobile || !SpellHelper.ValidIndirectTarget(from.Mobile, mob))
{
return;
continue;
}
if (!CheckInvoke(from))
if (mob.GetStatMod("Holy Curse") != null)
{
return;
continue;
}
var powerFunctioned = false;
SpellHelper.GetSurfaceTop(ref p);
foreach (var mob in from.Mobile.GetMobilesInRange(6))
if (!from.Mobile.CanBeHarmful(mob, false))
{
if (mob == from.Mobile || !SpellHelper.ValidIndirectTarget(from.Mobile, mob))
{
continue;
}
if (mob.GetStatMod("Holy Curse") != null)
{
continue;
}
if (!from.Mobile.CanBeHarmful(mob, false))
{
continue;
}
from.Mobile.DoHarmful(mob, true);
mob.AddStatMod(new StatMod(StatType.All, "Holy Curse", -10, TimeSpan.FromMinutes(30.0)));
mob.FixedParticles(0x374A, 10, 15, 5028, EffectLayer.Waist);
mob.PlaySound(0x1FB);
powerFunctioned = true;
continue;
}
if (powerFunctioned)
{
SpellHelper.Turn(from.Mobile, p);
from.Mobile.DoHarmful(mob, true);
Effects.PlaySound(new Point3D(p), from.Mobile.Map, 0x1FB);
mob.AddStatMod(new StatMod(StatType.All, "Holy Curse", -10, TimeSpan.FromMinutes(30.0)));
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You curse the area.");
mob.FixedParticles(0x374A, 10, 15, 5028, EffectLayer.Waist);
mob.PlaySound(0x1FB);
FinishInvoke(from);
}
else
{
from.Mobile.FixedEffect(0x3735, 6, 30);
from.Mobile.PlaySound(0x5C);
}
powerFunctioned = true;
}
if (powerFunctioned)
{
SpellHelper.Turn(from.Mobile, p);
Effects.PlaySound(new Point3D(p), from.Mobile.Map, 0x1FB);
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You curse the area.");
FinishInvoke(from);
}
else
{
from.Mobile.FixedEffect(0x3735, 6, 30);
from.Mobile.PlaySound(0x5C);
}
}
}
}

View file

@ -1,45 +1,44 @@
using System;
using Server.Mobiles;
namespace Server.Ethics.Evil
namespace Server.Ethics.Evil;
public sealed class SummonFamiliar : Power
{
public sealed class SummonFamiliar : Power
public SummonFamiliar() =>
Definition = new PowerDefinition(
5,
"Summon Familiar",
"Trubechs Vingir",
""
);
public override void BeginInvoke(Player from)
{
public SummonFamiliar() =>
m_Definition = new PowerDefinition(
5,
"Summon Familiar",
"Trubechs Vingir",
""
);
public override void BeginInvoke(Player from)
if (from.Familiar?.Deleted == true)
{
if (from.Familiar?.Deleted == true)
{
from.Familiar = null;
}
from.Familiar = null;
}
if (from.Familiar != null)
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You already have an unholy familiar.");
return;
}
if (from.Familiar != null)
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You already have an unholy familiar.");
return;
}
if (from.Mobile.Followers + 1 > from.Mobile.FollowersMax)
{
from.Mobile.SendLocalizedMessage(1049645); // You have too many followers to summon that creature.
return;
}
if (from.Mobile.Followers + 1 > from.Mobile.FollowersMax)
{
from.Mobile.SendLocalizedMessage(1049645); // You have too many followers to summon that creature.
return;
}
var familiar = new UnholyFamiliar();
var familiar = new UnholyFamiliar();
if (BaseCreature.Summon(familiar, from.Mobile, from.Mobile.Location, 0x217, TimeSpan.FromHours(1.0)))
{
from.Familiar = familiar;
if (BaseCreature.Summon(familiar, from.Mobile, from.Mobile.Location, 0x217, TimeSpan.FromHours(1.0)))
{
from.Familiar = familiar;
FinishInvoke(from);
}
FinishInvoke(from);
}
}
}
}

View file

@ -1,71 +1,70 @@
using Server.Items;
using Server.Targeting;
namespace Server.Ethics.Evil
{
public sealed class UnholyItem : Power
{
public UnholyItem() =>
m_Definition = new PowerDefinition(
5,
"Unholy Item",
"Vidda K'balc",
""
);
namespace Server.Ethics.Evil;
public override void BeginInvoke(Player from)
public sealed class UnholyItem : Power
{
public UnholyItem() =>
Definition = new PowerDefinition(
5,
"Unholy Item",
"Vidda K'balc",
""
);
public override void BeginInvoke(Player from)
{
from.Mobile.BeginTarget(12, false, TargetFlags.None, Power_OnTarget, from);
from.Mobile.SendMessage("Which item do you wish to imbue?");
}
private void Power_OnTarget(Mobile fromMobile, object obj, Player from)
{
if (obj is not Item item)
{
from.Mobile.BeginTarget(12, false, TargetFlags.None, Power_OnTarget, from);
from.Mobile.SendMessage("Which item do you wish to imbue?");
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You may not imbue that.");
return;
}
private void Power_OnTarget(Mobile fromMobile, object obj, Player from)
if (item.Parent != from.Mobile)
{
if (obj is not Item item)
from.Mobile.LocalOverheadMessage(
MessageType.Regular,
0x3B2,
false,
"You may only imbue items you are wearing."
);
return;
}
if ((item.SavedFlags & 0x300) != 0)
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "That has already been imbued.");
return;
}
var canImbue = item is Spellbook or BaseClothing or BaseArmor or BaseWeapon &&
item.Name == null;
if (canImbue)
{
if (!CheckInvoke(from))
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You may not imbue that.");
return;
}
if (item.Parent != from.Mobile)
{
from.Mobile.LocalOverheadMessage(
MessageType.Regular,
0x3B2,
false,
"You may only imbue items you are wearing."
);
return;
}
item.Hue = Ethic.Evil.Definition.PrimaryHue;
item.SavedFlags |= 0x200;
if ((item.SavedFlags & 0x300) != 0)
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "That has already been imbued.");
return;
}
from.Mobile.FixedEffect(0x375A, 10, 20);
from.Mobile.PlaySound(0x209);
var canImbue = item is Spellbook or BaseClothing or BaseArmor or BaseWeapon &&
item.Name == null;
if (canImbue)
{
if (!CheckInvoke(from))
{
return;
}
item.Hue = Ethic.Evil.Definition.PrimaryHue;
item.SavedFlags |= 0x200;
from.Mobile.FixedEffect(0x375A, 10, 20);
from.Mobile.PlaySound(0x209);
FinishInvoke(from);
}
else
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You may not imbue that.");
}
FinishInvoke(from);
}
else
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You may not imbue that.");
}
}
}
}

View file

@ -1,97 +1,76 @@
using System;
using Server.Text;
namespace Server.Ethics.Evil
namespace Server.Ethics.Evil;
public sealed class UnholySense : Power
{
public sealed class UnholySense : Power
public UnholySense() =>
Definition = new PowerDefinition(
0,
"Unholy Sense",
"Drewrok Velgo",
""
);
public override void BeginInvoke(Player from)
{
public UnholySense() =>
m_Definition = new PowerDefinition(
0,
"Unholy Sense",
"Drewrok Velgo",
""
);
var opposition = Ethic.Hero;
public override void BeginInvoke(Player from)
var enemyCount = 0;
var maxRange = 18 + from.Power;
Player primary = null;
foreach (var pl in opposition.Players)
{
var opposition = Ethic.Hero;
var mob = pl.Mobile;
var enemyCount = 0;
var maxRange = 18 + from.Power;
Player primary = null;
foreach (var pl in opposition.Players)
if (mob == null || mob.Map != from.Mobile.Map || !mob.Alive)
{
var mob = pl.Mobile;
if (mob == null || mob.Map != from.Mobile.Map || !mob.Alive)
{
continue;
}
if (!mob.InRange(from.Mobile, Math.Max(18, maxRange - pl.Power)))
{
continue;
}
if (primary == null || pl.Power > primary.Power)
{
primary = pl;
}
++enemyCount;
continue;
}
using var sb = ValueStringBuilder.Create();
sb.Append("You sense ");
sb.Append(enemyCount == 0 ? "no" : enemyCount.ToString());
sb.Append(enemyCount == 1 ? " enemy" : " enemies");
if (primary != null)
if (!mob.InRange(from.Mobile, Math.Max(18, maxRange - pl.Power)))
{
sb.Append(", and a strong presence");
switch (from.Mobile.GetDirectionTo(primary.Mobile))
{
case Direction.West:
sb.Append(" to the west.");
break;
case Direction.East:
sb.Append(" to the east.");
break;
case Direction.North:
sb.Append(" to the north.");
break;
case Direction.South:
sb.Append(" to the south.");
break;
case Direction.Up:
sb.Append(" to the north-west.");
break;
case Direction.Down:
sb.Append(" to the south-east.");
break;
case Direction.Left:
sb.Append(" to the south-west.");
break;
case Direction.Right:
sb.Append(" to the north-east.");
break;
}
}
else
{
sb.Append('.');
continue;
}
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x59, false, sb.ToString());
if (primary == null || pl.Power > primary.Power)
{
primary = pl;
}
FinishInvoke(from);
++enemyCount;
}
using var sb = ValueStringBuilder.Create();
sb.Append($"You sense {(enemyCount == 0 ? "no" : enemyCount.ToString())} {(enemyCount == 1 ? "enemy" : "enemies")}");
if (primary != null)
{
var direction = from.Mobile.GetDirectionTo(primary.Mobile) switch
{
Direction.East => "east",
Direction.North => "north",
Direction.South => "south",
Direction.Up => "north-west",
Direction.Down => "south-east",
Direction.Left => "south-west",
Direction.Right => "north-east",
_ => "west"
};
sb.Append($", and a strong presence to the {direction}.");
}
else
{
sb.Append('.');
}
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x59, false, sb.ToString());
FinishInvoke(from);
}
}

View file

@ -1,38 +1,37 @@
namespace Server.Ethics.Evil
namespace Server.Ethics.Evil;
public sealed class UnholyShield : Power
{
public sealed class UnholyShield : Power
public UnholyShield() =>
Definition = new PowerDefinition(
20,
"Unholy Shield",
"Velgo K'blac",
""
);
public override void BeginInvoke(Player from)
{
public UnholyShield() =>
m_Definition = new PowerDefinition(
20,
"Unholy Shield",
"Velgo K'blac",
""
);
public override void BeginInvoke(Player from)
if (from.IsShielded)
{
if (from.IsShielded)
{
from.Mobile.LocalOverheadMessage(
MessageType.Regular,
0x3B2,
false,
"You are already under the protection of an unholy shield."
);
return;
}
from.BeginShield();
from.Mobile.LocalOverheadMessage(
MessageType.Regular,
0x3B2,
false,
"You are now under the protection of an unholy shield."
"You are already under the protection of an unholy shield."
);
FinishInvoke(from);
return;
}
from.BeginShield();
from.Mobile.LocalOverheadMessage(
MessageType.Regular,
0x3B2,
false,
"You are now under the protection of an unholy shield."
);
FinishInvoke(from);
}
}
}

View file

@ -1,45 +1,44 @@
using System;
using Server.Mobiles;
namespace Server.Ethics.Evil
namespace Server.Ethics.Evil;
public sealed class UnholySteed : Power
{
public sealed class UnholySteed : Power
public UnholySteed() =>
Definition = new PowerDefinition(
30,
"Unholy Steed",
"Trubechs Yeliab",
""
);
public override void BeginInvoke(Player from)
{
public UnholySteed() =>
m_Definition = new PowerDefinition(
30,
"Unholy Steed",
"Trubechs Yeliab",
""
);
public override void BeginInvoke(Player from)
if (from.Steed?.Deleted == true)
{
if (from.Steed?.Deleted == true)
{
from.Steed = null;
}
from.Steed = null;
}
if (from.Steed != null)
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You already have an unholy steed.");
return;
}
if (from.Steed != null)
{
from.Mobile.LocalOverheadMessage(MessageType.Regular, 0x3B2, false, "You already have an unholy steed.");
return;
}
if (from.Mobile.Followers + 1 > from.Mobile.FollowersMax)
{
from.Mobile.SendLocalizedMessage(1049645); // You have too many followers to summon that creature.
return;
}
if (from.Mobile.Followers + 1 > from.Mobile.FollowersMax)
{
from.Mobile.SendLocalizedMessage(1049645); // You have too many followers to summon that creature.
return;
}
var steed = new Mobiles.UnholySteed();
var steed = new Mobiles.UnholySteed();
if (BaseCreature.Summon(steed, from.Mobile, from.Mobile.Location, 0x217, TimeSpan.FromHours(1.0)))
{
from.Steed = steed;
if (BaseCreature.Summon(steed, from.Mobile, from.Mobile.Location, 0x217, TimeSpan.FromHours(1.0)))
{
from.Steed = steed;
FinishInvoke(from);
}
FinishInvoke(from);
}
}
}
}

View file

@ -1,17 +1,16 @@
namespace Server.Ethics.Evil
{
public sealed class UnholyWord : Power
{
public UnholyWord() =>
m_Definition = new PowerDefinition(
100,
"Unholy Word",
"Velgo Oostrac",
""
);
namespace Server.Ethics.Evil;
public override void BeginInvoke(Player from)
{
}
public sealed class UnholyWord : Power
{
public UnholyWord() =>
Definition = new PowerDefinition(
100,
"Unholy Word",
"Velgo Oostrac",
""
);
public override void BeginInvoke(Player from)
{
}
}
}

View file

@ -1,17 +1,16 @@
namespace Server.Ethics.Evil
{
public sealed class VileBlade : Power
{
public VileBlade() =>
m_Definition = new PowerDefinition(
10,
"Vile Blade",
"Velgo Reyam",
""
);
namespace Server.Ethics.Evil;
public override void BeginInvoke(Player from)
{
}
public sealed class VileBlade : Power
{
public VileBlade() =>
Definition = new PowerDefinition(
10,
"Vile Blade",
"Velgo Reyam",
""
);
public override void BeginInvoke(Player from)
{
}
}
}