summaryrefslogtreecommitdiff
path: root/src/game-server/character.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server/character.cpp')
-rw-r--r--src/game-server/character.cpp164
1 files changed, 161 insertions, 3 deletions
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index 48621ef4..a08b07ff 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -36,7 +36,6 @@
#include "scripting/scriptmanager.h"
#include "net/messagein.h"
#include "net/messageout.h"
-#include "serialize/characterdata.h"
#include "utils/logger.h"
@@ -105,8 +104,7 @@ CharacterComponent::CharacterComponent(Entity &entity, MessageIn &msg):
mDatabaseID = msg.readInt32();
beingComponent->setName(msg.readString());
- CharacterData characterData(&entity, this);
- deserializeCharacterData(characterData, msg);
+ deserialize(entity, msg);
Inventory(&entity, mPossessions).initialize();
modifiedAllAttributes(entity);;
@@ -123,6 +121,166 @@ CharacterComponent::~CharacterComponent()
delete mNpcThread;
}
+void CharacterComponent::deserialize(Entity &entity, MessageIn &msg)
+{
+ auto *beingComponent = entity.getComponent<BeingComponent>();
+
+ // general character properties
+ setAccountLevel(msg.readInt8());
+ beingComponent->setGender(ManaServ::getGender(msg.readInt8()));
+ setHairStyle(msg.readInt8());
+ setHairColor(msg.readInt8());
+ setAttributePoints(msg.readInt16());
+ setCorrectionPoints(msg.readInt16());
+
+ // character attributes
+ unsigned attrSize = msg.readInt16();
+ for (unsigned i = 0; i < attrSize; ++i)
+ {
+ unsigned id = msg.readInt16();
+ double base = msg.readDouble();
+ beingComponent->setAttribute(entity, id, base);
+ }
+
+ // status effects currently affecting the character
+ int statusSize = msg.readInt16();
+
+ for (int i = 0; i < statusSize; i++)
+ {
+ int status = msg.readInt16();
+ int time = msg.readInt16();
+ beingComponent->applyStatusEffect(status, time);
+ }
+
+ // location
+ auto *map = MapManager::getMap(msg.readInt16());
+ entity.setMap(map);
+
+ Point temporaryPoint;
+ temporaryPoint.x = msg.readInt16();
+ temporaryPoint.y = msg.readInt16();
+ entity.getComponent<ActorComponent>()->setPosition(entity, temporaryPoint);
+
+ // kill count
+ int killSize = msg.readInt16();
+ for (int i = 0; i < killSize; i++)
+ {
+ int monsterId = msg.readInt16();
+ int kills = msg.readInt32();
+ setKillCount(monsterId, kills);
+ }
+
+ // character abilities
+ int abilitiesSize = msg.readInt16();
+ for (int i = 0; i < abilitiesSize; i++)
+ {
+ const int id = msg.readInt32();
+ entity.getComponent<AbilityComponent>()->giveAbility(id);
+ }
+
+
+ Possessions &poss = getPossessions();
+ EquipData equipData;
+ int equipSlotsSize = msg.readInt16();
+ unsigned eqSlot;
+ EquipmentItem equipItem;
+ for (int j = 0; j < equipSlotsSize; ++j)
+ {
+ eqSlot = msg.readInt16();
+ equipItem.itemId = msg.readInt16();
+ equipItem.itemInstance = msg.readInt16();
+ equipData.insert(equipData.end(),
+ std::make_pair(eqSlot, equipItem));
+ }
+ poss.setEquipment(equipData);
+
+ // Loads inventory - must be last because size isn't transmitted
+ InventoryData inventoryData;
+ while (msg.getUnreadLength())
+ {
+ InventoryItem i;
+ int slotId = msg.readInt16();
+ i.itemId = msg.readInt16();
+ i.amount = msg.readInt16();
+ inventoryData.insert(inventoryData.end(), std::make_pair(slotId, i));
+ }
+ poss.setInventory(inventoryData);
+}
+
+void CharacterComponent::serialize(Entity &entity, MessageOut &msg)
+{
+ auto *beingComponent = entity.getComponent<BeingComponent>();
+
+ // general character properties
+ msg.writeInt8(getAccountLevel());
+ msg.writeInt8(beingComponent->getGender());
+ msg.writeInt8(getHairStyle());
+ msg.writeInt8(getHairColor());
+ msg.writeInt16(getAttributePoints());
+ msg.writeInt16(getCorrectionPoints());
+
+
+ const AttributeMap &attributes = beingComponent->getAttributes();
+ msg.writeInt16(attributes.size());
+ for (auto attributeIt : attributes)
+ {
+ msg.writeInt16(attributeIt.first);
+ msg.writeDouble(attributeIt.second.getBase());
+ msg.writeDouble(attributeIt.second.getModifiedAttribute());
+ }
+
+ // status effects currently affecting the character
+ auto &statusEffects = beingComponent->getStatusEffects();
+ msg.writeInt16(statusEffects.size());
+ for (auto &statusIt : statusEffects)
+ {
+ msg.writeInt16(statusIt.first);
+ msg.writeInt16(statusIt.second.time);
+ }
+
+ // location
+ msg.writeInt16(entity.getMap()->getID());
+ const Point &pos = entity.getComponent<ActorComponent>()->getPosition();
+ msg.writeInt16(pos.x);
+ msg.writeInt16(pos.y);
+
+ // kill count
+ msg.writeInt16(getKillCountSize());
+ for (auto &killCountIt : mKillCount)
+ {
+ msg.writeInt16(killCountIt.first);
+ msg.writeInt32(killCountIt.second);
+ }
+
+ // character abilities
+ auto &abilities = entity.getComponent<AbilityComponent>()->getAbilities();
+ msg.writeInt16(abilities.size());
+ for (auto &abilityIt : abilities) {
+ msg.writeInt32(abilityIt.first);
+ }
+
+ // inventory - must be last because size isn't transmitted
+ const Possessions &poss = getPossessions();
+ const EquipData &equipData = poss.getEquipment();
+ msg.writeInt16(equipData.size()); // number of equipment
+ for (EquipData::const_iterator k = equipData.begin(),
+ k_end = equipData.end(); k != k_end; ++k)
+ {
+ msg.writeInt16(k->first); // Equip slot id
+ msg.writeInt16(k->second.itemId); // ItemId
+ msg.writeInt16(k->second.itemInstance); // Item Instance id
+ }
+
+ const InventoryData &inventoryData = poss.getInventory();
+ for (InventoryData::const_iterator j = inventoryData.begin(),
+ j_end = inventoryData.end(); j != j_end; ++j)
+ {
+ msg.writeInt16(j->first); // slot id
+ msg.writeInt16(j->second.itemId); // item id
+ msg.writeInt16(j->second.amount); // amount
+ }
+}
+
void CharacterComponent::update(Entity &entity)
{
// Dead character: don't regenerate anything else