示例#1
0
    public void useItem(int x, int y, int amount)
    {
        if (!ItemStackable.getStackable(this.items[x, y].id))
        {
            Inventory weight = this;
            weight.weight = weight.weight - ItemWeight.getWeight(this.items[x, y].id);
            this.syncWeight();
            this.items[x, y].id     = -1;
            this.items[x, y].amount = 0;
            this.items[x, y].state  = string.Empty;
        }

        else
        {
            Inventory inventory = this;
            inventory.weight = inventory.weight - ItemWeight.getWeight(this.items[x, y].id) * amount;
            this.syncWeight();
            this.items[x, y].amount = this.items[x, y].amount - amount;
            if (this.items[x, y].amount == 0)
            {
                this.items[x, y].id     = -1;
                this.items[x, y].amount = 0;
                this.items[x, y].state  = string.Empty;
            }
        }
    }
示例#2
0
 public void sendDeleteItem(int x, int y)
 {
     if (!Network.isServer)
     {
         if (!ItemStackable.getStackable(this.items[x, y].id))
         {
             Inventory weight = this;
             weight.weight = weight.weight - ItemWeight.getWeight(this.items[x, y].id);
         }
         else
         {
             Inventory inventory = this;
             inventory.weight = inventory.weight - ItemWeight.getWeight(this.items[x, y].id) * this.items[x, y].amount;
         }
         this.items[x, y].id     = -1;
         this.items[x, y].amount = 0;
         this.items[x, y].state  = string.Empty;
         base.networkView.RPC("askDeleteItem", RPCMode.Server, new object[] { x, y });
     }
     else
     {
         this.deleteItem(x, y);
         this.syncItem(x, y);
     }
 }
示例#3
0
 public void sendUseItem(int x, int y)
 {
     if (!Network.isServer)
     {
         Inventory weight = this;
         weight.weight = weight.weight - ItemWeight.getWeight(this.items[x, y].id);
         if (!ItemStackable.getStackable(this.items[x, y].id))
         {
             this.items[x, y].amount = 0;
         }
         else
         {
             this.items[x, y].amount = this.items[x, y].amount - 1;
         }
         if (this.items[x, y].amount == 0)
         {
             this.items[x, y].id     = -1;
             this.items[x, y].amount = 0;
             this.items[x, y].state  = string.Empty;
         }
         base.networkView.RPC("askUseItem", RPCMode.Server, new object[] { x, y });
     }
     else
     {
         this.askUseItem(x, y);
     }
 }
示例#4
0
    public int hasSpace(ServerItem item)
    {
        if (ItemWeight.getWeight(item.id) == -1000)
        {
            return(1);
        }
        if (this.weight + ItemWeight.getWeight(item.id) > this.capacity)
        {
            return(2);
        }
        if (!ItemStackable.getStackable(item.id))
        {
            if (this.search(-1).x != -1)
            {
                return(0);
            }
            return(1);
        }
        Point2 point2 = this.search(item.id);

        if (point2.x != -1 && this.items[point2.x, point2.y].amount < Inventory.MAX_STACK)
        {
            return(0);
        }
        point2 = this.search(-1);
        if (point2.x != -1)
        {
            return(0);
        }
        return(1);
    }
示例#5
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);
        }
    }
示例#6
0
 public void askDrag(int x_0, int y_0, int x_1, int y_1, bool all)
 {
     if (x_0 != x_1 || y_0 != y_1)
     {
         ClientItem clientItem  = this.items[x_0, y_0];
         ClientItem clientItem1 = this.items[x_1, y_1];
         if (clientItem.id == clientItem1.id && ItemStackable.getStackable(clientItem.id) && (x_0 != x_1 || y_0 != y_1))
         {
             if (this.items[x_1, y_1].amount <= Inventory.MAX_STACK)
             {
                 this.items[x_1, y_1].amount = this.items[x_1, y_1].amount + clientItem.amount;
                 if (this.items[x_1, y_1].amount <= Inventory.MAX_STACK)
                 {
                     this.items[x_0, y_0].id     = -1;
                     this.items[x_0, y_0].amount = 0;
                     this.items[x_0, y_0].state  = string.Empty;
                 }
                 else
                 {
                     this.items[x_0, y_0].amount = this.items[x_1, y_1].amount - Inventory.MAX_STACK;
                     this.items[x_1, y_1].amount = Inventory.MAX_STACK;
                 }
             }
             else
             {
                 this.items[x_0, y_0] = clientItem1;
                 this.items[x_1, y_1] = clientItem;
             }
         }
         else if (all)
         {
             this.items[x_0, y_0] = clientItem1;
             this.items[x_1, y_1] = clientItem;
         }
         else if (clientItem1.id != -1 || !ItemStackable.getStackable(clientItem.id))
         {
             this.items[x_0, y_0] = clientItem1;
             this.items[x_1, y_1] = clientItem;
         }
         else
         {
             this.items[x_1, y_1] = clientItem;
             if (clientItem.amount <= 1)
             {
                 this.items[x_0, y_0] = clientItem1;
             }
             else
             {
                 this.items[x_1, y_1].amount = Mathf.FloorToInt((float)clientItem.amount / 2f);
                 this.items[x_0, y_0].amount = Mathf.CeilToInt((float)clientItem.amount / 2f);
             }
         }
         this.syncItem(x_0, y_0);
         this.syncItem(x_1, y_1);
     }
 }
示例#7
0
 public Point2 search(int id)
 {
     for (int i = 0; i < this.height; i++)
     {
         for (int j = 0; j < this.width; j++)
         {
             if (this.items[j, i].id == id && (!ItemStackable.getStackable(id) || this.items[j, i].amount < Inventory.MAX_STACK))
             {
                 return(new Point2(j, i));
             }
         }
     }
     return(Point2.NONE);
 }
示例#8
0
 public void deleteItem(int x, int y)
 {
     if (!ItemStackable.getStackable(this.items[x, y].id))
     {
         Inventory weight = this;
         weight.weight = weight.weight - ItemWeight.getWeight(this.items[x, y].id);
     }
     else
     {
         Inventory inventory = this;
         inventory.weight = inventory.weight - ItemWeight.getWeight(this.items[x, y].id) * this.items[x, y].amount;
     }
     this.syncWeight();
     this.items[x, y].id     = -1;
     this.items[x, y].amount = 0;
     this.items[x, y].state  = string.Empty;
 }
示例#9
0
 public static void use()
 {
     if (!Player.life.dead)
     {
         if (!ItemStackable.getStackable(Equipment.id) || Player.inventory.items[Equipment.equipped.x, Equipment.equipped.y].amount <= 1)
         {
             Player.inventory.sendUseItem(Equipment.equipped.x, Equipment.equipped.y);
             Equipment.dequip();
         }
         else
         {
             Player.inventory.sendUseItem(Equipment.equipped.x, Equipment.equipped.y);
             int num  = Equipment.equipped.x;
             int num1 = Equipment.equipped.y;
             Equipment.dequip();
             Equipment.equip(num, num1);
         }
     }
 }
示例#10
0
 public void addItem(ServerItem item)
 {
     if (ItemWeight.getWeight(item.id) != -1000)
     {
         if (!ItemStackable.getStackable(item.id))
         {
             Point2 point2 = this.search(-1);
             if (point2.x != -1)
             {
                 this.items[point2.x, point2.y] = new ClientItem(item);
                 Inventory weight = this;
                 weight.weight = weight.weight + ItemWeight.getWeight(item.id);
                 this.syncItem(point2.x, point2.y);
                 this.syncWeight();
             }
         }
         else
         {
             Point2 point21 = this.search(item.id);
             if (point21.x == -1 || this.items[point21.x, point21.y].amount >= Inventory.MAX_STACK)
             {
                 point21 = this.search(-1);
                 if (point21.x != -1)
                 {
                     this.items[point21.x, point21.y] = new ClientItem(item);
                     Inventory inventory = this;
                     inventory.weight = inventory.weight + ItemWeight.getWeight(item.id) * item.amount;
                     this.syncItem(point21.x, point21.y);
                     this.syncWeight();
                 }
             }
             else
             {
                 this.items[point21.x, point21.y].amount = this.items[point21.x, point21.y].amount + item.amount;
                 Inventory weight1 = this;
                 weight1.weight = weight1.weight + ItemWeight.getWeight(item.id) * item.amount;
                 this.syncItem(point21.x, point21.y);
                 this.syncWeight();
             }
         }
     }
 }
示例#11
0
    public void askDrop(int x, int y, bool all, NetworkPlayer player)
    {
        GameObject playerModel = NetworkUserList.getModelFromPlayer(player);

        if (playerModel != null)
        {
            Inventory inventory = playerModel.GetComponent <Inventory>();
            if (x >= 0 && y >= 0 && x < inventory.width && y < inventory.height && inventory.items[x, y].amount > 0)
            {
                Vector3 position = inventory.transform.position;
                if (inventory.transform.GetComponent <Player>().vehicle != null)
                {
                    position = inventory.transform.GetComponent <Player>().vehicle.getPosition();
                }
                if (!ItemStackable.getStackable(inventory.items[x, y].id))
                {
                    SpawnItems.drop(inventory.items[x, y].id, inventory.items[x, y].amount, inventory.items[x, y].state, position);
                    inventory.useItem(x, y);
                }
                else if (!all)
                {
                    SpawnItems.drop(inventory.items[x, y].id, 1, inventory.items[x, y].state, position);
                    inventory.useItem(x, y);
                }
                else
                {
                    for (int i = 0; i < inventory.items[x, y].amount; i++)
                    {
                        SpawnItems.drop(inventory.items[x, y].id, 1, inventory.items[x, y].state, position);
                    }
                    inventory.deleteItem(x, y);
                }
                inventory.syncItem(x, y);
                NetworkSounds.askSound("Sounds/General/drop", position, 0.2f, UnityEngine.Random.Range(0.9f, 1.1f), 1f);
            }
        }
    }
示例#12
0
    public void resize(int setWidth, int setHeight, int setCapacity)
    {
        ClientItem[,] clientItem = new ClientItem[setWidth, setHeight];
        int weight = 0;

        for (int i = 0; i < setWidth; i++)
        {
            for (int j = 0; j < setHeight; j++)
            {
                clientItem[i, j] = new ClientItem(-1, 0, string.Empty);
            }
        }
        if (this.items != null)
        {
            Vector3 position = base.transform.position;

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

            for (int k = 0; k < this.width; k++)
            {
                for (int l = 0; l < this.height; l++)
                {
                    if (k < setWidth && l < setHeight)
                    {
                        if (this.items[k, l].id != -1)
                        {
                            if (ItemStackable.getStackable(this.items[k, l].id))
                            {
                                clientItem[k, l]        = this.items[k, l];
                                clientItem[k, l].amount = 0;

                                for (int m = 0; m < this.items[k, l].amount; m++)
                                {
                                    if (weight + ItemWeight.getWeight(this.items[k, l].id) > setCapacity)
                                    {
                                        SpawnItems.drop(this.items[k, l].id, 1, this.items[k, l].state, position + new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), 0f, UnityEngine.Random.Range(-1.5f, 1.5f)));
                                    }
                                    else
                                    {
                                        clientItem[k, l].amount = clientItem[k, l].amount + 1;
                                        weight = weight + ItemWeight.getWeight(this.items[k, l].id);
                                    }
                                }

                                if (clientItem[k, l].amount == 0)
                                {
                                    clientItem[k, l].id    = -1;
                                    clientItem[k, l].state = string.Empty;
                                }
                            }
                            else if (weight + ItemWeight.getWeight(this.items[k, l].id) > setCapacity)
                            {
                                SpawnItems.drop(this.items[k, l].id, this.items[k, l].amount, this.items[k, l].state, position + new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), 0f, UnityEngine.Random.Range(-1.5f, 1.5f)));
                            }
                            else
                            {
                                clientItem[k, l] = this.items[k, l];
                                weight           = weight + ItemWeight.getWeight(this.items[k, l].id);
                            }
                        }
                    }
                    else if (this.items[k, l].id != -1)
                    {
                        if (!ItemStackable.getStackable(this.items[k, l].id))
                        {
                            SpawnItems.drop(this.items[k, l].id, this.items[k, l].amount, this.items[k, l].state, position + new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), 0f, UnityEngine.Random.Range(-1.5f, 1.5f)));
                        }
                        else
                        {
                            for (int n = 0; n < this.items[k, l].amount; n++)
                            {
                                SpawnItems.drop(this.items[k, l].id, 1, this.items[k, l].state, position + new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), 0f, UnityEngine.Random.Range(-1.5f, 1.5f)));
                            }
                        }
                    }
                }
            }
        }

        this.width    = setWidth;
        this.height   = setHeight;
        this.weight   = weight;
        this.capacity = setCapacity;

        if (base.networkView.owner != Network.player)
        {
            base.networkView.RPC("syncSize", base.networkView.owner, new object[] { this.width, this.height, this.capacity });
        }
        else
        {
            this.syncSize_Pizza(this.width, this.height, this.capacity);
        }

        this.items = clientItem;
        for (int o = 0; o < this.width; o++)
        {
            for (int p = 0; p < this.height; p++)
            {
                this.syncItem(o, p);
            }
        }
    }
示例#13
0
    public void drop()
    {
        //this.resize(0, 0, 0);
        Vector3 position = base.transform.position;

        int maxItems       = height * width;
        int droppableItems = (int)(maxItems * 0.60);

        List <int> list = new List <int>();

        int i = 0;

        do
        {
            int rand = UnityEngine.Random.Range(0, maxItems - 1);
            if (!list.Contains(rand))
            {
                list.Add(rand);
                i++;
            }
        } while (i < droppableItems);

        foreach (int item in list)
        {
            int itemX = item / height;
            int itemY = item % height;

            try {
                if (!ItemStackable.getStackable(this.items[itemX, itemY].id))
                {
                    SpawnItems.drop(this.items[itemX, itemY].id, this.items[itemX, itemY].amount, this.items[itemX, itemY].state, position + new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), 0f, UnityEngine.Random.Range(-1.5f, 1.5f)));
                }
                else
                {
                    for (int n = 0; n < this.items[itemX, itemY].amount; n++)
                    {
                        SpawnItems.drop(
                            this.items[itemX, itemY].id,
                            1,
                            this.items[itemX, itemY].state,
                            position + new Vector3(UnityEngine.Random.Range(-1.5f, 1.5f), 0f, UnityEngine.Random.Range(-1.5f, 1.5f))
                            );
                    }
                }

                this.items[itemX, itemY].amount = 0;
                this.items[itemX, itemY].id     = -1;
                this.items[itemX, itemY].state  = String.Empty;
            }
            catch (Exception e)
            {
                Console.WriteLine("Error while dropping item: " + e.Data + " X: " + itemX + " Y:" + itemY);
            }
        }

        weight = 0;
        for (int itemX = 0; itemX < this.width; itemX++)
        {
            for (int itemY = 0; itemY < this.height; itemY++)
            {
                this.syncItem(itemX, itemY);
                this.weight += ItemWeight.getWeight(this.items[itemX, itemY].id) * this.items[itemX, itemY].amount;
            }
        }

        this.syncWeight();
    }
示例#14
0
    public void destroyBarricade(Vector3 position)
    {
        int indexFromPositionServer;

        ClientItem[,] crateItems;
        Point2  region  = NetworkRegions.getRegion(position);
        bool    flag    = false;
        int     item    = -1;
        Vector3 vector3 = Vector3.zero;

        if (Network.isServer)
        {
            indexFromPositionServer = SpawnBarricades.getIndexFromPositionServer(region, position);
            if (SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id == 16019 || SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id == 16025 || SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id == 16023)
            {
                if (SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id != 16019)
                {
                    string[] strArrays = Packer.unpack(SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].state, '\u005F');
                    crateItems = InteractionInterface.getCrateItems(SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id, Sneaky.expose(strArrays[2]));
                }
                else
                {
                    crateItems = InteractionInterface.getCrateItems(SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id, Sneaky.expose(SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].state));
                }
                for (int i = 0; i < 2; i++)
                {
                    for (int j = 0; j < BarricadeStats.getCapacity(SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id); j++)
                    {
                        if (!ItemStackable.getStackable(crateItems[i, j].id))
                        {
                            SpawnItems.drop(crateItems[i, j].id, crateItems[i, j].amount, crateItems[i, j].state, position);
                        }
                        else
                        {
                            for (int k = 0; k < crateItems[i, j].amount; k++)
                            {
                                SpawnItems.drop(crateItems[i, j].id, 1, crateItems[i, j].state, position);
                            }
                        }
                    }
                }
            }
            else if (ExplosiveStats.getDamage(SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id) != 0)
            {
                flag = true;
                item = SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id;
                if (SpawnBarricades.regions[region.x, region.y].barricades[indexFromPositionServer].id != 16015)
                {
                    vector3 = position + Vector3.up;
                    NetworkEffects.askEffect("Effects/grenade", position, Quaternion.Euler(-90f, 0f, 0f), -1f);
                    NetworkSounds.askSoundMax("Sounds/Projectiles/grenade", position, 1f, UnityEngine.Random.Range(0.95f, 1.05f), 4f, 64f);
                }
                else
                {
                    vector3 = position + SpawnBarricades.regions[region.x, region.y].models[indexFromPositionServer].transform.up;
                    NetworkEffects.askEffect("Effects/bomb", position, Quaternion.Euler(-90f, 0f, 0f), -1f);
                    NetworkSounds.askSoundMax("Sounds/Projectiles/bomb", position, 1f, UnityEngine.Random.Range(0.95f, 1.05f), 4f, 64f);
                }
            }
            if (indexFromPositionServer != -1 && indexFromPositionServer < SpawnBarricades.regions[region.x, region.y].barricades.Count)
            {
                SpawnBarricades.regions[region.x, region.y].barricades.RemoveAt(indexFromPositionServer);
            }
        }
        indexFromPositionServer = SpawnBarricades.getIndexFromPositionClient(region, position);
        if (indexFromPositionServer != -1 && indexFromPositionServer < SpawnBarricades.regions[region.x, region.y].models.Count)
        {
            UnityEngine.Object.Destroy(SpawnBarricades.regions[region.x, region.y].models[indexFromPositionServer]);
            SpawnBarricades.regions[region.x, region.y].models.RemoveAt(indexFromPositionServer);
        }
        if (flag)
        {
            ExplosionTool.explode(vector3, (float)ExplosiveStats.getRange(item), ExplosiveStats.getDamage(item));
        }
    }