Skip to content

Commit

Permalink
extracted out event phrases, import them into localization system
Browse files Browse the repository at this point in the history
  • Loading branch information
snollygolly committed Jun 15, 2019
1 parent b10d54c commit a50d761
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 43 deletions.
14 changes: 0 additions & 14 deletions models/game/data/events.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
34 changes: 34 additions & 0 deletions models/game/data/localization/en_US.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
15 changes: 2 additions & 13 deletions models/game/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions tests/05b-events-adjust-markets.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const common = main.common;
const model = main.model;

const events = main.events;
const localization = main.localization;

let life;

Expand All @@ -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,
Expand Down Expand Up @@ -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();
});

Expand Down
13 changes: 7 additions & 6 deletions tests/05c-events-adjust-inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const common = main.common;
const model = main.model;

const events = main.events;
const localization = main.localization;

let life;

Expand All @@ -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,
Expand Down Expand Up @@ -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();
});

Expand Down Expand Up @@ -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}}"
Expand Down
11 changes: 6 additions & 5 deletions tests/05d-events-adjust-cash.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const common = main.common;
const model = main.model;

const events = main.events;
const localization = main.localization;

let life;

Expand All @@ -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,
Expand Down Expand Up @@ -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();
});

Expand Down

0 comments on commit a50d761

Please sign in to comment.