alright i have a loot system that is based on the EnemyType and was wondering if the forum could give me critical feedback on how i did it.
Rundown : when an enemy dies it calls the LootTable() function and passes its transform and its EnemyType.
after building the loot table for that particular EnemyType, it uses a random number 0-100 ish to decide what rarity to drop, then uses ANOTHER random number to chose WHAT rare item to drop. initially each enemy was going have a chance to drop 2-3 items, but i’m thinking i should reserve that for boss loot only.
i have a question, should i build the loot table as totally random? or have a slot for rare loot and 2 slots for common loot drops? meaning common loot always drops, and there is just a chance for something less common to drop?
again critical feedback is welcome
-Lamont
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Loot : MonoBehaviour {
public ItemDatabase itemDatabase;
public List<Item> lootList = new List<Item>();
public List<Item> rareCollection = new List<Item>();
public List<Item> itemDrop = new List<Item>();
public Rigidbody2D physicalLootPrefab;
float lootRNG;
int pickerRNG;
void Start () {
itemDatabase = GetComponent<ItemDatabase> ();
}
public void LootTable(Transform enemy, EnemyStats type){
switch (type.enemyType){
case EnemyStats.EnemyType.Lowly:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Common || rarity == Item.Rarity.Uncommon || rarity == Item.Rarity.Rare ||
rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter || rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Basic:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Common || rarity == Item.Rarity.Uncommon || rarity == Item.Rarity.Rare ||
rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter || rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Hard:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Uncommon || rarity == Item.Rarity.Rare ||
rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter || rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Supporter:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Devout:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Hardned:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Crazed:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.BadAss:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.WarForged:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Insane:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.Zealot:{
lootList = new List<Item>();
for(int i = 0; i < itemDatabase.items.Count; i++){
Item.Rarity rarity = itemDatabase.items[i].itemRarity;
if(rarity == Item.Rarity.Rare || rarity == Item.Rarity.Rarer || rarity == Item.Rarity.SaughtAfter ||
rarity == Item.Rarity.Legend){
lootList.Add (itemDatabase.items[i]);
}
}
LootPicker(enemy);
break;
}
case EnemyStats.EnemyType.RightHand:{
lootList = new List<Item>();
break;
}
case EnemyStats.EnemyType.Boss:{
lootList = new List<Item>();
break;
}
}
}
void LootPicker(Transform enemy){
lootRNG = Random.Range (0.0f, 100.01f);
int lootint = 0;
for(int j = 0; j < 1; j++){
if (lootRNG >= 50.0f && lootRNG < 75.0f) {
for(int i = 0; i < lootList.Count; i++){
if(lootList[i].itemRarity == Item.Rarity.Common){
rareCollection.Add(lootList[i]);
lootint += 1;
}
}
}
if(lootRNG >= 75.0f && lootRNG < 87.5f){
for(int i = 0; i < lootList.Count; i++){
if(lootList[i].itemRarity == Item.Rarity.Uncommon){
rareCollection.Add(lootList[i]);
lootint += 1;
}
}
}
if(lootRNG > 87.5f && lootRNG <= 93.7f){
for(int i = 0; i < lootList.Count; i++){
if(lootList[i].itemRarity == Item.Rarity.Rare){
rareCollection.Add(lootList[i]);
lootint += 1;
}
}
}
if(lootRNG > 93.7f && lootRNG <= 97.0f){
for(int i = 0; i < lootList.Count; i++){
if(lootList[i].itemRarity == Item.Rarity.Rarer){
rareCollection.Add(lootList[i]);
lootint += 1;
}
}
}
if(lootRNG > 97.0f && lootRNG <= 99.0f){
for(int i = 0; i < lootList.Count; i++){
if(lootList[i].itemRarity == Item.Rarity.SaughtAfter){
rareCollection.Add(lootList[i]);
lootint += 1;
}
}
}
if(lootRNG > 99.0f){
for(int i = 0; i < lootList.Count; i++){
if(lootList[i].itemRarity == Item.Rarity.Legend){
rareCollection.Add(lootList[i]);
lootint += 1;
}
}
}
if(lootint >= 1){
pickerRNG = Random.Range (0, rareCollection.Count);
itemDrop.Add(rareCollection[pickerRNG]);
rareCollection = new List<Item>();
MakeLoot (enemy);
}
//yield return new WaitForSeconds(0.2f);
}
}
void MakeLoot(Transform target){
Vector3 position = new Vector3(target.localPosition.x, target.localPosition.y, 0);
physicalLootPrefab = Instantiate(physicalLootPrefab, position, Quaternion.identity)as Rigidbody2D;
}
}