itemstats: check for two handed interactions (#12168)
This commit is contained in:
@@ -24,6 +24,7 @@
|
|||||||
*/
|
*/
|
||||||
package net.runelite.http.api.item;
|
package net.runelite.http.api.item;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Value;
|
import lombok.Value;
|
||||||
|
|
||||||
@@ -33,6 +34,9 @@ public class ItemEquipmentStats
|
|||||||
{
|
{
|
||||||
private int slot;
|
private int slot;
|
||||||
|
|
||||||
|
@SerializedName("is2h")
|
||||||
|
private boolean isTwoHanded;
|
||||||
|
|
||||||
private int astab;
|
private int astab;
|
||||||
private int aslash;
|
private int aslash;
|
||||||
private int acrush;
|
private int acrush;
|
||||||
@@ -51,4 +55,3 @@ public class ItemEquipmentStats
|
|||||||
private int prayer;
|
private int prayer;
|
||||||
private int aspeed;
|
private int aspeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -239,10 +239,18 @@ public class ItemStatOverlay extends Overlay
|
|||||||
return b.toString();
|
return b.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ItemStats getItemStatsFromContainer(ItemContainer container, int slotID)
|
||||||
|
{
|
||||||
|
final Item item = container.getItem(slotID);
|
||||||
|
return item != null ? itemManager.getItemStats(item.getId(), false) : null;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
String buildStatBonusString(ItemStats s)
|
String buildStatBonusString(ItemStats s)
|
||||||
{
|
{
|
||||||
ItemStats other = null;
|
ItemStats other = null;
|
||||||
|
// Used if switching into a 2 handed weapon to store off-hand stats
|
||||||
|
ItemStats offHand = null;
|
||||||
final ItemEquipmentStats currentEquipment = s.getEquipment();
|
final ItemEquipmentStats currentEquipment = s.getEquipment();
|
||||||
|
|
||||||
ItemContainer c = client.getItemContainer(InventoryID.EQUIPMENT);
|
ItemContainer c = client.getItemContainer(InventoryID.EQUIPMENT);
|
||||||
@@ -250,20 +258,39 @@ public class ItemStatOverlay extends Overlay
|
|||||||
{
|
{
|
||||||
final int slot = currentEquipment.getSlot();
|
final int slot = currentEquipment.getSlot();
|
||||||
|
|
||||||
final Item item = c.getItem(slot);
|
other = getItemStatsFromContainer(c, slot);
|
||||||
if (item != null)
|
// Check if this is a shield and there's a two-handed weapon equipped
|
||||||
|
if (other == null && slot == EquipmentInventorySlot.SHIELD.getSlotIdx())
|
||||||
{
|
{
|
||||||
other = itemManager.getItemStats(item.getId(), false);
|
other = getItemStatsFromContainer(c, EquipmentInventorySlot.WEAPON.getSlotIdx());
|
||||||
|
if (other != null)
|
||||||
|
{
|
||||||
|
final ItemEquipmentStats otherEquip = other.getEquipment();
|
||||||
|
if (otherEquip != null)
|
||||||
|
{
|
||||||
|
// Account for speed change when two handed weapon gets removed
|
||||||
|
// shield - (2h - unarmed) == shield - 2h + unarmed
|
||||||
|
other = otherEquip.isTwoHanded() ? other.subtract(UNARMED) : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (other == null && slot == EquipmentInventorySlot.WEAPON.getSlotIdx())
|
if (slot == EquipmentInventorySlot.WEAPON.getSlotIdx())
|
||||||
{
|
{
|
||||||
// Unarmed
|
if (other == null)
|
||||||
other = UNARMED;
|
{
|
||||||
|
other = UNARMED;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get offhand's stats to be removed from equipping a 2h weapon
|
||||||
|
if (currentEquipment.isTwoHanded())
|
||||||
|
{
|
||||||
|
offHand = getItemStatsFromContainer(c, EquipmentInventorySlot.SHIELD.getSlotIdx());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ItemStats subtracted = s.subtract(other);
|
final ItemStats subtracted = s.subtract(other).subtract(offHand);
|
||||||
final ItemEquipmentStats e = subtracted.getEquipment();
|
final ItemEquipmentStats e = subtracted.getEquipment();
|
||||||
|
|
||||||
final StringBuilder b = new StringBuilder();
|
final StringBuilder b = new StringBuilder();
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public class ItemStatOverlayTest
|
|||||||
private static final ItemStats ABYSSAL_DAGGER = new ItemStats(false, true, 0.453, 8,
|
private static final ItemStats ABYSSAL_DAGGER = new ItemStats(false, true, 0.453, 8,
|
||||||
ItemEquipmentStats.builder()
|
ItemEquipmentStats.builder()
|
||||||
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
||||||
|
.isTwoHanded(false)
|
||||||
.astab(75)
|
.astab(75)
|
||||||
.aslash(40)
|
.aslash(40)
|
||||||
.acrush(-4)
|
.acrush(-4)
|
||||||
@@ -67,6 +68,7 @@ public class ItemStatOverlayTest
|
|||||||
private static final ItemStats KATANA = new ItemStats(false, true, 0, 8,
|
private static final ItemStats KATANA = new ItemStats(false, true, 0, 8,
|
||||||
ItemEquipmentStats.builder()
|
ItemEquipmentStats.builder()
|
||||||
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
||||||
|
.isTwoHanded(true)
|
||||||
.astab(7)
|
.astab(7)
|
||||||
.aslash(45)
|
.aslash(45)
|
||||||
.dstab(3)
|
.dstab(3)
|
||||||
@@ -79,6 +81,7 @@ public class ItemStatOverlayTest
|
|||||||
private static final ItemStats BLOWPIPE = new ItemStats(false, true, 0, 0,
|
private static final ItemStats BLOWPIPE = new ItemStats(false, true, 0, 0,
|
||||||
ItemEquipmentStats.builder()
|
ItemEquipmentStats.builder()
|
||||||
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
||||||
|
.isTwoHanded(true)
|
||||||
.arange(60)
|
.arange(60)
|
||||||
.rstr(40)
|
.rstr(40)
|
||||||
.aspeed(3)
|
.aspeed(3)
|
||||||
@@ -86,6 +89,7 @@ public class ItemStatOverlayTest
|
|||||||
private static final ItemStats HEAVY_BALLISTA = new ItemStats(false, true, 4, 8,
|
private static final ItemStats HEAVY_BALLISTA = new ItemStats(false, true, 4, 8,
|
||||||
ItemEquipmentStats.builder()
|
ItemEquipmentStats.builder()
|
||||||
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
|
||||||
|
.isTwoHanded(true)
|
||||||
.arange(110)
|
.arange(110)
|
||||||
.aspeed(7)
|
.aspeed(7)
|
||||||
.build());
|
.build());
|
||||||
|
|||||||
Reference in New Issue
Block a user