diff options
Diffstat (limited to 'src/game-server')
-rw-r--r-- | src/game-server/monster.cpp | 32 | ||||
-rw-r--r-- | src/game-server/monster.h | 7 |
2 files changed, 12 insertions, 27 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. diff --git a/src/game-server/monster.h b/src/game-server/monster.h index 7d459c45..b9463168 100644 --- a/src/game-server/monster.h +++ b/src/game-server/monster.h @@ -190,12 +190,6 @@ class MonsterClass /** Returns script filename */ const std::string &getScript() const { return mScript; } - /** - * Randomly selects a monster drop - * @returns A class of item to drop, or NULL if none was found. - */ - ItemClass *getRandomDrop() const; - private: unsigned short mId; std::string mName; @@ -216,6 +210,7 @@ class MonsterClass std::string mScript; friend class MonsterManager; + friend class Monster; }; /** |