public void SpawnVanityItems() { if (spawnVanityItems) { foreach (GameObject tileGo in DungeonGenerator.instance.GetTiles()) { Tile tile = tileGo.GetComponent <Tile>(); // if the tile is not floor or it is a trap // -> continue. if (tile.myType != Tile.TileType.Floor || tileGo.GetComponent <Trap>() != null) { continue; } if (Random.Range(0, 100) > 100 - vanityitemCoverage) { if (tile.vanityItem == null) { VanityItem item = RandomVanityItem(); while (item == VanityItem.Blood) { item = RandomVanityItem(); } SpawnVanityItem(item, tile.position); } } } } }
private VanityItem RandomVanityItem() { System.Array values = System.Enum.GetValues(typeof(VanityItem)); VanityItem item = (VanityItem)values.GetValue(Random.Range(0, values.Length)); return(item); }
public void SpawnVanityItem(VanityItem item, Vector2 pos) { if (parentGo == null) { parentGo = new GameObject("VanityItems"); } GameObject vanityItemPrefab = null; switch (item) { case VanityItem.Candle: vanityItemPrefab = burntCandlePrefab; break; case VanityItem.Lantern: vanityItemPrefab = lantern01Prefab; break; case VanityItem.Skull: vanityItemPrefab = skull01Prefab; break; case VanityItem.Blood: vanityItemPrefab = bloodPrefab; break; default: Debug.LogError("No such item."); break; } GameObject inst = (GameObject)Instantiate(vanityItemPrefab); inst.transform.position = new Vector3(pos.x, pos.y, GameMaster.instance.vanityitemsZLevel); if (randomizeItemOffset) { Vector2 offset = new Vector2(Random.Range(-offsetAmount, offsetAmount), Random.Range(-offsetAmount, offsetAmount)); inst.transform.position = new Vector3(pos.x + offset.x, pos.y + offset.y, GameMaster.instance.vanityitemsZLevel); } else { inst.transform.position = new Vector3(pos.x, pos.y, GameMaster.instance.vanityitemsZLevel); } inst.transform.SetParent(parentGo.transform); DungeonGenerator.instance.GetTileAtPos(pos).GetComponent <Tile>().vanityItem = inst; InstantiatedVanityItems.Add(inst); }
/// <summary> /// Open this instance. /// Chest cannot drop legendary or rare loot! /// Hardcoded /// </summary> public void Open() { // Detach this item from tile. DungeonGenerator.instance.UpdateTileItem(position, null); // attach this to vanity item slot. DungeonGenerator.instance.UpdateVanityItem(position, this.gameObject); VanityItem vi = gameObject.AddComponent <VanityItem>(); vi.position = position; // stop bouncing effect. Destroy(GetComponent <ItemBounce>()); // randomize loot type Item.Type randomType = PrefabManager.instance.RandomizeItemType(); while (randomType == Type.Container) { randomType = PrefabManager.instance.RandomizeItemType(); } // randomize loot rarity. Item.Rarity randomRarity = PrefabManager.instance.RandomizeItemRarity(); while (randomRarity == Item.Rarity.Legendary || randomRarity == Item.Rarity.Rare) { randomRarity = PrefabManager.instance.RandomizeItemRarity(); } // instantiate random type of loot. PrefabManager.instance.InstantiateRandomItemInCategory(randomType, position, randomRarity); // Update the sprite. updateGraphics(); // play sound effect SoundManager.instance.PlaySound(SoundManager.Sound.OpenChest); }