Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

For my game, there's two types of items - stackable, and nonstackable.

Nonstackable items get assigned a unique ID that stays with it forever. A character ID is assosicated with the item, as is a state (CHANGED, UNCHANGED, NEW, REMOVED). The character ID and state is used for item saving purposes.

Stackable items have one unique ID, as in the entire stack has one unique ID. For example: 5 Potions (stacked ontop of each other) has one unique ID.

When dropping a nonstackable item, the state gets set to REMOVED, and the unique ID and state don't change. If picked up by another player, the state gets set to NEW, and the character ID gets changed to the new character's ID.

When dropping all items in a stack of stackable items (for example, 5 potions out of 5) - it behaves just like a nonstackable item.

When dropping some of a stack of stackable items (for example, 3 potions out of 5)... I really have no clue what to do. The 3 dropped potions have the state of REMOVED, but the same unique ID and character ID. If another player picks it up, it has no choice but to obtain a new unique ID, and its state gets changed to NEW and its character ID to the new one. If the dropping player picks it back up, they'd just be readded to the stack.

There's two issues with that though. 1. If the player who dropped the 3 potions picks it back up, there's no way to tell if they legitimately dropped the items, or if they're duped items. 2. If another player picks up the 3 potions (assuming they're duped), there's no way to know if they're duped or not.

My question is: How can I create a system that detects duplicated items for both nonstackable and stackable items?

share|improve this question
    
Why is it important to assign stacked items one unique id, instead of having each of them with it's own unique id? –  Arthur Wulf White Sep 30 '12 at 6:37
    
Because in a stack of items, each item isn't its own instance. It's technically one item, with a quantity (5, in the main post). –  PuppyKevin Sep 30 '12 at 6:43
    
I recommend this link: en.wikipedia.org/wiki/… - for intuition. Keeping transactions atomic helps to keep them secure (preventing duplication) –  Arthur Wulf White Sep 30 '12 at 8:01
add comment

1 Answer

up vote 5 down vote accepted

How about having a unique itemp ID for each item, stack-able or not and then simply displaying the items that belong to the same category as a stack instead?

Solution II:

Each time the player splits a stack of items, a new unique ID is created for the stack that was dropped on the ground. When two stacks are merged, the lesser stack's ID is the destroyed and it contents are merged with the larger stack.

The destroyed stacks are indicated as such in the DB and can be used later for other items.

So each new stack with x units in the game, gets it's own ID(mentioning x units). When stacks are split, we get a new stack (y units) with a new ID and the old stack is then registered in the server as one with (x - y) units. When a stack is depleted, the server remembers it as an empty stack with 0 units.

No player can hope to reuse an empty stack.

share|improve this answer
    
I feel like that's the only real solution (albiet, it'll be rough on the server). –  PuppyKevin Sep 30 '12 at 6:41
1  
How is that bad for the server?(cause I have an alternative solution to offer that could minimize the Unique ids) –  Arthur Wulf White Sep 30 '12 at 6:41
    
The way I see it is like this: Each "item" in the stack would need a separate instance to dignify their unique ID. That means, a stack of 5 potions that previously was 1 instance, with an integer of 5 for the quantity, is now 5 instances (somehow all merged into a List). I should also note, items don't automatically gets categorized. I can have one stack of 5 potions, and another stack of 12 potions, with two separate unique IDs. –  PuppyKevin Sep 30 '12 at 6:47
    
You mean items may be need to be 'identified' ? As in Rogue –  Arthur Wulf White Sep 30 '12 at 6:48
1  
let us continue this discussion in chat –  Arthur Wulf White Sep 30 '12 at 6:58
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.