mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-15 10:18:43 -04:00
Add /copyslot random to allow randomly selecting between used slots (Thanks saiko)
This commit is contained in:
parent
681899edc6
commit
f05a6f617e
@ -16,9 +16,13 @@
|
||||
permissions and limitations under the Licenses.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using MCGalaxy.Drawing;
|
||||
|
||||
namespace MCGalaxy.Commands.Building {
|
||||
public sealed class CmdCopySlot : Command2 {
|
||||
namespace MCGalaxy.Commands.Building
|
||||
{
|
||||
public sealed class CmdCopySlot : Command2
|
||||
{
|
||||
public override string name { get { return "CopySlot"; } }
|
||||
public override string shortcut { get { return "cs"; } }
|
||||
public override string type { get { return CommandTypes.Building; } }
|
||||
@ -27,19 +31,52 @@ namespace MCGalaxy.Commands.Building {
|
||||
|
||||
public override void Use(Player p, string message, CommandData data) {
|
||||
if (message.Length == 0) {
|
||||
OutputCopySlots(p);
|
||||
} else if (message.CaselessEq("random")) {
|
||||
SetRandomCopySlot(p);
|
||||
} else {
|
||||
int i = 0;
|
||||
if (!CommandParser.GetInt(p, message, "Slot number", ref i, 1, p.group.CopySlots)) return;
|
||||
|
||||
SetCopySlot(p, i);
|
||||
}
|
||||
}
|
||||
|
||||
static void OutputCopySlots(Player p) {
|
||||
List<CopyState> copySlots = p.CopySlots;
|
||||
int used = 0;
|
||||
for (int i = 0; i < p.CopySlots.Count; i++) {
|
||||
if (p.CopySlots[i] == null) continue;
|
||||
p.Message(" #{0}: {1}", i + 1, p.CopySlots[i].Summary);
|
||||
|
||||
for (int i = 0; i < copySlots.Count; i++)
|
||||
{
|
||||
if (copySlots[i] == null) continue;
|
||||
p.Message(" #{0}: {1}", i + 1, copySlots[i].Summary);
|
||||
used++;
|
||||
}
|
||||
|
||||
p.Message("Using {0} of {1} slots, with slot #{2} selected.",
|
||||
used, p.group.CopySlots, p.CurrentCopySlot + 1);
|
||||
} else {
|
||||
int i = 0;
|
||||
if (!CommandParser.GetInt(p, message, "Slot number", ref i, 1, p.group.CopySlots)) return;
|
||||
}
|
||||
|
||||
static void SetRandomCopySlot(Player p) {
|
||||
List<CopyState> copySlots = p.CopySlots;
|
||||
List<int> slots = new List<int>();
|
||||
|
||||
for (int i = 0; i < copySlots.Count; i++)
|
||||
{
|
||||
if (copySlots[i] == null) continue;
|
||||
slots.Add(i);
|
||||
}
|
||||
|
||||
if (slots.Count == 0) {
|
||||
p.Message("&WCannot randomly select when all copy slots are unused/empty");
|
||||
return;
|
||||
}
|
||||
|
||||
int idx = new Random().Next(slots.Count);
|
||||
SetCopySlot(p, slots[idx] + 1);
|
||||
}
|
||||
|
||||
static void SetCopySlot(Player p, int i) {
|
||||
p.CurrentCopySlot = i - 1;
|
||||
if (p.CurrentCopy == null) {
|
||||
p.Message("Selected copy slot {0} (unused)", i);
|
||||
@ -47,9 +84,10 @@ namespace MCGalaxy.Commands.Building {
|
||||
p.Message("Selected copy slot {0}: {1}", i, p.CurrentCopy.Summary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Help(Player p) {
|
||||
p.Message("&T/CopySlot random");
|
||||
p.Message("&HSelects a random slot to &T/copy &Hand &T/paste &Hfrom");
|
||||
p.Message("&T/CopySlot [number]");
|
||||
p.Message("&HSelects the slot to &T/copy &Hand &T/paste &Hfrom");
|
||||
p.Message("&HMaxmimum number of copy slots is determined by your rank");
|
||||
|
@ -424,8 +424,9 @@ namespace MCGalaxy
|
||||
}
|
||||
|
||||
if (continued) {
|
||||
if (text.Length < NetUtils.StringSize) text += " ";
|
||||
partialMessage += text;
|
||||
if (text.Length < NetUtils.StringSize) partialMessage += " ";
|
||||
|
||||
LimitPartialMessage();
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user