From 406be26dd7a12795a4a2702aabe2ef46a5e0a6bb Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Thu, 26 May 2011 21:57:19 +0200 Subject: 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. --- example/clientdata/monsters.xml | 45 ++++++++++++++++++----------------------- src/game-server/monster.cpp | 32 ++++++++++------------------- src/game-server/monster.h | 7 +------ 3 files changed, 32 insertions(+), 52 deletions(-) diff --git a/example/clientdata/monsters.xml b/example/clientdata/monsters.xml index 5b478e5f..a268096f 100644 --- a/example/clientdata/monsters.xml +++ b/example/clientdata/monsters.xml @@ -41,12 +41,10 @@ exp: Tells how much experience point a monster is giving up monsters/maggot/maggot-hit2.ogg monsters/maggot/maggot-miss1.ogg monsters/maggot/maggot-dying1.ogg - - - - - - + + + + : Tells how much experience point a monster is giving up monsters/scorpion/scorpion-hit3.ogg monsters/scorpion/scorpion-hit4.ogg monsters/scorpion/scorpion-miss1.ogg - - - - + + + + 20 : Tells how much experience point a monster is giving up monsters/scorpion/scorpion-hit3.ogg monsters/scorpion/scorpion-hit4.ogg monsters/scorpion/scorpion-miss1.ogg - - - - - - - + + + + + 50 : Tells how much experience point a monster is giving up monsters/monster-slime.xml|#72982c,ffffff monsters/slime/slime-hit1.ogg - - - - - - - - + + + + + + + 60 -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; }; /** -- cgit v1.2.3-70-g09d2