fix: Updates pool of acid (#1028)
- [X] Removes duplicate Created property - [X] Removes allocation while damaging mobiles - [X] Adds manual dirty checking since we won't be codegenning it and we won't be serializing it.
This commit is contained in:
parent
dfdadd3204
commit
f2ced497ec
1 changed files with 76 additions and 81 deletions
|
|
@ -1,102 +1,97 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Collections;
|
||||
using Server.Mobiles;
|
||||
|
||||
namespace Server.Items
|
||||
namespace Server.Items;
|
||||
|
||||
[ManualDirtyChecking]
|
||||
[TypeAlias("Server.Items.AcidSlime")]
|
||||
public class PoolOfAcid : Item
|
||||
{
|
||||
[TypeAlias("Server.Items.AcidSlime")]
|
||||
public class PoolOfAcid : Item
|
||||
private readonly TimeSpan _duration;
|
||||
private readonly int _maxDamage;
|
||||
private readonly int _minDamage;
|
||||
private TimerExecutionToken _timerToken;
|
||||
private bool _drying;
|
||||
|
||||
[Constructible]
|
||||
public PoolOfAcid() : this(TimeSpan.FromSeconds(10.0), 2, 5)
|
||||
{
|
||||
private readonly DateTime m_Created;
|
||||
private readonly TimeSpan m_Duration;
|
||||
private readonly int m_MaxDamage;
|
||||
private readonly int m_MinDamage;
|
||||
private TimerExecutionToken _timerToken;
|
||||
private bool m_Drying;
|
||||
}
|
||||
|
||||
[Constructible]
|
||||
public PoolOfAcid() : this(TimeSpan.FromSeconds(10.0), 2, 5)
|
||||
[Constructible]
|
||||
public PoolOfAcid(TimeSpan duration, int minDamage, int maxDamage) : base(0x122A)
|
||||
{
|
||||
Hue = 0x3F;
|
||||
Movable = false;
|
||||
|
||||
_minDamage = minDamage;
|
||||
_maxDamage = maxDamage;
|
||||
_duration = duration;
|
||||
|
||||
Timer.StartTimer(TimeSpan.Zero, TimeSpan.FromSeconds(1), OnTick, out _timerToken);
|
||||
}
|
||||
|
||||
public PoolOfAcid(Serial serial) : base(serial)
|
||||
{
|
||||
}
|
||||
|
||||
public override string DefaultName => "a pool of acid";
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
_timerToken.Cancel();
|
||||
}
|
||||
|
||||
private void OnTick()
|
||||
{
|
||||
var now = Core.Now;
|
||||
var age = now - Created;
|
||||
|
||||
if (age > _duration)
|
||||
{
|
||||
Delete();
|
||||
return;
|
||||
}
|
||||
|
||||
[Constructible]
|
||||
public PoolOfAcid(TimeSpan duration, int minDamage, int maxDamage)
|
||||
: base(0x122A)
|
||||
if (!_drying && age > _duration - age)
|
||||
{
|
||||
Hue = 0x3F;
|
||||
Movable = false;
|
||||
|
||||
m_MinDamage = minDamage;
|
||||
m_MaxDamage = maxDamage;
|
||||
m_Created = Core.Now;
|
||||
m_Duration = duration;
|
||||
|
||||
Timer.StartTimer(TimeSpan.Zero, TimeSpan.FromSeconds(1), OnTick, out _timerToken);
|
||||
_drying = true;
|
||||
ItemID = 0x122B;
|
||||
}
|
||||
|
||||
public PoolOfAcid(Serial serial) : base(serial)
|
||||
using var queue = PooledRefQueue<Mobile>.Create();
|
||||
|
||||
foreach (var m in GetMobilesInRange(0))
|
||||
{
|
||||
}
|
||||
|
||||
public override string DefaultName => "a pool of acid";
|
||||
|
||||
public override void OnDelete()
|
||||
{
|
||||
_timerToken.Cancel();
|
||||
}
|
||||
|
||||
private void OnTick()
|
||||
{
|
||||
var now = Core.Now;
|
||||
var age = now - m_Created;
|
||||
|
||||
if (age > m_Duration)
|
||||
if (m.Alive && !m.IsDeadBondedPet && (m is not BaseCreature bc || bc.Controlled || bc.Summoned))
|
||||
{
|
||||
Delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_Drying && age > m_Duration - age)
|
||||
{
|
||||
m_Drying = true;
|
||||
ItemID = 0x122B;
|
||||
}
|
||||
|
||||
var toDamage = new List<Mobile>();
|
||||
|
||||
foreach (var m in GetMobilesInRange(0))
|
||||
{
|
||||
if (m.Alive && !m.IsDeadBondedPet && (m is not BaseCreature bc || bc.Controlled || bc.Summoned))
|
||||
{
|
||||
toDamage.Add(m);
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < toDamage.Count; i++)
|
||||
{
|
||||
Damage(toDamage[i]);
|
||||
}
|
||||
queue.Enqueue(m);
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMoveOver(Mobile m)
|
||||
{
|
||||
Damage(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Damage(Mobile m)
|
||||
{
|
||||
m.Damage(Utility.RandomMinMax(m_MinDamage, m_MaxDamage));
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
// Don't serialize these
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
while (queue.Count > 0)
|
||||
{
|
||||
Damage(queue.Dequeue());
|
||||
}
|
||||
}
|
||||
|
||||
public override bool OnMoveOver(Mobile m)
|
||||
{
|
||||
Damage(m);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Damage(Mobile m)
|
||||
{
|
||||
m.Damage(Utility.RandomMinMax(_minDamage, _maxDamage));
|
||||
}
|
||||
|
||||
public override void Serialize(IGenericWriter writer)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Deserialize(IGenericReader reader)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue