Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
222
Scripts/SubSystem/VitaNex/Core/Misc/AnimationInfo.cs
Normal file
222
Scripts/SubSystem/VitaNex/Core/Misc/AnimationInfo.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[PropertyObject]
|
||||
public struct AnimationInfo : IEquatable<AnimationInfo>
|
||||
{
|
||||
public static readonly AnimationInfo Empty = new AnimationInfo(0, 0, 0, true, false, 0);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public int AnimID { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public int Frames { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public bool Forward { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public bool Repeat { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public int Delay { get; private set; }
|
||||
|
||||
public AnimationInfo(int animID, int frames)
|
||||
: this(animID, frames, true)
|
||||
{ }
|
||||
|
||||
public AnimationInfo(int animID, int frames, bool forward)
|
||||
: this(animID, frames, 1, forward, false, 0)
|
||||
{ }
|
||||
|
||||
public AnimationInfo(int animID, int frames, int count, bool forward, bool repeat)
|
||||
: this(animID, frames, count, forward, repeat, 0)
|
||||
{ }
|
||||
|
||||
public AnimationInfo(int animID, int frames, int count, bool forward, bool repeat, int delay)
|
||||
: this()
|
||||
{
|
||||
AnimID = animID;
|
||||
Frames = frames;
|
||||
Count = count;
|
||||
Forward = forward;
|
||||
Repeat = repeat;
|
||||
Delay = delay;
|
||||
}
|
||||
|
||||
public AnimationInfo(GenericReader reader)
|
||||
: this()
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
public bool Animate(Mobile m)
|
||||
{
|
||||
if (m != null && !m.Deleted && this != Empty && AnimID > 0 && Frames > 0)
|
||||
{
|
||||
m.Animate(AnimID, Frames, Count, Forward, Repeat, Delay);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hash = AnimID;
|
||||
hash = (hash * 397) ^ Frames;
|
||||
hash = (hash * 397) ^ Count;
|
||||
hash = (hash * 397) ^ (Forward ? 1 : 0);
|
||||
hash = (hash * 397) ^ (Repeat ? 1 : 0);
|
||||
hash = (hash * 397) ^ Delay;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is AnimationInfo && Equals((AnimationInfo)obj);
|
||||
}
|
||||
|
||||
public bool Equals(AnimationInfo other)
|
||||
{
|
||||
return AnimID.Equals(other.AnimID) && Frames.Equals(other.Frames) && Count.Equals(other.Count) &&
|
||||
Forward.Equals(other.Forward) && Repeat.Equals(other.Repeat) && Delay.Equals(other.Delay);
|
||||
}
|
||||
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.SetVersion(0);
|
||||
|
||||
writer.Write(AnimID);
|
||||
writer.Write(Frames);
|
||||
writer.Write(Count);
|
||||
writer.Write(Forward);
|
||||
writer.Write(Repeat);
|
||||
writer.Write(Delay);
|
||||
}
|
||||
|
||||
public void Deserialize(GenericReader reader)
|
||||
{
|
||||
reader.GetVersion();
|
||||
|
||||
AnimID = reader.ReadInt();
|
||||
Frames = reader.ReadInt();
|
||||
Count = reader.ReadInt();
|
||||
Forward = reader.ReadBool();
|
||||
Repeat = reader.ReadBool();
|
||||
Delay = reader.ReadInt();
|
||||
}
|
||||
|
||||
#region Operators
|
||||
public static bool operator ==(AnimationInfo l, AnimationInfo r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(AnimationInfo l, AnimationInfo r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator >(AnimationInfo l, AnimationInfo r)
|
||||
{
|
||||
return l.AnimID > r.AnimID;
|
||||
}
|
||||
|
||||
public static bool operator <(AnimationInfo l, AnimationInfo r)
|
||||
{
|
||||
return l.AnimID < r.AnimID;
|
||||
}
|
||||
|
||||
public static bool operator >=(AnimationInfo l, AnimationInfo r)
|
||||
{
|
||||
return l.AnimID >= r.AnimID;
|
||||
}
|
||||
|
||||
public static bool operator <=(AnimationInfo l, AnimationInfo r)
|
||||
{
|
||||
return l.AnimID <= r.AnimID;
|
||||
}
|
||||
|
||||
public static bool operator ==(AnimationInfo l, int r)
|
||||
{
|
||||
return l.AnimID.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(AnimationInfo l, int r)
|
||||
{
|
||||
return !l.AnimID.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator >(AnimationInfo l, int r)
|
||||
{
|
||||
return l.AnimID > r;
|
||||
}
|
||||
|
||||
public static bool operator <(AnimationInfo l, int r)
|
||||
{
|
||||
return l.AnimID < r;
|
||||
}
|
||||
|
||||
public static bool operator >=(AnimationInfo l, int r)
|
||||
{
|
||||
return l.AnimID >= r;
|
||||
}
|
||||
|
||||
public static bool operator <=(AnimationInfo l, int r)
|
||||
{
|
||||
return l.AnimID <= r;
|
||||
}
|
||||
|
||||
public static bool operator ==(int l, AnimationInfo r)
|
||||
{
|
||||
return l.Equals(r.AnimID);
|
||||
}
|
||||
|
||||
public static bool operator !=(int l, AnimationInfo r)
|
||||
{
|
||||
return !l.Equals(r.AnimID);
|
||||
}
|
||||
|
||||
public static bool operator >(int l, AnimationInfo r)
|
||||
{
|
||||
return l > r.AnimID;
|
||||
}
|
||||
|
||||
public static bool operator <(int l, AnimationInfo r)
|
||||
{
|
||||
return l < r.AnimID;
|
||||
}
|
||||
|
||||
public static bool operator >=(int l, AnimationInfo r)
|
||||
{
|
||||
return l >= r.AnimID;
|
||||
}
|
||||
|
||||
public static bool operator <=(int l, AnimationInfo r)
|
||||
{
|
||||
return l <= r.AnimID;
|
||||
}
|
||||
#endregion Operators
|
||||
}
|
||||
}
|
||||
23
Scripts/SubSystem/VitaNex/Core/Misc/Arguments.cs
Normal file
23
Scripts/SubSystem/VitaNex/Core/Misc/Arguments.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public static class Arguments
|
||||
{
|
||||
public static readonly object[] Empty = new object[0];
|
||||
|
||||
public static object[] Create(params object[] args)
|
||||
{
|
||||
return args ?? Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
216
Scripts/SubSystem/VitaNex/Core/Misc/ArtworkSupport.cs
Normal file
216
Scripts/SubSystem/VitaNex/Core/Misc/ArtworkSupport.cs
Normal file
@@ -0,0 +1,216 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public static class ArtworkSupport
|
||||
{
|
||||
public static short[] LandTextures { get; private set; }
|
||||
public static short[] StaticAnimations { get; private set; }
|
||||
|
||||
static ArtworkSupport()
|
||||
{
|
||||
LandTextures = new short[TileData.MaxLandValue];
|
||||
LandTextures.SetAll((short)-1);
|
||||
|
||||
StaticAnimations = new short[TileData.MaxItemValue];
|
||||
StaticAnimations.SetAll((short)-1);
|
||||
|
||||
var filePath = Core.FindDataFile("tiledata.mul");
|
||||
|
||||
if (String.IsNullOrWhiteSpace(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var file = new FileInfo(filePath);
|
||||
|
||||
if (!file.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
using (var fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
{
|
||||
var bin = new BinaryReader(fs);
|
||||
var buffer = new byte[25];
|
||||
|
||||
if (fs.Length == 3188736)
|
||||
{
|
||||
// 7.0.9.0
|
||||
LandTextures = new short[0x4000];
|
||||
|
||||
for (var i = 0; i < 0x4000; ++i)
|
||||
{
|
||||
if (i == 1 || (i > 0 && (i & 0x1F) == 0))
|
||||
{
|
||||
bin.Read(buffer, 0, 4);
|
||||
}
|
||||
|
||||
bin.Read(buffer, 0, 8);
|
||||
|
||||
var texture = bin.ReadInt16();
|
||||
|
||||
bin.Read(buffer, 0, 20);
|
||||
|
||||
LandTextures[i] = texture;
|
||||
}
|
||||
|
||||
StaticAnimations = new short[0x10000];
|
||||
|
||||
for (var i = 0; i < 0x10000; ++i)
|
||||
{
|
||||
if ((i & 0x1F) == 0)
|
||||
{
|
||||
bin.Read(buffer, 0, 4);
|
||||
}
|
||||
|
||||
bin.Read(buffer, 0, 14);
|
||||
|
||||
var anim = bin.ReadInt16();
|
||||
|
||||
bin.Read(buffer, 0, 25);
|
||||
|
||||
StaticAnimations[i] = anim;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LandTextures = new short[0x4000];
|
||||
|
||||
for (var i = 0; i < 0x4000; ++i)
|
||||
{
|
||||
if ((i & 0x1F) == 0)
|
||||
{
|
||||
bin.Read(buffer, 0, 4);
|
||||
}
|
||||
|
||||
bin.Read(buffer, 0, 4);
|
||||
|
||||
var texture = bin.ReadInt16();
|
||||
|
||||
bin.Read(buffer, 0, 20);
|
||||
|
||||
LandTextures[i] = texture;
|
||||
}
|
||||
|
||||
if (fs.Length == 1644544)
|
||||
{
|
||||
// 7.0.0.0
|
||||
StaticAnimations = new short[0x8000];
|
||||
|
||||
for (var i = 0; i < 0x8000; ++i)
|
||||
{
|
||||
if ((i & 0x1F) == 0)
|
||||
{
|
||||
bin.Read(buffer, 0, 4);
|
||||
}
|
||||
|
||||
bin.Read(buffer, 0, 10);
|
||||
|
||||
var anim = bin.ReadInt16();
|
||||
|
||||
bin.Read(buffer, 0, 25);
|
||||
|
||||
StaticAnimations[i] = anim;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
StaticAnimations = new short[0x4000];
|
||||
|
||||
for (var i = 0; i < 0x4000; ++i)
|
||||
{
|
||||
if ((i & 0x1F) == 0)
|
||||
{
|
||||
bin.Read(buffer, 0, 4);
|
||||
}
|
||||
|
||||
bin.Read(buffer, 0, 10);
|
||||
|
||||
var anim = bin.ReadInt16();
|
||||
|
||||
bin.Read(buffer, 0, 25);
|
||||
|
||||
StaticAnimations[i] = anim;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static short LookupTexture(int landID)
|
||||
{
|
||||
return LandTextures.InBounds(landID) ? LandTextures[landID] : (short)0;
|
||||
}
|
||||
|
||||
public static short LookupAnimation(int staticID)
|
||||
{
|
||||
return StaticAnimations.InBounds(staticID) ? StaticAnimations[staticID] : (short)0;
|
||||
}
|
||||
|
||||
public static int LookupGump(int staticID, bool female)
|
||||
{
|
||||
int value = LookupAnimation(staticID);
|
||||
|
||||
if (value > 0)
|
||||
{
|
||||
value += female ? 60000 : 50000;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
public static int LookupGump(Body body)
|
||||
{
|
||||
switch (body.BodyID)
|
||||
{
|
||||
case 183:
|
||||
case 185:
|
||||
case 400:
|
||||
case 402:
|
||||
return 12;
|
||||
case 184:
|
||||
case 186:
|
||||
case 401:
|
||||
case 403:
|
||||
return 13;
|
||||
case 605:
|
||||
case 607:
|
||||
return 14;
|
||||
case 606:
|
||||
case 608:
|
||||
return 15;
|
||||
case 666:
|
||||
return 666;
|
||||
case 667:
|
||||
return 665;
|
||||
case 694:
|
||||
return 666;
|
||||
case 695:
|
||||
return 665;
|
||||
case 750:
|
||||
return 12;
|
||||
case 751:
|
||||
return 13;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Scripts/SubSystem/VitaNex/Core/Misc/AttackAnimation.cs
Normal file
26
Scripts/SubSystem/VitaNex/Core/Misc/AttackAnimation.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public enum AttackAnimation
|
||||
{
|
||||
Slash1H = 9,
|
||||
Pierce1H = 10,
|
||||
Bash1H = 11,
|
||||
Bash2H = 12,
|
||||
Slash2H = 13,
|
||||
Pierce2H = 14,
|
||||
ShootBow = 18,
|
||||
ShootXBow = 19,
|
||||
Wrestle = 31
|
||||
}
|
||||
}
|
||||
65
Scripts/SubSystem/VitaNex/Core/Misc/AttributeDefinition.cs
Normal file
65
Scripts/SubSystem/VitaNex/Core/Misc/AttributeDefinition.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Server
|
||||
{
|
||||
public class AttributeDefinition : AttributeFactors
|
||||
{
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public TextDefinition Name { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public string NameString { get => Name.String; set => Name = new TextDefinition(Name.Number, value); }
|
||||
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public int NameNumber { get => Name.Number; set => Name = new TextDefinition(value, Name.String); }
|
||||
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public bool Percentage { get; set; }
|
||||
|
||||
public AttributeDefinition(TextDefinition name = default, double weight = 1.0, int min = 0, int max = 1, int inc = 1, bool percentage = false)
|
||||
: base(weight, min, max, inc)
|
||||
{
|
||||
Name = name;
|
||||
Percentage = percentage;
|
||||
}
|
||||
|
||||
public AttributeDefinition(AttributeDefinition def)
|
||||
: this(new TextDefinition(def.Name.Number, def.Name.String), def.Weight, def.Min, def.Max, def.Inc)
|
||||
{ }
|
||||
|
||||
public AttributeDefinition(GenericReader reader)
|
||||
: base(reader)
|
||||
{ }
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
writer.SetVersion(0);
|
||||
|
||||
writer.WriteTextDef(Name);
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
reader.GetVersion();
|
||||
|
||||
Name = reader.ReadTextDef();
|
||||
}
|
||||
}
|
||||
}
|
||||
108
Scripts/SubSystem/VitaNex/Core/Misc/AttributeFactors.cs
Normal file
108
Scripts/SubSystem/VitaNex/Core/Misc/AttributeFactors.cs
Normal file
@@ -0,0 +1,108 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using VitaNex;
|
||||
#endregion
|
||||
|
||||
namespace Server
|
||||
{
|
||||
[PropertyObject]
|
||||
public class AttributeFactors
|
||||
{
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public double Weight { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public int Min { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public int Max { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Administrator)]
|
||||
public int Inc { get; set; }
|
||||
|
||||
public AttributeFactors(double weight = 1.0, int min = 0, int max = 1, int inc = 1)
|
||||
{
|
||||
Weight = weight;
|
||||
Min = min;
|
||||
Max = max;
|
||||
Inc = inc;
|
||||
}
|
||||
|
||||
public AttributeFactors(GenericReader reader)
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
public double GetIntensity(int value)
|
||||
{
|
||||
value = Math.Max(Min, Math.Min(Max, value));
|
||||
|
||||
if (value > 0)
|
||||
return value / Math.Max(1.0, Max);
|
||||
|
||||
if (value < 0)
|
||||
return value / Math.Min(-1.0, Min);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public double GetWeight(int value)
|
||||
{
|
||||
return GetIntensity(value) * Weight;
|
||||
}
|
||||
|
||||
public virtual void Serialize(GenericWriter writer)
|
||||
{
|
||||
var version = writer.SetVersion(1);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
writer.Write(Min);
|
||||
}
|
||||
goto case 0;
|
||||
case 0:
|
||||
{
|
||||
writer.Write(Weight);
|
||||
writer.Write(Max);
|
||||
writer.Write(Inc);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Deserialize(GenericReader reader)
|
||||
{
|
||||
var version = reader.ReadInt();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Min = reader.ReadInt();
|
||||
}
|
||||
goto case 0;
|
||||
case 0:
|
||||
{
|
||||
Weight = reader.ReadDouble();
|
||||
Max = reader.ReadInt();
|
||||
Inc = reader.ReadInt();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Scripts/SubSystem/VitaNex/Core/Misc/Axis.cs
Normal file
27
Scripts/SubSystem/VitaNex/Core/Misc/Axis.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[Flags]
|
||||
public enum Axis
|
||||
{
|
||||
None = 0x0,
|
||||
Vertical = 0x1,
|
||||
Horizontal = 0x2,
|
||||
|
||||
Both = Vertical | Horizontal
|
||||
}
|
||||
}
|
||||
451
Scripts/SubSystem/VitaNex/Core/Misc/Color555.cs
Normal file
451
Scripts/SubSystem/VitaNex/Core/Misc/Color555.cs
Normal file
@@ -0,0 +1,451 @@
|
||||
#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;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[Parsable]
|
||||
public struct Color555 : IEquatable<Color555>, IEquatable<Color>, IEquatable<short>, IEquatable<ushort>
|
||||
{
|
||||
#region Colors
|
||||
public static readonly Color555 MinValue = UInt16.MinValue;
|
||||
public static readonly Color555 MaxValue = UInt16.MaxValue;
|
||||
|
||||
public static readonly Color555 Empty = Color.Empty;
|
||||
|
||||
public static readonly Color555 AliceBlue = Color.AliceBlue;
|
||||
public static readonly Color555 AntiqueWhite = Color.AntiqueWhite;
|
||||
public static readonly Color555 Aqua = Color.Aqua;
|
||||
public static readonly Color555 Aquamarine = Color.Aquamarine;
|
||||
public static readonly Color555 Azure = Color.Azure;
|
||||
public static readonly Color555 Beige = Color.Beige;
|
||||
public static readonly Color555 Bisque = Color.Bisque;
|
||||
public static readonly Color555 Black = Color.Black;
|
||||
public static readonly Color555 BlanchedAlmond = Color.BlanchedAlmond;
|
||||
public static readonly Color555 Blue = Color.Blue;
|
||||
public static readonly Color555 BlueViolet = Color.BlueViolet;
|
||||
public static readonly Color555 Brown = Color.Brown;
|
||||
public static readonly Color555 BurlyWood = Color.BurlyWood;
|
||||
public static readonly Color555 CadetBlue = Color.CadetBlue;
|
||||
public static readonly Color555 Chartreuse = Color.Chartreuse;
|
||||
public static readonly Color555 Chocolate = Color.Chocolate;
|
||||
public static readonly Color555 Coral = Color.Coral;
|
||||
public static readonly Color555 CornflowerBlue = Color.CornflowerBlue;
|
||||
public static readonly Color555 Cornsilk = Color.Cornsilk;
|
||||
public static readonly Color555 Crimson = Color.Crimson;
|
||||
public static readonly Color555 Cyan = Color.Cyan;
|
||||
public static readonly Color555 DarkBlue = Color.DarkBlue;
|
||||
public static readonly Color555 DarkCyan = Color.DarkCyan;
|
||||
public static readonly Color555 DarkGoldenrod = Color.DarkGoldenrod;
|
||||
public static readonly Color555 DarkGray = Color.DarkGray;
|
||||
public static readonly Color555 DarkGreen = Color.DarkGreen;
|
||||
public static readonly Color555 DarkKhaki = Color.DarkKhaki;
|
||||
public static readonly Color555 DarkMagenta = Color.DarkMagenta;
|
||||
public static readonly Color555 DarkOliveGreen = Color.DarkOliveGreen;
|
||||
public static readonly Color555 DarkOrange = Color.DarkOrange;
|
||||
public static readonly Color555 DarkOrchid = Color.DarkOrchid;
|
||||
public static readonly Color555 DarkRed = Color.DarkRed;
|
||||
public static readonly Color555 DarkSalmon = Color.DarkSalmon;
|
||||
public static readonly Color555 DarkSeaGreen = Color.DarkSeaGreen;
|
||||
public static readonly Color555 DarkSlateBlue = Color.DarkSlateBlue;
|
||||
public static readonly Color555 DarkSlateGray = Color.DarkSlateGray;
|
||||
public static readonly Color555 DarkTurquoise = Color.DarkTurquoise;
|
||||
public static readonly Color555 DarkViolet = Color.DarkViolet;
|
||||
public static readonly Color555 DeepPink = Color.DeepPink;
|
||||
public static readonly Color555 DeepSkyBlue = Color.DeepSkyBlue;
|
||||
public static readonly Color555 DimGray = Color.DimGray;
|
||||
public static readonly Color555 DodgerBlue = Color.DodgerBlue;
|
||||
public static readonly Color555 Firebrick = Color.Firebrick;
|
||||
public static readonly Color555 FloralWhite = Color.FloralWhite;
|
||||
public static readonly Color555 ForestGreen = Color.ForestGreen;
|
||||
public static readonly Color555 Fuchsia = Color.Fuchsia;
|
||||
public static readonly Color555 Gainsboro = Color.Gainsboro;
|
||||
public static readonly Color555 GhostWhite = Color.GhostWhite;
|
||||
public static readonly Color555 Gold = Color.Gold;
|
||||
public static readonly Color555 Goldenrod = Color.Goldenrod;
|
||||
public static readonly Color555 Gray = Color.Gray;
|
||||
public static readonly Color555 Green = Color.Green;
|
||||
public static readonly Color555 GreenYellow = Color.GreenYellow;
|
||||
public static readonly Color555 Honeydew = Color.Honeydew;
|
||||
public static readonly Color555 HotPink = Color.HotPink;
|
||||
public static readonly Color555 IndianRed = Color.IndianRed;
|
||||
public static readonly Color555 Indigo = Color.Indigo;
|
||||
public static readonly Color555 Ivory = Color.Ivory;
|
||||
public static readonly Color555 Khaki = Color.Khaki;
|
||||
public static readonly Color555 Lavender = Color.Lavender;
|
||||
public static readonly Color555 LavenderBlush = Color.LavenderBlush;
|
||||
public static readonly Color555 LawnGreen = Color.LawnGreen;
|
||||
public static readonly Color555 LemonChiffon = Color.LemonChiffon;
|
||||
public static readonly Color555 LightBlue = Color.LightBlue;
|
||||
public static readonly Color555 LightCoral = Color.LightCoral;
|
||||
public static readonly Color555 LightCyan = Color.LightCyan;
|
||||
public static readonly Color555 LightGoldenrodYellow = Color.LightGoldenrodYellow;
|
||||
public static readonly Color555 LightGray = Color.LightGray;
|
||||
public static readonly Color555 LightGreen = Color.LightGreen;
|
||||
public static readonly Color555 LightPink = Color.LightPink;
|
||||
public static readonly Color555 LightSalmon = Color.LightSalmon;
|
||||
public static readonly Color555 LightSeaGreen = Color.LightSeaGreen;
|
||||
public static readonly Color555 LightSkyBlue = Color.LightSkyBlue;
|
||||
public static readonly Color555 LightSlateGray = Color.LightSlateGray;
|
||||
public static readonly Color555 LightSteelBlue = Color.LightSteelBlue;
|
||||
public static readonly Color555 LightYellow = Color.LightYellow;
|
||||
public static readonly Color555 Lime = Color.Lime;
|
||||
public static readonly Color555 LimeGreen = Color.LimeGreen;
|
||||
public static readonly Color555 Linen = Color.Linen;
|
||||
public static readonly Color555 Magenta = Color.Magenta;
|
||||
public static readonly Color555 Maroon = Color.Maroon;
|
||||
public static readonly Color555 MediumAquamarine = Color.MediumAquamarine;
|
||||
public static readonly Color555 MediumBlue = Color.MediumBlue;
|
||||
public static readonly Color555 MediumOrchid = Color.MediumOrchid;
|
||||
public static readonly Color555 MediumPurple = Color.MediumPurple;
|
||||
public static readonly Color555 MediumSeaGreen = Color.MediumSeaGreen;
|
||||
public static readonly Color555 MediumSlateBlue = Color.MediumSlateBlue;
|
||||
public static readonly Color555 MediumSpringGreen = Color.MediumSpringGreen;
|
||||
public static readonly Color555 MediumTurquoise = Color.MediumTurquoise;
|
||||
public static readonly Color555 MediumVioletRed = Color.MediumVioletRed;
|
||||
public static readonly Color555 MidnightBlue = Color.MidnightBlue;
|
||||
public static readonly Color555 MintCream = Color.MintCream;
|
||||
public static readonly Color555 MistyRose = Color.MistyRose;
|
||||
public static readonly Color555 Moccasin = Color.Moccasin;
|
||||
public static readonly Color555 NavajoWhite = Color.NavajoWhite;
|
||||
public static readonly Color555 Navy = Color.Navy;
|
||||
public static readonly Color555 OldLace = Color.OldLace;
|
||||
public static readonly Color555 Olive = Color.Olive;
|
||||
public static readonly Color555 OliveDrab = Color.OliveDrab;
|
||||
public static readonly Color555 Orange = Color.Orange;
|
||||
public static readonly Color555 OrangeRed = Color.OrangeRed;
|
||||
public static readonly Color555 Orchid = Color.Orchid;
|
||||
public static readonly Color555 PaleGoldenrod = Color.PaleGoldenrod;
|
||||
public static readonly Color555 PaleGreen = Color.PaleGreen;
|
||||
public static readonly Color555 PaleTurquoise = Color.PaleTurquoise;
|
||||
public static readonly Color555 PaleVioletRed = Color.PaleVioletRed;
|
||||
public static readonly Color555 PapayaWhip = Color.PapayaWhip;
|
||||
public static readonly Color555 PeachPuff = Color.PeachPuff;
|
||||
public static readonly Color555 Peru = Color.Peru;
|
||||
public static readonly Color555 Pink = Color.Pink;
|
||||
public static readonly Color555 Plum = Color.Plum;
|
||||
public static readonly Color555 PowderBlue = Color.PowderBlue;
|
||||
public static readonly Color555 Purple = Color.Purple;
|
||||
public static readonly Color555 Red = Color.Red;
|
||||
public static readonly Color555 RosyBrown = Color.RosyBrown;
|
||||
public static readonly Color555 RoyalBlue = Color.RoyalBlue;
|
||||
public static readonly Color555 SaddleBrown = Color.SaddleBrown;
|
||||
public static readonly Color555 Salmon = Color.Salmon;
|
||||
public static readonly Color555 SandyBrown = Color.SandyBrown;
|
||||
public static readonly Color555 SeaGreen = Color.SeaGreen;
|
||||
public static readonly Color555 SeaShell = Color.SeaShell;
|
||||
public static readonly Color555 Sienna = Color.Sienna;
|
||||
public static readonly Color555 Silver = Color.Silver;
|
||||
public static readonly Color555 SkyBlue = Color.SkyBlue;
|
||||
public static readonly Color555 SlateBlue = Color.SlateBlue;
|
||||
public static readonly Color555 SlateGray = Color.SlateGray;
|
||||
public static readonly Color555 Snow = Color.Snow;
|
||||
public static readonly Color555 SpringGreen = Color.SpringGreen;
|
||||
public static readonly Color555 SteelBlue = Color.SteelBlue;
|
||||
public static readonly Color555 Tan = Color.Tan;
|
||||
public static readonly Color555 Teal = Color.Teal;
|
||||
public static readonly Color555 Thistle = Color.Thistle;
|
||||
public static readonly Color555 Tomato = Color.Tomato;
|
||||
public static readonly Color555 Transparent = Color.Transparent;
|
||||
public static readonly Color555 Turquoise = Color.Turquoise;
|
||||
public static readonly Color555 Violet = Color.Violet;
|
||||
public static readonly Color555 Wheat = Color.Wheat;
|
||||
public static readonly Color555 White = Color.White;
|
||||
public static readonly Color555 WhiteSmoke = Color.WhiteSmoke;
|
||||
public static readonly Color555 Yellow = Color.Yellow;
|
||||
public static readonly Color555 YellowGreen = Color.YellowGreen;
|
||||
#endregion Colors
|
||||
|
||||
public static Color555 Parse(string input)
|
||||
{
|
||||
if (input == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(input));
|
||||
}
|
||||
|
||||
if (Insensitive.Equals(input, "None") || Insensitive.Equals(input, "Empty"))
|
||||
{
|
||||
return Empty;
|
||||
}
|
||||
|
||||
if (Insensitive.StartsWith(input, "0x"))
|
||||
{
|
||||
return FromArgb(Convert.ToInt32(input.Substring(2), 16));
|
||||
}
|
||||
|
||||
if (Insensitive.StartsWith(input, "#"))
|
||||
{
|
||||
return FromArgb(Convert.ToInt32(input.Substring(1), 16));
|
||||
}
|
||||
|
||||
if (Int32.TryParse(input, out var val))
|
||||
{
|
||||
return FromArgb(val);
|
||||
}
|
||||
|
||||
var rgb = input.Split(',');
|
||||
|
||||
if (rgb.Length >= 3)
|
||||
{
|
||||
if (Byte.TryParse(rgb[0], out var r) && Byte.TryParse(rgb[1], out var g) && Byte.TryParse(rgb[2], out var b))
|
||||
{
|
||||
return FromArgb(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
return FromName(input);
|
||||
}
|
||||
|
||||
public static bool TryParse(string input, out Color555 value)
|
||||
{
|
||||
try
|
||||
{
|
||||
value = Parse(input);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
value = Color.Empty;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Color555 FromKnownColor(KnownColor color)
|
||||
{
|
||||
return new Color555(Color.FromKnownColor(color));
|
||||
}
|
||||
|
||||
public static Color555 FromName(string name)
|
||||
{
|
||||
return new Color555(Color.FromName(name));
|
||||
}
|
||||
|
||||
public static Color555 FromArgb(int argb)
|
||||
{
|
||||
return new Color555(Color.FromArgb(argb));
|
||||
}
|
||||
|
||||
public static Color555 FromArgb(int r, int g, int b)
|
||||
{
|
||||
return new Color555(Color.FromArgb(r, g, b));
|
||||
}
|
||||
|
||||
public static Color555 FromArgb(int a, int r, int g, int b)
|
||||
{
|
||||
return new Color555(Color.FromArgb(a, r, g, b));
|
||||
}
|
||||
|
||||
public static Color555 FromArgb(int a, Color baseColor)
|
||||
{
|
||||
return new Color555(Color.FromArgb(a, baseColor));
|
||||
}
|
||||
|
||||
public static Color555 FromArgb(int a, Color555 baseColor)
|
||||
{
|
||||
return new Color555(Color.FromArgb(a, baseColor._Color));
|
||||
}
|
||||
|
||||
public static Color555 FromRgb(short rgb)
|
||||
{
|
||||
return new Color555(rgb);
|
||||
}
|
||||
|
||||
public static Color555 FromRgb(ushort rgb)
|
||||
{
|
||||
return new Color555(rgb);
|
||||
}
|
||||
|
||||
public static Color555 FromColor(Color color)
|
||||
{
|
||||
return new Color555(color);
|
||||
}
|
||||
|
||||
private string _String;
|
||||
|
||||
private readonly ushort _RGB;
|
||||
private readonly int _ARGB;
|
||||
private readonly Color _Color;
|
||||
|
||||
public byte R => _Color.R;
|
||||
public byte G => _Color.G;
|
||||
public byte B => _Color.B;
|
||||
|
||||
public bool IsEmpty => _Color.IsEmpty;
|
||||
public bool IsKnownColor => _Color.IsKnownColor;
|
||||
public bool IsNamedColor => _Color.IsNamedColor;
|
||||
public bool IsSystemColor => _Color.IsSystemColor;
|
||||
|
||||
public string Name => _Color.Name;
|
||||
|
||||
public Color555(Color color)
|
||||
{
|
||||
_Color = color;
|
||||
|
||||
_ARGB = color.ToArgb();
|
||||
|
||||
_RGB = (ushort)((_ARGB >> 16) & 0x8000 | (_ARGB >> 9) & 0x7C00 | (_ARGB >> 6) & 0x03E0 | (_ARGB >> 3) & 0x1F);
|
||||
|
||||
_String = null;
|
||||
}
|
||||
|
||||
public Color555(short rgb)
|
||||
: this((ushort)rgb)
|
||||
{ }
|
||||
|
||||
public Color555(ushort rgb)
|
||||
{
|
||||
_RGB = rgb;
|
||||
|
||||
_ARGB = ((rgb & 0x7C00) << 9) | ((rgb & 0x03E0) << 6) | ((rgb & 0x1F) << 3);
|
||||
_ARGB = ((rgb & 0x8000) * 0x1FE00) | _ARGB | ((_ARGB >> 5) & 0x070707);
|
||||
|
||||
_Color = Color.FromArgb(_ARGB);
|
||||
|
||||
_String = null;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return _ARGB;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Color555 c16 && Equals(c16))
|
||||
|| (obj is Color c32 && Equals(c32))
|
||||
|| (obj is short srgb && Equals(srgb))
|
||||
|| (obj is ushort urgb && Equals(urgb));
|
||||
}
|
||||
|
||||
public bool Equals(Color555 other)
|
||||
{
|
||||
return _RGB == other._RGB;
|
||||
}
|
||||
|
||||
public bool Equals(Color other)
|
||||
{
|
||||
return _Color == other;
|
||||
}
|
||||
|
||||
public bool Equals(short other)
|
||||
{
|
||||
return _RGB == other;
|
||||
}
|
||||
|
||||
public bool Equals(ushort other)
|
||||
{
|
||||
return _RGB == other;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return _String ?? (_String = _Color.ToString());
|
||||
}
|
||||
|
||||
public ushort ToRgb()
|
||||
{
|
||||
return _RGB;
|
||||
}
|
||||
|
||||
public int ToArgb()
|
||||
{
|
||||
return _ARGB;
|
||||
}
|
||||
|
||||
public Color ToColor()
|
||||
{
|
||||
return _Color;
|
||||
}
|
||||
|
||||
public KnownColor ToKnownColor()
|
||||
{
|
||||
return _Color.ToKnownColor();
|
||||
}
|
||||
|
||||
public static bool operator ==(Color555 l, Color555 r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(Color555 l, Color555 r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator ==(Color555 l, Color r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(Color555 l, Color r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator ==(Color l, Color555 r)
|
||||
{
|
||||
return r.Equals(l);
|
||||
}
|
||||
|
||||
public static bool operator !=(Color l, Color555 r)
|
||||
{
|
||||
return !r.Equals(l);
|
||||
}
|
||||
|
||||
public static bool operator ==(Color555 l, ushort r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(Color555 l, ushort r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator ==(ushort l, Color555 r)
|
||||
{
|
||||
return r.Equals(l);
|
||||
}
|
||||
|
||||
public static bool operator !=(ushort l, Color555 r)
|
||||
{
|
||||
return !r.Equals(l);
|
||||
}
|
||||
|
||||
public static implicit operator Color555(Color value)
|
||||
{
|
||||
return new Color555(value);
|
||||
}
|
||||
|
||||
public static implicit operator Color555(ushort value)
|
||||
{
|
||||
return new Color555(value);
|
||||
}
|
||||
|
||||
public static implicit operator Color(Color555 value)
|
||||
{
|
||||
return value._Color;
|
||||
}
|
||||
|
||||
public static implicit operator ushort(Color555 value)
|
||||
{
|
||||
return value._RGB;
|
||||
}
|
||||
}
|
||||
}
|
||||
206
Scripts/SubSystem/VitaNex/Core/Misc/ColorGradient.cs
Normal file
206
Scripts/SubSystem/VitaNex/Core/Misc/ColorGradient.cs
Normal file
@@ -0,0 +1,206 @@
|
||||
#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;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public class ColorGradient : List<Color>, IDisposable
|
||||
{
|
||||
private static readonly Color[] _EmptyColors = new Color[0];
|
||||
private static readonly int[] _EmptySizes = new int[0];
|
||||
|
||||
public static ColorGradient CreateInstance(params Color[] colors)
|
||||
{
|
||||
return CreateInstance(0, colors);
|
||||
}
|
||||
|
||||
public static ColorGradient CreateInstance(int fade, params Color[] colors)
|
||||
{
|
||||
if (fade <= 0 || colors.Length < 2)
|
||||
{
|
||||
return new ColorGradient(colors);
|
||||
}
|
||||
|
||||
var gradient = new ColorGradient(colors.Length + ((fade - 1) * colors.Length));
|
||||
|
||||
Color c1, c2;
|
||||
double f;
|
||||
|
||||
for (var i = 0; colors.InBounds(i); i++)
|
||||
{
|
||||
c1 = colors[i];
|
||||
|
||||
if (!colors.InBounds(i + 1))
|
||||
{
|
||||
gradient.Add(c1);
|
||||
break;
|
||||
}
|
||||
|
||||
c2 = colors[i + 1];
|
||||
|
||||
for (f = 0; f < fade; f++)
|
||||
{
|
||||
gradient.Add(c1.Interpolate(c2, f / fade));
|
||||
}
|
||||
}
|
||||
|
||||
gradient.Free(false);
|
||||
|
||||
return gradient;
|
||||
}
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public ColorGradient(int capacity)
|
||||
: base(capacity)
|
||||
{ }
|
||||
|
||||
public ColorGradient(params Color[] colors)
|
||||
: base(colors.Ensure())
|
||||
{ }
|
||||
|
||||
public ColorGradient(IEnumerable<Color> colors)
|
||||
: base(colors.Ensure())
|
||||
{ }
|
||||
|
||||
~ColorGradient()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void ForEachSegment(int size, Action<int, int, Color> action)
|
||||
{
|
||||
if (size <= 0 || action == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
GetSegments(size, out var colors, out var sizes, out var count);
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Color c;
|
||||
int s;
|
||||
|
||||
for (int i = 0, o = 0; i < count; i++)
|
||||
{
|
||||
c = colors[i];
|
||||
s = sizes[i];
|
||||
|
||||
if (!c.IsEmpty && c != Color.Transparent && s > 0)
|
||||
{
|
||||
action(o, s, c);
|
||||
}
|
||||
|
||||
o += s;
|
||||
}
|
||||
}
|
||||
|
||||
public void GetSegments(int size, out Color[] colors, out int[] sizes, out int count)
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
count = 0;
|
||||
colors = _EmptyColors;
|
||||
sizes = _EmptySizes;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
count = Count;
|
||||
|
||||
if (count == 0)
|
||||
{
|
||||
colors = _EmptyColors;
|
||||
sizes = _EmptySizes;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
colors = new Color[count];
|
||||
sizes = new int[count];
|
||||
|
||||
var chunk = (int)Math.Ceiling(size / (double)count);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
colors[i] = this[i];
|
||||
sizes[i] = chunk;
|
||||
}
|
||||
|
||||
var total = sizes.Sum();
|
||||
|
||||
if (total > size)
|
||||
{
|
||||
var diff = total - size;
|
||||
|
||||
while (diff > 0)
|
||||
{
|
||||
var share = (int)Math.Ceiling(diff / (double)count);
|
||||
|
||||
for (var i = count - 1; i >= 0; i--)
|
||||
{
|
||||
sizes[i] -= share;
|
||||
|
||||
diff -= share;
|
||||
|
||||
if (diff <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (total < size)
|
||||
{
|
||||
var diff = size - total;
|
||||
|
||||
while (diff > 0)
|
||||
{
|
||||
var share = (int)Math.Ceiling(diff / (double)count);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
sizes[i] += share;
|
||||
|
||||
diff -= share;
|
||||
|
||||
if (diff <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
this.Free(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
222
Scripts/SubSystem/VitaNex/Core/Misc/CommandUtility.cs
Normal file
222
Scripts/SubSystem/VitaNex/Core/Misc/CommandUtility.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
#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.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
using Server;
|
||||
using Server.Commands;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public static class CommandUtility
|
||||
{
|
||||
private static readonly Type _TypeOfDescriptionAttribute = typeof(DescriptionAttribute);
|
||||
private static readonly Type _TypeOfUsageAttribute = typeof(UsageAttribute);
|
||||
|
||||
public static CommandEntry Unregister(string value)
|
||||
{
|
||||
CommandEntry handler = null;
|
||||
|
||||
if (!String.IsNullOrWhiteSpace(value) && CommandSystem.Entries.TryGetValue(value, out handler))
|
||||
{
|
||||
CommandSystem.Entries.Remove(value);
|
||||
}
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
public static bool Register(string value, AccessLevel access, CommandEventHandler handler)
|
||||
{
|
||||
return Register(value, access, handler, out var entry);
|
||||
}
|
||||
|
||||
public static bool Register(string value, AccessLevel access, CommandEventHandler handler, out CommandEntry entry)
|
||||
{
|
||||
entry = null;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (CommandSystem.Entries.ContainsKey(value))
|
||||
{
|
||||
return Replace(value, access, handler, value, out entry);
|
||||
}
|
||||
|
||||
CommandSystem.Register(value, access, handler);
|
||||
|
||||
return CommandSystem.Entries.TryGetValue(value, out entry);
|
||||
}
|
||||
|
||||
public static bool RegisterAlias(string value, string alias)
|
||||
{
|
||||
return RegisterAlias(value, alias, out var entry);
|
||||
}
|
||||
|
||||
public static bool RegisterAlias(string value, string alias, out CommandEntry entry)
|
||||
{
|
||||
entry = null;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(value) || String.IsNullOrWhiteSpace(alias))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CommandSystem.Entries.TryGetValue(value, out entry) || entry == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return Register(alias, entry.AccessLevel, entry.Handler, out entry);
|
||||
}
|
||||
|
||||
public static bool Replace(string value, AccessLevel access, CommandEventHandler handler, string newValue)
|
||||
{
|
||||
return Replace(value, access, handler, newValue, out var entry);
|
||||
}
|
||||
|
||||
public static bool Replace(
|
||||
string value,
|
||||
AccessLevel access,
|
||||
CommandEventHandler handler,
|
||||
string newValue,
|
||||
out CommandEntry entry)
|
||||
{
|
||||
entry = null;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(newValue))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = newValue;
|
||||
}
|
||||
|
||||
if (handler == null)
|
||||
{
|
||||
if (!CommandSystem.Entries.ContainsKey(value))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
handler = CommandSystem.Entries[value].Handler;
|
||||
}
|
||||
|
||||
if (value != newValue)
|
||||
{
|
||||
if (String.IsNullOrWhiteSpace(newValue))
|
||||
{
|
||||
Unregister(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
value = newValue;
|
||||
}
|
||||
|
||||
Unregister(value);
|
||||
CommandSystem.Register(value, access, handler);
|
||||
|
||||
return CommandSystem.Entries.TryGetValue(value, out entry);
|
||||
}
|
||||
|
||||
public static bool SetAccess(string value, AccessLevel access)
|
||||
{
|
||||
if (!String.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
if (CommandSystem.Entries.TryGetValue(value, out var handler))
|
||||
{
|
||||
return Register(value, access, handler.Handler);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static IEnumerable<CommandEntry> EnumerateCommands(AccessLevel level)
|
||||
{
|
||||
return CommandSystem.Entries.Values.Where(o => o != null && o.Handler != null)
|
||||
.Where(o => !String.IsNullOrWhiteSpace(o.Command))
|
||||
.Where(o => level >= o.AccessLevel);
|
||||
}
|
||||
|
||||
public static IEnumerable<CommandEntry> EnumerateCommands()
|
||||
{
|
||||
return EnumerateCommands(0);
|
||||
}
|
||||
|
||||
public static ILookup<AccessLevel, CommandEntry> LookupCommands(AccessLevel level)
|
||||
{
|
||||
return EnumerateCommands(level)
|
||||
.ToLookup(o => o.Handler.Method)
|
||||
.Select(o => o.Highest(e => e.Command.Length))
|
||||
.ToLookup(o => o.AccessLevel);
|
||||
}
|
||||
|
||||
public static ILookup<AccessLevel, CommandEntry> LookupCommands()
|
||||
{
|
||||
return LookupCommands(0);
|
||||
}
|
||||
|
||||
public static string GetDescription(this CommandEntry e)
|
||||
{
|
||||
return GetDescription(e.Handler);
|
||||
}
|
||||
|
||||
public static string GetDescription(this CommandEventHandler o)
|
||||
{
|
||||
if (o == null)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
return String.Join(
|
||||
"\n",
|
||||
o.Method.GetCustomAttributes(_TypeOfDescriptionAttribute, true)
|
||||
.OfType<DescriptionAttribute>()
|
||||
.Where(a => !String.IsNullOrWhiteSpace(a.Description))
|
||||
.Select(a => a.Description.StripCRLF().StripExcessWhiteSpace())
|
||||
.Select(v => Regex.Replace(v, @"[\<\{]", "("))
|
||||
.Select(v => Regex.Replace(v, @"[\>\}]", ")")));
|
||||
}
|
||||
|
||||
public static string GetUsage(this CommandEntry e)
|
||||
{
|
||||
return GetUsage(e.Handler);
|
||||
}
|
||||
|
||||
public static string GetUsage(this CommandEventHandler o)
|
||||
{
|
||||
if (o == null)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
var usage = String.Join(
|
||||
"\n",
|
||||
o.Method.GetCustomAttributes(_TypeOfUsageAttribute, true)
|
||||
.OfType<UsageAttribute>()
|
||||
.Where(a => !String.IsNullOrWhiteSpace(a.Usage))
|
||||
.Select(a => a.Usage.StripCRLF().StripExcessWhiteSpace())
|
||||
.Select(v => Regex.Replace(v, @"[\<\{]", "("))
|
||||
.Select(v => Regex.Replace(v, @"[\>\}]", ")")));
|
||||
|
||||
return usage;
|
||||
}
|
||||
}
|
||||
}
|
||||
106
Scripts/SubSystem/VitaNex/Core/Misc/CustomContextEntry.cs
Normal file
106
Scripts/SubSystem/VitaNex/Core/Misc/CustomContextEntry.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using VitaNex;
|
||||
#endregion
|
||||
|
||||
namespace Server.ContextMenus
|
||||
{
|
||||
public class CustomContextEntry : ContextMenuEntry
|
||||
{
|
||||
public static Color555 DefaultColor = 0xFFFF;
|
||||
|
||||
private static Action<IEntity, Mobile> WrapCallback(Action<Mobile> callback)
|
||||
{
|
||||
if (callback != null)
|
||||
{
|
||||
return (e, m) => callback(m);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Action<IEntity, Mobile> Callback { get; set; }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<Mobile> callback)
|
||||
: this(clilocID, WrapCallback(callback))
|
||||
{ }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<Mobile> callback, Color555 color)
|
||||
: this(clilocID, WrapCallback(callback), color)
|
||||
{ }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<Mobile> callback, bool enabled)
|
||||
: this(clilocID, WrapCallback(callback), enabled)
|
||||
{ }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<Mobile> callback, bool enabled, Color555 color)
|
||||
: this(clilocID, WrapCallback(callback), enabled, color)
|
||||
{ }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<IEntity, Mobile> callback)
|
||||
: this(clilocID, callback, true, DefaultColor)
|
||||
{ }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<IEntity, Mobile> callback, Color555 color)
|
||||
: this(clilocID, callback, true, color)
|
||||
{ }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<IEntity, Mobile> callback, bool enabled)
|
||||
: this(clilocID, callback, enabled, DefaultColor)
|
||||
{ }
|
||||
|
||||
public CustomContextEntry(int clilocID, Action<IEntity, Mobile> callback, bool enabled, Color555 color)
|
||||
: base(clilocID)
|
||||
{
|
||||
Callback = callback;
|
||||
Enabled = enabled;
|
||||
Color = color;
|
||||
}
|
||||
|
||||
public override sealed void OnClick()
|
||||
{
|
||||
if (Enabled && OnClick(Owner.Target, Owner.From))
|
||||
{
|
||||
OnCallback(Owner.Target, Owner.From);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnCallback(object owner, Mobile user)
|
||||
{
|
||||
if (owner is IEntity)
|
||||
{
|
||||
OnCallback((IEntity)owner, user);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnCallback(IEntity owner, Mobile user)
|
||||
{
|
||||
if (Callback != null)
|
||||
{
|
||||
Callback(owner, user);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual bool OnClick(object owner, Mobile user)
|
||||
{
|
||||
return owner is IEntity && OnClick((IEntity)owner, user);
|
||||
}
|
||||
|
||||
protected virtual bool OnClick(IEntity owner, Mobile user)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
587
Scripts/SubSystem/VitaNex/Core/Misc/DataTypes.cs
Normal file
587
Scripts/SubSystem/VitaNex/Core/Misc/DataTypes.cs
Normal file
@@ -0,0 +1,587 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace System
|
||||
{
|
||||
public enum DataType
|
||||
{
|
||||
Null = 0,
|
||||
Bool,
|
||||
Char,
|
||||
Byte,
|
||||
SByte,
|
||||
Short,
|
||||
UShort,
|
||||
Int,
|
||||
UInt,
|
||||
Long,
|
||||
ULong,
|
||||
Float,
|
||||
Decimal,
|
||||
Double,
|
||||
String,
|
||||
DateTime,
|
||||
TimeSpan
|
||||
}
|
||||
|
||||
public struct SimpleType
|
||||
{
|
||||
private static readonly object _InvalidCast = new object();
|
||||
|
||||
public static SimpleType Null => new SimpleType((object)null);
|
||||
|
||||
public DataType Flag { get; private set; }
|
||||
public Type Type { get; private set; }
|
||||
public object Value { get; private set; }
|
||||
|
||||
public bool HasValue => Value != null;
|
||||
|
||||
public SimpleType(object obj)
|
||||
: this()
|
||||
{
|
||||
Value = obj;
|
||||
Type = obj != null ? obj.GetType() : null;
|
||||
Flag = DataTypes.Lookup(Type);
|
||||
|
||||
//Console.WriteLine("SimpleType: {0} ({1}) [{2}]", Value, Type, Flag);
|
||||
|
||||
if (Flag == DataType.Null)
|
||||
{
|
||||
Value = null;
|
||||
}
|
||||
}
|
||||
|
||||
public SimpleType(GenericReader reader)
|
||||
: this()
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
public T Cast<T>()
|
||||
{
|
||||
return TryCast(out T value) ? value : default(T);
|
||||
}
|
||||
|
||||
public bool TryCast<T>(out T value)
|
||||
{
|
||||
value = default(T);
|
||||
|
||||
try
|
||||
{
|
||||
var cast = _InvalidCast;
|
||||
|
||||
if (this is T)
|
||||
{
|
||||
cast = this;
|
||||
}
|
||||
else if (HasValue)
|
||||
{
|
||||
if (Value is T)
|
||||
{
|
||||
cast = Value;
|
||||
}
|
||||
else if (value is string)
|
||||
{
|
||||
cast = Value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
if (cast != _InvalidCast)
|
||||
{
|
||||
value = (T)cast;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0} ({1})", Value != null ? Value.ToString() : "null", Flag);
|
||||
}
|
||||
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.WriteFlag(Flag);
|
||||
|
||||
switch (Flag)
|
||||
{
|
||||
case DataType.Null:
|
||||
break;
|
||||
case DataType.Bool:
|
||||
writer.Write(Convert.ToBoolean(Value));
|
||||
break;
|
||||
case DataType.Char:
|
||||
writer.Write(Convert.ToChar(Value));
|
||||
break;
|
||||
case DataType.Byte:
|
||||
writer.Write(Convert.ToByte(Value));
|
||||
break;
|
||||
case DataType.SByte:
|
||||
writer.Write(Convert.ToSByte(Value));
|
||||
break;
|
||||
case DataType.Short:
|
||||
writer.Write(Convert.ToInt16(Value));
|
||||
break;
|
||||
case DataType.UShort:
|
||||
writer.Write(Convert.ToUInt16(Value));
|
||||
break;
|
||||
case DataType.Int:
|
||||
writer.Write(Convert.ToInt32(Value));
|
||||
break;
|
||||
case DataType.UInt:
|
||||
writer.Write(Convert.ToUInt32(Value));
|
||||
break;
|
||||
case DataType.Long:
|
||||
writer.Write(Convert.ToInt64(Value));
|
||||
break;
|
||||
case DataType.ULong:
|
||||
writer.Write(Convert.ToUInt64(Value));
|
||||
break;
|
||||
case DataType.Float:
|
||||
writer.Write(Convert.ToSingle(Value));
|
||||
break;
|
||||
case DataType.Decimal:
|
||||
writer.Write(Convert.ToDecimal(Value));
|
||||
break;
|
||||
case DataType.Double:
|
||||
writer.Write(Convert.ToDouble(Value));
|
||||
break;
|
||||
case DataType.String:
|
||||
writer.Write(Convert.ToString(Value));
|
||||
break;
|
||||
case DataType.DateTime:
|
||||
writer.Write(Convert.ToDateTime(Value));
|
||||
break;
|
||||
case DataType.TimeSpan:
|
||||
writer.Write((TimeSpan)Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Deserialize(GenericReader reader)
|
||||
{
|
||||
Flag = reader.ReadFlag<DataType>();
|
||||
Type = Flag.ToType();
|
||||
|
||||
switch (Flag)
|
||||
{
|
||||
case DataType.Null:
|
||||
Value = null;
|
||||
break;
|
||||
case DataType.Bool:
|
||||
Value = reader.ReadBool();
|
||||
break;
|
||||
case DataType.Char:
|
||||
Value = reader.ReadChar();
|
||||
break;
|
||||
case DataType.Byte:
|
||||
Value = reader.ReadByte();
|
||||
break;
|
||||
case DataType.SByte:
|
||||
Value = reader.ReadSByte();
|
||||
break;
|
||||
case DataType.Short:
|
||||
Value = reader.ReadShort();
|
||||
break;
|
||||
case DataType.UShort:
|
||||
Value = reader.ReadUShort();
|
||||
break;
|
||||
case DataType.Int:
|
||||
Value = reader.ReadInt();
|
||||
break;
|
||||
case DataType.UInt:
|
||||
Value = reader.ReadUInt();
|
||||
break;
|
||||
case DataType.Long:
|
||||
Value = reader.ReadLong();
|
||||
break;
|
||||
case DataType.ULong:
|
||||
Value = reader.ReadULong();
|
||||
break;
|
||||
case DataType.Float:
|
||||
Value = reader.ReadFloat();
|
||||
break;
|
||||
case DataType.Decimal:
|
||||
Value = reader.ReadDecimal();
|
||||
break;
|
||||
case DataType.Double:
|
||||
Value = reader.ReadDouble();
|
||||
break;
|
||||
case DataType.String:
|
||||
Value = reader.ReadString() ?? String.Empty;
|
||||
break;
|
||||
case DataType.DateTime:
|
||||
Value = reader.ReadDateTime();
|
||||
break;
|
||||
case DataType.TimeSpan:
|
||||
Value = reader.ReadTimeSpan();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsSimpleType(object value)
|
||||
{
|
||||
return value != null && DataTypes.Lookup(value) != DataType.Null;
|
||||
}
|
||||
|
||||
public static bool IsSimpleType(Type type)
|
||||
{
|
||||
return type != null && DataTypes.Lookup(type) != DataType.Null;
|
||||
}
|
||||
|
||||
public static object ToObject(SimpleType value)
|
||||
{
|
||||
return value.Value;
|
||||
}
|
||||
|
||||
public static SimpleType FromObject(object value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static bool TryParse<T>(string data, out T value)
|
||||
{
|
||||
value = default(T);
|
||||
|
||||
var flag = DataTypes.Lookup(value);
|
||||
|
||||
object val;
|
||||
|
||||
if (flag == DataType.Null)
|
||||
{
|
||||
var i = 0;
|
||||
|
||||
while (i < DataTypes.NumericFlags.Length)
|
||||
{
|
||||
flag = DataTypes.NumericFlags[i++];
|
||||
|
||||
if (TryConvert(data, flag, out val))
|
||||
{
|
||||
try
|
||||
{
|
||||
value = (T)val;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryConvert(data, flag, out val))
|
||||
{
|
||||
try
|
||||
{
|
||||
value = (T)val;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TryParse(string data, DataType flag, out SimpleType value)
|
||||
{
|
||||
value = Null;
|
||||
|
||||
object val;
|
||||
|
||||
if (flag == DataType.Null)
|
||||
{
|
||||
var i = 0;
|
||||
|
||||
while (i < DataTypes.NumericFlags.Length)
|
||||
{
|
||||
flag = DataTypes.NumericFlags[i++];
|
||||
|
||||
if (TryConvert(data, flag, out val))
|
||||
{
|
||||
try
|
||||
{
|
||||
value = new SimpleType(val);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryConvert(data, flag, out val))
|
||||
{
|
||||
try
|
||||
{
|
||||
value = new SimpleType(val);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool TryConvert(string data, DataType flag, out object val)
|
||||
{
|
||||
val = null;
|
||||
|
||||
if (flag == DataType.Null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var numStyle = Insensitive.StartsWith(data.Trim(), "0x") ? NumberStyles.HexNumber : NumberStyles.Any;
|
||||
|
||||
if (numStyle == NumberStyles.HexNumber)
|
||||
{
|
||||
data = data.Substring(data.IndexOf("0x", StringComparison.OrdinalIgnoreCase) + 2);
|
||||
}
|
||||
|
||||
switch (flag)
|
||||
{
|
||||
case DataType.Bool:
|
||||
val = Boolean.Parse(data);
|
||||
return true;
|
||||
case DataType.Char:
|
||||
val = Char.Parse(data);
|
||||
return true;
|
||||
case DataType.Byte:
|
||||
val = Byte.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.SByte:
|
||||
val = SByte.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.Short:
|
||||
val = Int16.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.UShort:
|
||||
val = UInt16.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.Int:
|
||||
val = Int32.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.UInt:
|
||||
val = UInt32.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.Long:
|
||||
val = Int64.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.ULong:
|
||||
val = UInt64.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.Float:
|
||||
val = Single.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.Decimal:
|
||||
val = Decimal.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.Double:
|
||||
val = Double.Parse(data, numStyle);
|
||||
return true;
|
||||
case DataType.String:
|
||||
val = data;
|
||||
return true;
|
||||
case DataType.DateTime:
|
||||
val = DateTime.Parse(data, CultureInfo.CurrentCulture, DateTimeStyles.AllowWhiteSpaces);
|
||||
return true;
|
||||
case DataType.TimeSpan:
|
||||
val = TimeSpan.Parse(data);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(bool value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(char value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(byte value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(sbyte value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(short value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(ushort value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(int value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(uint value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(long value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(ulong value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(float value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(decimal value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(double value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(string value)
|
||||
{
|
||||
return new SimpleType(value ?? String.Empty);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(DateTime value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
|
||||
public static implicit operator SimpleType(TimeSpan value)
|
||||
{
|
||||
return new SimpleType(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static class DataTypes
|
||||
{
|
||||
private static readonly Dictionary<DataType, Type> _DataTypeTable = new Dictionary<DataType, Type>
|
||||
{
|
||||
{DataType.Null, null},
|
||||
{DataType.Bool, typeof(bool)},
|
||||
{DataType.Char, typeof(char)},
|
||||
{DataType.Byte, typeof(byte)},
|
||||
{DataType.SByte, typeof(sbyte)},
|
||||
{DataType.Short, typeof(short)},
|
||||
{DataType.UShort, typeof(ushort)},
|
||||
{DataType.Int, typeof(int)},
|
||||
{DataType.UInt, typeof(uint)},
|
||||
{DataType.Long, typeof(long)},
|
||||
{DataType.ULong, typeof(ulong)},
|
||||
{DataType.Float, typeof(float)},
|
||||
{DataType.Decimal, typeof(decimal)},
|
||||
{DataType.Double, typeof(double)},
|
||||
{DataType.String, typeof(string)},
|
||||
{DataType.DateTime, typeof(DateTime)},
|
||||
{DataType.TimeSpan, typeof(TimeSpan)}
|
||||
};
|
||||
|
||||
public static DataType[] Flags = _DataTypeTable.Keys.ToArray();
|
||||
|
||||
public static DataType[] IntegralNumericFlags =
|
||||
{
|
||||
DataType.Byte, DataType.SByte, DataType.Short, DataType.UShort, DataType.Int, DataType.UInt, DataType.Long,
|
||||
DataType.ULong
|
||||
};
|
||||
|
||||
public static DataType[] RealNumericFlags = { DataType.Float, DataType.Decimal, DataType.Double };
|
||||
|
||||
public static DataType[] NumericFlags = IntegralNumericFlags.Merge(RealNumericFlags);
|
||||
|
||||
public static Type ToType(this DataType f)
|
||||
{
|
||||
return Lookup(f);
|
||||
}
|
||||
|
||||
public static DataType FromType(Type t)
|
||||
{
|
||||
return Lookup(t);
|
||||
}
|
||||
|
||||
public static DataType Lookup(object o)
|
||||
{
|
||||
return o != null ? Lookup(o.GetType()) : DataType.Null;
|
||||
}
|
||||
|
||||
public static DataType Lookup(Type t)
|
||||
{
|
||||
return _DataTypeTable.GetKey(t);
|
||||
}
|
||||
|
||||
public static Type Lookup(DataType f)
|
||||
{
|
||||
return _DataTypeTable.GetValue(f);
|
||||
}
|
||||
|
||||
public static bool IsSimple(this Type t)
|
||||
{
|
||||
return Lookup(t) != DataType.Null;
|
||||
}
|
||||
|
||||
public static DataType GetDataType(this Type t)
|
||||
{
|
||||
return Lookup(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
137
Scripts/SubSystem/VitaNex/Core/Misc/ExpansionFlags.cs
Normal file
137
Scripts/SubSystem/VitaNex/Core/Misc/ExpansionFlags.cs
Normal file
@@ -0,0 +1,137 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[Flags]
|
||||
public enum ExpansionFlags
|
||||
{
|
||||
None = 0x0,
|
||||
|
||||
T2A = 0x1,
|
||||
UOR = 0x2,
|
||||
UOTD = 0x4,
|
||||
LBR = 0x8,
|
||||
AOS = 0x10,
|
||||
SE = 0x20,
|
||||
ML = 0x40,
|
||||
SA = 0x80,
|
||||
HS = 0x100,
|
||||
TOL = 0x200,
|
||||
EJ = 0x400,
|
||||
|
||||
PreUOR = T2A,
|
||||
PostUOR = UOR | UOTD | LBR | AOS | SE | ML | SA | HS | TOL | EJ,
|
||||
|
||||
PreAOS = T2A | UOR | UOTD | LBR,
|
||||
PostAOS = AOS | SE | ML | SA | HS | TOL | EJ,
|
||||
|
||||
PreSE = T2A | UOR | UOTD | LBR | AOS,
|
||||
PostSE = SE | ML | SA | HS | TOL | EJ,
|
||||
|
||||
PreML = T2A | UOR | UOTD | LBR | AOS | SE,
|
||||
PostML = ML | SA | HS | TOL | EJ,
|
||||
|
||||
PreSA = T2A | UOR | UOTD | LBR | AOS | SE | ML,
|
||||
PostSA = SA | HS | TOL | EJ,
|
||||
|
||||
PreHS = T2A | UOR | UOTD | LBR | AOS | SE | ML | SA,
|
||||
PostHS = HS | TOL | EJ,
|
||||
|
||||
PreTOL = T2A | UOR | UOTD | LBR | AOS | SE | ML | SA | HS,
|
||||
PostTOL = TOL | EJ,
|
||||
|
||||
PreEJ = T2A | UOR | UOTD | LBR | AOS | SE | ML | SA | HS | TOL,
|
||||
PostEJ = EJ,
|
||||
|
||||
All = ~None
|
||||
}
|
||||
|
||||
public interface IExpansionCheck
|
||||
{
|
||||
ExpansionFlags Expansions { get; }
|
||||
}
|
||||
|
||||
public static class ExpansionFlagsExtension
|
||||
{
|
||||
public static bool CheckExpansion(this IExpansionCheck o)
|
||||
{
|
||||
return o != null && CheckExpansion(o.Expansions);
|
||||
}
|
||||
|
||||
public static bool CheckExpansion(this IExpansionCheck o, Expansion ex)
|
||||
{
|
||||
return o != null && CheckExpansion(o.Expansions, ex);
|
||||
}
|
||||
|
||||
public static string GetName(this ExpansionFlags flags)
|
||||
{
|
||||
return GetName(flags, ", ");
|
||||
}
|
||||
|
||||
public static string GetName(this ExpansionFlags flags, string separator)
|
||||
{
|
||||
if (flags == ExpansionFlags.None)
|
||||
{
|
||||
return "None";
|
||||
}
|
||||
|
||||
return String.Join(separator, flags.EnumerateValues<ExpansionFlags>(true).Not(s => s == ExpansionFlags.None));
|
||||
}
|
||||
|
||||
public static bool CheckExpansion(this ExpansionFlags flags)
|
||||
{
|
||||
return CheckExpansion(flags, Core.Expansion);
|
||||
}
|
||||
|
||||
public static bool CheckExpansion(this ExpansionFlags flags, Expansion ex)
|
||||
{
|
||||
if (flags == ExpansionFlags.None)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (ex)
|
||||
{
|
||||
case Expansion.T2A:
|
||||
return flags.HasFlag(ExpansionFlags.T2A);
|
||||
case Expansion.UOR:
|
||||
return flags.HasFlag(ExpansionFlags.UOR);
|
||||
case Expansion.UOTD:
|
||||
return flags.HasFlag(ExpansionFlags.UOTD);
|
||||
case Expansion.LBR:
|
||||
return flags.HasFlag(ExpansionFlags.LBR);
|
||||
case Expansion.AOS:
|
||||
return flags.HasFlag(ExpansionFlags.AOS);
|
||||
case Expansion.SE:
|
||||
return flags.HasFlag(ExpansionFlags.SE);
|
||||
case Expansion.ML:
|
||||
return flags.HasFlag(ExpansionFlags.ML);
|
||||
case Expansion.SA:
|
||||
return flags.HasFlag(ExpansionFlags.SA);
|
||||
case Expansion.HS:
|
||||
return flags.HasFlag(ExpansionFlags.HS);
|
||||
case Expansion.TOL:
|
||||
return flags.HasFlag(ExpansionFlags.TOL);
|
||||
case Expansion.EJ:
|
||||
return flags.HasFlag(ExpansionFlags.EJ);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
557
Scripts/SubSystem/VitaNex/Core/Misc/Grid.cs
Normal file
557
Scripts/SubSystem/VitaNex/Core/Misc/Grid.cs
Normal file
@@ -0,0 +1,557 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
|
||||
using VitaNex.Collections;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public class Grid<T> : IEnumerable<T>
|
||||
{
|
||||
private List<List<T>> _InternalGrid;
|
||||
|
||||
private Size _Size = Size.Empty;
|
||||
|
||||
public Action<GenericWriter, T, int, int> OnSerializeContent { get; set; }
|
||||
public Func<GenericReader, Type, int, int, T> OnDeserializeContent { get; set; }
|
||||
|
||||
public virtual T DefaultValue { get; set; }
|
||||
|
||||
public virtual int Width { get => _Size.Width; set => Resize(value, _Size.Height); }
|
||||
public virtual int Height { get => _Size.Height; set => Resize(_Size.Width, value); }
|
||||
|
||||
public virtual T this[int x, int y]
|
||||
{
|
||||
get
|
||||
{
|
||||
var val = DefaultValue;
|
||||
|
||||
if (InBounds(x, y))
|
||||
{
|
||||
val = _InternalGrid[x][y];
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (InBounds(x, y))
|
||||
{
|
||||
_InternalGrid[x][y] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Count => _InternalGrid.SelectMany(e => e).Count(e => e != null);
|
||||
|
||||
public int Capacity => Width * Height;
|
||||
|
||||
public Grid()
|
||||
: this(0, 0)
|
||||
{
|
||||
DefaultValue = default(T);
|
||||
}
|
||||
|
||||
public Grid(Grid<T> grid)
|
||||
: this(grid.Width, grid.Height)
|
||||
{
|
||||
SetAllContent(grid.GetContent);
|
||||
}
|
||||
|
||||
public Grid(int width, int height)
|
||||
{
|
||||
_InternalGrid = ListPool<List<T>>.AcquireObject();
|
||||
|
||||
Resize(width, height);
|
||||
}
|
||||
|
||||
public Grid(GenericReader reader)
|
||||
{
|
||||
_InternalGrid = ListPool<List<T>>.AcquireObject();
|
||||
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
~Grid()
|
||||
{
|
||||
if (!_InternalGrid.IsNullOrEmpty())
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
ObjectPool.Free(ref _InternalGrid);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
foreach (var col in _InternalGrid)
|
||||
{
|
||||
col.Clear();
|
||||
}
|
||||
|
||||
_InternalGrid.Clear();
|
||||
}
|
||||
|
||||
public void TrimExcess()
|
||||
{
|
||||
foreach (var col in _InternalGrid)
|
||||
{
|
||||
col.TrimExcess();
|
||||
}
|
||||
|
||||
_InternalGrid.TrimExcess();
|
||||
}
|
||||
|
||||
public void Free(bool clear)
|
||||
{
|
||||
if (clear)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
TrimExcess();
|
||||
}
|
||||
|
||||
public void TrimOverflow()
|
||||
{
|
||||
for (var x = Width - 1; x >= 0; x--)
|
||||
{
|
||||
if (FindCells(x, 0, 1, Height).All(e => e == null))
|
||||
{
|
||||
RemoveColumn(x);
|
||||
}
|
||||
}
|
||||
|
||||
for (var y = Height - 1; y >= 0; y--)
|
||||
{
|
||||
if (FindCells(0, y, Width, 1).All(e => e == null))
|
||||
{
|
||||
RemoveRow(y);
|
||||
}
|
||||
}
|
||||
|
||||
TrimExcess();
|
||||
}
|
||||
|
||||
public virtual void ForEach(Action<int, int> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var x = 0; x < Width; x++)
|
||||
{
|
||||
for (var y = 0; y < Height; y++)
|
||||
{
|
||||
action(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ForEach(Action<int, int, T> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var x = 0; x < Width; x++)
|
||||
{
|
||||
for (var y = 0; y < Height; y++)
|
||||
{
|
||||
action(x, y, this[x, y]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void ForEachIndex(Action<int, int, int> action)
|
||||
{
|
||||
if (action == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var i = 0;
|
||||
|
||||
for (var x = 0; x < Width; x++)
|
||||
{
|
||||
for (var y = 0; y < Height; y++)
|
||||
{
|
||||
action(x, y, i++);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Resize(int width, int height)
|
||||
{
|
||||
width = Math.Max(0, width);
|
||||
height = Math.Max(0, height);
|
||||
|
||||
if (width * height > 0)
|
||||
{
|
||||
while (Height != height)
|
||||
{
|
||||
if (Height < height)
|
||||
{
|
||||
AppendRow();
|
||||
}
|
||||
else if (Height > height)
|
||||
{
|
||||
RemoveRow(Height - 1);
|
||||
}
|
||||
}
|
||||
|
||||
while (Width != width)
|
||||
{
|
||||
if (Width < width)
|
||||
{
|
||||
AppendColumn();
|
||||
}
|
||||
else if (Width > width)
|
||||
{
|
||||
RemoveColumn(Width - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
_Size = new Size(width, height);
|
||||
}
|
||||
|
||||
public virtual Point GetLocaton(T content)
|
||||
{
|
||||
for (var x = 0; x < Width; x++)
|
||||
{
|
||||
for (var y = 0; y < Height; y++)
|
||||
{
|
||||
if (Equals(this[x, y], content))
|
||||
{
|
||||
return new Point(x, y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Point(-1, -1);
|
||||
}
|
||||
|
||||
public virtual T[] GetCells()
|
||||
{
|
||||
return GetCells(0, 0, Width, Height);
|
||||
}
|
||||
|
||||
public virtual T[] GetCells(int x, int y, int w, int h)
|
||||
{
|
||||
return FindCells(x, y, w, h).ToArray();
|
||||
}
|
||||
|
||||
public virtual IEnumerable<T> FindCells(int x, int y, int w, int h)
|
||||
{
|
||||
for (var col = x; col < x + w; col++)
|
||||
{
|
||||
if (!_InternalGrid.InBounds(col))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var row = y; row < y + h; row++)
|
||||
{
|
||||
if (_InternalGrid[col].InBounds(row))
|
||||
{
|
||||
yield return _InternalGrid[col][row];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public virtual T[][] SelectCells(Rectangle2D bounds)
|
||||
{
|
||||
return SelectCells(bounds.X, bounds.Y, bounds.Width, bounds.Height);
|
||||
}
|
||||
|
||||
public virtual T[][] SelectCells(int x, int y, int w, int h)
|
||||
{
|
||||
var list = new T[w][];
|
||||
|
||||
for (int xx = 0, col = x; col < x + w; col++, xx++)
|
||||
{
|
||||
list[xx] = new T[h];
|
||||
|
||||
for (int yy = 0, row = y; row < y + h; row++, yy++)
|
||||
{
|
||||
if (col >= Width || row >= Height)
|
||||
{
|
||||
list[xx][yy] = DefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
list[xx][yy] = this[col, row];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public virtual void PrependColumn()
|
||||
{
|
||||
InsertColumn(0);
|
||||
}
|
||||
|
||||
public virtual void AppendColumn()
|
||||
{
|
||||
InsertColumn(Width);
|
||||
}
|
||||
|
||||
public virtual void InsertColumn(int x)
|
||||
{
|
||||
x = Math.Max(0, x);
|
||||
|
||||
var col = ListPool<T>.AcquireObject();
|
||||
|
||||
col.Capacity = Height;
|
||||
col.SetAll(DefaultValue);
|
||||
|
||||
if (x >= Width)
|
||||
{
|
||||
_InternalGrid.Add(col);
|
||||
}
|
||||
else
|
||||
{
|
||||
_InternalGrid.Insert(x, col);
|
||||
}
|
||||
|
||||
_Size = new Size(_InternalGrid.Count, _Size.Height);
|
||||
}
|
||||
|
||||
public virtual void RemoveColumn(int x)
|
||||
{
|
||||
if (x >= 0 && x < Width)
|
||||
{
|
||||
if (_InternalGrid.InBounds(x))
|
||||
{
|
||||
ObjectPool.Free(_InternalGrid[x]);
|
||||
|
||||
_InternalGrid.RemoveAt(x);
|
||||
}
|
||||
}
|
||||
|
||||
_Size = new Size(_InternalGrid.Count, _Size.Height);
|
||||
}
|
||||
|
||||
public virtual void PrependRow()
|
||||
{
|
||||
InsertRow(0);
|
||||
}
|
||||
|
||||
public virtual void AppendRow()
|
||||
{
|
||||
InsertRow(Height);
|
||||
}
|
||||
|
||||
public virtual void InsertRow(int y)
|
||||
{
|
||||
y = Math.Max(0, y);
|
||||
|
||||
foreach (var col in _InternalGrid)
|
||||
{
|
||||
if (y >= Height)
|
||||
{
|
||||
col.Add(DefaultValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
col.Insert(y, DefaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
_Size = new Size(_InternalGrid.Count, Math.Max(0, _Size.Height + 1));
|
||||
}
|
||||
|
||||
public virtual void RemoveRow(int y)
|
||||
{
|
||||
if (y >= 0 && y < Height)
|
||||
{
|
||||
foreach (var col in _InternalGrid)
|
||||
{
|
||||
if (col.InBounds(y))
|
||||
{
|
||||
col.RemoveAt(y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_Size = new Size(_InternalGrid.Count, Math.Max(0, _Size.Height - 1));
|
||||
}
|
||||
|
||||
public virtual T GetContent(int x, int y)
|
||||
{
|
||||
return this[x, y];
|
||||
}
|
||||
|
||||
public virtual void SetContent(int x, int y, T content)
|
||||
{
|
||||
if (x >= Width || y >= Height)
|
||||
{
|
||||
Resize(Width, Height);
|
||||
}
|
||||
|
||||
this[x, y] = content;
|
||||
}
|
||||
|
||||
public virtual void SetAllContent(T content, Predicate<T> replace)
|
||||
{
|
||||
ForEach(
|
||||
(x, y, c) =>
|
||||
{
|
||||
if (replace == null || replace(c))
|
||||
{
|
||||
this[x, y] = content;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public virtual void SetAllContent(Func<int, int, T> resolve)
|
||||
{
|
||||
if (resolve != null)
|
||||
{
|
||||
ForEach((x, y, c) => this[x, y] = resolve(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetAllContent(Func<int, int, T, T> resolve)
|
||||
{
|
||||
if (resolve != null)
|
||||
{
|
||||
ForEach((x, y, c) => this[x, y] = resolve(x, y, c));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SetAllContent(Func<int, int, int, T> resolve)
|
||||
{
|
||||
if (resolve != null)
|
||||
{
|
||||
ForEachIndex((x, y, i) => this[x, y] = resolve(x, y, i));
|
||||
}
|
||||
}
|
||||
|
||||
public bool InBounds(int gx, int gy)
|
||||
{
|
||||
return _InternalGrid.InBounds(gx) && _InternalGrid[gx].InBounds(gy);
|
||||
}
|
||||
|
||||
public virtual IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
return _InternalGrid.SelectMany(x => x).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
|
||||
public virtual void Serialize(GenericWriter writer)
|
||||
{
|
||||
var version = writer.SetVersion(0);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
writer.Write(Width);
|
||||
writer.Write(Height);
|
||||
|
||||
ForEach(
|
||||
(x, y, c) =>
|
||||
{
|
||||
if (c == null)
|
||||
{
|
||||
writer.Write(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.Write(true);
|
||||
writer.WriteType(c);
|
||||
|
||||
SerializeContent(writer, c, x, y);
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Deserialize(GenericReader reader)
|
||||
{
|
||||
var version = reader.GetVersion();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
var width = reader.ReadInt();
|
||||
var height = reader.ReadInt();
|
||||
|
||||
Resize(width, height);
|
||||
|
||||
ForEach(
|
||||
(x, y, c) =>
|
||||
{
|
||||
if (!reader.ReadBool())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var type = reader.ReadType();
|
||||
|
||||
this[x, y] = DeserializeContent(reader, type, x, y);
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void SerializeContent(GenericWriter writer, T content, int x, int y)
|
||||
{
|
||||
if (OnSerializeContent != null)
|
||||
{
|
||||
OnSerializeContent(writer, content, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual T DeserializeContent(GenericReader reader, Type type, int x, int y)
|
||||
{
|
||||
return OnDeserializeContent != null ? OnDeserializeContent(reader, type, x, y) : DefaultValue;
|
||||
}
|
||||
|
||||
public static implicit operator Rectangle2D(Grid<T> grid)
|
||||
{
|
||||
return new Rectangle2D(0, 0, grid.Width, grid.Height);
|
||||
}
|
||||
|
||||
public static implicit operator Grid<T>(Rectangle2D rect)
|
||||
{
|
||||
return new Grid<T>(rect.Width, rect.Height);
|
||||
}
|
||||
}
|
||||
}
|
||||
485
Scripts/SubSystem/VitaNex/Core/Misc/IconDefinition.cs
Normal file
485
Scripts/SubSystem/VitaNex/Core/Misc/IconDefinition.cs
Normal file
@@ -0,0 +1,485 @@
|
||||
#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.Gumps;
|
||||
|
||||
using Ultima;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public enum IconType
|
||||
{
|
||||
GumpArt,
|
||||
ItemArt
|
||||
}
|
||||
|
||||
[PropertyObject]
|
||||
public class IconDefinition
|
||||
{
|
||||
private static readonly Size _Zero = new Size(0, 0);
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, IconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, int hue, IconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y, hue);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, int offsetX, int offsetY, IconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y, offsetX, offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, int hue, int offsetX, int offsetY, IconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y, hue, offsetX, offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public static IconDefinition Create(IconType type, int assetID)
|
||||
{
|
||||
return new IconDefinition(type, assetID);
|
||||
}
|
||||
|
||||
public static IconDefinition Create(IconType type, int assetID, int hue)
|
||||
{
|
||||
return new IconDefinition(type, assetID, hue);
|
||||
}
|
||||
|
||||
public static IconDefinition Create(IconType type, int assetID, int offsetX, int offsetY)
|
||||
{
|
||||
return new IconDefinition(type, assetID, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition Create(IconType type, int assetID, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return new IconDefinition(type, assetID, hue, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition FromGump(int gumpID)
|
||||
{
|
||||
return Create(IconType.GumpArt, gumpID);
|
||||
}
|
||||
|
||||
public static IconDefinition FromGump(int gumpID, int hue)
|
||||
{
|
||||
return Create(IconType.GumpArt, gumpID, hue);
|
||||
}
|
||||
|
||||
public static IconDefinition FromGump(int gumpID, int offsetX, int offsetY)
|
||||
{
|
||||
return Create(IconType.GumpArt, gumpID, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition FromGump(int gumpID, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return Create(IconType.GumpArt, gumpID, hue, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition FromItem(int itemID)
|
||||
{
|
||||
return Create(IconType.ItemArt, itemID);
|
||||
}
|
||||
|
||||
public static IconDefinition FromItem(int itemID, int hue)
|
||||
{
|
||||
return Create(IconType.ItemArt, itemID, hue);
|
||||
}
|
||||
|
||||
public static IconDefinition FromItem(int itemID, int offsetX, int offsetY)
|
||||
{
|
||||
return Create(IconType.ItemArt, itemID, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition FromItem(int itemID, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return Create(IconType.ItemArt, itemID, hue, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition FromMobile(int body)
|
||||
{
|
||||
return FromItem(ShrinkTable.Lookup(body));
|
||||
}
|
||||
|
||||
public static IconDefinition FromMobile(int body, int hue)
|
||||
{
|
||||
return FromItem(ShrinkTable.Lookup(body), hue);
|
||||
}
|
||||
|
||||
public static IconDefinition FromMobile(int body, int offsetX, int offsetY)
|
||||
{
|
||||
return FromItem(ShrinkTable.Lookup(body), offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition FromMobile(int body, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return FromItem(ShrinkTable.Lookup(body), hue, offsetX, offsetY);
|
||||
}
|
||||
|
||||
#region Spell Icons
|
||||
public static IconDefinition ItemSpellIcon()
|
||||
{
|
||||
return FromItem(SpellIcons.RandomItemIcon());
|
||||
}
|
||||
|
||||
public static IconDefinition ItemSpellIcon(int hue)
|
||||
{
|
||||
return FromItem(SpellIcons.RandomItemIcon(), hue);
|
||||
}
|
||||
|
||||
public static IconDefinition ItemSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
return FromItem(SpellIcons.RandomItemIcon(), offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition ItemSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return FromItem(SpellIcons.RandomItemIcon(), hue, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition GumpSpellIcon()
|
||||
{
|
||||
return FromGump(SpellIcons.RandomGumpIcon());
|
||||
}
|
||||
|
||||
public static IconDefinition GumpSpellIcon(int hue)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomGumpIcon(), hue);
|
||||
}
|
||||
|
||||
public static IconDefinition GumpSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomGumpIcon(), offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition GumpSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomGumpIcon(), hue, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition SmallSpellIcon()
|
||||
{
|
||||
return FromGump(SpellIcons.RandomSmallIcon());
|
||||
}
|
||||
|
||||
public static IconDefinition SmallSpellIcon(int hue)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomSmallIcon(), hue);
|
||||
}
|
||||
|
||||
public static IconDefinition SmallSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomSmallIcon(), offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition SmallSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomSmallIcon(), hue, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition LargeSpellIcon()
|
||||
{
|
||||
return FromGump(SpellIcons.RandomLargeIcon());
|
||||
}
|
||||
|
||||
public static IconDefinition LargeSpellIcon(int hue)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomLargeIcon(), hue);
|
||||
}
|
||||
|
||||
public static IconDefinition LargeSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomLargeIcon(), offsetX, offsetY);
|
||||
}
|
||||
|
||||
public static IconDefinition LargeSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
return FromGump(SpellIcons.RandomLargeIcon(), hue, offsetX, offsetY);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static IconDefinition Empty()
|
||||
{
|
||||
return new IconDefinition();
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public IconType AssetType { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public int AssetID { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsEmpty => AssetID <= (IsItemArt ? 1 : 0);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsGumpArt => AssetType == IconType.GumpArt;
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsItemArt => AssetType == IconType.ItemArt;
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public int Hue { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public int OffsetX { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public int OffsetY { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool ComputeOffset { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public Size Size
|
||||
{
|
||||
get
|
||||
{
|
||||
if (IsGumpArt)
|
||||
{
|
||||
return GumpsExtUtility.GetImageSize(AssetID);
|
||||
}
|
||||
|
||||
if (IsItemArt)
|
||||
{
|
||||
return ArtExtUtility.GetImageSize(AssetID);
|
||||
}
|
||||
|
||||
return _Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsSpellIcon => SpellIcons.IsIcon(AssetID);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsItemSpellIcon => IsItemArt && SpellIcons.IsItemIcon(AssetID);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsGumpSpellIcon => IsGumpArt && SpellIcons.IsGumpIcon(AssetID);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsSmallSpellIcon => IsGumpArt && SpellIcons.IsSmallIcon(AssetID);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool IsLargeSpellIcon => IsGumpArt && SpellIcons.IsLargeIcon(AssetID);
|
||||
|
||||
public IconDefinition()
|
||||
: this(IconType.ItemArt, 0)
|
||||
{ }
|
||||
|
||||
public IconDefinition(IconType assetType, int assetID)
|
||||
: this(assetType, assetID, 0)
|
||||
{ }
|
||||
|
||||
public IconDefinition(IconType assetType, int assetID, int hue)
|
||||
: this(assetType, assetID, hue, 0, 0)
|
||||
{ }
|
||||
|
||||
public IconDefinition(IconType assetType, int assetID, int offsetX, int offsetY)
|
||||
: this(assetType, assetID, 0, offsetX, offsetY)
|
||||
{ }
|
||||
|
||||
public IconDefinition(IconDefinition icon)
|
||||
: this(icon.AssetType, icon.AssetID, icon.Hue, icon.OffsetX, icon.OffsetY)
|
||||
{
|
||||
ComputeOffset = icon.ComputeOffset;
|
||||
}
|
||||
|
||||
public IconDefinition(IconType assetType, int assetID, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
AssetType = assetType;
|
||||
AssetID = assetID;
|
||||
|
||||
Hue = hue;
|
||||
|
||||
OffsetX = offsetX;
|
||||
OffsetY = offsetY;
|
||||
|
||||
ComputeOffset = true;
|
||||
}
|
||||
|
||||
public IconDefinition(GenericReader reader)
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y)
|
||||
{
|
||||
AddToGump(g, x, y, -1, -1, -1);
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y, int hue)
|
||||
{
|
||||
AddToGump(g, x, y, hue, -1, -1);
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y, int offsetX, int offsetY)
|
||||
{
|
||||
AddToGump(g, x, y, -1, offsetX, offsetY);
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
if (IsEmpty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (offsetX < 0)
|
||||
{
|
||||
x += OffsetX;
|
||||
}
|
||||
else if (offsetX > 0)
|
||||
{
|
||||
x += offsetX;
|
||||
}
|
||||
|
||||
if (offsetY < 0)
|
||||
{
|
||||
y += OffsetY;
|
||||
}
|
||||
else if (offsetY > 0)
|
||||
{
|
||||
y += offsetY;
|
||||
}
|
||||
|
||||
if (hue < 0)
|
||||
{
|
||||
hue = Hue;
|
||||
}
|
||||
|
||||
switch (AssetType)
|
||||
{
|
||||
case IconType.ItemArt:
|
||||
{
|
||||
if (ComputeOffset)
|
||||
{
|
||||
var o = ArtExtUtility.GetImageOffset(AssetID);
|
||||
|
||||
if (o != Point.Empty)
|
||||
{
|
||||
x += o.X;
|
||||
y += o.Y;
|
||||
}
|
||||
}
|
||||
|
||||
x = Math.Max(0, x);
|
||||
y = Math.Max(0, y);
|
||||
|
||||
if (hue > 0)
|
||||
{
|
||||
g.AddItem(x, y, AssetID, hue);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.AddItem(x, y, AssetID);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IconType.GumpArt:
|
||||
{
|
||||
x = Math.Max(0, x);
|
||||
y = Math.Max(0, y);
|
||||
|
||||
if (hue > 0)
|
||||
{
|
||||
g.AddImage(x, y, AssetID, hue);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.AddImage(x, y, AssetID);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Serialize(GenericWriter writer)
|
||||
{
|
||||
var version = writer.SetVersion(3);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 3:
|
||||
writer.Write(ComputeOffset);
|
||||
goto case 2;
|
||||
case 2:
|
||||
{
|
||||
writer.Write(OffsetX);
|
||||
writer.Write(OffsetY);
|
||||
}
|
||||
goto case 1;
|
||||
case 1:
|
||||
writer.Write(Hue);
|
||||
goto case 0;
|
||||
case 0:
|
||||
{
|
||||
writer.WriteFlag(AssetType);
|
||||
writer.Write(AssetID);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Deserialize(GenericReader reader)
|
||||
{
|
||||
var version = reader.GetVersion();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 3:
|
||||
ComputeOffset = reader.ReadBool();
|
||||
goto case 2;
|
||||
case 2:
|
||||
{
|
||||
OffsetX = reader.ReadInt();
|
||||
OffsetY = reader.ReadInt();
|
||||
}
|
||||
goto case 1;
|
||||
case 1:
|
||||
Hue = reader.ReadInt();
|
||||
goto case 0;
|
||||
case 0:
|
||||
{
|
||||
AssetType = reader.ReadFlag<IconType>();
|
||||
AssetID = reader.ReadInt();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (version < 3)
|
||||
{
|
||||
ComputeOffset = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Scripts/SubSystem/VitaNex/Core/Misc/KeyValueString.cs
Normal file
117
Scripts/SubSystem/VitaNex/Core/Misc/KeyValueString.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace System
|
||||
{
|
||||
[PropertyObject]
|
||||
public struct KeyValueString : IEquatable<KeyValuePair<string, string>>, IEquatable<KeyValueString>
|
||||
{
|
||||
public static int GetHashCode(string key, string value)
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int k = key != null ? key.GetContentsHashCode() : 0, v = value != null ? value.GetContentsHashCode() : 0;
|
||||
|
||||
return (k * 397) ^ v;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public string Key { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public string Value { get; private set; }
|
||||
|
||||
public KeyValueString(KeyValueString kvs)
|
||||
: this(kvs.Key, kvs.Value)
|
||||
{ }
|
||||
|
||||
public KeyValueString(KeyValuePair<string, string> kvp)
|
||||
: this(kvp.Key, kvp.Value)
|
||||
{ }
|
||||
|
||||
public KeyValueString(string key, string value)
|
||||
: this()
|
||||
{
|
||||
Key = key;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public KeyValueString(GenericReader reader)
|
||||
: this()
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return GetHashCode(Key, Value);
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is KeyValueString && Equals((KeyValueString)obj)) ||
|
||||
(obj is KeyValuePair<string, string> && Equals((KeyValuePair<string, string>)obj));
|
||||
}
|
||||
|
||||
public bool Equals(KeyValueString other)
|
||||
{
|
||||
return Key == other.Key && Value == other.Value;
|
||||
}
|
||||
|
||||
public bool Equals(KeyValuePair<string, string> other)
|
||||
{
|
||||
return Key == other.Key && Value == other.Value;
|
||||
}
|
||||
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.SetVersion(0);
|
||||
|
||||
writer.Write(Key);
|
||||
writer.Write(Value);
|
||||
}
|
||||
|
||||
public void Deserialize(GenericReader reader)
|
||||
{
|
||||
reader.GetVersion();
|
||||
|
||||
Key = reader.ReadString();
|
||||
Value = reader.ReadString();
|
||||
}
|
||||
|
||||
public static bool operator ==(KeyValueString l, KeyValueString r)
|
||||
{
|
||||
return Equals(l, r);
|
||||
}
|
||||
|
||||
public static bool operator !=(KeyValueString l, KeyValueString r)
|
||||
{
|
||||
return !Equals(l, r);
|
||||
}
|
||||
|
||||
public static implicit operator KeyValuePair<string, string>(KeyValueString kv)
|
||||
{
|
||||
return new KeyValuePair<string, string>(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
public static implicit operator KeyValueString(KeyValuePair<string, string> kv)
|
||||
{
|
||||
return new KeyValueString(kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
Scripts/SubSystem/VitaNex/Core/Misc/LCD.cs
Normal file
100
Scripts/SubSystem/VitaNex/Core/Misc/LCD.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[Flags]
|
||||
public enum LCDLines : byte
|
||||
{
|
||||
None = 0x00,
|
||||
Top = 0x01,
|
||||
TopLeft = 0x02,
|
||||
TopRight = 0x04,
|
||||
Middle = 0x08,
|
||||
BottomLeft = 0x10,
|
||||
BottomRight = 0x20,
|
||||
Bottom = 0x40,
|
||||
|
||||
Number0 = Top | TopLeft | TopRight | BottomLeft | BottomRight | Bottom,
|
||||
Number1 = TopLeft | BottomLeft,
|
||||
Number2 = Top | TopRight | Middle | BottomLeft | Bottom,
|
||||
Number3 = Top | TopRight | Middle | BottomRight | Bottom,
|
||||
Number4 = TopLeft | TopRight | Middle | BottomRight,
|
||||
Number5 = Top | TopLeft | Middle | BottomRight | Bottom,
|
||||
Number6 = Top | TopLeft | Middle | BottomLeft | BottomRight | Bottom,
|
||||
Number7 = Top | TopRight | BottomRight,
|
||||
Number8 = Top | TopLeft | TopRight | Middle | BottomLeft | BottomRight | Bottom,
|
||||
Number9 = Top | TopLeft | TopRight | Middle | BottomRight
|
||||
}
|
||||
|
||||
public static class LCD
|
||||
{
|
||||
private static readonly LCDLines[] _NumericMatrix = LCDLines.None.EnumerateValues<LCDLines>(false).Skip(7).ToArray();
|
||||
|
||||
public static LCDLines[] NumericMatrix => _NumericMatrix;
|
||||
|
||||
public static bool TryParse(int val, out LCDLines[] matrix)
|
||||
{
|
||||
var s = val.ToString(CultureInfo.InvariantCulture);
|
||||
matrix = new LCDLines[s.Length];
|
||||
|
||||
var success = false;
|
||||
|
||||
for (var i = 0; i < s.Length; i++)
|
||||
{
|
||||
success = Int32.TryParse(s[i].ToString(CultureInfo.InvariantCulture), out val) && TryParse(val, out matrix[i]);
|
||||
|
||||
if (success)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
matrix = new LCDLines[0];
|
||||
break;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public static bool TryParse(int val, out LCDLines matrix)
|
||||
{
|
||||
if (val < 0 || val > 9)
|
||||
{
|
||||
matrix = LCDLines.None;
|
||||
return false;
|
||||
}
|
||||
|
||||
matrix = _NumericMatrix[val];
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool HasLines(int val, LCDLines lines)
|
||||
{
|
||||
if (val < 0 || val > 9)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TryParse(val, out LCDLines matrix))
|
||||
{
|
||||
return matrix.HasFlag(lines);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
371
Scripts/SubSystem/VitaNex/Core/Misc/LayeredIconDefinition.cs
Normal file
371
Scripts/SubSystem/VitaNex/Core/Misc/LayeredIconDefinition.cs
Normal file
@@ -0,0 +1,371 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Gumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[PropertyObject]
|
||||
public class LayeredIconDefinition : List<IconDefinition>
|
||||
{
|
||||
private static readonly Rectangle _Zero = Rectangle.Empty;
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, LayeredIconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, int hue, LayeredIconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y, hue);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, int offsetX, int offsetY, LayeredIconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y, offsetX, offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddTo(Gump gump, int x, int y, int hue, int offsetX, int offsetY, LayeredIconDefinition icon)
|
||||
{
|
||||
if (gump != null && icon != null)
|
||||
{
|
||||
icon.AddToGump(gump, x, y, hue, offsetX, offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public static LayeredIconDefinition Empty()
|
||||
{
|
||||
return new LayeredIconDefinition();
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public int Layers => Count;
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public Point Offset
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Count == 0)
|
||||
{
|
||||
return _Zero.Location;
|
||||
}
|
||||
|
||||
var x = this.Min(o => o.ComputeOffset ? o.OffsetX : 0);
|
||||
var y = this.Min(o => o.ComputeOffset ? o.OffsetY : 0);
|
||||
|
||||
if (x != 0 || y != 0)
|
||||
{
|
||||
return new Point(x, y);
|
||||
}
|
||||
|
||||
return _Zero.Location;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public Size Size
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Count == 0)
|
||||
{
|
||||
return _Zero.Size;
|
||||
}
|
||||
|
||||
var w = this.Max(o => (o.ComputeOffset ? o.OffsetX : 0) + o.Size.Width);
|
||||
var h = this.Max(o => (o.ComputeOffset ? o.OffsetY : 0) + o.Size.Height);
|
||||
|
||||
if (w > 0 || h > 0)
|
||||
{
|
||||
return new Size(w, h);
|
||||
}
|
||||
|
||||
return _Zero.Size;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public Rectangle Bounds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (Count > 0)
|
||||
{
|
||||
return new Rectangle(Offset, Size);
|
||||
}
|
||||
|
||||
return _Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool HasSpellIcon => this.Any(o => o.IsSpellIcon);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool HasItemSpellIcon => this.Any(o => o.IsItemSpellIcon);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool HasGumpSpellIcon => this.Any(o => o.IsGumpSpellIcon);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool HasSmallSpellIcon => this.Any(o => o.IsSmallSpellIcon);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool HasLargeSpellIcon => this.Any(o => o.IsLargeSpellIcon);
|
||||
|
||||
public LayeredIconDefinition()
|
||||
{ }
|
||||
|
||||
public LayeredIconDefinition(IEnumerable<IconDefinition> collection)
|
||||
: base(collection)
|
||||
{ }
|
||||
|
||||
public LayeredIconDefinition(int capacity)
|
||||
: base(capacity)
|
||||
{ }
|
||||
|
||||
public LayeredIconDefinition(GenericReader reader)
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
#region Gumps
|
||||
public void AddGump(int gumpID)
|
||||
{
|
||||
Add(IconDefinition.FromGump(gumpID));
|
||||
}
|
||||
|
||||
public void AddGump(int gumpID, int hue)
|
||||
{
|
||||
Add(IconDefinition.FromGump(gumpID, hue));
|
||||
}
|
||||
|
||||
public void AddGump(int gumpID, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.FromGump(gumpID, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddGump(int gumpID, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.FromGump(gumpID, hue, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void ClearGumps()
|
||||
{
|
||||
RemoveAll(o => o.AssetType == IconType.GumpArt);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Items
|
||||
public void AddItem(int itemID)
|
||||
{
|
||||
Add(IconDefinition.FromItem(itemID));
|
||||
}
|
||||
|
||||
public void AddItem(int itemID, int hue)
|
||||
{
|
||||
Add(IconDefinition.FromItem(itemID, hue));
|
||||
}
|
||||
|
||||
public void AddItem(int itemID, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.FromItem(itemID, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddItem(int itemID, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.FromItem(itemID, hue, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void ClearItems()
|
||||
{
|
||||
RemoveAll(o => o.AssetType == IconType.ItemArt);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Spell Icons
|
||||
public void AddItemSpellIcon()
|
||||
{
|
||||
Add(IconDefinition.ItemSpellIcon());
|
||||
}
|
||||
|
||||
public void AddItemSpellIcon(int hue)
|
||||
{
|
||||
Add(IconDefinition.ItemSpellIcon(hue));
|
||||
}
|
||||
|
||||
public void AddItemSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.ItemSpellIcon(offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddItemSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.ItemSpellIcon(hue, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddGumpSpellIcon()
|
||||
{
|
||||
Add(IconDefinition.GumpSpellIcon());
|
||||
}
|
||||
|
||||
public void AddGumpSpellIcon(int hue)
|
||||
{
|
||||
Add(IconDefinition.GumpSpellIcon(hue));
|
||||
}
|
||||
|
||||
public void AddGumpSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.GumpSpellIcon(offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddGumpSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.GumpSpellIcon(hue, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddSmallSpellIcon()
|
||||
{
|
||||
Add(IconDefinition.SmallSpellIcon());
|
||||
}
|
||||
|
||||
public void AddSmallSpellIcon(int hue)
|
||||
{
|
||||
Add(IconDefinition.SmallSpellIcon(hue));
|
||||
}
|
||||
|
||||
public void AddSmallSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.SmallSpellIcon(offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddSmallSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.SmallSpellIcon(hue, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddLargeSpellIcon()
|
||||
{
|
||||
Add(IconDefinition.LargeSpellIcon());
|
||||
}
|
||||
|
||||
public void AddLargeSpellIcon(int hue)
|
||||
{
|
||||
Add(IconDefinition.LargeSpellIcon(hue));
|
||||
}
|
||||
|
||||
public void AddLargeSpellIcon(int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.LargeSpellIcon(offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void AddLargeSpellIcon(int hue, int offsetX, int offsetY)
|
||||
{
|
||||
Add(IconDefinition.LargeSpellIcon(hue, offsetX, offsetY));
|
||||
}
|
||||
|
||||
public void ClearSpellIcons()
|
||||
{
|
||||
RemoveAll(o => o.IsSpellIcon);
|
||||
}
|
||||
|
||||
public void ClearItemSpellIcons()
|
||||
{
|
||||
RemoveAll(o => o.IsItemSpellIcon);
|
||||
}
|
||||
|
||||
public void ClearImageSpellIcons()
|
||||
{
|
||||
RemoveAll(o => o.IsGumpSpellIcon);
|
||||
}
|
||||
|
||||
public void ClearSmallSpellIcons()
|
||||
{
|
||||
RemoveAll(o => o.IsSmallSpellIcon);
|
||||
}
|
||||
|
||||
public void ClearLargeSpellIcons()
|
||||
{
|
||||
RemoveAll(o => o.IsLargeSpellIcon);
|
||||
}
|
||||
#endregion
|
||||
|
||||
public int RemoveAll(int assetID)
|
||||
{
|
||||
return RemoveAll(o => o.AssetID == assetID);
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y)
|
||||
{
|
||||
foreach (var icon in this)
|
||||
{
|
||||
icon.AddToGump(g, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y, int hue)
|
||||
{
|
||||
foreach (var icon in this)
|
||||
{
|
||||
icon.AddToGump(g, x, y, hue);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y, int offsetX, int offsetY)
|
||||
{
|
||||
foreach (var icon in this)
|
||||
{
|
||||
icon.AddToGump(g, x, y, offsetX, offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void AddToGump(Gump g, int x, int y, int hue, int offsetX, int offsetY)
|
||||
{
|
||||
foreach (var icon in this)
|
||||
{
|
||||
icon.AddToGump(g, x, y, hue, offsetX, offsetY);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Serialize(GenericWriter writer)
|
||||
{
|
||||
writer.SetVersion(0);
|
||||
|
||||
writer.WriteList(this, (w, o) => o.Serialize(w));
|
||||
}
|
||||
|
||||
public virtual void Deserialize(GenericReader reader)
|
||||
{
|
||||
reader.GetVersion();
|
||||
|
||||
Clear();
|
||||
|
||||
reader.ReadList(r => new IconDefinition(r), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
1568
Scripts/SubSystem/VitaNex/Core/Misc/Numeral.cs
Normal file
1568
Scripts/SubSystem/VitaNex/Core/Misc/Numeral.cs
Normal file
File diff suppressed because it is too large
Load Diff
107
Scripts/SubSystem/VitaNex/Core/Misc/Pair.cs
Normal file
107
Scripts/SubSystem/VitaNex/Core/Misc/Pair.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
#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 Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public static class Pair
|
||||
{
|
||||
public static Pair<T1, T2> Create<T1, T2>(T1 left, T2 right)
|
||||
{
|
||||
return Pair<T1, T2>.Create(left, right);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// It's kinda like a Tuple, but it's a Pair.
|
||||
/// </summary>
|
||||
[PropertyObject]
|
||||
public struct Pair<TLeft, TRight> : IEquatable<KeyValuePair<TLeft, TRight>>, IEquatable<Pair<TLeft, TRight>>
|
||||
{
|
||||
public static Pair<TLeft, TRight> Create(TLeft left, TRight right)
|
||||
{
|
||||
return new Pair<TLeft, TRight>(left, right);
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public TLeft Left { get; private set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, true)]
|
||||
public TRight Right { get; private set; }
|
||||
|
||||
public Pair(Pair<TLeft, TRight> p)
|
||||
: this(p.Left, p.Right)
|
||||
{ }
|
||||
|
||||
public Pair(KeyValuePair<TLeft, TRight> kvp)
|
||||
: this(kvp.Key, kvp.Value)
|
||||
{ }
|
||||
|
||||
public Pair(TLeft left, TRight right)
|
||||
: this()
|
||||
{
|
||||
Left = left;
|
||||
Right = right;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
int l = Left != null ? Left.GetHashCode() : 0, r = Right != null ? Right.GetHashCode() : 0;
|
||||
|
||||
return (l * 397) ^ r;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is KeyValuePair<TLeft, TRight> && Equals((KeyValuePair<TLeft, TRight>)obj)) ||
|
||||
(obj is Pair<TLeft, TRight> && Equals((Pair<TLeft, TRight>)obj));
|
||||
}
|
||||
|
||||
public bool Equals(KeyValuePair<TLeft, TRight> other)
|
||||
{
|
||||
return Equals(Left, other.Key) && Equals(Right, other.Value);
|
||||
}
|
||||
|
||||
public bool Equals(Pair<TLeft, TRight> other)
|
||||
{
|
||||
return Equals(Left, other.Left) && Equals(Right, other.Right);
|
||||
}
|
||||
|
||||
public static bool operator ==(Pair<TLeft, TRight> l, Pair<TLeft, TRight> r)
|
||||
{
|
||||
return Equals(l, r);
|
||||
}
|
||||
|
||||
public static bool operator !=(Pair<TLeft, TRight> l, Pair<TLeft, TRight> r)
|
||||
{
|
||||
return !Equals(l, r);
|
||||
}
|
||||
|
||||
public static implicit operator KeyValuePair<TLeft, TRight>(Pair<TLeft, TRight> p)
|
||||
{
|
||||
return new KeyValuePair<TLeft, TRight>(p.Left, p.Right);
|
||||
}
|
||||
|
||||
public static implicit operator Pair<TLeft, TRight>(KeyValuePair<TLeft, TRight> p)
|
||||
{
|
||||
return new Pair<TLeft, TRight>(p.Key, p.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
220
Scripts/SubSystem/VitaNex/Core/Misc/PaperdollBounds.cs
Normal file
220
Scripts/SubSystem/VitaNex/Core/Misc/PaperdollBounds.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public struct PaperdollBounds : IEquatable<PaperdollBounds>, IEquatable<Layer>, IEnumerable<Rectangle2D>
|
||||
{
|
||||
public static readonly PaperdollBounds Empty = new PaperdollBounds();
|
||||
|
||||
public static readonly PaperdollBounds MainHand = new PaperdollBounds(
|
||||
new Rectangle2D(20, 25, 40, 90),
|
||||
new Rectangle2D(20, 115, 20, 20),
|
||||
new Rectangle2D(20, 135, 30, 40));
|
||||
|
||||
public static readonly PaperdollBounds OffHand = new PaperdollBounds(
|
||||
new Rectangle2D(120, 90, 40, 25),
|
||||
new Rectangle2D(120, 120, 20, 15),
|
||||
new Rectangle2D(120, 135, 40, 30));
|
||||
|
||||
public static readonly PaperdollBounds Arms = new PaperdollBounds(
|
||||
new Rectangle2D(55, 80, 25, 40),
|
||||
new Rectangle2D(100, 80, 25, 40));
|
||||
|
||||
public static readonly PaperdollBounds Backpack = new PaperdollBounds(new Rectangle2D(115, 180, 50, 50));
|
||||
|
||||
public static readonly PaperdollBounds Bracelet = new PaperdollBounds(
|
||||
new Rectangle2D(50, 110, 10, 15),
|
||||
new Rectangle2D(125, 115, 10, 15));
|
||||
|
||||
public static readonly PaperdollBounds Cloak = new PaperdollBounds(new Rectangle2D(45, 135, 100, 100));
|
||||
|
||||
public static readonly PaperdollBounds Earrings = new PaperdollBounds(
|
||||
new Rectangle2D(70, 65, 10, 10),
|
||||
new Rectangle2D(105, 70, 10, 10));
|
||||
|
||||
public static readonly PaperdollBounds Gloves = new PaperdollBounds(
|
||||
new Rectangle2D(35, 105, 20, 20),
|
||||
new Rectangle2D(130, 115, 20, 20));
|
||||
|
||||
public static readonly PaperdollBounds Helm = new PaperdollBounds(new Rectangle2D(80, 55, 20, 20));
|
||||
|
||||
public static readonly PaperdollBounds InnerLegs = new PaperdollBounds(
|
||||
new Rectangle2D(70, 135, 20, 30),
|
||||
new Rectangle2D(65, 165, 20, 30),
|
||||
new Rectangle2D(90, 135, 20, 60));
|
||||
|
||||
public static readonly PaperdollBounds InnerTorso = new PaperdollBounds(new Rectangle2D(70, 85, 45, 75));
|
||||
public static readonly PaperdollBounds MiddleTorso = new PaperdollBounds(new Rectangle2D(70, 85, 45, 75));
|
||||
public static readonly PaperdollBounds Neck = new PaperdollBounds(new Rectangle2D(80, 75, 20, 15));
|
||||
|
||||
public static readonly PaperdollBounds OneHanded = new PaperdollBounds(
|
||||
new Rectangle2D(20, 25, 40, 90),
|
||||
new Rectangle2D(20, 115, 20, 20),
|
||||
new Rectangle2D(20, 135, 30, 40));
|
||||
|
||||
public static readonly PaperdollBounds OuterLegs = new PaperdollBounds(
|
||||
new Rectangle2D(70, 135, 20, 30),
|
||||
new Rectangle2D(65, 165, 20, 30),
|
||||
new Rectangle2D(90, 135, 20, 60));
|
||||
|
||||
public static readonly PaperdollBounds OuterTorso = new PaperdollBounds(new Rectangle2D(60, 80, 60, 140));
|
||||
|
||||
public static readonly PaperdollBounds Pants = new PaperdollBounds(
|
||||
new Rectangle2D(70, 135, 20, 30),
|
||||
new Rectangle2D(65, 165, 20, 30),
|
||||
new Rectangle2D(90, 135, 20, 60));
|
||||
|
||||
public static readonly PaperdollBounds Ring = new PaperdollBounds(new Rectangle2D(40, 110, 5, 5));
|
||||
public static readonly PaperdollBounds Shirt = new PaperdollBounds(new Rectangle2D(70, 85, 45, 45));
|
||||
|
||||
public static readonly PaperdollBounds Shoes = new PaperdollBounds(
|
||||
new Rectangle2D(55, 190, 20, 35),
|
||||
new Rectangle2D(90, 190, 20, 35));
|
||||
|
||||
public static readonly PaperdollBounds Talisman = new PaperdollBounds(new Rectangle2D(130, 70, 35, 35));
|
||||
|
||||
public static readonly PaperdollBounds TwoHanded = new PaperdollBounds(
|
||||
new Rectangle2D(20, 25, 40, 90),
|
||||
new Rectangle2D(20, 115, 20, 20),
|
||||
new Rectangle2D(20, 135, 30, 40),
|
||||
new Rectangle2D(120, 90, 40, 25),
|
||||
new Rectangle2D(120, 120, 20, 15),
|
||||
new Rectangle2D(120, 135, 40, 30));
|
||||
|
||||
public static readonly PaperdollBounds Waist = new PaperdollBounds(new Rectangle2D(70, 110, 45, 25));
|
||||
|
||||
private static readonly Dictionary<Layer, PaperdollBounds> _LayerBounds = new Dictionary<Layer, PaperdollBounds>
|
||||
{
|
||||
{Layer.Arms, Arms},
|
||||
{Layer.Backpack, Backpack},
|
||||
{Layer.Bracelet, Bracelet},
|
||||
{Layer.Cloak, Cloak},
|
||||
{Layer.Earrings, Earrings},
|
||||
{Layer.Gloves, Gloves},
|
||||
{Layer.Helm, Helm},
|
||||
{Layer.InnerLegs, InnerLegs},
|
||||
{Layer.InnerTorso, InnerTorso},
|
||||
{Layer.MiddleTorso, MiddleTorso},
|
||||
{Layer.Neck, Neck},
|
||||
{Layer.OneHanded, OneHanded},
|
||||
{Layer.OuterLegs, OuterLegs},
|
||||
{Layer.OuterTorso, OuterTorso},
|
||||
{Layer.Pants, Pants},
|
||||
{Layer.Ring, Ring},
|
||||
{Layer.Shirt, Shirt},
|
||||
{Layer.Shoes, Shoes},
|
||||
{Layer.Talisman, Talisman},
|
||||
{Layer.TwoHanded, TwoHanded},
|
||||
{Layer.Waist, Waist}
|
||||
};
|
||||
|
||||
public static PaperdollBounds Find(Layer layer)
|
||||
{
|
||||
if (!_LayerBounds.TryGetValue(layer, out var b))
|
||||
{
|
||||
b = Empty;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public Rectangle2D[] Bounds { get; private set; }
|
||||
|
||||
private PaperdollBounds(params Rectangle2D[] bounds)
|
||||
: this()
|
||||
{
|
||||
Bounds = bounds ?? new Rectangle2D[0];
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return Bounds.Aggregate(Bounds.Length, (h, b) => (h * 397) ^ b.GetHashCode());
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is PaperdollBounds && Equals((PaperdollBounds)obj)) || (obj is Layer && Equals((Layer)obj));
|
||||
}
|
||||
|
||||
public bool Equals(Layer layer)
|
||||
{
|
||||
return _LayerBounds.ContainsKey(layer) && Equals(_LayerBounds[layer]);
|
||||
}
|
||||
|
||||
public bool Equals(PaperdollBounds bounds)
|
||||
{
|
||||
return GetHashCode() == bounds.GetHashCode();
|
||||
}
|
||||
|
||||
public IEnumerator<Rectangle2D> GetEnumerator()
|
||||
{
|
||||
return Bounds.GetEnumerator<Rectangle2D>();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return Bounds.GetEnumerator();
|
||||
}
|
||||
|
||||
public static bool operator ==(PaperdollBounds l, PaperdollBounds r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(PaperdollBounds l, PaperdollBounds r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator ==(PaperdollBounds l, Layer r)
|
||||
{
|
||||
return l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(PaperdollBounds l, Layer r)
|
||||
{
|
||||
return !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator ==(Layer l, PaperdollBounds r)
|
||||
{
|
||||
return r.Equals(l);
|
||||
}
|
||||
|
||||
public static bool operator !=(Layer l, PaperdollBounds r)
|
||||
{
|
||||
return !r.Equals(l);
|
||||
}
|
||||
|
||||
public static implicit operator Rectangle2D[](PaperdollBounds b)
|
||||
{
|
||||
return b.Bounds;
|
||||
}
|
||||
|
||||
public static implicit operator PaperdollBounds(Layer l)
|
||||
{
|
||||
return Find(l);
|
||||
}
|
||||
}
|
||||
}
|
||||
286
Scripts/SubSystem/VitaNex/Core/Misc/PollTimer.cs
Normal file
286
Scripts/SubSystem/VitaNex/Core/Misc/PollTimer.cs
Normal file
@@ -0,0 +1,286 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[CoreService("PollTimer", "1.0.0.0", TaskPriority.Highest)]
|
||||
public sealed class PollTimer : Timer, IDisposable
|
||||
{
|
||||
public static PollTimer FromMilliseconds(
|
||||
double interval,
|
||||
Action callback,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromMilliseconds(interval), callback, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromMilliseconds<TObj>(
|
||||
double interval,
|
||||
Action<TObj> callback,
|
||||
TObj o,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromMilliseconds(interval), callback, o, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromSeconds(
|
||||
double interval,
|
||||
Action callback,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromSeconds(interval), callback, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromSeconds<TObj>(
|
||||
double interval,
|
||||
Action<TObj> callback,
|
||||
TObj o,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromSeconds(interval), callback, o, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromMinutes(
|
||||
double interval,
|
||||
Action callback,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromMinutes(interval), callback, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromMinutes<TObj>(
|
||||
double interval,
|
||||
Action<TObj> callback,
|
||||
TObj o,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromMinutes(interval), callback, o, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromHours(
|
||||
double interval,
|
||||
Action callback,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromHours(interval), callback, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromHours<TObj>(
|
||||
double interval,
|
||||
Action<TObj> callback,
|
||||
TObj o,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromHours(interval), callback, o, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromDays(double interval, Action callback, Func<bool> condition = null, bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromDays(interval), callback, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromDays<TObj>(
|
||||
double interval,
|
||||
Action<TObj> callback,
|
||||
TObj o,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromDays(interval), callback, o, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromTicks(long interval, Action callback, Func<bool> condition = null, bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromTicks(interval), callback, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer FromTicks<TObj>(
|
||||
long interval,
|
||||
Action<TObj> callback,
|
||||
TObj o,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return CreateInstance(TimeSpan.FromTicks(interval), callback, o, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer CreateInstance(
|
||||
TimeSpan interval,
|
||||
Action callback,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return new PollTimer(interval, callback, condition, autoStart);
|
||||
}
|
||||
|
||||
public static PollTimer CreateInstance<TObj>(
|
||||
TimeSpan interval,
|
||||
Action<TObj> callback,
|
||||
TObj o,
|
||||
Func<bool> condition = null,
|
||||
bool autoStart = true)
|
||||
{
|
||||
return new PollTimer(interval, () => callback(o), condition, autoStart);
|
||||
}
|
||||
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
public bool IgnoreWorldIO { get; set; }
|
||||
|
||||
public Func<bool> Condition { get; set; }
|
||||
public Action Callback { get; set; }
|
||||
|
||||
public PollTimer(TimeSpan interval, Action callback, Func<bool> condition = null, bool autoStart = true)
|
||||
: base(interval, interval)
|
||||
{
|
||||
Condition = condition;
|
||||
Callback = callback;
|
||||
Running = autoStart;
|
||||
}
|
||||
|
||||
~PollTimer()
|
||||
{
|
||||
Dispose();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
Running = false;
|
||||
Condition = null;
|
||||
Callback = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls the protected PollTimer.OnTick method to force the PollTimer to tick without affecting its current state.
|
||||
/// </summary>
|
||||
public void Tick()
|
||||
{
|
||||
OnTick();
|
||||
}
|
||||
|
||||
protected override void OnTick()
|
||||
{
|
||||
base.OnTick();
|
||||
|
||||
if (Callback != null && (IgnoreWorldIO || (!World.Loading && !World.Saving)))
|
||||
{
|
||||
if (Condition != null)
|
||||
{
|
||||
if (VitaNexCore.TryCatchGet(Condition, VitaNexCore.ToConsole))
|
||||
{
|
||||
VitaNexCore.TryCatch(Callback, VitaNexCore.ToConsole);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
VitaNexCore.TryCatch(Callback, VitaNexCore.ToConsole);
|
||||
}
|
||||
}
|
||||
|
||||
if (Interval <= TimeSpan.Zero)
|
||||
{
|
||||
Running = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var p = ResolvePriority();
|
||||
|
||||
if (Priority != p)
|
||||
{
|
||||
Priority = p;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TimerPriority ResolvePriority()
|
||||
{
|
||||
var ms = Interval.TotalMilliseconds;
|
||||
|
||||
if (ms >= 600000.0)
|
||||
{
|
||||
return TimerPriority.OneMinute;
|
||||
}
|
||||
|
||||
if (ms >= 60000.0)
|
||||
{
|
||||
return TimerPriority.FiveSeconds;
|
||||
}
|
||||
|
||||
if (ms >= 10000.0)
|
||||
{
|
||||
return TimerPriority.OneSecond;
|
||||
}
|
||||
|
||||
if (ms >= 5000.0)
|
||||
{
|
||||
return TimerPriority.TwoFiftyMS;
|
||||
}
|
||||
|
||||
if (ms >= 1000.0)
|
||||
{
|
||||
return TimerPriority.FiftyMS;
|
||||
}
|
||||
|
||||
if (ms >= 500.0)
|
||||
{
|
||||
return TimerPriority.TwentyFiveMS;
|
||||
}
|
||||
|
||||
if (ms >= 100.0)
|
||||
{
|
||||
return TimerPriority.TenMS;
|
||||
}
|
||||
|
||||
return TimerPriority.EveryTick;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("PollTimer[{0}]", FormatDelegate(Callback));
|
||||
}
|
||||
|
||||
private static string FormatDelegate(Delegate callback)
|
||||
{
|
||||
if (callback == null)
|
||||
{
|
||||
return "null";
|
||||
}
|
||||
|
||||
if (callback.Method.DeclaringType == null)
|
||||
{
|
||||
return callback.Method.Name;
|
||||
}
|
||||
|
||||
return String.Format("{0}.{1}", callback.Method.DeclaringType.FullName, callback.Method.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
217
Scripts/SubSystem/VitaNex/Core/Misc/ResistBuffInfo.cs
Normal file
217
Scripts/SubSystem/VitaNex/Core/Misc/ResistBuffInfo.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public class UniqueResistMod : ResistanceMod
|
||||
{
|
||||
public static bool ApplyTo(Mobile m, ResistanceType type, string name, int offset)
|
||||
{
|
||||
if (m == null || m.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
RemoveFrom(m, type, name);
|
||||
|
||||
return new UniqueResistMod(type, name, offset).ApplyTo(m);
|
||||
}
|
||||
|
||||
public static bool RemoveFrom(Mobile m, ResistanceType type, string name)
|
||||
{
|
||||
if (m == null || m.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m.ResistanceMods != null)
|
||||
{
|
||||
return m.ResistanceMods.OfType<UniqueResistMod>().Where(rm => rm.Type == type && rm.Name == name).Count(mod => mod.RemoveFrom(m)) > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public UniqueResistMod(ResistanceType res, string name, int value)
|
||||
: base(res, value)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public virtual bool ApplyTo(Mobile from)
|
||||
{
|
||||
if (from == null || from.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
from.AddResistanceMod(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool RemoveFrom(Mobile from)
|
||||
{
|
||||
if (from == null || from.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
from.RemoveResistanceMod(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class ResistBuffInfo : PropertyObject, IEquatable<ResistBuffInfo>, IEquatable<ResistanceMod>, ICloneable
|
||||
{
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public ResistanceType Type { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public int Offset { get; set; }
|
||||
|
||||
public ResistBuffInfo(ResistanceType type, int offset)
|
||||
{
|
||||
Type = type;
|
||||
Offset = offset;
|
||||
}
|
||||
|
||||
public ResistBuffInfo(GenericReader reader)
|
||||
: base(reader)
|
||||
{ }
|
||||
|
||||
public override void Clear()
|
||||
{ }
|
||||
|
||||
public override void Reset()
|
||||
{ }
|
||||
|
||||
object ICloneable.Clone()
|
||||
{
|
||||
return Clone();
|
||||
}
|
||||
|
||||
public ResistBuffInfo Clone()
|
||||
{
|
||||
return new ResistBuffInfo(Type, Offset);
|
||||
}
|
||||
|
||||
public ResistanceMod ToResistMod()
|
||||
{
|
||||
return new ResistanceMod(Type, Offset);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Type.ToString();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
return ((int)Type * 397) ^ Offset;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as ResistanceMod) || Equals(obj as ResistBuffInfo);
|
||||
}
|
||||
|
||||
public bool Equals(ResistanceMod mod)
|
||||
{
|
||||
return mod != null && Type == mod.Type && Offset == mod.Offset;
|
||||
}
|
||||
|
||||
public bool Equals(ResistBuffInfo info)
|
||||
{
|
||||
return info != null && Type == info.Type && Offset == info.Offset;
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
var version = writer.SetVersion(0);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
writer.WriteFlag(Type);
|
||||
writer.Write(Offset);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.GetVersion();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Type = reader.ReadFlag<ResistanceType>();
|
||||
Offset = reader.ReadInt();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(ResistBuffInfo l, ResistBuffInfo r)
|
||||
{
|
||||
return l?.Equals(r) ?? r?.Equals(l) ?? true;
|
||||
}
|
||||
|
||||
public static bool operator !=(ResistBuffInfo l, ResistBuffInfo r)
|
||||
{
|
||||
return !l?.Equals(r) ?? !r?.Equals(l) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator ==(ResistBuffInfo l, ResistanceMod r)
|
||||
{
|
||||
return l?.Equals(r) ?? r?.Equals(l) ?? true;
|
||||
}
|
||||
|
||||
public static bool operator !=(ResistBuffInfo l, ResistanceMod r)
|
||||
{
|
||||
return !l?.Equals(r) ?? !r?.Equals(l) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator ==(ResistanceMod l, ResistBuffInfo r)
|
||||
{
|
||||
return r == l;
|
||||
}
|
||||
|
||||
public static bool operator !=(ResistanceMod l, ResistBuffInfo r)
|
||||
{
|
||||
return r != l;
|
||||
}
|
||||
|
||||
public static implicit operator ResistanceMod(ResistBuffInfo info)
|
||||
{
|
||||
return new ResistanceMod(info.Type, info.Offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
226
Scripts/SubSystem/VitaNex/Core/Misc/SkillBuffInfo.cs
Normal file
226
Scripts/SubSystem/VitaNex/Core/Misc/SkillBuffInfo.cs
Normal file
@@ -0,0 +1,226 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public class UniqueSkillMod : DefaultSkillMod
|
||||
{
|
||||
public static bool ApplyTo(Mobile m, SkillName skill, string name, bool relative, double value)
|
||||
{
|
||||
if (m == null || m.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
RemoveFrom(m, skill, name);
|
||||
|
||||
return new UniqueSkillMod(skill, name, relative, value).ApplyTo(m);
|
||||
}
|
||||
|
||||
public static bool RemoveFrom(Mobile m, SkillName skill, string name)
|
||||
{
|
||||
if (m == null || m.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m.SkillMods != null)
|
||||
{
|
||||
return m.SkillMods.OfType<UniqueSkillMod>().Where(sm => sm.Skill == skill && sm.Name == name).Count(mod => mod.RemoveFrom(m)) > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public UniqueSkillMod(SkillName skill, string name, bool relative, double value)
|
||||
: base(skill, relative, value)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public virtual bool ApplyTo(Mobile from)
|
||||
{
|
||||
if (from == null || from.Deleted || from.Skills[Skill] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
from.AddSkillMod(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool RemoveFrom(Mobile from)
|
||||
{
|
||||
if (from == null || from.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
from.RemoveSkillMod(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SkillBuffInfo : PropertyObject, IEquatable<SkillBuffInfo>, IEquatable<SkillMod>, ICloneable
|
||||
{
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public SkillName Skill { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public bool Relative { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public double Value { get; set; }
|
||||
|
||||
public SkillBuffInfo(SkillName skill, bool relative, double value)
|
||||
{
|
||||
Skill = skill;
|
||||
Relative = relative;
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public SkillBuffInfo(GenericReader reader)
|
||||
: base(reader)
|
||||
{ }
|
||||
|
||||
public override void Clear()
|
||||
{ }
|
||||
|
||||
public override void Reset()
|
||||
{ }
|
||||
|
||||
object ICloneable.Clone()
|
||||
{
|
||||
return Clone();
|
||||
}
|
||||
|
||||
public SkillBuffInfo Clone()
|
||||
{
|
||||
return new SkillBuffInfo(Skill, Relative, Value);
|
||||
}
|
||||
|
||||
public SkillMod ToSkillMod()
|
||||
{
|
||||
return new DefaultSkillMod(Skill, Relative, Value);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Skill.GetName();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hash = (int)Skill;
|
||||
hash = (hash * 397) ^ Relative.GetHashCode();
|
||||
hash = (hash * 397) ^ Value.GetHashCode();
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as SkillMod) || Equals(obj as SkillBuffInfo);
|
||||
}
|
||||
|
||||
public bool Equals(SkillMod mod)
|
||||
{
|
||||
return mod != null && Value == mod.Value && Relative == mod.Relative && Skill == mod.Skill;
|
||||
}
|
||||
|
||||
public bool Equals(SkillBuffInfo info)
|
||||
{
|
||||
return info != null && Value == info.Value && Relative == info.Relative && Skill == info.Skill;
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
var version = writer.SetVersion(0);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
writer.WriteFlag(Skill);
|
||||
writer.Write(Relative);
|
||||
writer.Write(Value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.GetVersion();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Skill = reader.ReadFlag<SkillName>();
|
||||
Relative = reader.ReadBool();
|
||||
Value = reader.ReadDouble();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(SkillBuffInfo l, SkillBuffInfo r)
|
||||
{
|
||||
return l?.Equals(r) ?? r?.Equals(l) ?? true;
|
||||
}
|
||||
|
||||
public static bool operator !=(SkillBuffInfo l, SkillBuffInfo r)
|
||||
{
|
||||
return !l?.Equals(r) ?? !r?.Equals(l) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator ==(SkillBuffInfo l, SkillMod r)
|
||||
{
|
||||
return l?.Equals(r) ?? r?.Equals(l) ?? true;
|
||||
}
|
||||
|
||||
public static bool operator !=(SkillBuffInfo l, SkillMod r)
|
||||
{
|
||||
return !l?.Equals(r) ?? !r?.Equals(l) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator ==(SkillMod l, SkillBuffInfo r)
|
||||
{
|
||||
return r == l;
|
||||
}
|
||||
|
||||
public static bool operator !=(SkillMod l, SkillBuffInfo r)
|
||||
{
|
||||
return r != l;
|
||||
}
|
||||
|
||||
public static implicit operator DefaultSkillMod(SkillBuffInfo info)
|
||||
{
|
||||
return new DefaultSkillMod(info.Skill, info.Relative, info.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
373
Scripts/SubSystem/VitaNex/Core/Misc/SpellIcons.cs
Normal file
373
Scripts/SubSystem/VitaNex/Core/Misc/SpellIcons.cs
Normal file
@@ -0,0 +1,373 @@
|
||||
#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.Gumps;
|
||||
|
||||
using VitaNex.SuperGumps;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public class SpellIconUI : SuperGump
|
||||
{
|
||||
private int _Display, _Displaying;
|
||||
|
||||
public bool DisplaySmall
|
||||
{
|
||||
get => _Display == 0 || (_Display & 0x1) != 0;
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
_Display |= 0x1;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Display &= ~0x1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisplayLarge
|
||||
{
|
||||
get => _Display == 0 || (_Display & 0x2) != 0;
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
_Display |= 0x2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Display &= ~0x2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int Icon { get; set; }
|
||||
|
||||
public Action<int> SelectHandler { get; set; }
|
||||
|
||||
public bool CloseOnSelect { get; set; }
|
||||
|
||||
public int BackgroundID { get; set; }
|
||||
|
||||
public SpellIconUI(Mobile user, Gump parent = null, int? icon = null, Action<int> onSelect = null)
|
||||
: base(user, parent)
|
||||
{
|
||||
Icon = icon ?? -1;
|
||||
SelectHandler = onSelect;
|
||||
|
||||
DisplaySmall = true;
|
||||
DisplayLarge = true;
|
||||
|
||||
CanClose = true;
|
||||
CanDispose = true;
|
||||
CanMove = true;
|
||||
CanResize = false;
|
||||
|
||||
BackgroundID = SupportsUltimaStore ? 40000 : 9270;
|
||||
}
|
||||
|
||||
protected override void Compile()
|
||||
{
|
||||
if (_Displaying == 0x0)
|
||||
{
|
||||
if (SpellIcons.IsSmallIcon(Icon) && DisplaySmall)
|
||||
{
|
||||
_Displaying = 0x1;
|
||||
}
|
||||
else if (SpellIcons.IsLargeIcon(Icon) && DisplayLarge)
|
||||
{
|
||||
_Displaying = 0x2;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Displaying = DisplaySmall ? 0x1 : DisplayLarge ? 0x2 : 0x0;
|
||||
}
|
||||
}
|
||||
|
||||
if (_Displaying == 0x1 && !DisplaySmall)
|
||||
{
|
||||
_Displaying = DisplayLarge ? 0x2 : 0x0;
|
||||
}
|
||||
|
||||
if (_Displaying == 0x2 && !DisplayLarge)
|
||||
{
|
||||
_Displaying = DisplaySmall ? 0x1 : 0x0;
|
||||
}
|
||||
|
||||
base.Compile();
|
||||
}
|
||||
|
||||
protected override bool OnBeforeSend()
|
||||
{
|
||||
return (_Displaying == 0x1 || _Displaying == 0x2) && base.OnBeforeSend();
|
||||
}
|
||||
|
||||
protected override void CompileLayout(SuperGumpLayout layout)
|
||||
{
|
||||
base.CompileLayout(layout);
|
||||
|
||||
int[] icons;
|
||||
int iw, ih;
|
||||
|
||||
switch (_Displaying)
|
||||
{
|
||||
case 0x1:
|
||||
{
|
||||
icons = SpellIcons.SmallIcons;
|
||||
iw = SpellIcons.SmallSize.Width;
|
||||
ih = SpellIcons.SmallSize.Height;
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x2:
|
||||
{
|
||||
icons = SpellIcons.LargeIcons;
|
||||
iw = SpellIcons.LargeSize.Width;
|
||||
ih = SpellIcons.LargeSize.Height;
|
||||
}
|
||||
break;
|
||||
|
||||
default: return;
|
||||
}
|
||||
|
||||
var sqrt = (int)Math.Ceiling(Math.Sqrt(icons.Length));
|
||||
|
||||
var w = 20 + (sqrt * iw);
|
||||
var h = 50 + (sqrt * ih);
|
||||
|
||||
layout.Add("bg", () => AddBackground(0, 0, w, h, BackgroundID));
|
||||
|
||||
layout.Add("header", () =>
|
||||
{
|
||||
var title = "Icon Selection";
|
||||
title = title.WrapUOHtmlBig();
|
||||
title = title.WrapUOHtmlColor(Color.Gold, false);
|
||||
|
||||
AddHtml(15, 12, w - 130, 40, title, false, false);
|
||||
|
||||
if (!DisplayLarge || !DisplaySmall)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var x = 15 + (w - 30);
|
||||
|
||||
if (DisplayLarge)
|
||||
{
|
||||
x -= 50;
|
||||
|
||||
var c = _Displaying == 0x2 ? Color.Gold : Color.White;
|
||||
|
||||
AddHtmlButton(x, 10, 50, 30, b =>
|
||||
{
|
||||
_Displaying = 0x2;
|
||||
Refresh(true);
|
||||
}, "Large".WrapUOHtmlCenter(), c, Color.Empty, c, 1);
|
||||
}
|
||||
|
||||
if (DisplaySmall)
|
||||
{
|
||||
x -= 50;
|
||||
|
||||
var c = _Displaying == 0x1 ? Color.Gold : Color.White;
|
||||
|
||||
AddHtmlButton(x, 10, 50, 30, b =>
|
||||
{
|
||||
_Displaying = 0x1;
|
||||
Refresh(true);
|
||||
}, "Small".WrapUOHtmlCenter(), c, Color.Empty, c, 1);
|
||||
}
|
||||
});
|
||||
|
||||
layout.Add("icons", () =>
|
||||
{
|
||||
int xx, yy, x, y, i = 0;
|
||||
|
||||
for (yy = 0; yy < sqrt; yy++)
|
||||
{
|
||||
y = 40 + (yy * ih);
|
||||
|
||||
for (xx = 0; xx < sqrt; xx++)
|
||||
{
|
||||
x = 10 + (xx * iw);
|
||||
|
||||
var index = i++;
|
||||
|
||||
if (!icons.InBounds(index))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var icon = icons[index];
|
||||
|
||||
AddButton(x, y, icon, icon, b => SelectIcon(icon));
|
||||
|
||||
if (icon == Icon)
|
||||
{
|
||||
AddRectangle(x, y, iw, ih, Color.LawnGreen, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected virtual void SelectIcon(int icon)
|
||||
{
|
||||
Icon = icon;
|
||||
|
||||
if (SelectHandler != null)
|
||||
{
|
||||
SelectHandler(icon);
|
||||
}
|
||||
|
||||
if (!CloseOnSelect)
|
||||
{
|
||||
Refresh(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class SpellIcons
|
||||
{
|
||||
public static readonly Size SmallSize = new Size(44, 44);
|
||||
public static readonly Size LargeSize = new Size(70, 70);
|
||||
|
||||
private static readonly int[][] _Icons = new int[3][];
|
||||
|
||||
public static int[] SmallIcons => _Icons[0];
|
||||
public static int[] LargeIcons => _Icons[1];
|
||||
public static int[] ItemIcons => _Icons[2];
|
||||
|
||||
static SpellIcons()
|
||||
{
|
||||
var small = new HashSet<int>();
|
||||
var large = new HashSet<int>();
|
||||
var items = new HashSet<int>();
|
||||
|
||||
Register(small, 2237);
|
||||
Register(small, 2240, 2305);
|
||||
Register(small, 2373, 2378);
|
||||
Register(large, 7000, 7064);
|
||||
Register(small, 20480, 20496);
|
||||
Register(small, 20736, 20745);
|
||||
Register(small, 20992, 21022);
|
||||
Register(large, 21248, 21255);
|
||||
Register(small, 21256, 21257);
|
||||
Register(small, 21280, 21287);
|
||||
Register(large, 21504, 21510);
|
||||
Register(small, 21536, 21542);
|
||||
Register(large, 21632, 21642);
|
||||
Register(small, 23000, 23015);
|
||||
Register(small, 24000, 24030);
|
||||
Register(small, 30103);
|
||||
Register(small, 30106);
|
||||
Register(small, 30109);
|
||||
Register(small, 30114);
|
||||
Register(small, 39819, 39860);
|
||||
Register(items, 8320, 8383, true);
|
||||
|
||||
_Icons[0] = small.FreeToArray(true);
|
||||
_Icons[1] = large.FreeToArray(true);
|
||||
_Icons[2] = items.FreeToArray(true);
|
||||
}
|
||||
|
||||
private static void Register(HashSet<int> list, int from, int to, bool items = false)
|
||||
{
|
||||
var c = to - from;
|
||||
|
||||
if (c <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (var id = from; id <= to; id++)
|
||||
{
|
||||
Register(list, id, items);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Register(HashSet<int> list, int id, bool item = false)
|
||||
{
|
||||
var size = item ? Ultima.ArtExtUtility.GetImageSize(id) : Ultima.GumpsExtUtility.GetImageSize(id);
|
||||
|
||||
if (size == SmallSize || size == LargeSize)
|
||||
{
|
||||
list.Add(id);
|
||||
}
|
||||
#if DEBUG
|
||||
else
|
||||
{
|
||||
Utility.PushColor(ConsoleColor.Yellow);
|
||||
Console.WriteLine($"Warning: Invalid spell icon 0x{id:X4} ({id}) W{size.Width} H{size.Height}");
|
||||
Utility.PopColor();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool IsIcon(int id)
|
||||
{
|
||||
return IsItemIcon(id) || IsGumpIcon(id);
|
||||
}
|
||||
|
||||
public static bool IsItemIcon(int id)
|
||||
{
|
||||
return ItemIcons.Contains(id);
|
||||
}
|
||||
|
||||
public static bool IsGumpIcon(int id)
|
||||
{
|
||||
return IsSmallIcon(id) || IsLargeIcon(id);
|
||||
}
|
||||
|
||||
public static bool IsSmallIcon(int id)
|
||||
{
|
||||
return SmallIcons.Contains(id);
|
||||
}
|
||||
|
||||
public static bool IsLargeIcon(int id)
|
||||
{
|
||||
return LargeIcons.Contains(id);
|
||||
}
|
||||
|
||||
public static int RandomItemIcon()
|
||||
{
|
||||
return ItemIcons.GetRandom();
|
||||
}
|
||||
|
||||
public static int RandomGumpIcon()
|
||||
{
|
||||
return Utility.RandomBool() ? RandomSmallIcon() : RandomLargeIcon();
|
||||
}
|
||||
|
||||
public static int RandomSmallIcon()
|
||||
{
|
||||
return SmallIcons.GetRandom();
|
||||
}
|
||||
|
||||
public static int RandomLargeIcon()
|
||||
{
|
||||
return LargeIcons.GetRandom();
|
||||
}
|
||||
}
|
||||
}
|
||||
505
Scripts/SubSystem/VitaNex/Core/Misc/SpellUtility.cs
Normal file
505
Scripts/SubSystem/VitaNex/Core/Misc/SpellUtility.cs
Normal file
@@ -0,0 +1,505 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Items;
|
||||
using Server.Network;
|
||||
using Server.Spells;
|
||||
using Server.Spells.Fifth;
|
||||
using Server.Spells.First;
|
||||
using Server.Spells.Fourth;
|
||||
using Server.Spells.Necromancy;
|
||||
using Server.Spells.Ninjitsu;
|
||||
using Server.Spells.Seventh;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public static class SpellUtility
|
||||
{
|
||||
public static string[] CircleNames =
|
||||
{
|
||||
"First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Necromancy", "Chivalry", "Bushido",
|
||||
"Ninjitsu", "Spellweaving", "Mystic", "SkillMasteries", "Racial"
|
||||
};
|
||||
|
||||
public static Dictionary<Type, SpellInfo> SpellsInfo { get; private set; }
|
||||
public static Dictionary<Type, int> ItemSpellIcons { get; private set; }
|
||||
public static Dictionary<string, Dictionary<Type, SpellInfo>> TreeStructure { get; private set; }
|
||||
|
||||
static SpellUtility()
|
||||
{
|
||||
SpellsInfo = new Dictionary<Type, SpellInfo>();
|
||||
ItemSpellIcons = new Dictionary<Type, int>();
|
||||
TreeStructure = new Dictionary<string, Dictionary<Type, SpellInfo>>();
|
||||
}
|
||||
|
||||
[CallPriority(Int16.MaxValue)]
|
||||
public static void Initialize()
|
||||
{
|
||||
for (int i = 0, j = 8320; i < SpellRegistry.Types.Length; i++, j++)
|
||||
{
|
||||
var s = SpellRegistry.NewSpell(i, null, null);
|
||||
|
||||
if (s == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var o = s.Info;
|
||||
|
||||
if (o == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var t = SpellRegistry.Types[i] ?? s.GetType();
|
||||
|
||||
SpellsInfo[t] = new SpellInfo(o.Name, o.Mantra, o.Action, o.LeftHandEffect, o.RightHandEffect, o.AllowTown, o.Reagents);
|
||||
|
||||
if (SpellIcons.IsItemIcon(j))
|
||||
{
|
||||
ItemSpellIcons[t] = j;
|
||||
}
|
||||
}
|
||||
|
||||
InvalidateTreeStructure();
|
||||
}
|
||||
|
||||
public static void InvalidateTreeStructure()
|
||||
{
|
||||
TreeStructure.Clear();
|
||||
|
||||
foreach (var c in CircleNames)
|
||||
{
|
||||
var d = new Dictionary<Type, SpellInfo>();
|
||||
|
||||
foreach (var o in SpellsInfo.Where(o => Insensitive.StartsWith(o.Key.FullName, "Server.Spells." + c)))
|
||||
{
|
||||
d[o.Key] = o.Value;
|
||||
}
|
||||
|
||||
TreeStructure[c] = d;
|
||||
}
|
||||
}
|
||||
|
||||
public static SpellInfo GetSpellInfo<TSpell>() where TSpell : ISpell
|
||||
{
|
||||
return GetSpellInfo(typeof(TSpell));
|
||||
}
|
||||
|
||||
public static SpellInfo GetSpellInfo(int spellID)
|
||||
{
|
||||
return SpellRegistry.Types.InBounds(spellID) ? GetSpellInfo(SpellRegistry.Types[spellID]) : null;
|
||||
}
|
||||
|
||||
public static SpellInfo GetSpellInfo(ISpell s)
|
||||
{
|
||||
return s != null ? GetSpellInfo(s.GetType()) : null;
|
||||
}
|
||||
|
||||
public static SpellInfo GetSpellInfo(Type type)
|
||||
{
|
||||
return SpellsInfo.GetValue(type);
|
||||
}
|
||||
|
||||
public static string GetSpellName<TSpell>() where TSpell : ISpell
|
||||
{
|
||||
return GetSpellName(typeof(TSpell));
|
||||
}
|
||||
|
||||
public static string GetSpellName(int spellID)
|
||||
{
|
||||
return SpellRegistry.Types.InBounds(spellID) ? GetSpellName(SpellRegistry.Types[spellID]) : String.Empty;
|
||||
}
|
||||
|
||||
public static string GetSpellName(ISpell s)
|
||||
{
|
||||
return s != null ? GetSpellName(s.GetType()) : String.Empty;
|
||||
}
|
||||
|
||||
public static string GetSpellName(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
var o = GetSpellInfo(type);
|
||||
|
||||
return o != null ? o.Name : String.Empty;
|
||||
}
|
||||
|
||||
public static int GetItemIcon<TSpell>() where TSpell : ISpell
|
||||
{
|
||||
return GetItemIcon(typeof(TSpell));
|
||||
}
|
||||
|
||||
public static int GetItemIcon(int spellID)
|
||||
{
|
||||
return SpellRegistry.Types.InBounds(spellID) ? GetItemIcon(SpellRegistry.Types[spellID]) : 0;
|
||||
}
|
||||
|
||||
public static int GetItemIcon(ISpell s)
|
||||
{
|
||||
return s != null ? GetItemIcon(s.GetType()) : 0;
|
||||
}
|
||||
|
||||
public static int GetItemIcon(Type type)
|
||||
{
|
||||
return ItemSpellIcons.GetValue(type);
|
||||
}
|
||||
|
||||
public static string GetCircleName<TSpell>() where TSpell : ISpell
|
||||
{
|
||||
return GetCircleName(typeof(TSpell));
|
||||
}
|
||||
|
||||
public static string GetCircleName(int spellID)
|
||||
{
|
||||
return SpellRegistry.Types.InBounds(spellID) ? GetCircleName(SpellRegistry.Types[spellID]) : String.Empty;
|
||||
}
|
||||
|
||||
public static string GetCircleName(ISpell s)
|
||||
{
|
||||
return s != null ? GetCircleName(s.GetType()) : String.Empty;
|
||||
}
|
||||
|
||||
public static string GetCircleName(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
if (TreeStructure == null || TreeStructure.Count == 0)
|
||||
{
|
||||
InvalidateTreeStructure();
|
||||
}
|
||||
|
||||
if (TreeStructure == null || TreeStructure.Count == 0)
|
||||
{
|
||||
return String.Empty;
|
||||
}
|
||||
|
||||
return TreeStructure.FirstOrDefault(o => o.Value.ContainsKey(type)).Key ?? String.Empty;
|
||||
}
|
||||
|
||||
public static int GetCircle<TSpell>() where TSpell : ISpell
|
||||
{
|
||||
return GetCircle(typeof(TSpell));
|
||||
}
|
||||
|
||||
public static int GetCircle(int spellID)
|
||||
{
|
||||
return SpellRegistry.Types.InBounds(spellID) ? GetCircle(SpellRegistry.Types[spellID]) : 0;
|
||||
}
|
||||
|
||||
public static int GetCircle(ISpell s)
|
||||
{
|
||||
return s != null ? GetCircle(s.GetType()) : 0;
|
||||
}
|
||||
|
||||
public static int GetCircle(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var circle = GetCircleName(type);
|
||||
|
||||
return !String.IsNullOrWhiteSpace(circle) ? CircleNames.IndexOf(circle) + 1 : 0;
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> FindCircleSpells(int circleID)
|
||||
{
|
||||
if (!CircleNames.InBounds(--circleID))
|
||||
{
|
||||
return Enumerable.Empty<Type>();
|
||||
}
|
||||
|
||||
return FindCircleSpells(CircleNames[circleID]);
|
||||
}
|
||||
|
||||
public static IEnumerable<Type> FindCircleSpells(string circle)
|
||||
{
|
||||
if (SpellsInfo == null || SpellsInfo.Count == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (TreeStructure == null || TreeStructure.Count == 0)
|
||||
{
|
||||
InvalidateTreeStructure();
|
||||
}
|
||||
|
||||
if (TreeStructure == null || TreeStructure.Count == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
circle = TreeStructure.Keys.FirstOrDefault(c => Insensitive.EndsWith(circle, c));
|
||||
|
||||
if (circle == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
var spells = TreeStructure[circle];
|
||||
|
||||
if (spells == null || spells.Count == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var t in spells.Keys)
|
||||
{
|
||||
yield return t;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool AddStatOffset(Mobile m, StatType type, int offset, TimeSpan duration)
|
||||
{
|
||||
if (offset > 0)
|
||||
{
|
||||
return AddStatBonus(m, m, type, offset, duration);
|
||||
}
|
||||
|
||||
if (offset < 0)
|
||||
{
|
||||
return AddStatCurse(m, m, type, -offset, duration);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool RemoveStatBonus(Mobile m, StatType type)
|
||||
{
|
||||
if (type == StatType.All)
|
||||
{
|
||||
return RemoveStatBonus(m, StatType.Str) | RemoveStatBonus(m, StatType.Dex) | RemoveStatBonus(m, StatType.Int);
|
||||
}
|
||||
|
||||
#if ServUO
|
||||
var name = String.Format("[Magic] {0} Buff", type);
|
||||
#else
|
||||
var name = String.Format("[Magic] {0} Offset", type);
|
||||
#endif
|
||||
|
||||
var mod = m.GetStatMod(name);
|
||||
|
||||
if (mod != null && mod.Offset >= 0)
|
||||
{
|
||||
m.RemoveStatMod(mod.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool AddStatBonus(Mobile caster, Mobile target, StatType type, int bonus, TimeSpan duration)
|
||||
{
|
||||
if (type == StatType.All)
|
||||
{
|
||||
return AddStatBonus(caster, target, StatType.Str, bonus, duration) | AddStatBonus(caster, target, StatType.Dex, bonus, duration) | AddStatBonus(caster, target, StatType.Int, bonus, duration);
|
||||
}
|
||||
|
||||
var offset = bonus;
|
||||
|
||||
#if ServUO
|
||||
var name = String.Format("[Magic] {0} Buff", type);
|
||||
#else
|
||||
var name = String.Format("[Magic] {0} Offset", type);
|
||||
#endif
|
||||
|
||||
var mod = target.GetStatMod(name);
|
||||
|
||||
if (mod != null && mod.Offset < 0)
|
||||
{
|
||||
target.AddStatMod(new StatMod(type, name, mod.Offset + offset, duration));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mod == null || mod.Offset < offset)
|
||||
{
|
||||
target.AddStatMod(new StatMod(type, name, offset, duration));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool RemoveStatCurse(Mobile m, StatType type)
|
||||
{
|
||||
if (type == StatType.All)
|
||||
{
|
||||
var success = RemoveStatCurse(m, StatType.Str);
|
||||
success = RemoveStatCurse(m, StatType.Dex) || success;
|
||||
success = RemoveStatCurse(m, StatType.Int) || success;
|
||||
return success;
|
||||
}
|
||||
|
||||
#if ServUO
|
||||
var name = String.Format("[Magic] {0} Curse", type);
|
||||
#else
|
||||
var name = String.Format("[Magic] {0} Offset", type);
|
||||
#endif
|
||||
|
||||
var mod = m.GetStatMod(name);
|
||||
|
||||
if (mod != null && mod.Offset <= 0)
|
||||
{
|
||||
m.RemoveStatMod(mod.Name);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool AddStatCurse(Mobile caster, Mobile target, StatType type, int curse, TimeSpan duration)
|
||||
{
|
||||
if (type == StatType.All)
|
||||
{
|
||||
var success = AddStatCurse(caster, target, StatType.Str, curse, duration);
|
||||
success = AddStatCurse(caster, target, StatType.Dex, curse, duration) || success;
|
||||
success = AddStatCurse(caster, target, StatType.Int, curse, duration) || success;
|
||||
return success;
|
||||
}
|
||||
|
||||
var offset = -curse;
|
||||
|
||||
#if ServUO
|
||||
var name = String.Format("[Magic] {0} Curse", type);
|
||||
#else
|
||||
var name = String.Format("[Magic] {0} Offset", type);
|
||||
#endif
|
||||
|
||||
var mod = target.GetStatMod(name);
|
||||
|
||||
if (mod != null && mod.Offset > 0)
|
||||
{
|
||||
target.AddStatMod(new StatMod(type, name, mod.Offset + offset, duration));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mod == null || mod.Offset > offset)
|
||||
{
|
||||
target.AddStatMod(new StatMod(type, name, offset, duration));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void NegateAllEffects(Mobile target)
|
||||
{
|
||||
NegateEffects(target, true, true, true, true);
|
||||
}
|
||||
|
||||
public static void NegateEffects(Mobile target, bool curses, bool buffs, bool damage, bool morph)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (damage)
|
||||
{
|
||||
if (target.Poisoned)
|
||||
{
|
||||
var p = target.Poison;
|
||||
|
||||
target.Poison = null;
|
||||
|
||||
target.OnCured(target, p);
|
||||
}
|
||||
|
||||
target.Frozen = false;
|
||||
target.Paralyzed = false;
|
||||
|
||||
target.SetPropertyValue("Asleep", false);
|
||||
|
||||
BuffInfo.RemoveBuff(target, BuffIcon.Paralyze);
|
||||
BuffInfo.RemoveBuff(target, BuffIcon.Sleep);
|
||||
}
|
||||
|
||||
if (buffs)
|
||||
{
|
||||
ReactiveArmorSpell.EndArmor(target);
|
||||
MagicReflectSpell.EndReflect(target);
|
||||
}
|
||||
|
||||
if (curses)
|
||||
{
|
||||
#region Pain Spike
|
||||
if (typeof(PainSpikeSpell).GetFieldValue("m_Table", out IDictionary table) && table.Contains(target))
|
||||
{
|
||||
if (table[target] is Timer t)
|
||||
{
|
||||
t.Stop();
|
||||
}
|
||||
|
||||
table.Remove(target);
|
||||
|
||||
BuffInfo.RemoveBuff(target, BuffIcon.PainSpike);
|
||||
}
|
||||
#endregion
|
||||
|
||||
CurseSpell.RemoveEffect(target);
|
||||
EvilOmenSpell.TryEndEffect(target);
|
||||
StrangleSpell.RemoveCurse(target);
|
||||
CorpseSkinSpell.RemoveCurse(target);
|
||||
BloodOathSpell.RemoveCurse(target);
|
||||
MindRotSpell.ClearMindRotScalar(target);
|
||||
}
|
||||
|
||||
if (damage)
|
||||
{
|
||||
MortalStrike.EndWound(target);
|
||||
BleedAttack.EndBleed(target, target.Alive);
|
||||
}
|
||||
|
||||
if (morph)
|
||||
{
|
||||
AnimalForm.RemoveContext(target, true);
|
||||
|
||||
PolymorphSpell.StopTimer(target);
|
||||
IncognitoSpell.StopTimer(target);
|
||||
|
||||
target.Send(SpeedControl.Disable);
|
||||
|
||||
target.EndAction(typeof(PolymorphSpell));
|
||||
target.EndAction(typeof(IncognitoSpell));
|
||||
|
||||
BuffInfo.RemoveBuff(target, BuffIcon.AnimalForm);
|
||||
BuffInfo.RemoveBuff(target, BuffIcon.Polymorph);
|
||||
BuffInfo.RemoveBuff(target, BuffIcon.Incognito);
|
||||
}
|
||||
|
||||
if (buffs)
|
||||
{
|
||||
RemoveStatBonus(target, StatType.All);
|
||||
}
|
||||
|
||||
if (curses)
|
||||
{
|
||||
RemoveStatCurse(target, StatType.All);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
227
Scripts/SubSystem/VitaNex/Core/Misc/StatBuffInfo.cs
Normal file
227
Scripts/SubSystem/VitaNex/Core/Misc/StatBuffInfo.cs
Normal file
@@ -0,0 +1,227 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public class UniqueStatMod : StatMod
|
||||
{
|
||||
public static bool ApplyTo(Mobile m, StatType type, string name, int offset, TimeSpan duration)
|
||||
{
|
||||
if (m == null || m.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
RemoveFrom(m, type, name);
|
||||
|
||||
return new UniqueStatMod(type, name, offset, duration).ApplyTo(m);
|
||||
}
|
||||
|
||||
public static bool RemoveFrom(Mobile m, StatType type, string name)
|
||||
{
|
||||
if (m == null || m.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (m.StatMods != null)
|
||||
{
|
||||
return m.StatMods.OfType<UniqueStatMod>().Where(sm => sm.Type.HasFlag(type) && sm.Name == name).Count(mod => mod.RemoveFrom(m)) > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public UniqueStatMod(StatType stat, string name, int value, TimeSpan duration)
|
||||
: base(stat, name, value, duration)
|
||||
{ }
|
||||
|
||||
public virtual bool ApplyTo(Mobile from)
|
||||
{
|
||||
if (from == null || from.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
from.AddStatMod(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual bool RemoveFrom(Mobile from)
|
||||
{
|
||||
if (from == null || from.Deleted)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
from.RemoveStatMod(Name);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class StatBuffInfo : PropertyObject, IEquatable<StatBuffInfo>, IEquatable<StatMod>, ICloneable
|
||||
{
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public StatType Type { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public string Name { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public int Offset { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public TimeSpan Duration { get; set; }
|
||||
|
||||
public StatBuffInfo(StatType type, string name, int offset, TimeSpan duration)
|
||||
{
|
||||
Type = type;
|
||||
Name = name;
|
||||
Offset = offset;
|
||||
Duration = duration;
|
||||
}
|
||||
|
||||
public StatBuffInfo(GenericReader reader)
|
||||
: base(reader)
|
||||
{ }
|
||||
|
||||
public override void Clear()
|
||||
{ }
|
||||
|
||||
public override void Reset()
|
||||
{ }
|
||||
|
||||
object ICloneable.Clone()
|
||||
{
|
||||
return Clone();
|
||||
}
|
||||
|
||||
public StatBuffInfo Clone()
|
||||
{
|
||||
return new StatBuffInfo(Type, Name, Offset, Duration);
|
||||
}
|
||||
|
||||
public StatMod ToStatMod()
|
||||
{
|
||||
return new StatMod(Type, Name, Offset, Duration);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.IsNullOrWhiteSpace(Name) ? Name : Type.ToString();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
var hashCode = (int)Type;
|
||||
hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
|
||||
return hashCode;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return Equals(obj as StatMod) || Equals(obj as StatBuffInfo);
|
||||
}
|
||||
|
||||
public bool Equals(StatMod mod)
|
||||
{
|
||||
return mod != null && Type == mod.Type && Name == mod.Name;
|
||||
}
|
||||
|
||||
public bool Equals(StatBuffInfo info)
|
||||
{
|
||||
return info != null && Type == info.Type && Name == info.Name;
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
var version = writer.SetVersion(0);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
writer.WriteFlag(Type);
|
||||
writer.Write(Name);
|
||||
writer.Write(Offset);
|
||||
writer.Write(Duration);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.GetVersion();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Type = reader.ReadFlag<StatType>();
|
||||
Name = reader.ReadString();
|
||||
Offset = reader.ReadInt();
|
||||
Duration = reader.ReadTimeSpan();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool operator ==(StatBuffInfo l, StatBuffInfo r)
|
||||
{
|
||||
return l?.Equals(r) ?? r?.Equals(l) ?? true;
|
||||
}
|
||||
|
||||
public static bool operator !=(StatBuffInfo l, StatBuffInfo r)
|
||||
{
|
||||
return !l?.Equals(r) ?? !r?.Equals(l) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator ==(StatBuffInfo l, StatMod r)
|
||||
{
|
||||
return l?.Equals(r) ?? r?.Equals(l) ?? true;
|
||||
}
|
||||
|
||||
public static bool operator !=(StatBuffInfo l, StatMod r)
|
||||
{
|
||||
return !l?.Equals(r) ?? !r?.Equals(l) ?? false;
|
||||
}
|
||||
|
||||
public static bool operator ==(StatMod l, StatBuffInfo r)
|
||||
{
|
||||
return r == l;
|
||||
}
|
||||
|
||||
public static bool operator !=(StatMod l, StatBuffInfo r)
|
||||
{
|
||||
return r != l;
|
||||
}
|
||||
|
||||
public static implicit operator StatMod(StatBuffInfo info)
|
||||
{
|
||||
return new StatMod(info.Type, info.Name, info.Offset, info.Duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Scripts/SubSystem/VitaNex/Core/Misc/StatFlags.cs
Normal file
68
Scripts/SubSystem/VitaNex/Core/Misc/StatFlags.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[Flags]
|
||||
public enum StatFlags : byte
|
||||
{
|
||||
None = 0x0,
|
||||
|
||||
Str = 0x1,
|
||||
Dex = 0x2,
|
||||
Int = 0x4,
|
||||
|
||||
Hits = 0x8,
|
||||
Stam = 0x10,
|
||||
Mana = 0x20,
|
||||
|
||||
All = Byte.MaxValue
|
||||
}
|
||||
|
||||
public static class StatsFlagsExtension
|
||||
{
|
||||
public static bool TryConvert(this StatFlags flags, out StatType stats)
|
||||
{
|
||||
stats = StatType.All;
|
||||
|
||||
var f = (byte)flags;
|
||||
|
||||
if (f < 0x1 || f > 0x7)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
stats = (StatType)flags;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string GetName(this StatFlags flags)
|
||||
{
|
||||
return GetName(flags, ", ");
|
||||
}
|
||||
|
||||
public static string GetName(this StatFlags flags, string separator)
|
||||
{
|
||||
if (flags == StatFlags.None)
|
||||
{
|
||||
return "None";
|
||||
}
|
||||
|
||||
return String.Join(separator, flags.EnumerateValues<StatFlags>(true).Not(s => s == StatFlags.None));
|
||||
}
|
||||
}
|
||||
}
|
||||
68
Scripts/SubSystem/VitaNex/Core/Misc/StringCompression.cs
Normal file
68
Scripts/SubSystem/VitaNex/Core/Misc/StringCompression.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public static class StringCompression
|
||||
{
|
||||
public static Encoding DefaultEncoding = Encoding.UTF8;
|
||||
|
||||
public static byte[] Pack(string str)
|
||||
{
|
||||
return Pack(str, DefaultEncoding);
|
||||
}
|
||||
|
||||
public static byte[] Pack(string str, Encoding enc)
|
||||
{
|
||||
var bytes = enc.GetBytes(str);
|
||||
|
||||
using (var stdIn = new MemoryStream(bytes))
|
||||
{
|
||||
using (var stdOut = new MemoryStream())
|
||||
{
|
||||
using (var s = new GZipStream(stdOut, CompressionMode.Compress))
|
||||
{
|
||||
stdIn.CopyTo(s);
|
||||
}
|
||||
|
||||
return stdOut.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string Unpack(byte[] bytes)
|
||||
{
|
||||
return Unpack(bytes, DefaultEncoding);
|
||||
}
|
||||
|
||||
public static string Unpack(byte[] bytes, Encoding enc)
|
||||
{
|
||||
using (var stdIn = new MemoryStream(bytes))
|
||||
{
|
||||
using (var stdOut = new MemoryStream())
|
||||
{
|
||||
using (var s = new GZipStream(stdIn, CompressionMode.Decompress))
|
||||
{
|
||||
s.CopyTo(stdOut);
|
||||
}
|
||||
|
||||
return enc.GetString(stdOut.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
599
Scripts/SubSystem/VitaNex/Core/Misc/TimeStamp.cs
Normal file
599
Scripts/SubSystem/VitaNex/Core/Misc/TimeStamp.cs
Normal file
@@ -0,0 +1,599 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public struct TimeStamp
|
||||
: IComparable<TimeStamp>,
|
||||
IComparable<DateTime>,
|
||||
IComparable<TimeSpan>,
|
||||
IComparable<double>,
|
||||
IComparable<long>,
|
||||
IEquatable<TimeStamp>,
|
||||
IEquatable<DateTime>,
|
||||
IEquatable<TimeSpan>,
|
||||
IEquatable<double>,
|
||||
IEquatable<long>
|
||||
{
|
||||
public static readonly DateTime Origin = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified);
|
||||
|
||||
public static TimeStamp Zero => Origin;
|
||||
|
||||
public static TimeStamp Now => DateTime.Now;
|
||||
public static TimeStamp UtcNow => DateTime.UtcNow;
|
||||
|
||||
public static TimeStamp FromTicks(long value)
|
||||
{
|
||||
return new TimeStamp(value);
|
||||
}
|
||||
|
||||
public static TimeStamp FromTicks(long value, DateTimeKind kind)
|
||||
{
|
||||
return new TimeStamp(value, kind);
|
||||
}
|
||||
|
||||
public static TimeStamp FromMilliseconds(double value)
|
||||
{
|
||||
return new TimeStamp(value / 1000.0);
|
||||
}
|
||||
|
||||
public static TimeStamp FromMilliseconds(double value, DateTimeKind kind)
|
||||
{
|
||||
return new TimeStamp(value / 1000.0, kind);
|
||||
}
|
||||
|
||||
public static TimeStamp FromSeconds(double value)
|
||||
{
|
||||
return new TimeStamp(value);
|
||||
}
|
||||
|
||||
public static TimeStamp FromSeconds(double value, DateTimeKind kind)
|
||||
{
|
||||
return new TimeStamp(value, kind);
|
||||
}
|
||||
|
||||
public static TimeStamp FromMinutes(double value)
|
||||
{
|
||||
return new TimeStamp(value * 60);
|
||||
}
|
||||
|
||||
public static TimeStamp FromMinutes(double value, DateTimeKind kind)
|
||||
{
|
||||
return new TimeStamp(value * 60, kind);
|
||||
}
|
||||
|
||||
public static TimeStamp FromHours(double value)
|
||||
{
|
||||
return new TimeStamp(value * 3600);
|
||||
}
|
||||
|
||||
public static TimeStamp FromHours(double value, DateTimeKind kind)
|
||||
{
|
||||
return new TimeStamp(value * 3600, kind);
|
||||
}
|
||||
|
||||
public static TimeStamp FromDays(double value)
|
||||
{
|
||||
return new TimeStamp(value * 86400);
|
||||
}
|
||||
|
||||
public static TimeStamp FromDays(double value, DateTimeKind kind)
|
||||
{
|
||||
return new TimeStamp(value * 86400, kind);
|
||||
}
|
||||
|
||||
public static TimeStamp FromDateTime(DateTime date)
|
||||
{
|
||||
return new TimeStamp(date);
|
||||
}
|
||||
|
||||
public static int Compare(TimeStamp l, TimeStamp r)
|
||||
{
|
||||
return l.CompareTo(r);
|
||||
}
|
||||
|
||||
public DateTimeKind Kind { get; private set; }
|
||||
public DateTime Value { get; private set; }
|
||||
public double Stamp { get; private set; }
|
||||
|
||||
public long Ticks => Value.Ticks;
|
||||
|
||||
public TimeStamp(DateTime date)
|
||||
: this(date.Kind)
|
||||
{
|
||||
Value = date;
|
||||
Stamp = ResolveStamp();
|
||||
}
|
||||
|
||||
public TimeStamp(TimeSpan time)
|
||||
: this(time, DateTimeKind.Unspecified)
|
||||
{ }
|
||||
|
||||
public TimeStamp(TimeSpan time, DateTimeKind kind)
|
||||
: this(kind)
|
||||
{
|
||||
Stamp = time.TotalSeconds;
|
||||
Value = ResolveDate();
|
||||
}
|
||||
|
||||
public TimeStamp(double stamp)
|
||||
: this(stamp, DateTimeKind.Unspecified)
|
||||
{ }
|
||||
|
||||
public TimeStamp(double stamp, DateTimeKind kind)
|
||||
: this(kind)
|
||||
{
|
||||
Stamp = stamp;
|
||||
Value = ResolveDate();
|
||||
}
|
||||
|
||||
public TimeStamp(long ticks)
|
||||
: this(ticks, DateTimeKind.Unspecified)
|
||||
{ }
|
||||
|
||||
public TimeStamp(long ticks, DateTimeKind kind)
|
||||
: this(kind)
|
||||
{
|
||||
Value = new DateTime(ticks, kind);
|
||||
Stamp = ResolveStamp();
|
||||
}
|
||||
|
||||
public TimeStamp(DateTimeKind kind)
|
||||
: this()
|
||||
{
|
||||
Kind = kind;
|
||||
}
|
||||
|
||||
public TimeStamp(GenericReader reader)
|
||||
: this(Origin)
|
||||
{
|
||||
Deserialize(reader);
|
||||
}
|
||||
|
||||
private DateTime ResolveDate()
|
||||
{
|
||||
var dt = new DateTime(
|
||||
Origin.Year,
|
||||
Origin.Month,
|
||||
Origin.Day,
|
||||
Origin.Hour,
|
||||
Origin.Minute,
|
||||
Origin.Second,
|
||||
Origin.Millisecond,
|
||||
Kind);
|
||||
|
||||
return dt.AddSeconds(Stamp);
|
||||
}
|
||||
|
||||
private double ResolveStamp()
|
||||
{
|
||||
return Value.Subtract(Origin).TotalSeconds;
|
||||
}
|
||||
|
||||
public TimeStamp Add(TimeSpan ts)
|
||||
{
|
||||
return Stamp + ts.TotalSeconds;
|
||||
}
|
||||
|
||||
public TimeStamp Subtract(TimeSpan ts)
|
||||
{
|
||||
return Stamp - ts.TotalSeconds;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Stamp.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is TimeStamp && Equals((TimeStamp)obj)) //
|
||||
|| (obj is DateTime && Equals((DateTime)obj)) //
|
||||
|| (obj is TimeSpan && Equals((TimeSpan)obj)) //
|
||||
|| (obj is double && Equals((double)obj)) //
|
||||
|| (obj is long && Equals((long)obj));
|
||||
}
|
||||
|
||||
public bool Equals(TimeStamp t)
|
||||
{
|
||||
return Stamp == t.Stamp;
|
||||
}
|
||||
|
||||
public bool Equals(DateTime d)
|
||||
{
|
||||
return Value == d;
|
||||
}
|
||||
|
||||
public bool Equals(TimeSpan t)
|
||||
{
|
||||
return Stamp == t.TotalSeconds;
|
||||
}
|
||||
|
||||
public bool Equals(double stamp)
|
||||
{
|
||||
return Stamp == stamp;
|
||||
}
|
||||
|
||||
public bool Equals(long ticks)
|
||||
{
|
||||
return Ticks == ticks;
|
||||
}
|
||||
|
||||
public int CompareTo(TimeStamp t)
|
||||
{
|
||||
return Stamp.CompareTo(t.Stamp);
|
||||
}
|
||||
|
||||
public int CompareTo(DateTime d)
|
||||
{
|
||||
return Value.CompareTo(d);
|
||||
}
|
||||
|
||||
public int CompareTo(TimeSpan t)
|
||||
{
|
||||
return Stamp.CompareTo(t.TotalSeconds);
|
||||
}
|
||||
|
||||
public int CompareTo(double stamp)
|
||||
{
|
||||
return Stamp.CompareTo(stamp);
|
||||
}
|
||||
|
||||
public int CompareTo(long ticks)
|
||||
{
|
||||
return Ticks.CompareTo(ticks);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("{0:F2}", Stamp);
|
||||
}
|
||||
|
||||
public void Serialize(GenericWriter writer)
|
||||
{
|
||||
var version = writer.SetVersion(1);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
writer.WriteFlag(Kind);
|
||||
goto case 0;
|
||||
case 0:
|
||||
writer.Write(Stamp);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void Deserialize(GenericReader reader)
|
||||
{
|
||||
var version = reader.GetVersion();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
Kind = reader.ReadFlag<DateTimeKind>();
|
||||
goto case 0;
|
||||
case 0:
|
||||
{
|
||||
Stamp = reader.ReadDouble();
|
||||
Value = ResolveDate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#region TimeStamp Equality
|
||||
public static bool operator ==(TimeStamp l, TimeStamp r)
|
||||
{
|
||||
return l.Stamp.Equals(r.Stamp);
|
||||
}
|
||||
|
||||
public static bool operator !=(TimeStamp l, TimeStamp r)
|
||||
{
|
||||
return !l.Stamp.Equals(r.Stamp);
|
||||
}
|
||||
|
||||
public static bool operator >(TimeStamp l, TimeStamp r)
|
||||
{
|
||||
return l.Stamp > r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator <(TimeStamp l, TimeStamp r)
|
||||
{
|
||||
return l.Stamp < r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator >=(TimeStamp l, TimeStamp r)
|
||||
{
|
||||
return l.Stamp >= r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator <=(TimeStamp l, TimeStamp r)
|
||||
{
|
||||
return l.Stamp <= r.Stamp;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region DateTime Equality
|
||||
public static bool operator ==(TimeStamp l, DateTime r)
|
||||
{
|
||||
return l.Ticks.Equals(r.Ticks);
|
||||
}
|
||||
|
||||
public static bool operator !=(TimeStamp l, DateTime r)
|
||||
{
|
||||
return !l.Ticks.Equals(r.Ticks);
|
||||
}
|
||||
|
||||
public static bool operator >(TimeStamp l, DateTime r)
|
||||
{
|
||||
return l.Ticks > r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator <(TimeStamp l, DateTime r)
|
||||
{
|
||||
return l.Ticks < r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator >=(TimeStamp l, DateTime r)
|
||||
{
|
||||
return l.Ticks >= r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator <=(TimeStamp l, DateTime r)
|
||||
{
|
||||
return l.Ticks <= r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator ==(DateTime l, TimeStamp r)
|
||||
{
|
||||
return l.Ticks.Equals(r.Ticks);
|
||||
}
|
||||
|
||||
public static bool operator !=(DateTime l, TimeStamp r)
|
||||
{
|
||||
return !l.Ticks.Equals(r.Ticks);
|
||||
}
|
||||
|
||||
public static bool operator >(DateTime l, TimeStamp r)
|
||||
{
|
||||
return l.Ticks > r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator <(DateTime l, TimeStamp r)
|
||||
{
|
||||
return l.Ticks < r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator >=(DateTime l, TimeStamp r)
|
||||
{
|
||||
return l.Ticks >= r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator <=(DateTime l, TimeStamp r)
|
||||
{
|
||||
return l.Ticks <= r.Ticks;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region TimeSpan Equality
|
||||
public static bool operator ==(TimeStamp l, TimeSpan r)
|
||||
{
|
||||
return l.Stamp.Equals(r.TotalSeconds);
|
||||
}
|
||||
|
||||
public static bool operator !=(TimeStamp l, TimeSpan r)
|
||||
{
|
||||
return !l.Stamp.Equals(r.TotalSeconds);
|
||||
}
|
||||
|
||||
public static bool operator >(TimeStamp l, TimeSpan r)
|
||||
{
|
||||
return l.Stamp > r.TotalSeconds;
|
||||
}
|
||||
|
||||
public static bool operator <(TimeStamp l, TimeSpan r)
|
||||
{
|
||||
return l.Stamp < r.TotalSeconds;
|
||||
}
|
||||
|
||||
public static bool operator >=(TimeStamp l, TimeSpan r)
|
||||
{
|
||||
return l.Stamp >= r.TotalSeconds;
|
||||
}
|
||||
|
||||
public static bool operator <=(TimeStamp l, TimeSpan r)
|
||||
{
|
||||
return l.Stamp <= r.TotalSeconds;
|
||||
}
|
||||
|
||||
public static bool operator ==(TimeSpan l, TimeStamp r)
|
||||
{
|
||||
return l.TotalSeconds.Equals(r.Stamp);
|
||||
}
|
||||
|
||||
public static bool operator !=(TimeSpan l, TimeStamp r)
|
||||
{
|
||||
return !l.TotalSeconds.Equals(r.Stamp);
|
||||
}
|
||||
|
||||
public static bool operator >(TimeSpan l, TimeStamp r)
|
||||
{
|
||||
return l.TotalSeconds > r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator <(TimeSpan l, TimeStamp r)
|
||||
{
|
||||
return l.TotalSeconds < r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator >=(TimeSpan l, TimeStamp r)
|
||||
{
|
||||
return l.TotalSeconds >= r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator <=(TimeSpan l, TimeStamp r)
|
||||
{
|
||||
return l.TotalSeconds <= r.Stamp;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Stamp Equality
|
||||
public static bool operator ==(TimeStamp l, double r)
|
||||
{
|
||||
return l.Stamp.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(TimeStamp l, double r)
|
||||
{
|
||||
return !l.Stamp.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator >(TimeStamp l, double r)
|
||||
{
|
||||
return l.Stamp > r;
|
||||
}
|
||||
|
||||
public static bool operator <(TimeStamp l, double r)
|
||||
{
|
||||
return l.Stamp < r;
|
||||
}
|
||||
|
||||
public static bool operator >=(TimeStamp l, double r)
|
||||
{
|
||||
return l.Stamp >= r;
|
||||
}
|
||||
|
||||
public static bool operator <=(TimeStamp l, double r)
|
||||
{
|
||||
return l.Stamp <= r;
|
||||
}
|
||||
|
||||
public static bool operator ==(double l, TimeStamp r)
|
||||
{
|
||||
return l.Equals(r.Stamp);
|
||||
}
|
||||
|
||||
public static bool operator !=(double l, TimeStamp r)
|
||||
{
|
||||
return !l.Equals(r.Stamp);
|
||||
}
|
||||
|
||||
public static bool operator >(double l, TimeStamp r)
|
||||
{
|
||||
return l > r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator <(double l, TimeStamp r)
|
||||
{
|
||||
return l < r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator >=(double l, TimeStamp r)
|
||||
{
|
||||
return l >= r.Stamp;
|
||||
}
|
||||
|
||||
public static bool operator <=(double l, TimeStamp r)
|
||||
{
|
||||
return l <= r.Stamp;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Ticks Equality
|
||||
public static bool operator ==(TimeStamp l, long r)
|
||||
{
|
||||
return l.Ticks.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(TimeStamp l, long r)
|
||||
{
|
||||
return !l.Ticks.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator >(TimeStamp l, long r)
|
||||
{
|
||||
return l.Ticks > r;
|
||||
}
|
||||
|
||||
public static bool operator <(TimeStamp l, long r)
|
||||
{
|
||||
return l.Ticks < r;
|
||||
}
|
||||
|
||||
public static bool operator >=(TimeStamp l, long r)
|
||||
{
|
||||
return l.Ticks >= r;
|
||||
}
|
||||
|
||||
public static bool operator <=(TimeStamp l, long r)
|
||||
{
|
||||
return l.Ticks <= r;
|
||||
}
|
||||
|
||||
public static bool operator ==(long l, TimeStamp r)
|
||||
{
|
||||
return l.Equals(r.Ticks);
|
||||
}
|
||||
|
||||
public static bool operator !=(long l, TimeStamp r)
|
||||
{
|
||||
return !l.Equals(r.Ticks);
|
||||
}
|
||||
|
||||
public static bool operator >(long l, TimeStamp r)
|
||||
{
|
||||
return l > r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator <(long l, TimeStamp r)
|
||||
{
|
||||
return l < r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator >=(long l, TimeStamp r)
|
||||
{
|
||||
return l >= r.Ticks;
|
||||
}
|
||||
|
||||
public static bool operator <=(long l, TimeStamp r)
|
||||
{
|
||||
return l <= r.Ticks;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public static implicit operator TimeStamp(DateTime date)
|
||||
{
|
||||
return new TimeStamp(date);
|
||||
}
|
||||
|
||||
public static implicit operator TimeStamp(TimeSpan time)
|
||||
{
|
||||
return new TimeStamp(time);
|
||||
}
|
||||
|
||||
public static implicit operator TimeStamp(double stamp)
|
||||
{
|
||||
return new TimeStamp(stamp);
|
||||
}
|
||||
|
||||
public static implicit operator TimeStamp(long ticks)
|
||||
{
|
||||
return new TimeStamp(ticks);
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Scripts/SubSystem/VitaNex/Core/Misc/UOCursor.cs
Normal file
34
Scripts/SubSystem/VitaNex/Core/Misc/UOCursor.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
public enum UOCursor
|
||||
{
|
||||
None = 0,
|
||||
PointUp = 8298,
|
||||
PointNorth = 8299,
|
||||
PointRight = 8300,
|
||||
PointEast = 8301,
|
||||
PointDown = 8302,
|
||||
PointSouth = 8303,
|
||||
PointLeft = 8304,
|
||||
PointWest = 8305,
|
||||
Grab = 8306,
|
||||
Interact = 8307,
|
||||
Hold = 8308,
|
||||
Feel = 8309,
|
||||
Target = 8310,
|
||||
Wait = 8311,
|
||||
Input = 8312,
|
||||
Pin = 8313
|
||||
}
|
||||
}
|
||||
308
Scripts/SubSystem/VitaNex/Core/Misc/VersionInfo.cs
Normal file
308
Scripts/SubSystem/VitaNex/Core/Misc/VersionInfo.cs
Normal file
@@ -0,0 +1,308 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.All, Inherited = false)]
|
||||
public class VersionInfoAttribute : Attribute
|
||||
{
|
||||
public VersionInfo Version { get; set; }
|
||||
|
||||
public string Name { get => Version.Name; set => Version.Name = value; }
|
||||
public string Description { get => Version.Description; set => Version.Description = value; }
|
||||
|
||||
public VersionInfoAttribute(string version = "1.0.0.0", string name = "", string description = "")
|
||||
{
|
||||
Version = version;
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
}
|
||||
|
||||
public class VersionInfo
|
||||
: PropertyObject, IEquatable<VersionInfo>, IComparable<VersionInfo>, IEquatable<Version>, IComparable<Version>
|
||||
{
|
||||
public static Version DefaultVersion => new Version(1, 0, 0, 0);
|
||||
|
||||
protected Version InternalVersion { get; set; }
|
||||
|
||||
public Version Version => InternalVersion ?? (InternalVersion = DefaultVersion);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public virtual string Value => ToString(4);
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public virtual int Major
|
||||
{
|
||||
get => Version.Major;
|
||||
set => InternalVersion = new Version(value, Minor, Build, Revision);
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public virtual int Minor
|
||||
{
|
||||
get => Version.Minor;
|
||||
set => InternalVersion = new Version(Major, value, Build, Revision);
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public virtual int Build
|
||||
{
|
||||
get => Version.Build;
|
||||
set => InternalVersion = new Version(Major, Minor, value, Revision);
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public virtual int Revision
|
||||
{
|
||||
get => Version.Revision;
|
||||
set => InternalVersion = new Version(Major, Minor, Build, value);
|
||||
}
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public virtual string Name { get; set; }
|
||||
|
||||
[CommandProperty(AccessLevel.Counselor, AccessLevel.GameMaster)]
|
||||
public virtual string Description { get; set; }
|
||||
|
||||
public VersionInfo()
|
||||
{
|
||||
InternalVersion = DefaultVersion;
|
||||
}
|
||||
|
||||
public VersionInfo(int major = 1, int minor = 0, int build = 0, int revision = 0)
|
||||
{
|
||||
InternalVersion = new Version(major, minor, build, revision);
|
||||
}
|
||||
|
||||
public VersionInfo(string version)
|
||||
{
|
||||
if (!Version.TryParse(version, out var v))
|
||||
{
|
||||
v = DefaultVersion;
|
||||
}
|
||||
|
||||
InternalVersion = new Version(
|
||||
Math.Max(0, v.Major),
|
||||
Math.Max(0, v.Minor),
|
||||
Math.Max(0, v.Build),
|
||||
Math.Max(0, v.Revision));
|
||||
}
|
||||
|
||||
public VersionInfo(Version v)
|
||||
{
|
||||
InternalVersion = new Version(
|
||||
Math.Max(0, v.Major),
|
||||
Math.Max(0, v.Minor),
|
||||
Math.Max(0, v.Build),
|
||||
Math.Max(0, v.Revision));
|
||||
}
|
||||
|
||||
public VersionInfo(GenericReader reader)
|
||||
: base(reader)
|
||||
{ }
|
||||
|
||||
public override void Clear()
|
||||
{
|
||||
InternalVersion = DefaultVersion;
|
||||
}
|
||||
|
||||
public override void Reset()
|
||||
{
|
||||
InternalVersion = DefaultVersion;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Version.ToString();
|
||||
}
|
||||
|
||||
public virtual string ToString(int fieldCount)
|
||||
{
|
||||
return Version.ToString(fieldCount);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Version.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return (obj is Version && Equals((Version)obj)) || (obj is VersionInfo && Equals((VersionInfo)obj));
|
||||
}
|
||||
|
||||
public virtual bool Equals(Version other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) && Version == other;
|
||||
}
|
||||
|
||||
public virtual bool Equals(VersionInfo other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) && Version == other.Version;
|
||||
}
|
||||
|
||||
public virtual int CompareTo(Version other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) ? Version.CompareTo(other) : -1;
|
||||
}
|
||||
|
||||
public virtual int CompareTo(VersionInfo other)
|
||||
{
|
||||
return !ReferenceEquals(other, null) ? Version.CompareTo(other.Version) : -1;
|
||||
}
|
||||
|
||||
public override void Serialize(GenericWriter writer)
|
||||
{
|
||||
base.Serialize(writer);
|
||||
|
||||
var version = writer.SetVersion(0);
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
writer.Write(Name);
|
||||
writer.Write(Description);
|
||||
}
|
||||
goto case 0;
|
||||
case 0:
|
||||
{
|
||||
writer.Write(Version.Major);
|
||||
writer.Write(Version.Minor);
|
||||
writer.Write(Version.Build);
|
||||
writer.Write(Version.Revision);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Deserialize(GenericReader reader)
|
||||
{
|
||||
base.Deserialize(reader);
|
||||
|
||||
var version = reader.GetVersion();
|
||||
|
||||
switch (version)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
Name = reader.ReadString();
|
||||
Description = reader.ReadString();
|
||||
}
|
||||
goto case 0;
|
||||
case 0:
|
||||
{
|
||||
int major = reader.ReadInt(), minor = reader.ReadInt(), build = reader.ReadInt(), revision = reader.ReadInt();
|
||||
|
||||
InternalVersion = new Version(Math.Max(0, major), Math.Max(0, minor), Math.Max(0, build), Math.Max(0, revision));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryParse(string s, out VersionInfo version)
|
||||
{
|
||||
version = DefaultVersion;
|
||||
|
||||
if (String.IsNullOrWhiteSpace(s))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var value = String.Empty;
|
||||
|
||||
foreach (var c in s.Select(c => c.ToString(CultureInfo.InvariantCulture)))
|
||||
{
|
||||
if (c == ".")
|
||||
{
|
||||
if (value.Length > 0)
|
||||
{
|
||||
value += c;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Byte.TryParse(c, out var b))
|
||||
{
|
||||
value += b;
|
||||
}
|
||||
}
|
||||
|
||||
if (Version.TryParse(value, out var v))
|
||||
{
|
||||
version = new Version(Math.Max(0, v.Major), Math.Max(0, v.Minor), Math.Max(0, v.Build), Math.Max(0, v.Revision));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static implicit operator VersionInfo(string version)
|
||||
{
|
||||
return new VersionInfo(version);
|
||||
}
|
||||
|
||||
public static implicit operator string(VersionInfo version)
|
||||
{
|
||||
return version.Value;
|
||||
}
|
||||
|
||||
public static implicit operator VersionInfo(Version version)
|
||||
{
|
||||
return new VersionInfo(version);
|
||||
}
|
||||
|
||||
public static implicit operator Version(VersionInfo a)
|
||||
{
|
||||
return a.Version;
|
||||
}
|
||||
|
||||
public static bool operator ==(VersionInfo l, VersionInfo r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? ReferenceEquals(r, null) : l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator !=(VersionInfo l, VersionInfo r)
|
||||
{
|
||||
return ReferenceEquals(l, null) ? !ReferenceEquals(r, null) : !l.Equals(r);
|
||||
}
|
||||
|
||||
public static bool operator <=(VersionInfo v1, VersionInfo v2)
|
||||
{
|
||||
return (!ReferenceEquals(v1, null) && !ReferenceEquals(v2, null) && v1.Version <= v2.Version);
|
||||
}
|
||||
|
||||
public static bool operator >=(VersionInfo v1, VersionInfo v2)
|
||||
{
|
||||
return (!ReferenceEquals(v1, null) && !ReferenceEquals(v2, null) && v1.Version >= v2.Version);
|
||||
}
|
||||
|
||||
public static bool operator <(VersionInfo v1, VersionInfo v2)
|
||||
{
|
||||
return (!ReferenceEquals(v1, null) && !ReferenceEquals(v2, null) && v1.Version < v2.Version);
|
||||
}
|
||||
|
||||
public static bool operator >(VersionInfo v1, VersionInfo v2)
|
||||
{
|
||||
return (!ReferenceEquals(v1, null) && !ReferenceEquals(v2, null) && v1.Version > v2.Version);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user