using System.Collections.Generic;
using System.Linq;
using ACE.Entity.Enum;
using ACE.Server.Network.GameMessages.Messages;
namespace ACE.Server.WorldObjects
{
partial class Creature
{
///
/// Called every ~5 seconds for Creatures
///
public override void Heartbeat(double currentUnixTime)
{
var expireItems = new List();
// added where clause
foreach (var wo in EquippedObjects.Values.Where(i => i.EnchantmentManager.HasEnchantments || i.Lifespan.HasValue))
{
// FIXME: wo.NextHeartbeatTime is double.MaxValue here
//if (wo.NextHeartbeatTime <= currentUnixTime)
//wo.Heartbeat(currentUnixTime);
// just go by parent heartbeats, only for enchantments?
// TODO: handle players dropping / picking up items
wo.EnchantmentManager.HeartBeat(CachedHeartbeatInterval);
if (wo.IsLifespanSpent)
expireItems.Add(wo);
}
VitalHeartBeat();
EmoteManager.HeartBeat();
DamageHistory.TryPrune();
// delete items when RemainingLifespan <= 0
foreach (var expireItem in expireItems)
{
expireItem.DeleteObject(this);
if (this is Player player)
player.Session.Network.EnqueueSend(new GameMessageSystemChat($"Its lifespan finished, your {expireItem.Name} crumbles to dust.", ChatMessageType.Broadcast));
}
base.Heartbeat(currentUnixTime);
}
}
}