Exemplo n.º 1
0
    public void UpdateItems()
    {
        for (int i = 0; i < this.height * this.width; i++)
        {
            int bagX = i % this.width;
            int bagY = i / this.width;

            if (ItemStackable.getStackable(this.items[bagX, bagY].id) && this.items[bagX, bagY].amount > Inventory.MAX_STACK)
            {
                this.items[bagX, bagY].amount = Inventory.MAX_STACK;
            }
            else if (ItemType.getType(this.items[bagX, bagY].id) == 10 && this.items[bagX, bagY].amount > ItemAmount.getAmount(this.items[bagX, bagY].id))
            {
                this.items[bagX, bagY].amount = ItemAmount.getAmount(this.items[bagX, bagY].id);
            }
            else if (ItemType.getType(this.items[bagX, bagY].id) == 7)
            {
                if (this.items[bagX, bagY].state == string.Empty)
                {
                    this.items[bagX, bagY].id     = -1;
                    this.items[bagX, bagY].amount = 0;
                    this.items[bagX, bagY].state  = string.Empty;
                }
                else
                {
                    string[] itemStateArray = Packer.unpack(this.items[bagX, bagY].state, '\u005F');
                    int      bullets        = int.Parse(itemStateArray[0]);
                    int      ammoType       = int.Parse(itemStateArray[1]);

                    if (!AmmoStats.getGunCompatible(this.items[bagX, bagY].id, ammoType))
                    {
                        ammoType = -1;
                        bullets  = 0;
                    }
                    else if (bullets > AmmoStats.getCapacity(this.items[bagX, bagY].id, ammoType))
                    {
                        bullets = 0;
                    }

                    object[] objArray = new object[] { bullets, "_", ammoType, "_", itemStateArray[2], "_", itemStateArray[3], "_", itemStateArray[4], "_", itemStateArray[5], "_", itemStateArray[6], "_" };
                    this.items[bagX, bagY].state = string.Concat(objArray);
                }
            }

            if (this.items[bagX, bagY].id != -1)
            {
                if (!ItemStackable.getStackable(this.items[bagX, bagY].id))
                {
                    Inventory weight = this;
                    weight.weight = weight.weight + ItemWeight.getWeight(this.items[bagX, bagY].id);
                }
                else
                {
                    Inventory inventory = this;
                    inventory.weight = inventory.weight + ItemWeight.getWeight(this.items[bagX, bagY].id) * this.items[bagX, bagY].amount;
                }
            }
            this.syncItem(bagX, bagY);
        }
    }
Exemplo n.º 2
0
 public void askCraft(int x_0, int y_0, int x_1, int y_1, int xTool, int yTool, int mode, bool all)
 {
     if (!base.GetComponent <Life>().dead&& (x_0 == -1 || this.items[x_0, y_0].id != -1) && (x_1 == -1 || this.items[x_1, y_1].id != -1) && (xTool == -1 || this.items[xTool, yTool].id != -1))
     {
         if (x_0 == -1 || x_1 == -1 || ItemType.getType(this.items[x_0, y_0].id) != 10 || ItemType.getType(this.items[x_1, y_1].id) != 10 || !AmmoStats.getCaliberCompatible(this.items[x_0, y_0].id, this.items[x_1, y_1].id) || this.items[x_0, y_0].amount <= 1 || this.items[x_1, y_1].amount <= 1)
         {
             bool flag  = Cooking.fire(base.transform.position);
             bool flag1 = false;
             int  num   = 0;
             while (num < (int)Blueprints.prints.Length)
             {
                 if (!flag1)
                 {
                     Blueprint blueprint = Blueprints.prints[num];
                     if ((mode == 0 && !blueprint.fire || mode == 1 && blueprint.fire && flag) && (blueprint.knowledge == 0f || base.GetComponent <Skills>().crafting() >= blueprint.knowledge) && ((blueprint.id_0 == -1 && x_0 == -1 || x_0 != -1 && blueprint.id_0 == this.items[x_0, y_0].id) && (blueprint.id_1 == -1 && x_1 == -1 || x_1 != -1 && blueprint.id_1 == this.items[x_1, y_1].id) || (blueprint.id_0 == -1 && x_1 == -1 || x_1 != -1 && blueprint.id_0 == this.items[x_1, y_1].id) && (blueprint.id_1 == -1 && x_0 == -1 || x_0 != -1 && blueprint.id_1 == this.items[x_0, y_0].id)) && (blueprint.idTool == -1 && xTool == -1 || xTool != -1 && blueprint.idTool == this.items[xTool, yTool].id))
                     {
                         int num1 = 0;
                         while (true)
                         {
                             if ((blueprint.id_0 == -1 && x_0 == -1 || x_0 != -1 && blueprint.id_0 == this.items[x_0, y_0].id && this.items[x_0, y_0].amount >= blueprint.amount_0) && (blueprint.id_1 == -1 && x_1 == -1 || x_1 != -1 && blueprint.id_1 == this.items[x_1, y_1].id && this.items[x_1, y_1].amount >= blueprint.amount_1) && (blueprint.idTool == -1 && xTool == -1 || xTool != -1 && blueprint.idTool == this.items[xTool, yTool].id))
                             {
                                 if (x_0 != -1)
                                 {
                                     this.useItem(x_0, y_0, blueprint.amount_0);
                                 }
                                 if (x_1 != -1)
                                 {
                                     this.useItem(x_1, y_1, blueprint.amount_1);
                                 }
                                 num1++;
                             }
                             else if ((blueprint.id_0 != -1 || x_1 != -1) && (x_1 == -1 || blueprint.id_0 != this.items[x_1, y_1].id || this.items[x_1, y_1].amount < blueprint.amount_0) || (blueprint.id_1 != -1 || x_0 != -1) && (x_0 == -1 || blueprint.id_1 != this.items[x_0, y_0].id || this.items[x_0, y_0].amount < blueprint.amount_1) || (blueprint.idTool != -1 || xTool != -1) && (xTool == -1 || blueprint.idTool != this.items[xTool, yTool].id))
                             {
                                 break;
                             }
                             else
                             {
                                 if (x_1 != -1)
                                 {
                                     this.useItem(x_1, y_1, blueprint.amount_0);
                                 }
                                 if (x_0 != -1)
                                 {
                                     this.useItem(x_0, y_0, blueprint.amount_1);
                                 }
                                 num1++;
                             }
                             if (!all || ItemType.getType(blueprint.id_0) == 10 || ItemType.getType(blueprint.id_1) == 10)
                             {
                                 break;
                             }
                         }
                         for (int i = 0; i < num1; i++)
                         {
                             this.tryAddItem(blueprint.idReward, blueprint.amountReward);
                         }
                         flag1 = true;
                     }
                     num++;
                 }
                 else
                 {
                     if (x_0 != -1)
                     {
                         this.syncItem(x_0, y_0);
                     }
                     if (x_1 != -1)
                     {
                         this.syncItem(x_1, y_1);
                     }
                     NetworkSounds.askSound("Sounds/General/craft", base.transform.position, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 1f);
                     break;
                 }
             }
         }
         else
         {
             int num2    = this.items[x_0, y_0].id;
             int num3    = this.items[x_1, y_1].id;
             int amount  = this.items[x_0, y_0].amount;
             int amount1 = this.items[x_1, y_1].amount;
             amount1 = amount1 + (this.items[x_0, y_0].amount - 1);
             if (amount1 <= ItemAmount.getAmount(this.items[x_1, y_1].id))
             {
                 num2 = -1;
             }
             else
             {
                 amount  = amount1 - ItemAmount.getAmount(this.items[x_1, y_1].id) + 1;
                 amount1 = ItemAmount.getAmount(this.items[x_1, y_1].id);
             }
             this.deleteItem(x_0, y_0);
             this.deleteItem(x_1, y_1);
             this.syncItem(x_0, y_0);
             this.syncItem(x_1, y_1);
             if (num2 != -1)
             {
                 this.tryAddItem(num2, amount, string.Empty);
             }
             if (num3 != -1)
             {
                 this.tryAddItem(num3, amount1, string.Empty);
             }
             NetworkSounds.askSound("Sounds/General/craft", base.transform.position, 0.5f, UnityEngine.Random.Range(0.9f, 1.1f), 1f);
         }
     }
 }