forked from mdrdatalab/PokeClicker-Helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runDungeon.js
129 lines (113 loc) · 5.53 KB
/
runDungeon.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
function loadDungeon(dungeonName) {
if (dungeonName in dungeonList) {
var dungeon = dungeonList[dungeonName]
} else {
var dungeon = player.town().dungeon
}
if (dungeon) {
DungeonRunner.initializeDungeon(dungeon)
console.log('loading Dungeon:', dungeon.name, loopTimeDungeon)
} else {
console.log('This Dungeon does not exist:', dungeonName)
}
}
var loopTimeDungeon = 0
function loopDungeon(dungeonName, times = 1, stepMode = 0) {
var stepMode = stepMode
if (!(dungeonName in dungeonList) && !player.town().dungeon) {
console.log("This Dungeon does not exist:", dungeonName)
return
}
loopTimeDungeon = Math.floor(times)
console.log("entering dungeon loop", times)
var stepOrder
var stepIndex
// patch for previous winning
if(DungeonRunner.defeatedBoss() && loopTimeDungeon > 0) {loopTimeDungeon = loopTimeDungeon + 1}
var looper = setInterval(function() {
// if not in a dungeon
if((App.game.gameState != GameConstants.GameState.dungeon )){
// next step
if(loopTimeDungeon > 0) {
//if not in a gym or having other constraints
if(App.game.gameState != GameConstants.GameState.gym){
// if won
if(DungeonRunner.defeatedBoss()) {loopTimeDungeon = loopTimeDungeon - 1}
// next time?
if(loopTimeDungeon > 0) {
// load dungeon first
loadDungeon(dungeonName)
//start the dungeon
//order in which to traverse dungeon tiles
//remake dOrder based on DungeonRunner.map.size and DungeonRunner.map.playerPosition
stepOrder = [];
// first line
var xList = [];
for (let x = DungeonRunner.map.playerPosition()['x']; x >= 0; x--) {xList.push(x)}
for (let x = DungeonRunner.map.playerPosition()['x'] + 1; x < DungeonRunner.map.size; x++) {xList.push(x)}
for (const x of xList) {
stepOrder.push(new Point(x, DungeonRunner.map.playerPosition()['y']))
}
// switch to columns first
var xList = [];
for (let x = 1; x < DungeonRunner.map.size; x = x+3) {xList.push(x)}
for (let x = 0; x < DungeonRunner.map.size; x = x+3) {xList.push(x)}
for (let x = 2; x < DungeonRunner.map.size; x = x+3) {xList.push(x)}
var yList = [];
for (let y = DungeonRunner.map.playerPosition()['y'] - 1; y >= 0; y--) {yList.push(y)}
for (let y = DungeonRunner.map.playerPosition()['y'] + 1; y < DungeonRunner.map.size; y++) {yList.push(y)}
//
for (const x of xList) { for (const y of yList) {
stepOrder.push(new Point(x,y))
}}
stepIndex = 1
}
}
} else { // stop loop
console.log("done")
clearInterval(looper)
complete = 1
}
}
// To Do: move or action
if(!(DungeonRunner.fighting() || DungeonBattle.catching()) && !DungeonRunner.defeatedBoss()) {
var stepNext
// open chest or start boss fight
if (DungeonRunner.map.currentTile().type() !== GameConstants.DungeonTile.entrance) { DungeonRunner.handleClick();}
// if all tiles shown
if (DungeonRunner.chestsOpened >= GameConstants.DUNGEON_MAP_SHOW) {
if (stepMode == 1){
var typeTile = GameConstants.DungeonTile.enemy
} else {
var typeTile = GameConstants.DungeonTile.boss
}
for (let i = 0; i < DungeonRunner.map.board().length; i++) {
for (let j = 0; j < DungeonRunner.map.board()[i].length; j++) {
if (DungeonRunner.map.board()[i][j].type() == typeTile) {
stepNext = new Point(j,i)
}
}
}
}
// always open chests first if possible
if (DungeonRunner.chestsOpened >= GameConstants.DUNGEON_CHEST_SHOW && DungeonRunner.chestsOpened < GameConstants.DUNGEON_MAP_SHOW) {
for (let i = 0; i < DungeonRunner.map.board().length; i++) {
for (let j = 0; j < DungeonRunner.map.board()[i].length; j++) {
if (DungeonRunner.map.board()[i][j].type() == GameConstants.DungeonTile.chest) {
if (DungeonRunner.map.hasAccesToTile(new Point(j,i))) {
stepNext = new Point(j,i)
}
}
}
}
}
if (stepNext) {
console.log('jumping to', stepNext)
DungeonRunner.map.moveToTile(stepNext)
} else {
DungeonRunner.map.moveToTile(stepOrder[stepIndex])
stepIndex = stepIndex + 1
}
}
}, 600)
}