Merge pull request #493 from CoderCow/patch-1

Fixed /region info, Improved /item
This commit is contained in:
Lucas Nicodemus 2013-07-02 10:05:13 -07:00
commit e5889765fc
2 changed files with 161 additions and 132 deletions

View file

@ -2843,9 +2843,7 @@ namespace TShockAPI
} }
case "info": case "info":
{ {
if (args.Parameters.Count > 1) if (args.Parameters.Count == 1 || args.Parameters.Count > 4)
{
if (args.Parameters.Count > 4)
{ {
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /region info <region> [-d] [page]"); args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /region info <region> [-d] [page]");
break; break;
@ -2936,19 +2934,20 @@ namespace TShockAPI
} }
} }
new Timer((dummy) => { Timer boundaryHideTimer = null;
boundaryHideTimer = new Timer((state) => {
foreach (Point boundaryPoint in Utils.Instance.EnumerateRegionBoundaries(regionArea)) foreach (Point boundaryPoint in Utils.Instance.EnumerateRegionBoundaries(regionArea))
if ((boundaryPoint.X + boundaryPoint.Y & 1) == 0) if ((boundaryPoint.X + boundaryPoint.Y & 1) == 0)
args.Player.SendTileSquare(boundaryPoint.X, boundaryPoint.Y, 1); args.Player.SendTileSquare(boundaryPoint.X, boundaryPoint.Y, 1);
// ReSharper disable AccessToModifiedClosure
Debug.Assert(boundaryHideTimer != null);
boundaryHideTimer.Dispose();
// ReSharper restore AccessToModifiedClosure
}, },
null, 5000, Timeout.Infinite null, 5000, Timeout.Infinite
); );
} }
}
else
{
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /region info <name>");
}
break; break;
} }
@ -3493,43 +3492,77 @@ namespace TShockAPI
args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /item <item name/id> [item amount] [prefix id/name]"); args.Player.SendErrorMessage("Invalid syntax! Proper syntax: /item <item name/id> [item amount] [prefix id/name]");
return; return;
} }
if (args.Parameters[0].Length == 0)
{ int amountParamIndex = -1;
args.Player.SendErrorMessage("Missing an item name/id.");
return;
}
int itemAmount = 0; int itemAmount = 0;
int prefix = 0; for (int i = 1; i < args.Parameters.Count; i++)
if (args.Parameters.Count == 2)
int.TryParse(args.Parameters[1], out itemAmount);
else if (args.Parameters.Count == 3)
{ {
int.TryParse(args.Parameters[1], out itemAmount); if (int.TryParse(args.Parameters[i], out itemAmount))
var found = TShock.Utils.GetPrefixByIdOrName(args.Parameters[2]); {
if (found.Count == 1) amountParamIndex = i;
prefix = found[0]; break;
} }
var items = TShock.Utils.GetItemByIdOrName(args.Parameters[0]); }
if (items.Count == 0)
string itemNameOrId;
if (amountParamIndex == -1)
itemNameOrId = string.Join(" ", args.Parameters);
else
itemNameOrId = string.Join(" ", args.Parameters.Take(amountParamIndex));
Item item;
List<Item> matchedItems = TShock.Utils.GetItemByIdOrName(itemNameOrId);
if (matchedItems.Count == 0)
{ {
args.Player.SendErrorMessage("Invalid item type!"); args.Player.SendErrorMessage("Invalid item type!");
return;
} }
else if (items.Count > 1) else if (matchedItems.Count > 1)
{ {
args.Player.SendErrorMessage(string.Format("More than one ({0}) item matched!", items.Count)); args.Player.SendErrorMessage("More than one item matched:");
args.Player.SendErrorMessage(string.Join(", ", matchedItems.Select(i => i.name)));
return;
} }
else else
{ {
var item = items[0]; item = matchedItems[0];
if (item.type >= 1 && item.type < Main.maxItemTypes) }
if (item.type < 1 && item.type >= Main.maxItemTypes)
{ {
args.Player.SendErrorMessage("The item type {0} is invalid.", itemNameOrId);
return;
}
int prefixId = 0;
if (amountParamIndex != -1 && args.Parameters.Count > amountParamIndex + 1)
{
string prefixidOrName = args.Parameters[amountParamIndex + 1];
List<int> matchedPrefixIds = TShock.Utils.GetPrefixByIdOrName(prefixidOrName);
if (matchedPrefixIds.Count > 1)
{
args.Player.SendErrorMessage("More than one ({0}) prefixes matched \"{1}\".", matchedPrefixIds.Count, prefixidOrName);
return;
}
else if (matchedPrefixIds.Count == 0)
{
args.Player.SendErrorMessage("No prefix matched \"{0}\".", prefixidOrName);
return;
}
else
{
prefixId = matchedPrefixIds[0];
}
}
if (args.Player.InventorySlotAvailable || item.name.Contains("Coin")) if (args.Player.InventorySlotAvailable || item.name.Contains("Coin"))
{ {
if (itemAmount == 0 || itemAmount > item.maxStack) if (itemAmount == 0 || itemAmount > item.maxStack)
itemAmount = item.maxStack; itemAmount = item.maxStack;
if (args.Player.GiveItemCheck(item.type, item.name, item.width, item.height, itemAmount, prefix))
if (args.Player.GiveItemCheck(item.type, item.name, item.width, item.height, itemAmount, prefixId))
{ {
args.Player.SendSuccessMessage(string.Format("Gave {0} {1}(s).", itemAmount, item.name)); item.prefix = (byte)prefixId;
args.Player.SendSuccessMessage("Gave {0} {1}(s).", itemAmount, item.AffixName());
} }
else else
{ {
@ -3538,13 +3571,7 @@ namespace TShockAPI
} }
else else
{ {
args.Player.SendErrorMessage("You don't have free slots!"); args.Player.SendErrorMessage("Your inventory seems full.");
}
}
else
{
args.Player.SendErrorMessage("Invalid item type!");
}
} }
} }

View file

@ -1381,11 +1381,13 @@ namespace TShockAPI
} }
else if (!TShock.CheckInventory(args.Player)) else if (!TShock.CheckInventory(args.Player))
{ {
args.Player.LoginFailsBySsi = true;
args.Player.SendMessage("Login Failed, Please fix the above errors then /login again.", Color.Cyan); args.Player.SendMessage("Login Failed, Please fix the above errors then /login again.", Color.Cyan);
args.Player.IgnoreActionsForClearingTrashCan = true; args.Player.IgnoreActionsForClearingTrashCan = true;
return true; return true;
} }
} }
args.Player.LoginFailsBySsi = false;
if (group.HasPermission(Permissions.ignorestackhackdetection)) if (group.HasPermission(Permissions.ignorestackhackdetection))
args.Player.IgnoreActionsForCheating = "none"; args.Player.IgnoreActionsForCheating = "none";