|
|
|
|
@ -292,22 +292,18 @@ bool AutoEquip(int playerId, const Item &item, inv_body_loc bodyLocation, bool p
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CheckInvPaste(Player &player, Point cursorPosition) |
|
|
|
|
int FindSlotUnderCursor(Point cursorPosition, Size itemSize) |
|
|
|
|
{ |
|
|
|
|
int i = cursorPosition.x; |
|
|
|
|
int j = cursorPosition.y; |
|
|
|
|
|
|
|
|
|
Size itemSize = GetInventorySize(player.HoldItem); |
|
|
|
|
|
|
|
|
|
if (!IsHardwareCursor()) { |
|
|
|
|
// offset the cursor position to match the hot pixel we'd use for a hardware cursor
|
|
|
|
|
i += itemSize.width * INV_SLOT_HALF_SIZE_PX; |
|
|
|
|
j += itemSize.height * INV_SLOT_HALF_SIZE_PX; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool done = false; |
|
|
|
|
int r = 0; |
|
|
|
|
for (; r < NUM_XY_SLOTS && !done; r++) { |
|
|
|
|
for (int r = 0; r < NUM_XY_SLOTS; r++) { |
|
|
|
|
int xo = GetRightPanel().position.x; |
|
|
|
|
int yo = GetRightPanel().position.y; |
|
|
|
|
if (r >= SLOTXY_BELT_FIRST) { |
|
|
|
|
@ -317,8 +313,7 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
|
|
|
|
|
if (i >= InvRect[r].x + xo && i <= InvRect[r].x + xo + InventorySlotSizeInPixels.width) { |
|
|
|
|
if (j >= InvRect[r].y + yo - InventorySlotSizeInPixels.height - 1 && j < InvRect[r].y + yo) { |
|
|
|
|
done = true; |
|
|
|
|
r--; |
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (r == SLOTXY_CHEST_LAST) { |
|
|
|
|
@ -330,37 +325,38 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
if (r == SLOTXY_INV_LAST && itemSize.height % 2 == 0) |
|
|
|
|
j += INV_SLOT_HALF_SIZE_PX; |
|
|
|
|
} |
|
|
|
|
if (!done) |
|
|
|
|
return NUM_XY_SLOTS; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CheckInvPaste(Player &player, Point cursorPosition) |
|
|
|
|
{ |
|
|
|
|
Size itemSize = GetInventorySize(player.HoldItem); |
|
|
|
|
|
|
|
|
|
int slot = FindSlotUnderCursor(cursorPosition, itemSize); |
|
|
|
|
if (slot == NUM_XY_SLOTS) |
|
|
|
|
return; |
|
|
|
|
|
|
|
|
|
item_equip_type il = ILOC_UNEQUIPABLE; |
|
|
|
|
if (r >= SLOTXY_HEAD_FIRST && r <= SLOTXY_HEAD_LAST) |
|
|
|
|
if (slot >= SLOTXY_HEAD_FIRST && slot <= SLOTXY_HEAD_LAST) |
|
|
|
|
il = ILOC_HELM; |
|
|
|
|
if (r >= SLOTXY_RING_LEFT && r <= SLOTXY_RING_RIGHT) |
|
|
|
|
if (slot >= SLOTXY_RING_LEFT && slot <= SLOTXY_RING_RIGHT) |
|
|
|
|
il = ILOC_RING; |
|
|
|
|
if (r == SLOTXY_AMULET) |
|
|
|
|
if (slot == SLOTXY_AMULET) |
|
|
|
|
il = ILOC_AMULET; |
|
|
|
|
if (r >= SLOTXY_HAND_LEFT_FIRST && r <= SLOTXY_HAND_RIGHT_LAST) |
|
|
|
|
if (slot >= SLOTXY_HAND_LEFT_FIRST && slot <= SLOTXY_HAND_RIGHT_LAST) |
|
|
|
|
il = ILOC_ONEHAND; |
|
|
|
|
if (r >= SLOTXY_CHEST_FIRST && r <= SLOTXY_CHEST_LAST) |
|
|
|
|
if (slot >= SLOTXY_CHEST_FIRST && slot <= SLOTXY_CHEST_LAST) |
|
|
|
|
il = ILOC_ARMOR; |
|
|
|
|
if (r >= SLOTXY_BELT_FIRST && r <= SLOTXY_BELT_LAST) |
|
|
|
|
if (slot >= SLOTXY_BELT_FIRST && slot <= SLOTXY_BELT_LAST) |
|
|
|
|
il = ILOC_BELT; |
|
|
|
|
|
|
|
|
|
done = player.GetItemLocation(player.HoldItem) == il; |
|
|
|
|
|
|
|
|
|
if (il == ILOC_ONEHAND && player.GetItemLocation(player.HoldItem) == ILOC_TWOHAND) { |
|
|
|
|
item_equip_type desiredIl = player.GetItemLocation(player.HoldItem); |
|
|
|
|
if (il == ILOC_ONEHAND && desiredIl == ILOC_TWOHAND) |
|
|
|
|
il = ILOC_TWOHAND; |
|
|
|
|
done = true; |
|
|
|
|
} |
|
|
|
|
if (il == ILOC_BELT) { |
|
|
|
|
done = CanBePlacedOnBelt(player.HoldItem); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int8_t it = 0; |
|
|
|
|
if (il == ILOC_UNEQUIPABLE) { |
|
|
|
|
done = true; |
|
|
|
|
int ii = r - SLOTXY_INV_FIRST; |
|
|
|
|
int ii = slot - SLOTXY_INV_FIRST; |
|
|
|
|
if (player.HoldItem._itype == ItemType::Gold) { |
|
|
|
|
if (player.InvGrid[ii] != 0) { |
|
|
|
|
int8_t iv = player.InvGrid[ii]; |
|
|
|
|
@ -374,22 +370,20 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
int yy = std::max(INV_ROW_SLOT_SIZE * ((ii / INV_ROW_SLOT_SIZE) - ((itemSize.height - 1) / 2)), 0); |
|
|
|
|
for (j = 0; j < itemSize.height && done; j++) { |
|
|
|
|
for (int j = 0; j < itemSize.height; j++) { |
|
|
|
|
if (yy >= NUM_INV_GRID_ELEM) |
|
|
|
|
done = false; |
|
|
|
|
return; |
|
|
|
|
int xx = std::max((ii % INV_ROW_SLOT_SIZE) - ((itemSize.width - 1) / 2), 0); |
|
|
|
|
for (i = 0; i < itemSize.width && done; i++) { |
|
|
|
|
if (xx >= INV_ROW_SLOT_SIZE) { |
|
|
|
|
done = false; |
|
|
|
|
} else { |
|
|
|
|
if (player.InvGrid[xx + yy] != 0) { |
|
|
|
|
int8_t iv = abs(player.InvGrid[xx + yy]); |
|
|
|
|
if (it != 0) { |
|
|
|
|
if (it != iv) |
|
|
|
|
done = false; |
|
|
|
|
} else { |
|
|
|
|
it = iv; |
|
|
|
|
} |
|
|
|
|
for (int i = 0; i < itemSize.width; i++) { |
|
|
|
|
if (xx >= INV_ROW_SLOT_SIZE) |
|
|
|
|
return; |
|
|
|
|
if (player.InvGrid[xx + yy] != 0) { |
|
|
|
|
int8_t iv = abs(player.InvGrid[xx + yy]); |
|
|
|
|
if (it != 0) { |
|
|
|
|
if (it != iv) |
|
|
|
|
return; |
|
|
|
|
} else { |
|
|
|
|
it = iv; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
xx++; |
|
|
|
|
@ -397,18 +391,17 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
yy += INV_ROW_SLOT_SIZE; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!done) |
|
|
|
|
} else if (il == ILOC_BELT) { |
|
|
|
|
if (!CanBePlacedOnBelt(player.HoldItem)) |
|
|
|
|
return; |
|
|
|
|
} else if (desiredIl != il) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT) && !player.CanUseItem(player.HoldItem)) { |
|
|
|
|
done = false; |
|
|
|
|
player.Say(HeroSpeech::ICantUseThisYet); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!done) |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (player._pmode > PM_WALK3 && IsNoneOf(il, ILOC_UNEQUIPABLE, ILOC_BELT)) |
|
|
|
|
return; |
|
|
|
|
@ -421,12 +414,12 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
case ILOC_RING: |
|
|
|
|
case ILOC_AMULET: |
|
|
|
|
case ILOC_ARMOR: { |
|
|
|
|
auto iLocToInvLoc = [&r](item_equip_type loc) { |
|
|
|
|
auto iLocToInvLoc = [&slot](item_equip_type loc) { |
|
|
|
|
switch (loc) { |
|
|
|
|
case ILOC_HELM: |
|
|
|
|
return INVLOC_HEAD; |
|
|
|
|
case ILOC_RING: |
|
|
|
|
return (r == SLOTXY_RING_LEFT ? INVLOC_RING_LEFT : INVLOC_RING_RIGHT); |
|
|
|
|
return (slot == SLOTXY_RING_LEFT ? INVLOC_RING_LEFT : INVLOC_RING_RIGHT); |
|
|
|
|
case ILOC_AMULET: |
|
|
|
|
return INVLOC_AMULET; |
|
|
|
|
case ILOC_ARMOR: |
|
|
|
|
@ -444,8 +437,8 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case ILOC_ONEHAND: { |
|
|
|
|
inv_body_loc selectedHand = r <= SLOTXY_HAND_LEFT_LAST ? INVLOC_HAND_LEFT : INVLOC_HAND_RIGHT; |
|
|
|
|
inv_body_loc otherHand = r <= SLOTXY_HAND_LEFT_LAST ? INVLOC_HAND_RIGHT : INVLOC_HAND_LEFT; |
|
|
|
|
inv_body_loc selectedHand = slot <= SLOTXY_HAND_LEFT_LAST ? INVLOC_HAND_LEFT : INVLOC_HAND_RIGHT; |
|
|
|
|
inv_body_loc otherHand = slot <= SLOTXY_HAND_LEFT_LAST ? INVLOC_HAND_RIGHT : INVLOC_HAND_LEFT; |
|
|
|
|
|
|
|
|
|
bool pasteIntoSelectedHand = (player.InvBody[otherHand].isEmpty() || player.InvBody[otherHand]._iClass != player.HoldItem._iClass) |
|
|
|
|
|| (player._pClass == HeroClass::Bard && player.InvBody[otherHand]._iClass == ICLASS_WEAPON && player.HoldItem._iClass == ICLASS_WEAPON); |
|
|
|
|
@ -496,7 +489,7 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
break; |
|
|
|
|
case ILOC_UNEQUIPABLE: |
|
|
|
|
if (player.HoldItem._itype == ItemType::Gold && it == 0) { |
|
|
|
|
int ii = r - SLOTXY_INV_FIRST; |
|
|
|
|
int ii = slot - SLOTXY_INV_FIRST; |
|
|
|
|
if (player.InvGrid[ii] > 0) { |
|
|
|
|
int invIndex = player.InvGrid[ii] - 1; |
|
|
|
|
int gt = player.InvList[invIndex]._ivalue; |
|
|
|
|
@ -540,7 +533,7 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
itemIndex = 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
int ii = r - SLOTXY_INV_FIRST; |
|
|
|
|
int ii = slot - SLOTXY_INV_FIRST; |
|
|
|
|
|
|
|
|
|
// Calculate top-left position of item for InvGrid and then add item to InvGrid
|
|
|
|
|
|
|
|
|
|
@ -550,7 +543,7 @@ void CheckInvPaste(Player &player, Point cursorPosition)
|
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
case ILOC_BELT: { |
|
|
|
|
int ii = r - SLOTXY_BELT_FIRST; |
|
|
|
|
int ii = slot - SLOTXY_BELT_FIRST; |
|
|
|
|
if (player.SpdList[ii].isEmpty()) { |
|
|
|
|
player.SpdList[ii] = player.HoldItem.pop(); |
|
|
|
|
} else { |
|
|
|
|
|