I am making a game where every creature can have 3 attacks and every attack can have many effects at the same time. I'm using CoreData to hold all of the data.
A basic example of what my problem is can be seen with three entities:
Creature
: contains a to-many relationship toAttack
entityAttack
: contains a to-many relationship toEffect
entityEffect
: contains the details of the effect (damage, confuse, poison, etc)
So to begin I need to have three unique Attack
entities for each unique Creature
entity. Then I would need to add the Effect
entities to each attack. My problem is that each effect can have a different value but it is basically the same effect as all the other creatures: It is still "Damage" but the value of the damage is different from each creature.
There are only two ways i've thought of doing this:
Create a unique
Effect
for eachAttack
for eachCreature
, this way I could store the effect value inside the entity. The disadvantage of this would be that the data could grow big: 3x3x400 = 3,600Effect
entities that only exist to have a single relationship each.Create one
Effect
for each type (damage, confuse, etc) and use a Transformable data type in theAttack
entity where I store an array of dictionaries containing eachEffect
entity identifier (so that they can be found when needed) and the value for that effect. This can be easily handled byNSCoding
automatically and would reduce the amount ofEntity
object from 3,600 to probably 20.
The Effect
& Attack
entities are rarely accessed (only when the creature is in a battle) and I do not need to search inside them, therefore I think that would not be a noticeable performance impact. I have also read in many websites that they suggest not to store arrays and dictionaries in CoreData. Is there any other way of doing this? and if not, what option would be better?
PS: Sorry for the non descriptive title, I could not figure out what to put.