fixed ItemManager

This commit is contained in:
CPunch 2020-08-20 22:25:39 -05:00
parent aa2adcd9e2
commit eee1b52722

View File

@ -12,52 +12,65 @@ void ItemManager::init() {
void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) { void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
if (data->size != sizeof(sP_CL2FE_REQ_ITEM_MOVE)) if (data->size != sizeof(sP_CL2FE_REQ_ITEM_MOVE))
return; // ignore the malformed packet return; // ignore the malformed packet
sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf; sP_CL2FE_REQ_ITEM_MOVE* itemmove = (sP_CL2FE_REQ_ITEM_MOVE*)data->buf;
sP_FE2CL_PC_ITEM_MOVE_SUCC* resp = (sP_FE2CL_PC_ITEM_MOVE_SUCC*)xmalloc(sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC)); sP_FE2CL_PC_ITEM_MOVE_SUCC* resp = (sP_FE2CL_PC_ITEM_MOVE_SUCC*)xmalloc(sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
PlayerView plr = PlayerManager::players[sock]; PlayerView plr = PlayerManager::players[sock];
sItemBase fromItem;
//weird flip flop but it makes things happen sItemBase toItem;
resp->eFrom = itemmove->eTo;
resp->iFromSlotNum = itemmove->iToSlotNum;
resp->eTo = itemmove->eFrom;
resp->iToSlotNum = itemmove->iFromSlotNum;
//eFrom 0 means from equip, 1 means from inventory // eFrom 0 means from equip
if (itemmove->eFrom == 0) { if (itemmove->eFrom == 0) {
resp->FromSlotItem = plr.plr.Equip[itemmove->iFromSlotNum]; // unequiping an item
std::cout << "unequipting item" << std::endl;
fromItem = plr.plr.Equip[itemmove->iFromSlotNum];
} else { } else {
resp->FromSlotItem = plr.plr.Inven[itemmove->iFromSlotNum]; fromItem = plr.plr.Inven[itemmove->iFromSlotNum];
} }
//eTo 0 means to equip, 1 means to inventory // eTo 0 means to equip
if (itemmove->eTo == 0) { if (itemmove->eTo == 0) {
resp->ToSlotItem = plr.plr.Equip[itemmove->iToSlotNum]; std::cout << "equipting item" << std::endl;
plr.plr.Equip[itemmove->iToSlotNum] = resp->FromSlotItem; // equiping an item
toItem = plr.plr.Equip[itemmove->iToSlotNum];
plr.plr.Equip[itemmove->iToSlotNum] = fromItem;
} else { } else {
resp->ToSlotItem = plr.plr.Inven[itemmove->iToSlotNum]; toItem = plr.plr.Inven[itemmove->iToSlotNum];
plr.plr.Inven[itemmove->iToSlotNum] = resp->FromSlotItem; plr.plr.Inven[itemmove->iToSlotNum] = fromItem;
} }
if (itemmove->eFrom == 0) { if (itemmove->eFrom == 0) {
plr.plr.Equip[itemmove->iFromSlotNum] = resp->ToSlotItem; plr.plr.Equip[itemmove->iFromSlotNum] = toItem;
sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
resp2->iPC_ID = plr.plr.iID;
resp2->iEquipSlotNum = resp->iToSlotNum;
resp2->EquipSlotItem = resp->ToSlotItem;
for (CNSocket* otherSock : plr.viewable) {
otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey()));
}
} else { } else {
plr.plr.Inven[itemmove->iFromSlotNum] = resp->ToSlotItem; plr.plr.Inven[itemmove->iFromSlotNum] = toItem;
} }
if (itemmove->eFrom == 0 || itemmove->eTo == 0) {
for (CNSocket* otherSock : plr.viewable) {
sP_FE2CL_PC_EQUIP_CHANGE* resp2 = (sP_FE2CL_PC_EQUIP_CHANGE*)xmalloc(sizeof(sP_FE2CL_PC_EQUIP_CHANGE));
resp2->iPC_ID = plr.plr.iID;
if (itemmove->eFrom == 0) {
resp2->iEquipSlotNum = itemmove->iFromSlotNum;
resp2->EquipSlotItem = toItem;
}
else {
resp2->iEquipSlotNum = itemmove->iToSlotNum;
resp2->EquipSlotItem = fromItem;
}
otherSock->sendPacket(new CNPacketData((void*)resp2, P_FE2CL_PC_EQUIP_CHANGE, sizeof(sP_FE2CL_PC_EQUIP_CHANGE), otherSock->getFEKey()));
}
}
PlayerManager::players[sock] = plr; PlayerManager::players[sock] = plr;
resp->eTo = itemmove->eFrom;
resp->iToSlotNum = itemmove->iFromSlotNum;
resp->ToSlotItem = toItem;
resp->eFrom = itemmove->eTo;
resp->iFromSlotNum = itemmove->iToSlotNum;
resp->FromSlotItem = fromItem;
sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey())); sock->sendPacket(new CNPacketData((void*)resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC), sock->getFEKey()));
} }