Merge branch 'master' into master

This commit is contained in:
Patrick Watts
2024-09-18 11:22:40 +04:00
committed by GitHub
29 changed files with 1988 additions and 686 deletions

View File

@@ -1,7 +1,13 @@
package com.toofifty.easygiantsfoundry;
import static com.toofifty.easygiantsfoundry.MathUtil.max1;
import static com.toofifty.easygiantsfoundry.EasyGiantsFoundryClientIDs.*;
import com.toofifty.easygiantsfoundry.enums.Heat;
import com.toofifty.easygiantsfoundry.enums.Stage;
import static com.toofifty.easygiantsfoundry.enums.Stage.GRINDSTONE;
import static com.toofifty.easygiantsfoundry.enums.Stage.POLISHING_WHEEL;
import static com.toofifty.easygiantsfoundry.enums.Stage.TRIP_HAMMER;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.Client;
@@ -15,33 +21,6 @@ import java.util.List;
@Singleton
public class EasyGiantsFoundryState
{
// heat and progress are from 0-1000
private static final int VARBIT_HEAT = 13948;
private static final int VARBIT_PROGRESS = 13949;
private static final int VARBIT_ORE_COUNT = 13934;
private static final int VARBIT_FORTE_SELECTED = 13910;
private static final int VARBIT_BLADE_SELECTED = 13911;
private static final int VARBIT_TIP_SELECTED = 13912;
// 0 - load bars
// 1 - set mould
// 2 - collect preform
// 3 -
static final int VARBIT_GAME_STAGE = 13914;
private static final int WIDGET_HEAT_PARENT = 49414153;
private static final int WIDGET_LOW_HEAT_PARENT = 49414163;
private static final int WIDGET_MED_HEAT_PARENT = 49414164;
private static final int WIDGET_HIGH_HEAT_PARENT = 49414165;
static final int WIDGET_PROGRESS_PARENT = 49414219;
// children with type 3 are stage boxes
// every 11th child is a sprite
private static final int SPRITE_ID_TRIP_HAMMER = 4442;
private static final int SPRITE_ID_GRINDSTONE = 4443;
private static final int SPRITE_ID_POLISHING_WHEEL = 4444;
@Inject
private Client client;
@@ -52,6 +31,9 @@ public class EasyGiantsFoundryState
@Getter
private int bonusActionsReceived = 0;
@Setter
private int smithsOutfitPieces;
private final List<Stage> stages = new ArrayList<>();
private double heatRangeRatio = 0;
@@ -84,7 +66,7 @@ public class EasyGiantsFoundryState
return 0;
}
heatRangeRatio = medHeat.getWidth() /(double) heatWidget.getWidth();
heatRangeRatio = medHeat.getWidth() / (double) heatWidget.getWidth();
}
return heatRangeRatio;
@@ -129,13 +111,13 @@ public class EasyGiantsFoundryState
switch (child.getSpriteId())
{
case SPRITE_ID_TRIP_HAMMER:
stages.add(Stage.TRIP_HAMMER);
stages.add(TRIP_HAMMER);
break;
case SPRITE_ID_GRINDSTONE:
stages.add(Stage.GRINDSTONE);
stages.add(GRINDSTONE);
break;
case SPRITE_ID_POLISHING_WHEEL:
stages.add(Stage.POLISHING_WHEEL);
stages.add(POLISHING_WHEEL);
break;
}
}
@@ -211,7 +193,8 @@ public class EasyGiantsFoundryState
public int getBonusActionsExpected()
{
if (getStages().size() >= 6) {
if (getStages().size() >= 6)
{
return 3;
}
@@ -222,4 +205,110 @@ public class EasyGiantsFoundryState
{
++bonusActionsReceived;
}
public int getCrucibleCount()
{
int bronze = client.getVarbitValue(VARBIT_BRONZE_COUNT);
int iron = client.getVarbitValue(VARBIT_IRON_COUNT);
int steel = client.getVarbitValue(VARBIT_STEEL_COUNT);
int mithril = client.getVarbitValue(VARBIT_MITHRIL_COUNT);
int adamant = client.getVarbitValue(VARBIT_ADAMANT_COUNT);
int rune = client.getVarbitValue(VARBIT_RUNE_COUNT);
return bronze + iron + steel + mithril + adamant + rune;
}
public double getCrucibleQuality()
{
if (getCrucibleCount() == 0) return 0;
int bronze = client.getVarbitValue(VARBIT_BRONZE_COUNT);
int iron = client.getVarbitValue(VARBIT_IRON_COUNT);
int steel = client.getVarbitValue(VARBIT_STEEL_COUNT);
int mithril = client.getVarbitValue(VARBIT_MITHRIL_COUNT);
int adamant = client.getVarbitValue(VARBIT_ADAMANT_COUNT);
int rune = client.getVarbitValue(VARBIT_RUNE_COUNT);
final int BRONZE_VALUE = 1;
final int IRON_VALUE = 2;
final int STEEL_VALUE = 3;
final int MITHRIL_VALUE = 4;
final int ADAMANT_VALUE = 5;
final int RUNE_VALUE = 6;
final double vB = (10 * BRONZE_VALUE * bronze) / 28.0;
final double vI = (10 * IRON_VALUE * iron) / 28.0;
final double vS = (10 * STEEL_VALUE * steel) / 28.0;
final double vM = (10 * MITHRIL_VALUE * mithril) / 28.0;
final double vA = (10 * ADAMANT_VALUE * adamant) / 28.0;
final double vR = (10 * RUNE_VALUE * rune) / 28.0;
return
(10 * (vB + vI + vS + vM + vA + vR)
+ (max1(vB) * max1(vI) * max1(vS) * max1(vM) * max1(vA) * max1(vR))) / 10.0;
}
/**
* Get the amount of progress each stage needs
*/
public double getProgressPerStage()
{
return 1000d / getStages().size();
}
public int getActionsLeftInStage()
{
int progress = getProgressAmount();
double progressPerStage = getProgressPerStage();
double progressTillNext = progressPerStage - progress % progressPerStage;
Stage current = getCurrentStage();
// Each Smith's Outfit piece adds 20% chance to increase action progress by 1, or 100% for all 4 pieces.
double smithsOutfitBonus = smithsOutfitPieces == 4 ? 1 : 0.2 * smithsOutfitPieces;
return (int) Math.ceil(progressTillNext / (current.getProgressPerAction() + smithsOutfitBonus));
}
public int[] getCurrentHeatRange()
{
switch (getCurrentStage())
{
case POLISHING_WHEEL:
return getLowHeatRange();
case GRINDSTONE:
return getMedHeatRange();
case TRIP_HAMMER:
return getHighHeatRange();
default:
return new int[]{0, 0};
}
}
/**
* Get the amount of current stage actions that can be
* performed before the heat drops too high or too low to
* continue
*/
public int getActionsForHeatLevel()
{
Heat heatStage = getCurrentHeat();
Stage stage = getCurrentStage();
if (heatStage != stage.getHeat())
{
// not the right heat to start with
return 0;
}
int[] range = getCurrentHeatRange();
int actions = 0;
int heat = getHeatAmount();
while (heat > range[0] && heat < range[1])
{
actions++;
heat += stage.getHeatChange();
}
return actions;
}
public HeatActionStateMachine heatingCoolingState = new HeatActionStateMachine();
}