Overwrite
Complete Overwrite of the Folder with the free shard. ServUO 57.3 has been added.
This commit is contained in:
122
Scripts/SubSystem/VitaNex/Core/Commands/ExportBounds.cs
Normal file
122
Scripts/SubSystem/VitaNex/Core/Commands/ExportBounds.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
#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;
|
||||
using Server.Mobiles;
|
||||
|
||||
using VitaNex.IO;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Commands
|
||||
{
|
||||
public static class ExportBoundsCommand
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandUtility.Register(
|
||||
"ExportBounds2D",
|
||||
AccessLevel.GameMaster,
|
||||
e =>
|
||||
{
|
||||
if (e != null && e.Mobile != null)
|
||||
{
|
||||
OnExportBounds2D(e.Mobile, e.GetString(0), e.GetString(1));
|
||||
}
|
||||
});
|
||||
CommandUtility.RegisterAlias("ExportBounds2D", "XB2D");
|
||||
|
||||
CommandUtility.Register(
|
||||
"ExportBounds3D",
|
||||
AccessLevel.GameMaster,
|
||||
e =>
|
||||
{
|
||||
if (e != null && e.Mobile != null)
|
||||
{
|
||||
OnExportBounds3D(e.Mobile, e.GetString(0), e.GetString(1));
|
||||
}
|
||||
});
|
||||
CommandUtility.RegisterAlias("ExportBounds3D", "XB3D");
|
||||
}
|
||||
|
||||
public static void OnExportBounds2D(Mobile m, string speech, string comment)
|
||||
{
|
||||
if (m == null || m.Deleted || !(m is PlayerMobile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrWhiteSpace(speech))
|
||||
{
|
||||
speech = "Bounds";
|
||||
}
|
||||
|
||||
BoundingBoxPicker.Begin(
|
||||
m,
|
||||
(from, map, start, end, state) =>
|
||||
{
|
||||
var r = new Rectangle2D(start, end.Clone2D(1, 1));
|
||||
|
||||
IOUtility.EnsureFile(VitaNexCore.DataDirectory + "/Export/Bounds/2D/" + IOUtility.GetSafeFileName(speech) + ".txt")
|
||||
.AppendText(
|
||||
false,
|
||||
String.Format(
|
||||
"new Rectangle2D({0}, {1}, {2}, {3}), //{4}",
|
||||
//
|
||||
r.Start.X,
|
||||
r.Start.Y,
|
||||
r.Width,
|
||||
r.Height,
|
||||
comment ?? String.Empty));
|
||||
},
|
||||
null);
|
||||
}
|
||||
|
||||
public static void OnExportBounds3D(Mobile m, string speech, string comment)
|
||||
{
|
||||
if (m == null || m.Deleted || !(m is PlayerMobile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrWhiteSpace(speech))
|
||||
{
|
||||
speech = "Bounds";
|
||||
}
|
||||
|
||||
BoundingBoxPicker.Begin(
|
||||
m,
|
||||
(from, map, start, end, state) =>
|
||||
{
|
||||
var r = new Rectangle3D(start, end.Clone3D(1, 1));
|
||||
|
||||
IOUtility
|
||||
.EnsureFile(VitaNexCore.DataDirectory + "/Export/Bounds/3D/" + IOUtility.GetSafeFileName(speech) + ".txt")
|
||||
.AppendText(
|
||||
false,
|
||||
String.Format(
|
||||
"new Rectangle3D({0}, {1}, {2}, {3}, {4}, {5}), //{6}",
|
||||
//
|
||||
r.Start.X,
|
||||
r.Start.Y,
|
||||
r.Start.Z,
|
||||
r.Width,
|
||||
r.Height,
|
||||
r.Depth,
|
||||
comment ?? String.Empty));
|
||||
},
|
||||
null);
|
||||
}
|
||||
}
|
||||
}
|
||||
100
Scripts/SubSystem/VitaNex/Core/Commands/ExportPoint.cs
Normal file
100
Scripts/SubSystem/VitaNex/Core/Commands/ExportPoint.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.IO;
|
||||
|
||||
using Server;
|
||||
using Server.Mobiles;
|
||||
|
||||
using VitaNex.IO;
|
||||
using VitaNex.Targets;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Commands
|
||||
{
|
||||
public static class ExportPointCommand
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandUtility.Register(
|
||||
"ExportPoint2D",
|
||||
AccessLevel.GameMaster,
|
||||
e =>
|
||||
{
|
||||
if (e != null && e.Mobile != null)
|
||||
{
|
||||
OnExportPoint2D(e.Mobile, e.GetString(0), e.GetString(1));
|
||||
}
|
||||
});
|
||||
CommandUtility.RegisterAlias("ExportPoint2D", "XP2D");
|
||||
|
||||
CommandUtility.Register(
|
||||
"ExportPoint3D",
|
||||
AccessLevel.GameMaster,
|
||||
e =>
|
||||
{
|
||||
if (e != null && e.Mobile != null)
|
||||
{
|
||||
OnExportPoint3D(e.Mobile, e.GetString(0), e.GetString(1));
|
||||
}
|
||||
});
|
||||
CommandUtility.RegisterAlias("ExportPoint3D", "XP3D");
|
||||
}
|
||||
|
||||
public static void OnExportPoint2D(Mobile m, string speech, string comment)
|
||||
{
|
||||
if (m == null || m.Deleted || !(m is PlayerMobile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrWhiteSpace(speech))
|
||||
{
|
||||
speech = "Points";
|
||||
}
|
||||
|
||||
GenericSelectTarget<IPoint2D>.Begin(
|
||||
m,
|
||||
(from, p) =>
|
||||
IOUtility
|
||||
.EnsureFile(VitaNexCore.DataDirectory + "/Export/Points/2D/" + IOUtility.GetSafeFileName(speech) + ".txt")
|
||||
.AppendText(false, String.Format("new Point2D({0}, {1}), //{2}", p.X, p.Y, comment ?? String.Empty)),
|
||||
null,
|
||||
-1,
|
||||
true);
|
||||
}
|
||||
|
||||
public static void OnExportPoint3D(Mobile m, string speech, string comment)
|
||||
{
|
||||
if (m == null || m.Deleted || !(m is PlayerMobile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (String.IsNullOrWhiteSpace(speech))
|
||||
{
|
||||
speech = "Points";
|
||||
}
|
||||
|
||||
GenericSelectTarget<IPoint3D>.Begin(
|
||||
m,
|
||||
(from, p) =>
|
||||
IOUtility
|
||||
.EnsureFile(VitaNexCore.DataDirectory + "/Export/Points/3D/" + IOUtility.GetSafeFileName(speech) + ".txt")
|
||||
.AppendText(false, String.Format("new Point3D({0}, {1}, {2}), //{3}", p.X, p.Y, p.Z, comment ?? String.Empty)),
|
||||
null,
|
||||
-1,
|
||||
true);
|
||||
}
|
||||
}
|
||||
}
|
||||
484
Scripts/SubSystem/VitaNex/Core/Commands/FixMe.cs
Normal file
484
Scripts/SubSystem/VitaNex/Core/Commands/FixMe.cs
Normal file
@@ -0,0 +1,484 @@
|
||||
#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;
|
||||
|
||||
using Server;
|
||||
using Server.Commands;
|
||||
using Server.Gumps;
|
||||
using Server.Mobiles;
|
||||
using Server.Network;
|
||||
|
||||
using VitaNex.SuperGumps;
|
||||
using VitaNex.SuperGumps.UI;
|
||||
using VitaNex.Targets;
|
||||
|
||||
using Skills = Server.Skills;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Commands
|
||||
{
|
||||
[Flags]
|
||||
public enum FixMeFlags
|
||||
{
|
||||
None = 0x0000,
|
||||
Mount = 0x0001,
|
||||
Pets = 0x0002,
|
||||
Equip = 0x0004,
|
||||
Gumps = 0x0008,
|
||||
Tags = 0x0010,
|
||||
Skills = 0x0020,
|
||||
Quests = 0x0040,
|
||||
All = ~None
|
||||
}
|
||||
|
||||
public static class FixMeCommand
|
||||
{
|
||||
public delegate void ResolveFlagsHandler(Mobile m, ref FixMeFlags flags);
|
||||
|
||||
public static event Action<Mobile> OnFixMount;
|
||||
public static event Action<PlayerMobile> OnFixPets;
|
||||
public static event Action<PlayerMobile> OnFixEquip;
|
||||
public static event Action<Mobile> OnFixGumps;
|
||||
public static event Action<Mobile> OnFixTags;
|
||||
public static event Action<Mobile> OnFixSkills;
|
||||
public static event Action<PlayerMobile> OnFixQuests;
|
||||
|
||||
public static event Action<FixMeGump> OnGumpSend;
|
||||
public static event Action<Mobile, FixMeFlags> OnFix;
|
||||
|
||||
public static event ResolveFlagsHandler ResolveFlags;
|
||||
|
||||
public static FixMeFlags DisabledFlags { get; set; }
|
||||
|
||||
static FixMeCommand()
|
||||
{
|
||||
OnFixMount += FixMount;
|
||||
OnFixPets += FixPets;
|
||||
OnFixEquip += FixEquip;
|
||||
OnFixGumps += FixGumps;
|
||||
OnFixTags += FixTags;
|
||||
OnFixSkills += FixSkills;
|
||||
OnFixQuests += FixQuests;
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
CommandSystem.Register(
|
||||
"FixMe",
|
||||
AccessLevel.Player,
|
||||
e =>
|
||||
{
|
||||
if (e == null || !(e.Mobile is PlayerMobile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var g = SuperGump.Send(new FixMeGump((PlayerMobile)e.Mobile));
|
||||
|
||||
if (OnGumpSend != null)
|
||||
{
|
||||
OnGumpSend(g);
|
||||
}
|
||||
});
|
||||
|
||||
CommandSystem.Register(
|
||||
"FixThem",
|
||||
AccessLevel.GameMaster,
|
||||
e =>
|
||||
{
|
||||
if (e == null || !(e.Mobile is PlayerMobile))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
e.Mobile.SendMessage(0x22, "Target an online player to send them the FixMe gump.");
|
||||
e.Mobile.Target = new MobileSelectTarget<PlayerMobile>(
|
||||
(m, target) =>
|
||||
{
|
||||
if (target == null || target.Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target.IsOnline())
|
||||
{
|
||||
m.SendMessage(0x22, "{0} must be online.", target.RawName);
|
||||
return;
|
||||
}
|
||||
|
||||
m.SendMessage(0x55, "Opening FixMe gump for {0}...", target.RawName);
|
||||
|
||||
var g = SuperGump.Send(new FixMeGump(target));
|
||||
|
||||
if (OnGumpSend != null)
|
||||
{
|
||||
OnGumpSend(g);
|
||||
}
|
||||
},
|
||||
m => m.SendMessage(0x22, "Target an on-line player to send them the FixMe gump."));
|
||||
});
|
||||
}
|
||||
|
||||
public static string GetDescription(this FixMeFlags flags)
|
||||
{
|
||||
var html = new StringBuilder();
|
||||
|
||||
switch (flags)
|
||||
{
|
||||
case FixMeFlags.Mount:
|
||||
html.Append("Attempt to correct your mount if it appears to be glitched.");
|
||||
break;
|
||||
case FixMeFlags.Pets:
|
||||
{
|
||||
html.AppendLine("All pets will be stabled or teleported and your follower count will be normalized.");
|
||||
html.Append("If mounted, the mount will not be included.");
|
||||
}
|
||||
break;
|
||||
case FixMeFlags.Equip:
|
||||
html.Append("All equipment will be validated, any invalid equipment will be unequipped.");
|
||||
break;
|
||||
case FixMeFlags.Gumps:
|
||||
html.Append("All open gumps will be refreshed.");
|
||||
break;
|
||||
case FixMeFlags.Tags:
|
||||
html.Append("All character and equipment attribute tags will be refreshed.");
|
||||
break;
|
||||
case FixMeFlags.Skills:
|
||||
html.Append("All skills will be normalized if they are detected as invalid.");
|
||||
break;
|
||||
case FixMeFlags.Quests:
|
||||
html.Append("All quests will be repaired if they are detected as invalid.");
|
||||
break;
|
||||
}
|
||||
|
||||
return html.ToString();
|
||||
}
|
||||
|
||||
public static void FixMe(this Mobile m, FixMeFlags flags)
|
||||
{
|
||||
if (m == null || m.Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldFlags = flags;
|
||||
|
||||
if (ResolveFlags != null)
|
||||
{
|
||||
ResolveFlags(m, ref flags);
|
||||
}
|
||||
|
||||
if (flags.HasFlag(FixMeFlags.Mount) && OnFixMount != null)
|
||||
{
|
||||
OnFixMount(m);
|
||||
m.SendMessage(0x55, "Your mount has been validated.");
|
||||
}
|
||||
else if (oldFlags.HasFlag(FixMeFlags.Mount))
|
||||
{
|
||||
m.SendMessage(0x22, "Fixing mounts is currently unavailable.");
|
||||
}
|
||||
|
||||
if (flags.HasFlag(FixMeFlags.Pets) && OnFixPets != null && m is PlayerMobile)
|
||||
{
|
||||
OnFixPets((PlayerMobile)m);
|
||||
m.SendMessage(
|
||||
0x55,
|
||||
"Your pets have been stabled or teleported to you and your follower count has been normalized, it is now {0}.",
|
||||
m.Followers);
|
||||
}
|
||||
else if (oldFlags.HasFlag(FixMeFlags.Pets))
|
||||
{
|
||||
m.SendMessage(0x22, "Fixing pets is currently unavailable.");
|
||||
}
|
||||
|
||||
if (flags.HasFlag(FixMeFlags.Equip) && OnFixEquip != null && m is PlayerMobile)
|
||||
{
|
||||
OnFixEquip((PlayerMobile)m);
|
||||
m.SendMessage(0x55, "Your equipment has been validated.");
|
||||
}
|
||||
else if (oldFlags.HasFlag(FixMeFlags.Equip))
|
||||
{
|
||||
m.SendMessage(0x22, "Fixing equipment is currently unavailable.");
|
||||
}
|
||||
|
||||
if (flags.HasFlag(FixMeFlags.Gumps) && OnFixGumps != null)
|
||||
{
|
||||
OnFixGumps(m);
|
||||
m.SendMessage(0x55, "Your gumps have been refreshed.");
|
||||
}
|
||||
else if (oldFlags.HasFlag(FixMeFlags.Gumps))
|
||||
{
|
||||
m.SendMessage(0x22, "Fixing gumps is currently unavailable.");
|
||||
}
|
||||
|
||||
if (flags.HasFlag(FixMeFlags.Tags) && OnFixTags != null)
|
||||
{
|
||||
OnFixTags(m);
|
||||
m.SendMessage(0x55, "Your character and equipment tags have been refreshed.");
|
||||
}
|
||||
else if (oldFlags.HasFlag(FixMeFlags.Tags))
|
||||
{
|
||||
m.SendMessage(0x22, "Fixing character and equipment tags is currently unavailable.");
|
||||
}
|
||||
|
||||
if (flags.HasFlag(FixMeFlags.Skills) && OnFixSkills != null)
|
||||
{
|
||||
OnFixSkills(m);
|
||||
m.SendMessage(0x55, "Your skills have been normalized.");
|
||||
}
|
||||
else if (oldFlags.HasFlag(FixMeFlags.Skills))
|
||||
{
|
||||
m.SendMessage(0x22, "Fixing skills is currently unavailable.");
|
||||
}
|
||||
|
||||
if (flags.HasFlag(FixMeFlags.Quests) && OnFixQuests != null && m is PlayerMobile)
|
||||
{
|
||||
OnFixQuests((PlayerMobile)m);
|
||||
m.SendMessage(0x55, "Your quests have been validated.");
|
||||
}
|
||||
else if (oldFlags.HasFlag(FixMeFlags.Quests))
|
||||
{
|
||||
m.SendMessage(0x22, "Fixing quests is currently unavailable.");
|
||||
}
|
||||
|
||||
if (OnFix != null)
|
||||
{
|
||||
OnFix(m, flags);
|
||||
}
|
||||
|
||||
m.SendMessage(0x55, "FixMe completed! If you still have issues, contact a member of staff.");
|
||||
}
|
||||
|
||||
public static void FixMount(Mobile m)
|
||||
{
|
||||
if (!m.Mounted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var mountItem = m.FindItemOnLayer(Layer.Mount) as IMountItem;
|
||||
|
||||
if (mountItem != null)
|
||||
{
|
||||
if (mountItem.Mount == null || mountItem.Mount != m.Mount)
|
||||
{
|
||||
m.RemoveItem(mountItem as Item);
|
||||
}
|
||||
else if (mountItem.Mount.Rider == null)
|
||||
{
|
||||
mountItem.Mount.Rider = m;
|
||||
}
|
||||
}
|
||||
else if (m.Mount != null && m.Mount.Rider == null)
|
||||
{
|
||||
m.Mount.Rider = m;
|
||||
}
|
||||
|
||||
m.Delta(MobileDelta.Followers);
|
||||
}
|
||||
|
||||
public static void FixPets(PlayerMobile m)
|
||||
{
|
||||
if (m.AllFollowers == null || m.AllFollowers.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
BaseCreature pet;
|
||||
|
||||
var count = m.AllFollowers.Count;
|
||||
|
||||
while (--count >= 0)
|
||||
{
|
||||
pet = m.AllFollowers[count] as BaseCreature;
|
||||
|
||||
if (pet == null || pet.IsStabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pet.Deleted || !pet.IsControlledBy(m))
|
||||
{
|
||||
m.AllFollowers.RemoveAt(count);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pet == m.Mount || pet.Stable(false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
pet.MoveToWorld(m.Location, m.Map);
|
||||
pet.ControlTarget = m;
|
||||
pet.ControlOrder = OrderType.Follow;
|
||||
}
|
||||
|
||||
m.Followers = m.AllFollowers.OfType<BaseCreature>()
|
||||
.Where(p => !p.IsStabled && p.Map == m.Map)
|
||||
.Aggregate(0, (c, p) => c + p.ControlSlots);
|
||||
|
||||
m.Followers = Math.Max(0, m.Followers);
|
||||
|
||||
m.Delta(MobileDelta.Followers);
|
||||
}
|
||||
|
||||
public static void FixEquip(PlayerMobile m)
|
||||
{
|
||||
m.ValidateEquipment();
|
||||
}
|
||||
|
||||
public static void FixGumps(Mobile m)
|
||||
{
|
||||
if (!m.IsOnline())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var gumps = m.NetState.Gumps.ToList();
|
||||
|
||||
foreach (var gump in gumps)
|
||||
{
|
||||
if (gump is SuperGump)
|
||||
{
|
||||
((SuperGump)gump).Refresh(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m.NetState.Send(new CloseGump(gump.TypeID, 0));
|
||||
m.NetState.RemoveGump(gump);
|
||||
|
||||
gump.OnServerClose(m.NetState);
|
||||
|
||||
m.SendGump(gump);
|
||||
}
|
||||
}
|
||||
|
||||
gumps.Free(true);
|
||||
}
|
||||
|
||||
public static void FixTags(Mobile m)
|
||||
{
|
||||
m.Items.ForEach(
|
||||
item =>
|
||||
{
|
||||
if (item != null && !item.Deleted)
|
||||
{
|
||||
item.InvalidateProperties();
|
||||
}
|
||||
});
|
||||
|
||||
if (m.Backpack != null)
|
||||
{
|
||||
m.Backpack.InvalidateProperties();
|
||||
var list = m.Backpack.FindItemsByType<Item>(true);
|
||||
|
||||
list.ForEach(
|
||||
item =>
|
||||
{
|
||||
if (item != null && !item.Deleted)
|
||||
{
|
||||
item.InvalidateProperties();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
m.InvalidateProperties();
|
||||
}
|
||||
|
||||
public static void FixSkills(Mobile m)
|
||||
{
|
||||
if (m.Skills == null)
|
||||
{
|
||||
m.Skills = new Skills(m);
|
||||
}
|
||||
|
||||
foreach (var skill in SkillInfo.Table.Select(si => m.Skills[si.SkillID]))
|
||||
{
|
||||
skill.Normalize();
|
||||
}
|
||||
}
|
||||
|
||||
public static void FixQuests(PlayerMobile m)
|
||||
{
|
||||
if (m.Quest == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (m.Quest.From == null)
|
||||
{
|
||||
m.Quest.From = m;
|
||||
}
|
||||
|
||||
if (m.Quest.Objectives == null || m.Quest.Objectives.Count == 0 || m.Quest.Conversations == null ||
|
||||
m.Quest.Conversations.Count == 0)
|
||||
{
|
||||
m.Quest.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class FixMeGump : ListGump<FixMeFlags>
|
||||
{
|
||||
private static readonly FixMeFlags[] _FixMeFlags = default(FixMeFlags)
|
||||
.GetValues<FixMeFlags>()
|
||||
.Not(f => f == FixMeFlags.All || f == FixMeFlags.None)
|
||||
.ToArray();
|
||||
|
||||
public FixMeGump(Mobile user, Gump parent = null)
|
||||
: base(user, parent, title: "Fix Me!", emptyText: "There are no operations to display.")
|
||||
{
|
||||
Modal = true;
|
||||
CanMove = false;
|
||||
CanResize = false;
|
||||
BlockSpeech = true;
|
||||
BlockMovement = true;
|
||||
}
|
||||
|
||||
protected override void CompileList(List<FixMeFlags> list)
|
||||
{
|
||||
list.Clear();
|
||||
list.AddRange(_FixMeFlags.Not(f => FixMeCommand.DisabledFlags.HasFlag(f)));
|
||||
|
||||
base.CompileList(list);
|
||||
}
|
||||
|
||||
protected override void SelectEntry(GumpButton button, FixMeFlags entry)
|
||||
{
|
||||
base.SelectEntry(button, entry);
|
||||
|
||||
var html = new StringBuilder();
|
||||
|
||||
html.AppendFormat("This operation will fix your {0}.", entry.ToString().ToLower());
|
||||
html.AppendLine();
|
||||
html.Append(entry.GetDescription());
|
||||
html.AppendLine();
|
||||
html.AppendLine("Do you want to continue?");
|
||||
|
||||
Send(
|
||||
new ConfirmDialogGump(
|
||||
User,
|
||||
Refresh(),
|
||||
title: "Confirm Operation",
|
||||
html: html.ToString(),
|
||||
onAccept: b =>
|
||||
{
|
||||
User.FixMe(entry);
|
||||
Refresh(true);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
117
Scripts/SubSystem/VitaNex/Core/Commands/GC.cs
Normal file
117
Scripts/SubSystem/VitaNex/Core/Commands/GC.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;
|
||||
using System.Diagnostics;
|
||||
|
||||
using Server;
|
||||
using Server.Network;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Commands
|
||||
{
|
||||
/// <summary>
|
||||
/// Force full Garbage Collection cycle on all generations.
|
||||
/// </summary>
|
||||
public static class GCCommand
|
||||
{
|
||||
private static bool _Initialized;
|
||||
private static bool _Optimizing;
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (_Initialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_Initialized = true;
|
||||
|
||||
CommandUtility.Register(
|
||||
"GC",
|
||||
AccessLevel.Administrator,
|
||||
e =>
|
||||
{
|
||||
var message = true;
|
||||
|
||||
if (e.Arguments != null && e.Arguments.Length > 0)
|
||||
{
|
||||
message = e.GetBoolean(0);
|
||||
}
|
||||
|
||||
Optimize(e.Mobile, message);
|
||||
});
|
||||
|
||||
CommandUtility.RegisterAlias("GC", "Optimize");
|
||||
}
|
||||
|
||||
public static void Optimize(bool message)
|
||||
{
|
||||
Optimize(null, message);
|
||||
}
|
||||
|
||||
public static void Optimize(Mobile m, bool message)
|
||||
{
|
||||
if (World.Saving || World.Loading || _Optimizing)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
NetState.FlushAll();
|
||||
NetState.Pause();
|
||||
|
||||
_Optimizing = true;
|
||||
|
||||
var now = DateTime.UtcNow;
|
||||
|
||||
if (message)
|
||||
{
|
||||
World.Broadcast(0x35, true, "[{0}]: The world is optimizing, please wait.", now.ToShortTimeString());
|
||||
}
|
||||
|
||||
var watch = new Stopwatch();
|
||||
|
||||
watch.Start();
|
||||
|
||||
double mem = GC.GetTotalMemory(false);
|
||||
|
||||
GC.Collect();
|
||||
|
||||
mem -= GC.GetTotalMemory(false);
|
||||
mem = (mem / 1024.0) / 1024.0;
|
||||
|
||||
watch.Stop();
|
||||
_Optimizing = false;
|
||||
|
||||
if (m != null)
|
||||
{
|
||||
m.SendMessage("[{0}]: GC done in {1:F2} seconds.", now.ToShortTimeString(), watch.Elapsed.TotalSeconds);
|
||||
m.SendMessage("[{0}]: GC reports {1:#,0.00} MB freed memory.", now.ToShortTimeString(), mem);
|
||||
}
|
||||
|
||||
Console.WriteLine("[{0}]: GC done in {1:F2} seconds.", now.ToShortTimeString(), watch.Elapsed.TotalSeconds);
|
||||
Console.WriteLine("[{0}]: GC reports {1:#,0.00} MB freed memory.", now.ToShortTimeString(), mem);
|
||||
|
||||
if (message)
|
||||
{
|
||||
World.Broadcast(
|
||||
0x35,
|
||||
true,
|
||||
"[{0}]: World optimization complete. The entire process took {1:F1} seconds.",
|
||||
DateTime.UtcNow.ToShortTimeString(),
|
||||
watch.Elapsed.TotalSeconds);
|
||||
}
|
||||
|
||||
NetState.Resume();
|
||||
}
|
||||
}
|
||||
}
|
||||
132
Scripts/SubSystem/VitaNex/Core/Commands/MyCommands.cs
Normal file
132
Scripts/SubSystem/VitaNex/Core/Commands/MyCommands.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
#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.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
using Server;
|
||||
using Server.Commands;
|
||||
using Server.Gumps;
|
||||
|
||||
using VitaNex.SuperGumps.UI;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Commands
|
||||
{
|
||||
public static class MyCommandsCommand
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandSystem.Register("MyCommands", AccessLevel.Player, e => new MyCommandsGump(e.Mobile).Send());
|
||||
}
|
||||
}
|
||||
|
||||
public class MyCommandsGump : ListGump<CommandEntry>
|
||||
{
|
||||
public MyCommandsGump(Mobile user, Gump parent = null)
|
||||
: base(user, parent, title: "My Commands", emptyText: "No commands to display.")
|
||||
{
|
||||
Sorted = true;
|
||||
Modal = false;
|
||||
CanMove = false;
|
||||
CanResize = false;
|
||||
}
|
||||
|
||||
public override string GetSearchKeyFor(CommandEntry key)
|
||||
{
|
||||
return key != null ? key.Command : base.GetSearchKeyFor(null);
|
||||
}
|
||||
|
||||
public override int SortCompare(CommandEntry a, CommandEntry b)
|
||||
{
|
||||
var res = 0;
|
||||
|
||||
if (a.CompareNull(b, ref res))
|
||||
{
|
||||
return res;
|
||||
}
|
||||
|
||||
if (a.AccessLevel > b.AccessLevel)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (a.AccessLevel < b.AccessLevel)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return String.Compare(a.Command, b.Command, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
protected override void CompileList(List<CommandEntry> list)
|
||||
{
|
||||
list.Clear();
|
||||
|
||||
var commands = CommandUtility.EnumerateCommands(User.AccessLevel);
|
||||
|
||||
commands = commands.Where(c => !Insensitive.Equals(c.Command, "MyCommands"));
|
||||
|
||||
list.AddRange(commands);
|
||||
|
||||
base.CompileList(list);
|
||||
}
|
||||
|
||||
protected override void SelectEntry(GumpButton button, CommandEntry entry)
|
||||
{
|
||||
base.SelectEntry(button, entry);
|
||||
|
||||
User.SendMessage(0x55, "Using Command: {0}", entry.Command);
|
||||
CommandSystem.Handle(User, String.Format("{0}{1}", CommandSystem.Prefix, entry.Command));
|
||||
Refresh();
|
||||
}
|
||||
|
||||
protected override string GetLabelText(int index, int pageIndex, CommandEntry entry)
|
||||
{
|
||||
return entry != null && !String.IsNullOrWhiteSpace(entry.Command)
|
||||
? entry.Command[0].ToString(CultureInfo.InvariantCulture).ToUpper() + entry.Command.Substring(1)
|
||||
: base.GetLabelText(index, pageIndex, entry);
|
||||
}
|
||||
|
||||
protected override int GetLabelHue(int index, int pageIndex, CommandEntry entry)
|
||||
{
|
||||
if (entry == null)
|
||||
{
|
||||
return base.GetLabelHue(index, pageIndex, null);
|
||||
}
|
||||
|
||||
if (entry.AccessLevel >= AccessLevel.Administrator)
|
||||
{
|
||||
return 0x516;
|
||||
}
|
||||
|
||||
if (entry.AccessLevel > AccessLevel.GameMaster)
|
||||
{
|
||||
return 0x144;
|
||||
}
|
||||
|
||||
if (entry.AccessLevel > AccessLevel.Counselor)
|
||||
{
|
||||
return 0x21;
|
||||
}
|
||||
|
||||
if (entry.AccessLevel > AccessLevel.Player)
|
||||
{
|
||||
return 0x30;
|
||||
}
|
||||
|
||||
return TextHue;
|
||||
}
|
||||
}
|
||||
}
|
||||
723
Scripts/SubSystem/VitaNex/Core/Commands/PlayerBackup.cs
Normal file
723
Scripts/SubSystem/VitaNex/Core/Commands/PlayerBackup.cs
Normal file
@@ -0,0 +1,723 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#if ServUO58
|
||||
#define ServUOX
|
||||
#endif
|
||||
|
||||
#region References
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Server;
|
||||
using Server.Accounting;
|
||||
using Server.Commands;
|
||||
using Server.Items;
|
||||
using Server.Misc;
|
||||
using Server.Mobiles;
|
||||
|
||||
using VitaNex.IO;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Commands
|
||||
{
|
||||
public static class PlayerBackup
|
||||
{
|
||||
public static void Configure()
|
||||
{
|
||||
EventSink.DeleteRequest += HandleDeleteRequest;
|
||||
}
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
CommandUtility.Register("BackupState", AccessLevel.Administrator, OnBackupCommand);
|
||||
CommandUtility.Register("RestoreState", AccessLevel.Administrator, OnRestoreCommand);
|
||||
}
|
||||
|
||||
private static void HandleDeleteRequest(DeleteRequestEventArgs e)
|
||||
{
|
||||
var state = e.State;
|
||||
var index = e.Index;
|
||||
|
||||
var acct = state.Account as Account;
|
||||
|
||||
if (acct == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var m = acct[index] as PlayerMobile;
|
||||
|
||||
if (m != null && !m.Deleted && m.GameTime.TotalHours >= 24)
|
||||
{
|
||||
try
|
||||
{
|
||||
BackupState(m, true);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
[Usage("BackupState [DisableLogs=false]"), Description("Writes a binary data file containing information for a character's Bank, Pack and Equipment.")]
|
||||
public static void OnBackupCommand(CommandEventArgs e)
|
||||
{
|
||||
if (e.Mobile == null || e.Mobile.Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
e.Mobile.SendMessage("Target a PlayerMobile to backup...");
|
||||
e.Mobile.BeginTarget<PlayerMobile>((m, t) =>
|
||||
{
|
||||
BackupState(t, !e.GetBoolean(0), out var count, out var fails);
|
||||
|
||||
if (fails > 0)
|
||||
{
|
||||
e.Mobile.SendMessage("Backup: {0:#,0} / {1:#,0} saved item states.", count - fails, count);
|
||||
}
|
||||
else
|
||||
{
|
||||
e.Mobile.SendMessage("Backup: {0:#,0} saved item states.", count);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
[Usage("RestoreState <Serial=-1, MoveExisting=false, Logging=true>"), Description("Reads a binary data file containing information for a character's Bank, Pack and Equipment.")]
|
||||
public static void OnRestoreCommand(CommandEventArgs e)
|
||||
{
|
||||
if (e.Mobile == null || e.Mobile.Deleted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var serial = Serial.MinusOne;
|
||||
|
||||
var moveExisting = false;
|
||||
var logging = true;
|
||||
|
||||
if (e.Arguments.Length > 0)
|
||||
{
|
||||
#if ServUOX
|
||||
serial = e.GetSerial(0);
|
||||
#else
|
||||
serial = e.GetInt32(0);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (e.Arguments.Length > 1)
|
||||
{
|
||||
moveExisting = e.GetBoolean(1);
|
||||
}
|
||||
|
||||
if (e.Arguments.Length > 2)
|
||||
{
|
||||
logging = e.GetBoolean(2);
|
||||
}
|
||||
|
||||
e.Mobile.SendMessage("Target a PlayerMobile to restore...");
|
||||
e.Mobile.BeginTarget<PlayerMobile>((m, t) =>
|
||||
{
|
||||
|
||||
RestoreState(t, serial, moveExisting, logging, out var created, out var deleted, out var ignored, out var moved);
|
||||
|
||||
e.Mobile.SendMessage("Restore: {0:#,0} created, {1:#,0} deleted, {2:#,0} ignored, and {3:#,0} moved item states.", created, deleted, ignored, moved);
|
||||
}, null);
|
||||
}
|
||||
|
||||
public static void BackupState(PlayerMobile m, bool logging)
|
||||
{
|
||||
|
||||
BackupState(m, logging, out var count, out var fails);
|
||||
}
|
||||
|
||||
public static void BackupState(PlayerMobile m, bool logging, out int count, out int fails)
|
||||
{
|
||||
var root = VitaNexCore.DataDirectory + "/PlayerBackup/" + m.Account.Username + "/" + m.Serial;
|
||||
|
||||
var idxFile = IOUtility.EnsureFile(root + ".idx", true);
|
||||
var binFile = IOUtility.EnsureFile(root + ".bin", true);
|
||||
|
||||
var logFile = logging ? IOUtility.EnsureFile(root + ".log") : null;
|
||||
var log = logging ? new StringBuilder() : null;
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine();
|
||||
log.AppendLine(new string('*', 10));
|
||||
log.AppendLine();
|
||||
log.AppendLine("BACKUP:\tDate[{0}]\tMobile[{1}]", DateTime.UtcNow, m);
|
||||
log.AppendLine();
|
||||
}
|
||||
|
||||
var idxLength = 0L;
|
||||
var idxCount = 0;
|
||||
var idxFails = 0;
|
||||
|
||||
idxFile.Serialize(idx =>
|
||||
{
|
||||
var v = idx.SetVersion(1);
|
||||
|
||||
idx.Write(m.Serial.Value);
|
||||
|
||||
if (v > 0)
|
||||
{
|
||||
WriteLength(idx, false, idxLength, idxCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
idx.Write(idxLength);
|
||||
idx.Write(idxCount);
|
||||
}
|
||||
|
||||
binFile.Serialize(bin =>
|
||||
{
|
||||
bin.SetVersion(0);
|
||||
|
||||
var items = m.FindItemsByType<Item>(true, i => i != null && !i.Deleted);
|
||||
|
||||
foreach (var item in items)
|
||||
{
|
||||
#if NEWPARENT
|
||||
var parent = item.Parent != null ? item.Parent.Serial : Serial.MinusOne;
|
||||
var logParent = item.Parent ?? (object)Serial.MinusOne;
|
||||
#else
|
||||
var parent = item.ParentEntity != null ? item.ParentEntity.Serial : Serial.MinusOne;
|
||||
var logParent = item.ParentEntity ?? (object)Serial.MinusOne;
|
||||
#endif
|
||||
var pos = bin.Position;
|
||||
|
||||
Exception x = null;
|
||||
string status;
|
||||
|
||||
try
|
||||
{
|
||||
item.Serialize(bin);
|
||||
|
||||
status = "SAVED";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
++idxFails;
|
||||
x = e;
|
||||
|
||||
status = "ERROR";
|
||||
}
|
||||
|
||||
var len = bin.Position - pos;
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("WRITE:\tIndex[{0}]\t\tLength[{1}]\tStatus[{2}]\tItem[{3}]\t\t\tParent[{4}]", pos, len, status, item, logParent);
|
||||
|
||||
if (x != null)
|
||||
{
|
||||
log.AppendLine();
|
||||
log.AppendLine(new string('*', 10));
|
||||
log.AppendLine(x.ToString());
|
||||
log.AppendLine(new string('*', 10));
|
||||
log.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
WriteIndex(idx, item.GetType(), item.Serial, parent, pos, len);
|
||||
|
||||
idxLength += len;
|
||||
++idxCount;
|
||||
}
|
||||
});
|
||||
|
||||
WriteLength(idx, true, idxLength, idxCount);
|
||||
});
|
||||
|
||||
count = idxCount;
|
||||
fails = idxFails;
|
||||
|
||||
if (log == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
log.AppendLine();
|
||||
log.AppendLine("RESULT:\tCount[{0}]\tFails[{1}]\tLength[{2}]", count - fails, fails, idxLength);
|
||||
log.AppendLine();
|
||||
logFile.AppendText(false, log.ToString());
|
||||
}
|
||||
|
||||
public static void RestoreState(PlayerMobile m, Serial serial, bool moveExisting, bool logging)
|
||||
{
|
||||
RestoreState(m, serial, moveExisting, logging, out var created, out var deleted, out var ignored, out var moved);
|
||||
}
|
||||
|
||||
public static void RestoreState(PlayerMobile m, Serial serial, bool moveExisting, bool logging, out int created, out int deleted, out int ignored, out int moved)
|
||||
{
|
||||
var pack = m.Backpack;
|
||||
|
||||
if (pack == null || pack.Deleted)
|
||||
{
|
||||
m.AddItem(pack = new Backpack
|
||||
{
|
||||
Movable = false
|
||||
});
|
||||
}
|
||||
|
||||
var bank = m.BankBox;
|
||||
|
||||
if (bank == null || bank.Deleted)
|
||||
{
|
||||
m.AddItem(bank = new BankBox(m)
|
||||
{
|
||||
Movable = false
|
||||
});
|
||||
}
|
||||
|
||||
if (serial == Serial.MinusOne)
|
||||
{
|
||||
serial = m.Serial;
|
||||
}
|
||||
|
||||
var root = VitaNexCore.DataDirectory + "/PlayerBackup/" + m.Account.Username + "/" + serial;
|
||||
|
||||
var idxFile = IOUtility.EnsureFile(root + ".idx");
|
||||
var binFile = IOUtility.EnsureFile(root + ".bin");
|
||||
|
||||
var logFile = logging ? IOUtility.EnsureFile(root + ".log") : null;
|
||||
var log = logging ? new StringBuilder() : null;
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine();
|
||||
log.AppendLine(new string('*', 10));
|
||||
log.AppendLine();
|
||||
log.AppendLine("RESTORE:\tDate[{0}]\tMobile[{1}]", DateTime.UtcNow, m);
|
||||
log.AppendLine();
|
||||
}
|
||||
|
||||
int idxCreated = 0, idxDeleted = 0, idxIgnored = 0, idxMoved = 0;
|
||||
|
||||
idxFile.Deserialize(idx =>
|
||||
{
|
||||
var v = idx.GetVersion();
|
||||
|
||||
int ser;
|
||||
|
||||
if (v > 0)
|
||||
{
|
||||
ser = idx.ReadInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
ser = serial.Value;
|
||||
}
|
||||
|
||||
if (ser != serial.Value)
|
||||
{
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("INVALID:\tSerial[{0:X8}]", ser);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
long idxLength;
|
||||
int idxCount;
|
||||
|
||||
if (v > 0)
|
||||
{
|
||||
ReadLength(idx, false, out idxLength, out idxCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
idxLength = idx.ReadLong();
|
||||
idxCount = idx.ReadInt();
|
||||
}
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("INDEX:\tCount[{0}]\tLength[{1}]", idxCount, idxLength);
|
||||
}
|
||||
|
||||
var items = new Tuple<Item, Serial, long, long, string>[idxCount];
|
||||
|
||||
binFile.Deserialize(bin =>
|
||||
{
|
||||
bin.GetVersion();
|
||||
|
||||
var restored = new Dictionary<Item, Serial>();
|
||||
|
||||
Backpack oldPack = null;
|
||||
BankBox oldBank = null;
|
||||
|
||||
for (var i = 0; i < idxCount; i++)
|
||||
{
|
||||
|
||||
ReadIndex(idx, out var type, out var s, out var parent, out var binIndex, out var binLength);
|
||||
|
||||
var valid = s.IsValid && s.IsItem;
|
||||
var exists = World.Items.ContainsKey(s);
|
||||
|
||||
Item item = null;
|
||||
|
||||
if (exists)
|
||||
{
|
||||
item = World.Items[s];
|
||||
|
||||
if (item == null || item.Deleted)
|
||||
{
|
||||
World.Items.Remove(s);
|
||||
exists = false;
|
||||
}
|
||||
}
|
||||
|
||||
object logItem;
|
||||
string status;
|
||||
|
||||
if (!exists && valid && type.IsEqualOrChildOf<Item>())
|
||||
{
|
||||
item = type.CreateInstanceSafe<Item>(s);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
++idxIgnored;
|
||||
|
||||
logItem = s;
|
||||
status = "NULL";
|
||||
}
|
||||
else if (item.Deleted)
|
||||
{
|
||||
++idxDeleted;
|
||||
|
||||
item = null;
|
||||
logItem = s;
|
||||
status = "DELETED";
|
||||
}
|
||||
else
|
||||
{
|
||||
++idxCreated;
|
||||
|
||||
World.AddItem(item);
|
||||
|
||||
logItem = item;
|
||||
status = "CREATED";
|
||||
}
|
||||
}
|
||||
else if (exists && valid && moveExisting && item.RootParent != m)
|
||||
{
|
||||
++idxMoved;
|
||||
|
||||
logItem = item;
|
||||
status = "MOVE";
|
||||
}
|
||||
else
|
||||
{
|
||||
++idxIgnored;
|
||||
|
||||
item = null;
|
||||
logItem = s;
|
||||
status = exists ? "EXISTS" : "INVALID";
|
||||
}
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("DATA:\tIndex[{0}]\t\tLength[{1}]\tStatus[{2}]\tItem[{3}]\t\t\tParent[{4}]", binIndex, binLength, status, logItem, parent);
|
||||
}
|
||||
|
||||
items[i] = Tuple.Create(item, parent, binIndex, binLength, status);
|
||||
}
|
||||
|
||||
foreach (var t in items)
|
||||
{
|
||||
var item = t.Item1;
|
||||
var parent = t.Item2;
|
||||
var index = t.Item3;
|
||||
var length = t.Item4;
|
||||
var status = t.Item5;
|
||||
|
||||
bin.Seek(index, SeekOrigin.Begin);
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
bin.Seek(index + length, SeekOrigin.Begin);
|
||||
continue;
|
||||
}
|
||||
|
||||
Exception x = null;
|
||||
|
||||
if (status == "MOVE")
|
||||
{
|
||||
bin.Seek(index + length, SeekOrigin.Begin);
|
||||
|
||||
status = "IGNORED";
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
item.Deserialize(bin);
|
||||
|
||||
status = "LOADED";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
--idxCreated;
|
||||
++idxDeleted;
|
||||
|
||||
item.Delete();
|
||||
x = e;
|
||||
|
||||
status = "ERROR";
|
||||
}
|
||||
}
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("READ:\tIndex[{0}]\tLength[{1}]\tStatus[{2}]\tItem[{3}]\t\t\tParent[{4}]", index, length, status, item, parent);
|
||||
|
||||
if (x != null)
|
||||
{
|
||||
log.AppendLine();
|
||||
log.AppendLine(new string('*', 10));
|
||||
log.AppendLine(x.ToString());
|
||||
log.AppendLine(new string('*', 10));
|
||||
log.AppendLine();
|
||||
}
|
||||
}
|
||||
|
||||
if (parent == m.Serial)
|
||||
{
|
||||
if (item is BankBox)
|
||||
{
|
||||
oldBank = (BankBox)item;
|
||||
}
|
||||
else if (item is Backpack)
|
||||
{
|
||||
oldPack = (Backpack)item;
|
||||
}
|
||||
}
|
||||
|
||||
restored.Add(item, parent);
|
||||
}
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine();
|
||||
}
|
||||
|
||||
Point3D p;
|
||||
|
||||
foreach (var kv in restored.Where(kv => !kv.Key.Deleted).OrderBy(kv => kv.Value))
|
||||
{
|
||||
var item = kv.Key;
|
||||
|
||||
if ((item == oldPack || item == oldBank) && item != pack && item != bank)
|
||||
{
|
||||
if (item.Parent is Item)
|
||||
{
|
||||
((Item)item.Parent).RemoveItem(item);
|
||||
}
|
||||
else if (item.Parent is Mobile)
|
||||
{
|
||||
((Mobile)item.Parent).RemoveItem(item);
|
||||
}
|
||||
|
||||
item.Parent = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
var parent = World.FindEntity(kv.Value);
|
||||
|
||||
if (item != pack && item != bank && (item.Parent == oldPack || item.Parent == oldBank))
|
||||
{
|
||||
((Item)item.Parent).RemoveItem(item);
|
||||
}
|
||||
|
||||
if (parent != null)
|
||||
{
|
||||
if (item == pack || item == bank)
|
||||
{
|
||||
m.AddItem(item);
|
||||
}
|
||||
else if (parent == pack || parent == oldPack)
|
||||
{
|
||||
p = item.Location;
|
||||
pack.DropItem(item);
|
||||
item.Location = p;
|
||||
}
|
||||
else if (parent == bank || parent == oldBank)
|
||||
{
|
||||
p = item.Location;
|
||||
bank.DropItem(item);
|
||||
item.Location = p;
|
||||
}
|
||||
else if (parent is Container)
|
||||
{
|
||||
if (parent.Deleted)
|
||||
{
|
||||
bank.DropItem(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
p = item.Location;
|
||||
((Container)parent).DropItem(item);
|
||||
item.Location = p;
|
||||
}
|
||||
}
|
||||
else if (parent is Mobile)
|
||||
{
|
||||
if (!m.EquipItem(item))
|
||||
{
|
||||
pack.DropItem(item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bank.DropItem(item);
|
||||
}
|
||||
|
||||
item.SetLastMoved();
|
||||
item.UpdateTotals();
|
||||
item.Delta(ItemDelta.Update);
|
||||
}
|
||||
else if (Cleanup.IsBuggable(item))
|
||||
{
|
||||
--idxCreated;
|
||||
++idxDeleted;
|
||||
|
||||
item.Delete();
|
||||
}
|
||||
else
|
||||
{
|
||||
item.Internalize();
|
||||
}
|
||||
}
|
||||
|
||||
if (oldPack != null && oldPack != pack && !restored.ContainsKey(oldPack))
|
||||
{
|
||||
oldPack.Delete();
|
||||
}
|
||||
|
||||
if (oldBank != null && oldBank != bank && !restored.ContainsKey(oldBank))
|
||||
{
|
||||
oldBank.Delete();
|
||||
}
|
||||
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine();
|
||||
}
|
||||
|
||||
foreach (var kv in restored)
|
||||
{
|
||||
if (kv.Key.Deleted)
|
||||
{
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("DELETED:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
else if (kv.Key.RootParent == m && kv.Key.Map == Map.Internal && kv.Key.Location == Point3D.Zero)
|
||||
{
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("INTERNAL:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
else if (kv.Key.RootParent != m)
|
||||
{
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("IGNORED:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Value);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (log != null)
|
||||
{
|
||||
log.AppendLine("RESTORED:\tItem[{0}]\t\tParent[{1}]", kv.Key, kv.Key.Parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
restored.Clear();
|
||||
|
||||
m.SendEverything();
|
||||
});
|
||||
});
|
||||
|
||||
created = idxCreated;
|
||||
deleted = idxDeleted;
|
||||
ignored = idxIgnored;
|
||||
moved = idxMoved;
|
||||
|
||||
if (log == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
log.AppendLine();
|
||||
log.AppendLine("RESULT:\tCreated[{0}]\t\tDeleted[{1}]\t\tIgnored[{2}]\t\tMoved[{3}]", created, deleted, ignored, moved);
|
||||
|
||||
logFile.AppendText(false, log.ToString());
|
||||
}
|
||||
|
||||
private static void WriteLength(GenericWriter idx, bool reset, long length, int count)
|
||||
{
|
||||
var index = idx.Seek(0, SeekOrigin.Current);
|
||||
|
||||
idx.Seek(8, SeekOrigin.Begin);
|
||||
|
||||
idx.Write(length);
|
||||
idx.Write(count);
|
||||
|
||||
if (reset)
|
||||
{
|
||||
idx.Seek(index, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ReadLength(GenericReader idx, bool reset, out long length, out int count)
|
||||
{
|
||||
var index = idx.Seek(0, SeekOrigin.Current);
|
||||
|
||||
idx.Seek(8, SeekOrigin.Begin);
|
||||
|
||||
length = idx.ReadLong();
|
||||
count = idx.ReadInt();
|
||||
|
||||
if (reset)
|
||||
{
|
||||
idx.Seek(index, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteIndex(GenericWriter idx, Type type, Serial serial, Serial parent, long index, long length)
|
||||
{
|
||||
idx.WriteType(type);
|
||||
idx.Write(serial);
|
||||
idx.Write(parent);
|
||||
idx.Write(index);
|
||||
idx.Write(length);
|
||||
}
|
||||
|
||||
private static void ReadIndex(GenericReader idx, out Type type, out Serial serial, out Serial parent, out long index, out long length)
|
||||
{
|
||||
type = idx.ReadType();
|
||||
serial = idx.ReadSerial();
|
||||
parent = idx.ReadSerial();
|
||||
index = idx.ReadLong();
|
||||
length = idx.ReadLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
127
Scripts/SubSystem/VitaNex/Core/Commands/Say.cs
Normal file
127
Scripts/SubSystem/VitaNex/Core/Commands/Say.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
#region Header
|
||||
// _,-'/-'/
|
||||
// . __,-; ,'( '/
|
||||
// \. `-.__`-._`:_,-._ _ , . ``
|
||||
// `:-._,------' ` _,`--` -: `_ , ` ,' :
|
||||
// `---..__,,--' (C) 2023 ` -'. -'
|
||||
// # Vita-Nex [http://core.vita-nex.com] #
|
||||
// {o)xxx|===============- # -===============|xxx(o}
|
||||
// # #
|
||||
#endregion
|
||||
|
||||
#region References
|
||||
using System;
|
||||
|
||||
using Server;
|
||||
using Server.Commands;
|
||||
using Server.Commands.Generic;
|
||||
using Server.Items;
|
||||
using Server.Mobiles;
|
||||
using Server.Network;
|
||||
using Server.Targeting;
|
||||
|
||||
using VitaNex.Targets;
|
||||
#endregion
|
||||
|
||||
namespace VitaNex.Commands
|
||||
{
|
||||
public class SayCommand : BaseCommand
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
TargetCommands.Register(new SayCommand());
|
||||
}
|
||||
|
||||
public SayCommand()
|
||||
{
|
||||
AccessLevel = AccessLevel.GameMaster;
|
||||
Supports = CommandSupport.All;
|
||||
Commands = new[] { "Say" };
|
||||
ObjectTypes = ObjectTypes.All;
|
||||
Usage = "Say <speech>";
|
||||
Description = "Causes an object to say the given speech.";
|
||||
}
|
||||
|
||||
public override void Execute(CommandEventArgs e, object o)
|
||||
{
|
||||
HandleTarget(e.Mobile as PlayerMobile, o as IPoint3D, e.ArgString);
|
||||
}
|
||||
|
||||
public static void BeginTarget(PlayerMobile m, string speech)
|
||||
{
|
||||
if (m != null && !String.IsNullOrWhiteSpace(speech))
|
||||
{
|
||||
GenericSelectTarget<IPoint3D>.Begin(m, (user, target) => HandleTarget(m, target, speech), null);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HandleTarget(PlayerMobile m, IPoint3D target, string speech)
|
||||
{
|
||||
if (m == null || target == null || String.IsNullOrWhiteSpace(speech))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target is Item)
|
||||
{
|
||||
var item = (Item)target;
|
||||
|
||||
item.PublicOverheadMessage(MessageType.Regular, m.SpeechHue, false, speech);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target is Mobile)
|
||||
{
|
||||
var mobile = (Mobile)target;
|
||||
|
||||
mobile.Say(speech);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target is StaticTarget)
|
||||
{
|
||||
var t = (StaticTarget)target;
|
||||
|
||||
Send(m.Map, t.Location, t.ItemID, m.SpeechHue, t.Name, speech);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (target is LandTarget)
|
||||
{
|
||||
var t = (LandTarget)target;
|
||||
|
||||
Send(m.Map, t.Location, 0, m.SpeechHue, t.Name, speech);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void Send(Map map, Point3D loc, int itemID, int hue, string name, string speech)
|
||||
{
|
||||
var fx = EffectItem.Create(loc, map, EffectItem.DefaultDuration);
|
||||
|
||||
Packet p = null;
|
||||
|
||||
var eable = map.GetClientsInRange(loc, Core.GlobalMaxUpdateRange);
|
||||
|
||||
foreach (var state in eable)
|
||||
{
|
||||
if (p == null)
|
||||
{
|
||||
p = Packet.Acquire(new UnicodeMessage(fx.Serial, itemID, MessageType.Label, hue, 1, "ENU", name, speech));
|
||||
}
|
||||
|
||||
state.Send(p);
|
||||
}
|
||||
|
||||
Packet.Release(p);
|
||||
|
||||
eable.Free();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user