Skip to content

Commit

Permalink
equipment.js - Big Changes to Shield buying. Refactor entire file way…
Browse files Browse the repository at this point in the history
… better
  • Loading branch information
genbtc committed Nov 15, 2023
1 parent 6d69f64 commit 727950b
Showing 1 changed file with 55 additions and 47 deletions.
102 changes: 55 additions & 47 deletions modules/equipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ MODULES["equipment"].enoughDamageCutoff = 4; //above this the game will buy atta
MODULES["equipment"].capDivisor = 10; //Your Equipment cap divided by this will give you the lower cap for liquified and overkilled zones
MODULES["equipment"].alwaysLvl2 = true; //Always buys the 2nd level of equipment. Its the most effective.
MODULES["equipment"].waitTill60 = true; // 'Skip Gear Level 58&59', 'Dont Buy Gear during level 58 and 59, wait till level 60, when cost drops down to 10%
MODULES["equipment"].equipHealthDebugMessage = false; //this repeats a message when you don't have enough health. set to false to stop the spam.

var equipmentList = {
'Dagger': {
Expand Down Expand Up @@ -132,22 +131,17 @@ function PrestigeValue(what) {
function evaluateEquipmentEfficiency(equipName) {
var equip = equipmentList[equipName];
var gameResource = equip.Equip ? game.equipment[equipName] : game.buildings[equipName];
if (equipName == 'Shield') {
if (gameResource.blockNow) {
equip.Stat = 'block';
} else {
equip.Stat = 'health';
}
}
if (equipName == 'Shield')
equip.Stat = (gameResource.blockNow) ? 'block' : 'health';

var Effect = equipEffect(gameResource, equip);
var Cost = equipCost(gameResource, equip);
var Factor = Effect / Cost;
var StatusBorder = 'white';
var Wall = false;

//Evaluate existing upgrade
if (!game.upgrades[equip.Upgrade].locked) {
//Evaluating upgrade!
var CanAfford = canAffordTwoLevel(game.upgrades[equip.Upgrade]);
if (equip.Equip) {
var NextEffect = PrestigeValue(equip.Upgrade);
//Scientist 3 and 4 challenge: set metalcost to Infinity so it can buy equipment levels without waiting for prestige. (fake the impossible science cost)
Expand All @@ -164,72 +158,87 @@ function evaluateEquipmentEfficiency(equipName) {
//orange - Upgrade is affordable, but will lower stats
//red - Yes, do it now!

if (!CanAfford) {
var CanAfford = canAffordTwoLevel(game.upgrades[equip.Upgrade]);
if (!CanAfford)
StatusBorder = 'yellow';
} else {
if (!equip.Equip) {
//Gymystic is always Valid
else {
//Gymystic is always Valid
if (!equip.Equip)
StatusBorder = 'red';
} else {
else {
var CurrEffect = gameResource.level * Effect;
var NeedLevel = Math.ceil(CurrEffect / NextEffect);
var Ratio = gameResource.cost[equip.Resource][1];
var NeedResource = NextCost * (Math.pow(Ratio, NeedLevel) - 1) / (Ratio - 1);
if (game.resources[equip.Resource].owned > NeedResource) {
StatusBorder = 'red';
} else {
StatusBorder = 'orange';
}
var canReallyAfford = (game.resources[equip.Resource].owned > NeedResource);
StatusBorder = canReallyAfford ? 'red' : 'orange';
}
}
}
//what this means:
//wall (don't buy any more equipment, buy prestige first)
//Factor = 0 sets the efficiency to 0 so that it will be disregarded. if not, efficiency will still be somenumber that is cheaper,
// and the algorithm will get stuck on whatever equipment we have capped, and not buy other equipment.
//TODO: This sucks when early game jobs for miners is not unlocked yet, as it leads to equipment not being bought until the unlock,
//TODO: This sucks when early game jobs for miners is not unlocked yet, as it leads to equipment not being bought until the unlock,
// which is paradoxical because it likely cant reach it without even 1 or 2 points.
if (game.jobs[mapresourcetojob[equip.Resource]].locked && (game.global.challengeActive != 'Metal')){
//cap any equips that we haven't unlocked metal for (new/fresh game/level1/no helium code)
Factor = 0;
Wall = true;
}
//Detecting the liquification through liquimp

//Detecting the liquification through liquimp
var isLiquified = (game.options.menu.liquification.enabled && game.talents.liquification.purchased && !game.global.mapsActive && game.global.gridArray && game.global.gridArray[0] && game.global.gridArray[0].name == "Liquimp");
//Run a quick Time estimate and if we complete it in 25 seconds or less, use 1/10th of our cap just so we can continue (MODULES["equipment"].capDivisor=10;)
//Run a quick Time estimate and if we complete it in 25 seconds or less, use 1/10th of our cap just so we can continue (MODULES["equipment"].capDivisor=10;)
var time = mapTimeEstimater();
var isQuick = (time!=0) && (time < 25000);
var isQuick = (time != 0) && (time < 25000);
//CapEquip2
var cap = getPageSetting('CapEquip2');
if ((isLiquified || isQuick) && cap > 0 && gameResource.level >= (cap / MODULES["equipment"].capDivisor)) {
var doCapEq2 = (gameResource.level >= cap);
var doCapDiv = (gameResource.level >= (cap / MODULES["equipment"].capDivisor));
//CapEquip2 + liquification | quick Time estimate
if (cap > 0 && (doCapEq2 || (doCapDiv && (isLiquified || isQuick)))) {
Factor = 0;
Wall = true;
StatusBorder = 'black';
}
//CapEquip2
else if (cap > 0 && gameResource.level >= cap) {
Factor = 0;
Wall = true;

//Skip prioritizing Shield if Cost is high Compared to what we get with Gyms (bad cost effectiveness)
var skipLowBlockHighCost = false;
//similar/same code is in buildings.js:
if (equipName == 'Shield' && gameResource.blockNow) {
var gymEff = evaluateEquipmentEfficiency('Gym');
if (gymEff.Wall || (Factor < gymEff.Factor))
skipLowBlockHighCost = true;
}

//Skip prioritizing health shields (w/out shieldblock) if we are Prestige 3 ~ pre Level 11 + AND going for ShieldBlock (wastes wood when SB prestiges it back to level 1)
var skipThisShield = (equipName == 'Shield' && gameResource.prestige == 3 && !gameResource.blockNow && getPageSetting('BuyShieldblock') &&
game.global.world <= 11); //(likely in the middle of running The Block to get Shieldblock)

//AlwaysLvl2 // dont apply it to shieldblock //or when shieldblock cost effectiveness is worse compared to gym
if (gameResource.level < 2 && MODULES["equipment"].alwaysLvl2 && !skipThisShield && !skipLowBlockHighCost)
Factor += 999 + gameResource.prestige;

//WaitTill60 (skip58&59 + wait for breaking the planet reduction) (now default)
if (equipName != 'Gym' && game.global.world < 60 && game.global.world >= 58 && MODULES["equipment"].waitTill60){
if (equipName != 'Gym' && (game.global.world == 58 || game.global.world == 59) && MODULES["equipment"].waitTill60)
Wall = true;
}
//AlwaysLvl2 - Was AlwaysArmorLvl2 (now default)
if (gameResource.level < 2 && MODULES["equipment"].alwaysLvl2) {
Factor = 999 - gameResource.prestige;
}

//skip buying shields (w/ shieldblock) if we need gymystics
if (equipName == 'Shield' && gameResource.blockNow && canGymystic()) {
Factor = 0;
Wall = true;
StatusBorder = 'orange';
}
//TODO Skip buying shields (w/out shieldblock) if we are Prestige 3 and in the middle of running The Block to get Shieldblock

//Return Custom Struct of Data
return {
Stat: equip.Stat,
Factor: Factor,
StatusBorder: StatusBorder,
Wall: Wall,
Cost: Cost
Cost: Cost,
Effect: Effect
};
}

Expand Down Expand Up @@ -286,17 +295,15 @@ function autoLevelEquipment() {
//const FORMATION_MOD_2 = game.upgrades.Dominance.done ? 4 : 1;
var numHits = MODULES["equipment"].numHitsSurvived; //this can be changed.
var numHitsScry = MODULES["equipment"].numHitsSurvivedScry;
var min_zone = getPageSetting('ScryerMinZone');
var max_zone = getPageSetting('ScryerMaxZone');
var min_zone = getPageSetting('ScryerMinZone') ?? 0; //181
var max_zone = getPageSetting('ScryerMaxZone') ?? 0; //230
var valid_min = game.global.world >= min_zone;
var valid_max = max_zone <= 0 || game.global.world < max_zone;
//asks if we can survive x number of hits in either D stance or X stance.
enoughHealthE = !(doVoids && voidCheckPercent > 0) &&
(baseHealth/FORMATION_MOD_1 > numHits * (enemyDamage - baseBlock/FORMATION_MOD_1 > 0 ? enemyDamage - baseBlock/FORMATION_MOD_1 : enemyDamage * pierceMod)) &&
(!(valid_min && valid_max) || (baseHealth/2 > numHitsScry * (enemyDamage - baseBlock/2 > 0 ? enemyDamage - baseBlock/2 : enemyDamage * pierceMod)));
enoughDamageE = (baseDamage * MODULES["equipment"].enoughDamageCutoff > enemyHealth);
if (!enoughHealthE && MODULES["equipment"].equipHealthDebugMessage)
debug("Equipment module thought there was not enough health","equips");

//PRESTIGE and UPGRADE SECTION:
for (var equipName in equipmentList) {
Expand Down Expand Up @@ -327,6 +334,7 @@ function autoLevelEquipment() {
//yellow - Upgrade is not affordable (or capped)
//orange - Upgrade is affordable, but will lower stats
//red - Yes, do it now!

if (evaluation.Wall)
$equipName.style.color = 'yellow';
$equipName.style.border = '1px solid ' + evaluation.StatusBorder;
Expand All @@ -336,6 +344,7 @@ function autoLevelEquipment() {
$equipUpgrade.style.color = evaluation.StatusBorder;
if (evaluation.StatusBorder == 'yellow' && $equipUpgrade)
$equipUpgrade.style.color = 'white';
//GYM
if (equipName == 'Gym' && canGymystic()) {
$equipName.style.color = 'white';
$equipName.style.border = '1px solid white';
Expand All @@ -345,9 +354,8 @@ function autoLevelEquipment() {
}
}


//Code is Spaced This Way So You Can Read It:
if (evaluation.StatusBorder == 'red' && !(game.global.world < 60 && game.global.world >= 58 && MODULES["equipment"].waitTill60)) {
//Buy/Delay - code is Spaced This Way So You Can Read It:
if (evaluation.StatusBorder == 'red' && !((game.global.world == 58 || game.global.world == 59) && MODULES["equipment"].waitTill60)) {
var BuyWeaponUpgrades = getPageSetting('BuyWeaponUpgrades');
var BuyArmorUpgrades = getPageSetting('BuyArmorUpgrades');
var DelayArmorWhenNeeded = getPageSetting('DelayArmorWhenNeeded');
Expand Down Expand Up @@ -411,21 +419,21 @@ function autoLevelEquipment() {
if (getPageSetting('BuyWeapons') && DaThing.Stat == 'attack' && (!enoughDamageE || enoughHealthE || maxmap || spirecheck)) {
if (DaThing.Equip && !Best[stat].Wall && canAffordBuilding(eqName, null, null, true)) {
buyEquipment(eqName, null, true);
debug('Equipment: Leveling ' + eqName + " level " + equipItem.level, "equips", '*upload3');
debug('Equipment: Leveling ' + eqName + " - level " + equipItem.level, "equips", '*upload3');
}
}
//If we're considering a health item, buy it if we don't have enough health, otherwise we default to buying damage
if (getPageSetting('BuyArmor') && (DaThing.Stat == 'health' || DaThing.Stat == 'block') && (!enoughHealthE || maxmap || spirecheck)) {
if (DaThing.Equip && !Best[stat].Wall && canAffordBuilding(eqName, null, null, true)) {
buyEquipment(eqName, null, true);
debug('Equipment: Leveling ' + eqName + " level " + equipItem.level, "equips", '*upload3');
debug('Equipment: Leveling ' + eqName + " - level " + equipItem.level, "equips", '*upload3');
}
}
var aalvl2 = MODULES["equipment"].alwaysLvl2; //getPageSetting('AlwaysArmorLvl2');
if (getPageSetting('BuyArmor') && (DaThing.Stat == 'health') && aalvl2 && game.equipment[eqName].level < 2){
if (DaThing.Equip && !Best[stat].Wall && canAffordBuilding(eqName, null, null, true)) {
buyEquipment(eqName, null, true);
debug('Equipment: Leveling ' + eqName + " level " + equipItem.level + " (AlwaysLvl2)", "equips", '*upload3');
debug('Equipment: Leveling ' + eqName + " - level " + equipItem.level + " (AlwaysLvl2)", "equips", '*upload3');
}
}
}
Expand Down

0 comments on commit 727950b

Please sign in to comment.