   Need Help with Boundless Crafting System
Hey everybody,I am currently learning Java, looking forward to do some Game-Development in the near Future.As the title says, I am trying to do a crafting system as a training project. So these classes are what I got so far (tree structure to see what is child of what) Item    ItemPart   Spike   Core    Weapons   Shuriken  What i want the crafting system to do is the folowing:You take a random number of spikes (Max 10), and one core to craft a Shuriken. This then calculates its characteristics out of the spikes and core characteristics. But! The Shuriken Object then holds the spike and core objects too, so it is reforgeable, detachable and upgradeable. so in the end each weapon of whatever type has ist own components AND optional components. My problems are the components. I COULD, and will randomize some of them, but how do I create preset ones? creating an own class like "sharp spike of whatever" and then always create objects of that. using a Class as databank and define preset objects in it? Using a databank?What would be the most easy way if I donÄt know how to use databanks?Thanks for reading :)Greetz, Toriath (I feel shame for my bad english :( )
Hmm your Shuriken object doesnt need to hold 'n' Spike objects, Thats a waste of space. Personally I'd just have a a yield function in the Shuriken object (or Deconstruct) which returns 'n' number of NEW Spike objects and a core. So for instance: Stage 1: Player inventory 4 x Spikes1 x Core Stage 2: Player visits a workbench turns the 4 spikes and 1 core into 1 Shuriken Object. Stage 3: Player receives 1 Shuriken, their inventory is now 1 x Shuriken The Shuriken object holds the number of spikes used to create it, (as an INTEGER) and then when the player deconstructs the object  object[] Deconstruct(){ return 1x core and 'n' Spikes. } So the spikes returned are new objects. In terms of Creating Weapons, I would have a base "WeaponBase" class which knows what "Component" object(s) it needs to make the Weapon and use inhertiance so: class UberLongSword extends WeaponBase. So a Iron Sword knows it needs 4x Iron Ingots and 1xWooden stick to make.;In terms of Creating Weapons, I would have a base "WeaponBase" class which knows what "Component" object(s) it needs to make the Weapon and use inhertiance so: class UberLongSword extends WeaponBase. So a Iron Sword knows it needs 4x Iron Ingots and 1xWooden stick to make. Hmm, this looks okay, but what if an Iron Sword could be crafted with lets say 5 different kinds of handles and 7 different kinds of blades? (f.E. sharp blade, rusty blade, long blade...)I'll  just go and tell the Sword to use 1 blade and 1 handle and make each "kind of handle", a subclass of handle?Hmm your Shuriken object doesnt need to hold 'n' Spike objects, Thats a waste of space. Personally I'd just have a a yield function in the Shuriken object (or Deconstruct) which returns 'n' number of NEW Spike objects and a core. So for instance: Stage 1: Player inventory 4 x Spikes1 x Core Stage 2: Player visits a workbench turns the 4 spikes and 1 core into 1 Shuriken Object. Stage 3: Player receives 1 Shuriken, their inventory is now 1 x Shuriken The Shuriken object holds the number of spikes used to create it, (as an INTEGER) and then when the player deconstructs the object  object[] Deconstruct(){ return 1x core and 'n' Spikes. }Well, that would work, but what if the shuriken is build out of different spikes? Maybe one grants firedamage and another armor penetration? Would theses Objects still be waste of space?Maybe I didn't pointed it out before, but there wont be predefined weapons. So a Sword is not only handle + BladeWhat I want is "Sword = Handle + Blade + Optional Items (Power stones f.E.). The Swords Name, attributes etc. shall be generatet out of its materials stats.If i got a big handle(2 att per sec) + long, sharp ironblade(90 damage, Armorpenetration, durability) its going to be a "Sharp Twohanded Ironblade of fast devastation"Thanks for your answer by the way Toriath;Hmm, this looks okay, but what if an Iron Sword could be crafted with lets say 5 different kinds of handles and 7 different kinds of blades? (f.E. sharp blade, rusty blade, long blade...)I'll just go and tell the Sword to use 1 blade and 1 handle and make each "kind of handle", a subclass of handle? One way I tend to look at 'objects' is that nouns are objects and adjectives are properties of those objects.  So I would look at that as only have 1 kind of blade, but that blade has an assortment of different properties.  Inheritance should always be used frugally.;Well, that would work, but what if the shuriken is build out of different spikes? Maybe one grants firedamage and another armor penetration? Would theses Objects still be waste of space? Well are you really going to need them? if you have todo this every frame to check what type of dmg todo:if(allSpikesAreFireDmg)  return 500000000000 fire dmg. then yes, you'll need them. Personally again, i'd go for once an object is made with spikes, have a DamageType enum, and jsut assign it.public enum DamageType{    Common = 1,    Fire,    Ice,    Shadow,}public enum WeaponBonus {    ArmourPen = 1,    WeaponDamage,    MaxHealth,    MagicResistance,    MagicDamage,}So lets say we have a 2x Spikes with the follwing properties, and 1 Core with the follwing property: Spike: 8 WeaponDamge, 1 max HealthCore: 8 WeaponDamage, 4 magic Resistance //We can store in it a Dictionary (HashMap in java?) in each component an just sum it up in the Weapon.HashMap<WeaponDamage, int> BuffsTable; //SpikeHashMap<WeaponDamage, int> spikeBuffsTable = [WeaponDamage, 8][MaxHealth, 1] //CoreHashMap<WeaponDamage, int> coreBuffsTable = [WeaponDamage, 8][magicResist, 4] //BuffsTable summed= [WeaponDamage 16, maxhealth 1, magicResist 4] ;This might be a little off, but you could also go in the area of material used / weight of material... So say you use a lighter material 10x spikes would work out good for distance but use a material a lot heavier than construct the object with 10x spikes and you end up with a shuriken that weighs too much to be really effective or not good at long distance, etc... Just a little food for thought since you are looking to develop a nice crafting system.;Hmm, this looks okay, but what if an Iron Sword could be crafted with lets say 5 different kinds of handles and 7 different kinds of blades? (f.E. sharp blade, rusty blade, long blade...)I'll just go and tell the Sword to use 1 blade and 1 handle and make each "kind of handle", a subclass of handle? One way I tend to look at 'objects' is that nouns are objects and adjectives are properties of those objects.  So I would look at that as only have 1 kind of blade, but that blade has an assortment of different properties.  Inheritance should always be used frugally. Okay. Instead of creating lots of subclasses for "Blade" I am going to give "blade" an String-array (f.E. String[n] specials = {"special 1","special 2"," special n"}), and the craftingsystem will identify these? Well are you really going to need them? if you have todo this every frame to check what type of dmg todo:if(allSpikesAreFireDmg)  return 500000000000 fire dmg. then yes, you'll need them. Personally again, i'd go for once an object is made with spikes, have a DamageType enum, and jsut assign it.public enum DamageType{    Common = 1,    Fire,    Ice,    Shadow,}public enum WeaponBonus {    ArmourPen = 1,    WeaponDamage,    MaxHealth,    MagicResistance,    MagicDamage,}So lets say we have a 2x Spikes with the follwing properties, and 1 Core with the follwing property:  Spike: 8 WeaponDamge, 1 max HealthCore: 8 WeaponDamage, 4 magic Resistance //We can store in it a Dictionary (HashMap in java?) in each component an just sum it up in the Weapon.HashMap<WeaponDamage, int> BuffsTable; //SpikeHashMap<WeaponDamage, int> spikeBuffsTable = [WeaponDamage, 8][MaxHealth, 1] //CoreHashMap<WeaponDamage, int> coreBuffsTable = [WeaponDamage, 8][magicResist, 4] //BuffsTable summed= [WeaponDamage 16, maxhealth 1, magicResist 4]  I think I should take a deeper look into enumerations and afterwards read this again. ^^Well the reason why I want to store the Objects is, that there may be the ability to disassamble the Shuriken and to regain each part with its properties.  This might be a little off, but you could also go in the area of material used / weight of material... So say you use a lighter material 10x spikes would work out good for distance but use a material a lot heavier than construct the object with 10x spikes and you end up with a shuriken that weighs too much to be really effective or not good at long distance, etc... Just a little food for thought since you are looking to develop a nice crafting system. Sounds good. As the crafting system will be used in a game later on, I think i know how to implement this in an interesting way :) Thanks for that Idea.;I think I should take a deeper look into enumerations and afterwards read this again. ^^Well the reason why I want to store the Objects is, that there may be the ability to disassamble the Shuriken and to regain each part with its properties. Well it will Work, but i just think there are easier (more memory efficient) ways of storing the data. IF you do go with this approach, then make sure your 'Object' doesn't store and graphics data E.g. Meshes / Textures or you will be storing 10 Meshes/Textures in the object which are never used and just sit there using Memory.;Well it will Work, but i just think there are easier (more memory efficient) ways of storing the data. IF you do go with this approach, then make sure your 'Object' doesn't store and graphics data E.g. Meshes / Textures or you will be storing 10 Meshes/Textures in the object which are never used and just sit there using Memory.I didn't even think about Textures by now.^^ Well, I am going to work a little on this now and when I got a little progress and/or more questions I will come beck here. :Dthanks for now @all.Toriath;What may be helpful here is the composite pattern http://en.wikipedia.org/wiki/Composite_pattern Here you have an abstract class/interface which is the base of everything else, e.g. an item. You can then have base items (leafs) which cannot be deconstructed further e.g. spikes or cores. You then can have some kind Weapons or other stuff, the components. You can also only see these components as groups and can go further down the path and just make ThrowableWeapons and maybe let a shuriken be a ThrowableWeapon. The recipe could be defined by a hashmap or a table in the class saying for building you will need x spikes and so on. When you're building/crafting the stuff, check if the required items are in your inventory ( which may also be a component) if so remove them from there. If you're trying to decompose an item just add new instances of the items in the table to your inventory.