ModernUO/Projects/UOContent/Mobiles/Monsters/ML/Special/Ilhenir.cs
Kamron Batman 351611a23a
Updates movement packets & Fastwalk (#324)
- [X] Updates Movement packets
- [X] Adds OSI fastwalk packets. These aren't used on OSi anymore.
- [X] Adds new movement handling, but looks like the client doesn't use it. (Also leaving the 0x4000 Character List Flag off)
- [X] Adds time sync request handler, but also looks like the client doesn't use it.
- [X] Adds time sync response for time sync, just in case, but it isn't used, so not sure about the arguments.
- [X] Reimplements RunUO's fastwalk to use a circular array on the netstate instead of every mobile
- [X] Removes ClearFastwalkStack from RunUO implementation. This shouldn't be needed anymore

Changed fastwalk settings:
```cs
        public static int WalkFootDelay { get; set; } = 440;
        public static int RunFootDelay { get; set; } = 220;
        public static int WalkMountDelay { get; set; } = 220;
        public static int RunMountDelay { get; set; } = 110;

        public static bool EnableFastwalkPrevention { get; set; } = true;
        public static AccessLevel FastwalkExemptionLevel { get; set; } = AccessLevel.Counselor;

        // If this is changed during runtime, then the steps array needs resizing.
        public static int MaxSteps { get; private set; } = 4;
```

modernuo.json
```json
{
  "settings": {
    "movement.delay.runFoot": "220",
    "movement.delay.runMount": "110",
    "movement.delay.walkFoot": "440",
    "movement.delay.walkMount": "220",
    "movement.enableFastWalkPrevention": "True",
    "movement.fastwalkExemptionLevel": "Counselor",
    "movement.maxSteps": "4"
  }
}
```

Notes about OSI fastwalk:
While it does work, I can't find a benefit in using it because of the variable speeds. If players moved at a single speed then we could refill the stack every X milliseconds with 6 keys and use a naive token bucket implementation.
Unfortunately variable speeds mount/run/walk/etc means we would have to use a leaky bucket algorithm.
If we are using a leaky bucket algorithm with a variable leak, then we don't need to send tokens because we are already tracking it on the server side.

ModernUO vs OSI Fastwalk:
When the fastwalk was implemented on OSI, it used up to 6 tokens. These tokens were probably distributed every 600-750 milliseconds. To get the same effect, the new fastwalk settings might need to be adjusted. I would tweak them and feel free to let me know what worked for you!

Bumps release version
2020-11-26 23:53:47 -08:00

421 lines
12 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Server.Engines.CannedEvil;
using Server.Items;
using Server.Network;
namespace Server.Mobiles
{
public class Ilhenir : BaseChampion
{
private static readonly HashSet<Mobile> m_Table = new HashSet<Mobile>();
[Constructible]
public Ilhenir()
: base(AIType.AI_Mage)
{
Title = "the Stained";
Body = 0x103;
BaseSoundID = 589;
SetStr(1105, 1350);
SetDex(82, 160);
SetInt(505, 750);
SetHits(9000);
SetDamage(21, 28);
SetDamageType(ResistanceType.Physical, 60);
SetDamageType(ResistanceType.Fire, 20);
SetDamageType(ResistanceType.Poison, 20);
SetResistance(ResistanceType.Physical, 55, 65);
SetResistance(ResistanceType.Fire, 50, 60);
SetResistance(ResistanceType.Cold, 55, 65);
SetResistance(ResistanceType.Poison, 70, 90);
SetResistance(ResistanceType.Energy, 65, 75);
SetSkill(SkillName.EvalInt, 100);
SetSkill(SkillName.Magery, 100);
SetSkill(SkillName.Meditation, 0);
SetSkill(SkillName.Poisoning, 5.4);
SetSkill(SkillName.Anatomy, 117.5);
SetSkill(SkillName.MagicResist, 120.0);
SetSkill(SkillName.Tactics, 119.9);
SetSkill(SkillName.Wrestling, 119.9);
Fame = 50000;
Karma = -50000;
VirtualArmor = 44;
if (Core.ML)
{
PackResources(8);
PackTalismans(5);
}
}
public Ilhenir(Serial serial)
: base(serial)
{
}
public override string CorpseName => "a corpse of Ilhenir";
public override ChampionSkullType SkullType => ChampionSkullType.Pain;
public override Type[] UniqueList => Array.Empty<Type>();
public override Type[] SharedList => new[]
{
typeof(ANecromancerShroud),
typeof(LieutenantOfTheBritannianRoyalGuard),
typeof(OblivionsNeedle),
typeof(TheRobeOfBritanniaAri)
};
public override Type[] DecorativeList => new[] { typeof(MonsterStatuette) };
public override MonsterStatuetteType[] StatueTypes => new[]
{
MonsterStatuetteType.PlagueBeast,
MonsterStatuetteType.RedDeath
};
public override string DefaultName => "Ilhenir";
public override bool Unprovokable => true;
public override bool Uncalmable => true;
public override Poison PoisonImmune => Poison.Lethal;
// public override bool GivesMLMinorArtifact => true; // TODO: Needs verification
public override int TreasureMapLevel => 5;
public virtual void PackResources(int amount)
{
for (var i = 0; i < amount; i++)
{
PackItem(
Utility.Random(6) switch
{
0 => new Blight(),
1 => new Scourge(),
2 => new Taint(),
3 => new Putrefication(),
4 => new Corruption(),
_ => new Muculent() // 5
}
);
}
}
public virtual void PackItems(Item item, int amount)
{
for (var i = 0; i < amount; i++)
{
PackItem(item);
}
}
public virtual void PackTalismans(int amount)
{
var count = Utility.Random(amount);
for (var i = 0; i < count; i++)
{
PackItem(new RandomTalisman());
}
}
public override void GenerateLoot()
{
AddLoot(LootPack.FilthyRich, 8);
}
public override void OnDeath(Container c)
{
base.OnDeath(c);
if (Core.ML)
{
c.DropItem(new GrizzledBones());
// TODO: Parrots
/*if (Utility.RandomDouble() < 0.6)
c.DropItem( new ParrotItem() ); */
if (Utility.RandomDouble() < 0.05)
{
c.DropItem(new GrizzledMareStatuette());
}
if (Utility.RandomDouble() < 0.025)
{
c.DropItem(new CrimsonCincture());
}
// TODO: Armor sets
/*if (Utility.RandomDouble() < 0.05)
{
switch ( Utility.Random(5) )
{
case 0: c.DropItem( new GrizzleGauntlets() ); break;
case 1: c.DropItem( new GrizzleGreaves() ); break;
case 2: c.DropItem( new GrizzleHelm() ); break;
case 3: c.DropItem( new GrizzleTunic() ); break;
case 4: c.DropItem( new GrizzleVambraces() ); break;
}
}*/
}
}
public override void OnGaveMeleeAttack(Mobile defender)
{
base.OnGaveMeleeAttack(defender);
if (Utility.RandomDouble() < 0.25)
{
CacophonicAttack(defender);
}
}
public override void OnDamage(int amount, Mobile from, bool willKill)
{
if (Utility.RandomDouble() < 0.1)
{
DropOoze();
}
base.OnDamage(amount, from, willKill);
}
public override int GetAngerSound() => 0x581;
public override int GetIdleSound() => 0x582;
public override int GetAttackSound() => 0x580;
public override int GetHurtSound() => 0x583;
public override int GetDeathSound() => 0x584;
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();
}
public virtual void CacophonicAttack(Mobile to)
{
if (to.Alive && to.Player && !UnderCacophonicAttack(to))
{
to.NetState.SendSpeedControl(SpeedControlSetting.Walk);
to.SendLocalizedMessage(1072069); // A cacophonic sound lambastes you, suppressing your ability to move.
to.PlaySound(0x584);
m_Table.Add(to);
Timer.DelayCall(TimeSpan.FromSeconds(30), CacophonicEnd, to);
}
}
public virtual void CacophonicEnd(Mobile from)
{
m_Table.Remove(from);
from.NetState.SendSpeedControl(SpeedControlSetting.Disable);
}
public static bool UnderCacophonicAttack(Mobile from) => m_Table.Contains(from);
public virtual void DropOoze()
{
var amount = Utility.RandomMinMax(1, 3);
var corrosive = Utility.RandomBool();
for (var i = 0; i < amount; i++)
{
Item ooze = new StainedOoze(corrosive);
var p = new Point3D(Location);
for (var j = 0; j < 5; j++)
{
p = GetSpawnPosition(2);
if (!Map.GetItemsInRange(p, 0).OfType<StainedOoze>().Any())
{
break;
}
}
ooze.MoveToWorld(p, Map);
}
if (Combatant != null)
{
if (corrosive)
{
Combatant.SendLocalizedMessage(1072071); // A corrosive gas seeps out of your enemy's skin!
}
else
{
Combatant.SendLocalizedMessage(1072072); // A poisonous gas seeps out of your enemy's skin!
}
}
}
private int RandomPoint(int mid) => mid + Utility.RandomMinMax(-2, 2);
public virtual Point3D GetSpawnPosition(int range) => GetSpawnPosition(Location, Map, range);
public virtual Point3D GetSpawnPosition(Point3D from, Map map, int range)
{
if (map == null)
{
return from;
}
var loc = new Point3D(RandomPoint(X), RandomPoint(Y), Z);
loc.Z = Map.GetAverageZ(loc.X, loc.Y);
return loc;
}
}
public class StainedOoze : Item
{
private int m_Ticks;
private Timer m_Timer;
[Constructible]
public StainedOoze(bool corrosive = false) : base(0x122A)
{
Movable = false;
Hue = 0x95;
Corrosive = corrosive;
m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(1), OnTick);
m_Ticks = 0;
}
public StainedOoze(Serial serial)
: base(serial)
{
}
[CommandProperty(AccessLevel.GameMaster)]
public bool Corrosive { get; set; }
public override void OnAfterDelete()
{
if (m_Timer != null)
{
m_Timer.Stop();
m_Timer = null;
}
}
private void OnTick()
{
var toDamage = new List<Mobile>();
foreach (var m in GetMobilesInRange(0))
{
if (m is BaseCreature bc)
{
if (!bc.Controlled && !bc.Summoned)
{
continue;
}
}
else if (!m.Player)
{
continue;
}
if (m.Alive && !m.IsDeadBondedPet && m.CanBeDamaged())
{
toDamage.Add(m);
}
}
for (var i = 0; i < toDamage.Count; ++i)
{
Damage(toDamage[i]);
}
++m_Ticks;
if (m_Ticks >= 35)
{
Delete();
}
else if (m_Ticks == 30)
{
ItemID = 0x122B;
}
}
public void Damage(Mobile m)
{
if (Corrosive)
{
var items = m.Items;
var damaged = false;
for (var i = 0; i < items.Count; ++i)
{
if (items[i] is IDurability wearable && wearable.HitPoints >= 10 && Utility.RandomDouble() < 0.25)
{
wearable.HitPoints -= wearable.HitPoints == 10 ? Utility.Random(1, 5) : 10;
damaged = true;
}
}
if (damaged)
{
m.LocalOverheadMessage(
MessageType.Regular,
0x21,
1072070
); // The infernal ooze scorches you, setting you and your equipment ablaze!
return;
}
}
AOS.Damage(m, 40, 0, 0, 0, 100, 0);
}
public override void Serialize(IGenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
writer.Write(Corrosive);
}
public override void Deserialize(IGenericReader reader)
{
base.Deserialize(reader);
var version = reader.ReadInt();
Corrosive = reader.ReadBool();
m_Timer = Timer.DelayCall(TimeSpan.Zero, TimeSpan.FromSeconds(1), OnTick);
m_Ticks = ItemID == 0x122A ? 0 : 30;
}
}
}