mirror of
https://github.com/OpenFusionProject/OpenFusion.git
synced 2024-11-05 06:50:04 +00:00
Add item stacking logic
This commit is contained in:
parent
fb281b0237
commit
1eb806af58
@ -98,10 +98,38 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
resp.ToSlotItem = *toItem;
|
resp.ToSlotItem = *toItem;
|
||||||
resp.FromSlotItem = *fromItem;
|
resp.FromSlotItem = *fromItem;
|
||||||
|
|
||||||
// swap items in session
|
// swap/stack items in session
|
||||||
|
Item* itemDat = getItemData(toItem->iID, toItem->iType);
|
||||||
|
if (itemDat->stackSize > 1 && itemDat == getItemData(fromItem->iID, fromItem->iType)) {
|
||||||
|
// items are stackable and identical, so run stacking logic
|
||||||
|
|
||||||
|
toItem->iOpt += fromItem->iOpt; // sum counts
|
||||||
|
fromItem->iOpt = 0; // deplete from item
|
||||||
|
if (toItem->iOpt > itemDat->stackSize) {
|
||||||
|
// handle overflow
|
||||||
|
fromItem->iOpt += (toItem->iOpt - itemDat->stackSize); // add overflow to fromItem
|
||||||
|
toItem->iOpt = itemDat->stackSize; // set toItem count to max
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fromItem->iOpt == 0) { // from item count depleted
|
||||||
|
// delete item
|
||||||
|
fromItem->iID = 0;
|
||||||
|
fromItem->iType = 0;
|
||||||
|
fromItem->iTimeLimit = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
resp.iFromSlotNum = itemmove->iFromSlotNum;
|
||||||
|
resp.iToSlotNum = itemmove->iToSlotNum;
|
||||||
|
resp.FromSlotItem = *fromItem;
|
||||||
|
resp.ToSlotItem = *toItem;
|
||||||
|
} else {
|
||||||
|
// items not stackable; just swap them
|
||||||
sItemBase temp = *toItem;
|
sItemBase temp = *toItem;
|
||||||
*toItem = *fromItem;
|
*toItem = *fromItem;
|
||||||
*fromItem = temp;
|
*fromItem = temp;
|
||||||
|
resp.iFromSlotNum = itemmove->iToSlotNum;
|
||||||
|
resp.iToSlotNum = itemmove->iFromSlotNum;
|
||||||
|
}
|
||||||
|
|
||||||
// send equip change to viewable players
|
// send equip change to viewable players
|
||||||
if (itemmove->eFrom == (int)SlotType::EQUIP || itemmove->eTo == (int)SlotType::EQUIP) {
|
if (itemmove->eFrom == (int)SlotType::EQUIP || itemmove->eTo == (int)SlotType::EQUIP) {
|
||||||
@ -130,9 +158,8 @@ void ItemManager::itemMoveHandler(CNSocket* sock, CNPacketData* data) {
|
|||||||
|
|
||||||
// send response
|
// send response
|
||||||
resp.eTo = itemmove->eFrom;
|
resp.eTo = itemmove->eFrom;
|
||||||
resp.iToSlotNum = itemmove->iFromSlotNum;
|
|
||||||
resp.eFrom = itemmove->eTo;
|
resp.eFrom = itemmove->eTo;
|
||||||
resp.iFromSlotNum = itemmove->iToSlotNum;
|
|
||||||
|
|
||||||
sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
|
sock->sendPacket((void*)&resp, P_FE2CL_PC_ITEM_MOVE_SUCC, sizeof(sP_FE2CL_PC_ITEM_MOVE_SUCC));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user