diff --git a/models/game/data/events.json b/models/game/data/events.json index 9f0d269..2fed710 100644 --- a/models/game/data/events.json +++ b/models/game/data/events.json @@ -2,9 +2,6 @@ { "id": "item_bust", "type": "adjust_market", - "descriptions": [ - "The dogs have made a big bust on {{item}}! Prices are going through the roof." - ], "parameters": { "price": { "min": 1.50, @@ -19,9 +16,6 @@ { "id": "item_flood", "type": "adjust_market", - "descriptions": [ - "Cat dealers have flooded the market with cheap {{item}}. Prices have bottomed out." - ], "parameters": { "price": { "min": 0.10, @@ -36,10 +30,6 @@ { "id": "free_item", "type": "adjust_inventory", - "descriptions": [ - "You run into a cat at the airport. He shakes your hand, and slips you a few units of {{item}}. He smiles and walks off without saying anything.", - "You find a few units of {{item}} on the ground outside the airport!" - ], "parameters": { "units": { "min": 0.005, @@ -50,10 +40,6 @@ { "id": "free_cash", "type": "adjust_cash", - "descriptions": [ - "A cat hands you an envelope at the airport with your name on it. You look down to open the envelope and see ${{amount}}! When you look up to thank the stranger, they're gone.", - "You find ${{amount}} on the ground outside the airport!" - ], "parameters": { "amount": { "min": 0.50, diff --git a/models/game/data/localization/en_US.js b/models/game/data/localization/en_US.js index 552ee05..51f6a88 100644 --- a/models/game/data/localization/en_US.js +++ b/models/game/data/localization/en_US.js @@ -19,6 +19,40 @@ module.exports = { if (data === true) { return phrases; } return phrases[common.getRandomInt(0, phrases.length - 1)]; }, + // includes adjustment and flag to dump phrases for testing + event_item_bust: (data) => { + const phrases = [ + `The dogs have made a big bust on ${data.item.name}! Prices are going through the roof.` + ]; + if (data.all) { return phrases; } + return phrases[common.getRandomInt(0, phrases.length - 1)]; + }, + // includes adjustment and flag to dump phrases for testing + event_item_flood: (data) => { + const phrases = [ + `Cat dealers have flooded the market with cheap ${data.item.name}. Prices have bottomed out.` + ]; + if (data.all) { return phrases; } + return phrases[common.getRandomInt(0, phrases.length - 1)]; + }, + // includes adjustment and flag to dump phrases for testing + event_free_item: (data) => { + const phrases = [ + `You run into a cat at the airport. He shakes your hand, and slips you a few units of ${data.item.name}. He smiles and walks off without saying anything.`, + `You find a few units of ${data.item.name} on the ground outside the airport!` + ]; + if (data.all) { return phrases; } + return phrases[common.getRandomInt(0, phrases.length - 1)]; + }, + // includes adjustment and flag to dump phrases for testing + event_free_cash: (data) => { + const phrases = [ + `A cat hands you an envelope at the airport with your name on it. You look down to open the envelope and see ${data.total}! When you look up to thank the stranger, they're gone.`, + `You find ${data.total} on the ground outside the airport!` + ]; + if (data.all) { return phrases; } + return phrases[common.getRandomInt(0, phrases.length - 1)]; + }, // receives an array of countries and their awareness of the player obituary_heat_some: (data) => { const phrases = [ diff --git a/models/game/events.js b/models/game/events.js index 3b91fe8..af39903 100644 --- a/models/game/events.js +++ b/models/game/events.js @@ -56,11 +56,12 @@ module.exports.simulateEvents = function simulateEvents(life, eventObj) { type: eventObj.type, amount: common.getRandomArbitrary(eventObj.parameters.amount.min, eventObj.parameters.amount.max) }; + adjustment.total = Math.round(adjustment.amount * game.market.base_price); newLife = adjustCurrentCash(newLife, adjustment); break; } // write the description - newLife.current.event = makeDescription(eventObj, adjustment); + newLife.current.event = localization(`event_${eventObj.id}`, adjustment); // wipe meta if (newLife.current.event_meta) { delete newLife.current.event_meta; @@ -75,18 +76,6 @@ module.exports.simulateEvents = function simulateEvents(life, eventObj) { return newLife; }; -function makeDescription(eventObj, adjustment) { - // pick description - let description = eventObj.descriptions[common.getRandomInt(0, (eventObj.descriptions.length - 1))]; - if (description.indexOf("{{item}}") >= 0) { - description = description.replace(/\{\{item\}\}/g, adjustment.item.name); - } - if (description.indexOf("{{amount}}") >= 0) { - description = description.replace(/\{\{amount\}\}/g, Math.round(adjustment.amount * game.market.base_price)); - } - return description; -} - function adjustMarketListing(life, adjustment) { const newLife = JSON.parse(JSON.stringify(life)); // get the listing diff --git a/tests/05b-events-adjust-markets.js b/tests/05b-events-adjust-markets.js index 0ce886b..60a37ff 100644 --- a/tests/05b-events-adjust-markets.js +++ b/tests/05b-events-adjust-markets.js @@ -8,6 +8,7 @@ const common = main.common; const model = main.model; const events = main.events; +const localization = main.localization; let life; @@ -18,11 +19,8 @@ describe("Events - Simulation Validation (Adjust Markets)", () => { let newLife; let itemObj; const eventObj = { - id: "testing", + id: "item_bust", type: "adjust_market", - descriptions: [ - "This should have an item here -> {{item}}" - ], parameters: { price: { min: 1.50, @@ -58,7 +56,10 @@ describe("Events - Simulation Validation (Adjust Markets)", () => { it("event should update the current event", (done) => { expect(newLife.current.event).to.be.a("string"); - expect(newLife.current.event).to.equal(`This should have an item here -> ${itemObj.name}`); + expect(localization("event_item_bust", { + item: itemObj, + all: true + })).to.include(newLife.current.event); return done(); }); diff --git a/tests/05c-events-adjust-inventory.js b/tests/05c-events-adjust-inventory.js index d1510ce..a923fd3 100644 --- a/tests/05c-events-adjust-inventory.js +++ b/tests/05c-events-adjust-inventory.js @@ -8,6 +8,7 @@ const common = main.common; const model = main.model; const events = main.events; +const localization = main.localization; let life; @@ -19,11 +20,8 @@ describe("Events - Simulation Validation (Adjust Inventory)", () => { let newLife; let itemObj; const eventObj = { - id: "testing", + id: "free_item", type: "adjust_inventory", - descriptions: [ - "This should have an item here -> {{item}}" - ], parameters: { units: { min: 0.005, @@ -57,7 +55,10 @@ describe("Events - Simulation Validation (Adjust Inventory)", () => { it("event should update the current event", (done) => { expect(newLife.current.event).to.be.a("string"); - expect(newLife.current.event).to.equal(`This should have an item here -> ${itemObj.name}`); + expect(localization("event_free_item", { + item: itemObj, + all: true + })).to.include(newLife.current.event); return done(); }); @@ -115,7 +116,7 @@ describe("Events - Simulation Error Validation (Adjust Inventory)", () => { let oldLife; let newLife; const eventObj = { - id: "testing", + id: "free_item", type: "adjust_inventory", descriptions: [ "This should have an item here -> {{item}}" diff --git a/tests/05d-events-adjust-cash.js b/tests/05d-events-adjust-cash.js index 334dfc2..49e3e99 100644 --- a/tests/05d-events-adjust-cash.js +++ b/tests/05d-events-adjust-cash.js @@ -8,6 +8,7 @@ const common = main.common; const model = main.model; const events = main.events; +const localization = main.localization; let life; @@ -16,11 +17,8 @@ describe("Events - Simulation Validation (Adjust Cash)", () => { let newLife; let adjustmentAmount; const eventObj = { - id: "testing", + id: "free_cash", type: "adjust_cash", - descriptions: [ - "This should have an amount here -> {{amount}}" - ], parameters: { amount: { min: 0.50, @@ -48,7 +46,10 @@ describe("Events - Simulation Validation (Adjust Cash)", () => { it("event should update the current event", (done) => { const newCash = Math.round(adjustmentAmount * config.GAME.market.base_price); expect(newLife.current.event).to.be.a("string"); - expect(newLife.current.event).to.equal(`This should have an amount here -> ${newCash}`); + expect(localization("event_free_cash", { + total: newCash, + all: true + })).to.include(newLife.current.event); return done(); });