Exemplo n.º 1
0
        public void CmdSwapItems(Vector2Byte positionOne, Vector2Byte positionTwo)
        {
            bool one = inventoryData.ContainsKey(positionOne);
            bool two = inventoryData.ContainsKey(positionTwo);

            if (one && !two)
            {
                inventoryData.Add(positionTwo, inventoryData[positionOne]);
                inventoryData.Remove(positionOne);
            }
            else if (two && !one)
            {
                inventoryData.Add(positionOne, inventoryData[positionTwo]);
                inventoryData.Remove(positionTwo);
            }
            else if (one && two)
            {
                ItemData itemOne = inventoryData[positionOne];
                ItemData itemTwo = inventoryData[positionTwo];

                inventoryData.Remove(positionOne);
                inventoryData.Remove(positionTwo);

                inventoryData.Add(positionOne, itemTwo);
                inventoryData.Add(positionTwo, itemOne);
            }
        }
Exemplo n.º 2
0
 public void DropItem(Vector2Byte position)
 {
     if (inventoryData.ContainsKey(position))
     {
         inventoryData.Remove(position);
     }
 }
Exemplo n.º 3
0
 public bool IsEqual(Vector2Byte pos)
 {
     if (pos != null)
     {
         return(pos.x == this.x && pos.y == this.y);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 4
0
    MapBuildingFence GetBuildingFenceData(Vector2Int item)
    {
        var key = new Vector2Byte(item);

        if (mapGenerator.buildingFenceDict != null && mapGenerator.buildingFenceDict.ContainsKey(key))
        {
            return(mapGenerator.buildingFenceDict[key]);
        }
        else
        {
            Debug.LogError("没有坐标数据:" + item);
            return(null);
        }
    }
Exemplo n.º 5
0
 public void RemoveItem(Vector2Byte position, short count)
 {
     if (inventoryData.ContainsKey(position))
     {
         ItemData item   = inventoryData[position];
         short    nCount = (short)(item.Count - count);
         if (nCount <= 0)
         {
             DropItem(position);
         }
         else
         {
             inventoryData[position] = new ItemData(item.ID, nCount);
         }
     }
 }
        /// <summary>
        /// Equip item
        /// </summary>
        /// <param name="position"></param>
        public override void UseItem(Vector2Byte position)
        {
            // get inventory cell
            InventoryCellUI cell = InventorySystem.Instance.GetInventoryCell(position.x, position.y);

            // check if player can set equipment and remove item from toolbar if so
            if (cell && (!Player.localPlayer.equipmentData.ContainsKey(equipmentSlot) || Player.localPlayer.equipmentData[equipmentSlot].Count == 0 || Player.localPlayer.equipmentData[equipmentSlot].ID != ID))
            {
                // clear cell data
                cell.ClearData();
                cell.toolbarIndex = -1;

                // equip item
                Player.localPlayer.CmdSetEquipment(equipmentSlot, new ItemData(ID, 1), position);
            }
        }
Exemplo n.º 7
0
        public void CmdUseItem(Vector2Byte position)
        {
            if (inventoryData.ContainsKey(position))
            {
                Item item = ObjectDatabase.GetItem(inventoryData[position].ID);
                if (item is UsableItem)
                {
                    UsableItem usableItem = (UsableItem)item;

                    Armor        += usableItem.ArmorBonus;
                    maxHealth    += usableItem.MaxHealthBonus;
                    Health       += usableItem.HealthBonus;
                    Strength     += usableItem.StrengthBonus;
                    Intelligence += usableItem.IntelligenceBonus;
                    Stamina      += usableItem.StaminaBonus;
                    // TODO: TIME BUFFS
                }

                RemoveItem(position, 1);
            }
        }
        public static Dictionary <Vector2Byte, ItemData> StringToItemData(string itemData)
        {
            Dictionary <Vector2Byte, ItemData> result = new Dictionary <Vector2Byte, ItemData>();

            string[] items = itemData.Split('|');
            foreach (string line in items)
            {
                string[] item = line.Split(';');

                if (item.Length != 4)
                {
                    continue;
                }

                Vector2Byte position = new Vector2Byte(int.Parse(item[0]), int.Parse(item[1]));
                short       ID       = short.Parse(item[2]);
                short       Count    = short.Parse(item[3]);

                result.Add(position, new ItemData(ID, Count));
            }

            return(result);
        }
Exemplo n.º 9
0
 public MapBuildingFence(Vector2Byte pos, GameObject[] fenceArray)
 {
     Coord  = pos;
     fences = fenceArray;
 }
Exemplo n.º 10
0
 public MapBuildingFence(Vector2Int pos, GameObject[] fenceArray)
 {
     Coord  = new Vector2Byte(pos);
     fences = fenceArray;
 }
Exemplo n.º 11
0
 public MapBuildingFence(byte x, byte y, GameObject[] fenceArray)
 {
     Coord  = new Vector2Byte(x, y);
     fences = fenceArray;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Возвращает индекс по локальным координатам позиции в ячейке
 /// </summary>
 /// <param name="pos">Локальные координаты позиции</param>
 /// <returns>Индекс позиции в ячейке</returns>
 public ushort GetCellItemIndex(Vector2Byte pos)
 {
     return((ushort)(pos.x + pos.y * SettingsAccess.CellPxSize));
 }
Exemplo n.º 13
0
        /// <summary>
        /// On inventory update event callback
        /// </summary>
        /// <param name="op">Operation (ADD, SET, REMOVE...)</param>
        /// <param name="key">inventory item position</param>
        /// <param name="item">item data</param>
        private void OnInventoryUpdate(SyncIDictionary <Vector2Byte, ItemData> .Operation op, Vector2Byte key, ItemData item)
        {
            switch (op)
            {
            case SyncIDictionary <Vector2Byte, ItemData> .Operation.OP_ADD:
            case SyncIDictionary <Vector2Byte, ItemData> .Operation.OP_SET:
                InventorySystem.Instance.OnInventoryUpdate(key, item);
                break;

            case SyncIDictionary <Vector2Byte, ItemData> .Operation.OP_REMOVE:
                InventorySystem.DropItem(key);
                break;
            }
        }
Exemplo n.º 14
0
 public virtual void UseItem(Vector2Byte position)
 {
     Player.localPlayer.CmdUseItem(position);
 }
Exemplo n.º 15
0
        public void CmdSetEquipment(EquipmentSlot ID, ItemData itemData, Vector2Byte position)
        {
            if (ID < 0 || (int)ID > 4)
            {
                return;
            }

            Item item = ObjectDatabase.GetItem(itemData.ID);

            if (item && item is Equipment)
            {
                Equipment equipment    = (Equipment)item;
                Equipment oldEquipment = null;

                // add new equipment
                if (equipmentData.ContainsKey(ID))
                {
                    oldEquipment      = (Equipment)ObjectDatabase.GetItem(equipmentData[ID].ID);
                    equipmentData[ID] = itemData;
                }
                else
                {
                    equipmentData.Add(ID, itemData);
                }

                if (item.GetType() == typeof(Weapon))
                {
                    usedWeapon   = (Weapon)item;
                    usedWeaponID = item.ID;
                }

                Armor        += equipment.ArmorBonus;
                maxHealth    += equipment.HealthBonus;
                Strength     += equipment.StrengthBonus;
                Intelligence += equipment.IntelligenceBonus;
                Stamina      += equipment.StaminaBonus;

                inventoryData.Remove(position);

                // remove old equipment
                if (oldEquipment)
                {
                    Armor     -= oldEquipment.ArmorBonus;
                    maxHealth -= oldEquipment.HealthBonus;
                    if (Health > maxHealth)
                    {
                        Health = maxHealth;
                    }
                    Strength     -= oldEquipment.StrengthBonus;
                    Intelligence -= oldEquipment.IntelligenceBonus;
                    Stamina      -= oldEquipment.StaminaBonus;

                    ItemData newItemData = new ItemData(oldEquipment.ID, 1);
                    if (!inventoryData.ContainsKey(position))
                    {
                        inventoryData.Add(position, newItemData);
                    }
                    else
                    {
                        AddItem(newItemData);
                    }
                }
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Возвращает рейтинг по локальным координатам
 /// </summary>
 /// <param name="pos"></param>
 /// <returns></returns>
 public ushort GetRating(Vector2Byte pos)
 {
     return(GetRating(GetCellItemIndex(pos)));
 }
Exemplo n.º 17
0
 public void CmdRemoveItem(Vector2Byte position, short count)
 {
     RemoveItem(position, count);
 }
Exemplo n.º 18
0
        public bool AddItem(ItemData item)
        {
            int   max   = InventorySystem.Instance.maxCellCapacity;
            short toAdd = item.Count;

            if (item.ID < 10000)
            {
                for (int x = 0; x < InventorySystem.Instance.inventorySize.x; x++)
                {
                    for (int y = 0; y < InventorySystem.Instance.inventorySize.y; y++)
                    {
                        Vector2Byte key = new Vector2Byte(x, y);
                        if (inventoryData.ContainsKey(key))
                        {
                            if (toAdd == 0)
                            {
                                break;
                            }
                            ItemData nItem = inventoryData[key];
                            if (nItem.ID == item.ID && nItem.Count < max)
                            {
                                short res = (short)(max - nItem.Count);
                                if (res <= toAdd)
                                {
                                    inventoryData[key] = new ItemData(nItem.ID, (short)(nItem.Count + res));
                                    toAdd -= res;
                                }
                                else
                                {
                                    inventoryData[key] = new ItemData(nItem.ID, (short)(nItem.Count + toAdd));
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            if (toAdd > 0)
            {
                Vector2Int?pos = InventorySystem.Instance.FindFirstPosition(inventoryData);
                if (pos != null)
                {
                    Vector2Int  position     = (Vector2Int)pos;
                    Vector2Byte itemPosition = new Vector2Byte(position.x, position.y);

                    if (!inventoryData.ContainsKey(itemPosition))
                    {
                        ItemData itemData = new ItemData()
                        {
                            ID    = item.ID,
                            Count = toAdd,
                        };
                        inventoryData.Add(itemPosition, itemData);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 19
0
 public void CmdDropItem(Vector2Byte position)
 {
     DropItem(position);
 }