Changes 2 (#43)

* Initial commit for maxhit plugin

* WIP: Magic max hit calculator

* Add chance to obtain a Unique from Chambers of Xeric

Based on the formula from the wiki. Does not handle >80% chance properly (it should go into a second item)

* MaxHit Refactor a lot for magic max hit

* Wip: refactoring

* Pest Control Update

* Pest Control: Add Intermediate portals

* Revert "Remove raids points overlay"

This reverts commit fbd3ea6202.

* Wip: refactoring

* Fixed WidgetInfo merge issue

* Fixed trident

* Implement range

* Refactored according to intellij analyzer

* Run checkstyle from xml and fix code style issues

* Fix copyright

* Replace item names with item id's

* Code cleanup with reformat code

* Fixed checkstyle

* Use game slotitem

* Use game slotitem

* Fixed prayer bonus

* Looked up value for saradomin strike

* Fixed prayer bonus

* Fixed surge spell id's

* Fixed magix max hit tests

* Fixed rounding after obisidian

* Fix dharok custom formula

* Add melee max hit

* Refactored spellbonus items for magic

* Added voidknight

* Use boosted skill levels and add copyright

* Add accurate attack style for ranging

* Add range Tests

* Cleanup code

* Cleanup code

* Rename calculate methods to be more distinguishable

* Add parenthesis to dharok maxhit formula for clarification

* Fix widgetinfo merge

* Remove print in MaxHitPlugin

* Make sure an Item is not null when checking if the player is wearing it.

* Add daily notification for collection of ogre arrows from Rantz.

Add varbit for rantz arrow collection

Fix continuation indent settings


Group ifs to single check.

* Refactor all relevant daily checks to have grouped if check.


Further refactor grouped ifs

* Adds type

* Raids point overlay
This commit is contained in:
James
2019-04-22 01:49:35 -07:00
committed by Tyler Bochard
parent 3a01eb67dc
commit 41c12a858d
60 changed files with 5848 additions and 279 deletions

View File

@@ -0,0 +1,69 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.maxhit.calculators;
import com.google.inject.Guice;
import com.google.inject.testing.fieldbinder.Bind;
import com.google.inject.testing.fieldbinder.BoundFieldModule;
import net.runelite.api.Client;
import net.runelite.client.plugins.maxhit.calculators.testconfig.MagicMaxHitConfig;
import net.runelite.client.plugins.maxhit.calculators.testconfig.MaxHitConfig;
import net.runelite.client.plugins.maxhit.calculators.testconfig.MeleeMaxHitConfig;
import net.runelite.client.plugins.maxhit.calculators.testconfig.RangeMaxHitConfig;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
@RunWith(MockitoJUnitRunner.class)
public class MaxHitCalculatorTest
{
@Mock
@Bind
protected Client client;
@Before
public void setUp()
{
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void calculate()
{
testMaxHitConfig(MeleeMaxHitConfig.values());
testMaxHitConfig(RangeMaxHitConfig.values());
testMaxHitConfig(MagicMaxHitConfig.values());
}
private void testMaxHitConfig(MaxHitConfig[] maxHitConfigs)
{
for (MaxHitConfig maxHitConfig : maxHitConfigs)
{
maxHitConfig.test(client);
}
}
}

View File

@@ -0,0 +1,243 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.maxhit.calculators.testconfig;
import net.runelite.api.*;
import net.runelite.client.plugins.maxhit.calculators.MagicMaxHitCalculator;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public enum MagicMaxHitConfig implements MaxHitConfig
{
TRIDENT_SLAYER(new int[] {75, 83, 99}, 0, new Item[]
{
mockItem(ItemID.SLAYER_HELMET_I),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.OCCULT_NECKLACE),
mockItem(ItemID.TRIDENT_OF_THE_SEAS),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[] {25, 27, 34}),
TRIDENT_OF_SEAS(new int[] {75, 83, 99}, 0, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.TRIDENT_OF_THE_SEAS),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[] {20, 22, 28}),
TRIDENT_OF_SWAMP(new int[] {75, 83, 99}, 0, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.TRIDENT_OF_THE_SWAMP),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[] {23, 25, 31}),
MAGIC_DART(new int[] {75, 83, 99}, 18, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.SLAYERS_STAFF),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, new int[] {17, 18, 19}),
FIRE_BOLT(75, 8, new Item[]
{
mockItem(ItemID.SLAYER_HELMET_I),
mockItem(ItemID.IMBUED_SARADOMIN_CAPE),
mockItem(ItemID.OCCULT_NECKLACE),
mockItem(ItemID.STAFF_OF_THE_DEAD),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.TOME_OF_FIRE),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.CHAOS_GAUNTLETS),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 31),
WIND_BLAST(75, 9, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.STAFF_OF_AIR),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 13),
EARTH_WAVE(75, 15, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.OCCULT_NECKLACE),
mockItem(ItemID.STAFF_OF_EARTH),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.TOME_OF_FIRE),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 20),
FLAMES_OF_ZAMORAK(75, 20, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.STAFF_OF_THE_DEAD),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 23),
SARADOMIN_STRIKE(75, 52, new Item[]
{
mockItem(ItemID.MYSTIC_HAT),
mockItem(ItemID.SARADOMIN_CAPE),
mockItem(ItemID.AMULET_OF_GLORY),
mockItem(ItemID.STAFF_OF_LIGHT),
mockItem(ItemID.MYSTIC_ROBE_TOP),
mockItem(ItemID.BROODOO_SHIELD),
null,
mockItem(ItemID.MYSTIC_ROBE_BOTTOM),
null,
mockItem(ItemID.MYSTIC_GLOVES),
mockItem(ItemID.WIZARD_BOOTS),
mockItem(ItemID.RING_OF_WEALTH)
}, 23),
;
private final int[] magicLevels;
private final int spellId;
private final Item[] equipedItems;
private final int[] expectedMaxHits;
MagicMaxHitConfig(int magicLevel, int spellId, Item[] equipedItems, int expectedMaxHit)
{
this.magicLevels = new int[] {magicLevel};
this.spellId = spellId;
this.equipedItems = equipedItems;
this.expectedMaxHits = new int[] {expectedMaxHit};
}
MagicMaxHitConfig(int[] magicLevels, int spellId, Item[] equipedItems, int[] expectedMaxHits)
{
this.magicLevels = magicLevels;
this.spellId = spellId;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
private static Item mockItem(int itemId)
{
Item item = mock(Item.class);
when(item.getId()).thenReturn(itemId);
return item;
}
public void test(Client client)
{
int[] magicLevels = this.magicLevels;
for (int i = 0, magicLevelsLength = magicLevels.length; i < magicLevelsLength; i++)
{
int magicLevel = magicLevels[i];
int expectedMaxHit = this.expectedMaxHits[i];
// Mock equipment container
ItemContainer equipmentContainer = mock(ItemContainer.class);
when(equipmentContainer.getItems())
.thenReturn(this.equipedItems);
when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentContainer);
// Mock Varbits
when(client.getBoostedSkillLevel(Skill.MAGIC)).thenReturn(magicLevel);
when(client.getVar(Varbits.AUTO_CAST_SPELL)).thenReturn(this.spellId);
// Test
MagicMaxHitCalculator maxHitCalculator = new MagicMaxHitCalculator(client, this.equipedItems);
assertEquals(this.toString(), expectedMaxHit, maxHitCalculator.getMaxHit(), 0);
}
}
}

View File

@@ -0,0 +1,32 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.maxhit.calculators.testconfig;
import net.runelite.api.Client;
public interface MaxHitConfig
{
void test(Client client);
}

View File

@@ -0,0 +1,217 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.maxhit.calculators.testconfig;
import net.runelite.api.*;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.plugins.maxhit.attackstyle.WeaponType;
import net.runelite.client.plugins.maxhit.calculators.MeleeMaxHitCalculator;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public enum MeleeMaxHitConfig implements MaxHitConfig
{
DRAGON_SCIMITAR(new int[] {75, 83, 99}, 66, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.IRON_PLATEBODY),
mockItem(ItemID.IRON_KITESHIELD),
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[] {17, 19, 22}),
DRAGON_SCIMITAR_DEFENDER(new int[] {75, 83, 99}, 76, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.IRON_PLATEBODY),
mockItem(ItemID.DRAGON_DEFENDER),
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[] {19, 21, 24}),
DRAGON_SCIMITAR_COMPLETE(new int[] {75, 83, 99}, 108, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.SLAYER_HELMET),
mockItem(ItemID.FIRE_CAPE),
mockItem(ItemID.AMULET_OF_FURY),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.FIGHTER_TORSO),
mockItem(ItemID.DRAGON_DEFENDER),
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.BARROWS_GLOVES),
mockItem(ItemID.DRAGON_BOOTS),
mockItem(ItemID.BERSERKER_RING)
}, new int[] {26, 29, 35}),
OBSIDIAN_SET(new int[] {75, 83, 99}, 61, WeaponType.TYPE_17, 2, new Item[]
{
mockItem(ItemID.OBSIDIAN_HELMET),
mockItem(ItemID.OBSIDIAN_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.TOKTZXILAK),
mockItem(ItemID.OBSIDIAN_PLATEBODY),
mockItem(ItemID.TOKTZKETXIL),
null,
mockItem(ItemID.OBSIDIAN_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[] {18, 19, 23}),
DHAROK_SET(new int[] {75, 75, 75, 83, 83, 83, 99, 99, 99}, 105, WeaponType.TYPE_1, 1,
new int[][] {{99, 99}, {1, 99}, {32, 75}, {99, 99}, {1, 99}, {32, 75}, {99, 99}, {1, 99}, {32, 75}},
new Item[]
{
mockItem(ItemID.DHAROKS_HELM_100),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DHAROKS_GREATAXE_100),
mockItem(ItemID.DHAROKS_PLATEBODY_100),
null,
null,
mockItem(ItemID.DHAROKS_PLATELEGS_100),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[] {23, 45, 30, 25, 49, 33, 29, 57, 38}),
VOID_SET(new int[] {75, 83, 99}, 66, WeaponType.TYPE_9, 1, new Item[]
{
mockItem(ItemID.VOID_MELEE_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.DRAGON_SCIMITAR),
mockItem(ItemID.VOID_KNIGHT_TOP),
mockItem(ItemID.IRON_KITESHIELD),
null,
mockItem(ItemID.VOID_KNIGHT_ROBE),
null,
mockItem(ItemID.VOID_KNIGHT_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[] {19, 21, 25}),
;
private final int[] strengthLevels;
private final WeaponType weaponType;
private final int attackStyleId;
private final Item[] equipedItems;
private final int[] expectedMaxHits;
private final int[][] hitpoints;
private final int meleeEquipmentStrength;
MeleeMaxHitConfig(int[] strengthLevels, int meleeEquipmentStrength, WeaponType weaponType, int attackStyleId, int[][] hitpoints, Item[] equipedItems, int[] expectedMaxHits)
{
this.strengthLevels = strengthLevels;
this.meleeEquipmentStrength = meleeEquipmentStrength;
this.weaponType = weaponType;
this.attackStyleId = attackStyleId;
this.hitpoints = hitpoints;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
MeleeMaxHitConfig(int[] strengthLevels, int meleeEquipmentStrength, WeaponType weaponType, int attackStyleId, Item[] equipedItems, int[] expectedMaxHits)
{
this.strengthLevels = strengthLevels;
this.hitpoints = new int[strengthLevels.length][2];
this.meleeEquipmentStrength = meleeEquipmentStrength;
this.weaponType = weaponType;
this.attackStyleId = attackStyleId;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
private static Item mockItem(int itemId)
{
Item item = mock(Item.class);
when(item.getId()).thenReturn(itemId);
return item;
}
public void test(Client client)
{
int[] strengthLevels = this.strengthLevels;
for (int i = 0, strengthLevelsLength = strengthLevels.length; i < strengthLevelsLength; i++)
{
int strengthLevel = strengthLevels[i];
int[] hitpoints = this.hitpoints[i];
int expectedMaxHit = this.expectedMaxHits[i];
// Mock equipment container
ItemContainer equipmentContainer = mock(ItemContainer.class);
when(equipmentContainer.getItems())
.thenReturn(this.equipedItems);
when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentContainer);
// Mock equipment strength
Widget equipmentWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.EQUIPMENT_MELEE_STRENGTH)).thenReturn(equipmentWidget);
when(equipmentWidget.getText()).thenReturn("Melee strength: " + this.meleeEquipmentStrength);
// Mock Varbits
when(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(this.weaponType.ordinal());
when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(this.attackStyleId);
// Mock strength
when(client.getBoostedSkillLevel(Skill.STRENGTH)).thenReturn(strengthLevel);
// Mock hitpoints
when(client.getBoostedSkillLevel(Skill.HITPOINTS)).thenReturn(hitpoints[0]);
when(client.getRealSkillLevel(Skill.HITPOINTS)).thenReturn(hitpoints[1]);
// Test
MeleeMaxHitCalculator maxHitCalculator = new MeleeMaxHitCalculator(client, this.equipedItems);
assertEquals(this.toString(), expectedMaxHit, maxHitCalculator.getMaxHit(), 0);
}
}
}

View File

@@ -0,0 +1,167 @@
/*
* Copyright (c) 2019, Bartvollebregt <https://github.com/Bartvollebregt>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.runelite.client.plugins.maxhit.calculators.testconfig;
import net.runelite.api.*;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.plugins.maxhit.attackstyle.WeaponType;
import net.runelite.client.plugins.maxhit.calculators.RangeMaxHitCalculator;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public enum RangeMaxHitConfig implements MaxHitConfig
{
MAGIC_SHORTBOW(new int[] {75, 83, 99}, 49, WeaponType.TYPE_3, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.MAGIC_SHORTBOW),
mockItem(ItemID.IRON_PLATEBODY),
null,
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING),
mockItem(ItemID.RUNE_ARROW)
}, new int[] {15, 16, 19}),
RUNE_CROSSBOW(new int[] {75, 83, 99}, 115, WeaponType.TYPE_5, 0, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.RUNE_CROSSBOW),
mockItem(ItemID.IRON_PLATEBODY),
null,
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING),
mockItem(ItemID.RUNITE_BOLTS)
}, new int[] {24, 26, 31}),
BLOwPIPE(new int[] {75, 83, 99}, 50, WeaponType.TYPE_19, 1, new Item[]
{
mockItem(ItemID.IRON_FULL_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.TOXIC_BLOWPIPE),
mockItem(ItemID.IRON_PLATEBODY),
null,
null,
mockItem(ItemID.IRON_PLATELEGS),
null,
mockItem(ItemID.LEATHER_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[] {15, 16, 19}),
VOID_SET(new int[] {75, 83, 99}, 115, WeaponType.TYPE_5, 1, new Item[]
{
mockItem(ItemID.VOID_RANGER_HELM),
mockItem(ItemID.BLACK_CAPE),
mockItem(ItemID.GOLD_NECKLACE),
mockItem(ItemID.RUNE_CROSSBOW),
mockItem(ItemID.VOID_KNIGHT_TOP),
mockItem(ItemID.IRON_KITESHIELD),
null,
mockItem(ItemID.VOID_KNIGHT_ROBE),
null,
mockItem(ItemID.VOID_KNIGHT_GLOVES),
mockItem(ItemID.LEATHER_BOOTS),
mockItem(ItemID.GOLD_RING)
}, new int[] {26, 28, 33}),
;
private final int[] rangeLevels;
private final WeaponType weaponType;
private final int attackStyleId;
private final Item[] equipedItems;
private final int[] expectedMaxHits;
private final int ammoEquipmentStrength;
RangeMaxHitConfig(int[] rangeLevels, int ammoEquipmentStrength, WeaponType weaponType, int attackStyleId, Item[] equipedItems, int[] expectedMaxHits)
{
this.rangeLevels = rangeLevels;
this.ammoEquipmentStrength = ammoEquipmentStrength;
this.weaponType = weaponType;
this.attackStyleId = attackStyleId;
this.equipedItems = equipedItems;
this.expectedMaxHits = expectedMaxHits;
}
private static Item mockItem(int itemId)
{
Item item = mock(Item.class);
when(item.getId()).thenReturn(itemId);
return item;
}
public void test(Client client)
{
int[] rangeLevels = this.rangeLevels;
for (int i = 0, rangeLevelsLength = rangeLevels.length; i < rangeLevelsLength; i++)
{
int rangeLevel = rangeLevels[i];
int expectedMaxHit = this.expectedMaxHits[i];
// Mock equipment container
ItemContainer equipmentContainer = mock(ItemContainer.class);
when(equipmentContainer.getItems())
.thenReturn(this.equipedItems);
when(client.getItemContainer(InventoryID.EQUIPMENT)).thenReturn(equipmentContainer);
// Mock equipment strength
Widget equipmentWidget = mock(Widget.class);
when(client.getWidget(WidgetInfo.EQUIPMENT_RANGED_STRENGTH)).thenReturn(equipmentWidget);
when(equipmentWidget.getText()).thenReturn("Ranged strength: " + this.ammoEquipmentStrength);
// Mock Varbits
when(client.getVar(Varbits.EQUIPPED_WEAPON_TYPE)).thenReturn(this.weaponType.ordinal());
when(client.getVar(VarPlayer.ATTACK_STYLE)).thenReturn(this.attackStyleId);
// Mock strength
when(client.getBoostedSkillLevel(Skill.RANGED)).thenReturn(rangeLevel);
// Test
RangeMaxHitCalculator maxHitCalculator = new RangeMaxHitCalculator(client, this.equipedItems);
assertEquals(this.toString(), expectedMaxHit, maxHitCalculator.getMaxHit(), 0);
}
}
}