ModernUO/Projects/Scripts/Items/Guilds/Guildstone.cs
Kamron Batman 179cb50557 Updates Packets & Randomizer (#43)
* Fixes a bug with the main loop. Removes unnecessary optimizations for RDRand.

* WIP - Rewriting packets.

* Cleanup and updates README

* Converts more packets

* Fixes header

* Converts Effects packets.

* Forgot the send command

* Adds the start of containers packets.

* Adds message packets with caching

* Extends the send methods

* Starts to add Acquire methods

* Converted the packets

* Cleanup

* Cleanup

* Adds more packets

* Adds more packets

* Fixes clearing arrays from pool. Adds Mobile Incoming

* Converts more packets.

* Moves more packets

* Moves more packets

* Test compression

* Merges

* Migrating to an idiomatic syntax that also supports compression, and proxying.

* Optimize the stack alloc. Changes attributes

* Converted container packets

* Visual Studio doesn't auto save files. I am still getting used to subpar IDEs.

* Adds static packet caching. Will profile later. Converts more packets

* Fixes packets and changes how compression is configured

* WIP - Adds basics for Gumps. Not finished though.

* Fix file

* Fixes formatting

* Changed SpanWriter to be more idiomatic.

* Fixes Span vs RawSpan and missing stackallocs

* Converts over some more gumps

* WIP - Deletes 32bit support.

* Drops RDRand32 support.

* Fixes gump compilation

* Converting gump components

* Removes old huffman compression function

* Revert signature for backwards compatibility

* WIP - Converting more gump components

* Creates ArraySet for the strings. Updates AppendTo to reference that.

* Converts the maining gump components

* Cleans up gump components

* Cleans up directives

* Cleans up ArraySet and moves it. Adds null-coalescing-assignment

* Cleanup, Target Packets, and C# 8 changes.

* Removed OPL Packet

* World packets

* Fixing packet uses

* Cleans up code. Fixes packet uses in various places.

* More cleanup for packets

* Code cleanup

* Converts more packet uses and cleans up more code

* More code cleanup

* Finishes fixing the packets in Item

* Updates secure trade packets

* Updates core and gets it to compile.

* Moved packets to scripts. Fixed account handler use of packets

* Code cleanup

* Updates chat packets

* Code cleanuo

* Adds party packets, but need to implement them.

* Party packets WIP

* Finishes party packets

* Rearrange movement namespaces and classes

* Finishes plant packets

* Code Formatting

* Fixes moving effects

* Code cleanup, eliminates equipinfo

* Adds more packets. Fixes bugs with various packets.

* Finishes mahjon packets

* Fixes mahjong packet

* Code cleanup

* Finishes mahjong packets

* Adds Map packets

* Add multifacet maps and charts

* Cleans up some packets with UTF8

* Optimizes packets

* Cleans up more packets. Moves the MessageHelper

* Removes assistant support. Removes extended protocol. Incorporates MapUO packets as normal packets.

* Updates protocol extensions packet receiver

* Fixes a few bugs. Fixes a few more packets.

* Code cleanup and fixing more packets

* Fixes packet effects

* Cleaned up more code

* Buff Icon cleanup

* Removed unused constructors

* Code Cleanup. Adds BoatHS Packets

* Moves house files. Updates house foundation packets.

* Deployment cleanup

* Fixes:

* Code cleanup

* More code cleanup

* More code cleanup

* Cleaned up BaseHouse

* Enforces styling

* Converts foreach to linq where possible.

* Dont need that

* Goals/Readme updates

* Removes 32bit support at the highest level. Turns on HRT by default.

* Code cleanup. Fixes extended features packet.

* Fixes various bugs

* Code cleanup

* Code cleanup

* Code cleanup. Fixes gump X/Y assignment.

* Code cleanup using |= operator

* More code cleanup

* Cleanup

* Fixes spacing issues. Thanks Visual Studio. You suck.

* Compiler error

* Fixes NPE from RunUO 2.7

* Renames ScriptCompiler to AssemblyHandler. Fixes packets. Updates README

* Fixes more packets. Stupid trailing nulls.

* Fixes various bugs.

* Fixes for gumps

* Fixes more gump stuff. Going to split it out later since it is getting insane

* Recoded the gump writing

* WIP

* *Added output path of scripts project to dev branch
*Activated debugging in code
2019-11-11 12:40:16 +01:00

422 lines
10 KiB
C#

using System;
using Server.Factions;
using Server.Guilds;
using Server.Gumps;
using Server.Multis;
using Server.Network;
using Server.Targeting;
namespace Server.Items
{
public class Guildstone : Item, IAddon, IChopable
{
private bool m_BeforeChangeover;
private string m_GuildAbbrev;
private string m_GuildName;
public Guildstone(Guild g) : this(g, g.Name, g.Abbreviation)
{
}
public Guildstone(Guild g, string guildName, string abbrev) : base(Guild.NewGuildSystem ? 0xED6 : 0xED4)
{
Guild = g;
m_GuildName = guildName;
m_GuildAbbrev = abbrev;
Movable = false;
}
public Guildstone(Serial serial) : base(serial)
{
}
[CommandProperty(AccessLevel.GameMaster)]
public string GuildName
{
get => m_GuildName;
set
{
m_GuildName = value;
InvalidateProperties();
}
}
[CommandProperty(AccessLevel.GameMaster)]
public string GuildAbbrev
{
get => m_GuildAbbrev;
set
{
m_GuildAbbrev = value;
InvalidateProperties();
}
}
[CommandProperty(AccessLevel.GameMaster)]
public Guild Guild{ get; private set; }
public override int LabelNumber => 1041429; // a guildstone
#region IChopable Members
public void OnChop(Mobile from)
{
if (!Guild.NewGuildSystem)
return;
BaseHouse house = BaseHouse.FindHouseAt(this);
bool contains = false;
if (house == null && m_BeforeChangeover || house?.IsOwner(from) == true && (contains = house.Addons.Contains(this)))
{
Effects.PlaySound(GetWorldLocation(), Map, 0x3B3);
from.SendLocalizedMessage(500461); // You destroy the item.
Delete();
if (contains)
house.Addons.Remove(this);
Item deed = Deed;
if (deed != null)
from.AddToBackpack(deed);
}
}
#endregion
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
if (Guild?.Disbanded == false)
{
m_GuildName = Guild.Name;
m_GuildAbbrev = Guild.Abbreviation;
}
writer.Write(3); // version
writer.Write(m_BeforeChangeover);
writer.Write(m_GuildName);
writer.Write(m_GuildAbbrev);
writer.Write(Guild);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 3:
{
m_BeforeChangeover = reader.ReadBool();
goto case 2;
}
case 2:
{
m_GuildName = reader.ReadString();
m_GuildAbbrev = reader.ReadString();
goto case 1;
}
case 1:
{
Guild = reader.ReadGuild() as Guild;
goto case 0;
}
case 0:
{
break;
}
}
if (Guild.NewGuildSystem && ItemID == 0xED4)
ItemID = 0xED6;
m_BeforeChangeover |= version <= 2;
if (Guild.NewGuildSystem && m_BeforeChangeover)
Timer.DelayCall(TimeSpan.Zero, AddToHouse);
if (!Guild.NewGuildSystem && Guild == null)
Delete();
}
private void AddToHouse()
{
BaseHouse house = BaseHouse.FindHouseAt(this);
if (Guild.NewGuildSystem && m_BeforeChangeover && house?.Addons.Contains(this) == false)
{
house.Addons.Add(this);
m_BeforeChangeover = false;
}
}
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
if (Guild?.Disbanded == false)
{
string name;
string abbr;
if ((name = Guild.Name) == null || (name = name.Trim()).Length <= 0)
name = "(unnamed)";
if ((abbr = Guild.Abbreviation) == null || (abbr = abbr.Trim()).Length <= 0)
abbr = "";
//list.Add( 1060802, Utility.FixHtml( name ) ); // Guild name: ~1_val~
list.Add(1060802, $"{Utility.FixHtml(name)} [{Utility.FixHtml(abbr)}]");
}
else if (m_GuildName != null && m_GuildAbbrev != null)
{
list.Add(1060802, $"{Utility.FixHtml(m_GuildName)} [{Utility.FixHtml(m_GuildAbbrev)}]");
}
}
public override void OnSingleClick(Mobile from)
{
base.OnSingleClick(from);
if (Guild?.Disbanded == false)
{
string name;
if ((name = Guild.Name) == null || (name = name.Trim()).Length <= 0)
name = "(unnamed)";
LabelTo(from, name);
}
else if (m_GuildName != null)
{
LabelTo(from, m_GuildName);
}
}
public override void OnAfterDelete()
{
if (!Guild.NewGuildSystem && Guild?.Disbanded == false)
Guild.Disband();
}
public override void OnDoubleClick(Mobile from)
{
if (Guild.NewGuildSystem)
return;
if (Guild?.Disbanded != false)
{
Delete();
}
else if (!from.InRange(GetWorldLocation(), 2))
{
from.SendLocalizedMessage(500446); // That is too far away.
}
else if (Guild.Accepted.Contains(from))
{
#region Factions
PlayerState guildState = PlayerState.Find(Guild.Leader);
PlayerState targetState = PlayerState.Find(from);
Faction guildFaction = guildState?.Faction;
Faction targetFaction = targetState?.Faction;
if (guildFaction != targetFaction || targetState?.IsLeaving == true)
return;
if (guildState != null && targetState != null)
targetState.Leaving = guildState.Leaving;
#endregion
Guild.Accepted.Remove(from);
Guild.AddMember(from);
GuildGump.EnsureClosed(from);
from.SendGump(new GuildGump(from, Guild));
}
else if (from.AccessLevel < AccessLevel.GameMaster && !Guild.IsMember(from))
Packets.SendMessageLocalized(from.NetState, Serial, ItemID, MessageType.Regular, 0x3B2, 3,
501158); // You are not a member ...
else
{
GuildGump.EnsureClosed(from);
from.SendGump(new GuildGump(from, Guild));
}
}
public Item Deed => new GuildstoneDeed(Guild, m_GuildName, m_GuildAbbrev);
public bool CouldFit(IPoint3D p, Map map) => map.CanFit(p.X, p.Y, p.Z, ItemData.Height);
#endregion
}
[Flippable(0x14F0, 0x14EF)]
public class GuildstoneDeed : Item
{
private string m_GuildAbbrev;
private string m_GuildName;
public GuildstoneDeed(Guild g = null, string guildName = null, string abbrev = null) :
base(0x14F0)
{
Guild = g;
m_GuildName = guildName;
m_GuildAbbrev = abbrev;
Weight = 1.0;
}
public GuildstoneDeed(Serial serial) : base(serial)
{
}
public override int LabelNumber => 1041233; // deed to a guildstone
[CommandProperty(AccessLevel.GameMaster)]
public string GuildName
{
get => m_GuildName;
set
{
m_GuildName = value;
InvalidateProperties();
}
}
[CommandProperty(AccessLevel.GameMaster)]
public string GuildAbbrev
{
get => m_GuildAbbrev;
set
{
m_GuildAbbrev = value;
InvalidateProperties();
}
}
[CommandProperty(AccessLevel.GameMaster)]
public Guild Guild{ get; private set; }
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
if (Guild?.Disbanded == false)
{
m_GuildName = Guild.Name;
m_GuildAbbrev = Guild.Abbreviation;
}
writer.Write(1); // version
writer.Write(m_GuildName);
writer.Write(m_GuildAbbrev);
writer.Write(Guild);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
switch (version)
{
case 1:
{
m_GuildName = reader.ReadString();
m_GuildAbbrev = reader.ReadString();
Guild = reader.ReadGuild() as Guild;
break;
}
}
}
public override void GetProperties(ObjectPropertyList list)
{
base.GetProperties(list);
if (Guild?.Disbanded == false)
{
string name;
string abbr;
if ((name = Guild.Name) == null || (name = name.Trim()).Length <= 0)
name = "(unnamed)";
if ((abbr = Guild.Abbreviation) == null || (abbr = abbr.Trim()).Length <= 0)
abbr = "";
//list.Add( 1060802, Utility.FixHtml( name ) ); // Guild name: ~1_val~
list.Add(1060802, $"{Utility.FixHtml(name)} [{Utility.FixHtml(abbr)}]");
}
else if (m_GuildName != null && m_GuildAbbrev != null)
list.Add(1060802, $"{Utility.FixHtml(m_GuildName)} [{Utility.FixHtml(m_GuildAbbrev)}]");
}
public override void OnDoubleClick(Mobile from)
{
if (IsChildOf(from.Backpack))
{
BaseHouse house = BaseHouse.FindHouseAt(from);
if (house?.IsOwner(from) == true)
{
from.SendLocalizedMessage(1062838); // Where would you like to place this decoration?
from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget);
}
else
from.SendLocalizedMessage(502092); // You must be in your house to do this.
}
else
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
}
public void Placement_OnTarget(Mobile from, object targeted)
{
if (!(targeted is IPoint3D p) || Deleted)
return;
Point3D loc = new Point3D(p);
BaseHouse house = BaseHouse.FindHouseAt(loc, from.Map, 16);
if (IsChildOf(from.Backpack))
{
if (house?.IsOwner(from) == true)
{
Item addon = new Guildstone(Guild, m_GuildName, m_GuildAbbrev);
addon.MoveToWorld(loc, from.Map);
house.Addons.Add(addon);
Delete();
}
else
from.SendLocalizedMessage(1042036); // That location is not in your house.
}
else
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
}
}
}