summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-09-23 00:42:38 +0300
committerAndrei Karas <akaras@inbox.ru>2014-09-23 00:42:38 +0300
commit2acd4cd73813e8cd0bf6d662e10e34af59cfac99 (patch)
tree2fa62d81b7849510df10a9efb8cec8b3384fa12b
parentc4122f537ce74b55c6e465d2020f17b791b278a4 (diff)
downloadplus-2acd4cd73813e8cd0bf6d662e10e34af59cfac99.tar.gz
plus-2acd4cd73813e8cd0bf6d662e10e34af59cfac99.tar.bz2
plus-2acd4cd73813e8cd0bf6d662e10e34af59cfac99.tar.xz
plus-2acd4cd73813e8cd0bf6d662e10e34af59cfac99.zip
eathena: use petinfo for loading and storing data about pet.
-rw-r--r--src/being/petinfo.h11
-rw-r--r--src/being/playerinfo.cpp23
-rw-r--r--src/being/playerinfo.h7
-rw-r--r--src/net/eathena/pethandler.cpp65
4 files changed, 95 insertions, 11 deletions
diff --git a/src/being/petinfo.h b/src/being/petinfo.h
index 3d171079d..8e7b50200 100644
--- a/src/being/petinfo.h
+++ b/src/being/petinfo.h
@@ -30,8 +30,11 @@ struct PetInfo final
id(0),
level(0),
hungry(0),
- intimate(0),
- race(0)
+ intimacy(0),
+ race(0),
+ performance(0),
+ hairStyle(0),
+ equip(0)
{ }
A_DELETE_COPY(PetInfo)
@@ -40,7 +43,11 @@ struct PetInfo final
int id;
int level;
int hungry;
+ int intimacy;
int race;
+ int performance;
+ int hairStyle;
+ int equip;
};
#endif // BEING_PETINFO_H
diff --git a/src/being/playerinfo.cpp b/src/being/playerinfo.cpp
index e23c4c1b5..6c4e1c92d 100644
--- a/src/being/playerinfo.cpp
+++ b/src/being/playerinfo.cpp
@@ -28,6 +28,7 @@
#include "being/attributes.h"
#include "being/localplayer.h"
#include "being/mercenaryinfo.h"
+#include "being/petinfo.h"
#include "itemsoundmanager.h"
@@ -56,6 +57,7 @@ int mCharId = 0;
Inventory *mInventory = nullptr;
Equipment *mEquipment = nullptr;
MercenaryInfo *mMercenary = nullptr;
+PetInfo *mPet = nullptr;
bool mTrading = false;
int mLevelProgress = 0;
@@ -488,4 +490,25 @@ MercenaryInfo *getMercenary()
return mMercenary;
}
+void setPet(PetInfo *const info)
+{
+ if (mPet)
+ delete mPet;
+ mPet = info;
+}
+
+void setPetBeing(Being *const being)
+{
+ if (!being || !mPet)
+ return;
+ being->setName(mPet->name);
+ being->setOwner(localPlayer);
+ being->setLevel(mPet->level);
+}
+
+PetInfo *getPet()
+{
+ return mPet;
+}
+
} // namespace PlayerInfo
diff --git a/src/being/playerinfo.h b/src/being/playerinfo.h
index 4fcc5dfc1..23fb41731 100644
--- a/src/being/playerinfo.h
+++ b/src/being/playerinfo.h
@@ -64,6 +64,7 @@ class Inventory;
class Item;
struct MercenaryInfo;
+struct PetInfo;
/**
* A database like namespace which holds global info about the localplayer
@@ -242,6 +243,12 @@ namespace PlayerInfo
void setMercenary(MercenaryInfo *const info);
void setMercenaryBeing(Being *const being);
+
+ PetInfo *getPet();
+
+ void setPet(PetInfo *const info);
+
+ void setPetBeing(Being *const being);
} // namespace PlayerInfo
#endif // BEING_PLAYERINFO_H
diff --git a/src/net/eathena/pethandler.cpp b/src/net/eathena/pethandler.cpp
index 899e836bf..f8984d10b 100644
--- a/src/net/eathena/pethandler.cpp
+++ b/src/net/eathena/pethandler.cpp
@@ -20,9 +20,11 @@
#include "net/eathena/pethandler.h"
+#include "actormanager.h"
#include "inventory.h"
#include "notifymanager.h"
+#include "being/petinfo.h"
#include "being/playerinfo.h"
#include "gui/chatconsts.h"
@@ -183,20 +185,65 @@ void PetHandler::processEggsList(Net::MessageIn &msg)
void PetHandler::processPetData(Net::MessageIn &msg)
{
- msg.readUInt8("type");
- msg.readInt32("pet id");
- msg.readInt32("param");
+ const int cmd = msg.readUInt8("type");
+ const int id = msg.readInt32("pet id");
+ Being *const dstBeing = actorManager->findBeing(id);
+ const int data = msg.readInt32("data");
+ if (!cmd) // pre init
+ {
+ PetInfo *const info = new PetInfo;
+ info->id = id;
+ PlayerInfo::setPet(info);
+ PlayerInfo::setPetBeing(dstBeing);
+ return;
+ }
+ PetInfo *const info = PlayerInfo::getPet();
+ if (!info)
+ return;
+ switch (cmd)
+ {
+ case 1: // intimacy
+ info->intimacy = data;
+ break;
+ case 2: // hunger
+ info->hungry = data;
+ break;
+ case 3: // accesory
+ info->equip = data;
+ break;
+ case 4: // performance
+ info->performance = data;
+ break;
+ case 5: // hair style
+ info->hairStyle = data;
+ break;
+ default:
+ break;
+ }
}
void PetHandler::processPetStatus(Net::MessageIn &msg)
{
- msg.readString(24, "pet name");
+ const std::string name = msg.readString(24, "pet name");
msg.readUInt8("rename flag");
- msg.readInt16("level");
- msg.readInt16("hungry");
- msg.readInt16("intimate");
- msg.readInt16("equip");
- msg.readInt16("class");
+ const int level = msg.readInt16("level");
+ const int hungry = msg.readInt16("hungry");
+ const int intimacy = msg.readInt16("intimacy");
+ const int equip = msg.readInt16("equip");
+ const int race = msg.readInt16("class");
+
+// Being *const being = PlayerInfo::getPetBeing();
+// if (being)
+// being->setLevel(level);
+
+ PetInfo *const info = PlayerInfo::getPet();
+ if (!info)
+ return;
+ info->level = level;
+ info->hungry = hungry;
+ info->intimacy = intimacy;
+ info->equip = equip;
+ info->race = race;
}
} // namespace EAthena