/// <summary> /// Handles the ObjectDestroyed event. Only DataAccess should call this directly. /// </summary> /// <param name="source">The object raising the event</param> /// <param name="args">The generic event args</param> protected override void OnObjectDestroyed(object source, CacheObjectEventArgs args) { if (args.CacheType == CacheType.Instance) { DataAccess.RemoveMany(_entityList, args.CacheType); } }
/// <summary> /// Handles death for the entity. Does not remove from cache. /// </summary> protected virtual void HandleDeath(object source, CacheObjectEventArgs args) { if (args.ID == Instance) { // TODO: Handle soulbound items for players var newCorpse = new Storage { Name = "corpse " + Name, ShortDescription = $"{ShortDescription}'s corpse.", LongDescription = $"{ShortDescription}'s corpse.", }; newCorpse.Tier.Level = Tier.Level; DataAccess.Add <Storage>(newCorpse, CacheType.Instance); foreach (var invItem in GetInventoryItems().Concat(GetEquippedItems())) { newCorpse.AddEntity(invItem.Instance, invItem); } _inventory.RemoveAllEntities(); _equipment.RemoveAllEntities(); GetInstanceParentRoom()?.StorageItems.AddEntity(newCorpse.Instance, newCorpse, false); } else { // TODO: Does HandleDeath need to allow for situations where the entity itself isn't the one dying? } }
/// <summary> /// Raises the Entity Added event /// </summary> /// <param name="args">The event args</param> protected void OnEntityAdded(CacheObjectEventArgs args) { var handler = EntityAdded; if (handler != null) { EntityAdded.Invoke(this, args); } }
/// <summary> /// Invokes the EntityDied event /// </summary> /// <param name="args">The event args</param> protected virtual void OnDeath(CacheObjectEventArgs args) { var handler = EntityDied; if (handler != null) { EntityDied.Invoke(this, args); } }
/// <summary> /// Handles the CacheObjectRemoved event. Only DataAccess should call this directly. /// </summary> /// <param name="source">The object raising the event</param> /// <param name="args">The args containing the ID of the entity to remove</param> protected override void OnCacheObjectRemoved(object source, CacheObjectEventArgs args) { _entityList.Remove(args.ID); OnEntityRemoved(new CacheObjectEventArgs(args.ID, CacheType)); // Persist this entity to disk since the data structure has changed if (CacheType == CacheType.Prototype) { DataPersistence.SaveObject(this); } }
/// <summary> /// Handles the ObjectDestroyed event. Only DataAccess should call this directly. /// </summary> /// <param name="source">The object raising the event</param> /// <param name="args">The generic event args</param> override protected void OnObjectDestroyed(object source, CacheObjectEventArgs args) { // Safely remove players without deleting/disconnecting them var players = Animates.GetAllEntitiesAsObjects <Player>(); foreach (var player in players) { Animates.RemoveEntity(player?.Instance, player); } DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? Animates.Instance : Animates.Prototype, args.CacheType); DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? Items.Instance : Items.Prototype, args.CacheType); DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? ShopItems.Instance : ShopItems.Prototype, args.CacheType); DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? StorageItems.Instance : StorageItems.Prototype, args.CacheType); }
/// <summary> /// Method to handle item unequipped event /// </summary> /// <param name="args">The event args</param> public void HandleItemUnequipped(object source, CacheObjectEventArgs args) { if (CurrentPools.HitPoints > BaseMaxPools.HitPoints) { ModifyCurrentHealth(0 - (int)(CurrentPools.HitPoints - BaseMaxPools.HitPoints), false); } if (CurrentPools.Energy > BaseMaxPools.Energy) { ModifyCurrentEnergy(0 - (int)(CurrentPools.Energy - BaseMaxPools.Energy), false); } if (CurrentPools.Stamina > BaseMaxPools.Stamina) { ModifyCurrentStamina(0 - (int)(CurrentPools.Stamina - BaseMaxPools.Stamina), false); } }
protected override void OnObjectDestroyed(object source, CacheObjectEventArgs args) { DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? _inventory.Instance : _inventory.Prototype, args.CacheType); DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? _equipment.Instance : _equipment.Prototype, args.CacheType); }
/// <summary> /// Override OnObjectDestroyed to ensure all Effects are removed upon entity deletion /// </summary> /// <param name="source"></param> /// <param name="args"></param> protected override void OnObjectDestroyed(object source, CacheObjectEventArgs args) { RemoveAllEffects(); base.OnObjectDestroyed(source, args); }
/// <summary> /// Handles the ObjectDestroyed event. Only DataAccess should call this directly. /// </summary> /// <param name="source">The object raising the event</param> /// <param name="args">The generic event args</param> override protected void OnObjectDestroyed(object source, CacheObjectEventArgs args) { DataAccess.Remove <EntityContainer>(args.CacheType == CacheType.Instance ? Rooms.Instance : Rooms.Prototype, args.CacheType); }
/// <summary> /// Method to handle item equipped event /// </summary> /// <param name="args">The event args</param> public void HandleItemEquipped(object source, CacheObjectEventArgs args) { }
/// <summary> /// Drops a corpse with all items and restores player to full health. /// </summary> protected override void HandleDeath(object source, CacheObjectEventArgs args) { base.HandleDeath(source, args); ModifyCurrentHealth((int)ModifiedPools.HitPoints, false); IOHandler?.QueueRawOutput("You have been restored to full health!"); }
override protected void OnObjectDestroyed(object source, CacheObjectEventArgs args) { }