buff falling pixel and use runAfterAutogen

This commit is contained in:
Laetitia (O-01-67) 2023-02-12 10:35:48 -05:00 committed by GitHub
parent 5b7686a220
commit be7236a9b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 109 additions and 87 deletions

View File

@ -1,101 +1,123 @@
if(typeof(width) === "undefined") { var modName = "mods/insane_random_events.js";
width = 20; var runAfterAutogenMod = "mods/runAfterAutogen and onload restructure.js";
} var libraryMod = "mods/code_library.js";
if(typeof(height) === "undefined") {
height = 10;
}
runAfterLoad(function() { if(enabledMods.includes(runAfterAutogenMod) && enabledMods.includes(libraryMod)) {
var randomChoices = Object.keys(elements).filter(function(e) { if(typeof(width) === "undefined") {
return elements[e].excludeRandom != true && elements[e].category != "tools" && !elements[e].tool; width = 20;
});
randomEventChoices = {
"falling_pixel": randomChoices,
"element_circle": randomChoices,
"explosion": randomChoices,
} }
randomEvents.falling_pixel = function() { if(typeof(height) === "undefined") {
//console.log("changed"); height = 10;
// random x between 1 and width-1 }
var x = Math.floor(Math.random()*(width-1))+1;
// random y between 1 and 6 runAfterAutogen(function() {
var y = Math.floor(Math.random()*6)+1; //Regenerate randomChoices
if (isEmpty(x,y)) { var randomChoices = Object.keys(elements).filter(function(e) {
// random element from randomEventChoices.falling_pixel return elements[e].excludeRandom != true && elements[e].category != "tools" && !elements[e].tool;
});
//Set all event choices to randomChoices
randomEventChoices = {
"falling_pixel": randomChoices.filter( function(elem) { return commonMovableCriteria(elem) } ),
"element_circle": randomChoices,
"explosion": randomChoices,
}
//Buff event functions
randomEvents.old_falling_pixel = randomEvents.falling_pixel;
//transform falling_pixel into a rain of pixels
randomEvents.falling_pixel = function() {
var element = randomEventChoices.falling_pixel[Math.floor(Math.random()*randomEventChoices.falling_pixel.length)]; var element = randomEventChoices.falling_pixel[Math.floor(Math.random()*randomEventChoices.falling_pixel.length)];
// if element is an array, choose a random element from the array for(i = 1; i < width; i++) {
if (Array.isArray(element)) { for(j = 0; j < Math.round(height * 0.35); j++) {
element = element[Math.floor(Math.random()*element.length)]; if(Math.random() < 0.1 && isEmpty(i,j)) {
createPixel(element,i,j)
};
};
};
};
randomEvents.element_circle = function() {
// random x between 1 and width-1
var x = Math.floor(Math.random()*(width-1))+1;
// random y between 1 and height-1
var y = Math.floor(Math.random()*(height-1))+1;
// random radius between 1 and 9
var radius = Math.floor(Math.random()*19)+1;
// random element from randomEventChoices.element_circle
var element = randomEventChoices.element_circle[Math.floor(Math.random()*randomEventChoices.element_circle.length)];
var coords = circleCoords(x,y,radius);
for (var i = 0; i < coords.length; i++) {
var coord = coords[i];
if (isEmpty(coord.x,coord.y)) {
createPixel(element,coord.x,coord.y);
}
} }
createPixel(element,x,y); };
} randomEvents.explosion = function() {
}; // similar but do explodeAt(x,y,radius,element)
randomEvents.element_circle = function() {
// random x between 1 and width-1
var x = Math.floor(Math.random()*(width-1))+1;
// random y between 1 and height-1
var y = Math.floor(Math.random()*(height-1))+1;
// random radius between 1 and 9
var radius = Math.floor(Math.random()*19)+1;
// random element from randomEventChoices.element_circle
var element = randomEventChoices.element_circle[Math.floor(Math.random()*randomEventChoices.element_circle.length)];
var coords = circleCoords(x,y,radius);
for (var i = 0; i < coords.length; i++) {
var coord = coords[i];
if (isEmpty(coord.x,coord.y)) {
createPixel(element,coord.x,coord.y);
}
}
};
randomEvents.explosion = function() {
// similar but do explodeAt(x,y,radius,element)
var x = Math.floor(Math.random()*(width-1))+1;
var y = Math.floor(Math.random()*(height-1))+1;
var radius = Math.floor(Math.random()*19)+1;
var element = randomEventChoices.explosion[Math.floor(Math.random()*randomEventChoices.explosion.length)];
explodeAt(x,y,radius,element);
};
randomEvents.temperature = function() {
// set the temperature in a random circle to a random value
var x = Math.floor(Math.random()*(width-1))+1;
var y = Math.floor(Math.random()*(height-1))+1;
var radius = Math.floor(Math.random()*19)+1;
var temp = Math.floor(Math.random()*400)-273;
var coords = circleCoords(x,y,radius);
for (var i = 0; i < coords.length; i++) {
var coord = coords[i];
if (!outOfBounds(coord.x,coord.y) && !isEmpty(coord.x,coord.y)) {
pixelMap[coord.x][coord.y].temp = temp;
}
}
};
if(enabledMods.includes("mods/paint_event.js")) {
randomEvents.paint = function() {
// set the color of a random circle to a random color
var x = Math.floor(Math.random()*(width-1))+1; var x = Math.floor(Math.random()*(width-1))+1;
var y = Math.floor(Math.random()*(height-1))+1; var y = Math.floor(Math.random()*(height-1))+1;
var randomR = Math.floor(Math.random() * 256);
var randomG = Math.floor(Math.random() * 256);
var randomB = Math.floor(Math.random() * 256);
var radius = Math.floor(Math.random()*19)+1; var radius = Math.floor(Math.random()*19)+1;
var rColor = "rgb(" + randomR + "," + randomG + "," + randomB + ")"; var element = randomEventChoices.explosion[Math.floor(Math.random()*randomEventChoices.explosion.length)];
explodeAt(x,y,radius,element);
};
randomEvents.temperature = function() {
// set the temperature in a random circle to a random value
var x = Math.floor(Math.random()*(width-1))+1;
var y = Math.floor(Math.random()*(height-1))+1;
var radius = Math.floor(Math.random()*19)+1;
var temp = Math.floor(Math.random()*400)-273;
var coords = circleCoords(x,y,radius); var coords = circleCoords(x,y,radius);
for (var i = 0; i < coords.length; i++) { for (var i = 0; i < coords.length; i++) {
var coord = coords[i]; var coord = coords[i];
if (!outOfBounds(coord.x,coord.y) && !isEmpty(coord.x,coord.y)) { if (!outOfBounds(coord.x,coord.y) && !isEmpty(coord.x,coord.y)) {
pixelMap[coord.x][coord.y].color = rColor; pixelMap[coord.x][coord.y].temp = temp;
}
}
};
if(enabledMods.includes("mods/paint_event.js")) {
randomEvents.paint = function() {
// set the color of a random circle to a random color
var x = Math.floor(Math.random()*(width-1))+1;
var y = Math.floor(Math.random()*(height-1))+1;
var randomR = Math.floor(Math.random() * 256);
var randomG = Math.floor(Math.random() * 256);
var randomB = Math.floor(Math.random() * 256);
var radius = Math.floor(Math.random()*19)+1;
var rColor = "rgb(" + randomR + "," + randomG + "," + randomB + ")";
var coords = circleCoords(x,y,radius);
for (var i = 0; i < coords.length; i++) {
var coord = coords[i];
if (!outOfBounds(coord.x,coord.y) && !isEmpty(coord.x,coord.y)) {
pixelMap[coord.x][coord.y].color = rColor;
};
}; };
}; };
}; };
}; //Buff mob events
//creeper event if(typeof(maximumCreeperTries) !== "undefined") {
if(typeof(maximumCreeperTries) !== "undefined") { minimumCreeperTries = 10;
minimumCreeperTries = 10; maximumCreeperTries = 30;
maximumCreeperTries = 30; };
}; if(typeof(maximumZombieTries) !== "undefined") {
//zombie event minimumZombieTries = 10;
if(typeof(maximumZombieTries) !== "undefined") { maximumZombieTries = 30;
minimumZombieTries = 10; };
maximumZombieTries = 30; if(typeof(maximumSkeletonTries) !== "undefined") {
}; minimumSkeletonTries = 10;
}); maximumSkeletonTries = 30;
};
//New event option
var eventOptions = document.querySelectorAll('span[setting="events"]')[0].children[0];
var newEventOption = document.createElement("option");
newEventOption.setAttribute("value","1");
newEventOption.textContent = "Every tick (why)";
eventOptions.appendChild(newEventOption);
});
} else {
if(!enabledMods.includes(libraryMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,libraryMod) };
if(!enabledMods.includes(runAfterAutogenMod)) { enabledMods.splice(enabledMods.indexOf(modName),0,runAfterAutogenMod) };
localStorage.setItem("enabledMods", JSON.stringify(enabledMods));
alert(`The "${runAfterAutogenMod}" and "${libraryMod}" mods are required and have been automatically inserted (reload for this to take effect).`);
};