Skip to content

Instantly share code, notes, and snippets.

@BenjaminUrquhart
Created October 20, 2024 09:49
Show Gist options
  • Save BenjaminUrquhart/11a96f24aa76397f1b07e7b4d437d0d9 to your computer and use it in GitHub Desktop.
Save BenjaminUrquhart/11a96f24aa76397f1b07e7b4d437d0d9 to your computer and use it in GitHub Desktop.
Very dirty JS portion of an In Stars and Time mod that makes the Memory of Emptiness function in every act.
// Helper stuff
// Learning Javascript using Notepad++ is not ideal but it works I guess.
// Could be worse.
clone = function(obj) {
return JSON.parse(JSON.stringify(obj))
}
var ReviveMod = {}
ReviveMod.initialized = false
ReviveMod.initCode = undefined
ReviveMod.depthShift = 0
ReviveMod.BM_processDefeat = BattleManager.processDefeat;
BattleManager.processDefeat = function() {
let actor = $gameActors.actor(1);
if(!actor.hasArmor($dataArmors[88])) {
return ReviveMod.BM_processDefeat.call(this);
}/*
Game_Interpreter.prototype.iterateActorEx(0, 0, function(a) {
//a.removeState(1);
a.removeState(19);
});*/
BattleManager.actionCommonEvent(310);
}
ReviveMod.init = function() {
if(this.initialized) {
return true;
}
this.initCode = []
let mapCode = $gameMap._interpreter._list;
if(!mapCode) {
console.warn("Map interpreter is not running, bailing init!");
return false;
}
// Copy init event code so it can be inserted when saved (TODO)
for(let i = mapCode.length - 1; i >= 0; i--) {
let inst = mapCode[i]
if(inst.code == 118 && inst.parameters[0] == "end") {
this.initCode = mapCode.slice(i - mapCode.length);
this.depthShift = inst.depth;
break;
}
}
if(!this.initCode) {
console.warn("Failed to find init code (needs to end with 'Label: end')");
return false;
}
if($dataSkills[187].scope != 8) {
// Yeah so turns out this big commented blob
// doesn't work for whatever reason and isn't even needed.
// Only found that out after like 4 hours of debugging.
/*
//if ReviveMod.allDown() {
// Common Event: ReviveAct5
// Jump to Label: end
//} End
const reviveCheck = [
{
code: 111,
indent: 0,
parameters: [12, "$gameActors.actor(1).hasArmor(88) && ReviveMod.allDown()"]
},
{
code: 117,
indent: 1,
parameters: [310]
},
{
code: 119,
indent: 1,
parameters: ["end"]
},
{
code: 0,
indent: 1,
parameters: []
}
]
// Create new event for Mirabelle
let miraPage = clone($dataTroops[54].pages[8]);
miraPage.conditions.actorId = 3;
miraPage.list = clone(reviveCheck);
miraPage.list.push({
code: 0,
indent: 0,
parameters: []
});
// Make party immortal if memory is worn
let immortalPage = {}
immortalPage.conditions = clone($dataTroops[54].pages[8].conditions)
immortalPage.conditions.actorValid = false;
immortalPage.conditions.turnValid = true;
immortalPage.span = 0;
//if Siffrin has equipped Memory of Emptiness {
// Change State: Siffrin, +Immortal
//} End
immortalPage.list = [
{
code: 111,
indent: 0,
parameters: [4,1,2,88]
},
{
code: 355,
indent: 1,
parameters: ["console.log('Making the frin immortal')"]
},
{
code: 313,
indent: 1,
parameters: [0,1,0,3]
},
{
code: 0,
indent: 1,
parameters: []
}
];
// Edit battle events directly beacuse the base event plugin has already ran
for(let i = 1; i < $dataTroops.length; i++) {
let troop = $dataTroops[i]
for(let j = 0; j < troop.pages.length; j++) {
page = troop.pages[j]
if(page.conditions.actorValid && page.conditions.actorId != 6 && page.conditions.actorHp == 0) {
// This does not exist naturally (and shouldn't happen tbh)
if(page.conditions.actorId == 3) {
continue;
}
// Insert death check
for(let k = reviveCheck.length - 1; k >= 0; k--) {
page.list.unshift(reviveCheck[k]);
}
// Insert end label
let exit = page.list.pop();
page.list.push({
code: 118,
indent: 0,
parameters: ["end"]
});
page.list.push(exit);
}
}
troop.pages.push(miraPage);
troop.pages.push(immortalPage);
}
// Remove immortality on battle end
$dataCommonEvents[64].list.push({
code: 313,
indent: 0,
parameters: [0,0,1,3]
});*/
// Modify loop heal skill to target the entire party
// and not lock equipment
let skill = $dataSkills[187];
skill.scope = 8;
// Remove item lockout effect from skill
let last = skill.effects.slice(-1)[0];
if(last.code == 21 && last.dataId == 88) {
skill.effects.pop();
}
// Edit existing revive common event
let eventCmds = $dataCommonEvents[310].list;
for(let i = 0; i < eventCmds.length; i++) {
let cmd = eventCmds[i]
// if RE_diedAct5Once is OFF -> if eval: <act == 5 and RE_diedAct5Once is OFF>
if(cmd.code == 111 && cmd.parameters[0] == 0 && cmd.parameters[1] == 291 && cmd.parameters[2] == 1) {
cmd.parameters[0] = 12;
cmd.parameters[1] = "$gameVariables.value(2) == 5 && !$gameSwitches.value(291)";
}
else if(cmd.code == 313) {
// Restrict item lock state change to Act 5 Siffrin
// and remove funny internal state from the entire party
// Funny internal state
if(cmd.parameters[3] == 53) {
cmd.parameters[1] = 0
}
// Item lock
else if(cmd.parameters[3] == 88) {
cmd.parameters[1] = 6
}
}
else if(cmd.code == 250) {
// Remove knockout states here
eventCmds.splice(i + 1, 0, {
code: 313,
indent: 0,
parameters: [0,0,1,19]
});
eventCmds.splice(i + 1, 0, {
code: 313,
indent: 0,
parameters: [0,0,1,1]
});
}
}
}
this.initialized = true;
return true;
}
// TODO: handle writing init code to the save
// and also properly unload if an unrelated save is loaded
ReviveMod.DM_extractSaveContents = DataManager.extractSaveContents;
DataManager.extractSaveContents = function(save) {
ReviveMod.DM_extractSaveContents.call(this, save)
ReviveMod.unhook()
}
ReviveMod.DM_makeSaveContents = DataManager.makeSaveContents;
DataManager.makeSaveContents = function() {
let data = ReviveMod.DM_makeSaveContents.call(this);
return data;
}
ReviveMod.unhook = function() {
DataManager.extractSaveContents = ReviveMod.DM_extractSaveContents;
DataManager.makeSaveContents = ReviveMod.DM_makeSaveContents;
}
if(!ReviveMod.init()) {
alert("Mod init failed")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment