forked from Ishadijcks/Ishadijcks.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
breeding.js
289 lines (264 loc) · 8.32 KB
/
breeding.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
var Egg = function(type, steps, pokemon){
var temp = {
type:type,
steps:steps,
progress: 0,
shinyProgress: 0,
pokemon:pokemon ,
notified: 0,
}
return temp;
}
var possibleEggs = Array.apply(null, Array(17)).map(Number.prototype.valueOf,0);
var eggSlotPrice = [0, 500, 1000, 2500];
var initPossibleEggs = function(){
var fireEggs = ["Charmander", "Vulpix", "Growlithe", "Ponyta"];
var waterEggs = ["Squirtle", "Lapras", "Staryu", "Psyduck"];
var grassEggs = ["Bulbasaur", "Oddish", "Tangela", "Bellsprout"];
var fightEggs = ["Hitmonlee", "Hitmonchan", "Machop", "Mankey"];
var electricEggs = ["Magnemite", "Pikachu", "Voltorb", "Electabuzz"];
var dragonEggs = ["Dratini", "Dragonair", "Dragonite"];
possibleEggs[FIRE] = fireEggs;
possibleEggs[WATER] = waterEggs;
possibleEggs[GRASS] = grassEggs;
possibleEggs[FIGHTING] = fightEggs;
possibleEggs[ELECTRIC] = electricEggs;
possibleEggs[DRAGON] = dragonEggs;
}
var gainRandomEgg = function(type){
if(type === "random"){
var eggs = [];
for(var i = 0; i<possibleEggs.length; i++){
for( var j = 0; j<possibleEggs[i].length; j++){
eggs.push(possibleEggs[i][j]);
}
}
var eggName = eggs[Math.floor(Math.random()*(eggs.length))];
var type = getPokemonByName(eggName).type;
gainEgg(Egg(type, getSteps(eggName), eggName));
} else {
var num = typeToNumber(type);
var eggs = possibleEggs[num];
var eggName = eggs[Math.floor(Math.random()*(eggs.length))];
gainEgg(Egg(type, getSteps(eggName), eggName));
}
}
var gainPokemonEgg = function(pokemonName){
var pokemon = getPokemonByName(pokemonName);
gainEgg(Egg(pokemon.type, getSteps(pokemonName), pokemonName));
}
var gainMineEgg = function(itemId){
if(breedSlotLeft()) {
sellMineItem(itemId);
var type = "amber";
var pokemonName = "Aerodactyl";
if (itemId === 1) {
type = "helix";
pokemonName = "Omanyte";
} else if (itemId === 2) {
type = "dome";
pokemonName = "Kabuto";
}
var pokemon = getPokemonByName(pokemonName);
gainEgg(Egg(type, getSteps(pokemonName), pokemonName));
} else {
$.notify("Your hatchery is full");
}
}
var getSteps = function(pokemonName){
var pokemon = getPokemonByName(pokemonName);
if( pokemon.eggCycles === undefined){
return 500;
} else {
return pokemon.eggCycles * 40;
}
}
var gainEgg = function(egg){
var eggType;
if (egg.type[0] == 'Normal' && egg.type.length == 2) {
eggType = egg.type[1];
} else {
eggType = egg.type[0];
}
for(var i = 0; i<player.eggSlots; i++){
if(player.eggList[i] === null){
var tempEgg = {
type: eggType,
steps: egg.steps,
progress: 0,
shinyProgress: 0,
pokemon: egg.pokemon
}
player.eggList[i] = tempEgg;
showEggs();
return;
}
}
save();
}
var releasePokemon = function(pokemonName){
var index = -1;
for(var i = 0; i<player.caughtPokemonList.length; i++){
if(player.caughtPokemonList[i].name === pokemonName){
index = i;
}
}
if (index > -1) {
player.caughtPokemonList.splice(index, 1);
}
updateCaughtList();
}
var breedPokemon = function(pokemonName){
if(pokemonName === "Farfetch"){
pokemonName = "Farfetch'd";
}
for(var i = 0; i<player.eggSlots; i++){
if(player.eggList[i] === null){
var pokemon = getCaughtPokemonByName(pokemonName);
if(canBreed(pokemon)){
gainPokemonEgg(pokemonName);
releasePokemon(pokemonName);
}
showMom();
$.notify("You start breeding...", "success");
$.notify("You leave your " + pokemonName + " with your mom", "success");
save();
return;
}
}
$.notify("Your hatchery is full");
save();
}
var breedSlotLeft = function(){
for(var i = 0; i<player.eggSlots; i++){
if(player.eggList[i] === null){
return true;
}
}
return false;
}
var progressEgg = function(amount){
if(isActive("Blaze Cassette")){
amount *= getOakItemBonus("Blaze Cassette");
}
for(var i = 0; i<player.eggList.length; i++){
if(player.eggList[i] !== null){
if(player.eggList[i].progress < player.eggList[i].steps && isActive("Shiny Charm")){
//Prevent the egg from having more shinyProgress then steps if amount would go over the max (eg if progress is 499 and steps is 5 the egg doesn't get 504 shinyprogress)
player.eggList[i].shinyProgress = Math.min(player.eggList[i].steps, player.eggList[i].shinyProgress + amount);
}
player.eggList[i].progress += amount;
}
}
checkEggHatch();
showEggs();
}
var checkEggHatch = function(){
for(var i = 0; i<player.eggList.length; i++){
var egg = player.eggList[i];
if(egg !== null){
if( egg.progress >= egg.steps){
if(!egg.notify){
egg.notify = 1;
$.notify("One of your eggs is ready to hatch!", "success");
notifyMe("One of your eggs is ready to hatch!");
}
}
}
}
}
var hatchEgg = function(i){
var egg = player.eggList[i];
player.eggList[i] = null;
$.notify("You hatched " + egg.pokemon, 'success');
progressQuest('breedPokemon', "none", 1);
capturePokemon(egg.pokemon, generateEggShiny(egg));
player.totalBred++;
showEggs();
save();
}
var buyEggSlot = function(i){
if(canBuyEggSlot(i)){
player.questPoints -= eggSlotPrice[i];
player.eggSlots++;
showEggs();
save();
}
}
var canBuyEggSlot = function(i){
return player.questPoints >= eggSlotPrice[i];
}
var showEggs = function(){
for(var i = 0; i<player.eggList.length; i++){
var html = ""
if(player.eggList[i] !== null){
if( player.eggList[i].progress >= player.eggList[i].steps){
html += "<img style='cursor:pointer;' onClick='hatchEgg(" + i + ")' title='" + player.eggList[i].type + "' class='egg tooltipUp' src=images/breeding/egg" + player.eggList[i].type.toLowerCase() + ".png>"
} else{
html += "<img title='" + player.eggList[i].type + "' class='egg tooltipUp' src=images/breeding/egg" + player.eggList[i].type.toLowerCase() + ".png>";
}
if(player.eggList[i].progress < player.eggList[i].steps){
html += "<div title='" + Math.floor(player.eggList[i].progress) + "/" + player.eggList[i].steps + "' class='progress eggProgress tooltipEggProgress' style='width: 80%; margin:auto'>";
} else {
html += "<div title='Click on the egg to hatch it!' class='progress eggProgress tooltipEggProgress' style='width: 80%; margin:auto'>";
}
html += "<div class='progress-bar progress-bar-success' style='width: " + Math.floor(player.eggList[i].progress)/player.eggList[i].steps*100 + "%'>";
html += "<span class='sr-only'></span>";
html += "</div>";
html += "</div>";
} else {
if( i == player.eggSlots && canBuyEggSlot(i)){
html += "<br><button class='egg btn btn-info' onClick='buyEggSlot("+i+")'>" + eggSlotPrice[i] + " QP</p><p>Egg slot</p>";
} else if (i >= player.eggSlots){
html += "<br><button class='egg btn btn-info disabled'>" + eggSlotPrice[i] + " QP</p><p>Egg slot</p>";
}
}
$("#egg"+i).html(html)
}
$(".tooltipUp").tooltipster({
position: "top"
});
$(".tooltipEggProgress").tooltipster({
position: "bottom"
});
}
var showMom = function(){
var html = "<div class='row'>";
html += "<p>Breed your level 100 Pokemon.</p>";
html += "<p>You lose your Pokemon, but gain an egg with the same Pokemon</p>";
html += "<p>Hatched Pokemon have a big chance to be shiny!</p>"
html += "<p>Defeat wild Pokemon to hatch your eggs.</p>";
html += "<p>Click on a Pokemon to breed them!</p>"
html += "</div>";
html += "<div class='row'>";
for( var i = 0; i<player.caughtPokemonList.length; i++){
if(canBreed(player.caughtPokemonList[i])){
html += "<div data-pokemon='" + player.caughtPokemonList[i].name + "' class='col-sm-3 col-md-2 pokedexEntry breedPokemon' style='height:auto;'>";
html += "<img class='center-block' id='pokedexImage' src=images/pokemon/"+player.caughtPokemonList[i].id+".png >";
html += "<p>" + player.caughtPokemonList[i].name + "</p>";
html += "</div>"
}
}
html += "</div";
$("#breedingBody").html(html);
$("#breedingModal").modal('show');
}
var canBreed = function(pokemon){
var pokemonLevel = experienceToLevel(pokemon.experience, pokemon.levelType);
return pokemonLevel >= 100 && !pokemon.shiny;
}
var generateEggShiny = function(egg){
var chance = 1024;
if(isActive("Shiny Charm")){
chance /= getOakItemBonus("Shiny Charm") - (1-(egg.shinyProgress/egg.steps));
}
var number = Math.floor(Math.random()*chance) + 1;
if(number <= 1){
console.log("Shiny!!!");
return 1;
}
if(recoverResetShiny(egg)){
return 1;
}
return 0;
};