summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--example/clientdata/monsters.xml45
-rw-r--r--src/game-server/monster.cpp32
-rw-r--r--src/game-server/monster.h7
3 files changed, 32 insertions, 52 deletions
diff --git a/example/clientdata/monsters.xml b/example/clientdata/monsters.xml
index 5b478e5..a268096 100644
--- a/example/clientdata/monsters.xml
+++ b/example/clientdata/monsters.xml
@@ -41,12 +41,10 @@ exp<TAG>: Tells how much experience point a monster is giving up
<sound event="hit">monsters/maggot/maggot-hit2.ogg</sound>
<sound event="miss">monsters/maggot/maggot-miss1.ogg</sound>
<sound event="die">monsters/maggot/maggot-dying1.ogg</sound>
- <drop item="505" percent="8"/>
- <drop item="518" percent="4"/>
- <drop item="501" percent="1.5"/>
- <drop item="533" percent="1.5"/>
- <drop item="502" percent="0.7"/>
- <drop item="522" percent="0.1"/>
+ <drop item="1" percent="50"/>
+ <drop item="2" percent="15"/>
+ <drop item="3" percent="2.8"/>
+ <drop item="4" percent="0.7"/>
<attributes
hp="20"
size="4"
@@ -92,10 +90,10 @@ exp<TAG>: Tells how much experience point a monster is giving up
<sound event="hit">monsters/scorpion/scorpion-hit3.ogg</sound>
<sound event="hit">monsters/scorpion/scorpion-hit4.ogg</sound>
<sound event="miss">monsters/scorpion/scorpion-miss1.ogg</sound>
- <drop item="507" percent="7"/>
- <drop item="510" percent="1"/>
- <drop item="509" percent="0.5"/>
- <drop item="518" percent="7"/>
+ <drop item="1" percent="7"/>
+ <drop item="2" percent="1"/>
+ <drop item="5" percent="0.5"/>
+ <drop item="9" percent="7"/>
<exp>20</exp>
<attributes
hp="20"
@@ -147,13 +145,11 @@ exp<TAG>: Tells how much experience point a monster is giving up
<sound event="hit">monsters/scorpion/scorpion-hit3.ogg</sound>
<sound event="hit">monsters/scorpion/scorpion-hit4.ogg</sound>
<sound event="miss">monsters/scorpion/scorpion-miss1.ogg</sound>
- <drop item="517" percent="20"/>
- <drop item="509" percent="1"/>
- <drop item="518" percent="5"/>
- <drop item="1200" percent="0.1"/>
- <drop item="1199" percent="7.6"/>
- <drop item="1201" percent="5.4"/>
- <drop item="524" percent="0.1"/>
+ <drop item="2" percent="20"/>
+ <drop item="3" percent="1"/>
+ <drop item="4" percent="5"/>
+ <drop item="6" percent="0.1"/>
+ <drop item="9" percent="5.4"/>
<exp>50</exp>
<attributes
hp="20"
@@ -191,14 +187,13 @@ exp<TAG>: Tells how much experience point a monster is giving up
<monster id="4" name="Green Slime">
<sprite>monsters/monster-slime.xml|#72982c,ffffff</sprite>
<sound event="hit">monsters/slime/slime-hit1.ogg</sound>
- <drop item="502" percent="2"/>
- <drop item="513" percent="1"/>
- <drop item="501" percent="1"/>
- <drop item="521" percent="1"/>
- <drop item="522" percent="1.9"/>
- <drop item="526" percent="0.1"/>
- <drop item="503" percent="5"/>
- <drop item="535" percent="7.5"/>
+ <drop item="1" percent="2"/>
+ <drop item="2" percent="1"/>
+ <drop item="3" percent="1"/>
+ <drop item="4" percent="1"/>
+ <drop item="7" percent="1.9"/>
+ <drop item="8" percent="0.1"/>
+ <drop item="9" percent="7.5"/>
<exp>60</exp>
<attributes
hp="200"
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 8db0df6..d0c5507 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 7d459c4..b946316 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;
};
/**