summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-14 20:09:22 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-14 23:35:07 +0300
commit796f7e2c2ace55462acfa50e5085d4d048047e68 (patch)
tree878c6f36f001774047cc26fa7fb68f474920bbf0 /src/being.cpp
parent6b5c7e7a5ed32abfc98d9acdebacc50c68a91a1d (diff)
downloadmanaverse-796f7e2c2ace55462acfa50e5085d4d048047e68.tar.gz
manaverse-796f7e2c2ace55462acfa50e5085d4d048047e68.tar.bz2
manaverse-796f7e2c2ace55462acfa50e5085d4d048047e68.tar.xz
manaverse-796f7e2c2ace55462acfa50e5085d4d048047e68.zip
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.
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)
{