c# - InventorySystem List of Items and their subclass Permanents Bug -


hey need inventory system. it's simplistic - guess - got problems , couldn't find solution online.

//! edited minimal best of knowledge

my task university system contains sub-classes. worked fine till added sub-classes.. apparently items created , added inventory @ start somehow child part , in-fact entire item seems overwritten @ point. guess list of items cause problems later on when sub-class of permanents added.

anyway started out , can't find problem.

any appreciated - or point me right direction read on given problem.

cheers , in advance!

itemdatabase

public class itemdatabase : monobehaviour {     public list<item> items = new list<item>();      void start ()     {         items.add(new permanent(0, "iron armor", "the armor has seen battle.", 0, item.itemtype.permanent, 110, 20000, 6640, 600, 100, true, "torso", 5, -5, 10, 50));         items.add(new consumable(139, "healing potion", "brew restore health.", 1, item.itemtype.consumable, 30, 800, 720, 100, 100, 1, 3, 50, 0, 0, 0));         items.add(new permanent(376, "bronze sword", "the sword made poor quality bronze.", 0, item.itemtype.permanent, 5, 1480, 820, 480, 100, true, "hand", 5, -5, 10, 50));         items.add(new permanent(24, "gladiator helmet", "this helmet can kick ass!", 0, item.itemtype.permanent, 110, 20000, 6640, 500, 200, true, "head", 5, -5, 10, 50));      } } 

inventory

public class inventory : monobehaviour {     public int slotsx, slotsy;     public guiskin skin;     public list<item> inventory = new list<item>();     public list<item> slots = new list<item>();     private itemdatabase database;     private bool showinventory;     private bool showtooltip;     public string tooltip;      private bool draggingitem;     private item draggeditem;     private int previndex;      void start()     {         (int = 0; < (slotsx * slotsy); i++)         {             slots.add(new item());             inventory.add(new item());         }          database = gameobject.findgameobjectwithtag("item database").getcomponent<itemdatabase>();          additem(0);         additem(0);         additem(139);         additem(376);         additem(24);      }      void additem(int id)     {         (int = 0; < inventory.count; i++)         {             if (inventory[i].itemname == null)             {                 (int j =0; j < database.items.count; j++)                 {                     if (database.items[j].itemid == id)                     {                         inventory[i] = database.items[j];                     }                 }                 break;             }         }     }  } 

item

public class item : monobehaviour {     public int itemid;     public string itemname;     public string itemdesc;     public int itemtypeint;     public itemtype itemtype;     public texture2d itemicon;     public int itemvalue;     public float itemweight;     public int itemvolume;     public int itemsturdiness;     public int itemhealth;      public string cpermanent = "#ffff66";     public string cconsumable = "#00ffff";     public string cmiscellaneous = "#ff00ff";     public string cdefault = "#ffffff";      public enum itemtype     {         permanent,         consumable,         miscellaneous,     }      public item(int id, string name, string desc, int typeint, itemtype type, int value, float weight, int volume, int sturdiness, int health)     {         itemid = id;         itemname = name;         itemdesc = desc;         itemtypeint = typeint;         itemtype = type;         itemicon = resources.load<texture2d>("item icons/" + id);         itemvalue = value;         itemweight = weight;         itemvolume = volume;         itemsturdiness = sturdiness;         itemhealth = health;     }      public item()     {         itemid = -1;     } } 

permanent

public class permanent : item {     public bool pequipment;     public string pequipmentslot;     public int pstre;     public int pagil;     public int pinte;     public int pwisd;     public permanent(int id, string name, string desc, int typeint, itemtype type, int value, float weight, int volume, int sturdiness, int health, bool equipment, string equipmentslot, int stre, int agil, int intl, int wisd) : base(id, name, desc, typeint, type,  value, weight, volume, sturdiness, health)     {         bool pequipment = equipment;         string pequipmentslot = equipmentslot;         int pstre = stre;         int pagil = agil;         int pinte = intl;         int pwisd = wisd;     }  } 

consumable

public class consumable : item {     public int ccharges;     public int cmaxcharges;     public int cstre;     public int cagil;     public int cinte;     public int cwisd;     public consumable(int id, string name, string desc, int typeint, itemtype type, int value, float weight, int volume, int sturdiness, int health, int charges, int maxcharges, int stre, int agil, int intl, int wisd) : base(id, name, desc, typeint, type, value, weight, volume, sturdiness, health)     {         int ccharges = charges;         int cmaxcharges = maxcharges;         int cstre = stre;         int cagil = agil;         int cinte = intl;         int cwisd = wisd;     } } 

miscellaneous

public class miscellaneous : item {     public bool mquest;      public miscellaneous(int id, string name, string desc, int typeint, itemtype type, int value, float weight, int volume, int sturdiness, int health, bool quest) : base(id, name, desc, typeint, type, value, weight, volume, sturdiness, health)     {         bool mquest = quest;     } } 


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -