Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Seasonal Events update fix #345

Merged
merged 2 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions autobattlefrontier.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @description Adds in stage resetting to the Battle Frontier that allows you to set a target stage and infinitely farm the Battle Frontier while being fully AFK. Also, gives the appropriate amount of Battle Points and Money without needing to fail and lose a stage.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.5.2
// @version 1.5.3

// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
Expand Down Expand Up @@ -53,16 +53,18 @@ class AutoBattleFrontier {
bfQuit.setAttribute('onclick', 'BattleFrontierRunner.end()');

const battleFrontTitle = document.querySelector('#battleFrontierInformation div.card-header');
const attackCeilButton = document.createElement("div");
attackCeilButton.setAttribute("id", "bf-attack-ceil-btn");
attackCeilButton.innerHTML = `<button id="bf-attack-ceil-start" class="btn btn-block btn-${this.battleFrontAttackCeil ? 'success' : 'danger'}" style="font-size: 8pt;">Max Attacks: ${this.battleFrontAttackCeil || 'OFF'}</button>`
const attackCeilContainer = document.createElement("div");
attackCeilContainer.setAttribute("id", "bf-attack-ceil-btn");
attackCeilContainer.innerHTML = `<button id="bf-attack-ceil-start" style="font-size: 8pt;"></button>`;
const attackCeilButton = attackCeilContainer.querySelector('#bf-attack-ceil-start');
attackCeilButton.setAttribute('data-bind', 'class: `btn btn-block btn-${AutoBattleFrontier.battleFrontAttackCeil ? \'success\' : \'danger\'}`, text: `Max Attacks: ${AutoBattleFrontier.battleFrontAttackCeil}`');
attackCeilButton.setAttribute('onclick', 'AutoBattleFrontier.toggleBattleFrontAttackCeil()');
const bfInput = document.createElement("div");
bfInput.innerHTML = `Max Stage: <input id="battle-front-input" style="width: 70px; margin: 5px;"> <button id="battle-front-input-submit" class="btn btn-block btn-danger" style="font-size: 8pt; width: 42px; display:inline-block;">OK</button>`;
bfInput.setAttribute("id", "battle-front-cont");
bfInput.innerHTML = `Max Stage: <input id="battle-front-input" style="width: 70px; margin: 5px;"> <button id="battle-front-input-submit" class="btn btn-block btn-danger" style="font-size: 8pt; width: 42px; display:inline-block;">OK</button>`
battleFrontTitle.before(bfInput);
battleFrontTitle.before(attackCeilButton);
document.getElementById('battle-front-input').value = this.battleFrontCeil.toLocaleString('en-US');
battleFrontTitle.before(attackCeilContainer);
document.getElementById('battle-front-input').setAttribute('data-bind', 'value: AutoBattleFrontier.battleFrontCeil.toLocaleString(\'en-US\')');
document.getElementById('battle-front-input-submit').setAttribute('onclick', 'AutoBattleFrontier.setBattleFrontCeil()');

addGlobalStyle('#battle-front-cont { position:absolute;right:0px;top:0px;width:auto;height:41px;padding:5px;display:flex;align-items:center; }');
Expand Down
151 changes: 83 additions & 68 deletions custom/infiniteseasonalevents.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
// @name [Pokeclicker] Infinite Seasonal Events
// @namespace Pokeclicker Scripts
// @author Ephenia
// @description Adds in toggable options to have seasonal events infinitely run. Events can also run simultaneously with one another. Includes custom events as well.
// @description Adds in toggable options to have seasonal events infinitely run. Events can also run simultaneously with one another. Includes a custom event as well.
// @copyright https://github.com/Ephenia
// @license GPL-3.0 License
// @version 1.2
// @version 1.3

// @homepageURL https://github.com/Ephenia/Pokeclicker-Scripts/
// @supportURL https://github.com/Ephenia/Pokeclicker-Scripts/issues
Expand All @@ -20,60 +20,63 @@

var scriptName = 'infiniteseasonalevents'

var startDate = new Date(new Date().getFullYear(), -1);
var endDate = new Date(new Date().getFullYear(), 10000);
var getEvents = SpecialEvents.events;
var storedEvents = [];
var profileDrop = document.getElementById('startMenu').querySelectorAll('ul li')[0];
var profileModal = document.getElementById('profileModal');
var activeSeasonalEvents = {};

//Removed setTimeout, opted to make it load like the other scrips, also helps with notifications
function initEvents() {
SpecialEvents.newEvent('Ephenia\'s Gift', 'Encounter Ribombee that roams across all regions.<br/>A special thanks for using my scripts!',
startDate, () => {
GameHelper.enumNumbers(GameConstants.Region).filter(i => i != GameConstants.Region.none).forEach(region => {
RoamingPokemonList.add(region, new RoamingPokemon('Ribombee'));
});
},
endDate, () => {
GameHelper.enumNumbers(GameConstants.Region).filter(i => i != GameConstants.Region.none).forEach(region => {
RoamingPokemonList.remove(region, 'Ribombee');
});
}
);
const NUM_EVENTS = 10;
const startDate = new Date(new Date().getFullYear(), -1);
const endDate = new Date(new Date().getFullYear(), 10000);

App.game.specialEvents.newEvent('Ephenia\'s Gift',
'Encounter Ribombee that roams across all regions.<br/>A special thanks for using my scripts!',
startDate,
() => {
GameHelper.enumNumbers(GameConstants.Region).filter(i => i != GameConstants.Region.none).forEach(region => {
RoamingPokemonList.add(region, 0, new RoamingPokemon('Ribombee')); // Currently adding in base subregions only
});
},
endDate,
() => {
GameHelper.enumNumbers(GameConstants.Region).filter(i => i != GameConstants.Region.none).forEach(region => {
RoamingPokemonList.remove(region, 0, 'Ribombee');
});
},
true
);

//Testing loading events in init
for (var i = 0; i < getEvents.length; i++) {
if (localStorage.getItem(getEvents[i].title) == null) {
localStorage.setItem(getEvents[i].title, 0);
}
/*
Changed the storedEvents list to contain objects that have the name of the event and active status so we can search for them
even with a different order
*/
storedEvents.push({name: getEvents[i].title, active: localStorage.getItem(getEvents[i].title)})
for (const event of App.game.specialEvents.events) {
let eventActive = loadSetting(event.title, false);
activeSeasonalEvents[event.title] = eventActive;
}

for (var ii = 0; ii < getEvents.length; ii++) {
getEvents[ii].startTime = startDate
getEvents[ii].endTime = endDate
if (getEvents[ii].hasStarted() == false && storedEvents[ii].active == 1) {
getEvents[ii].start()
for (const event of App.game.specialEvents.events) {
event.startTime = startDate;
event.endTime = endDate;

if (!event.hasStarted() && activeSeasonalEvents[event.title]) {
event.start();
}
}

if (getEvents.length != 10) {
if (App.game.specialEvents.events.length != NUM_EVENTS) {
Notifier.notify({
title: '[Outdated] Infinite Seasonal Events',
message: `Please contact <a href="https://github.com/Ephenia/Pokeclicker-Scripts" target="_blank">Ephenia</a> so that this script can be updated!`,
type: NotificationConstants.NotificationOption.danger,
timeout: 10000
timeout: 1000000
});
}

var eventLi = document.createElement('li');
eventLi.innerHTML = `<a class="dropdown-item" href="#eventModal" data-toggle="modal">Toggle Events</a>`
profileDrop.before(eventLi);
eventLi.innerHTML = `<a class="dropdown-item" href="#eventModal" data-toggle="modal">Toggle Events</a>`;
for (const node of document.querySelectorAll('#startMenu ul li')) {
if (node.querySelector('a[href="#eventsModal"]')) {
node.after(eventLi);
break;
}
}

var eventMod = document.createElement('div');
eventMod.setAttribute("class", "modal noselect fade show");
Expand All @@ -96,22 +99,24 @@ function initEvents() {
</div>
</div>`

profileModal.before(eventMod);
document.getElementById('profileModal').before(eventMod);

var modalBody = document.querySelector('[id=eventModal] div div [class=modal-body]')
//Event order seems to change on startup so this loads them independent of order, also loads any new events without images
for (i = 0; i<getEvents.length;i++){
switch(getEvents[i].title){
for (const event of App.game.specialEvents.events) {
let title = event.title;
let description = event.description;
switch(title){
case "Flying Pikachu":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/25.1.png">
<img src="assets/images/pokemon/21.01.png">
</div><hr>`
break
case "Mewtwo strikes back!":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/150.03.png">
<img src="assets/images/pokemon/1.01.png">
<img src="assets/images/pokemon/4.01.png">
Expand All @@ -120,7 +125,7 @@ function initEvents() {
break
case "Halloween!":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/1.02.png">
<img src="assets/images/pokemon/25.12.png">
<img src="assets/images/pokemon/175.01.png"><br>
Expand All @@ -132,29 +137,29 @@ function initEvents() {
break
case "Let's GO!":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/25.13.png">
<img src="assets/images/pokemon/133.02.png">
</div><hr>`
break
case "Merry Christmas!":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/143.02.png">
<img src="assets/images/pokemon/251.01.png">
<img src="assets/images/pokemon/446.01.png">
</div><hr>`
break
case "Hoopa Day":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<i>(Note that this event only adds a special joke questline and doesn't add Hoopa as an additional roamer. Hoopa is available without this event.)</i><br>
<img src="assets/images/pokemon/720.png">
</div><hr>`
break
case "Lunar New Year":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/666.png">
<img src="assets/images/pokemon/666.19.png"><br>
<img src="assets/images/pokemon/666.01.png">
Expand All @@ -179,55 +184,65 @@ function initEvents() {
break
case "Easter":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/175.02.png">
</div><hr>`
break
case "Golden Week":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/1.03.png">
</div><hr>`
break
case "Ephenia's Gift":
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br>
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br>
<img src="assets/images/pokemon/743.png">
</div><hr>`
break
default:
modalBody.innerHTML +=
`<div id="event-`+i+`" class="event-select" data-value="`+i+`"><b>`+getEvents[i].title+`</b><br>`+getEvents[i].description+`<br><br>New event, Pokemon images coming soon, if not open an issue on github
`<div id="event-${title}" class="event-select" data-value="${title}"><b>${title}</b><br>${description}<br><br>New event, Pokemon images coming soon, if not open an issue on github
</div><hr>`
}
}

for (var add = 0; add < getEvents.length; add++) {
if (storedEvents[add].active == 1) {
document.getElementById('event-'+(add)).style = "background-color: rgba(93, 226, 60, 0.5)"
for (const event of App.game.specialEvents.events) {
if (activeSeasonalEvents[event.title]) {
document.getElementById('event-'+event.title).style = "background-color: rgba(93, 226, 60, 0.5)";
}
document.getElementById('event-'+(add)).addEventListener('click', toggleEvent, false)
document.getElementById('event-'+event.title).addEventListener('click', toggleEvent);
}

addGlobalStyle('.event-select { cursor: pointer; }');
addGlobalStyle('.event-select:hover { background-color: rgba(48, 197, 255, 0.5); }');
}

function toggleEvent() {
var getVal = this.getAttribute('data-value');
var getEvent = +localStorage.getItem(storedEvents[getVal].name)
if (getEvent == 0) {
this.style = "background-color: rgba(93, 226, 60, 0.5)"
storedEvents[getVal].value = 1
localStorage.setItem(storedEvents[getVal].name, 1)
getEvents[getVal].start()
var title = this.getAttribute('data-value');
activeSeasonalEvents[title] = !activeSeasonalEvents[title];
localStorage.setItem(title, activeSeasonalEvents[title]);
if (activeSeasonalEvents[title]) {
this.style = "background-color: rgba(93, 226, 60, 0.5)";
App.game.specialEvents.events.find((event) => (event.title === title)).start();
} else {
this.style = ""
storedEvents[getVal].value = 0
localStorage.setItem(storedEvents[getVal].name, 0)
getEvents[getVal].end()
this.style = "";
App.game.specialEvents.events.find((event) => (event.title === title)).end();
}
}

function loadSetting(key, defaultVal) {
var val;
try {
val = JSON.parse(localStorage.getItem(key));
if (val == null || typeof val !== typeof defaultVal) {
throw new Error;
}
} catch {
val = defaultVal;
localStorage.setItem(key, defaultVal);
}
//console.log(getVal)
return val;
}

//Made this script load like the others for consistency
Expand Down