-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamnesia.ts
102 lines (90 loc) · 3.39 KB
/
amnesia.ts
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
import { Random, SeededGenerator } from "utilities/Random";
import Mod from "mod/Mod";
import { HookMethod } from "mod/IHookHost";
export default class Amnesia extends Mod {
private lostRecipes: number[];
/**
* Called when the mod is initialized (mod files are read/loaded when the title screen loads)
* @param saveDataGlobal The save data object you previously saved via onInitialize()
* @returns An object containing the data you want to save (saved globally, not per slot)
*/
public onInitialize(saveDataGlobal: any): any {
}
/**
* Called when the mod is loaded
* Called before the world is loaded
* @param saveData The save data object you previously saved via onSave()
*/
public onLoad(saveData: any): void {
if (saveData !== undefined) {
// Remove recipes that are lost in this game slot
this.lostRecipes = saveData;
for (let r in this.lostRecipes) {
let craftedId = this.lostRecipes[r];
delete game.crafted[craftedId];
}
// Want to display the new craft table right from the start
game.updateTablesAndWeight();
} else {
this.lostRecipes = [];
}
}
/**
* Called when the mod is unloaded (quit to main menu)
* Called after onSave() when a game is ending
*/
public onUnload(): void {
// Restore all recipes that were deleted because the list is global and should not influence other game slots
for (let r in this.lostRecipes) {
let craftedId = this.lostRecipes[r];
game.crafted[craftedId] = true;
}
}
/**
* Called when the game is saved or the mod is unloaded
* This will be called before onUnload
* @returns An object containing the data you want to save
*/
public onSave(): any {
// Save only recipes that were not rediscovered
let cleanArray: number[] = [];
for (let r in this.lostRecipes) {
let craftedId = this.lostRecipes[r];
if (game.crafted[craftedId] !== true) {
cleanArray.push(craftedId);
}
}
this.lostRecipes = cleanArray;
return this.lostRecipes;
}
/**
* Called when the game is starting
* Called after onLoad()
* @param isLoadingSave True if a save game was loaded
* @param playedCount The number of times the player has played the game (globally, not per slot)
*/
@HookMethod
public onGameStart(isLoadingSave: boolean, playedCount: number): void {
if (isLoadingSave) {
return; // Restoring changed recipe list is handled in onLoad
}
// New game started, remove some recipes
if (playedCount < 10) {
return; // Don't want to kill new players' recipes
}
let gen = new SeededGenerator();
let rdm = new Random(gen);
// 25% to 75% chance to lose any recipe
let chance = rdm.intInRange(25, 75) / 100;
for (let i in game.crafted) {
let f = rdm.float();
if (f < chance) {
this.lostRecipes.push(Number(i));
delete game.crafted[i];
}
}
// Want to display the new craft table right from the start.
// This is only called once per loading game so it shouldn't hurt
game.updateTablesAndWeight();
}
}