コード例 #1
0
            public void OnWindowAction(WindowActionType actionType, IWindowController controller)
            {
                switch (actionType)
                {
                case WindowActionType.Undefined:
                    break;

                case WindowActionType.Open:
                    UpdateState(WindowState.InProgress);
                    break;

                case WindowActionType.Blocked:
                    UpdateState(WindowState.Paused);
                    break;

                case WindowActionType.Unblocked:
                    UpdateState(WindowState.InProgress);
                    break;

                case WindowActionType.Closed:
                    UpdateState(WindowState.Completed);
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(actionType), actionType, null);
                }
            }
コード例 #2
0
        public WindowActionMessage(WindowActionType action)
        {
            Action = action;
            var a = typeof(T);

            WindowViewModel = ServiceLocator.Current.GetInstance <T>();
        }
        /// <summary>
        /// Drag a stack of item over a set of slots. Those slots should be empty or have the same item as source item
        /// </summary>
        /// <param name="source">Source item</param>
        /// <param name="slots">Slots to be drag over</param>
        /// <param name="mouseKey">Which mouse key to use: StartDragLeft, StartDragRight or StartDragMiddle</param>
        /// <returns>True if success or false if Failed</returns>
        /// <remarks>
        /// After calling this method, you will need to wait until the server have updated the player inventory before doing next inventory action
        /// </remarks>
        public bool DragOverSlots(int source, IEnumerable <int> slots, WindowActionType mouseKey = WindowActionType.StartDragLeft)
        {
            if (!HasItem(source))
            {
                return(false);
            }
            List <int> availableSlots = new List <int>(slots.Count());

            // filter out different item type or non-empty slots (they will be ignored silently)
            foreach (var slot in slots)
            {
                if (ItemTypeEqual(source, slot) || !HasItem(slot))
                {
                    availableSlots.Add(slot);
                }
            }
            if (availableSlots.Count > 0)
            {
                WindowActionType startDragging = WindowActionType.StartDragLeft;
                WindowActionType addDragging   = WindowActionType.AddDragLeft;
                WindowActionType endDragging   = WindowActionType.EndDragLeft;
                switch (mouseKey)
                {
                case WindowActionType.StartDragRight:
                {
                    startDragging = WindowActionType.StartDragRight;
                    addDragging   = WindowActionType.AddDragRight;
                    endDragging   = WindowActionType.EndDragRight;
                    break;
                }

                case WindowActionType.StartDragMiddle:
                {
                    startDragging = WindowActionType.StartDragMiddle;
                    addDragging   = WindowActionType.AddDragMiddle;
                    endDragging   = WindowActionType.EndDragMiddle;
                    break;
                }
                }
                mc.DoWindowAction(c.ID, source, WindowActionType.LeftClick); // grab item
                mc.DoWindowAction(c.ID, -999, startDragging);
                foreach (var slot in availableSlots)
                {
                    mc.DoWindowAction(c.ID, slot, addDragging);
                }
                mc.DoWindowAction(c.ID, -999, endDragging);
                mc.DoWindowAction(c.ID, source, WindowActionType.LeftClick); // put down item left (if any)
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public WindowAction GetAction(WindowActionType type)
        {
            WindowAction result = null;

            for (var i = 0; i < this.Count; i++)
            {
                if (this[i].Type == type)
                {
                    result = this[i];
                }
            }

            return(result);
        }
コード例 #5
0
 public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item)
 {
     return(false); //Currently not implemented
 }
コード例 #6
0
        public override string Run(McClient handler, string command, Dictionary <string, object> localVars)
        {
            if (handler.GetInventoryEnabled())
            {
                string[] args = getArgs(command);
                if (args.Length >= 1)
                {
                    try
                    {
                        int inventoryId;
                        if (args[0].ToLower() == "player")
                        {
                            // player inventory is always ID 0
                            inventoryId = 0;
                        }
                        else if (args[0].ToLower() == "container")
                        {
                            List <int> availableIds = handler.GetInventories().Keys.ToList();
                            availableIds.Remove(0); // remove player inventory ID from list
                            if (availableIds.Count == 1)
                            {
                                inventoryId = availableIds[0]; // one container, use it
                            }
                            else
                            {
                                return("Cannot find container, please retry with explicit ID");
                            }
                        }
                        else if (args[0].ToLower() == "creativegive")
                        {
                            if (args.Length >= 4)
                            {
                                int      slot     = int.Parse(args[1]);
                                ItemType itemType = ItemType.Stone;
                                if (Enum.TryParse(args[2], out itemType))
                                {
                                    if (handler.GetGamemode() == 1)
                                    {
                                        int count = int.Parse(args[3]);
                                        if (handler.DoCreativeGive(slot, itemType, count, null))
                                        {
                                            return("Requested " + itemType + " x" + count + " in slot #" + slot);
                                        }
                                        else
                                        {
                                            return("Failed to request Creative Give");
                                        }
                                    }
                                    else
                                    {
                                        return("You need Gamemode Creative");
                                    }
                                }
                                else
                                {
                                    return(CMDDesc);
                                }
                            }
                            else
                            {
                                return(CMDDesc);
                            }
                        }
                        else
                        {
                            inventoryId = int.Parse(args[0]);
                        }
                        string action = args.Length > 1
                            ? args[1].ToLower()
                            : "list";
                        switch (action)
                        {
                        case "close":
                            if (handler.CloseInventory(inventoryId))
                            {
                                return("Closing Inventoy #" + inventoryId);
                            }
                            else
                            {
                                return("Failed to close Inventory #" + inventoryId);
                            }

                        case "list":
                            Container inventory = handler.GetInventory(inventoryId);
                            if (inventory == null)
                            {
                                return("Inventory #" + inventoryId + " do not exist");
                            }
                            List <string> response = new List <string>();
                            response.Add("Inventory #" + inventoryId + " - " + inventory.Title + "§8");
                            foreach (KeyValuePair <int, Item> item in inventory.Items)
                            {
                                string displayName = item.Value.DisplayName;
                                if (String.IsNullOrEmpty(displayName))
                                {
                                    response.Add(String.Format(" #{0}: {1} x{2}", item.Key, item.Value.Type, item.Value.Count));
                                }
                                else
                                {
                                    response.Add(String.Format(" #{0}: {1} x{2} - {3}§8", item.Key, item.Value.Type, item.Value.Count, displayName));
                                }
                            }
                            if (inventoryId == 0)
                            {
                                response.Add("Your selected hotbar is " + (handler.GetCurrentSlot() + 1));
                            }
                            return(String.Join("\n", response.ToArray()));

                        case "click":
                            if (args.Length >= 3)
                            {
                                int slot = int.Parse(args[2]);
                                WindowActionType actionType = WindowActionType.LeftClick;
                                string           keyName    = "Left";
                                if (args.Length >= 4)
                                {
                                    string b = args[3];
                                    if (b.ToLower()[0] == 'r')
                                    {
                                        actionType = WindowActionType.RightClick;
                                        keyName    = "Right";
                                    }
                                    if (b.ToLower()[0] == 'm')
                                    {
                                        actionType = WindowActionType.MiddleClick;
                                        keyName    = "Middle";
                                    }
                                }
                                handler.DoWindowAction(inventoryId, slot, actionType);
                                return(keyName + " clicking slot " + slot + " in window #" + inventoryId);
                            }
                            else
                            {
                                return(CMDDesc);
                            }

                        case "drop":
                            if (args.Length >= 3)
                            {
                                int slot = int.Parse(args[2]);
                                // check item exist
                                if (!handler.GetInventory(inventoryId).Items.ContainsKey(slot))
                                {
                                    return("No item in slot #" + slot);
                                }
                                WindowActionType actionType = WindowActionType.DropItem;
                                if (args.Length >= 4)
                                {
                                    if (args[3].ToLower() == "all")
                                    {
                                        actionType = WindowActionType.DropItemStack;
                                    }
                                }
                                if (handler.DoWindowAction(inventoryId, slot, actionType))
                                {
                                    if (actionType == WindowActionType.DropItemStack)
                                    {
                                        return("Dropped whole item stack from slot #" + slot);
                                    }
                                    else
                                    {
                                        return("Dropped 1 item from slot #" + slot);
                                    }
                                }
                                else
                                {
                                    return("Failed");
                                }
                            }
                            else
                            {
                                return(CMDDesc);
                            }

                        default:
                            return(CMDDesc);
                        }
                    }
                    catch (FormatException) { return(CMDDesc); }
                }
                else
                {
                    Dictionary <int, Container> inventories = handler.GetInventories();
                    List <string> response = new List <string>();
                    response.Add("Inventories:");
                    foreach (var inventory in inventories)
                    {
                        response.Add(String.Format(" #{0}: {1}", inventory.Key, inventory.Value.Title + "§8"));
                    }
                    response.Add(CMDDesc);
                    return(String.Join("\n", response));
                }
            }
            else
            {
                return("Please enable inventoryhandling in config to use this command.");
            }
        }
コード例 #7
0
 /// <summary>
 /// Perform inventory action
 /// </summary>
 /// <param name="inventoryId">Inventory ID</param>
 /// <param name="slot">Slot ID</param>
 /// <param name="actionType">Action Type</param>
 /// <returns>TRUE in case of success</returns>
 protected bool WindowAction(int inventoryId, int slot, WindowActionType actionType)
 {
     return(Handler.DoWindowAction(inventoryId, slot, actionType));
 }
コード例 #8
0
        public override string Run(McClient handler, string command, Dictionary <string, object> localVars)
        {
            if (handler.GetInventoryEnabled())
            {
                string[] args = getArgs(command);
                if (args.Length >= 1)
                {
                    try
                    {
                        int inventoryId;
                        if (args[0].ToLower() == "creativegive")
                        {
                            if (args.Length >= 4)
                            {
                                int      slot     = int.Parse(args[1]);
                                ItemType itemType = ItemType.Stone;
                                if (Enum.TryParse(args[2], true, out itemType))
                                {
                                    if (handler.GetGamemode() == 1)
                                    {
                                        int count = int.Parse(args[3]);
                                        if (handler.DoCreativeGive(slot, itemType, count, null))
                                        {
                                            return(Translations.Get("cmd.inventory.creative_done", itemType, count, slot));
                                        }
                                        else
                                        {
                                            return(Translations.Get("cmd.inventory.creative_fail"));
                                        }
                                    }
                                    else
                                    {
                                        return(Translations.Get("cmd.inventory.need_creative"));
                                    }
                                }
                                else
                                {
                                    return(GetCmdDescTranslated());
                                }
                            }
                            else
                            {
                                return(GetCmdDescTranslated());
                            }
                        }
                        else if (args[0].ToLower() == "creativedelete")
                        {
                            if (args.Length >= 2)
                            {
                                int slot = int.Parse(args[1]);
                                if (handler.GetGamemode() == 1)
                                {
                                    if (handler.DoCreativeGive(slot, ItemType.Null, 0, null))
                                    {
                                        return(Translations.Get("cmd.inventory.creative_delete", slot));
                                    }
                                    else
                                    {
                                        return(Translations.Get("cmd.inventory.creative_fail"));
                                    }
                                }
                                else
                                {
                                    return(Translations.Get("cmd.inventory.need_creative"));
                                }
                            }
                            else
                            {
                                return(GetCmdDescTranslated());
                            }
                        }
                        else if (args[0].ToLower().StartsWith("p"))
                        {
                            // player inventory is always ID 0
                            inventoryId = 0;
                        }
                        else if (args[0].ToLower().StartsWith("c"))
                        {
                            List <int> availableIds = handler.GetInventories().Keys.ToList();
                            availableIds.Remove(0); // remove player inventory ID from list
                            if (availableIds.Count == 1)
                            {
                                inventoryId = availableIds[0]; // one container, use it
                            }
                            else
                            {
                                return(Translations.Get("cmd.inventory.container_not_found"));
                            }
                        }
                        else if (args[0].ToLower() == "help")
                        {
                            if (args.Length >= 2)
                            {
                                return(GetSubCommandHelp(args[1]));
                            }
                            else
                            {
                                return(GetHelp());
                            }
                        }
                        else
                        {
                            inventoryId = int.Parse(args[0]);
                        }
                        string action = args.Length > 1
                            ? args[1].ToLower()
                            : "list";
                        switch (action)
                        {
                        case "close":
                            if (handler.CloseInventory(inventoryId))
                            {
                                return(Translations.Get("cmd.inventory.close", inventoryId));
                            }
                            else
                            {
                                return(Translations.Get("cmd.inventory.close_fail", inventoryId));
                            }

                        case "list":
                            Container inventory = handler.GetInventory(inventoryId);
                            if (inventory == null)
                            {
                                return(Translations.Get("cmd.inventory.not_exist", inventoryId));
                            }
                            SortedDictionary <int, Item> itemsSorted = new SortedDictionary <int, Item>(inventory.Items);
                            List <string> response = new List <string>();
                            response.Add(Translations.Get("cmd.inventory.inventory") + " #" + inventoryId + " - " + inventory.Title + "§8");
                            int selectedHotbar = handler.GetCurrentSlot() + 1;
                            foreach (KeyValuePair <int, Item> item in itemsSorted)
                            {
                                int    hotbar;
                                bool   isHotbar     = inventory.IsHotbar(item.Key, out hotbar);
                                string hotbarString = isHotbar ? (hotbar + 1).ToString() : " ";
                                if ((hotbar + 1) == selectedHotbar)
                                {
                                    hotbarString = ">" + hotbarString;
                                }
                                response.Add(String.Format("{0,2} | #{1,-2}: {2}", hotbarString, item.Key, item.Value.ToString()));
                            }
                            if (inventoryId == 0)
                            {
                                response.Add(Translations.Get("cmd.inventory.hotbar", (handler.GetCurrentSlot() + 1)));
                            }
                            return(String.Join("\n", response.ToArray()));

                        case "click":
                            if (args.Length >= 3)
                            {
                                int slot = int.Parse(args[2]);
                                WindowActionType actionType = WindowActionType.LeftClick;
                                string           keyName    = "cmd.inventory.left";
                                if (args.Length >= 4)
                                {
                                    string b = args[3];
                                    if (b.ToLower()[0] == 'r')
                                    {
                                        actionType = WindowActionType.RightClick;
                                        keyName    = "cmd.inventory.right";
                                    }
                                    if (b.ToLower()[0] == 'm')
                                    {
                                        actionType = WindowActionType.MiddleClick;
                                        keyName    = "cmd.inventory.middle";
                                    }
                                }
                                handler.DoWindowAction(inventoryId, slot, actionType);
                                return(Translations.Get("cmd.inventory.clicking", Translations.Get(keyName), slot, inventoryId));
                            }
                            else
                            {
                                return(CmdUsage);
                            }

                        case "drop":
                            if (args.Length >= 3)
                            {
                                int slot = int.Parse(args[2]);
                                // check item exist
                                if (!handler.GetInventory(inventoryId).Items.ContainsKey(slot))
                                {
                                    return(Translations.Get("cmd.inventory.no_item", slot));
                                }
                                WindowActionType actionType = WindowActionType.DropItem;
                                if (args.Length >= 4)
                                {
                                    if (args[3].ToLower() == "all")
                                    {
                                        actionType = WindowActionType.DropItemStack;
                                    }
                                }
                                if (handler.DoWindowAction(inventoryId, slot, actionType))
                                {
                                    if (actionType == WindowActionType.DropItemStack)
                                    {
                                        return(Translations.Get("cmd.inventory.drop_stack", slot));
                                    }
                                    else
                                    {
                                        return(Translations.Get("cmd.inventory.drop", slot));
                                    }
                                }
                                else
                                {
                                    return("Failed");
                                }
                            }
                            else
                            {
                                return(GetCmdDescTranslated());
                            }

                        default:
                            return(GetCmdDescTranslated());
                        }
                    }
                    catch (FormatException) { return(GetCmdDescTranslated()); }
                }
                else
                {
                    Dictionary <int, Container> inventories = handler.GetInventories();
                    List <string> response = new List <string>();
                    response.Add(Translations.Get("cmd.inventory.inventories") + ":");
                    foreach (KeyValuePair <int, Container> inventory in inventories)
                    {
                        response.Add(String.Format(" #{0}: {1}", inventory.Key, inventory.Value.Title + "§8"));
                    }
                    response.Add(CmdUsage);
                    return(String.Join("\n", response));
                }
            }
            else
            {
                return(Translations.Get("extra.inventory_required"));
            }
        }
コード例 #9
0
 private void OnWindowStateChanged(WindowActionType actionType, IWindowController controller)
 {
     //            Debug.Log($"<color=green>{actionType}    {controller.GetType()}</color>");
     _scenarios.First(s => s.Type == controller.Type).OnWindowAction(actionType, controller);
 }
コード例 #10
0
        public override string Run(McClient handler, string command, Dictionary <string, object> localVars)
        {
            if (handler.GetInventoryEnabled())
            {
                string[] args = getArgs(command);
                if (args.Length >= 1)
                {
                    try
                    {
                        int inventoryId;
                        if (args[0].ToLower() == "creativegive")
                        {
                            if (args.Length >= 4)
                            {
                                int      slot     = int.Parse(args[1]);
                                ItemType itemType = ItemType.Stone;
                                if (Enum.TryParse(args[2], true, out itemType))
                                {
                                    if (handler.GetGamemode() == 1)
                                    {
                                        int count = int.Parse(args[3]);
                                        if (handler.DoCreativeGive(slot, itemType, count, null))
                                        {
                                            return("已要求 " + itemType + " x" + count + " 在物品槽 #" + slot);
                                        }
                                        else
                                        {
                                            return("未能获取物品!");
                                        }
                                    }
                                    else
                                    {
                                        return("你必须处于创造模式");
                                    }
                                }
                                else
                                {
                                    return(CMDDesc);
                                }
                            }
                            else
                            {
                                return(CMDDesc);
                            }
                        }
                        else if (args[0].ToLower().StartsWith("p"))
                        {
                            // player inventory is always ID 0
                            inventoryId = 0;
                        }
                        else if (args[0].ToLower().StartsWith("c"))
                        {
                            List <int> availableIds = handler.GetInventories().Keys.ToList();
                            availableIds.Remove(0); // remove player inventory ID from list
                            if (availableIds.Count == 1)
                            {
                                inventoryId = availableIds[0]; // one container, use it
                            }
                            else
                            {
                                return("未找到容器 请用明确的ID重试");
                            }
                        }
                        else if (args[0].ToLower() == "help")
                        {
                            if (args.Length >= 2)
                            {
                                return(GetSubCommandHelp(args[1]));
                            }
                            else
                            {
                                return(GetHelp());
                            }
                        }
                        else
                        {
                            inventoryId = int.Parse(args[0]);
                        }
                        string action = args.Length > 1
                            ? args[1].ToLower()
                            : "list";
                        switch (action)
                        {
                        case "close":
                            if (handler.CloseInventory(inventoryId))
                            {
                                return("正在关闭物品栏 #" + inventoryId);
                            }
                            else
                            {
                                return("关闭物品栏 #" + inventoryId + "失败");
                            }

                        case "list":
                            Container inventory = handler.GetInventory(inventoryId);
                            if (inventory == null)
                            {
                                return("物品栏 #" + inventoryId + " 未退出");
                            }
                            List <string> response = new List <string>();
                            response.Add("Inventory #" + inventoryId + " - " + inventory.Title + "§8");
                            foreach (KeyValuePair <int, Item> item in inventory.Items)
                            {
                                string displayName = item.Value.DisplayName;
                                if (String.IsNullOrEmpty(displayName))
                                {
                                    if (item.Value.Damage != 0)
                                    {
                                        response.Add(String.Format(" #{0}: {1} x{2} | 已消耗耐久: {3}", item.Key, item.Value.Type, item.Value.Count, item.Value.Damage));
                                    }
                                    else
                                    {
                                        response.Add(String.Format(" #{0}: {1} x{2}", item.Key, item.Value.Type, item.Value.Count));
                                    }
                                }
                                else
                                {
                                    if (item.Value.Damage != 0)
                                    {
                                        response.Add(String.Format(" #{0}: {1} x{2} - {3}§8 | 已消耗耐久: {4}", item.Key, item.Value.Type, item.Value.Count, displayName, item.Value.Damage));
                                    }
                                    else
                                    {
                                        response.Add(String.Format(" #{0}: {1} x{2} - {3}§8", item.Key, item.Value.Type, item.Value.Count, displayName));
                                    }
                                }
                            }
                            if (inventoryId == 0)
                            {
                                response.Add("您选择的物品栏位置是 " + (handler.GetCurrentSlot() + 1));
                            }
                            return(String.Join("\n", response.ToArray()));

                        case "click":
                            if (args.Length >= 3)
                            {
                                int slot = int.Parse(args[2]);
                                WindowActionType actionType = WindowActionType.LeftClick;
                                string           keyName    = "左键";
                                if (args.Length >= 4)
                                {
                                    string b = args[3];
                                    if (b.ToLower()[0] == 'r')
                                    {
                                        actionType = WindowActionType.RightClick;
                                        keyName    = "右键";
                                    }
                                    if (b.ToLower()[0] == 'm')
                                    {
                                        actionType = WindowActionType.MiddleClick;
                                        keyName    = "中键";
                                    }
                                }
                                handler.DoWindowAction(inventoryId, slot, actionType);
                                return("正在使用 " + keyName + " 点击物品槽 " + slot + " 在窗口 #" + inventoryId);
                            }
                            else
                            {
                                return(CMDDesc);
                            }

                        case "drop":
                            if (args.Length >= 3)
                            {
                                int slot = int.Parse(args[2]);
                                // check item exist
                                if (!handler.GetInventory(inventoryId).Items.ContainsKey(slot))
                                {
                                    return("物品槽 #" + slot + "没有物品");
                                }
                                WindowActionType actionType = WindowActionType.DropItem;
                                if (args.Length >= 4)
                                {
                                    if (args[3].ToLower() == "all")
                                    {
                                        actionType = WindowActionType.DropItemStack;
                                    }
                                }
                                if (handler.DoWindowAction(inventoryId, slot, actionType))
                                {
                                    if (actionType == WindowActionType.DropItemStack)
                                    {
                                        return("从槽中删除整个项目堆栈 #" + slot);
                                    }
                                    else
                                    {
                                        return("从物品槽 #" + slot + "丢出一个物品");
                                    }
                                }
                                else
                                {
                                    return("失败");
                                }
                            }
                            else
                            {
                                return(CMDDesc);
                            }

                        default:
                            return(CMDDesc);
                        }
                    }
                    catch (FormatException) { return(CMDDesc); }
                }
                else
                {
                    Dictionary <int, Container> inventories = handler.GetInventories();
                    List <string> response = new List <string>();
                    response.Add("库存:");
                    foreach (KeyValuePair <int, Container> inventory in inventories)
                    {
                        response.Add(String.Format(" #{0}: {1}", inventory.Key, inventory.Value.Title + "§8"));
                    }
                    response.Add(CMDDesc);
                    return(String.Join("\n", response));
                }
            }
            else
            {
                return("请从配置文件中开启 inventoryhandling 来使用该指令");
            }
        }
コード例 #11
0
 public WindowAction(WindowActionType type)
 {
     Type     = type;
     IsActive = false;
     Action   = string.Empty;
 }