Skip to content

Commit

Permalink
Auto Bomb before Reachning Max Energy
Browse files Browse the repository at this point in the history
  • Loading branch information
zocke1r committed Jun 29, 2021
1 parent 491eb63 commit 4150491
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 126 deletions.
2 changes: 1 addition & 1 deletion docs/scripts/modules.min.js

Large diffs are not rendered by default.

39 changes: 21 additions & 18 deletions docs/scripts/script.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -36777,19 +36777,19 @@ class Mine {
static rotateReward(reward) {
let rotations = Math.floor(Math.random() * 4);
while (rotations-- > 0) {
reward.space = reward.space[0].map((val, index) => reward.space.map(row => row[index]).reverse());
reward.space = reward.space[0].map((val, index) => reward.space.map((row) => row[index]).reverse());
}
const currentRotation = this.calculateRotation(reward);
reward.space = reward.space.map(r => r.map(v => {
reward.space = reward.space.map((r) => r.map((v) => {
v.rotations = currentRotation;
return v;
}));
return reward;
}
static calculateRotation(reward) {
let indexX = 0;
const indexY = reward.space.findIndex(y => {
indexX = y.findIndex(x => !x.x && !x.y);
const indexY = reward.space.findIndex((y) => {
indexX = y.findIndex((x) => !x.x && !x.y);
return indexX >= 0;
});
return (indexX ? 1 : 0) + (indexY ? 2 : 0);
Expand All @@ -36815,7 +36815,7 @@ class Mine {
}
static rewardSummary() {
return Mine.rewardNumbers.reduce((res, id) => {
const reward = UndergroundItem.list.find(x => x.id == id);
const reward = UndergroundItem.list.find((x) => x.id == id);
if (ItemList[reward.valueType]) {
res.evoItems++;
}
Expand Down Expand Up @@ -36903,12 +36903,13 @@ class Mine {
if (!this.skipsRemaining()) {
return;
}
if (!shouldConfirm || (yield Notifier.confirm({
title: 'Underground',
message: 'Skip this mine layer?',
type: NotificationConstants.NotificationOption.warning,
confirm: 'skip',
}))) {
if (!shouldConfirm ||
(yield Notifier.confirm({
title: 'Underground',
message: 'Skip this mine layer?',
type: NotificationConstants.NotificationOption.warning,
confirm: 'skip',
}))) {
setTimeout(Mine.completed, 1500);
Mine.loadingNewLayer = true;
GameHelper.incrementObservable(this.skipsRemaining, -1);
Expand Down Expand Up @@ -37026,8 +37027,7 @@ class Mine {
}
static loadSavedMine(mine) {
var _a, _b;
this.grid = mine.grid.map(row => row.map(val => ko.observable(val))),
this.rewardGrid = mine.rewardGrid;
(this.grid = mine.grid.map((row) => row.map((val) => ko.observable(val)))), (this.rewardGrid = mine.rewardGrid);
this.itemsFound(mine.itemsFound);
this.itemsBuried(mine.itemsBuried);
this.rewardNumbers = mine.rewardNumbers;
Expand All @@ -37044,7 +37044,7 @@ class Mine {
Mine.loadMine();
}
const mineSave = {
grid: this.grid.map(row => row.map(val => val())),
grid: this.grid.map((row) => row.map((val) => val())),
rewardGrid: this.rewardGrid,
itemsFound: this.itemsFound(),
itemsBuried: this.itemsBuried(),
Expand Down Expand Up @@ -37116,8 +37116,7 @@ class Underground {
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.NewYLayer, 'Larger underground, +1 Max Item', 1, AmountFactory.createArray(GameHelper.createArray(3000, 3000, 3000), GameConstants.Currency.diamond), GameHelper.createArray(0, 1, 1)),
];
}
update(delta) {
}
update(delta) { }
getMaxEnergy() {
return Underground.BASE_ENERGY_MAX + this.getUpgrade(UndergroundUpgrade.Upgrades.Energy_Max).calculateBonus();
}
Expand Down Expand Up @@ -37204,7 +37203,7 @@ class Underground {
}
}
static getMineItemByName(name) {
return UndergroundItem.list.find(i => i.name == name);
return UndergroundItem.list.find((i) => i.name == name);
}
static getMineItemById(id) {
for (const item of UndergroundItem.list) {
Expand All @@ -37216,7 +37215,11 @@ class Underground {
gainEnergy() {
if (this.energy < this.getMaxEnergy()) {
const oakMultiplier = App.game.oakItems.calculateBonus(OakItems.OakItem.Cell_Battery);
this.energy = Math.min(this.getMaxEnergy(), this.energy + (oakMultiplier * this.getEnergyGain()));
const newEnergy = this.energy + oakMultiplier * this.getEnergyGain();
if (newEnergy > this.getMaxEnergy()) {
Mine.bomb();
}
this.energy = Math.min(this.getMaxEnergy(), this.energy + oakMultiplier * this.getEnergyGain());
if (this.energy === this.getMaxEnergy()) {
Notifier.notify({
message: 'Your mining energy has reached maximum capacity!',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/GameConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const ROAMING_MIN_CHANCE = 8192;
export const ROAMING_MAX_CHANCE = 4096;

// Shinies
export const SHINY_CHANCE_BATTLE = 16384;
export const SHINY_CHANCE_BATTLE = 8192;
export const SHINY_CHANCE_DUNGEON = 4096;
export const SHINY_CHANCE_SHOP = 2048;
export const SHINY_CHANCE_STONE = 2048;
Expand Down
83 changes: 45 additions & 38 deletions src/scripts/underground/Mine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Mine {
public static itemsBuried: KnockoutObservable<number> = ko.observable(0);
public static rewardNumbers: Array<number>;
public static surveyResult = ko.observable(null);
public static skipsRemaining = ko.observable(Mine.maxSkips)
public static skipsRemaining = ko.observable(Mine.maxSkips);

// 0 represents the Mine.Tool.Chisel but it's not loaded here yet.
public static toolSelected: KnockoutObservable<Mine.Tool> = ko.observable(0);
Expand Down Expand Up @@ -129,24 +129,26 @@ class Mine {
let rotations = Math.floor(Math.random() * 4);

while (rotations-- > 0) {
reward.space = reward.space[0].map((val, index) => reward.space.map(row => row[index]).reverse());
reward.space = reward.space[0].map((val, index) => reward.space.map((row) => row[index]).reverse());
}

const currentRotation = this.calculateRotation(reward);

reward.space = reward.space.map(r => r.map(v => {
v.rotations = currentRotation;
return v;
}));
reward.space = reward.space.map((r) =>
r.map((v) => {
v.rotations = currentRotation;
return v;
})
);

return reward;
}

private static calculateRotation(reward): number {
let indexX = 0;

const indexY = reward.space.findIndex(y => {
indexX = y.findIndex(x => !x.x && !x.y);
const indexY = reward.space.findIndex((y) => {
indexX = y.findIndex((x) => !x.x && !x.y);
return indexX >= 0;
});

Expand Down Expand Up @@ -177,28 +179,31 @@ class Mine {
}

private static rewardSummary() {
return Mine.rewardNumbers.reduce((res, id) => {
const reward = UndergroundItem.list.find(x => x.id == id);

if (ItemList[reward.valueType]) {
res.evoItems++;
} else {
switch (reward.valueType) {
case 'Diamond': {
res.totalValue += reward.value;
break;
}
case 'Mine Egg': {
res.fossils++;
break;
}
default: {
res.plates++;
return Mine.rewardNumbers.reduce(
(res, id) => {
const reward = UndergroundItem.list.find((x) => x.id == id);

if (ItemList[reward.valueType]) {
res.evoItems++;
} else {
switch (reward.valueType) {
case 'Diamond': {
res.totalValue += reward.value;
break;
}
case 'Mine Egg': {
res.fossils++;
break;
}
default: {
res.plates++;
}
}
}
}
return res;
}, {fossils: 0, plates: 0, evoItems: 0, totalValue: 0});
return res;
},
{ fossils: 0, plates: 0, evoItems: 0, totalValue: 0 }
);
}

private static updatesurveyResult(summary) {
Expand Down Expand Up @@ -255,7 +260,7 @@ class Mine {
}
}

private static bomb() {
public static bomb() {
let tiles = App.game.underground.getBombEfficiency();
if (App.game.underground.energy >= Underground.BOMB_ENERGY) {
while (tiles-- > 0) {
Expand All @@ -272,12 +277,15 @@ class Mine {
return;
}

if (!shouldConfirm || await Notifier.confirm({
title: 'Underground',
message: 'Skip this mine layer?',
type: NotificationConstants.NotificationOption.warning,
confirm: 'skip',
})) {
if (
!shouldConfirm ||
(await Notifier.confirm({
title: 'Underground',
message: 'Skip this mine layer?',
type: NotificationConstants.NotificationOption.warning,
confirm: 'skip',
}))
) {
setTimeout(Mine.completed, 1500);
Mine.loadingNewLayer = true;
GameHelper.incrementObservable(this.skipsRemaining, -1);
Expand Down Expand Up @@ -408,8 +416,7 @@ class Mine {
}

public static loadSavedMine(mine) {
this.grid = mine.grid.map(row => row.map(val => ko.observable(val))),
this.rewardGrid = mine.rewardGrid;
(this.grid = mine.grid.map((row) => row.map((val) => ko.observable(val)))), (this.rewardGrid = mine.rewardGrid);
this.itemsFound(mine.itemsFound);
this.itemsBuried(mine.itemsBuried);
this.rewardNumbers = mine.rewardNumbers;
Expand All @@ -428,7 +435,7 @@ class Mine {
Mine.loadMine();
}
const mineSave = {
grid: this.grid.map(row => row.map(val => val())),
grid: this.grid.map((row) => row.map((val) => val())),
rewardGrid: this.rewardGrid,
itemsFound: this.itemsFound(),
itemsBuried: this.itemsBuried(),
Expand Down
86 changes: 18 additions & 68 deletions src/scripts/underground/Underground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,73 +21,20 @@ class Underground implements Feature {

initialize() {
this.upgradeList = [
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Energy_Max, 'Max Energy', 10,
AmountFactory.createArray(
GameHelper.createArray(50, 500, 50), GameConstants.Currency.diamond),
GameHelper.createArray(0, 100, 10)
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Items_Max, 'Max items', 4,
AmountFactory.createArray(
GameHelper.createArray(200, 800, 200), GameConstants.Currency.diamond),
GameHelper.createArray(0, 4, 1)
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Items_Min, 'Min Items', 4,
AmountFactory.createArray(
GameHelper.createArray(500, 5000, 1500), GameConstants.Currency.diamond),
GameHelper.createArray(0, 4, 1)
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Energy_Gain, 'Energy restored', 17,
AmountFactory.createArray(
GameHelper.createArray(100, 1700, 100), GameConstants.Currency.diamond),
GameHelper.createArray(0, 17, 1)
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Energy_Regen_Time, 'Energy regen time', 20,
AmountFactory.createArray(
GameHelper.createArray(20, 400, 20), GameConstants.Currency.diamond),
GameHelper.createArray(0, 20, 1),
false
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Daily_Deals_Max, 'Daily deals', 2,
AmountFactory.createArray(
GameHelper.createArray(150, 300, 150), GameConstants.Currency.diamond),
GameHelper.createArray(0, 2, 1)
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Bomb_Efficiency, 'Bomb Efficiency', 5,
AmountFactory.createArray(
GameHelper.createArray(50, 250, 50), GameConstants.Currency.diamond),
GameHelper.createArray(0, 10, 2)
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Survey_Cost, 'Survey Cost', 5,
AmountFactory.createArray(
GameHelper.createArray(50, 250, 50), GameConstants.Currency.diamond),
GameHelper.createArray(0, 5, 1),
false
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.Survey_Efficiency, 'Survey Efficiency', 4,
AmountFactory.createArray(
GameHelper.createArray(100, 400, 100), GameConstants.Currency.diamond),
GameHelper.createArray(0, 4, 1)
),
new UndergroundUpgrade(
UndergroundUpgrade.Upgrades.NewYLayer, 'Larger underground, +1 Max Item', 1,
AmountFactory.createArray(
GameHelper.createArray(3000, 3000, 3000), GameConstants.Currency.diamond),
GameHelper.createArray(0, 1, 1)
),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Energy_Max, 'Max Energy', 10, AmountFactory.createArray(GameHelper.createArray(50, 500, 50), GameConstants.Currency.diamond), GameHelper.createArray(0, 100, 10)),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Items_Max, 'Max items', 4, AmountFactory.createArray(GameHelper.createArray(200, 800, 200), GameConstants.Currency.diamond), GameHelper.createArray(0, 4, 1)),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Items_Min, 'Min Items', 4, AmountFactory.createArray(GameHelper.createArray(500, 5000, 1500), GameConstants.Currency.diamond), GameHelper.createArray(0, 4, 1)),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Energy_Gain, 'Energy restored', 17, AmountFactory.createArray(GameHelper.createArray(100, 1700, 100), GameConstants.Currency.diamond), GameHelper.createArray(0, 17, 1)),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Energy_Regen_Time, 'Energy regen time', 20, AmountFactory.createArray(GameHelper.createArray(20, 400, 20), GameConstants.Currency.diamond), GameHelper.createArray(0, 20, 1), false),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Daily_Deals_Max, 'Daily deals', 2, AmountFactory.createArray(GameHelper.createArray(150, 300, 150), GameConstants.Currency.diamond), GameHelper.createArray(0, 2, 1)),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Bomb_Efficiency, 'Bomb Efficiency', 5, AmountFactory.createArray(GameHelper.createArray(50, 250, 50), GameConstants.Currency.diamond), GameHelper.createArray(0, 10, 2)),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Survey_Cost, 'Survey Cost', 5, AmountFactory.createArray(GameHelper.createArray(50, 250, 50), GameConstants.Currency.diamond), GameHelper.createArray(0, 5, 1), false),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.Survey_Efficiency, 'Survey Efficiency', 4, AmountFactory.createArray(GameHelper.createArray(100, 400, 100), GameConstants.Currency.diamond), GameHelper.createArray(0, 4, 1)),
new UndergroundUpgrade(UndergroundUpgrade.Upgrades.NewYLayer, 'Larger underground, +1 Max Item', 1, AmountFactory.createArray(GameHelper.createArray(3000, 3000, 3000), GameConstants.Currency.diamond), GameHelper.createArray(0, 1, 1)),
];
}

update(delta: number) {
}
update(delta: number) {}

getMaxEnergy() {
return Underground.BASE_ENERGY_MAX + this.getUpgrade(UndergroundUpgrade.Upgrades.Energy_Max).calculateBonus();
Expand Down Expand Up @@ -172,7 +119,7 @@ class Underground implements Feature {
const item = Underground.getMineItemById(id);

if (item.isStone()) {
const evostone: EvolutionStone = (ItemList[item.valueType] as EvolutionStone);
const evostone: EvolutionStone = ItemList[item.valueType] as EvolutionStone;
evostone.gain(num);
return;
}
Expand All @@ -194,7 +141,7 @@ class Underground implements Feature {
}

public static getMineItemByName(name: string): UndergroundItem {
return UndergroundItem.list.find(i => i.name == name);
return UndergroundItem.list.find((i) => i.name == name);
}

public static getMineItemById(id: number): UndergroundItem {
Expand All @@ -208,7 +155,11 @@ class Underground implements Feature {
gainEnergy() {
if (this.energy < this.getMaxEnergy()) {
const oakMultiplier = App.game.oakItems.calculateBonus(OakItems.OakItem.Cell_Battery);
this.energy = Math.min(this.getMaxEnergy(), this.energy + (oakMultiplier * this.getEnergyGain()));
const newEnergy = this.energy + oakMultiplier * this.getEnergyGain();
if (newEnergy > this.getMaxEnergy()) {
Mine.bomb();
}
this.energy = Math.min(this.getMaxEnergy(), this.energy + oakMultiplier * this.getEnergyGain());
if (this.energy === this.getMaxEnergy()) {
Notifier.notify({
message: 'Your mining energy has reached maximum capacity!',
Expand Down Expand Up @@ -370,7 +321,6 @@ class Underground implements Feature {
set energy(value) {
this._energy(value);
}

}

$(document).ready(() => {
Expand Down

0 comments on commit 4150491

Please sign in to comment.