- ServUO Version
- Publish 57
- Ultima Expansion
- Endless Journey
So trying to convert the interior decorator to a move everything tool for GMs to use, I have this and it compiles but still won't let you move addons, houses or mobs, it will move items or chests etc.. I'm sure I am missing something so thought I would post it here fore someone else to look at
C#:
using Server.Gumps;
using Server.Multis;
using Server.Network;
using Server.Targeting;
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
namespace Server.Items
{
public enum AdvancedDecorateCommandStaff
{
None,
Turn,
Up,
Down,
Secure,
Lockdown,
Release,
GetHue,
North,
NorthEast,
East,
SouthEast,
South,
SouthWest,
West,
NorthWest,
}
public class AdvancedInteriorDecoratorStaff : Item
{
private static readonly List<Type> donotMove = new List<Type>
{
};
//public override int LabelNumber => 1041280; // an interior decorator
private AdvancedDecorateCommandStaff m_Command;
[Constructable]
public AdvancedInteriorDecoratorStaff()
: base(0xFC1)
{
Name = " An Advanced Staff Interior Decorator";
Weight = 1.0;
LootType = LootType.Blessed;
}
public AdvancedInteriorDecoratorStaff(Serial serial)
: base(serial)
{
}
[CommandProperty(AccessLevel.GameMaster)]
public AdvancedDecorateCommandStaff Command
{
get { return m_Command; }
set
{
m_Command = value;
InvalidateProperties();
}
}
public override void Serialize(GenericWriter writer)
{
base.Serialize(writer);
writer.Write(0); // version
}
public override void Deserialize(GenericReader reader)
{
base.Deserialize(reader);
int version = reader.ReadInt();
}
public override void OnDoubleClick(Mobile from)
{
if (from.FindGump(typeof(InternalGump)) == null)
from.SendGump(new InternalGump(from, this));
if (m_Command != AdvancedDecorateCommandStaff.None)
from.Target = new InternalTarget(this);
}
enum CardinalDirections
{
N = 8, // pre existing buttons end at 7
NE,
E,
SE,
S,
SW,
W,
NW
}
private class InternalGump : Gump
{
private readonly AdvancedInteriorDecoratorStaff m_Decorator;
public InternalGump(Mobile from, AdvancedInteriorDecoratorStaff decorator)
: base(150, 50)
{
m_Decorator = decorator;
AddBackground(0, 0, 370, 410, 2600);
AddPage(0);
AddButton(40, 36, (decorator.Command == AdvancedDecorateCommandStaff.Turn ? 2154 : 2152), 2154, 1, GumpButtonType.Reply, 0);
AddHtmlLocalized(80, 41, 100, 20, 1018323, false, false); // Turn
AddButton(40, 86, (decorator.Command == AdvancedDecorateCommandStaff.Up ? 2154 : 2152), 2154, 2, GumpButtonType.Reply, 0);
AddHtmlLocalized(80, 91, 100, 20, 1018324, false, false); // Up
AddButton(40, 136, (decorator.Command == AdvancedDecorateCommandStaff.Down ? 2154 : 2152), 2154, 3, GumpButtonType.Reply, 0);
AddHtmlLocalized(80, 141, 100, 20, 1018325, false, false); // Down
AddButton(40, 186, (decorator.Command == AdvancedDecorateCommandStaff.Secure ? 2154 : 2152), 2154, 5, GumpButtonType.Reply, 0);
AddLabel(80, 191, 0, "Secure");
AddButton(40, 236, (decorator.Command == AdvancedDecorateCommandStaff.Lockdown ? 2154 : 2152), 2154, 6, GumpButtonType.Reply, 0);
AddLabel(80, 241, 0, "Lockdown");
AddButton(40, 286, (decorator.Command == AdvancedDecorateCommandStaff.Release ? 2154 : 2152), 2154, 7, GumpButtonType.Reply, 0);
AddLabel(80, 291, 0, "Release");
AddButton(40, 336, (decorator.Command == AdvancedDecorateCommandStaff.GetHue ? 2154 : 2152), 2154, 4, GumpButtonType.Reply, 0);
AddHtmlLocalized(80, 341, 100, 20, 1158863, false, false); // Get Hue
int x = 140;
int y = 30;
//AddLabel( x + 50, y - 10, 0, "Nudge");
AddImage(x, y, 5010);
// adding the coordinates of the image to the placement of the buttons due to aligning buttons based on image placement of 0,0 in gumpstudio
AddButton(110 + x, 44 + y, 4501, 4501, (int)CardinalDirections.N, GumpButtonType.Reply, 0); // N
AddButton(121 + x, 75 + y, 4502, 4502, (int)CardinalDirections.NE, GumpButtonType.Reply, 0); // NE
AddButton(106 + x, 107 + y, 4503, 4503, (int)CardinalDirections.E, GumpButtonType.Reply, 0); // E
AddButton(76 + x, 121 + y, 4504, 4504, (int)CardinalDirections.SE, GumpButtonType.Reply, 0); // SE
AddButton(44 + x, 105 + y, 4505, 4505, (int)CardinalDirections.S, GumpButtonType.Reply, 0); // S
AddButton(32 + x, 75 + y, 4506, 4506, (int)CardinalDirections.SW, GumpButtonType.Reply, 0); // SW
AddButton(45 + x, 46 + y, 4507, 4507, (int)CardinalDirections.W, GumpButtonType.Reply, 0); // W
AddButton(76 + x, 29 + y, 4500, 4500, (int)CardinalDirections.NW, GumpButtonType.Reply, 0); // NW
AddHtmlLocalized(0, 0, 0, 0, 4, false, false);
}
public override void OnResponse(NetState sender, RelayInfo info)
{
AdvancedDecorateCommandStaff command = AdvancedDecorateCommandStaff.None;
Mobile m = sender.Mobile;
int cliloc = 0;
string c_String = null;
switch (info.ButtonID)
{
case 1:
cliloc = 1073404; // Select an object to turn.
command = AdvancedDecorateCommandStaff.Turn;
break;
case 2:
cliloc = 1073405; // Select an object to increase its height.
command = AdvancedDecorateCommandStaff.Up;
break;
case 3:
cliloc = 1073406; // Select an object to lower its height.
command = AdvancedDecorateCommandStaff.Down;
break;
case 4:
cliloc = 1158864; // Select an object to get the hue.
command = AdvancedDecorateCommandStaff.GetHue;
break;
case 5://secure
c_String = "Select an object to secure."; // Select an object to secure.
command = AdvancedDecorateCommandStaff.Secure;
break;
case 6://lockdown
c_String = "Select an object to lock down."; // Select an object to lock down.
command = AdvancedDecorateCommandStaff.Lockdown;
break;
case 7://release
c_String = "Select an object to release."; // Select an object to release.
command = AdvancedDecorateCommandStaff.Release;
break;
case (int)CardinalDirections.N:
c_String = "Select an object to move north."; // Select an object to move north.
command = AdvancedDecorateCommandStaff.North;
break;
case (int)CardinalDirections.NE:
c_String = "Select an object to move northeast."; // Select an object to move northeast.
command = AdvancedDecorateCommandStaff.NorthEast;
break;
case (int)CardinalDirections.E:
c_String = "Select an object to move east."; // Select an object to move east.
command = AdvancedDecorateCommandStaff.East;
break;
case (int)CardinalDirections.SE:
c_String = "Select an object to move southeast."; // Select an object to move southeast.
command = AdvancedDecorateCommandStaff.SouthEast;
break;
case (int)CardinalDirections.S:
c_String = "Select an object to move south."; // Select an object to move south.
command = AdvancedDecorateCommandStaff.South;
break;
case (int)CardinalDirections.SW:
c_String = "Select an object to move southwest."; // Select an object to move southwest.
command = AdvancedDecorateCommandStaff.SouthWest;
break;
case (int)CardinalDirections.W:
c_String = "Select an object to move west."; // Select an object to move west.
command = AdvancedDecorateCommandStaff.West;
break;
case (int)CardinalDirections.NW:
c_String = "Select an object to move northwest."; // Select an object to move northwest.
command = AdvancedDecorateCommandStaff.NorthWest;
break;
}
if (command != AdvancedDecorateCommandStaff.None)
{
m_Decorator.Command = command;
m.SendGump(new InternalGump(m, m_Decorator));
if (cliloc != 0)
m.SendLocalizedMessage(cliloc);
if (c_String != null)
m.SendMessage(c_String);
m.Target = new InternalTarget(m_Decorator);
}
else
{
Target.Cancel(m);
}
}
}
private class InternalTarget : Target
{
private readonly AdvancedInteriorDecoratorStaff m_Decorator;
public InternalTarget(AdvancedInteriorDecoratorStaff decorator)
: base(-1, false, TargetFlags.None)
{
CheckLOS = false;
m_Decorator = decorator;
}
protected override void OnTargetNotAccessible(Mobile from, object targeted)
{
OnTarget(from, targeted);
}
private static readonly Type[] _IsSpecialTypes = new Type[]
{
typeof(BirdLamp), typeof(DragonLantern), typeof(KoiLamp),
typeof(TallLamp)
};
private static bool IsSpecialTypes(Item item)
{
return _IsSpecialTypes.Any(t => t == item.GetType());
}
protected override void OnTarget(Mobile from, object targeted)
{
if (m_Decorator.Command == AdvancedDecorateCommandStaff.GetHue)
{
int hue = 0;
if (targeted is Item)
hue = ((Item)targeted).Hue;
else if (targeted is Mobile)
hue = ((Mobile)targeted).Hue;
else
{
from.Target = new InternalTarget(m_Decorator);
return;
}
from.SendLocalizedMessage(1158862, string.Format("{0}", hue)); // That object is hue ~1_HUE~
}
else if (targeted is Item/* && CheckUse(m_Decorator, from)*/)
{
Item item = (Item)targeted;
if (item is CellarStairs || item is CellarFloor || item is CellarWall)
{
from.SendMessage("You can't move that!");
return;
}
else if (item is AddonComponent addoncomponent)
{
if (donotMove.Contains(addoncomponent.Addon.GetType()))
{
from.SendMessage("You can't move that");
return;
}
}
else
{
switch (m_Decorator.Command)
{
case AdvancedDecorateCommandStaff.Up:
Up(item, from);
break;
case AdvancedDecorateCommandStaff.Down:
Down(item, from);
break;
case AdvancedDecorateCommandStaff.Turn:
Turn(item, from);
break;
case AdvancedDecorateCommandStaff.Secure:
Secure(item, from);
break;
case AdvancedDecorateCommandStaff.Lockdown:
Lockdown(item, from);
break;
case AdvancedDecorateCommandStaff.Release:
Release(item, from);
break;
case AdvancedDecorateCommandStaff.North:
North(item, from);
break;
case AdvancedDecorateCommandStaff.NorthEast:
NorthEast(item, from);
break;
case AdvancedDecorateCommandStaff.East:
East(item, from);
break;
case AdvancedDecorateCommandStaff.SouthEast:
SouthEast(item, from);
break;
case AdvancedDecorateCommandStaff.South:
South(item, from);
break;
case AdvancedDecorateCommandStaff.SouthWest:
SouthWest(item, from);
break;
case AdvancedDecorateCommandStaff.West:
West(item, from);
break;
case AdvancedDecorateCommandStaff.NorthWest:
NorthWest(item, from);
break;
}
}
}
from.Target = new InternalTarget(m_Decorator);
}
protected override void OnTargetCancel(Mobile from, TargetCancelType cancelType)
{
if (cancelType == TargetCancelType.Canceled)
from.CloseGump(typeof(InternalGump));
}
private static void Secure(Item item, Mobile from)
{
BaseHouse house = BaseHouse.FindHouseAt(from);
if (house.IsLockedDown(item))
from.SendMessage("That is already locked down.");
else if (house.IsSecure(item))
from.SendMessage("That is already secured.");
else if (house.IsFriend(from) && !house.IsCoOwner(from))
{
from.SendMessage("Only Owners and CoOwners are allowed to secure things in a house.");
return;
}
else
house.AddSecure(from, item);
}
private static void Lockdown(Item item, Mobile from)
{
BaseHouse house = BaseHouse.FindHouseAt(from);
if (house.IsLockedDown(item))
from.SendMessage("That is already locked down.");
else if (house.IsSecure(item))
from.SendMessage("That is already secured.");
else
house.LockDown(from, item, true);
}
private static void Release(Item item, Mobile from)
{
BaseHouse house = BaseHouse.FindHouseAt(from);
if (!house.IsLockedDown(item) && !house.IsSecure(item) && (item.Movable))
from.SendMessage("That is not locked down or secured.");
else
house.Release(from, item);
}
private static void Turn(Item item, Mobile from)
{
if (item is IFlipable)
{
((IFlipable)item).OnFlip(from);
return;
}
if (item is AddonComponent || item is AddonContainerComponent || item is BaseAddonContainer)
{
object addon = null;
if (item is AddonComponent)
addon = ((AddonComponent)item).Addon;
else if (item is AddonContainerComponent)
addon = ((AddonContainerComponent)item).Addon;
else if (item is BaseAddonContainer)
addon = (BaseAddonContainer)item;
if (addon != null)
{
FlipableAddonAttribute[] aAttributes = (FlipableAddonAttribute[])addon.GetType().GetCustomAttributes(typeof(FlipableAddonAttribute), false);
if (aAttributes.Length > 0)
{
aAttributes[0].Flip(from, (Item)addon);
return;
}
}
}
FlipableAttribute[] attributes = (FlipableAttribute[])item.GetType().GetCustomAttributes(typeof(FlipableAttribute), false);
if (attributes.Length > 0)
attributes[0].Flip(item);
else
from.SendLocalizedMessage(1042273); // You cannot turn that.
}
private static void North(Item item, Mobile from)
{
item.Y = (item.Y - 1);
}
private static void NorthEast(Item item, Mobile from)
{
item.Y = (item.Y - 1);
item.X = (item.X + 1);
}
private static void NorthWest(Item item, Mobile from)
{
item.Y = (item.Y - 1);
item.X = (item.X - 1);
}
private static void East(Item item, Mobile from)
{
item.X = (item.X + 1);
}
private static void South(Item item, Mobile from)
{
item.Y = (item.Y + 1);
}
private static void SouthEast(Item item, Mobile from)
{
item.Y = (item.Y + 1);
item.X = (item.X + 1);
}
private static void SouthWest(Item item, Mobile from)
{
item.Y = (item.Y + 1);
item.X = (item.X - 1);
}
private static void West(Item item, Mobile from)
{
item.X = (item.X - 1);
}
private static void Up(Item item, Mobile from)
{
item.Z = (item.Z + 1);
}
private static void Down(Item item, Mobile from)
{
item.Z = (item.Z - 1);
}
}
}
}
Last edited: