From 796f7e2c2ace55462acfa50e5085d4d048047e68 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 14 Apr 2013 20:09:22 +0300 Subject: add basic client side only support for pets. now pets cant move and dont have any ai. pet can be only spawn at player position if equiped item with assigned pet. --- src/being.cpp | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'src/being.cpp') 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::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) { -- cgit v1.2.3-60-g2f50