2016-04-05 01:10:40 +02:00
|
|
|
var Game = {};
|
|
|
|
G = Game;
|
|
|
|
|
2016-04-06 01:33:38 +02:00
|
|
|
G.player = {}; // Just a reference until G.player is created at rm_Ocean's load time.
|
|
|
|
G.oceanParticle = {}; // One ocean particle will exist at any time and move around the boat.
|
|
|
|
G.map = []; // List of island objects, generated/loaded and saved at game start, loaded on room start.
|
2016-04-08 02:17:45 +02:00
|
|
|
G.currentScreen = ""; // For pause screen, stats screen, inventory screen
|
|
|
|
G.inventory = {
|
2016-04-06 22:41:40 +02:00
|
|
|
money: 100,
|
2016-04-08 22:39:12 +02:00
|
|
|
supplies: 20, // How much stuff you have to maintain your crew's illness with.
|
2016-04-12 00:22:56 +02:00
|
|
|
cargo: [0, 0, 0, 0, // Keeps track of how much of each item you have.
|
|
|
|
0, 0, 0, 0, // Requires a check to make sure you can't buy more different kinds than you can hold.
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0],
|
2016-04-12 18:02:27 +02:00
|
|
|
moneyDisplay: function () {
|
|
|
|
var moneyString = "";
|
|
|
|
if (G.inventory.money >= 1000000) {
|
|
|
|
moneyString = G.inventory.money.toString().substr(0, 1);
|
|
|
|
if (parseInt(G.inventory.money.toString().substr(1, 1)) > 0) {
|
|
|
|
moneyString += "." + G.inventory.money.toString().substr(1, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (G.inventory.money >= 1000000000000) {
|
|
|
|
moneyString += "T";
|
|
|
|
} else if (G.inventory.money >= 1000000000) {
|
|
|
|
moneyString += "B";
|
|
|
|
} else if (G.inventory.money >= 1000000) {
|
|
|
|
moneyString += "M";
|
|
|
|
} else {
|
|
|
|
moneyString = G.inventory.money.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
return moneyString;
|
|
|
|
},
|
2016-04-12 00:22:56 +02:00
|
|
|
CheckCargo: function () { // Returns an array of indices that have cargo
|
|
|
|
var indicesWithCargo = [];
|
|
|
|
for (var i = 0; i < G.inventory.cargo.length; i++) {
|
|
|
|
if (G.inventory.cargo[i] > 0) {
|
|
|
|
indicesWithCargo.push(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return indicesWithCargo;
|
|
|
|
},
|
|
|
|
CargoTotal: function () {
|
|
|
|
var cargo = G.inventory.CheckCargo();
|
|
|
|
var cargoTotal = 0;
|
|
|
|
for (var i = 0; i < cargo.length; i++) {
|
|
|
|
cargoTotal += G.inventory.cargo[cargo[i]];
|
|
|
|
}
|
|
|
|
return cargoTotal;
|
2016-04-14 00:49:32 +02:00
|
|
|
},
|
|
|
|
CanBuy: function (itemIndex, price) {
|
|
|
|
if (G.inventory.cargo[itemIndex] < G.stats.hold && G.inventory.money > price &&
|
|
|
|
(G.inventory.cargo[itemIndex] > 0 || G.inventory.CheckCargo().length < G.stats.inventory))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
CanSell: function (itemIndex) {
|
|
|
|
return G.inventory.cargo[itemIndex] > 0;
|
2016-04-12 00:22:56 +02:00
|
|
|
}
|
2016-04-08 02:17:45 +02:00
|
|
|
};
|
|
|
|
G.stats = {
|
2016-04-12 00:22:56 +02:00
|
|
|
inventory: 3, // Maximum number of different things the cargo can hold.
|
2016-04-07 20:26:58 +02:00
|
|
|
hold: 20, // Maximum number of each individual kind of thing in the inventory.
|
2016-04-08 02:17:45 +02:00
|
|
|
speed: 1, // How many pixels you move.
|
|
|
|
hull: 3, // Your HP, pretty much. How many times you can crash without exploding.
|
|
|
|
maxHull: 3, // How much your hull can refill to.
|
2016-04-14 02:06:45 +02:00
|
|
|
popularity: 5, // Haggle success rate in percentage.
|
2016-04-08 02:17:45 +02:00
|
|
|
haggling: 10, // How much you can increase the asking price by.
|
|
|
|
crew: 2, // How many crew members you have. Influences how fast your energy recovers.
|
|
|
|
energy: 25, // Drains rate determined by current speed. When drained, currentSpeed reduces until you have enough energy to continue.
|
|
|
|
maxEnergy: 50, // How much to refill your energy to. Can increase with upgrades.
|
2016-04-12 00:30:39 +02:00
|
|
|
illness: 0 // Your crew's overall health. When this is low, your ship slows down.
|
2016-04-12 00:22:56 +02:00
|
|
|
};
|
2016-04-08 02:17:45 +02:00
|
|
|
|
|
|
|
G.economy = { // Aww yea, supply and demand.
|
|
|
|
// Items are determined by their index, and their position on the sheet determines their index.
|
|
|
|
// So the second item on the top row is index 1, and to get its value, you get `G.economy.cargoItemWorth[1]`
|
2016-04-16 07:15:38 +02:00
|
|
|
innCost: 50,
|
|
|
|
innStays: 0,
|
|
|
|
cargoItemWorth: [10, 20, 30, 30, //Can be adjusted based on sales.
|
|
|
|
40, 20, 50, 80,
|
|
|
|
65, 20, 20, 30,
|
|
|
|
30, 60, 45, 70],
|
|
|
|
cargoSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0],
|
|
|
|
cargoBought: [0, 0, 0, 0, // The more you buy, the higher the price gets
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0],
|
2016-04-14 23:02:12 +02:00
|
|
|
UpdateEconomy: function () {
|
|
|
|
// console.log(G.economy.cargoItemWorth);
|
2016-04-14 07:33:42 +02:00
|
|
|
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
|
|
|
|
var totalPriceDifference = 0;
|
|
|
|
for (var m = 0; m < G.map.length; m++) {
|
2016-04-14 23:02:12 +02:00
|
|
|
// console.log("map: " + G.map[m].island);
|
|
|
|
totalPriceDifference += G.map[m].island.priceDifferences[i];
|
|
|
|
// console.log(G.map[m].island.priceDifferences[i]);
|
2016-04-08 02:17:45 +02:00
|
|
|
}
|
2016-04-14 07:33:42 +02:00
|
|
|
G.economy.cargoItemWorth[i] += Math.round(totalPriceDifference / G.map.length); // Apply the average price difference for the item.
|
2016-04-08 02:17:45 +02:00
|
|
|
}
|
2016-04-16 07:15:38 +02:00
|
|
|
var totalInnCost = 0;
|
|
|
|
for (var m = 0; m < G.map.length; m++) {
|
|
|
|
totalInnCost += G.map[m].island.innPriceDifference;
|
|
|
|
}
|
|
|
|
G.economy.innCost += Math.round(totalInnCost / G.map.length); // Apply the average inn price.
|
2016-04-14 23:02:12 +02:00
|
|
|
// console.log(G.economy.cargoItemWorth);
|
2016-04-08 02:17:45 +02:00
|
|
|
}
|
2016-04-12 00:22:56 +02:00
|
|
|
};
|
2016-04-08 02:17:45 +02:00
|
|
|
|
2016-04-14 07:33:42 +02:00
|
|
|
function loadGameManager () {
|
|
|
|
for (var i = 0; i < G.economy.cargoItemWorth.length; i++) {
|
|
|
|
G.economy.cargoItemWorth[i] += Math.round(Math.randomRange(-5, 5));
|
|
|
|
}
|
|
|
|
}
|