00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef _TMWSERV_SERIALIZE_CHARACTERDATA_HPP_
00022 #define _TMWSERV_SERIALIZE_CHARACTERDATA_HPP_
00023
00024 #include "defines.h"
00025 #include "common/inventorydata.hpp"
00026 #include "net/messagein.hpp"
00027 #include "net/messageout.hpp"
00028 #include "point.h"
00029
00030 template< class T >
00031 void serializeCharacterData(const T &data, MessageOut &msg)
00032 {
00033 msg.writeByte(data.getAccountLevel());
00034 msg.writeByte(data.getGender());
00035 msg.writeByte(data.getHairStyle());
00036 msg.writeByte(data.getHairColor());
00037 msg.writeShort(data.getLevel());
00038 msg.writeShort(data.getCharacterPoints());
00039 msg.writeShort(data.getCorrectionPoints());
00040
00041 for (int i = CHAR_ATTR_BEGIN; i < CHAR_ATTR_END; ++i)
00042 {
00043 msg.writeByte(data.getAttribute(i));
00044 }
00045
00046 for (int i = 0; i < CHAR_SKILL_NB; ++i)
00047 {
00048 msg.writeLong(data.getExperience(i));
00049 }
00050
00051
00052 msg.writeShort(data.getMapId());
00053 const Point &pos = data.getPosition();
00054 msg.writeShort(pos.x);
00055 msg.writeShort(pos.y);
00056
00057 const Possessions &poss = data.getPossessions();
00058 msg.writeLong(poss.money);
00059 for (int j = 0; j < EQUIPMENT_SLOTS; ++j)
00060 {
00061 msg.writeShort(poss.equipment[j]);
00062 }
00063 for (std::vector< InventoryItem >::const_iterator j = poss.inventory.begin(),
00064 j_end = poss.inventory.end(); j != j_end; ++j)
00065 {
00066 msg.writeShort(j->itemId);
00067 msg.writeByte(j->amount);
00068 }
00069 }
00070
00071 template< class T >
00072 void deserializeCharacterData(T &data, MessageIn &msg)
00073 {
00074 data.setAccountLevel(msg.readByte());
00075 data.setGender(msg.readByte());
00076 data.setHairStyle(msg.readByte());
00077 data.setHairColor(msg.readByte());
00078 data.setLevel(msg.readShort());
00079 data.setCharacterPoints(msg.readShort());
00080 data.setCorrectionPoints(msg.readShort());
00081
00082 for (int i = CHAR_ATTR_BEGIN; i < CHAR_ATTR_END; ++i)
00083 {
00084 data.setAttribute(i, msg.readByte());
00085 }
00086
00087 for (int i = 0; i < CHAR_SKILL_NB; ++i)
00088 {
00089 data.setExperience(i, msg.readLong());
00090 }
00091
00092 data.setMapId(msg.readShort());
00093
00094 Point temporaryPoint;
00095 temporaryPoint.x = msg.readShort();
00096 temporaryPoint.y = msg.readShort();
00097 data.setPosition(temporaryPoint);
00098
00099 Possessions &poss = data.getPossessions();
00100 poss.money = msg.readLong();
00101 for (int j = 0; j < EQUIPMENT_SLOTS; ++j)
00102 {
00103 poss.equipment[j] = msg.readShort();
00104 }
00105 poss.inventory.clear();
00106 while (msg.getUnreadLength())
00107 {
00108 InventoryItem i;
00109 i.itemId = msg.readShort();
00110 i.amount = msg.readByte();
00111 poss.inventory.push_back(i);
00112 }
00113 }
00114
00115 #endif