feat(spawners): Adds Respawn, EditSpawner, and SpawnProps commands (#532)
- [X] Adds `Respawn` command - [X] Adds `EditSpawner` command - Usage: `[global editspawner <type> <arguments> set <properties>` - This command replaces the arguments (optional) and properties of the affected spawners for that type - [X] Adds `SpawnProps` command - Usage: `[area spawnprops` - This command brings up a gump to modify targeted spawners based on the targeted entity. - To do this, the props/values are copied and then used to construct a properties list for the spawner entry. Closes #531
This commit is contained in:
parent
af021f748a
commit
0a435644eb
24 changed files with 708 additions and 377 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Server.Random;
|
||||
|
||||
namespace Server.Engines.Harvest
|
||||
|
|
@ -83,16 +84,16 @@ namespace Server.Engines.Harvest
|
|||
|
||||
public uint VeinWeights { get; private set; }
|
||||
|
||||
public Dictionary<Map, Dictionary<Point2D, HarvestBank>> Banks { get; }
|
||||
= new();
|
||||
public Dictionary<Map, Dictionary<Point2D, HarvestBank>> Banks { get; } = new();
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SendMessageTo(Mobile from, TextDefinition message)
|
||||
{
|
||||
if (message.Number > 0)
|
||||
if (message?.Number > 0)
|
||||
{
|
||||
from.SendLocalizedMessage(message.Number);
|
||||
}
|
||||
else
|
||||
else if (!string.IsNullOrWhiteSpace(message))
|
||||
{
|
||||
from.SendMessage(message);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ namespace Server.Engines.MLQuests
|
|||
{
|
||||
var name = $"MLQS-{GetType().Name}";
|
||||
|
||||
var toDelete = map.GetItemsInRange(loc, 0).Where(item => item is Spawner && item.Name == name);
|
||||
var toDelete = map.GetItemsInRange(loc, 0).Where(item => item is BaseSpawner && item.Name == name);
|
||||
|
||||
foreach (var item in toDelete)
|
||||
{
|
||||
|
|
|
|||
113
Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs
Normal file
113
Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: EditSpawnCommand.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Commands;
|
||||
using Server.Commands.Generic;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class EditSpawnCommand : BaseCommand
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
TargetCommands.Register(new EditSpawnCommand());
|
||||
}
|
||||
|
||||
public EditSpawnCommand()
|
||||
{
|
||||
AccessLevel = AccessLevel.GameMaster;
|
||||
Supports = CommandSupport.Complex | CommandSupport.Simple;
|
||||
Commands = new[] { "EditSpawner" };
|
||||
ObjectTypes = ObjectTypes.Items;
|
||||
Usage = "EditSpawner <type> <arguments> set <properties>";
|
||||
Description = "Modifies spawners arguments and properties for the given type";
|
||||
ListOptimized = true;
|
||||
}
|
||||
|
||||
public override void ExecuteList(CommandEventArgs e, List<object> list)
|
||||
{
|
||||
var args = e.Arguments;
|
||||
|
||||
if (args.Length <= 1)
|
||||
{
|
||||
LogFailure(Usage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (list.Count == 0)
|
||||
{
|
||||
LogFailure("No matching objects found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var name = args[0];
|
||||
|
||||
var type = AssemblyHandler.FindTypeByName(name);
|
||||
|
||||
if (!Add.IsEntity(type))
|
||||
{
|
||||
LogFailure("No type with that name was found.");
|
||||
return;
|
||||
}
|
||||
|
||||
var argSpan = e.ArgString.AsSpan(name.Length + 1);
|
||||
var setIndex = argSpan.InsensitiveIndexOf("set ");
|
||||
|
||||
ReadOnlySpan<char> props = null;
|
||||
|
||||
if (setIndex > -1)
|
||||
{
|
||||
var start = setIndex + 4;
|
||||
props = argSpan.Slice(start, argSpan.Length - start);
|
||||
argSpan = argSpan.SliceToLength(setIndex);
|
||||
}
|
||||
|
||||
var argStr = argSpan.ToString().DefaultIfNullOrEmpty(null);
|
||||
var propsStr = props.ToString().DefaultIfNullOrEmpty(null);
|
||||
|
||||
e.Mobile.SendMessage("Updating spawners...");
|
||||
|
||||
foreach (var obj in list)
|
||||
{
|
||||
if (obj is BaseSpawner spawner)
|
||||
{
|
||||
UpdateSpawner(spawner, name, argStr, propsStr);
|
||||
}
|
||||
}
|
||||
|
||||
e.Mobile.SendMessage("Update completed.");
|
||||
}
|
||||
|
||||
public static void UpdateSpawner(BaseSpawner spawner, string name, string arguments, string properties)
|
||||
{
|
||||
foreach (var entry in spawner.Entries)
|
||||
{
|
||||
// TODO: Should cache spawn type on the entry
|
||||
if (entry.SpawnedName.InsensitiveEquals(name))
|
||||
{
|
||||
if (arguments != null)
|
||||
{
|
||||
entry.Parameters = arguments;
|
||||
}
|
||||
|
||||
entry.Properties = properties;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
63
Projects/UOContent/Engines/Spawners/RespawnCommand.cs
Normal file
63
Projects/UOContent/Engines/Spawners/RespawnCommand.cs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: RespawnCommand.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Server.Commands.Generic;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class RespawnCommand : BaseCommand
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
TargetCommands.Register(new RespawnCommand());
|
||||
}
|
||||
|
||||
public RespawnCommand()
|
||||
{
|
||||
AccessLevel = AccessLevel.GameMaster;
|
||||
Supports = CommandSupport.Complex | CommandSupport.Simple;
|
||||
Commands = new[] { "Respawn" };
|
||||
ObjectTypes = ObjectTypes.Items;
|
||||
Usage = "Respawn";
|
||||
Description = "Respawns the given the spawners.";
|
||||
ListOptimized = true;
|
||||
}
|
||||
|
||||
public override void ExecuteList(CommandEventArgs e, List<object> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
LogFailure("No matching objects found.");
|
||||
return;
|
||||
}
|
||||
|
||||
e.Mobile.SendMessage("Respawning...");
|
||||
|
||||
NetState.FlushAll();
|
||||
|
||||
foreach (var obj in list)
|
||||
{
|
||||
if (obj is ISpawner spawner)
|
||||
{
|
||||
spawner.Respawn();
|
||||
}
|
||||
}
|
||||
|
||||
e.Mobile.SendMessage("Respawn completed.");
|
||||
}
|
||||
}
|
||||
}
|
||||
155
Projects/UOContent/Engines/Spawners/SpawnPropsGump.cs
Normal file
155
Projects/UOContent/Engines/Spawners/SpawnPropsGump.cs
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: GlobalPropsGump.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Server.Buffers;
|
||||
using Server.Commands.Generic;
|
||||
using Server.Engines.Spawners;
|
||||
using Server.Mobiles;
|
||||
using Server.Network;
|
||||
using CPA = Server.CommandPropertyAttribute;
|
||||
|
||||
namespace Server.Gumps
|
||||
{
|
||||
public class SpawnPropsGump : PropertiesGump
|
||||
{
|
||||
public static readonly HashSet<string> MobileAttributes = new()
|
||||
{
|
||||
nameof(Mobile.Hue),
|
||||
nameof(Mobile.Str),
|
||||
nameof(Mobile.Dex),
|
||||
nameof(Mobile.Int),
|
||||
nameof(BaseCreature.HitsMaxSeed),
|
||||
nameof(BaseCreature.Hits),
|
||||
nameof(BaseCreature.DamageMin),
|
||||
nameof(BaseCreature.DamageMax),
|
||||
nameof(BaseCreature.ActiveSpeed),
|
||||
nameof(BaseCreature.PassiveSpeed),
|
||||
nameof(BaseCreature.VirtualArmor)
|
||||
};
|
||||
|
||||
private List<object> _spawners;
|
||||
|
||||
public SpawnPropsGump(Mobile mobile, object o, List<object> spawners) : base(mobile, o)
|
||||
{
|
||||
_spawners = spawners;
|
||||
}
|
||||
|
||||
public SpawnPropsGump(Mobile mobile, object o, Stack<StackEntry> stack, StackEntry parent, List<object> spawners) : base(
|
||||
mobile, o, stack, parent
|
||||
)
|
||||
{
|
||||
_spawners = spawners;
|
||||
}
|
||||
|
||||
public SpawnPropsGump(Mobile mobile, object o, Stack<StackEntry> stack, List<object> list, int page, List<object> spawners) : base(
|
||||
mobile, o, stack, list, page
|
||||
)
|
||||
{
|
||||
_spawners = spawners;
|
||||
}
|
||||
|
||||
protected override int TotalHeight => base.TotalHeight + PropsConfig.ApplySize;
|
||||
|
||||
protected override void Initialize(int page)
|
||||
{
|
||||
base.Initialize(page);
|
||||
var totalHeight = TotalHeight - PropsConfig.ApplySize;
|
||||
|
||||
AddButton(BackWidth / 3, PropsConfig.BorderSize + totalHeight + PropsConfig.BorderSize, 5204, 5205, 3);
|
||||
}
|
||||
|
||||
public override void SendPropertiesGump() =>
|
||||
m_Mobile.SendGump(new SpawnPropsGump(m_Mobile, m_Object, m_Stack, m_List, m_Page, _spawners));
|
||||
|
||||
public static object GetPropValue(object src, string propName) =>
|
||||
src.GetType().GetProperty(propName)?.GetValue(src, null);
|
||||
|
||||
public override void OnResponse(NetState state, RelayInfo info)
|
||||
{
|
||||
var from = state.Mobile;
|
||||
|
||||
if (!BaseCommand.IsAccessible(from, m_Object))
|
||||
{
|
||||
from.SendMessage("You may no longer access their properties.");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (info.ButtonID)
|
||||
{
|
||||
default:
|
||||
{
|
||||
base.OnResponse(state, info);
|
||||
break;
|
||||
}
|
||||
case 3: // Apply
|
||||
{
|
||||
using var propsBuilder = new ValueStringBuilder(64);
|
||||
bool first = true;
|
||||
foreach (var attr in MobileAttributes)
|
||||
{
|
||||
var prop = GetPropValue(m_Object, attr);
|
||||
if (prop != null)
|
||||
{
|
||||
if (first)
|
||||
{
|
||||
first = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
propsBuilder.Append(' ');
|
||||
}
|
||||
|
||||
propsBuilder.Append(attr);
|
||||
propsBuilder.Append(' ');
|
||||
propsBuilder.Append(prop.ToString()); // TODO: Replace with ZString, or IFormatter code
|
||||
}
|
||||
}
|
||||
|
||||
var name = m_Object.GetType().Name;
|
||||
var props = propsBuilder.ToString();
|
||||
|
||||
m_Mobile.SendMessage("Updating spawners...");
|
||||
|
||||
foreach (var obj in _spawners)
|
||||
{
|
||||
if (obj is BaseSpawner spawner)
|
||||
{
|
||||
EditSpawnCommand.UpdateSpawner(spawner, name, null, props);
|
||||
}
|
||||
}
|
||||
|
||||
m_Mobile.SendMessage("Update completed.");
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ShowAttribute(string name)
|
||||
{
|
||||
foreach (var item in MobileAttributes)
|
||||
{
|
||||
if (item.InsensitiveEquals(name))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
73
Projects/UOContent/Engines/Spawners/SpawnPropsGumpCommand.cs
Normal file
73
Projects/UOContent/Engines/Spawners/SpawnPropsGumpCommand.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/*************************************************************************
|
||||
* ModernUO *
|
||||
* Copyright (C) 2019-2021 - ModernUO Development Team *
|
||||
* Email: hi@modernuo.com *
|
||||
* File: SpawnPropsGump.cs *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Server.Commands;
|
||||
using Server.Commands.Generic;
|
||||
using Server.Gumps;
|
||||
using Server.Targeting;
|
||||
|
||||
namespace Server.Engines.Spawners
|
||||
{
|
||||
public class SpawnPropsGumpCommand : BaseCommand
|
||||
{
|
||||
public static void Initialize()
|
||||
{
|
||||
TargetCommands.Register(new SpawnPropsGumpCommand());
|
||||
}
|
||||
|
||||
public SpawnPropsGumpCommand()
|
||||
{
|
||||
AccessLevel = AccessLevel.GameMaster;
|
||||
Supports = CommandSupport.Complex | CommandSupport.Simple;
|
||||
Commands = new[] { "SpawnProps" };
|
||||
ObjectTypes = ObjectTypes.Items;
|
||||
Usage = "SpawnProps";
|
||||
Description = "Shows a props gump that will modify the properties of spawn entries related to the chosen entity";
|
||||
ListOptimized = true;
|
||||
}
|
||||
|
||||
public override void ExecuteList(CommandEventArgs e, List<object> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
LogFailure("No matching objects found.");
|
||||
return;
|
||||
}
|
||||
|
||||
e.Mobile.SendMessage("Target the object you want to use as a template for modifying the spawner properties.");
|
||||
e.Mobile.Target = new InternalTarget(list);
|
||||
}
|
||||
|
||||
private class InternalTarget : Target
|
||||
{
|
||||
private List<object> _list;
|
||||
|
||||
public InternalTarget(List<object> list) : base(-1, false, TargetFlags.None) =>
|
||||
_list = list;
|
||||
|
||||
protected override void OnTarget(Mobile from, object targeted)
|
||||
{
|
||||
var type = targeted.GetType();
|
||||
if (!Add.IsEntity(type))
|
||||
{
|
||||
from.SendMessage("No type with that name was found.");
|
||||
}
|
||||
|
||||
from.SendGump(new SpawnPropsGump(from, targeted, _list));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue