* 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
435 lines
12 KiB
C#
435 lines
12 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Server.Network;
|
|
using Server.Targeting;
|
|
|
|
namespace Server.Items
|
|
{
|
|
public class CrystalRechargeInfo
|
|
{
|
|
public static readonly CrystalRechargeInfo[] Table =
|
|
{
|
|
new CrystalRechargeInfo(typeof(Citrine), 500),
|
|
new CrystalRechargeInfo(typeof(Amber), 500),
|
|
new CrystalRechargeInfo(typeof(Tourmaline), 750),
|
|
new CrystalRechargeInfo(typeof(Emerald), 1000),
|
|
new CrystalRechargeInfo(typeof(Sapphire), 1000),
|
|
new CrystalRechargeInfo(typeof(Amethyst), 1000),
|
|
new CrystalRechargeInfo(typeof(StarSapphire), 1250),
|
|
new CrystalRechargeInfo(typeof(Diamond), 2000)
|
|
};
|
|
|
|
private CrystalRechargeInfo(Type type, int amount)
|
|
{
|
|
Type = type;
|
|
Amount = amount;
|
|
}
|
|
|
|
public Type Type{ get; }
|
|
|
|
public int Amount{ get; }
|
|
|
|
public static CrystalRechargeInfo Get(Type type) => Table.FirstOrDefault(info => info.Type == type);
|
|
}
|
|
|
|
public class BroadcastCrystal : Item
|
|
{
|
|
public static readonly int MaxCharges = 2000;
|
|
|
|
private int m_Charges;
|
|
|
|
[Constructible]
|
|
public BroadcastCrystal(int charges = 2000) : base(0x1ED0)
|
|
{
|
|
Light = LightType.Circle150;
|
|
|
|
m_Charges = charges;
|
|
|
|
Receivers = new List<ReceiverCrystal>();
|
|
}
|
|
|
|
public BroadcastCrystal(Serial serial) : base(serial)
|
|
{
|
|
}
|
|
|
|
public override int LabelNumber => 1060740; // communication crystal
|
|
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public bool Active
|
|
{
|
|
get => ItemID == 0x1ECD;
|
|
set
|
|
{
|
|
ItemID = value ? 0x1ECD : 0x1ED0;
|
|
InvalidateProperties();
|
|
}
|
|
}
|
|
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public int Charges
|
|
{
|
|
get => m_Charges;
|
|
set
|
|
{
|
|
m_Charges = value;
|
|
InvalidateProperties();
|
|
}
|
|
}
|
|
|
|
public List<ReceiverCrystal> Receivers{ get; private set; }
|
|
|
|
public override bool HandlesOnSpeech => true;
|
|
|
|
public override void GetProperties(ObjectPropertyList list)
|
|
{
|
|
base.GetProperties(list);
|
|
|
|
list.Add(Active ? 1060742 : 1060743); // active / inactive
|
|
list.Add(1060745); // broadcast
|
|
list.Add(1060741, Charges.ToString()); // charges: ~1_val~
|
|
|
|
if (Receivers.Count > 0)
|
|
list.Add(1060746, Receivers.Count.ToString()); // links: ~1_val~
|
|
}
|
|
|
|
public override void OnSingleClick(Mobile from)
|
|
{
|
|
base.OnSingleClick(from);
|
|
|
|
LabelTo(from, Active ? 1060742 : 1060743); // active / inactive
|
|
LabelTo(from, 1060745); // broadcast
|
|
LabelTo(from, 1060741, Charges.ToString()); // charges: ~1_val~
|
|
|
|
if (Receivers.Count > 0)
|
|
LabelTo(from, 1060746, Receivers.Count.ToString()); // links: ~1_val~
|
|
}
|
|
|
|
public override void OnSpeech(SpeechEventArgs e)
|
|
{
|
|
if (!Active || Receivers.Count == 0 || RootParent != null && !(RootParent is Mobile))
|
|
return;
|
|
|
|
if (e.Type == MessageType.Emote)
|
|
return;
|
|
|
|
Mobile from = e.Mobile;
|
|
string speech = e.Speech;
|
|
|
|
foreach (ReceiverCrystal receiver in new List<ReceiverCrystal>(Receivers))
|
|
if (receiver.Deleted)
|
|
{
|
|
Receivers.Remove(receiver);
|
|
}
|
|
else if (Charges > 0)
|
|
{
|
|
receiver.TransmitMessage(from, speech);
|
|
Charges--;
|
|
}
|
|
else
|
|
{
|
|
Active = false;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public override void OnDoubleClick(Mobile from)
|
|
{
|
|
if (!from.InRange(GetWorldLocation(), 2))
|
|
{
|
|
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
|
|
return;
|
|
}
|
|
|
|
from.Target = new InternalTarget(this);
|
|
}
|
|
|
|
public override void Serialize(GenericWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
|
|
writer.WriteEncodedInt(0); // version
|
|
|
|
writer.WriteEncodedInt(m_Charges);
|
|
writer.WriteItemList(Receivers);
|
|
}
|
|
|
|
public override void Deserialize(GenericReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
|
|
int version = reader.ReadEncodedInt();
|
|
|
|
m_Charges = reader.ReadEncodedInt();
|
|
Receivers = reader.ReadStrongItemList<ReceiverCrystal>();
|
|
}
|
|
|
|
private class InternalTarget : Target
|
|
{
|
|
private BroadcastCrystal m_Crystal;
|
|
|
|
public InternalTarget(BroadcastCrystal crystal) : base(2, false, TargetFlags.None) => m_Crystal = crystal;
|
|
|
|
protected override void OnTarget(Mobile from, object targeted)
|
|
{
|
|
if (!m_Crystal.IsAccessibleTo(from))
|
|
return;
|
|
|
|
if (from.Map != m_Crystal.Map || !from.InRange(m_Crystal.GetWorldLocation(), 2))
|
|
{
|
|
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
|
|
return;
|
|
}
|
|
|
|
if (targeted == m_Crystal)
|
|
{
|
|
if (m_Crystal.Active)
|
|
{
|
|
m_Crystal.Active = false;
|
|
from.SendLocalizedMessage(500672); // You turn the crystal off.
|
|
}
|
|
else
|
|
{
|
|
if (m_Crystal.Charges > 0)
|
|
{
|
|
m_Crystal.Active = true;
|
|
from.SendLocalizedMessage(500673); // You turn the crystal on.
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(500676); // This crystal is out of charges.
|
|
}
|
|
}
|
|
}
|
|
else if (targeted is ReceiverCrystal receiver)
|
|
{
|
|
if (m_Crystal.Receivers.Count >= 10)
|
|
{
|
|
from.SendLocalizedMessage(1010042); // This broadcast crystal is already linked to 10 receivers.
|
|
}
|
|
else if (receiver.Sender == m_Crystal)
|
|
{
|
|
from.SendLocalizedMessage(500674); // This crystal is already linked with that crystal.
|
|
}
|
|
else if (receiver.Sender != null)
|
|
{
|
|
from.SendLocalizedMessage(
|
|
1010043); // That receiver crystal is already linked to another broadcast crystal.
|
|
}
|
|
else
|
|
{
|
|
receiver.Sender = m_Crystal;
|
|
from.SendLocalizedMessage(500675); // That crystal has been linked to this crystal.
|
|
}
|
|
}
|
|
else if (targeted == from)
|
|
{
|
|
foreach (ReceiverCrystal rc in new List<ReceiverCrystal>(m_Crystal.Receivers)) rc.Sender = null;
|
|
|
|
from.SendLocalizedMessage(1010046); // You unlink the broadcast crystal from all of its receivers.
|
|
}
|
|
else
|
|
{
|
|
if (targeted is Item targItem && targItem.VerifyMove(from))
|
|
{
|
|
CrystalRechargeInfo info = CrystalRechargeInfo.Get(targItem.GetType());
|
|
|
|
if (info != null)
|
|
{
|
|
if (m_Crystal.Charges >= MaxCharges)
|
|
{
|
|
from.SendLocalizedMessage(500678); // This crystal is already fully charged.
|
|
}
|
|
else
|
|
{
|
|
targItem.Consume();
|
|
|
|
if (m_Crystal.Charges + info.Amount >= MaxCharges)
|
|
{
|
|
m_Crystal.Charges = MaxCharges;
|
|
from.SendLocalizedMessage(500679); // You completely recharge the crystal.
|
|
}
|
|
else
|
|
{
|
|
m_Crystal.Charges += info.Amount;
|
|
from.SendLocalizedMessage(500680); // You recharge the crystal.
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
}
|
|
|
|
from.SendLocalizedMessage(500681); // You cannot use this crystal on that.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public class ReceiverCrystal : Item
|
|
{
|
|
private BroadcastCrystal m_Sender;
|
|
|
|
[Constructible]
|
|
public ReceiverCrystal() : base(0x1ED0) => Light = LightType.Circle150;
|
|
|
|
public ReceiverCrystal(Serial serial) : base(serial)
|
|
{
|
|
}
|
|
|
|
public override int LabelNumber => 1060740; // communication crystal
|
|
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public bool Active
|
|
{
|
|
get => ItemID == 0x1ED1;
|
|
set
|
|
{
|
|
ItemID = value ? 0x1ED1 : 0x1ED0;
|
|
InvalidateProperties();
|
|
}
|
|
}
|
|
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public BroadcastCrystal Sender
|
|
{
|
|
get => m_Sender;
|
|
set
|
|
{
|
|
if (m_Sender != null)
|
|
{
|
|
m_Sender.Receivers.Remove(this);
|
|
m_Sender.InvalidateProperties();
|
|
}
|
|
|
|
m_Sender = value;
|
|
|
|
if (value != null)
|
|
{
|
|
value.Receivers.Add(this);
|
|
value.InvalidateProperties();
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void GetProperties(ObjectPropertyList list)
|
|
{
|
|
base.GetProperties(list);
|
|
|
|
list.Add(Active ? 1060742 : 1060743); // active / inactive
|
|
list.Add(1060744); // receiver
|
|
}
|
|
|
|
public override void OnSingleClick(Mobile from)
|
|
{
|
|
base.OnSingleClick(from);
|
|
|
|
LabelTo(from, Active ? 1060742 : 1060743); // active / inactive
|
|
LabelTo(from, 1060744); // receiver
|
|
}
|
|
|
|
public void TransmitMessage(Mobile from, string message)
|
|
{
|
|
if (!Active)
|
|
return;
|
|
|
|
string text = $"{from.Name} says {message}";
|
|
|
|
if (RootParent is Mobile mobile)
|
|
mobile.SendMessage(0x2B2, $"Crystal: {text}");
|
|
else if (RootParent is Item item)
|
|
item.PublicOverheadMessage(MessageType.Regular, 0x2B2, false, $"Crystal: {text}");
|
|
else
|
|
PublicOverheadMessage(MessageType.Regular, 0x2B2, false, text);
|
|
}
|
|
|
|
public override void OnDoubleClick(Mobile from)
|
|
{
|
|
if (!from.InRange(GetWorldLocation(), 2))
|
|
{
|
|
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
|
|
return;
|
|
}
|
|
|
|
from.Target = new InternalTarget(this);
|
|
}
|
|
|
|
public override void Serialize(GenericWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
|
|
writer.WriteEncodedInt(0); // version
|
|
|
|
writer.WriteItem(m_Sender);
|
|
}
|
|
|
|
public override void Deserialize(GenericReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
|
|
int version = reader.ReadEncodedInt();
|
|
|
|
m_Sender = reader.ReadItem<BroadcastCrystal>();
|
|
}
|
|
|
|
private class InternalTarget : Target
|
|
{
|
|
private ReceiverCrystal m_Crystal;
|
|
|
|
public InternalTarget(ReceiverCrystal crystal) : base(-1, false, TargetFlags.None) => m_Crystal = crystal;
|
|
|
|
protected override void OnTarget(Mobile from, object targeted)
|
|
{
|
|
if (!m_Crystal.IsAccessibleTo(from))
|
|
return;
|
|
|
|
if (from.Map != m_Crystal.Map || !from.InRange(m_Crystal.GetWorldLocation(), 2))
|
|
{
|
|
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
|
|
return;
|
|
}
|
|
|
|
if (targeted == m_Crystal)
|
|
{
|
|
if (m_Crystal.Active)
|
|
{
|
|
m_Crystal.Active = false;
|
|
from.SendLocalizedMessage(500672); // You turn the crystal off.
|
|
}
|
|
else
|
|
{
|
|
m_Crystal.Active = true;
|
|
from.SendLocalizedMessage(500673); // You turn the crystal on.
|
|
}
|
|
}
|
|
else if (targeted == from)
|
|
{
|
|
if (m_Crystal.Sender != null)
|
|
{
|
|
m_Crystal.Sender = null;
|
|
from.SendLocalizedMessage(1010044); // You unlink the receiver crystal.
|
|
}
|
|
else
|
|
{
|
|
from.SendLocalizedMessage(1010045); // That receiver crystal is not linked.
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (targeted is Item targItem && targItem.VerifyMove(from))
|
|
{
|
|
CrystalRechargeInfo info = CrystalRechargeInfo.Get(targItem.GetType());
|
|
|
|
if (info != null)
|
|
{
|
|
from.SendLocalizedMessage(500677); // This crystal cannot be recharged.
|
|
return;
|
|
}
|
|
}
|
|
|
|
from.SendLocalizedMessage(1010045); // That receiver crystal is not linked.
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|