Example #1
0
        public async void MoveItem([FromSource] Player player, IDictionary <string, dynamic> data)
        {
            var movingData = data.FirstOrDefault().Value;

            if (movingData.typeFrom == "search")
            {
                movingData.typeFrom = "player";
            }
            if (movingData.typeTo == "search")
            {
                movingData.typeTo = "player";
            }

            if (movingData.typeFrom == movingData.typeTo && movingData.ownerFrom == movingData.ownerTo)
            {
                var key      = new KeyValuePair <string, string>(movingData.typeFrom, movingData.ownerFrom);
                var inv      = LoadedInventories[key];
                var slotFrom = inv.Inventory[movingData.slotFrom];
                if (movingData.slotTo == -1)
                {
                    movingData.slotTo = inv.Inventory.Count() + 1;
                }
                if (!inv.Inventory.ContainsKey(movingData.slotTo) || inv.Inventory[movingData.slotTo].Id == movingData.item.Id)
                {
                    if (slotFrom.Count - movingData.item.Count <= 0)
                    {
                        inv.Inventory.Remove(movingData.slotFrom);
                        DeleteSlot(movingData.slotFrom, inv);
                    }
                    else
                    {
                        slotFrom.Count -= movingData.item.Count;
                        UpdateSlot(movingData.slotFrom, inv, slotFrom);
                    }

                    if (inv.Inventory.ContainsKey(movingData.slotTo))
                    {
                        InventorySlot slot = inv.Inventory[movingData.slotTo];
                        slot.Count += movingData.item.Count;
                        UpdateSlot(movingData.slotTo, inv, slot);
                    }
                    else
                    {
                        InventorySlot slot = new InventorySlot
                        {
                            Id       = movingData.item.Id,
                            Count    = movingData.item.Count,
                            MetaData = movingData.item.MetaData
                        };
                        inv.Inventory.Add(movingData.slotTo, slot);
                        CreateSlot(movingData.slotTo, inv, slot);
                    }
                }
            }
            else
            {
                var fromKey  = new KeyValuePair <string, string>(movingData.typeFrom, movingData.ownerFrom);
                var toKey    = new KeyValuePair <string, string>(movingData.typeTo, movingData.ownerTo);
                var invFrom  = LoadedInventories[fromKey];
                var slotFrom = invFrom.Inventory[movingData.slotFrom];
                if (!LoadedInventories.ContainsKey(toKey) || !LoadedInventories[toKey].Inventory.ContainsKey(movingData.slotTo) || LoadedInventories[toKey].Inventory[movingData.slotTo].Id == movingData.item.Id)
                {
                    if (slotFrom.Count - movingData.item.Count <= 0)
                    {
                        invFrom.Inventory.Remove(movingData.slotFrom);
                        DeleteSlot(movingData.slotFrom, invFrom);
                    }
                    else
                    {
                        slotFrom.Count -= movingData.item.Count;
                        UpdateSlot(movingData.slotFrom, invFrom, slotFrom);
                    }

                    if (LoadedInventories.ContainsKey(toKey))
                    {
                        var invTo = LoadedInventories[toKey];
                        if (movingData.slotTo == -1)
                        {
                            movingData.slotTo = invTo.Inventory.Count() + 1;
                        }
                        if (invTo.Inventory.ContainsKey(movingData.slotTo))
                        {
                            InventorySlot slot = invTo.Inventory[movingData.slotTo];
                            slot.Count += movingData.item.Count;
                            UpdateSlot(movingData.slotTo, invTo, slot);
                        }
                        else
                        {
                            InventorySlot slot = new InventorySlot
                            {
                                Id       = movingData.item.Id,
                                Count    = movingData.item.Count,
                                MetaData = movingData.item.MetaData
                            };
                            invTo.Inventory.Add(movingData.slotTo, slot);
                            CreateSlot(movingData.slotTo, invTo, slot);
                        }
                    }
                    else
                    {
                        if (movingData.slotTo == -1)
                        {
                            movingData.slotTo = 1;
                        }
                        InventorySlot slot = new InventorySlot
                        {
                            Id       = movingData.item.Id,
                            Count    = movingData.item.Count,
                            MetaData = movingData.item.MetaData
                        };
                        InventoryData newData = new InventoryData
                        {
                            Owner     = movingData.ownerTo,
                            Type      = movingData.typeTo,
                            Coords    = ((IDictionary <string, dynamic>)movingData).ContainsKey("coords") ? Drop.fromOwner(movingData.coords) : new Vector3(),
                            Inventory = new Dictionary <int, InventorySlot>
                            {
                                [movingData.slotTo] = slot
                            }
                        };
                        LoadedInventories[toKey] = newData;
                        CreateSlot(movingData.slotTo, newData, slot);
                    }
                }
            }
            if (movingData.typeFrom == "drop" || movingData.typeTo == "drop")
            {
                Drop.Instance.SyncDrops();
            }
        }
Example #2
0
 public Drop()
 {
     Instance = this;
     LoadDrops();
 }
Example #3
0
 public Drop()
 {
     Instance = this;
     EventHandlers["onMySQLReady"]  += new Action(LoadDrops);
     EventHandlers[Events.OpenDrop] += new Action <Player, string>(Open);
 }