HalEmmerich 08-30-2006, 05:35 PM Although it applies to a game, this question is more or less a general programming question.
I am creating an RPG Character sheet for my IRC Rpg. Everything is going well, until I come to that bane of every existance...
Items.
Why are items such a pain you ask? Well, think about it. All of the following are items and what they do.
Poison Sword: Deals damage, 1/20% of poison
Potion: Heals damage
Antidote: Cures poison
Steel Armor: Reduces damage
Grenade: Deals a static amount of damage not based on your strength.
Flash Bang: Causes blindness
Fire Armlet: Nullifies fire damage
None of these items have common categories to them. You can't make an 'Item Class' for every possible scenario, because it would be 50 variables long and only 5 or 6 would be used in any one class. Not everything does damage, not everything has an associated element, some things do 2 kinds of damage (Static and strength based).
My question is, how do you store something that has THAT many unknowns. A delimited text file would take too long to read and is too prone to error, a database jacks up the file size, and theres too many possible items in my rpg to hard code them all. I was thinking about an 'Effect' hash code that would be like
DS2000DM2EF1
Static Damage '2000', Modified Damage '2', Element Fire 1
But that would have to be read at run time, and would probably take just as long as reading the stupid text file.
Help, please!
Thanks for your time.
I'd have thought creating a class/classes is exactly what you should be doing in this situation. Each 'Item' will have at least some things in common with the other items. These properties will be part of an Item class. You would then make subclasses such as Weapon, Armour and Potion. Then each item in your game would simply be an instance of one of these classes with the correct properties set.
Your Item class may include things such as 'Name', 'Weight', 'Type', 'Description' 'Value' and 'ImagePath'. Then your subclasses would add properties for example your weapon class may add 'ProficiencyType', 'DamageCaused' and 'Durability'.
Of course none of this is particularly relevant in terms of how you store the items to file, but it is certainly how I would store the items during gameplay. If you are storing the items like this you could always use a serializer/deserializer system to store individual items to file. I can see no reason why reading/writing to file like this should take too long. If doing it on the fly in a realtime environment it might cause lag, but you can get around this by loading items between level changes rather than on the fly.
Iceplug 08-31-2006, 07:16 AM Or you can just store the item by ID and the quantity to the text file... then do all of the lookups within your program... much simpler, and you manage all of the items' use in the program.
HalEmmerich 08-31-2006, 11:40 AM Well, heres the issues I had with both of those methods. Maybe you guys can think of a way around them..
#1: There isn't a set standard list of items, its a huge game (and its not the actual game , its a character sheet for an IRC RPG). I may make an online database for it at some point, but for the moment, I need a way to be able to define an items effect on the fly, since there won't be any kind of storage other than the players inventory.
#2: With the classes.. actually no, that would work fine, with the exception of 2 things.
A: I'd like to avoid having to have 30 different text boxes to define a weapon. In a previous iteration of this program, to define a weapon, it was an array of 30 elements, and EACH element had an associated text box/combo box, which made things very limiting. Any idea on how to get around that? I was thinking about a list of properties that you could add to a weapon (IE: A combo box that you can pull things out of)
B: Some items may cause more than one effect. For example, a flash bang could cause 'Deafness' and 'Blindness'. How could I do that without having to have a variable for each possible slot of a status effect.
wayneph 08-31-2006, 12:37 PM Or you could use a HashTable to store the properties. It's just a list of Key/Value pairs. You can have as many or as few as you want.
piggybank1974 08-31-2006, 12:52 PM Personally I would go the Class route, you have more control and its easiler to implement further feature intime.
I would use an Arraylist containing the individual classes you want, then you can easily iterate through an item of the Arraylist and retrieve the class you want.
the pig..
Iceplug 08-31-2006, 04:23 PM Sounds like you're just throwing some random stuff at us... why not just take a minute and formulate a list of exactly what properties your items can have - then make another list that states how your properties are related (heals 5% or heals 50%, cannot be both), if any are common properties (blindness and deafness can be caused by one weapon), and if any are standalone properties or require another property to be set (nullifies fire damage -- how much?).
Put all of these properties into a table, label/group them, and then try to look at all of the groupings, which should each correspond to a single item in a class.
HalEmmerich 08-31-2006, 06:19 PM Thats exactly the problem. Its not a game like Final Fantasy, where a potion heals X amount. You can have items from any time period. And specifically, I was concerned about things like 'Flash Bangs', which can cause 2 status effects (Blind and Deaf). So in other words, I suppose, I'll be going with the class routine, but the question is, is there anything anyone can think of that would let me have more than one property of the same kind? The class will look something like...
Inventory class
Item class
Name as String
Quantity as String
Proficiency as String
AffectStatistics as Boolean (Determine if the item affects a players statics when it is possessed, like an enchanted glove)
Weapon Class
Damage as String
StatusEffect as String
HitNumber As String (Number of hits per attack)
... and so on
etc.. so, how could I have multiple status effects, make it an array maybe?
Also, how do you suggest I get around the '30 text box' concept model (Having a text box for every concievable contingent of item)
Iceplug 09-01-2006, 03:13 PM Its not a game like Final Fantasy, where a potion heals X amount.
But you must have some idea of what the potion does - you know about how much health that it should give to a character and that's the attribute - you are the person in charge of the attributes.
is there anything anyone can think of that would let me have more than one property of the same kind?
Declare more of that kind of property via two or more declarations or an array.
StatusFx1 As StatusEffect
StatusFx2 As StatusEffect
or use an array: StatusFxs() As StatusEffect
Also, how do you suggest I get around the '30 text box' concept model (Having a text box for every concievable contingent of item)
When you develop your properties, you should only use textboxes for the nameof the item - nothing else - that includes Damage, StatusEffect, Quantity, and Proficiency. The fact that you've tried to declare everything as string is going to set you up for the textboxes, when they are not necessary - in fact, things like StatusEffects are better as enumerations. Damage is clearly a number (or an enumeration if, by damage, you meant damage type instead of amount of damage) so should be declared as such.
Numbers can be manipulated by NumericUpDowns or Sliderbars.
Booleans = Checkbox
However, if you're trying to not have 30 controls to do all of the complicated stuff that you keep surprising us with :eek:, you will probably not be able to have a small number of controls to do this in.
HalEmmerich 09-01-2006, 10:58 PM Ok, I've compiled my total list of properties. So in other words, theres like
Class Inventory
Class Item
General Variables
Class Damage (Contains damage related properties)
Class Equipment (Contains boolean for where the item is
equippable to, only if '_IsEquipment' = True)
Class Statistics (Contains effects to each stat, if general variable '_AffectStatistics' = True. If _IsEquipment=true, the benefits are only given when it is equipped)
Class Element (Sets elemental affinity)
Class StatusEffects (Contains status related variables)
Also, a note, StatusEffects themselves are integer flags (for the moment), but I make make it an Enum as you suggested.
I was thinking about using a combo box to display all of the possible addable properties, and then just have a text box to set the value, but there -must- be a better way than having a combo box of 90 items and one associated text box, than a list of the added properties. Any thoughts?
Iceplug 09-03-2006, 09:55 AM You can make a Multiselect box for things like that (enumerations if I understand correctly) - loop through the selected items to figure out which of the flags to set.
I personally don't think your properties should be classes, but if you want to do so, then go ahead. But, the way you are implementing them makes them look better as Interfaces rather than Classes.
|