-
Notifications
You must be signed in to change notification settings - Fork 0
/
JQB.js
91 lines (77 loc) · 2.37 KB
/
JQB.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
/************
Quad states
Empty ◄─────────────────────┬──┐
└─► Growing QBs │ │
└─► Breeding QBs ◄────┐ │ │
├─► Wrong Sprout ─┘ │ │
├─► Dying QBs ──────┘ │
└─► JQB Sprout │
└─► Mature JQB ────┘
************/
console.log('loaded JQB');
var G = Game.Objects['Farm'].minigame;
var JQB = new JqbGarden;
JQB.tickLoop();
function JqbGarden() {
// const gardenGame = Game.Objects['Farm'].minigame;
this.soilMode = undefined;
this.quads = [];
this.tiles = [];
this.fast = false; // set true for fast loops
var i, j;
for (i = 0; i < 6; i++) {
this.tiles[i] = new Array();
for (j = 0; j < 6; j++) {
this.tiles[i][j] = new JqbTile(this, i, j);
}
}
for ( i = 0; i < 4; i++) {
this.quads[i] = new JqbQuad(this, i);
}
this.tickLoop = function(){
G.harvestAll(G.plants.queenbeetLump,1); // skip the fooforaw and harvest any mature JQBs
for (i = 0; i < 4; i++) {
this.quads[i].check();
}
var self = this;
var nextLoop = setTimeout(() => {self.tickLoop()}, this.fast ? 10000 : G.nextStep - Date.now() + 5000);
}
}
function JqbQuad(g, i) {
this.n = i;
this.garden = g;
const x0 = (i % 2) * 3;
const y0 = Math.floor(i / 2) * 3;
this.tiles = [
this.garden.tiles[x0 ][y0], //northwest
this.garden.tiles[x0 + 1][y0], //north
this.garden.tiles[x0 + 2][y0], //northeast
this.garden.tiles[x0 + 2][y0 + 1], //east
this.garden.tiles[x0 + 2][y0 + 2], //southeast
this.garden.tiles[x0 + 1][y0 + 2], //south
this.garden.tiles[x0 ][y0 + 2], //southwest
this.garden.tiles[x0 ][y0 + 1], //west
this.garden.tiles[x0 + 1][y0 + 1] //center
];
this.outer = this.tiles.slice(0,8);
this.center = this.tiles[8];
this.check = function() {
console.log("quad " + this.n);
this.tiles.forEach(t => console.log(t.plantName()));
}
}
function JqbTile(garden, i, j) {
this.garden = garden;
this.tile = G.getTile(i, j);
this.plantName = function() {
let plantId = this.tile[0] - 1;
if (plantId < 0) {
return "empty"
} else {
return G.plantsById[this.tile[0] - 1].name;
}
}
}
/*
M.harvestAll(0,1,1);//ctrl & shift, harvest only mature non-immortal plants
*/