summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 4f1016b79..564cdec34 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -57,6 +57,7 @@
#include "resources/iteminfo.h"
#include "resources/monsterdb.h"
#include "resources/npcdb.h"
+#include "resources/petdb.h"
#include "resources/resourcemanager.h"
#include "gui/widgets/chattab.h"
@@ -251,6 +252,9 @@ Being::Being(const int id, const Type type, const uint16_t subtype,
mInactive(false),
mNumber(100),
mHairColor(0),
+ mPet(nullptr),
+ mPetId(0),
+ mOwner(nullptr),
mSpecialParticle(nullptr)
{
for (int f = 0; f < 20; f ++)
@@ -301,6 +305,11 @@ Being::~Being()
mEmotionSprite = nullptr;
delete mAnimationEffect;
mAnimationEffect = nullptr;
+
+ if (mOwner)
+ mOwner->setPet(nullptr);
+ if (mPet)
+ mPet->setOwner(nullptr);
}
void Being::setSubtype(const uint16_t subtype)
@@ -332,6 +341,15 @@ void Being::setSubtype(const uint16_t subtype)
mYDiff = mInfo->getSortOffsetY();
}
}
+ else if (mType == PET)
+ {
+ mInfo = PETDB::get(mId);
+ if (mInfo)
+ {
+ setupSpriteDisplay(mInfo->getDisplay(), false);
+ mYDiff = mInfo->getSortOffsetY();
+ }
+ }
else if (mType == PLAYER)
{
int id = -100 - subtype;
@@ -1826,6 +1844,13 @@ void Being::setSprite(const unsigned int slot, const int id,
if (isWeapon)
mEquippedWeapon = nullptr;
+ const ItemInfo &info = ItemDB::get(mSpriteIDs[slot]);
+ if (mMap)
+ {
+ const int pet = info.getPet();
+ if (pet)
+ removePet();
+ }
}
else
{
@@ -1833,6 +1858,13 @@ void Being::setSprite(const unsigned int slot, const int id,
const std::string filename = info.getSprite(mGender, mSubType);
AnimatedSprite *equipmentSprite = nullptr;
+ if (mType == PLAYER)
+ {
+ const int pet = info.getPet();
+ if (pet)
+ addPet(pet);
+ }
+
if (!filename.empty())
{
if (color.empty())
@@ -2855,6 +2887,52 @@ void Being::addEffect(const std::string &name)
paths.getStringValue("sprites") + name);
}
+void Being::addPet(const int id)
+{
+ if (!actorSpriteManager)
+ return;
+
+ removePet();
+ Being *const being = actorSpriteManager->createBeing(
+ id, ActorSprite::PET, 0);
+ if (being)
+ {
+ being->setTileCoords(getTileX(), getTileY());
+ being->setOwner(this);
+ mPetId = id;
+ mPet = being;
+ }
+}
+
+void Being::removePet()
+{
+ if (!actorSpriteManager)
+ return;
+
+ mPetId = 0;
+ if (mPet)
+ {
+ mPet->setOwner(nullptr);
+ actorSpriteManager->destroy(mPet);
+ mPet = nullptr;
+ }
+}
+
+void Being::updatePets()
+{
+ removePet();
+ FOR_EACH (std::vector<int>::const_iterator, it, mSpriteIDs)
+ {
+ const ItemInfo &info = ItemDB::get(*it);
+ const int pet = info.getPet();
+ if (pet)
+ {
+ addPet(pet);
+ return;
+ }
+ }
+}
+
BeingEquipBackend::BeingEquipBackend(Being *const being):
mBeing(being)
{