private static bool LiftType(string command, Variable[] vars, bool quiet, bool force) { if (vars.Length < 1) { throw new RunTimeError("Usage: lifttype (gfx/'name of item') [amount] [hue]"); } string gfxStr = vars[0].AsString(); ushort gfx = Utility.ToUInt16(gfxStr, 0); ushort amount = 1; int hue = -1; if (vars.Length > 1) { if (vars.Length == 2) { amount = Utility.ToUInt16(vars[1].AsString(), 1); } if (vars.Length == 3) { hue = Utility.ToUInt16(vars[2].AsString(), 0); } } if (_lastLiftTypeId > 0) { if (DragDropManager.LastIDLifted == _lastLiftTypeId) { _lastLiftTypeId = 0; Interpreter.ClearTimeout(); return(true); } Interpreter.Timeout(30000, () => { _lastLiftTypeId = 0; return(true); }); } else { List <Item> items = new List <Item>(); // No graphic id, maybe searching by name? if (gfx == 0) { items = World.Player.Backpack.FindItemsByName(gfxStr, true); if (items.Count == 0) { CommandHelper.SendWarning(command, $"Item '{gfxStr}' not found", quiet); return(true); } } else { items = World.Player.Backpack.FindItemsById(gfx); } if (hue > -1) { items.RemoveAll(item => item.Hue != hue); } if (items.Count > 0) { Item item = items[Utility.Random(items.Count)]; if (item.Amount < amount) { amount = item.Amount; } _lastLiftTypeId = DragDropManager.Drag(item, amount); } else { CommandHelper.SendWarning(command, Language.Format(LocString.NoItemOfType, (ItemID)gfx), quiet); return(true); } } return(false); }
private static bool LiftType(string command, Argument[] args, bool quiet, bool force) { if (args.Length < 1) { throw new RunTimeError(null, "Usage: lifttype (gfx/'name of item') [amount]"); } string gfxStr = args[0].AsString(); ushort gfx = Utility.ToUInt16(gfxStr, 0); ushort amount = 1; if (args.Length == 2) { amount = Utility.ToUInt16(args[1].AsString(), 1); } if (_lastLiftTypeId > 0) { if (DragDropManager.LastIDLifted == _lastLiftTypeId) { _lastLiftTypeId = 0; Interpreter.ClearTimeout(); return(true); } Interpreter.Timeout(30000, () => { _lastLiftTypeId = 0; return(true); }); } else { Item item; // No graphic id, maybe searching by name? if (gfx == 0) { item = World.Player.Backpack?.FindItemByName(gfxStr, true); if (item == null) { CommandHelper.SendWarning(command, $"Item '{gfxStr}' not found", quiet); return(true); } } else { item = World.Player.Backpack?.FindItemByID(gfx); } if (item != null) { if (item.Amount < amount) { amount = item.Amount; } _lastLiftTypeId = DragDropManager.Drag(item, amount); } else { CommandHelper.SendWarning(command, Language.Format(LocString.NoItemOfType, (ItemID)gfx), quiet); return(true); } } return(false); }
public void Drag(object sender, PointerPressedEventArgs e) => DragDrop.Drag(Program.Project.Window?.Selection, e);