예제 #1
0
파일: Inventory.cs 프로젝트: Horsuna/server
 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);
     }
 }
예제 #2
0
파일: Inventory.cs 프로젝트: Horsuna/server
    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;
            }
        }
    }
예제 #3
0
파일: Inventory.cs 프로젝트: Horsuna/server
    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);
                }
            }
        }
    }
예제 #4
0
파일: Inventory.cs 프로젝트: Horsuna/server
    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
파일: Inventory.cs 프로젝트: Horsuna/server
 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);
     }
 }
예제 #6
0
파일: Inventory.cs 프로젝트: Horsuna/server
    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);
        }
    }
예제 #7
0
 public void createItemNotRPC(int id, Vector3 position)
 {
     if (ItemWeight.getWeight(id) != -1000)
     {
         GameObject str = (GameObject)UnityEngine.Object.Instantiate(Resources.Load(string.Concat("Prefabs/Items/", id)));
         str.name               = id.ToString();
         str.transform.parent   = SpawnItems.model.transform.FindChild("models");
         str.transform.position = position;
         str.transform.rotation = Quaternion.Euler(-90f, (float)UnityEngine.Random.Range(0, 360), 0f);
         Point2 region = NetworkRegions.getRegion(position);
         SpawnItems.regions[region.x, region.y].models.Add(str);
     }
 }
예제 #8
0
파일: Inventory.cs 프로젝트: Horsuna/server
 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 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)));
                     }
                 }
             }
         }
     }
 }
예제 #10
0
파일: Inventory.cs 프로젝트: Horsuna/server
 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
파일: Inventory.cs 프로젝트: Horsuna/server
 public void tryAddItem(int id, int amount, string state)
 {
     if (ItemWeight.getWeight(id) != -1000)
     {
         ServerItem serverItem = new ServerItem(id, amount, state, Vector3.zero);
         if (this.hasSpace(serverItem) != 0)
         {
             Vector3 position = base.transform.position;
             if (base.GetComponent <Player>().vehicle != null)
             {
                 position = base.GetComponent <Player>().vehicle.getPosition();
             }
             SpawnItems.drop(id, amount, state, position);
         }
         else
         {
             this.addItem(serverItem);
         }
     }
 }
예제 #12
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);
                }
            }
        }
    }
예제 #13
0
파일: Inventory.cs 프로젝트: Horsuna/server
    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);
            }
        }
    }
예제 #14
0
파일: Inventory.cs 프로젝트: Horsuna/server
    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();
    }
예제 #15
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));
         }
     }
 }