Overwrite

Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
Unstable Kitsune
2023-11-28 23:20:26 -05:00
parent 3cd54811de
commit b918192e4e
11608 changed files with 2644205 additions and 47 deletions

View File

@@ -0,0 +1,282 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System;
using System.Collections.Generic;
using System.Drawing;
using Server;
using Server.Mobiles;
using Server.Spells;
using VitaNex.IO;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.CastBars
{
public static partial class SpellCastBars
{
public const AccessLevel Access = AccessLevel.Administrator;
private static readonly PollTimer _InternalTimer;
private static readonly Queue<PlayerMobile> _CastBarQueue;
public static CastBarsOptions CMOptions { get; private set; }
public static Dictionary<PlayerMobile, SpellCastBar> Instances { get; private set; }
public static BinaryDataStore<PlayerMobile, CastBarState> States { get; private set; }
public static event Action<CastBarRequestEventArgs> OnCastBarRequest;
private static void OnSpellRequest(CastSpellRequestEventArgs e)
{
if (!CMOptions.ModuleEnabled)
{
return;
}
var user = e.Mobile as PlayerMobile;
if (user == null)
{
return;
}
var o = EnsureState(user);
if (o != null && o.Enabled)
{
if (CMOptions.ModuleDebug)
{
CMOptions.ToConsole("{0} casting {1} ({2})", user, e.SpellID, user.Spell);
}
if (user.Spell != null && SpellRegistry.GetRegistryNumber(user.Spell) == e.SpellID)
{
SendCastBarGump(user);
}
else
{
_CastBarQueue.Enqueue(user);
}
}
}
private static void PollCastBarQueue()
{
if (!CMOptions.ModuleEnabled)
{
_CastBarQueue.Clear();
return;
}
while (_CastBarQueue.Count > 0)
{
SendCastBarGump(_CastBarQueue.Dequeue());
}
}
public static void SendCastBarGump(PlayerMobile user)
{
if (!CMOptions.ModuleEnabled || user == null || !user.IsOnline())
{
return;
}
var o = EnsureState(user);
if (o == null || !o.Enabled)
{
return;
}
var e = new CastBarRequestEventArgs(user, o.Offset);
if (OnCastBarRequest != null)
{
OnCastBarRequest(e);
}
if (e.Gump == null)
{
CastBarRequestHandler(e);
}
if (e.Gump != null)
{
e.Gump.Refresh(true);
}
}
private static void CastBarRequestHandler(CastBarRequestEventArgs e)
{
if (!CMOptions.ModuleEnabled || e.User == null || !e.User.IsOnline() || e.Gump != null)
{
return;
}
if (!Instances.TryGetValue(e.User, out var cb) || cb.IsDisposed)
{
Instances[e.User] = cb = new SpellCastBar(e.User, e.Location.X, e.Location.Y);
}
else
{
cb.X = e.Location.X;
cb.Y = e.Location.Y;
}
cb.Preview = false;
e.Gump = cb;
if (CMOptions.ModuleDebug)
{
CMOptions.ToConsole(
"Request: {0} casting {1}, using {2} ({3}) at {4}",
e.User,
e.User.Spell,
cb,
cb.Preview ? "Prv" : "Std",
e.Location);
}
}
public static void HandleToggleCommand(PlayerMobile user)
{
if (!CMOptions.ModuleEnabled || user == null || !user.IsOnline())
{
return;
}
var t = !GetToggle(user);
SetToggle(user, t);
user.SendMessage(!t ? 0x22 : 0x55, "Cast-Bar has been {0}.", !t ? "disabled" : "enabled");
}
public static void HandlePositionCommand(PlayerMobile user)
{
if (!CMOptions.ModuleEnabled || user == null || !user.IsOnline())
{
return;
}
var e = new CastBarRequestEventArgs(user, GetOffset(user));
if (OnCastBarRequest != null)
{
OnCastBarRequest(e);
}
if (e.Gump == null)
{
CastBarRequestHandler(e);
}
if (e.Gump == null)
{
return;
}
e.Gump.Preview = true;
new OffsetSelectorGump(
user,
e.Gump.Refresh(true),
e.Location,
(ui, oldValue) =>
{
SetOffset(user, ui.Value);
ui.User.SendMessage(0x55, "Cast-Bar position set to X({0:#,0}), Y({1:#,0}).", ui.Value.X, ui.Value.Y);
e.Gump.X = ui.Value.X;
e.Gump.Y = ui.Value.Y;
e.Gump.Refresh(true);
}).Send();
}
public static bool GetToggle(PlayerMobile user)
{
var o = EnsureState(user);
if (o != null)
{
return o.Enabled;
}
return CastBarState.DefEnabled;
}
public static void SetToggle(PlayerMobile user, bool toggle)
{
var o = EnsureState(user);
if (o != null)
{
o.Enabled = toggle;
}
}
public static Point GetOffset(PlayerMobile user)
{
var o = EnsureState(user);
if (o != null)
{
return o.Offset;
}
return CastBarState.DefOffset;
}
public static void SetOffset(PlayerMobile user, Point loc)
{
var o = EnsureState(user);
if (o != null)
{
o.Offset = loc;
}
}
public static CastBarState EnsureState(PlayerMobile user)
{
if (user == null)
{
return null;
}
var o = States.GetValue(user);
if (user.Deleted)
{
States.Remove(user);
return null;
}
if (o == null)
{
States[user] = o = new CastBarState();
}
return o;
}
}
}

View File

@@ -0,0 +1,144 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Server;
using Server.Mobiles;
using VitaNex.IO;
#endregion
namespace VitaNex.Modules.CastBars
{
[CoreModule("Spell Cast Bars", "2.0.0.0")]
public static partial class SpellCastBars
{
static SpellCastBars()
{
CMOptions = new CastBarsOptions();
_CastBarQueue = new Queue<PlayerMobile>();
_InternalTimer = PollTimer.CreateInstance(TimeSpan.FromSeconds(0.1), PollCastBarQueue, _CastBarQueue.Any);
Instances = new Dictionary<PlayerMobile, SpellCastBar>();
States = new BinaryDataStore<PlayerMobile, CastBarState>(VitaNexCore.SavesDirectory + "/SpellCastBars", "States")
{
Async = true,
OnSerialize = Serialize,
OnDeserialize = Deserialize
};
}
private static void CMInvoke()
{
EventSink.CastSpellRequest += OnSpellRequest;
}
private static void CMEnabled()
{
_InternalTimer.Start();
}
private static void CMDisabled()
{
_InternalTimer.Stop();
}
private static void CMSave()
{
States.Export();
}
private static void CMLoad()
{
States.Import();
}
private static bool Serialize(GenericWriter writer)
{
var version = writer.SetVersion(1);
switch (version)
{
case 1:
{
writer.WriteBlockDictionary(
States,
(w, k, v) =>
{
w.Write(k);
v.Serialize(w);
});
}
break;
case 0:
{
writer.WriteBlockDictionary(
States,
(w, k, v) =>
{
w.Write(k);
w.Write(v.Enabled);
w.Write(v.Offset.X);
w.Write(v.Offset.Y);
});
}
break;
}
return true;
}
private static bool Deserialize(GenericReader reader)
{
var version = reader.GetVersion();
switch (version)
{
case 1:
{
reader.ReadBlockDictionary(
r =>
{
var k = r.ReadMobile<PlayerMobile>();
var v = new CastBarState(r);
return new KeyValuePair<PlayerMobile, CastBarState>(k, v);
},
States);
}
break;
case 0:
{
reader.ReadBlockDictionary(
r =>
{
var k = r.ReadMobile<PlayerMobile>();
var v = new CastBarState(r.ReadBool(), new Point(r.ReadInt(), r.ReadInt()));
return new KeyValuePair<PlayerMobile, CastBarState>(k, v);
},
States);
}
break;
}
return true;
}
}
}

View File

@@ -0,0 +1,33 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System;
using System.Drawing;
using Server.Mobiles;
#endregion
namespace VitaNex.Modules.CastBars
{
public sealed class CastBarRequestEventArgs : EventArgs
{
public PlayerMobile User { get; private set; }
public Point Location { get; set; }
public SpellCastBar Gump { get; set; }
public CastBarRequestEventArgs(PlayerMobile user, Point loc)
{
User = user;
Location = loc;
}
}
}

View File

@@ -0,0 +1,93 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System.Drawing;
using Server;
#endregion
namespace VitaNex.Modules.CastBars
{
public sealed class CastBarState : PropertyObject
{
public static bool DefEnabled = false;
public static Point DefOffset = new Point(480, 460);
[CommandProperty(SpellCastBars.Access)]
public bool Enabled { get; set; }
[CommandProperty(SpellCastBars.Access)]
public Point Offset { get; set; }
public CastBarState()
{
SetDefaults();
}
public CastBarState(bool enabled)
: this(enabled, DefOffset)
{ }
public CastBarState(Point offset)
: this(DefEnabled, offset)
{ }
public CastBarState(bool enabled, Point offset)
{
Enabled = enabled;
Offset = offset;
}
public CastBarState(GenericReader reader)
: base(reader)
{ }
public void SetDefaults()
{
Enabled = DefEnabled;
Offset = DefOffset;
}
public override void Clear()
{
SetDefaults();
}
public override void Reset()
{
SetDefaults();
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.SetVersion(0);
writer.Write(Enabled);
writer.Write(Offset.X);
writer.Write(Offset.Y);
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
reader.GetVersion();
Enabled = reader.ReadBool();
Offset = new Point(reader.ReadInt(), reader.ReadInt());
}
}
}

View File

@@ -0,0 +1,234 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System.Drawing;
using Server;
using Server.Commands;
using Server.Mobiles;
using VitaNex.SuperGumps;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.CastBars
{
public sealed class CastBarsOptions : CoreModuleOptions
{
private string _PositionCommand;
private string _ToggleCommand;
[CommandProperty(SpellCastBars.Access)]
public string PositionCommand
{
get => _PositionCommand;
set => CommandUtility.Replace(_PositionCommand, AccessLevel.Player, HandlePositionCommand, (_PositionCommand = value));
}
[CommandProperty(SpellCastBars.Access)]
public string ToggleCommand
{
get => _ToggleCommand;
set => CommandUtility.Replace(_ToggleCommand, AccessLevel.Player, HandleToggleCommand, (_ToggleCommand = value));
}
[CommandProperty(SpellCastBars.Access)]
public int GumpWidth { get; set; }
[CommandProperty(SpellCastBars.Access)]
public int GumpHeight { get; set; }
[CommandProperty(SpellCastBars.Access)]
public int GumpPadding { get; set; }
[CommandProperty(SpellCastBars.Access)]
public int GumpBackground { get; set; }
[CommandProperty(SpellCastBars.Access)]
public int GumpForeground { get; set; }
[CommandProperty(SpellCastBars.Access)]
public ProgressBarFlow GumpFlow { get; set; }
[CommandProperty(SpellCastBars.Access)]
public KnownColor GumpTextColor { get; set; }
[CommandProperty(SpellCastBars.Access)]
public bool GumpDisplayPercent { get; set; }
[CommandProperty(SpellCastBars.Access)]
public bool GumpDisplayText { get; set; }
public CastBarsOptions()
: base(typeof(SpellCastBars))
{
PositionCommand = "CastBarPos";
ToggleCommand = "CastBarToggle";
GumpWidth = ProgressBarGump.DefaultWidth;
GumpHeight = ProgressBarGump.DefaultHeight;
GumpPadding = ProgressBarGump.DefaultPadding;
GumpBackground = ProgressBarGump.DefaultBackgroundID;
GumpForeground = ProgressBarGump.DefaultForegroundID;
GumpFlow = ProgressBarGump.DefaultFlow;
GumpTextColor = SuperGump.DefaultHtmlColor.ToKnownColor();
GumpDisplayPercent = false;
GumpDisplayText = true;
}
public CastBarsOptions(GenericReader reader)
: base(reader)
{ }
public void HandlePositionCommand(CommandEventArgs e)
{
SpellCastBars.HandlePositionCommand(e.Mobile as PlayerMobile);
}
public void HandleToggleCommand(CommandEventArgs e)
{
SpellCastBars.HandleToggleCommand(e.Mobile as PlayerMobile);
}
public override void Clear()
{
base.Clear();
PositionCommand = null;
ToggleCommand = null;
GumpWidth = ProgressBarGump.DefaultWidth;
GumpHeight = ProgressBarGump.DefaultHeight;
GumpPadding = ProgressBarGump.DefaultPadding;
GumpBackground = ProgressBarGump.DefaultBackgroundID;
GumpForeground = ProgressBarGump.DefaultForegroundID;
GumpFlow = ProgressBarGump.DefaultFlow;
GumpTextColor = SuperGump.DefaultHtmlColor.ToKnownColor();
GumpDisplayPercent = false;
GumpDisplayText = true;
}
public override void Reset()
{
base.Reset();
PositionCommand = "CastBarPos";
ToggleCommand = "CastBarToggle";
GumpWidth = ProgressBarGump.DefaultWidth;
GumpHeight = ProgressBarGump.DefaultHeight;
GumpPadding = ProgressBarGump.DefaultPadding;
GumpBackground = ProgressBarGump.DefaultBackgroundID;
GumpForeground = ProgressBarGump.DefaultForegroundID;
GumpFlow = ProgressBarGump.DefaultFlow;
GumpTextColor = SuperGump.DefaultHtmlColor.ToKnownColor();
GumpDisplayPercent = false;
GumpDisplayText = true;
}
public override string ToString()
{
return "Cast-Bars Config";
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
var version = writer.SetVersion(1);
switch (version)
{
case 1:
{
writer.Write(GumpWidth);
writer.Write(GumpHeight);
writer.Write(GumpPadding);
writer.Write(GumpBackground);
writer.Write(GumpForeground);
writer.WriteFlag(GumpFlow);
writer.WriteFlag(GumpTextColor);
writer.Write(GumpDisplayPercent);
writer.Write(GumpDisplayText);
}
goto case 0;
case 0:
{
writer.Write(PositionCommand);
writer.Write(ToggleCommand);
}
break;
}
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
var version = reader.GetVersion();
switch (version)
{
case 1:
{
GumpWidth = reader.ReadInt();
GumpHeight = reader.ReadInt();
GumpPadding = reader.ReadInt();
GumpBackground = reader.ReadInt();
GumpForeground = reader.ReadInt();
GumpFlow = reader.ReadFlag<ProgressBarFlow>();
GumpTextColor = reader.ReadFlag<KnownColor>();
GumpDisplayPercent = reader.ReadBool();
GumpDisplayText = reader.ReadBool();
}
goto case 0;
case 0:
{
PositionCommand = reader.ReadString();
ToggleCommand = reader.ReadString();
}
break;
}
if (version > 0)
{
return;
}
GumpWidth = ProgressBarGump.DefaultWidth;
GumpHeight = ProgressBarGump.DefaultHeight;
GumpPadding = ProgressBarGump.DefaultPadding;
GumpBackground = ProgressBarGump.DefaultBackgroundID;
GumpForeground = ProgressBarGump.DefaultForegroundID;
GumpFlow = ProgressBarGump.DefaultFlow;
GumpTextColor = SuperGump.DefaultHtmlColor.ToKnownColor();
GumpDisplayPercent = false;
GumpDisplayText = true;
}
}
}

View File

@@ -0,0 +1,200 @@
#region Header
// _,-'/-'/
// . __,-; ,'( '/
// \. `-.__`-._`:_,-._ _ , . ``
// `:-._,------' ` _,`--` -: `_ , ` ,' :
// `---..__,,--' (C) 2023 ` -'. -'
// # Vita-Nex [http://core.vita-nex.com] #
// {o)xxx|===============- # -===============|xxx(o}
// # #
#endregion
#region References
using System;
using System.Drawing;
using Server;
using Server.Spells;
using VitaNex.SuperGumps.UI;
#endregion
namespace VitaNex.Modules.CastBars
{
public class SpellCastBar : ProgressBarGump
{
private bool _Initialized;
private Timer _CloseTimer;
private bool _Casting;
public Spell ActiveSpell { get; set; }
public DateTime CastStart { get; set; }
public bool Preview { get; set; }
public SpellCastBar(Mobile user, int? x = null, int? y = null, Action<ProgressBarGump, double> valueChanged = null)
: base(user, x: x, y: y, text: "Casting", valueChanged: valueChanged)
{
CanMove = true;
UseSounds = false;
AutoRefreshRate = TimeSpan.FromMilliseconds(100.0);
AutoRefresh = true;
}
protected override void Compile()
{
if (!_Initialized)
{
Width = SpellCastBars.CMOptions.GumpWidth;
Height = SpellCastBars.CMOptions.GumpHeight;
BackgroundID = SpellCastBars.CMOptions.GumpBackground;
ForegroundID = SpellCastBars.CMOptions.GumpForeground;
Padding = SpellCastBars.CMOptions.GumpPadding;
Flow = SpellCastBars.CMOptions.GumpFlow;
TextColor = Color.FromKnownColor(SpellCastBars.CMOptions.GumpTextColor);
DisplayPercent = SpellCastBars.CMOptions.GumpDisplayPercent;
_Initialized = true;
}
UpdateSpell();
base.Compile();
}
public override void Reset()
{
base.Reset();
if (_CloseTimer != null)
{
_CloseTimer.Running = false;
_CloseTimer = null;
}
ActiveSpell = null;
MaxValue = 100;
if (Preview)
{
Text = "Placeholder";
InternalValue = 50;
}
else
{
Text = "Casting";
InternalValue = 0;
}
}
public void UpdateSpell()
{
if (Preview)
{
Reset();
return;
}
_Casting = false;
if (ActiveSpell == null || ActiveSpell != User.Spell)
{
ActiveSpell = User.Spell as Spell;
if (ActiveSpell == null)
{
return;
}
if (_CloseTimer != null)
{
_CloseTimer.Running = false;
_CloseTimer = null;
}
Text = ActiveSpell.Name;
CastStart = DateTime.UtcNow;
MaxValue = ActiveSpell.GetCastDelay().TotalMilliseconds - 100.0;
if (SpellCastBars.CMOptions.ModuleDebug)
{
SpellCastBars.CMOptions.ToConsole(
"'{0}', {1}: [{2}/{3}] ({4})",
Text,
CastStart,
InternalValue,
MaxValue,
PercentComplete);
}
_Casting = ActiveSpell.IsCasting;
}
else
{
_Casting = true;
}
if (!_Casting)
{
return;
}
InternalValue = (DateTime.UtcNow - CastStart).TotalMilliseconds;
if (SpellCastBars.CMOptions.ModuleDebug)
{
SpellCastBars.CMOptions.ToConsole("[{0} / {1}] ({2})", InternalValue, MaxValue, PercentComplete);
}
}
private void Finish()
{
if ((!IsOpen && !Hidden) || (_CloseTimer != null && _CloseTimer.Running))
{
return;
}
InternalValue = MaxValue;
if (_CloseTimer != null)
{
_CloseTimer.Running = true;
}
else
{
_CloseTimer = Timer.DelayCall(TimeSpan.FromMilliseconds(500), () => Close());
}
}
protected override void OnSend()
{
base.OnSend();
if (!Preview && (ActiveSpell == null || Completed))
{
Finish();
}
}
public override void Close(bool all)
{
_Initialized = Preview = false;
Reset();
base.Close(all);
}
protected override bool CanAutoRefresh()
{
return ActiveSpell != null && base.CanAutoRefresh();
}
public override string FormatText(bool html = false)
{
return SpellCastBars.CMOptions.GumpDisplayText ? base.FormatText(html) : String.Empty;
}
}
}