From 62524d8693235ca94d82b441c6f74d1d2b6b5a9f Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Tue, 26 Apr 2016 18:03:47 -0600 Subject: [PATCH] Started working on balancing the economy and limiting sales/purchases. Still needs work. --- gui/tradeGUI.js | 18 +++++---- images/sources/alphabets_sheet.xcf | Bin 48242 -> 48718 bytes images/sources/gui_sheet.xcf | Bin 84061 -> 84061 bytes prefabs/islandPrefab.js | 63 ++++++++++++++++++++++++----- 4 files changed, 64 insertions(+), 17 deletions(-) diff --git a/gui/tradeGUI.js b/gui/tradeGUI.js index 6a3d468..87f9841 100644 --- a/gui/tradeGUI.js +++ b/gui/tradeGUI.js @@ -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); diff --git a/images/sources/alphabets_sheet.xcf b/images/sources/alphabets_sheet.xcf index fd7aa4e5ae888a89df1efeb26258e9b8ac5c0a5c..d5b55ced5099fac3225426c500ea7270fb3fb30d 100644 GIT binary patch delta 1000 zcmZ9~OGs2v9LMqB+{#FNCE=Js=qxfMvjlV6BpN~>IW$8L0#g&EccM{kYQRMaMu>MK z(Lz*2=%LP)be@UO#)S(PK_NjywQynLqAbe#j!xq3z~`QO&-tHo{`Y_H@`^G0%jiDl z*g00=a}-QSkfRC4u7{sjQTRSGa1@I-wL*ImvH!T`?#AetGc8UO_HabIkVQi+p2dDKQpu4dU9^quomhf0e%^?@G4y54m#w{kEUxhcJYDJoiv^Y*!cPts5? z<)nW$DZT8MMwYDkfzfocIQYoS3Z#`4+Ye6ED^ShH$+V9L8l~~y(ks6->9I})=2OhF zV7GsEJN2ITSFcz9GY1)2$+;r>m%^UeA8{4lYQYHVj zmXf^poAMaQS}~j@#Q1ra e4QYq8?a$Hw_>GzMh*S#bbo{$6g`H+ir0_4K?&kLZ delta 661 zcmY+>Pe>GD7{~G7ylI4}9Rvws1ur5MLWiY^V8uiVgDqT)2sW1v=4p$(gjXai(ttI`_ z(Uov-iZ-k)^NwrzQa_*Bp_qvD{I|5&Xm>L2JNg&HB}YoiZ*rSMxKW?W?@CM0xJud= z>rx>rt$nw<`ByF8xRU3n^XTzZ|QdFO5j+Kcv^(^qT>jEPXxhEfgPn zZ_CXy+lNb?amhJFpIa{POPg`r!dQLYPfPwZ=0QPz0b8h`iW&~2jaGD`7csNE ze3R|Uz$61@aEorZxRa#Rr{w>+8+hvX{(JuKzvp@1QZi6V29m?Rj>5>SFIa@^2UL5( zU3boW4{O$*yJ)?}d%DBa%aDXb6PSZ_i-u>$oFTK{zp>h|-=rRjCJr?DQB?llC7xhQ z{`S7OgWW8oB0{56F*wYCE#EE+y)3f~$Javr$?vFE`i}n6f>TX6k*R!rkv}R83q9iW z7G7L^uUWK?%}`pzEaX(O8S$-MxZbkf#8S{7|DW;tWAuy1j-ZGWnIC>r0>sq_mSm%oCKs`$}k0-{I0 z(gb8jp gR3q>;r=ATXXouZRJLGmbXYO0j-ia=se$R~m0_!wn3IG5A diff --git a/prefabs/islandPrefab.js b/prefabs/islandPrefab.js index b649048..83b6b21 100644 --- a/prefabs/islandPrefab.js +++ b/prefabs/islandPrefab.js @@ -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;