Finished Trade GUI and got trading working! There's test data in there, so this isn't ready to merge yet.
This commit is contained in:
parent
470bac1997
commit
e8a43df0bc
265
gui/tradeGUI.js
265
gui/tradeGUI.js
|
@ -2,11 +2,13 @@ function tradeGUI() {
|
|||
guiControl.trade = {
|
||||
screen: "main", // "main", "buy", "sell", "gossip"
|
||||
cursorPosition: 0,
|
||||
page: 0, // horizontal page on item lists.
|
||||
page: 0, // horizontal page on item lists. Base 1 to match number of pages var "pages" within the gui.
|
||||
itemsPerPage: 3,
|
||||
show: false,
|
||||
activateDelay: 0,
|
||||
|
||||
island: null,
|
||||
haggleAmount: 0,
|
||||
|
||||
padding: pixel(2),
|
||||
leftBorder: pixel(12),
|
||||
|
@ -33,8 +35,17 @@ function drawTradeGUI() {
|
|||
// Play Move_Cursor_Up sound.
|
||||
guiControl.trade.cursorPosition--;
|
||||
}
|
||||
if (ct_right().down) {
|
||||
// Play Move_Cursor sound.
|
||||
guiControl.trade.page++;
|
||||
}
|
||||
if (ct_left().down) {
|
||||
// Play Move_Cursor_Up sound.
|
||||
guiControl.trade.page--;
|
||||
}
|
||||
|
||||
if (guiControl.trade.screen == "main") {
|
||||
// console.log(guiControl.trade.screen);
|
||||
// Limit Cursor
|
||||
if (guiControl.trade.cursorPosition < 0) {
|
||||
guiControl.trade.cursorPosition = 3;
|
||||
|
@ -42,15 +53,22 @@ function drawTradeGUI() {
|
|||
if (guiControl.trade.cursorPosition > 3) {
|
||||
guiControl.trade.cursorPosition = 0;
|
||||
}
|
||||
// Limit page
|
||||
if (guiControl.trade.page < 0) {
|
||||
guiControl.trade.page = 0;
|
||||
}
|
||||
if (guiControl.trade.page > 0) {
|
||||
guiControl.trade.page = 0;
|
||||
}
|
||||
|
||||
// Title
|
||||
guiControl.drawPixelText("On Island", (guiControl.trade.padding * 2), guiControl.trade.padding, 10, "black", 6);
|
||||
// Money icon
|
||||
// guiControl.drawIcon(7, 2, guiControl.trade.leftBorder, guiControl.trade.rowTop(0));
|
||||
guiControl.drawPixelText("Buy", guiControl.trade.leftBorder, guiControl.trade.rowTop(0) + pixel(), 8, "black", 6);
|
||||
guiControl.drawPixelText((guiControl.trade.island.CheckInventory().length > 0) ? "Buy" : "Sold Out!", guiControl.trade.leftBorder, guiControl.trade.rowTop(0) + pixel(), 10, (guiControl.trade.island.CheckInventory().length > 0) ? "black" : "white", 6);
|
||||
// Supplies icon
|
||||
// guiControl.drawIcon(9, 2, guiControl.trade.leftBorder, guiControl.trade.rowTop(1));
|
||||
guiControl.drawPixelText("Sell", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) + pixel(), 8, "black", 6);
|
||||
guiControl.drawPixelText((G.inventory.CheckCargo().length > 0) ? "Sell" : "No Cargo!", guiControl.trade.leftBorder, guiControl.trade.rowTop(1) + pixel(), 10, (G.inventory.CheckCargo().length > 0) ? "black" : "white", 6);
|
||||
// Cargo icon
|
||||
// guiControl.drawIcon(1, 0, guiControl.trade.leftBorder, guiControl.trade.rowTop(2));
|
||||
guiControl.drawPixelText("Gossip", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) + pixel(), 8, "black", 6);
|
||||
|
@ -65,10 +83,19 @@ function drawTradeGUI() {
|
|||
if (guiControl.trade.activateDelay <= 0 && ct_confirm().down) {
|
||||
switch (guiControl.trade.cursorPosition) {
|
||||
case 0:
|
||||
guiControl.trade.screen = "buy";
|
||||
if (guiControl.trade.island.CheckInventory().length > 0) {
|
||||
guiControl.trade.screen = "buy";
|
||||
}
|
||||
else {
|
||||
// Play Cannot_Buy sound.
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
guiControl.trade.screen = "sell";
|
||||
if (G.inventory.CheckCargo().length > 0) {
|
||||
guiControl.trade.screen = "sell";
|
||||
} else {
|
||||
// Play Cannot_Buy sound.
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
guiControl.trade.screen = "gossip";
|
||||
|
@ -82,48 +109,11 @@ function drawTradeGUI() {
|
|||
// Play Select sound.
|
||||
guiControl.trade.cursorPosition = 0;
|
||||
guiControl.trade.page = 0;
|
||||
// console.log(guiControl.trade.screen);
|
||||
}
|
||||
}
|
||||
else if (guiControl.trade.screen == "buy") {
|
||||
// Limit Cursor
|
||||
if (guiControl.trade.cursorPosition < 0) {
|
||||
guiControl.trade.cursorPosition = 0;
|
||||
}
|
||||
if (guiControl.trade.cursorPosition > 0) {
|
||||
guiControl.trade.cursorPosition = 0;
|
||||
}
|
||||
|
||||
// Title
|
||||
guiControl.drawPixelText("Buy", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
|
||||
|
||||
// Money icon
|
||||
guiControl.drawIcon(7, 2, guiControl.trade.leftBorder - pixel(5), guiControl.trade.rowTop(0) - pixel(3));
|
||||
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.leftBorder - pixel(5) + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(0) + pixel(2) - pixel(3), 10, "black", 4);
|
||||
|
||||
// Cargo icons
|
||||
var cargo = guiControl.trade.island.CheckInventory(); // Contains the item ids that have more than 1 item
|
||||
for (var i = 0; i < cargo.length; i++) {
|
||||
guiControl.drawItem(cargo[i], guiControl.trade.leftBorder, guiControl.trade.rowTop(i + 1));
|
||||
var itemPrice = G.economy.cargoItemWorth[cargo[i]] + guiControl.trade.island.priceDifferences[cargo[i]];
|
||||
var itemPriceDisplay = itemPrice.toString() + " c";
|
||||
guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(i + 1) + pixel(2), 8, "black", 4);
|
||||
// guiControl.drawPixelText(guiControl.trade.island.inventory[cargo[i]], guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(i + 1) + pixel(), 8, "black", 6);
|
||||
}
|
||||
|
||||
// Back Text
|
||||
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(3), 8, "black", 6);
|
||||
|
||||
// Draw cursor
|
||||
OS.context.drawImage(guiControl.cursor, guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(4) - pixel(4));
|
||||
|
||||
// Button Action
|
||||
if (ct_confirm().down || ct_cancel().down) {
|
||||
// Play Select sound.
|
||||
guiControl.trade.screen = "main";
|
||||
guiControl.trade.cursorPosition = 0;
|
||||
}
|
||||
}
|
||||
else if (guiControl.trade.screen == "sell") {
|
||||
// console.log(guiControl.trade.screen);
|
||||
// Limit Cursor
|
||||
if (guiControl.trade.cursorPosition < 0) {
|
||||
guiControl.trade.cursorPosition = 2;
|
||||
|
@ -133,49 +123,184 @@ function drawTradeGUI() {
|
|||
}
|
||||
|
||||
// Title
|
||||
guiControl.drawPixelText("Sell", guiControl.trade.leftBorder - pixel(6), guiControl.topOfBackground, 10, "black", 6);
|
||||
guiControl.drawPixelText("Buy", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
|
||||
|
||||
guiControl.drawPixelText("Heal Crew?", guiControl.trade.leftBorder - pixel(5), guiControl.trade.rowTop(0) + pixel(), 10, "black", 4);
|
||||
// Supplies icon
|
||||
guiControl.drawIcon(9, 2, guiControl.trade.leftBorder - pixel(5), guiControl.trade.rowTop(1) - pixel(3));
|
||||
guiControl.drawPixelText(G.inventory.supplies.toString(), guiControl.trade.leftBorder - pixel(5) + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(1) + pixel(2) - pixel(3), 2, "black", 4);
|
||||
// Illness icon
|
||||
guiControl.drawIcon(4, 1, guiControl.trade.leftBorder - pixel(5) + pixel(24), guiControl.trade.rowTop(1) - pixel(3));
|
||||
guiControl.drawPixelText(G.stats.illness.toString(), guiControl.trade.leftBorder - pixel(5) + pixel(24) + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(1) + pixel(2) - pixel(3), 2, "black", 4);
|
||||
// Money icon
|
||||
guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(3));
|
||||
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(0) + pixel(2) - pixel(3), 10, "black", 4);
|
||||
|
||||
// Yes/No options
|
||||
guiControl.drawPixelText("No", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(3), 3, "black", 6);
|
||||
guiControl.drawPixelText("Yes", guiControl.trade.leftBorder, guiControl.trade.rowTop(3) - pixel(3), 3, "black", 6);
|
||||
// Cargo icons
|
||||
var items = guiControl.trade.island.CheckInventory(); // Contains the item ids that have more than 1 item
|
||||
|
||||
// Limit page
|
||||
if (guiControl.trade.page < 0) {
|
||||
guiControl.trade.page = items.length - 1;
|
||||
}
|
||||
if (guiControl.trade.page > items.length - 1) {
|
||||
guiControl.trade.page = 0;
|
||||
}
|
||||
|
||||
if (items.length > 0) {
|
||||
var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]] - guiControl.trade.haggleAmount;
|
||||
if (itemPrice < 1) itemPrice = 1;
|
||||
var itemPriceDisplay = itemPrice.toString() + " c";
|
||||
guiControl.drawItem(items[guiControl.trade.page], guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5));
|
||||
guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(1) - pixel(5) + pixel(), 8, "black", 6);
|
||||
|
||||
// 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("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);
|
||||
}
|
||||
|
||||
// Draw Amount of Cargo
|
||||
guiControl.drawIcon(1, 1, OS.camera.width - pixel(20), guiControl.trade.rowTop(4) - pixel(5));
|
||||
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, (items.length > 0 && guiControl.trade.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);
|
||||
|
||||
// Back Text
|
||||
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(3), 8, "black", 6);
|
||||
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
|
||||
|
||||
// Draw cursor
|
||||
guiControl.drawCursor(guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(4));
|
||||
OS.context.drawImage(guiControl.cursor, guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
|
||||
|
||||
// Button Action
|
||||
if (ct_confirm().down) {
|
||||
switch (guiControl.trade.cursorPosition) {
|
||||
case 1:
|
||||
if (G.inventory.supplies > 0 && G.stats.illness > 0) { //If cursor is over yes, heal illness with supplies.
|
||||
G.inventory.supplies--;
|
||||
G.stats.illness--;
|
||||
case 0: // Haggle
|
||||
if (items.length > 0 &&
|
||||
guiControl.trade.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // If you haven't haggled yet and get a random number less than your popularity, haggle successfully.
|
||||
{
|
||||
guiControl.trade.haggleAmount = G.stats.haggling;
|
||||
// Play Sell sound.
|
||||
} else {
|
||||
// Play Cannot_Buy sound.
|
||||
}
|
||||
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.
|
||||
guiControl.trade.island.BuyFrom(items[guiControl.trade.page], itemPrice);
|
||||
} else {
|
||||
// Play Cannot_Buy sound.
|
||||
}
|
||||
break;
|
||||
default:
|
||||
guiControl.trade.screen = "main";
|
||||
guiControl.trade.cursorPosition = 1; // The position where "Supplies" is on main screen.
|
||||
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen.
|
||||
break;
|
||||
}
|
||||
// Play Select sound.
|
||||
// console.log(guiControl.trade.screen);
|
||||
}
|
||||
|
||||
if (ct_cancel().down) {
|
||||
guiControl.trade.screen = "main";
|
||||
guiControl.trade.cursorPosition = 1; // The position where "Supplies" is on main screen.
|
||||
guiControl.trade.cursorPosition = 0; // The position where "Buy" is on main screen.
|
||||
// console.log(guiControl.trade.screen);
|
||||
}
|
||||
}
|
||||
else if (guiControl.trade.screen == "sell") {
|
||||
// console.log(guiControl.trade.screen);
|
||||
// Limit Cursor
|
||||
if (guiControl.trade.cursorPosition < 0) {
|
||||
guiControl.trade.cursorPosition = 2;
|
||||
}
|
||||
if (guiControl.trade.cursorPosition > 2) {
|
||||
guiControl.trade.cursorPosition = 0;
|
||||
}
|
||||
|
||||
// Title
|
||||
guiControl.drawPixelText("Sell", guiControl.trade.leftBorder - pixel(2), guiControl.topOfBackground, 10, "black", 6);
|
||||
|
||||
// Money icon
|
||||
guiControl.drawIcon(7, 2, guiControl.trade.padding, guiControl.trade.rowTop(0) - pixel(3));
|
||||
guiControl.drawPixelText(G.inventory.moneyDisplay(), guiControl.trade.padding + pixel(guiControl.iconSize + 2), guiControl.trade.rowTop(0) + pixel(2) - pixel(3), 10, "black", 4);
|
||||
|
||||
// Cargo icons
|
||||
var items = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item
|
||||
|
||||
// Limit page
|
||||
if (guiControl.trade.page < 0) {
|
||||
guiControl.trade.page = items.length - 1;
|
||||
}
|
||||
if (guiControl.trade.page > items.length - 1) {
|
||||
guiControl.trade.page = 0;
|
||||
}
|
||||
|
||||
if (items.length > 0) {
|
||||
var itemPrice = G.economy.cargoItemWorth[items[guiControl.trade.page]] + guiControl.trade.island.priceDifferences[items[guiControl.trade.page]];
|
||||
var priceCut = 0.5 + ((guiControl.trade.haggleAmount == 0) ? 0 : (G.stats.popularity * 0.01 * 0.5)); // If haggled successfully, lessen the price cut by half of your popularity's percent worth.
|
||||
itemPrice = Math.round(itemPrice * priceCut);
|
||||
if (itemPrice < 1) itemPrice = 1;
|
||||
var itemPriceDisplay = itemPrice.toString() + " c";
|
||||
guiControl.drawItem(items[guiControl.trade.page], guiControl.trade.leftBorder, guiControl.trade.rowTop(1) - pixel(5));
|
||||
guiControl.drawPixelText(itemPriceDisplay, guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(1) - pixel(5) + pixel(), 8, "black", 6);
|
||||
|
||||
// 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("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);
|
||||
}
|
||||
|
||||
// Draw Amount of Cargo
|
||||
guiControl.drawIcon(1, 1, OS.camera.width - pixel(20), guiControl.trade.rowTop(4) - pixel(5));
|
||||
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 > 0) ? "black" : "yellow", 6);
|
||||
|
||||
// Yes/No Options
|
||||
guiControl.drawPixelText("Hagl?", guiControl.trade.leftBorder, guiControl.trade.rowTop(2) - pixel(2), 8, (items.length > 0 && guiControl.trade.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);
|
||||
|
||||
// Back Text
|
||||
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
|
||||
|
||||
// Draw cursor
|
||||
OS.context.drawImage(guiControl.cursor, guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(guiControl.trade.cursorPosition + 2) - pixel(3));
|
||||
|
||||
// Button Action
|
||||
if (ct_confirm().down) {
|
||||
switch (guiControl.trade.cursorPosition) {
|
||||
case 0: // Haggle
|
||||
if (items.length > 0 &&
|
||||
guiControl.trade.haggleAmount == 0 && Math.floor(Math.randomRange(0, 100)) < G.stats.popularity) // If you haven't haggled yet and get a random number less than your popularity, haggle successfully.
|
||||
{
|
||||
guiControl.trade.haggleAmount = G.stats.haggling;
|
||||
// Play Sell sound.
|
||||
} else {
|
||||
// Play Cannot_Buy sound.
|
||||
}
|
||||
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.
|
||||
{
|
||||
guiControl.trade.island.SellTo(items[guiControl.trade.page], itemPrice);
|
||||
} else {
|
||||
// Play Cannot_Buy sound.
|
||||
}
|
||||
break;
|
||||
default:
|
||||
guiControl.trade.screen = "main";
|
||||
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen.
|
||||
break;
|
||||
}
|
||||
// Play Select sound.
|
||||
// console.log(guiControl.trade.screen);
|
||||
}
|
||||
|
||||
if (ct_cancel().down) {
|
||||
guiControl.trade.screen = "main";
|
||||
guiControl.trade.cursorPosition = 1; // The position where "Sell" is on main screen.
|
||||
// console.log(guiControl.trade.screen);
|
||||
}
|
||||
}
|
||||
else if (guiControl.trade.screen == "gossip") {
|
||||
// console.log(guiControl.trade.screen);
|
||||
// Limit Cursor
|
||||
if (guiControl.trade.cursorPosition < 0) {
|
||||
guiControl.trade.cursorPosition = 0;
|
||||
|
@ -185,26 +310,22 @@ function drawTradeGUI() {
|
|||
}
|
||||
|
||||
// Title
|
||||
guiControl.drawPixelText("Gossip", guiControl.trade.padding - pixel(2), guiControl.topOfBackground, 10, "black", 6);
|
||||
guiControl.drawPixelText("Gossip", guiControl.trade.padding, guiControl.topOfBackground, 10, "black", 6);
|
||||
|
||||
// Cargo icons
|
||||
var cargo = G.inventory.CheckCargo(); // Contains the item ids that have more than 1 item
|
||||
for (var i = 0; i < cargo.length; i++) {
|
||||
guiControl.drawItem(cargo[i], guiControl.trade.leftBorder, guiControl.trade.rowTop(i));
|
||||
guiControl.drawPixelText(G.inventory.cargo[cargo[i]], guiControl.trade.leftBorder + pixel(guiControl.iconSize + 4), guiControl.trade.rowTop(i) + pixel(), 8, "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);
|
||||
|
||||
// Back Text
|
||||
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(3), 8, "black", 6);
|
||||
guiControl.drawPixelText("Back", guiControl.trade.leftBorder, guiControl.trade.rowTop(4) - pixel(2), 8, "black", 6);
|
||||
|
||||
// Draw cursor
|
||||
OS.context.drawImage(guiControl.cursor, guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(4) - pixel(4));
|
||||
OS.context.drawImage(guiControl.cursor, guiControl.trade.leftBorder - (guiControl.iconScaled), guiControl.trade.rowTop(4) - pixel(3));
|
||||
|
||||
// Button Action
|
||||
if (ct_confirm().down || ct_cancel().down) {
|
||||
guiControl.trade.screen = "main";
|
||||
guiControl.trade.cursorPosition = 2;
|
||||
// Play Select sound.
|
||||
// console.log(guiControl.trade.screen);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,18 @@ G.inventory = {
|
|||
cargoTotal += G.inventory.cargo[cargo[i]];
|
||||
}
|
||||
return cargoTotal;
|
||||
},
|
||||
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;
|
||||
}
|
||||
};
|
||||
G.stats = {
|
||||
|
|
|
@ -15,7 +15,11 @@ var pr_island = OS.P.Add("Island", {
|
|||
|
||||
canTrade: true,
|
||||
|
||||
inventory: [],
|
||||
// inventory: [],
|
||||
inventory: [0, 5, 0, 0,
|
||||
0, 0, 3, 0,
|
||||
0, 4, 0, 0,
|
||||
0, 0, 0, 6],
|
||||
priceDifferences: [],
|
||||
itemsSold: [0, 0, 0, 0, // The more you sell, the lower the price gets
|
||||
0, 0, 0, 0,
|
||||
|
@ -38,10 +42,10 @@ pr_island.GetMapPosition = function () {
|
|||
}
|
||||
|
||||
pr_island.SetUp = function () {
|
||||
for (var i = 0; i < 15; i++) {
|
||||
this.inventory[i] = Math.round(Math.randomRange(0, 20));
|
||||
for (var i = 0; i < 16; i++) {
|
||||
// this.inventory[i] = Math.round(Math.randomRange(0, 20));
|
||||
this.priceDifferences[i] = Math.round(Math.randomRange(-50, 50));
|
||||
if (G.economy.cargoItemWorth[i] + this.priceDifferences[i]) {
|
||||
if (G.economy.cargoItemWorth[i] + this.priceDifferences[i] < 0) {
|
||||
this.priceDifferences[i] = -G.economy.cargoItemWorth[i] + 1;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +64,7 @@ pr_island.AdjustPrices = function () {
|
|||
|
||||
pr_island.CheckInventory = function () { // Returns an array of indices that have cargo
|
||||
var indicesWithCargo = [];
|
||||
for (var i = 0; i < G.inventory.cargo.length; i++) {
|
||||
for (var i = 0; i < this.inventory.length; i++) {
|
||||
if (this.inventory[i] > 0) {
|
||||
indicesWithCargo.push(i);
|
||||
}
|
||||
|
@ -71,18 +75,25 @@ pr_island.CheckInventory = function () { // Returns an array of indices that hav
|
|||
pr_island.TradeWith = function () {
|
||||
// Change music to Trade.
|
||||
guiControl.trade.island = this.self;
|
||||
guiControl.trade.haggleAmount = 0;
|
||||
guiControl.trade.activateDelay = 5;
|
||||
guiControl.trade.show = true;
|
||||
}
|
||||
|
||||
pr_island.SellTo = function (itemIndex, amount) {
|
||||
pr_island.SellTo = function (itemIndex, price) {
|
||||
// Play Buy sound.
|
||||
this.inventory[itemIndex] += amount;
|
||||
this.itemsBought[itemIndex] += amount;
|
||||
this.inventory[itemIndex]++;
|
||||
this.itemsBought[itemIndex]++;
|
||||
|
||||
G.inventory.cargo[itemIndex]--;
|
||||
G.inventory.money += price;
|
||||
}
|
||||
|
||||
pr_island.BuyFrom = function (itemIndex, amount) {
|
||||
pr_island.BuyFrom = function (itemIndex, price) {
|
||||
// Play Sell sound.
|
||||
this.inventory[itemIndex] -= amount;
|
||||
this.itemsSold[itemIndex] += amount;
|
||||
this.inventory[itemIndex]--;
|
||||
this.itemsBought[itemIndex]++;
|
||||
|
||||
G.inventory.cargo[itemIndex]++;
|
||||
G.inventory.money -= price;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue