示例#1
0
    public void tryAddItem(int id, int amount)
    {
        if (ItemWeight.getWeight(id) != -1000)
        {
            ServerItem serverItem = new ServerItem(id, ItemAmount.getAmount(id), ItemState.getState(id), Vector3.zero);
            Vector3    position   = base.transform.position;

            if (base.GetComponent <Player>().vehicle != null)
            {
                position = base.GetComponent <Player>().vehicle.getPosition();
            }

            for (int i = 0; i < amount; i++)
            {
                if (this.hasSpace(serverItem) != 0)
                {
                    SpawnItems.dropItem(id, position);
                }
                else
                {
                    this.addItem(serverItem);
                }
            }
        }
    }
示例#2
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);
        }
    }
示例#3
0
    public static int getCapacity(int gun, int ammo)
    {
        int num = gun;

        switch (num)
        {
        case 7002:
        {
            return(2);
        }

        case 7004:
        {
            return(1);
        }

        case 7005:
        {
            return(5);
        }

        case 7007:
        {
            return(1);
        }

        case 7014:
        {
            return(1);
        }

        case 7015:
        {
            return(ItemAmount.getAmount(ammo) - 1);
        }

        case 7016:
        {
            return(4);
        }

        default:
        {
            return(ItemAmount.getAmount(ammo) - 1);
        }
        }
    }
示例#4
0
 public static void reset()
 {
     for (int i = 0; i < NetworkRegions.REGION_X; i++)
     {
         for (int j = 0; j < NetworkRegions.REGION_Y; j++)
         {
             Vector3[] item = new Vector3[SpawnItems.regions[i, j].items.Count];
             for (int k = 0; k < (int)item.Length; k++)
             {
                 item[k] = SpawnItems.regions[i, j].items[k].position;
             }
             for (int l = 0; l < (int)item.Length; l++)
             {
                 SpawnItems.tool.networkView.RPC("destroyItem", RPCMode.All, new object[] { item[l] });
             }
         }
     }
     for (int m = 0; m < SpawnItems.model.transform.FindChild("spawns").childCount; m++)
     {
         if ((ServerSettings.mode == 0 || ServerSettings.mode == 1) && UnityEngine.Random.@value > Loot.NORMAL_ITEM_CHANCE || ServerSettings.mode == 2 && UnityEngine.Random.@value > Loot.HARDCORE_ITEM_CHANCE || ServerSettings.mode == 3 && UnityEngine.Random.@value > Loot.GOLD_ITEM_CHANCE)
         {
             Transform child = SpawnItems.model.transform.FindChild("spawns").GetChild(m);
             int       loot  = Loot.getLoot(child.name);
             if (ItemWeight.getWeight(loot) != -1000)
             {
                 int type = ItemType.getType(loot);
                 if (type == 10)
                 {
                     SpawnItems.spawnItem(loot, UnityEngine.Random.Range(1, ItemAmount.getAmount(loot) + 1), child.position);
                 }
                 else if (type != 25)
                 {
                     SpawnItems.spawnItem(loot, ItemAmount.getAmount(loot), child.position);
                 }
                 else
                 {
                     for (int n = 0; n < UnityEngine.Random.Range(1, 4); n++)
                     {
                         SpawnItems.spawnItem(loot, ItemAmount.getAmount(loot), child.position + new Vector3(UnityEngine.Random.Range(-0.5f, 0.5f), 0f, UnityEngine.Random.Range(-0.5f, 0.5f)));
                     }
                 }
             }
         }
     }
 }
示例#5
0
    public void respawn()
    {
        Transform child = SpawnItems.model.transform.FindChild("spawns").GetChild(UnityEngine.Random.Range(0, SpawnItems.model.transform.FindChild("spawns").childCount));

        if ((int)SpawnItems.getItems(child.position, 2f).Length == 0)
        {
            int loot = Loot.getLoot(child.name);
            int type = ItemType.getType(loot);
            if (ItemWeight.getWeight(loot) != -1000 || type == 30)
            {
                if (type == 10)
                {
                    SpawnItems.spawnItem(loot, UnityEngine.Random.Range(1, ItemAmount.getAmount(loot) + 1), child.position);
                }
                else if (type == 25)
                {
                    for (int i = 0; i < UnityEngine.Random.Range(1, 4); i++)
                    {
                        SpawnItems.spawnItem(loot, ItemAmount.getAmount(loot), child.position + new Vector3(UnityEngine.Random.Range(-0.5f, 0.5f), 0f, UnityEngine.Random.Range(-0.5f, 0.5f)));
                    }
                }
                else if (loot == 30000)
                {
                    SpawnItems.spawnItem(11, 1, child.position);
                    SpawnItems.spawnItem(4017, 1, child.position);
                    SpawnItems.spawnItem(5017, 1, child.position);
                }
                else if (loot != 30001)
                {
                    SpawnItems.spawnItem(loot, ItemAmount.getAmount(loot), child.position);
                }
                else
                {
                    SpawnItems.spawnItem(12, 1, child.position);
                    SpawnItems.spawnItem(4018, 1, child.position);
                    SpawnItems.spawnItem(5018, 1, child.position);
                }
            }
        }
    }
示例#6
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);
         }
     }
 }
示例#7
0
 public void onReady()
 {
     SpawnItems.tool    = this;
     SpawnItems.model   = GameObject.Find(Application.loadedLevelName).transform.FindChild("items").gameObject;
     SpawnItems.regions = new ItemsRegion[NetworkRegions.REGION_X, NetworkRegions.REGION_Y];
     for (int i = 0; i < NetworkRegions.REGION_X; i++)
     {
         for (int j = 0; j < NetworkRegions.REGION_Y; j++)
         {
             SpawnItems.regions[i, j] = new ItemsRegion();
         }
     }
     if (Network.isServer)
     {
         int num = 0;
         for (int k = 0; k < SpawnItems.model.transform.FindChild("spawns").childCount; k++)
         {
             if (ServerSettings.mode == 0 && UnityEngine.Random.@value > Loot.NORMAL_ITEM_CHANCE || ServerSettings.mode == 1 && UnityEngine.Random.@value > Loot.BAMBI_ITEM_CHANCE || ServerSettings.mode == 2 && UnityEngine.Random.@value > Loot.HARDCORE_ITEM_CHANCE || ServerSettings.mode == 3 && UnityEngine.Random.@value > Loot.GOLD_ITEM_CHANCE)
             {
                 Transform child  = SpawnItems.model.transform.FindChild("spawns").GetChild(k);
                 Point2    region = NetworkRegions.getRegion(child.position);
                 int       loot   = Loot.getLoot(child.name);
                 int       type   = ItemType.getType(loot);
                 if (ItemWeight.getWeight(loot) != -1000 || type == 30)
                 {
                     if (type == 10)
                     {
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(loot, UnityEngine.Random.Range(1, ItemAmount.getAmount(loot) + 1), ItemState.getState(loot), child.position));
                         num++;
                     }
                     else if (type == 25)
                     {
                         for (int l = 0; l < UnityEngine.Random.Range(3, 6); l++)
                         {
                             SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(loot, ItemAmount.getAmount(loot), ItemState.getState(loot), child.position + new Vector3(UnityEngine.Random.Range(-0.5f, 0.5f), 0f, UnityEngine.Random.Range(-0.5f, 0.5f))));
                             num++;
                         }
                     }
                     else if (loot == 30000)
                     {
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(11, 1, ItemState.getState(11), child.position));
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(4017, 1, ItemState.getState(4017), child.position));
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(5017, 1, ItemState.getState(5017), child.position));
                         num = num + 3;
                     }
                     else if (loot != 30001)
                     {
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(loot, ItemAmount.getAmount(loot), ItemState.getState(loot), child.position));
                         num++;
                     }
                     else
                     {
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(12, 1, ItemState.getState(12), child.position));
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(4018, 1, ItemState.getState(4018), child.position));
                         SpawnItems.regions[region.x, region.y].items.Add(new ServerItem(5018, 1, ItemState.getState(5018), child.position));
                         num = num + 3;
                     }
                 }
             }
         }
         if (ServerSettings.map != 0)
         {
             base.InvokeRepeating("respawn", 5f, Loot.getRespawnRate() * (ServerSettings.mode != 3 ? 1f : 0.5f));
         }
     }
 }
示例#8
0
 public static void dropItem(int id, Vector3 position)
 {
     SpawnItems.drop(id, ItemAmount.getAmount(id), ItemState.getState(id), position);
 }