2016-04-07 21:19:22 +02:00
|
|
|
var ani_island_1 = OS.A.Add("Island 1", 256, 256, {});
|
|
|
|
|
2016-04-07 20:26:58 +02:00
|
|
|
function islandPrefab() {}
|
|
|
|
|
|
|
|
var pr_island = OS.P.Add("Island", {
|
|
|
|
solid: true,
|
2016-04-07 21:19:22 +02:00
|
|
|
imageSrc: "images/island.png",
|
2016-04-08 08:19:55 +02:00
|
|
|
animations: [ani_island_1],
|
2016-04-15 07:01:05 +02:00
|
|
|
depth: -50,
|
2016-04-08 08:19:55 +02:00
|
|
|
|
|
|
|
mapX: 0,
|
|
|
|
mapY: 0,
|
|
|
|
mapWidth: 1,
|
|
|
|
mapHeight: 1,
|
|
|
|
mapColor: "#00AB00",
|
|
|
|
|
2016-04-12 18:02:27 +02:00
|
|
|
canTrade: true,
|
2016-04-15 01:09:57 +02:00
|
|
|
haggleAmount: 0,
|
|
|
|
timesHaggledToday: 0,
|
2016-04-12 18:02:27 +02:00
|
|
|
|
2016-04-14 23:02:12 +02:00
|
|
|
inventory: [0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0],
|
2016-04-16 07:15:38 +02:00
|
|
|
innPriceDifference: 0,
|
|
|
|
innStays: 0,
|
2016-04-08 08:19:55 +02:00
|
|
|
priceDifferences: [],
|
|
|
|
itemsSold: [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],
|
|
|
|
itemsBought: [0, 0, 0, 0, // The more you buy, the higher the price gets
|
|
|
|
0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0,
|
2016-04-12 06:47:01 +02:00
|
|
|
0, 0, 0, 0]
|
2016-04-07 20:26:58 +02:00
|
|
|
});
|
2016-04-08 08:19:55 +02:00
|
|
|
|
|
|
|
pr_island.DoFirst = function () {
|
|
|
|
this.GetMapPosition();
|
2016-04-12 18:02:27 +02:00
|
|
|
this.SetUp();
|
2016-04-08 08:19:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pr_island.GetMapPosition = function () {
|
|
|
|
this.mapX = (this.x / OS.S.pixelScale) / (OS.camera.width / OS.S.pixelScale);
|
|
|
|
this.mapY = (this.y / OS.S.pixelScale) / (OS.camera.height / OS.S.pixelScale);
|
|
|
|
}
|
|
|
|
|
2016-04-12 06:47:01 +02:00
|
|
|
pr_island.SetUp = function () {
|
2016-04-14 00:49:32 +02:00
|
|
|
for (var i = 0; i < 16; i++) {
|
2016-04-14 01:56:52 +02:00
|
|
|
if (Math.randomRange(0, 100) < 25) {
|
|
|
|
this.inventory[i] = Math.round(Math.randomRange(0, 20));
|
|
|
|
}
|
|
|
|
}
|
2016-04-14 23:02:12 +02:00
|
|
|
// console.log(this.name + " stock: " + this.inventory);
|
2016-04-14 01:56:52 +02:00
|
|
|
|
|
|
|
this.AdjustPrices();
|
2016-04-14 23:02:12 +02:00
|
|
|
// console.log(this.name + " pricing: " + this.priceDifferences);
|
2016-04-14 01:56:52 +02:00
|
|
|
|
|
|
|
if (this.CheckInventory().length < 4) {
|
|
|
|
this.SetUp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_island.AdjustPrices = function () {
|
|
|
|
for (var i = 0; i < 16; i++) {
|
|
|
|
if (this.inventory[i] > 10) {
|
|
|
|
this.priceDifferences[i] = -Math.round(this.inventory[i] * Math.randomRange(1, 3));
|
|
|
|
} else if (this.inventory[i] < 5) {
|
2016-04-14 07:16:59 +02:00
|
|
|
this.priceDifferences[i] = Math.round((10 - this.inventory[i]) * Math.randomRange(1, 3));
|
2016-04-14 01:56:52 +02:00
|
|
|
} else {
|
2016-04-14 23:02:12 +02:00
|
|
|
this.priceDifferences[i] = Math.round(Math.randomRange(-2, 2));
|
2016-04-14 01:56:52 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 00:49:32 +02:00
|
|
|
if (G.economy.cargoItemWorth[i] + this.priceDifferences[i] < 0) {
|
2016-04-12 18:02:27 +02:00
|
|
|
this.priceDifferences[i] = -G.economy.cargoItemWorth[i] + 1;
|
|
|
|
}
|
2016-04-08 08:19:55 +02:00
|
|
|
}
|
2016-04-16 07:15:38 +02:00
|
|
|
|
|
|
|
var priceDifferencesOrdered = this.priceDifferences.slice().sort(sortNumber);
|
|
|
|
this.innPriceDifference += Math.round(Math.randomRange(priceDifferencesOrdered[0], priceDifferencesOrdered[priceDifferencesOrdered.length -1])) - Math.round(Math.randomRange(0, this.innStays));
|
2016-04-08 08:19:55 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 01:56:52 +02:00
|
|
|
pr_island.SimulateTrade = function () {
|
|
|
|
// This will be run on a timer that runs when not trading.
|
|
|
|
for (var i = 0; i < 16; i++) {
|
|
|
|
if (this.inventory[i] > 0) {
|
|
|
|
this.inventory[i] += Math.round(Math.randomRange(-5, 5));
|
|
|
|
if (this.inventory[i] < 0) {
|
|
|
|
this.inventory[i] = 0;
|
|
|
|
}
|
2016-04-08 08:19:55 +02:00
|
|
|
} else {
|
2016-04-14 01:56:52 +02:00
|
|
|
if (Math.randomRange(0, 100) < 15) {
|
|
|
|
this.inventory[i] = Math.round(Math.randomRange(0, 5));
|
|
|
|
}
|
2016-04-08 08:19:55 +02:00
|
|
|
}
|
|
|
|
}
|
2016-04-14 01:56:52 +02:00
|
|
|
|
|
|
|
this.AdjustPrices();
|
2016-04-08 08:19:55 +02:00
|
|
|
}
|
|
|
|
|
2016-04-16 07:15:38 +02:00
|
|
|
pr_island.NewDay = function () {
|
|
|
|
this.haggleAmount = 0;
|
|
|
|
this.timesHaggledToday = 0;
|
|
|
|
this.SimulateTrade();
|
|
|
|
}
|
|
|
|
|
2016-04-12 18:02:27 +02:00
|
|
|
pr_island.CheckInventory = function () { // Returns an array of indices that have cargo
|
|
|
|
var indicesWithCargo = [];
|
2016-04-14 00:49:32 +02:00
|
|
|
for (var i = 0; i < this.inventory.length; i++) {
|
2016-04-12 18:02:27 +02:00
|
|
|
if (this.inventory[i] > 0) {
|
|
|
|
indicesWithCargo.push(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return indicesWithCargo;
|
|
|
|
}
|
|
|
|
|
|
|
|
pr_island.TradeWith = function () {
|
2016-04-13 02:14:09 +02:00
|
|
|
// Change music to Trade.
|
2016-04-14 23:02:12 +02:00
|
|
|
// console.log(this.inventory);
|
2016-04-16 23:43:39 +02:00
|
|
|
mus_sail.Stop();
|
|
|
|
mus_trade.Play();
|
2016-04-14 23:02:12 +02:00
|
|
|
guiControl.trade.island = this;
|
2016-04-14 00:49:32 +02:00
|
|
|
guiControl.trade.haggleAmount = 0;
|
2016-04-12 18:02:27 +02:00
|
|
|
guiControl.trade.activateDelay = 5;
|
|
|
|
guiControl.trade.show = true;
|
|
|
|
}
|
|
|
|
|
2016-04-14 00:49:32 +02:00
|
|
|
pr_island.SellTo = function (itemIndex, price) {
|
2016-04-13 02:14:09 +02:00
|
|
|
// Play Buy sound.
|
2016-04-14 00:49:32 +02:00
|
|
|
this.inventory[itemIndex]++;
|
|
|
|
this.itemsBought[itemIndex]++;
|
2016-04-14 01:56:52 +02:00
|
|
|
|
2016-04-14 00:49:32 +02:00
|
|
|
G.inventory.cargo[itemIndex]--;
|
|
|
|
G.inventory.money += price;
|
2016-04-14 07:33:42 +02:00
|
|
|
G.economy.cargoSold[itemIndex]++;
|
2016-04-08 08:19:55 +02:00
|
|
|
}
|
|
|
|
|
2016-04-14 00:49:32 +02:00
|
|
|
pr_island.BuyFrom = function (itemIndex, price) {
|
2016-04-13 02:14:09 +02:00
|
|
|
// Play Sell sound.
|
2016-04-14 00:49:32 +02:00
|
|
|
this.inventory[itemIndex]--;
|
|
|
|
this.itemsBought[itemIndex]++;
|
|
|
|
|
|
|
|
G.inventory.cargo[itemIndex]++;
|
|
|
|
G.inventory.money -= price;
|
2016-04-14 07:33:42 +02:00
|
|
|
G.economy.cargoBought[itemIndex]++;
|
2016-04-08 08:19:55 +02:00
|
|
|
}
|
2016-04-16 07:15:38 +02:00
|
|
|
|
|
|
|
pr_island.StayAtInn = function () {
|
|
|
|
// Play Sell sound.
|
|
|
|
this.innStays++;
|
|
|
|
|
|
|
|
G.stats.illness--;
|
|
|
|
G.inventory.money -= G.economy.innCost + this.innPriceDifference;
|
|
|
|
G.economy.innStays++;
|
|
|
|
}
|