-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
622 lines (620 loc) · 22.9 KB
/
main.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// main.ts
var main_exports = {};
__export(main_exports, {
default: () => GamificationPlugin
});
module.exports = __toCommonJS(main_exports);
var import_obsidian = require("obsidian");
var classes = [
"Warrior",
"Mage",
"Rogue",
"Archer",
"Healer",
"Paladin",
"Necromancer",
"Druid",
"Bard",
"Monk",
"Sorcerer",
"Assassin",
"Ranger"
];
var skills = [
// Warrior skills
{ name: "Strength", classes: ["Warrior"], points: 0 },
{ name: "Endurance", classes: ["Warrior"], points: 0 },
{ name: "Speed", classes: ["Warrior"], points: 0 },
{ name: "Shield Mastery", classes: ["Warrior"], points: 0 },
{ name: "Swordsmanship", classes: ["Warrior"], points: 0 },
{ name: "Battle Cry", classes: ["Warrior"], points: 0 },
{ name: "Berserk", classes: ["Warrior"], points: 0 },
{ name: "Heavy Armor", classes: ["Warrior"], points: 0 },
// Mage skills
{ name: "Magic", classes: ["Mage"], points: 0 },
{ name: "Wisdom", classes: ["Mage"], points: 0 },
{ name: "Elemental Mastery", classes: ["Mage"], points: 0 },
{ name: "Arcane Power", classes: ["Mage"], points: 0 },
{ name: "Mana Control", classes: ["Mage"], points: 0 },
{ name: "Spellcasting", classes: ["Mage"], points: 0 },
{ name: "Teleportation", classes: ["Mage"], points: 0 },
{ name: "Alchemy", classes: ["Mage"], points: 0 },
// Rogue skills
{ name: "Stealth", classes: ["Rogue"], points: 0 },
{ name: "Agility", classes: ["Rogue"], points: 0 },
{ name: "Lockpicking", classes: ["Rogue"], points: 0 },
{ name: "Backstab", classes: ["Rogue"], points: 0 },
{ name: "Pickpocketing", classes: ["Rogue"], points: 0 },
{ name: "Evasion", classes: ["Rogue"], points: 0 },
{ name: "Poison Mastery", classes: ["Rogue"], points: 0 },
{ name: "Dual Wield", classes: ["Rogue"], points: 0 },
// Archer skills
{ name: "Marksmanship", classes: ["Archer"], points: 0 },
{ name: "Eagle Eye", classes: ["Archer"], points: 0 },
{ name: "Quick Shot", classes: ["Archer"], points: 0 },
{ name: "Tracking", classes: ["Archer"], points: 0 },
{ name: "Trap Setting", classes: ["Archer"], points: 0 },
{ name: "Survival", classes: ["Archer"], points: 0 },
{ name: "Camouflage", classes: ["Archer"], points: 0 },
{ name: "Arrow Crafting", classes: ["Archer"], points: 0 },
// Healer skills
{ name: "Healing Touch", classes: ["Healer"], points: 0 },
{ name: "Restoration", classes: ["Healer"], points: 0 },
{ name: "Purification", classes: ["Healer"], points: 0 },
{ name: "Revive", classes: ["Healer"], points: 0 },
{ name: "Protective Aura", classes: ["Healer"], points: 0 },
{ name: "Divine Light", classes: ["Healer"], points: 0 },
{ name: "Herbalism", classes: ["Healer"], points: 0 },
{ name: "Meditation", classes: ["Healer"], points: 0 },
// Paladin skills
{ name: "Holy Strike", classes: ["Paladin"], points: 0 },
{ name: "Divine Shield", classes: ["Paladin"], points: 0 },
{ name: "Righteous Fury", classes: ["Paladin"], points: 0 },
{ name: "Healing Light", classes: ["Paladin"], points: 0 },
{ name: "Blessing", classes: ["Paladin"], points: 0 },
{ name: "Smite", classes: ["Paladin"], points: 0 },
{ name: "Aura of Protection", classes: ["Paladin"], points: 0 },
{ name: "Holy Resistance", classes: ["Paladin"], points: 0 },
// Necromancer skills
{ name: "Raise Dead", classes: ["Necromancer"], points: 0 },
{ name: "Dark Pact", classes: ["Necromancer"], points: 0 },
{ name: "Bone Armor", classes: ["Necromancer"], points: 0 },
{ name: "Soul Siphon", classes: ["Necromancer"], points: 0 },
{ name: "Curse", classes: ["Necromancer"], points: 0 },
{ name: "Life Drain", classes: ["Necromancer"], points: 0 },
{ name: "Plague", classes: ["Necromancer"], points: 0 },
{ name: "Undead Minions", classes: ["Necromancer"], points: 0 },
// Druid skills
{ name: "Shapeshift", classes: ["Druid"], points: 0 },
{ name: "Nature's Grasp", classes: ["Druid"], points: 0 },
{ name: "Regrowth", classes: ["Druid"], points: 0 },
{ name: "Earthquake", classes: ["Druid"], points: 0 },
{ name: "Animal Companionship", classes: ["Druid"], points: 0 },
{ name: "Thorn Armor", classes: ["Druid"], points: 0 },
{ name: "Wind Whisper", classes: ["Druid"], points: 0 },
{ name: "Moonfire", classes: ["Druid"], points: 0 },
// Bard skills
{ name: "Song of Courage", classes: ["Bard"], points: 0 },
{ name: "Inspire", classes: ["Bard"], points: 0 },
{ name: "Lullaby", classes: ["Bard"], points: 0 },
{ name: "Battle Hymn", classes: ["Bard"], points: 0 },
{ name: "Dance of Blades", classes: ["Bard"], points: 0 },
{ name: "Epic Tale", classes: ["Bard"], points: 0 },
{ name: "Harmony", classes: ["Bard"], points: 0 },
{ name: "Dissonance", classes: ["Bard"], points: 0 },
// Monk skills
{ name: "Fist of Fury", classes: ["Monk"], points: 0 },
{ name: "Chi Focus", classes: ["Monk"], points: 0 },
{ name: "Meditative Stance", classes: ["Monk"], points: 0 },
{ name: "Pressure Point", classes: ["Monk"], points: 0 },
{ name: "Inner Peace", classes: ["Monk"], points: 0 },
{ name: "Swift Strike", classes: ["Monk"], points: 0 },
{ name: "Mystic Barrier", classes: ["Monk"], points: 0 },
{ name: "Spiritual Healing", classes: ["Monk"], points: 0 },
// Sorcerer skills
{ name: "Fireball", classes: ["Sorcerer"], points: 0 },
{ name: "Ice Shard", classes: ["Sorcerer"], points: 0 },
{ name: "Lightning Bolt", classes: ["Sorcerer"], points: 0 },
{ name: "Arcane Blast", classes: ["Sorcerer"], points: 0 },
{ name: "Mystic Shield", classes: ["Sorcerer"], points: 0 },
{ name: "Spell Weaving", classes: ["Sorcerer"], points: 0 },
{ name: "Mana Surge", classes: ["Sorcerer"], points: 0 },
{ name: "Summon Elemental", classes: ["Sorcerer"], points: 0 },
// Assassin skills
{ name: "Shadow Strike", classes: ["Assassin"], points: 0 },
{ name: "Vanish", classes: ["Assassin"], points: 0 },
{ name: "Critical Hit", classes: ["Assassin"], points: 0 },
{ name: "Silent Step", classes: ["Assassin"], points: 0 },
{ name: "Death Mark", classes: ["Assassin"], points: 0 },
{ name: "Poison Blade", classes: ["Assassin"], points: 0 },
{ name: "Night Vision", classes: ["Assassin"], points: 0 },
{ name: "Trap Disarm", classes: ["Assassin"], points: 0 },
// Ranger skills
{ name: "Precision Shot", classes: ["Ranger"], points: 0 },
{ name: "Forest Knowledge", classes: ["Ranger"], points: 0 },
{ name: "Animal Taming", classes: ["Ranger"], points: 0 },
{ name: "Natural Camouflage", classes: ["Ranger"], points: 0 },
{ name: "Bow Mastery", classes: ["Ranger"], points: 0 },
{ name: "Trap Expertise", classes: ["Ranger"], points: 0 },
{ name: "Survival Instinct", classes: ["Ranger"], points: 0 },
{ name: "Tracking Sense", classes: ["Ranger"], points: 0 }
];
var uniqueSkills = [
{
name: "Dragon Slayer",
description: "Increases damage to dragons by 50%",
rarity: "unique"
},
{
name: "Ethereal Form",
description: "Allows passing through objects",
rarity: "rare"
},
{
name: "Phoenix Rebirth",
description: "Revives once upon death",
rarity: "legendary"
},
{
name: "Shadow Strike",
description: "Deals 200% damage when attacking from stealth",
rarity: "unique"
},
{
name: "Arcane Shield",
description: "Absorbs all damage for 5 seconds",
rarity: "rare"
},
{
name: "Vampiric Touch",
description: "Drains life from enemy, healing you for 50% of the damage dealt",
rarity: "rare"
},
{
name: "Celestial Guidance",
description: "Grants a chance to avoid all damage from an attack",
rarity: "legendary"
},
{
name: "Berserker Rage",
description: "Increases attack speed and damage by 30% for 10 seconds",
rarity: "unique"
},
{
name: "Mana Surge",
description: "Instantly restores 50% of maximum mana",
rarity: "rare"
},
{
name: "Spirit Bond",
description: "Links your spirit to an ally, sharing health between you",
rarity: "legendary"
},
{
name: "Frozen Heart",
description: "Reduces all incoming damage by 20%",
rarity: "unique"
},
{
name: "Lightning Reflexes",
description: "Dodges the next incoming attack",
rarity: "rare"
},
{
name: "Blessing of the Ancients",
description: "Increases all attributes by 10% for 1 hour",
rarity: "legendary"
},
{
name: "Necromancer's Call",
description: "Summons a powerful undead minion to fight for you",
rarity: "unique"
},
{
name: "Astral Projection",
description: "Allows you to explore areas without your physical body",
rarity: "rare"
},
{
name: "Temporal Mastery",
description: "Slows down time for everyone except you for 5 seconds",
rarity: "legendary"
},
{
name: "Inferno Blast",
description: "Deals massive fire damage to all enemies in a large area",
rarity: "unique"
},
{
name: "Healing Light",
description: "Heals you and nearby allies for a significant amount",
rarity: "rare"
},
{
name: "Guardian's Oath",
description: "Reduces damage taken by allies within 10 meters by 20%",
rarity: "legendary"
},
{
name: "Soul Reaper",
description: "Steals a portion of enemy's life force upon hit",
rarity: "unique"
},
{
name: "Chrono Shift",
description: "Reverses the flow of time for 3 seconds, resetting your cooldowns",
rarity: "legendary"
},
{
name: "Divine Intervention",
description: "Automatically revives you with full health once per battle",
rarity: "legendary"
},
{
name: "Shadowmeld",
description: "Becomes invisible to enemies for 10 seconds or until you attack",
rarity: "rare"
},
{
name: "Ethereal Blade",
description: "Summons a ghostly sword that deals extra damage for 15 seconds",
rarity: "unique"
},
{
name: "Mirror Image",
description: "Creates illusions that distract enemies for 20 seconds",
rarity: "rare"
},
{
name: "Wrath of the Titans",
description: "Triples damage dealt for the next 3 attacks",
rarity: "unique"
},
{
name: "Dimensional Rift",
description: "Opens a portal to another realm, stunning nearby enemies",
rarity: "rare"
},
{
name: "Blood Pact",
description: "Sacrifices health to greatly increase damage output for 30 seconds",
rarity: "unique"
},
{
name: "Fury of the Storm",
description: "Summons a powerful storm that damages all enemies over time",
rarity: "legendary"
},
{
name: "Spectral Cloak",
description: "Becomes intangible and immune to damage for 5 seconds",
rarity: "rare"
},
{
name: "Eternal Flame",
description: "Permanently increases fire damage dealt by 20%",
rarity: "unique"
}
];
var enemies = [
{ name: "Rat", health: 5, damage: 5, xpReward: 1 },
{ name: "Wild wolf", health: 15, damage: 15, xpReward: 20 },
{ name: "Duck", health: 5, damage: 5, xpReward: 1 },
{ name: "Chicken", health: 5, damage: 5, xpReward: 1 },
{ name: "Wild boar", health: 20, damage: 10, xpReward: 15 },
{ name: "Goblin", health: 30, damage: 10, xpReward: 10 },
{ name: "Orc", health: 50, damage: 20, xpReward: 25 },
{ name: "Dragon", health: 100, damage: 40, xpReward: 100 },
{ name: "Zombie", health: 20, damage: 8, xpReward: 15 },
{ name: "Vampire", health: 60, damage: 25, xpReward: 30 },
{ name: "Skeleton", health: 10, damage: 10, xpReward: 5 },
{ name: "Giant Spider", health: 40, damage: 20, xpReward: 20 },
{ name: "Troll", health: 80, damage: 30, xpReward: 50 },
{ name: "Hydra", health: 150, damage: 50, xpReward: 150 },
{ name: "Necromancer", health: 70, damage: 35, xpReward: 70 },
{ name: "Bandit", health: 25, damage: 15, xpReward: 10 },
{ name: "Witch", health: 45, damage: 30, xpReward: 25 },
{ name: "Elemental", health: 90, damage: 45, xpReward: 80 },
{ name: "Dark Knight", health: 120, damage: 50, xpReward: 90 },
{ name: "Ghost", health: 30, damage: 20, xpReward: 20 },
{ name: "Minotaur", health: 100, damage: 55, xpReward: 110 },
{ name: "Demon", health: 200, damage: 70, xpReward: 200 },
{ name: "Phoenix", health: 150, damage: 60, xpReward: 150 },
{ name: "Giant", health: 180, damage: 65, xpReward: 180 },
{ name: "Lich", health: 130, damage: 55, xpReward: 130 },
{ name: "Banshee", health: 50, damage: 30, xpReward: 50 },
{ name: "Golem", health: 200, damage: 60, xpReward: 190 },
{ name: "Manticore", health: 170, damage: 65, xpReward: 170 },
{ name: "Cyclops", health: 140, damage: 50, xpReward: 140 },
{ name: "Harpy", health: 70, damage: 35, xpReward: 70 },
{ name: "Satyr", health: 60, damage: 30, xpReward: 60 },
{ name: "Chimera", health: 160, damage: 70, xpReward: 160 },
{ name: "Kraken", health: 250, damage: 80, xpReward: 250 },
{ name: "Medusa", health: 120, damage: 45, xpReward: 120 },
{ name: "Griffin", health: 130, damage: 55, xpReward: 130 },
{ name: "Werewolf", health: 100, damage: 50, xpReward: 100 },
{ name: "Ogre", health: 150, damage: 60, xpReward: 150 },
{ name: "Treant", health: 140, damage: 50, xpReward: 140 },
{ name: "Wyvern", health: 160, damage: 70, xpReward: 160 },
{ name: "Basilisk", health: 110, damage: 45, xpReward: 110 },
{ name: "Behemoth", health: 220, damage: 75, xpReward: 220 },
{ name: "Djinn", health: 130, damage: 55, xpReward: 130 },
{ name: "Wraith", health: 90, damage: 40, xpReward: 90 },
{ name: "Naga", health: 120, damage: 50, xpReward: 120 },
{ name: "Yeti", health: 150, damage: 60, xpReward: 150 },
{ name: "Sea Serpent", health: 200, damage: 70, xpReward: 200 },
{ name: "Gargoyle", health: 100, damage: 45, xpReward: 100 },
{ name: "Mummy", health: 80, damage: 35, xpReward: 80 },
{ name: "Imp", health: 40, damage: 20, xpReward: 40 },
{ name: "Gremlin", health: 60, damage: 25, xpReward: 60 },
{ name: "Shadow", health: 90, damage: 40, xpReward: 90 },
{ name: "Wendigo", health: 180, damage: 70, xpReward: 180 }
];
var GamificationPlugin = class extends import_obsidian.Plugin {
constructor() {
super(...arguments);
this.statusBarEl = null;
}
async updateStatusBar() {
if (this.statusBarEl) {
this.statusBarEl.setText(
`XP: ${this.data.xp}, Level: ${this.data.level}, Words: ${this.data.totalWords}`
);
console.log("updated points");
} else {
"No status bar was detected";
}
}
async addStatusBar() {
this.statusBarEl = this.addStatusBarItem();
await this.updateStatusBar();
}
async onload() {
console.log("Loading Gamification Plugin");
await this.loadSettings();
await this.addStatusBar();
await this.updateStatusBar();
this.addCommand({
id: "reset-streak",
name: "Reset Streak",
callback: () => this.resetStreak()
});
this.addCommand({
id: "choose-class",
name: "Choose Class",
callback: () => this.chooseClass()
});
this.addSettingTab(new GamificationSettingTab(this.app, this));
this.registerEvent(
this.app.workspace.on("editor-change", this.updateWordCount.bind(this))
);
}
onunload() {
console.log("Unloading Gamification Plugin");
}
async loadSettings() {
this.data = Object.assign(
{
streak: 0,
lastDate: "",
xp: 0,
level: 1,
health: 100,
class: "",
skills: {},
totalWords: 0
},
await this.loadData()
);
}
async saveSettings() {
await this.saveData(this.data);
}
async updateStreak() {
const today = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
if (this.data.lastDate !== today) {
if (this.data.lastDate === await this.yesterday().then((data) => {
return data;
})) {
this.data.streak++;
} else {
this.data.streak = 1;
}
this.data.lastDate = today;
await this.saveSettings();
}
}
async resetStreak() {
this.data.streak = 0;
this.data.lastDate = "";
await this.saveSettings();
await this.addStatusBarItem().setText("Streak: 0 days");
}
async yesterday() {
const yesterday = /* @__PURE__ */ new Date();
yesterday.setDate(yesterday.getDate() - 1);
return yesterday.toISOString().split("T")[0];
}
async chooseClass() {
const className = classes[Math.floor(Math.random() * classes.length)];
this.data.class = className;
this.data.skills = {};
skills.filter((skill) => skill.classes.includes(className)).forEach((skill) => {
if (!this.data.skills[skill.name]) {
this.data.skills[skill.name] = 0;
} else {
this.data.skills[skill.name] = this.data.skills[skill.name];
}
});
await this.saveSettings();
new import_obsidian.Notice(`You have chosen the ${className} class!`);
}
async triggerRandomEvent() {
const events = [
{ type: "gain_xp", amount: Math.floor(Math.random() * 50) + 10 },
{ type: "lose_health", amount: Math.floor(Math.random() * 20) + 5 },
{ type: "gain_health", amount: Math.floor(Math.random() * 20) + 5 },
{ type: "enemy_encounter" }
];
const event = events[Math.floor(Math.random() * events.length)];
const points = event.amount;
if (points !== void 0) {
if (event.type === "gain_xp") {
await this.enemyEncounter();
} else if (event.type === "lose_health") {
await this.enemyEncounter();
this.data.health -= points;
if (this.data.health < 0) this.data.health = 0;
new import_obsidian.Notice(`You lost ${event.amount} health!`);
} else if (event.type === "gain_health") {
this.data.health += points;
if (this.data.health > 100) this.data.health = 100;
new import_obsidian.Notice(`You gained ${event.amount} health!`);
} else if (event.type === "enemy_encounter") {
await this.enemyEncounter();
}
}
}
async enemyEncounter() {
const enemy = enemies[Math.floor(Math.random() * enemies.length)];
new import_obsidian.Notice(`An enemy ${enemy.name} appeared!`);
const playerDamage = Math.floor(Math.random() * 20) + 5;
enemy.health -= playerDamage;
this.data.health -= enemy.damage;
if (this.data.health < 0) this.data.health = 0;
if (enemy.health <= 0) {
new import_obsidian.Notice(
`You defeated the ${enemy.name} and gained ${enemy.xpReward} XP!`
);
await this.gainXP(enemy.xpReward);
await this.attemptToGainUniqueSkill();
} else {
new import_obsidian.Notice(
`The ${enemy.name} attacked you and you lost ${enemy.damage} health!`
);
}
await this.saveSettings();
}
async attemptToGainUniqueSkill() {
const chance = Math.random();
if (chance < 0.05) {
const uniqueSkill = uniqueSkills[Math.floor(Math.random() * uniqueSkills.length)];
if (!this.data.skills[uniqueSkill.name]) {
this.data.skills[uniqueSkill.name] = 1;
new import_obsidian.Notice(
`You have acquired a rare skill: ${uniqueSkill.name}! ${uniqueSkill.description}`
);
}
}
}
async updateWordCount() {
const activeLeaf = this.app.workspace.activeLeaf;
if (activeLeaf && activeLeaf.view instanceof import_obsidian.MarkdownView) {
const editor = activeLeaf.view.editor;
const wordCount = await this.countWords(editor.getValue()).then(
(wordCount2) => {
return wordCount2;
}
);
const newWords = wordCount - this.data.totalWords;
if (newWords > 0) {
this.data.totalWords = wordCount;
await this.updateStatusBar();
if (wordCount > 50) {
await this.triggerRandomEvent();
await this.saveSettings();
} else if (wordCount > 150) {
await this.gainXP(newWords);
await this.triggerRandomEvent();
await this.saveSettings();
}
}
}
}
async countWords(text) {
return text.split(/\s+/).filter((word) => word.length > 0).length;
}
async gainXP(amount) {
this.data.xp += amount;
const requiredXP = this.calculateRequiredXP().then((xpAmount) => {
return xpAmount;
});
if (this.data.xp >= await requiredXP) {
this.data.level++;
this.data.xp -= await requiredXP;
const className = classes[Math.floor(Math.random() * classes.length)];
this.data.skills = {};
if (this.data !== void 0) {
this.data.class = className;
skills.filter((skill) => skill.classes.includes(className)).forEach((skill) => {
let randomNum = Math.round(Math.random());
if (randomNum == 1) {
skill.points = skill.points + 1;
new import_obsidian.Notice(`Congratulations! ${skill.name} points were updated`);
}
});
await this.saveSettings();
new import_obsidian.Notice(`Congratulations! You've reached level ${this.data.level}`);
}
} else {
new import_obsidian.Notice(`You gained ${amount} XP!`);
}
}
async calculateRequiredXP() {
return 100 * Math.pow(1.1, this.data.level - 1);
}
};
var GamificationSettingTab = class extends import_obsidian.PluginSettingTab {
constructor(app, plugin) {
super(app, plugin);
}
async display() {
let { containerEl } = this;
containerEl.empty();
containerEl.createEl("h2", { text: "Settings for Gamification Plugin" });
let classValue;
new import_obsidian.Setting(containerEl).setName("Class").setDesc("Choose your class").addDropdown(async (drop) => {
classes.forEach((className) => drop.addOption(className, className));
drop.setValue(this.plugin.data.class);
drop.onChange(async (value) => {
this.plugin.data.class = value;
classValue = value;
this.plugin.data.skills = {};
skills.filter((skill) => skill.classes.includes(value)).forEach((skill) => {
this.plugin.data.skills[skill.name] = skill.points;
});
await this.plugin.saveSettings().then(async () => {
await this.display();
});
});
});
if (this.plugin.data.skills !== null && String(this.plugin.data.skills) !== "undefined") {
Object.keys(this.plugin.data.skills).forEach((skill) => {
new import_obsidian.Setting(containerEl).setName(skill).setDesc(`Skill level for ${skill}`).addText(
(text) => text.setValue(`${this.plugin.data.skills[skill]}`)
);
});
}
}
};