servuo/Scripts/Items/Addons/BaseAddonContainer.cs

327 lines
9.8 KiB
C#
Raw Permalink Normal View History

+ Removed most file header regions. + Add MONO to Makefile compile definitions. + Update Ultima SDK to support MONO compile definition. + Rename Properties Gump parent directory to prevent VS issues. + Console error messages will now use red instead of dark red font. + Add crash state handler function to Core. + AI optimizations and housekeeping. + Context Menu optimizations and housekeeping. + Add ability to drop throttled packets. + Add string parsing support to Rectangle3D. + Optimize guild messages and chat. + IAddon implements IChopable. + Add more flexibility for altering Mobile names. + Add ability to enable or disable OPL for individual mobiles. + Optimize damaging regions and ensure timers are removed properly. + Update Welcome Timer with more intuitive message groups. + Normalize all virtue related objects to the Server.Services.Virtues namespace. + Add ability for ISpawner to append OPL and Context Menus to their spawn. + Add EventSink events for obtaining items, equipping items, context menus, and world broadcasts. + Add ability to lock a creature's direction and movement regardless of AI manipulation. + Add ability to dynamically change a creature's approach range and wait state. + Add extended enumeration features for AOS attributes. + Add ability to control whether creatures have blood, and its color. + Expose corpse flag manipulation methods. + Add ability to prevent criminal action when looting a corpse. + Corpse will now be permanently tagged as murderer at time of death if owner is a murderer. + Add TextDefinition support for Commodity Deed descriptions. + House add-on and component optimizations and housekeeping. + Item light is no longer backed by the direction property. + ITool implements IEntity. + Prevent trading of Siege Bless items. + Guards are naturally be immune to guards. + Siege Shard initialization housekeeping. + Character Creation housekeeping. + Generic commands housekeeping. + Add Mark command for staff.
2018-07-19 22:12:52 +01:00
#region References
2013-10-28 07:09:42 +00:00
using Server.Multis;
using System.Collections.Generic;
+ Removed most file header regions. + Add MONO to Makefile compile definitions. + Update Ultima SDK to support MONO compile definition. + Rename Properties Gump parent directory to prevent VS issues. + Console error messages will now use red instead of dark red font. + Add crash state handler function to Core. + AI optimizations and housekeeping. + Context Menu optimizations and housekeeping. + Add ability to drop throttled packets. + Add string parsing support to Rectangle3D. + Optimize guild messages and chat. + IAddon implements IChopable. + Add more flexibility for altering Mobile names. + Add ability to enable or disable OPL for individual mobiles. + Optimize damaging regions and ensure timers are removed properly. + Update Welcome Timer with more intuitive message groups. + Normalize all virtue related objects to the Server.Services.Virtues namespace. + Add ability for ISpawner to append OPL and Context Menus to their spawn. + Add EventSink events for obtaining items, equipping items, context menus, and world broadcasts. + Add ability to lock a creature's direction and movement regardless of AI manipulation. + Add ability to dynamically change a creature's approach range and wait state. + Add extended enumeration features for AOS attributes. + Add ability to control whether creatures have blood, and its color. + Expose corpse flag manipulation methods. + Add ability to prevent criminal action when looting a corpse. + Corpse will now be permanently tagged as murderer at time of death if owner is a murderer. + Add TextDefinition support for Commodity Deed descriptions. + House add-on and component optimizations and housekeeping. + Item light is no longer backed by the direction property. + ITool implements IEntity. + Prevent trading of Siege Bless items. + Guards are naturally be immune to guards. + Siege Shard initialization housekeeping. + Character Creation housekeeping. + Generic commands housekeeping. + Add Mark command for staff.
2018-07-19 22:12:52 +01:00
#endregion
2013-10-28 07:09:42 +00:00
namespace Server.Items
{
public abstract class BaseAddonContainer : BaseContainer, IChopable, IAddon
{
private CraftResource m_Resource;
private List<AddonContainerComponent> m_Components;
public BaseAddonContainer(int itemID)
: base(itemID)
{
Movable = false;
AddonComponent.ApplyLightTo(this);
m_Components = new List<AddonContainerComponent>();
}
public BaseAddonContainer(Serial serial)
: base(serial)
{ }
2020-04-16 20:21:33 -04:00
public override bool DisplayWeight => false;
[Hue, CommandProperty(AccessLevel.GameMaster)]
public override int Hue
{
get { return base.Hue; }
set
{
if (base.Hue != value)
{
base.Hue = value;
if (!Deleted && ShareHue && m_Components != null)
{
Hue = value;
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent c in m_Components)
c.Hue = value;
}
}
}
}
[CommandProperty(AccessLevel.GameMaster)]
public CraftResource Resource
{
get { return m_Resource; }
set
{
if (m_Resource != value)
{
m_Resource = value;
Hue = CraftResources.GetHue(m_Resource);
InvalidateProperties();
}
}
}
2020-04-16 20:21:33 -04:00
public virtual bool RetainDeedHue => false;
public virtual bool NeedsWall => false;
public virtual bool ShareHue => true;
public virtual Point3D WallPosition => Point3D.Zero;
public virtual BaseAddonContainerDeed Deed => null;
public List<AddonContainerComponent> Components => m_Components;
Item IAddon.Deed => Deed;
public override void OnLocationChange(Point3D oldLoc)
{
base.OnLocationChange(oldLoc);
if (Deleted)
return;
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent c in m_Components)
c.Location = new Point3D(X + c.Offset.X, Y + c.Offset.Y, Z + c.Offset.Z);
}
public override void OnMapChange()
{
base.OnMapChange();
if (Deleted)
return;
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent c in m_Components)
c.Map = Map;
}
public override void OnDelete()
{
2020-04-16 18:32:20 -04:00
BaseHouse house = BaseHouse.FindHouseAt(this);
if (house != null)
house.Addons.Remove(this);
2020-04-16 18:32:20 -04:00
List<AddonContainerComponent> components = new List<AddonContainerComponent>(m_Components);
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent component in components)
{
component.Addon = null;
component.Delete();
}
components.Clear();
components.TrimExcess();
base.OnDelete();
}
public virtual void UpdateProperties()
{
InvalidateProperties();
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent o in Components)
{
o.InvalidateProperties();
}
}
public virtual void GetProperties(ObjectPropertyList list, AddonContainerComponent c)
{
}
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
if (!CraftResources.IsStandard(m_Resource))
list.Add(CraftResources.GetLocalizationNumber(m_Resource));
}
public override void OnAfterDelete()
{
base.OnAfterDelete();
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent c in m_Components)
c.Delete();
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
writer.WriteItemList(m_Components);
writer.Write((int)m_Resource);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
+ Removed most file header regions. + Add MONO to Makefile compile definitions. + Update Ultima SDK to support MONO compile definition. + Rename Properties Gump parent directory to prevent VS issues. + Console error messages will now use red instead of dark red font. + Add crash state handler function to Core. + AI optimizations and housekeeping. + Context Menu optimizations and housekeeping. + Add ability to drop throttled packets. + Add string parsing support to Rectangle3D. + Optimize guild messages and chat. + IAddon implements IChopable. + Add more flexibility for altering Mobile names. + Add ability to enable or disable OPL for individual mobiles. + Optimize damaging regions and ensure timers are removed properly. + Update Welcome Timer with more intuitive message groups. + Normalize all virtue related objects to the Server.Services.Virtues namespace. + Add ability for ISpawner to append OPL and Context Menus to their spawn. + Add EventSink events for obtaining items, equipping items, context menus, and world broadcasts. + Add ability to lock a creature's direction and movement regardless of AI manipulation. + Add ability to dynamically change a creature's approach range and wait state. + Add extended enumeration features for AOS attributes. + Add ability to control whether creatures have blood, and its color. + Expose corpse flag manipulation methods. + Add ability to prevent criminal action when looting a corpse. + Corpse will now be permanently tagged as murderer at time of death if owner is a murderer. + Add TextDefinition support for Commodity Deed descriptions. + House add-on and component optimizations and housekeeping. + Item light is no longer backed by the direction property. + ITool implements IEntity. + Prevent trading of Siege Bless items. + Guards are naturally be immune to guards. + Siege Shard initialization housekeeping. + Character Creation housekeeping. + Generic commands housekeeping. + Add Mark command for staff.
2018-07-19 22:12:52 +01:00
2020-04-16 18:32:20 -04:00
int version = reader.ReadInt();
+ Removed most file header regions. + Add MONO to Makefile compile definitions. + Update Ultima SDK to support MONO compile definition. + Rename Properties Gump parent directory to prevent VS issues. + Console error messages will now use red instead of dark red font. + Add crash state handler function to Core. + AI optimizations and housekeeping. + Context Menu optimizations and housekeeping. + Add ability to drop throttled packets. + Add string parsing support to Rectangle3D. + Optimize guild messages and chat. + IAddon implements IChopable. + Add more flexibility for altering Mobile names. + Add ability to enable or disable OPL for individual mobiles. + Optimize damaging regions and ensure timers are removed properly. + Update Welcome Timer with more intuitive message groups. + Normalize all virtue related objects to the Server.Services.Virtues namespace. + Add ability for ISpawner to append OPL and Context Menus to their spawn. + Add EventSink events for obtaining items, equipping items, context menus, and world broadcasts. + Add ability to lock a creature's direction and movement regardless of AI manipulation. + Add ability to dynamically change a creature's approach range and wait state. + Add extended enumeration features for AOS attributes. + Add ability to control whether creatures have blood, and its color. + Expose corpse flag manipulation methods. + Add ability to prevent criminal action when looting a corpse. + Corpse will now be permanently tagged as murderer at time of death if owner is a murderer. + Add TextDefinition support for Commodity Deed descriptions. + House add-on and component optimizations and housekeeping. + Item light is no longer backed by the direction property. + ITool implements IEntity. + Prevent trading of Siege Bless items. + Guards are naturally be immune to guards. + Siege Shard initialization housekeeping. + Character Creation housekeeping. + Generic commands housekeeping. + Add Mark command for staff.
2018-07-19 22:12:52 +01:00
m_Components = reader.ReadStrongItemList<AddonContainerComponent>();
m_Resource = (CraftResource)reader.ReadInt();
2013-10-28 07:09:42 +00:00
AddonComponent.ApplyLightTo(this);
}
2013-10-28 07:09:42 +00:00
public virtual void DropItemsToGround()
{
2020-04-16 18:32:20 -04:00
for (int i = Items.Count - 1; i >= 0; i--)
Items[i].MoveToWorld(Location);
}
2013-10-28 07:09:42 +00:00
public void AddComponent(AddonContainerComponent c, int x, int y, int z)
{
if (Deleted)
return;
2013-10-28 07:09:42 +00:00
m_Components.Add(c);
2013-10-28 07:09:42 +00:00
c.Addon = this;
c.Offset = new Point3D(x, y, z);
c.MoveToWorld(new Point3D(X + x, Y + y, Z + z), Map);
}
2013-10-28 07:09:42 +00:00
public AddonFitResult CouldFit(IPoint3D p, Map map, Mobile from, ref BaseHouse house)
{
if (Deleted)
return AddonFitResult.Blocked;
2013-10-28 07:09:42 +00:00
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent c in m_Components)
{
2020-04-16 18:32:20 -04:00
Point3D p3D = new Point3D(p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z);
2013-10-28 07:09:42 +00:00
if (!map.CanFit(p3D.X, p3D.Y, p3D.Z, c.ItemData.Height, false, true, (c.Z == 0)))
return AddonFitResult.Blocked;
if (!BaseAddon.CheckHouse(from, p3D, map, c.ItemData.Height, ref house))
return AddonFitResult.NotInHouse;
2013-10-28 07:09:42 +00:00
if (c.NeedsWall)
{
2020-04-16 18:32:20 -04:00
Point3D wall = c.WallPosition;
2013-10-28 07:09:42 +00:00
if (!BaseAddon.IsWall(p3D.X + wall.X, p3D.Y + wall.Y, p3D.Z + wall.Z, map))
return AddonFitResult.NoWall;
}
}
2013-10-28 07:09:42 +00:00
2020-04-16 18:32:20 -04:00
Point3D p3 = new Point3D(p.X, p.Y, p.Z);
2013-10-28 07:09:42 +00:00
if (!map.CanFit(p3.X, p3.Y, p3.Z, ItemData.Height, false, true, (Z == 0)))
return AddonFitResult.Blocked;
if (!BaseAddon.CheckHouse(from, p3, map, ItemData.Height, ref house))
return AddonFitResult.NotInHouse;
2013-10-28 07:09:42 +00:00
if (NeedsWall)
{
2020-04-16 18:32:20 -04:00
Point3D wall = WallPosition;
2013-10-28 07:09:42 +00:00
if (!BaseAddon.IsWall(p3.X + wall.X, p3.Y + wall.Y, p3.Z + wall.Z, map))
return AddonFitResult.NoWall;
}
2013-10-28 07:09:42 +00:00
if (house != null)
{
2020-04-16 18:32:20 -04:00
List<Item> doors = house.Doors;
2013-10-28 07:09:42 +00:00
2020-04-16 18:32:20 -04:00
for (int i = 0; i < doors.Count; ++i)
{
2020-04-16 18:32:20 -04:00
BaseDoor door = doors[i] as BaseDoor;
2013-10-28 07:09:42 +00:00
if (door == null)
continue;
2020-04-16 18:32:20 -04:00
Point3D doorLoc = door.GetWorldLocation();
int doorHeight = door.ItemData.CalcHeight;
2013-10-28 07:09:42 +00:00
2020-04-16 18:32:20 -04:00
foreach (AddonContainerComponent c in m_Components)
{
2020-04-16 18:32:20 -04:00
Point3D addonLoc = new Point3D(p.X + c.Offset.X, p.Y + c.Offset.Y, p.Z + c.Offset.Z);
int addonHeight = c.ItemData.CalcHeight;
2013-10-28 07:09:42 +00:00
if (Utility.InRange(doorLoc, addonLoc, 1) && (addonLoc.Z == doorLoc.Z ||
((addonLoc.Z + addonHeight) > doorLoc.Z && (doorLoc.Z + doorHeight) > addonLoc.Z)))
return AddonFitResult.DoorTooClose;
}
2013-10-28 07:09:42 +00:00
2020-04-16 18:32:20 -04:00
Point3D addonLo = new Point3D(p.X, p.Y, p.Z);
int addonHeigh = ItemData.CalcHeight;
2013-10-28 07:09:42 +00:00
if (Utility.InRange(doorLoc, addonLo, 1) && (addonLo.Z == doorLoc.Z ||
((addonLo.Z + addonHeigh) > doorLoc.Z && (doorLoc.Z + doorHeight) > addonLo.Z)))
return AddonFitResult.DoorTooClose;
}
}
return AddonFitResult.Valid;
}
2013-10-28 07:09:42 +00:00
public bool CouldFit(IPoint3D p, Map map)
{
BaseHouse house = null;
return (CouldFit(p, map, null, ref house) == AddonFitResult.Valid);
}
public virtual void OnChop(Mobile from)
{
2020-04-16 18:32:20 -04:00
BaseHouse house = BaseHouse.FindHouseAt(this);
if (house != null && house.IsOwner(from))
{
if (!IsSecure)
{
Effects.PlaySound(GetWorldLocation(), Map, 0x3B3);
from.SendLocalizedMessage(500461); // You destroy the item.
2020-04-16 18:32:20 -04:00
int hue = 0;
if (RetainDeedHue)
{
2020-04-16 18:32:20 -04:00
for (int i = 0; hue == 0 && i < m_Components.Count; ++i)
{
2020-04-16 18:32:20 -04:00
AddonContainerComponent c = m_Components[i];
if (c.Hue != 0)
hue = c.Hue;
}
}
2013-10-28 07:09:42 +00:00
DropItemsToGround();
Delete();
2013-10-28 07:09:42 +00:00
house.Addons.Remove(this);
2020-04-16 18:32:20 -04:00
BaseAddonContainerDeed deed = Deed;
2013-10-28 07:09:42 +00:00
if (deed != null)
{
deed.Resource = Resource;
2013-10-28 07:09:42 +00:00
if (RetainDeedHue)
deed.Hue = hue;
from.AddToBackpack(deed);
}
}
else
from.SendLocalizedMessage(1074870); // This item must be unlocked/unsecured before re-deeding it.
}
}
public virtual void OnComponentLoaded(AddonContainerComponent c)
{ }
public virtual void OnComponentUsed(AddonContainerComponent c, Mobile from)
{
if (!Deleted)
{
OnDoubleClick(from);
}
}
}
}