Author Topic: A Good Drop System  (Read 26068 times)

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
A Good Drop System
« on: October 27, 2010, 02:24:12 PM »
Sorry for this serie of (annoying) questions I'm writting here, but since this is the first roguelike I ever make, I want it to be pretty decent.

I need right now to polish it b4 release, and something that I need to do is a decent random drop system.
I explain: when monsters die, they drop (or maybe not) a certain item from the "list of items".
Right now i just implemented a simple "generate random number and drop such item".
I want a better way to do this, since I want to make items to have a certain chance of drop, so it's hard to get an "epic celestial angelical allmighty scythe of destruction +20", and so on.
With the current method (i know it's pretty crap) that can be dropped from a rat or from a godlike monster.

I though about adding to the items a propertie "DropPercent", but this also means that i need to add to the monsters a propertie "DropModdifier", that modifies the absolute drop chance, so certain monsters can't drop "epic" items.
But I don't know if this is the best way to do go, or there is an universal or better procedure.
Before start coding this, I would be interested in some oppinion and tips about dropping methods that you know, his advantages, disvantages, etc...

Thnx in advance.

Tschüs.

Bear

  • Rogueliker
  • ***
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: A Good Drop System
« Reply #1 on: October 28, 2010, 12:18:50 AM »
There's a lot of ways to do it.  There's a lot of ways to "tweak" each way to do it.  Ultimately drop determination is always an adhoc system, like map generation. There is a particularly cool  algorithm for making a random choice from a set with predetermined proportional rarities, but you'll probably still want to find a way to "adjust" them to suit your ideas about what should be possible.

That said, the cool algorithm is the alias method.

Suppose you want to sample from N different items, with relative probabilities p[0],...,p[N-1] summing to M.  You do the preprocessing I'll describe below to generate this table.  To take a sample, pick one of the N entries in the table at random (according to a uniform distribution). Each entry in the table contains two item numbers a and b, and an integer w. Now pick a random number from 0..M-1. If this number is smaller than w, you return the item in a, otherwise you return the one in b.

Here's how you set up the table.

First, multiply each p by N so that we can do everything in integer arithmetic. Store all item numbers to be selected from in a data structure S.  Then, for k=0..N-1, fill the entries as follows: Select the item i from S with smallest p, and the item j from S with largest p[j].
Put i in a[k], j in b[k], and p in w[k]. This gives item i a probability of w[k] out of MN to be sampled using the table, so we are done with it and removed it from S. Item j remains in S, and p[j] is reduced by M-w[k].

To see why it works, you have to realize that p <= M <= p[j] at every step.


Example: we have seven items with relative probabilities A=1,B=2,C=2,D=3,E=4,F=9,G=9. This means B or C are twice as likely as A, E is twice as likely as B or C, G is 3 times as likely as D, and so on.  This is 30 oddments.  An "oddment" is a funny word meaning an equal share of probability. 

We create a table S with 7 entries.

We multiply all oddments by 7 so we work can work with integers.

Our list is now

A=7,B=14,C=14,D=21,E=28,F=63,G=63. This is 210 oddments, but since the numbers are in the same proportion to each other as before, it's the same probabilities for each item.

Now, since we have 7 buckets, and 210/7 = 30, each bucket represents  30 oddments.

bucket 0 gets 7 oddments of A (which is all there is) and 23 oddments of F.

our list is now:
B=14, C=14, D=21, E=28, F=40, G=63

bucket 1 gets 14 oddments of B and 16 oddments of G.

our list is now:
C=14, D=21, E=28, F=40, G=47

Bucket 2 gets 14 oddments of C and 16 oddments of G.

our list is now:
D=21, E=28, F=40, G=31

Bucket 3 gets 21 oddments of D and 9 oddments of F.

our list is now:
E=28, F=31, G=31

Bucket 4 gets 28 oddments of E and 2 oddments of F.

our list is now:
F=29, G=31

Bucket 5 gets 29 oddments of F and 1 oddment of G.

our list is now
G=30.

So that's what bucket 6 gets. :-)


So when we want an item, we generate a number from 0 to 6 inclusive to pick a bucket, then generate a number from 0 to 29 inclusive to check which of the (at most 2) choices in that bucket we get. 

This gives you item selection from a set of items with fixed probabilities, in a way that has a number of desirable properties (runs in constant time, cannot hang continuing to retry, etc). So you can make your epic celestial angelical allmighty scythe of destruction +20 very very rare, and your simple dagger very common, and that will solve the most basic of your problems. 

Of course you're going to want to tweak it.  In practice, you'll probably build a different alias-method selection table every time you go to a new floor of the dungeon to enforce the "more powerful items deeper" thing.  Alternatively, or additionally, you can develop different tables to generate drops from different types of creature so as to keep them thematic.

Bear

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: A Good Drop System
« Reply #2 on: October 28, 2010, 06:46:08 AM »
One way is give each item a class data. That way you can rule out things like quest items or epic items from the usual creation. Monsters can also have a rough type which determines what kind of items they drop. That can include monster's ability to use weapons (drop weapons) and the level of monster (drop better weapons). Just one thing please, don't make rats drop gold coins. Or anything.

I think a cool way to decrease the amount of data is always rule out common cases (like monsters who can't carry/use anything, skip drop rules from them) and then use generic types to determine rough stuff, and then add special cases in individual monster type level.

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: A Good Drop System
« Reply #3 on: October 28, 2010, 07:08:36 PM »
There's a lot of ways to do it.  There's a lot of ways to "tweak" each way to do it.  Ultimately drop determination is always an adhoc system, like map generation. There is a particularly cool  algorithm for making a random choice from a set with predetermined proportional rarities, but you'll probably still want to find a way to "adjust" them to suit your ideas about what should be possible.

[...]  

Of course you're going to want to tweak it.  In practice, you'll probably build a different alias-method selection table every time you go to a new floor of the dungeon to enforce the "more powerful items deeper" thing.  Alternatively, or additionally, you can develop different tables to generate drops from different types of creature so as to keep them thematic.

Bear


Damn good answer.
Thanks for your time and efforts.



One way is give each item a class data. That way you can rule out things like quest items or epic items from the usual creation. Monsters can also have a rough type which determines what kind of items they drop. That can include monster's ability to use weapons (drop weapons) and the level of monster (drop better weapons). Just one thing please, don't make rats drop gold coins. Or anything.

I already did.
All items from my Roguelike have not only an itemClass, also an itemSubClass property.
I don't like to, but I must explain that the player in this roguelike will NOT increase level, but increase skills by using the associated "action": increase swords by using sword, increase blocking with a shield (and of course, using the shield), and so on...
So for useable/equipable items, a itemSubClass is necessary to increase the derived skill.
Also the players stats cannot be increased during gameplay. This can hapen only by the "god's mercy" and using certain magic" items that can increase them permanently.
And due to this, it's necessary to know if a drink is just "restore fatigue" drink, or anything else.

I think a cool way to decrease the amount of data is always rule out common cases (like monsters who can't carry/use anything, skip drop rules from them) and then use generic types to determine rough stuff, and then add special cases in individual monster type level.

That's true, but not for my Roguelike, since the monsters' stats are generated semi-randomly, depending on the map depth level and a small random seed, so it's hard to have common cases that rules all monsters of the same "family", because a Rat in depth level 1 is weaker than a rat in level 15 or even a "Angry Rat" is different from a "Weak Rat", and thus, the drop is also different, although the "base monster" is the same.

Talking about monsters-using-items-in-floor, i will not implement that. At least in this first version. I will do it later on, but not now.
I know it's quite a trivial thing, but I prefer a good working program with good features than a bugged program with lot of features.
I can tell that one of the implemented features in the Roguelike is the high amount of randomness involving maps and items and monsters stats.  ::)

Whatever it be, I'll have into account your tips.
« Last Edit: October 28, 2010, 07:15:55 PM by Übermann »

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: A Good Drop System
« Reply #4 on: October 28, 2010, 08:08:04 PM »
because a Rat in depth level 1 is weaker than a rat in level 15

What in level 1 makes that rat weaker?

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: A Good Drop System
« Reply #5 on: October 28, 2010, 08:57:06 PM »
because a Rat in depth level 1 is weaker than a rat in level 15

What in level 1 makes that rat weaker?

That's not the correct question. It should be: What in level 9 makes that rat stronger?

The answer is: the player overall strength.
Monsters become stronger when the player goes deeper. And it's supposed that  player also increases his skills, enhances his weapon and  so on. So, speedrunning the game is not a good idea ;-)
Also some monsters only appear from certain map depths.

Z

  • Rogueliker
  • ***
  • Posts: 905
  • Karma: +0/-0
    • View Profile
    • Z's Roguelike Stuff
Re: A Good Drop System
« Reply #6 on: October 28, 2010, 09:43:25 PM »
That said, the cool algorithm is the alias method.

That algorithm is indeed very cool, but probably something simple should be good enough for this particular use. This one is quick to implement:

count = 0;
for(i in all possible item types) {
  chance = relative chance of obtaining i-th item;
  count += chance;
  if(rand() % count < chance) itemSelected = i;
  }

the final value of itemSelected contains the id of item selected. Much less effective, but works. Or, if you know the sum of all relative chances and RNG is costly:

x = rand() % sum;
for(i in all possible item types) {
  chance = relative chance of obtaining i-th item;
  x -= chance;
  if(x<0) return i;
  }

Krice

  • (Banned)
  • Rogueliker
  • ***
  • Posts: 2316
  • Karma: +0/-2
    • View Profile
    • Email
Re: A Good Drop System
« Reply #7 on: October 29, 2010, 06:48:59 AM »
Monsters become stronger when the player goes deeper.

Monster leveling sucks. Everyone knows that.

Skeletor

  • Rogueliker
  • ***
  • Posts: 580
  • Karma: +0/-0
  • villains ftw
    • View Profile
Re: A Good Drop System
« Reply #8 on: October 29, 2010, 07:45:01 AM »
Monsters become stronger when the player goes deeper.

Monster leveling sucks. Everyone knows that.

Ditto.. it's maybe the most annoying thing in Adom.
What I enjoy the most in roguelikes: Anti-Farming and Mac Givering my way out. Kind of what I also enjoy in life.

Z

  • Rogueliker
  • ***
  • Posts: 905
  • Karma: +0/-0
    • View Profile
    • Z's Roguelike Stuff
Re: A Good Drop System
« Reply #9 on: October 29, 2010, 01:38:25 PM »
Ditto.. it's maybe the most annoying thing in Adom.

ADOM has the so called "uberjackal effect" which causes monsters which rarely appear randomly, but often appear in swarms from summoners and wilderness encounters, like jackals and spiders, to quickly obtain very high levels and become a major problem. It is indeed a not well thought out feature (and is considered a bug by most players and there is an unofficial patch which fixes that). But other than that, is levelling of e.g. goblins also a problem?

Skeletor

  • Rogueliker
  • ***
  • Posts: 580
  • Karma: +0/-0
  • villains ftw
    • View Profile
Re: A Good Drop System
« Reply #10 on: October 29, 2010, 02:07:39 PM »
Ditto.. it's maybe the most annoying thing in Adom.
ADOM has the so called "uberjackal effect" which causes monsters which rarely appear randomly, but often appear in swarms from summoners and wilderness encounters, like jackals and spiders, to quickly obtain very high levels and become a major problem. It is indeed a not well thought out feature (and is considered a bug by most players and there is an unofficial patch which fixes that). But other than that, is levelling of e.g. goblins also a problem?

In my opinion it is, because:
1- rats piercing armors aren't realistic
2- come on, it's cheesy
3- it doesn't reward the player to achieve new levels, because no matter how they grow strong there will always be a stronger goblin
4- it makes the tactic aspect stable over time

I think that DCSS gives a good example about this matter.
What I enjoy the most in roguelikes: Anti-Farming and Mac Givering my way out. Kind of what I also enjoy in life.

jim

  • Rogueliker
  • ***
  • Posts: 380
  • Karma: +0/-0
    • View Profile
Re: A Good Drop System
« Reply #11 on: October 29, 2010, 03:14:07 PM »
Hehe... rats... cheesy.

Damn, I am such a good contributor to this conversation.

RogueMaster

  • Rogueliker
  • ***
  • Posts: 65
  • Karma: +0/-0
    • View Profile
Re: A Good Drop System
« Reply #12 on: October 29, 2010, 04:03:34 PM »
Monsters become stronger when the player goes deeper.

Monster leveling sucks. Everyone knows that.

I will think about that. Maybe i remove it. I dont know.
But as I make it, the monsters' growth rate is higher than the player, so the game becomes even more difficult in later levels, unless:

1. You are lucky and all your drops and findings are "epic" items and/or
2. You are lucky and deal all critical hits and/or
3. The monsters spawned are the most weaker possible and/or
4. You dodge, block or parry (parry = block with weapon) all blows and/or
5. By using certain game feature that allows you to increase your overall power (I don't refer to skills. I will reveal it when release the game).


But yes, I will think about monster leveling. Afterall, it's the community who must like the game.

Z

  • Rogueliker
  • ***
  • Posts: 905
  • Karma: +0/-0
    • View Profile
    • Z's Roguelike Stuff
Re: A Good Drop System
« Reply #13 on: October 29, 2010, 07:59:00 PM »
1- rats piercing armors aren't realistic
I think rats becoming more powerful is as realistic as the player character becoming more powerful. (I.e. both are not realistic, but since the second one is a RPG convention, you should not protest that the first one is not realistic.)

Quote
2- come on, it's cheesy
I see no problem... Although it would be possible to do it in a more interesting way than ADOM does (e.g. goblins advancing to goblin rockthrowers or whatever, instead of having two separate types of goblins which can advance independently)

Quote
3- it doesn't reward the player to achieve new levels, because no matter how they grow strong there will always be a stronger goblin
I am not sure how ADOM does this, but if the player character of level P, on dungeon level D, finds goblins of level D-G (where G is the depth at which the goblins appear first), then your argument is false (if you do not achieve new levels, the goblins deeply in the dungeon will still be stronger, so you will have less chance against them).

(I suppose the formula in ADOM is rather something like (2D/3+P/3-G)+K/F where K is the number of goblins killed and F is the goblin frequency, and you have some point, due to this P/3. The last component is AFAIK what causes the uberjackal effect, since you kill a lot of them while ADOM thinks they are rare.)

Quote
4- it makes the tactic aspect stable over time
But new types of monsters appear in the dungeon... and monsters like goblins stop being a nuisance, even if experienced.

Fenrir

  • Rogueliker
  • ***
  • Posts: 473
  • Karma: +1/-2
  • The Monstrous Wolf
    • View Profile
Re: A Good Drop System
« Reply #14 on: October 29, 2010, 08:17:18 PM »
Actually, I don't think rats piercing armors is all that unrealistic. Those things have sharp teeth.

I don't like monster levelling. I don't know if it's more or less illogical than anything else, but there is just something wrong about all monsters levelling up as I kill them. Just ain't right.