summaryrefslogtreecommitdiff
path: root/src/game-server/monster.cpp
diff options
context:
space:
mode:
authorStefan Dombrowski <stefan@uni-bonn.de>2011-05-26 21:57:19 +0200
committerStefan Dombrowski <stefan@uni-bonn.de>2011-05-26 21:57:19 +0200
commit406be26dd7a12795a4a2702aabe2ef46a5e0a6bb (patch)
tree8fa13259fd570c8f388bf7ed6f73ecf73f4e6ca2 /src/game-server/monster.cpp
parentca2d7ad577fb08fdc353c8daaa27e9a16bf7a0a0 (diff)
downloadmanaserv-406be26dd7a12795a4a2702aabe2ef46a5e0a6bb.tar.gz
manaserv-406be26dd7a12795a4a2702aabe2ef46a5e0a6bb.tar.bz2
manaserv-406be26dd7a12795a4a2702aabe2ef46a5e0a6bb.tar.xz
manaserv-406be26dd7a12795a4a2702aabe2ef46a5e0a6bb.zip
Allow monsters to drop multiple items
Before at most one item was droped and the sum of all probablilites was limited to 100%. Also in the example data drops are changed to existing items.
Diffstat (limited to 'src/game-server/monster.cpp')
-rw-r--r--src/game-server/monster.cpp32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 8db0df69..d0c55073 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -34,21 +34,6 @@
#include <cmath>
-ItemClass *MonsterClass::getRandomDrop() const
-{
- int p = rand() / (RAND_MAX / 10000);
- for (MonsterDrops::const_iterator i = mDrops.begin(),
- i_end = mDrops.end(); i != i_end; ++i)
- {
- p -= i->probability;
- if (p < 0)
- {
- return i->item;
- }
- }
- return NULL;
-}
-
struct MonsterTargetEventDispatch: EventDispatch
{
MonsterTargetEventDispatch()
@@ -466,13 +451,18 @@ void Monster::died()
if (mExpReceivers.size() > 0)
{
- // If the monster was killed by players, randomly drop an item.
- if (ItemClass *drop = mSpecy->getRandomDrop())
+ // If the monster was killed by players, randomly drop items.
+ const unsigned size = mSpecy->mDrops.size();
+ for (unsigned i = 0; i < size; i++)
{
- Item *item = new Item(drop, 1);
- item->setMap(getMap());
- item->setPosition(getPosition());
- GameState::enqueueInsert(item);
+ const int p = rand() / (RAND_MAX / 10000);
+ if (p <= mSpecy->mDrops[i].probability)
+ {
+ Item *item = new Item(mSpecy->mDrops[i].item, 1);
+ item->setMap(getMap());
+ item->setPosition(getPosition());
+ GameState::enqueueInsert(item);
+ }
}
// Distribute exp reward.