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); } } }
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); } } }
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); } } }
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(); }
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)); } }
public static void dropItem(int id, Vector3 position) { SpawnItems.drop(id, ItemAmount.getAmount(id), ItemState.getState(id), position); }