diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-01-12 14:23:46 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-01-12 14:23:46 +0300 |
commit | e06ebbc33fae83c4817a39af15fa0784ac233459 (patch) | |
tree | 0a3994053f79e53dd3ed0b9507af747638c99548 | |
parent | dbf80cecba66c3171ccebb6c22d85c3b52637882 (diff) | |
download | plus-e06ebbc33fae83c4817a39af15fa0784ac233459.tar.gz plus-e06ebbc33fae83c4817a39af15fa0784ac233459.tar.bz2 plus-e06ebbc33fae83c4817a39af15fa0784ac233459.tar.xz plus-e06ebbc33fae83c4817a39af15fa0784ac233459.zip |
fix using same pet from different items at same time.
-rw-r--r-- | src/being/being.cpp | 18 | ||||
-rw-r--r-- | src/being/being.h | 7 |
2 files changed, 20 insertions, 5 deletions
diff --git a/src/being/being.cpp b/src/being/being.cpp index 399b3883c..5c89ba579 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -177,6 +177,7 @@ Being::Being(const int id, const Type type, const uint16_t subtype, mPvpRank(0), mNumber(100), mLook(0), + mUsageCounter(1), mHairColor(0), mErased(false), mEnemy(false), @@ -3214,8 +3215,12 @@ void Being::addPet(const int id) if (!actorManager || !config.getBoolValue("usepets")) return; - if (findChildPet(id)) + Being *const pet = findChildPet(id); + if (pet) + { + pet->incUsage(); return; + } Being *const being = actorManager->createBeing( id, ActorSprite::PET, 0); @@ -3252,10 +3257,13 @@ void Being::removePet(const int id) Being *const pet = *it; if (pet && pet->mId == id) { - pet->setOwner(nullptr); - actorManager->erase(pet); - mPets.erase(it); - delete pet; + if (!pet->decUsage()) + { + pet->setOwner(nullptr); + actorManager->erase(pet); + mPets.erase(it); + delete pet; + } } } } diff --git a/src/being/being.h b/src/being/being.h index a93d0e3db..56319c352 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -924,6 +924,12 @@ class Being : public ActorSprite, public ConfigListener void recreateItemParticles(); + void incUsage() + { mUsageCounter ++; } + + int decUsage() + { return --mUsageCounter; } + protected: /** * Updates name's location. @@ -1084,6 +1090,7 @@ class Being : public ActorSprite, public ConfigListener unsigned int mNumber; int mPetId; int mLook; + int mUsageCounter; unsigned char mHairColor; bool mErased; bool mEnemy; |