예제 #1
0
        public void SetSlot(InventoryItemType itemType, int x, int y)
        {
            CheckSlotPos(x, y);

            if (!IsItemTypeCategoryAllowed(itemType.Category))
            {
                throw new ArgumentException(string.Format("Invalid inventory item type. The item's category, {0}, is not compatible with inventory group, {1}", itemType.Category, GroupName));
            }

            MakeSlotValidInternal(x, y);
            DeleteSlotInternal(x, y);

            if (itemType.Category == InventoryItemCategory.Product)
            {
                var slot = MakeProductSlot(itemType.Id, x, y);
                ((JArray)_json.Slots).Last.AddAfterSelf(slot);
                _slots[x, y] = slot;
            }
            else if (itemType.Category == InventoryItemCategory.Substance)
            {
                var slot = MakeSubstanceSlot(itemType.Id, x, y);
                ((JArray)_json.Slots).Last.AddAfterSelf(slot);
                _slots[x, y] = slot;
            }
            else
            {
                var slot = MakeTechSlot(itemType, x, y);
                ((JArray)_json.Slots).Last.AddAfterSelf(slot);
                _slots[x, y] = slot;
            }
        }
예제 #2
0
        private JObject MakeTechSlot(InventoryItemType itemType, int x, int y)
        {
            //{
            //  "Type": {
            //    "InventoryType": "Technology"
            //  },
            //  "Id": "^JET1",
            //  "Amount": 1,
            //  "MaxAmount": 1,
            //  "DamageFactor": 0.0,
            //  "Index": {
            //    "X": 0,
            //    "Y": 0
            //  }
            //},

            var     slotObj = new JObject();
            dynamic slot    = slotObj;

            slot.Type = new JObject();
            slot.Type.InventoryType = "Technology";
            slot.Id           = itemType.Id;
            slot.Amount       = itemType.DefaultAmount;
            slot.MaxAmount    = itemType.MaxAmount;
            slot.DamageFactor = 0.0f;
            slot.Index        = new JObject();
            slot.Index.X      = x;
            slot.Index.Y      = y;

            return(slotObj);
        }
예제 #3
0
        public bool AddItemToFreeSlot(InventoryItemType itemType, out int x, out int y)
        {
            if (!_allowedCategories.Contains(itemType.Category))
            {
                throw new ArgumentException(string.Format("Inventory group does not support items of the specified type, {0}", itemType.Category));
            }

            if (!FindFreeSlot(out x, out y))
            {
                return(false);
            }

            if (itemType.Category == InventoryItemCategory.Product)
            {
                var slot = MakeProductSlot(itemType.Id, x, y);
                ((JArray)_json.Slots).Last.AddAfterSelf(slot);
                _slots[x, y] = slot;
            }
            else if (itemType.Category == InventoryItemCategory.Substance)
            {
                var slot = MakeSubstanceSlot(itemType.Id, x, y);
                ((JArray)_json.Slots).Last.AddAfterSelf(slot);
                _slots[x, y] = slot;
            }
            else
            {
                var slot = MakeTechSlot(itemType, x, y);
                ((JArray)_json.Slots).Last.AddAfterSelf(slot);
                _slots[x, y] = slot;
            }

            return(true);
        }
예제 #4
0
        public string DescribeSlot(int x, int y)
        {
            if (!_validSlots[x, y])
            {
                return(string.Format("[{0},{1}] <Invalid>", x + 1, y + 1));
            }

            var slot = _slots[x, y];

            if (slot == null)
            {
                return(string.Format("[{0},{1}] <Empty>", x + 1, y + 1));
            }

            InventoryItemType invCode = _invItemTypes[slot.Id.Value];

            if (IsSlotTechnology(slot))
            {
                if ((float)slot.DamageFactor != 0.0)
                {
                    return(string.Format("{0} ({1}), damage: {2:p0} <{3}>", invCode.Name, FormatSlotId(slot.Id), (float)slot.DamageFactor * 100.0, invCode.Category));
                }

                return(string.Format("{0} ({1}) <{2}>", invCode.Name, FormatSlotId(slot.Id), invCode.Category));
            }

            if (IsSlotSubstance(slot))
            {
                return(string.Format("{0} ({1}), {2}/{3}  <{4}>", invCode.Name, FormatSlotId(slot.Id), (int)slot.Amount, (int)slot.MaxAmount, invCode.Category));
            }

            if (IsSlotProduct(slot))
            {
                return(string.Format("{0} ({1}), {2}/{3} <{4}>", invCode.Name, FormatSlotId(slot.Id), (int)slot.Amount, (int)slot.MaxAmount, invCode.Category));
            }

            return("<Unknown>");
        }