Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function AbstractUpgrade(name, price = 0, requiredUpgrades = new Array()) {
- this.name = name;
- this.price = price;
- this.requiredUpgrades = requiredUpgrades;
- this.lock = true;
- this.unlock = function() {
- // Vérifie si le joueur dispose de la somme nécessaire pour débloquer cette amélioration
- if (game.getPlayer().getBalance() < price) {
- return;
- }
- // Vérifie si toutes les améliorations nécessaires ont été débloquées
- for (var i = 0; i < requiredUpgrades.length; i++) {
- if (requiredUpgrades[i].isLocked()) {
- return;
- }
- }
- this.doAction();
- this.lock = false;
- }
- this.doAction = function() {
- // à redéfinir
- }
- this.getName = function() {
- return this.name;
- }
- this.isLocked = function() {
- return this.lock;
- }
- }
- /* Objets héritant de AbstractUpgrade */
- function EnrollmentUpgrade() {}
- function BluePrintUpgrade() {}
- function KnowledgeTransferUpgrade() {}
- function SuperPumpUpgrade() {
- this.doAction = function() {
- game.getPlayer().setCurrentProduction(2);
- }
- }
- function MegaPumpUpgrade() {
- this.doAction = function() {
- game.getPlayer().setCurrentProduction(5);
- }
- }
- function GigaPumpUpgrade() {
- this.doAction = function() {
- game.getPlayer().setCurrentProduction(10);
- }
- }
- /* Prototyping */
- EnrollmentUpgrade.prototype = new AbstractUpgrade();
- BluePrintUpgrade.prototype = new AbstractUpgrade();
- KnowledgeTransferUpgrade.prototype = new AbstractUpgrade();
- SuperPumpUpgrade.prototype = new AbstractUpgrade();
- MegaPumpUpgrade.prototype = new AbstractUpgrade();
- GigaPumpUpgrade.prototype = new AbstractUpgrade();
- /* Initialisation */
- var enrollmentUpgrade = new EnrollmentUpgrade("upgrade_enrollment", 20);
- var bluePrintUpgrade = new BluePrintUpgrade("upgrade_blue_print", 200);
- var knowledgeTransferUpgrade = new KnowledgeTransferUpgrade("upgrade_knowledge_transfer", 2000);
- var superPumpUpgrade = new SuperPumpUpgrade("upgrade_super_pump", 100);
- var megaPumpUpgrade = new MegaPumpUpgrade("upgrade_mega_pump", 1000, [superPumpUpgrade]);
- var gigaPumpUpgrade = new GigaPumpUpgrade("upgrade_giga_pump", 10000 [megaPumpUpgrade]);
- const UPGRADES = [enrollmentUpgrade, bluePrintUpgrade, knowledgeTransferUpgrade, superPumpUpgrade, megaPumpUpgrade, gigaPumpUpgrade];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement