itemstats: check for two handed interactions (#12168)

This commit is contained in:
Cyborger1
2020-07-21 04:13:11 -04:00
committed by GitHub
parent 05c4a5c1d5
commit 4362adb876
3 changed files with 42 additions and 8 deletions

View File

@@ -24,6 +24,7 @@
*/
package net.runelite.http.api.item;
import com.google.gson.annotations.SerializedName;
import lombok.Builder;
import lombok.Value;
@@ -33,6 +34,9 @@ public class ItemEquipmentStats
{
private int slot;
@SerializedName("is2h")
private boolean isTwoHanded;
private int astab;
private int aslash;
private int acrush;
@@ -51,4 +55,3 @@ public class ItemEquipmentStats
private int prayer;
private int aspeed;
}

View File

@@ -239,10 +239,18 @@ public class ItemStatOverlay extends Overlay
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
String buildStatBonusString(ItemStats s)
{
ItemStats other = null;
// Used if switching into a 2 handed weapon to store off-hand stats
ItemStats offHand = null;
final ItemEquipmentStats currentEquipment = s.getEquipment();
ItemContainer c = client.getItemContainer(InventoryID.EQUIPMENT);
@@ -250,20 +258,39 @@ public class ItemStatOverlay extends Overlay
{
final int slot = currentEquipment.getSlot();
final Item item = c.getItem(slot);
if (item != null)
other = getItemStatsFromContainer(c, slot);
// 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
other = UNARMED;
if (other == null)
{
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 StringBuilder b = new StringBuilder();

View File

@@ -56,6 +56,7 @@ public class ItemStatOverlayTest
private static final ItemStats ABYSSAL_DAGGER = new ItemStats(false, true, 0.453, 8,
ItemEquipmentStats.builder()
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
.isTwoHanded(false)
.astab(75)
.aslash(40)
.acrush(-4)
@@ -67,6 +68,7 @@ public class ItemStatOverlayTest
private static final ItemStats KATANA = new ItemStats(false, true, 0, 8,
ItemEquipmentStats.builder()
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
.isTwoHanded(true)
.astab(7)
.aslash(45)
.dstab(3)
@@ -79,6 +81,7 @@ public class ItemStatOverlayTest
private static final ItemStats BLOWPIPE = new ItemStats(false, true, 0, 0,
ItemEquipmentStats.builder()
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
.isTwoHanded(true)
.arange(60)
.rstr(40)
.aspeed(3)
@@ -86,6 +89,7 @@ public class ItemStatOverlayTest
private static final ItemStats HEAVY_BALLISTA = new ItemStats(false, true, 4, 8,
ItemEquipmentStats.builder()
.slot(EquipmentInventorySlot.WEAPON.getSlotIdx())
.isTwoHanded(true)
.arange(110)
.aspeed(7)
.build());