Started working on balancing the economy and limiting sales/purchases. Still needs work.

This commit is contained in:
Robbie Antenesse 2016-04-26 18:03:47 -06:00
parent 98a02a38ac
commit 62524d8693
4 changed files with 64 additions and 17 deletions

View File

@ -170,7 +170,7 @@ guiControl.trade.Draw = function () {
}
// Amounts
guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, "black", 4);
guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, (guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow", 4);
guiControl.drawPixelText("Own " + G.inventory.cargo[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(3) - pixel(6) + pixel(), 4, (G.inventory.cargo[items[guiControl.trade.page]] < G.stats.hold) ? "black" : "yellow", 4);
} else {
guiControl.drawPixelText("Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
@ -181,8 +181,8 @@ guiControl.trade.Draw = function () {
guiControl.drawPixelText(G.inventory.CheckCargo().length.toString(), OS.camera.width - pixel(20) + (guiControl.iconScaled + pixel()), guiControl.trade.rowTop(4) - pixel(4), 4, (G.inventory.CheckCargo().length < G.stats.inventory) ? "black" : "yellow", 6);
// Yes/No Options
guiControl.drawPixelText("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6);
guiControl.drawPixelText("Yes", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanBuy(items[guiControl.trade.page], itemPrice)) ? "black" : "white", 6);
guiControl.drawPixelText("Haggle", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6);
guiControl.drawPixelText((guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "Yes" : "Over!", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanBuy(items[guiControl.trade.page], itemPrice)) ? ((guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow") : "white", 6);
// Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
@ -207,7 +207,8 @@ guiControl.trade.Draw = function () {
break;
case 1: // Buy
if (items.length > 0 &&
G.inventory.CanBuy(items[guiControl.trade.page], itemPrice)) //If cursor is over yes and you can buy, buy it.
G.inventory.CanBuy(items[guiControl.trade.page], itemPrice) &&
guiControl.trade.island.CanBuyFrom(items[guiControl.trade.page], itemPrice)) //If cursor is over yes and you can buy, buy it.
{
snd_buy.Play();
guiControl.trade.island.BuyFrom(items[guiControl.trade.page], itemPrice);
@ -276,7 +277,7 @@ guiControl.trade.Draw = function () {
}
// Amounts
guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, "black", 4);
guiControl.drawPixelText("Shop" + guiControl.trade.island.inventory[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(2) - pixel(6) + pixel(), 4, (guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow", 4);
guiControl.drawPixelText("Own " + G.inventory.cargo[items[guiControl.trade.page]].toString(), OS.camera.width - pixel(20), guiControl.trade.rowTop(3) - pixel(6) + pixel(), 4, (G.inventory.cargo[items[guiControl.trade.page]] > 0) ? "black" : "yellow", 4);
} else {
guiControl.drawPixelText("No Cargo!", guiControl.trade.padding, guiControl.trade.rowTop(1) - pixel(5) + pixel(), 10, "black", 6);
@ -288,7 +289,7 @@ guiControl.trade.Draw = function () {
// Yes/No Options
guiControl.drawPixelText("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (guiControl.trade.island.timesHaggledToday >= G.stats.popularity) ? "yellow" : ((items.length > 0 && guiControl.trade.island.haggleAmount == 0) ? "black" : "white"), 6);
guiControl.drawPixelText("Yes", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanSell(items[guiControl.trade.page])) ? "black" : "white", 6);
guiControl.drawPixelText((guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "Yes" : "Over!", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(2), 8, (items.length > 0 && G.inventory.CanSell(items[guiControl.trade.page])) ? ((guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) ? "black" : "yellow") : "white", 6);
// Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
@ -313,7 +314,8 @@ guiControl.trade.Draw = function () {
break;
case 1: // Sell
if (items.length > 0 &&
G.inventory.CanSell(items[guiControl.trade.page])) //If cursor is over yes and you can buy, buy it.
G.inventory.CanSell(items[guiControl.trade.page]) &&
guiControl.trade.island.CanSellTo(items[guiControl.trade.page], itemPrice)) //If cursor is over yes and you can buy, buy it.
{
snd_sell.Play();
guiControl.trade.island.SellTo(items[guiControl.trade.page], itemPrice);
@ -422,7 +424,7 @@ guiControl.trade.Draw = function () {
// Title
guiControl.drawPixelText("Gossip", guiControl.trade.padding, guiControl.topOfBackground, 10, "black", 6);
guiControl.drawPixelText("Nothing interesting to report! / / / / / -Actually, this isnt in the game yet-", guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(2), 0, "black", 4);
guiControl.drawPixelText("Use the map with M to find new islands to trade with!", guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(2), 0, "black", 4);
// Back Text
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);

Binary file not shown.

Binary file not shown.

View File

@ -17,11 +17,20 @@ var pr_island = OS.P.Add("Island", {
canTrade: true,
haggleAmount: 0,
timesHaggledToday: 0,
itemsSoldToday: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
itemsBoughtToday: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
inventory: [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0],
storageSpace: [],
innPriceDifference: 0,
innStays: 0,
priceDifferences: [],
@ -47,8 +56,13 @@ pr_island.GetMapPosition = function () {
pr_island.SetUp = function () {
for (var i = 0; i < 16; i++) {
this.storageSpace[i] = Math.round(Math.randomRange(10, 25));
if (this.storageSpace[i] > 20) {
this.inventory[i] = Math.round(this.storageSpace[i] - Math.randomRange(0, 10));
}
if (Math.randomRange(0, 100) < 25) {
this.inventory[i] = Math.round(Math.randomRange(0, 20));
this.inventory[i] = Math.round(Math.randomRange(0, this.storageSpace[i]));
}
}
// console.log(this.name + " stock: " + this.inventory);
@ -63,14 +77,17 @@ pr_island.SetUp = function () {
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) {
this.priceDifferences[i] = Math.round((10 - this.inventory[i]) * Math.randomRange(1, 3));
this.priceDifferences[i] = 0;
if (this.inventory[i] > (this.storageSpace[i] / 2)) {
this.priceDifferences[i] += -Math.round(this.inventory[i] * Math.randomRange(1, 3));
} else if (this.inventory[i] < (this.storageSpace[i] / 4)) {
this.priceDifferences[i] += Math.round((this.storageSpace[i] - this.inventory[i]) * Math.randomRange(1, 3));
} else {
this.priceDifferences[i] = Math.round(Math.randomRange(-2, 2));
this.priceDifferences[i] += Math.round(Math.randomRange(-2, 2));
}
this.priceDifferences[i] = Math.round(this.priceDifferences[i] * ((this.itemsBought[i] + 1) / (this.itemsSold[i] + 1)));
if (G.economy.cargoItemWorth[i] + this.priceDifferences[i] < 0) {
this.priceDifferences[i] = -G.economy.cargoItemWorth[i] + 1;
}
@ -84,13 +101,16 @@ 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));
this.inventory[i] += Math.round(Math.randomRange(-this.storageSpace[i], this.storageSpace[i]));
if (this.inventory[i] < 0) {
this.inventory[i] = 0;
}
if (this.inventory[i] > this.storageSpace[i]) {
this.inventory[i] = this.storageSpace[i];
}
} else {
if (Math.randomRange(0, 100) < 15) {
this.inventory[i] = Math.round(Math.randomRange(0, 5));
this.inventory[i] = Math.round(Math.randomRange(0, this.storageSpace[i]));
}
}
}
@ -101,6 +121,14 @@ pr_island.SimulateTrade = function () {
pr_island.NewDay = function () {
this.haggleAmount = 0;
this.timesHaggledToday = 0;
this.itemsSoldToday = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
this.itemsBoughtToday = [0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0,
0, 0, 0, 0];
this.SimulateTrade();
}
@ -125,6 +153,14 @@ pr_island.TradeWith = function () {
guiControl.trade.show = true;
}
pr_island.CanSellTo = function (itemIndex, price) {
if (this.inventory[itemIndex] < this.storageSpace[itemIndex]) { // If there's space in the inventory
if (this.itemsBoughtToday[itemIndex] < this.storageSpace[itemIndex] * 0.75) { // and if the island hasn't bought more than 75% of its storage space today
return true;
}
}
return false;
}
pr_island.SellTo = function (itemIndex, price) {
// Play Buy sound.
this.inventory[itemIndex]++;
@ -135,10 +171,19 @@ pr_island.SellTo = function (itemIndex, price) {
G.economy.cargoSold[itemIndex]++;
}
pr_island.CanBuyFrom = function (itemIndex, price) {
if (this.inventory[itemIndex] > 0) { // If there's enough of the item
if (this.itemsSoldToday[itemIndex] < this.storageSpace[itemIndex] * 0.90) { // and if the island hasn't sold more than 90% of its storage space today
return true;
}
}
return false;
}
pr_island.BuyFrom = function (itemIndex, price) {
// Play Sell sound.
this.inventory[itemIndex]--;
this.itemsBought[itemIndex]++;
this.itemsSold[itemIndex]++;
this.itemsSoldToday[itemIndex]++;
G.inventory.cargo[itemIndex]++;
G.inventory.money -= price;