2020-08-21 02:10:14 +00:00
|
|
|
#include "CNShardServer.hpp"
|
|
|
|
#include "CNStructs.hpp"
|
|
|
|
#include "ItemManager.hpp"
|
|
|
|
#include "PlayerManager.hpp"
|
|
|
|
#include "Player.hpp"
|
|
|
|
|
|
|
|
void ItemManager::init() {
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_ITEM_MOVE, itemMoveHandler);
|
2020-08-21 20:09:52 +00:00
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_ITEM_DELETE, itemDeleteHandler);
|
|
|
|
REGISTER_SHARD_PACKET(P_CL2FE_REQ_PC_GIVE_ITEM, itemGMGiveHandler);
|
2020-08-21 02:10:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_ITEM_MOVE))
|
|
|
|
return; // ignore the malformed packet
|
2020-08-21 03:25:39 +00:00
|
|
|
|
2020-08-21 02:10:14 +00:00
|
|
|
sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf;
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_ITEM_MOVE_SUCC, resp);
|
2020-08-21 03:25:39 +00:00
|
|
|
|
2020-08-21 19:28:14 +00:00
|
|
|
PlayerView& plr = PlayerManager::players[sock];
|
2020-08-21 03:25:39 +00:00
|
|
|
sItemBase fromItem;
|
|
|
|
sItemBase toItem;
|
2020-08-21 20:09:52 +00:00
|
|
|
|
2020-08-21 03:25:39 +00:00
|
|
|
// eFrom 0 means from equip
|
2020-08-21 02:10:14 +00:00
|
|
|
if (itemmove->eFrom == 0) {
|
2020-08-21 03:25:39 +00:00
|
|
|
// unequiping an item
|
|
|
|
fromItem = plr.plr.Equip[itemmove->iFromSlotNum];
|
2020-08-21 02:10:14 +00:00
|
|
|
} else {
|
2020-08-21 03:25:39 +00:00
|
|
|
fromItem = plr.plr.Inven[itemmove->iFromSlotNum];
|
2020-08-21 02:10:14 +00:00
|
|
|
}
|
2020-08-21 20:09:52 +00:00
|
|
|
|
2020-08-21 03:25:39 +00:00
|
|
|
// eTo 0 means to equip
|
2020-08-21 02:10:14 +00:00
|
|
|
if (itemmove->eTo == 0) {
|
2020-08-21 03:25:39 +00:00
|
|
|
// equiping an item
|
|
|
|
toItem = plr.plr.Equip[itemmove->iToSlotNum];
|
|
|
|
plr.plr.Equip[itemmove->iToSlotNum] = fromItem;
|
2020-08-21 02:10:14 +00:00
|
|
|
} else {
|
2020-08-21 03:25:39 +00:00
|
|
|
toItem = plr.plr.Inven[itemmove->iToSlotNum];
|
|
|
|
plr.plr.Inven[itemmove->iToSlotNum] = fromItem;
|
2020-08-21 02:10:14 +00:00
|
|
|
}
|
2020-08-21 03:25:39 +00:00
|
|
|
|
2020-08-21 02:10:14 +00:00
|
|
|
if (itemmove->eFrom == 0) {
|
2020-08-21 03:25:39 +00:00
|
|
|
plr.plr.Equip[itemmove->iFromSlotNum] = toItem;
|
2020-08-21 02:10:14 +00:00
|
|
|
} else {
|
2020-08-21 03:25:39 +00:00
|
|
|
plr.plr.Inven[itemmove->iFromSlotNum] = toItem;
|
2020-08-21 02:10:14 +00:00
|
|
|
}
|
2020-08-21 20:09:52 +00:00
|
|
|
|
|
|
|
if (itemmove->eFrom == 0 || itemmove->eTo == 0) {
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_PC_EQUIP_CHANGE, equipChange);
|
2020-08-22 23:31:09 +00:00
|
|
|
|
|
|
|
equipChange.iPC_ID = plr.plr.iID;
|
|
|
|
if (itemmove->eFrom == 0) {
|
|
|
|
equipChange.iEquipSlotNum = itemmove->iFromSlotNum;
|
|
|
|
equipChange.EquipSlotItem = toItem;
|
|
|
|
} else {
|
|
|
|
equipChange.iEquipSlotNum = itemmove->iToSlotNum;
|
|
|
|
equipChange.EquipSlotItem = fromItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
// send equip event to other players
|
2020-08-21 03:25:39 +00:00
|
|
|
for (CNSocket* otherSock : plr.viewable) {
|
2020-08-22 23:31:09 +00:00
|
|
|
otherSock->sendPacket((void*)&equipChange, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
|
2020-08-21 20:09:52 +00:00
|
|
|
}
|
2020-08-21 03:25:39 +00:00
|
|
|
}
|
2020-08-21 20:09:52 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.eTo = itemmove->eFrom;
|
|
|
|
resp.iToSlotNum = itemmove->iFromSlotNum;
|
|
|
|
resp.ToSlotItem = toItem;
|
|
|
|
resp.eFrom = itemmove->eTo;
|
|
|
|
resp.iFromSlotNum = itemmove->iToSlotNum;
|
|
|
|
resp.FromSlotItem = fromItem;
|
2020-08-21 03:25:39 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
|
2020-08-21 20:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemManager::itemDeleteHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_ITEM_DELETE))
|
|
|
|
return; // ignore the malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_ITEM_DELETE* itemdel = (sP_CL2FE_REQ_PC_ITEM_DELETE*)data->buf;
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC, resp);
|
2020-08-21 20:09:52 +00:00
|
|
|
|
|
|
|
PlayerView& plr = PlayerManager::players[sock];
|
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.eIL = itemdel->eIL;
|
|
|
|
resp.iSlotNum = itemdel->iSlotNum;
|
2020-08-21 20:09:52 +00:00
|
|
|
|
|
|
|
// so, im not sure what this eIL thing does since you always delete items in inventory and not equips
|
|
|
|
plr.plr.Inven[itemdel->iSlotNum].iID = 0;
|
|
|
|
plr.plr.Inven[itemdel->iSlotNum].iType = 0;
|
|
|
|
plr.plr.Inven[itemdel->iSlotNum].iOpt = 0;
|
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_ITEM_DELETE_SUCC, sizeof(sP_FE2CL_REP_PC_ITEM_DELETE_SUCC));
|
2020-08-21 20:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ItemManager::itemGMGiveHandler(CNSocket* sock, CNPacketData* data) {
|
|
|
|
if (data->size != sizeof(sP_CL2FE_REQ_PC_GIVE_ITEM))
|
|
|
|
return; // ignore the malformed packet
|
|
|
|
|
|
|
|
sP_CL2FE_REQ_PC_GIVE_ITEM* itemreq = (sP_CL2FE_REQ_PC_GIVE_ITEM*)data->buf;
|
|
|
|
PlayerView& plr = PlayerManager::players[sock];
|
|
|
|
|
2020-08-22 00:38:10 +00:00
|
|
|
// Commented and disabled for future use
|
|
|
|
//if (!plr.plr.IsGM) {
|
2020-08-21 20:09:52 +00:00
|
|
|
// TODO: send fail packet
|
2020-08-22 00:38:10 +00:00
|
|
|
// return;
|
|
|
|
//}
|
2020-08-21 20:09:52 +00:00
|
|
|
|
|
|
|
if (itemreq->eIL == 2) {
|
|
|
|
// Quest item, not a real item, handle this later, stubbed for now
|
|
|
|
// sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_REP_PC_GIVE_ITEM_FAIL, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_FAIL), sock->getFEKey()));
|
|
|
|
} else if (itemreq->eIL == 1) {
|
2020-08-23 00:26:18 +00:00
|
|
|
INITSTRUCT(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC, resp);
|
2020-08-21 20:09:52 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
resp.eIL = itemreq->eIL;
|
|
|
|
resp.iSlotNum = itemreq->iSlotNum;
|
|
|
|
resp.Item = itemreq->Item;
|
2020-08-21 20:09:52 +00:00
|
|
|
|
|
|
|
plr.plr.Inven[itemreq->iSlotNum] = itemreq->Item;
|
|
|
|
plr.plr.level = 36;
|
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp, P_FE2CL_REP_PC_GIVE_ITEM_SUCC, sizeof(sP_FE2CL_REP_PC_GIVE_ITEM_SUCC));
|
2020-08-21 20:09:52 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
// some items require a level, for now we're just going to bypass this by setting your level to 36
|
|
|
|
|
|
|
|
sP_FE2CL_REP_PC_CHANGE_LEVEL resp2;
|
2020-08-21 20:09:52 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
resp2.iPC_ID = plr.plr.iID;
|
|
|
|
resp2.iPC_Level = 36;
|
2020-08-21 20:09:52 +00:00
|
|
|
|
2020-08-22 23:31:09 +00:00
|
|
|
sock->sendPacket((void*)&resp2, P_FE2CL_REP_PC_CHANGE_LEVEL, sizeof(sP_FE2CL_REP_PC_CHANGE_LEVEL));
|
2020-08-21 20:09:52 +00:00
|
|
|
}
|
2020-08-21 02:10:14 +00:00
|
|
|
}
|