Author Topic: Stacking Items with Multiple Durability Values  (Read 849 times)

Offline Waizujin

  • Level 15
  • *
  • Posts: 132
  • Reputation: +1/-0
    • View Profile
Stacking Items with Multiple Durability Values
« on: November 10, 2010, 06:16:40 PM »
I hope this is the right section. :P

Anyway, in my game I am thinking of using a Durability System. Similar games had it setup so the item simply had a chance to break every time used.

My game would have thousands and thousands of these items since there are smithing skills and such.

The issue I see here is, if I have to have a separate entry in the inventory table for each item with a unique durability value, wont that really clog up the database after a while?

How can I make it so there is not so many entries in the database. If I can't make just a entry for multiple items with multiple durabilities, then how do I display it to the user without having a huge list of items. I want them to stack.

Any ideas?

Here is the post I made for my idea people to think on and comment on. :)

Quote
The Idea

Syrnia, Movoda, and Amaranthine all use a system where an item has a random percent chance to break. I don't much like this system. Many online 3D RPG's have a durability system, this is what I am thinking of using.

Using a Durability system, every item that is created would have a durability value. So take for example, an Iron Hatchet has a durability of 10,000. Assuming when you chop a log your durability drops by 1, then you can chop 10,000 Logs. As soon as the durability hits 0, the item breaks.

Of course, to make the system useful, we would have a way for you to take the item to a smith, tailor etc depending on the item, and have it repaired. However, the durability will slowly drop on the item. Take the above example, the Iron Hatchet. Say it's durability is almost to zero. You take it to a smith and he repairs it. But then, the max Durability of 10,000 would then become something like 9,750. Additionally, the amount that the max durability falls would be determined by the repairers skill level. If you have repaired that Iron Hatchet 39 times, that means the durability would be only 250 if the same skill level smith repaired it. If you went back to him to repair it, he could attempt to repair it but it would be unsuccessful and the item would be permanently broken. If the items durability is 1, and you use it once, it is automatically broken and disappears.

When an item is made by a smith, it will have a durability level that is dependent on a random variable and the smiths experience.

Each action would make the durability go down 1 point.


Implementation Method

How I would implement this is I would have a normal item entry. Such as a Iron Hatchet and I would set a max-durability value and a min-durability value. Items created can not exceed the max or min value. Then, when a user creates an item, it will be inserted into the inventory table with the current durability and max durability. With a new item, the durability and max durability would be the same. After each repair, the max durability would go down.

As you can see, there is a flaw in the implementation method.
« Last Edit: November 10, 2010, 06:18:36 PM by Waizujin »

Offline Barrikor

  • Level 21
  • *
  • Posts: 248
  • Reputation: +3/-0
    • View Profile
Re: Stacking Items with Multiple Durability Values
« Reply #1 on: November 10, 2010, 08:22:12 PM »
Yeah, with that setup you're stuck with the need to store the durability of each item that each player has in the DB. You could use a separate table or something,

Ex:

PlayerID | ItemID | ItemDurability
with no PK, or else maybe:

PlayerID | ItemID_1 | ItemDurability_1 | ItemID_2 | ItemDurability_2 | ...etc...
with PlayerID as the PK; this assumes there's a limit on how big the player's inventory can be


2 questions though,
- Does the durability really need to fall each time the item is used? or could it have a random chance to fall, in which case you could have less durability-levels
- Do you really need to have a min-durability value? Couldn't you just use 0 as the min for every kind of item?
« Last Edit: November 10, 2010, 08:57:46 PM by Barrikor »
Projects: Pith Framework (at 0.5), CactusGUI (at 0.3)

Offline Waizujin

  • Level 15
  • *
  • Posts: 132
  • Reputation: +1/-0
    • View Profile
Re: Stacking Items with Multiple Durability Values
« Reply #2 on: November 10, 2010, 09:07:50 PM »
Why would having several durability levels be an issue?

If I had 0 as a value, everytime someone created an item, and it is 0, the item automatically breaks. Which now that I think about it, that's not a bad idea. :P

Okay, so say I use your first example with PlayerID, ItemID, and ItemDurability wouldn't this become an issue with tens of thousands of items? Possibly more?

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,217
  • Reputation: +28/-1
    • View Profile
Re: Stacking Items with Multiple Durability Values
« Reply #3 on: November 11, 2010, 05:13:39 AM »
To clarify. Do you have 2 separate tables? One as "template" which describe the item permanent properties and second as "instance" that hold the template id and temporary/individual properties and is given to each player per item?

you add min/max durability to template
you add current durability to instance

Offline Barrikor

  • Level 21
  • *
  • Posts: 248
  • Reputation: +3/-0
    • View Profile
Re: Stacking Items with Multiple Durability Values
« Reply #4 on: November 11, 2010, 12:20:37 PM »
Why would having several durability levels be an issue?

Because if you access the DB and lower durability each time the item is used, that will add up.
A different way would be to just have a random chance that the durability would go down when the item is first used during the session, then maybe you could have it store in the session when to test the item with the random chance again.

Okay, so say I use your first example with PlayerID, ItemID, and ItemDurability wouldn't this become an issue with tens of thousands of items? Possibly more?

If it hits 4GB, which used to be a sort of table size limit ...should be good before that, but then again I've never maintained a table that big yet...
Projects: Pith Framework (at 0.5), CactusGUI (at 0.3)

Offline Waizujin

  • Level 15
  • *
  • Posts: 132
  • Reputation: +1/-0
    • View Profile
Re: Stacking Items with Multiple Durability Values
« Reply #5 on: November 11, 2010, 04:32:04 PM »
To clarify. Do you have 2 separate tables? One as "template" which describe the item permanent properties and second as "instance" that hold the template id and temporary/individual properties and is given to each player per item?

you add min/max durability to template
you add current durability to instance

I have the "items" table which holds the template. Then I have the "inventory" table that holds what every user has in their inventory. Then, I could put the current durability in the inventory table or in its own separate table. I would prob make it in its own separate table.


And thanks for your help everyone but I think this idea is a bit to much for something that isn't really a big deal. Appreciate the help guys, just wanted to see how it would be done. :)

Offline 133794m3r

  • Level 22
  • *
  • Posts: 265
  • Reputation: +2/-0
    • View Profile
Re: Stacking Items with Multiple Durability Values
« Reply #6 on: November 11, 2010, 06:41:10 PM »
even though you've sadi that you're already done with it, i felt like chiming in here. I've currently set up the system to have an optional value on the items table. It's the items current durability and it's id. The id is a mediumint 3 bytes, and durability for an item is maxed out at smallint 2 bytes. So thus adding the entry which is an optional one is only 2 extra bytes maximum if it was used. Since ~90% of the items in the game are items that can have durability it just makes sense to do it as such.

My system was to have the item slowly lose durability and put such things into the database when the person does something that requires a database query because until then none of teh data is actually stored, it's all living in the session data. The persons inventory as far as stacting is concerned i've not allowed stackign of any items that have durability since it'd make it harder. Also to combat this 'infinite table size' issue i've set a strict cap on how many items a person can carry with them and how many can be in their bank thus making the table itself smaller. If an item reaches 0 durability it has to be completely repaired for the full value of the item or they can toss it. Having the minimum durability in a template table doesn't make much sense to me since why not just use 0? it's a number adn thus it reduces an extra byte at the least from your table's size.

My inventory table looks sort of like this. I've left out constraints and other little things since i cannot remember them all from memory at the moment.
Code: [Select]
player_inventory(
playerid mediumint unsigned not null,
slot tinyint unsigned not null,
item_id mediumint unsigned not null,
durability smallint unsigned not null,
amount smallint unsigned not null,
)

hte items table holds if it has any durability which is then set when the person 'loots' the item. then as they use it the value slowly degrades, database calls are only done when necessary so as to slow down the overall degradation process. Right now it's something like 1-5 uses for it to lose one 'durability'

Using the above table layout isn't probably optimal for you, but for me it's what i came up with to get around the various little issues since i don't want players to always have the best things forever without them breaking. I need them to have a reason to actually do things besides pvp, and battling 24/7.

Offline pixlepix

  • Level 12
  • *
  • Posts: 90
  • Reputation: +0/-0
    • View Profile
Re: Stacking Items with Multiple Durability Values
« Reply #7 on: November 23, 2010, 07:29:11 PM »
or, you could have average durabilty value for a stack. Might have some exploits though.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal