Skip to content
Snippets Groups Projects
Commit cb6a7d0c authored by Arkerthan's avatar Arkerthan
Browse files

Fix it is possible to gain cash by repeatedly buying and selling shares of other arcologies

parent 7d3c7de5
Branches
Tags
1 merge request!10815Fixes
......@@ -119,6 +119,7 @@ App.Neighbor.Interact = function() {
const interact = (function() {
let nd = new App.Neighbor.Display((id) => replaceDetails(id));
const DEMAND_PER_PERCENT = 2;
return list;
......@@ -183,8 +184,7 @@ App.Neighbor.Interact = function() {
App.UI.DOM.appendNewElement("p", frag, `Your arcology's culture is capable of starting to exert cultural sway over other arcologies. It can project ${desc[0]}.`);
}
} else {
const ownershipCost = 500 * Math.trunc(V.arcologies[arcID].prosperity * (1 + (V.arcologies[arcID].demandFactor / 100)));
frag.append(`A 1% interest in this arcology is worth ${cashFormat(ownershipCost)}. `);
frag.append(`A 1% interest in this arcology is worth ${cashFormat(buyValue(V.arcologies[arcID], 1))}. `);
if (V.arcologies[arcID].ownership + V.arcologies[arcID].PCminority + V.arcologies[arcID].minority < 100) {
frag.append(`The transaction fee is ${cashFormat(10000)}.`);
}
......@@ -192,18 +192,16 @@ App.Neighbor.Interact = function() {
if (V.arcologies[arcID].ownership + V.arcologies[arcID].PCminority + V.arcologies[arcID].minority < 100) {
let links = [];
links.push(App.UI.DOM.link("Buy", () => {
cashX(forceNeg(ownershipCost), "war");
cashX(-10000, "war");
cashX(-(buyValue(V.arcologies[arcID], 1) + 10000), "war");
V.arcologies[arcID].PCminority += 1;
V.arcologies[arcID].demandFactor += 2;
V.arcologies[arcID].demandFactor += DEMAND_PER_PERCENT;
}, [], "Neighbor Interact"));
if (V.arcologies[arcID].ownership + V.arcologies[arcID].PCminority + V.arcologies[arcID].minority <= 90) {
if (V.cash > ownershipCost * 10) {
if (V.cash > buyValue(V.arcologies[arcID], 10) + 10000) {
const link = App.UI.DOM.link("10%", () => {
cashX(forceNeg(ownershipCost * 10), "war");
cashX(-10000, "war");
cashX(-(buyValue(V.arcologies[arcID], 10) + 10000), "war");
V.arcologies[arcID].PCminority += 10;
V.arcologies[arcID].demandFactor += 20;
V.arcologies[arcID].demandFactor += DEMAND_PER_PERCENT * 10;
}, [], "Neighbor Interact");
links.push(link);
}
......@@ -217,9 +215,9 @@ App.Neighbor.Interact = function() {
if (V.arcologies[arcID].PCminority > 0) {
let links = [];
links.push(App.UI.DOM.link("Sell", () => {
cashX(ownershipCost, "war");
cashX(sellValue(V.arcologies[arcID], 1), "war");
V.arcologies[arcID].PCminority -= 1;
V.arcologies[arcID].demandFactor -= 2;
V.arcologies[arcID].demandFactor -= DEMAND_PER_PERCENT;
if (V.arcologies[arcID].government !== "your agent" && V.arcologies[arcID].government !== "your trustees" && V.arcologies[arcID].rival !== 1) {
if (V.arcologies[arcID].ownership + V.arcologies[arcID].PCminority + V.arcologies[arcID].minority < 10) {
V.arcologies[arcID].ownership += 10;
......@@ -229,9 +227,9 @@ App.Neighbor.Interact = function() {
}, [], "Neighbor Interact"));
if (V.arcologies[arcID].PCminority >= 10) {
links.push(App.UI.DOM.link("10%", () => {
cashX((ownershipCost * 10), "war");
cashX(sellValue(V.arcologies[arcID], 10), "war");
V.arcologies[arcID].PCminority -= 10;
V.arcologies[arcID].demandFactor -= 20;
V.arcologies[arcID].demandFactor -= DEMAND_PER_PERCENT * 10;
if (V.arcologies[arcID].government !== "your agent" && V.arcologies[arcID].government !== "your trustees" && V.arcologies[arcID].rival !== 1) {
if (V.arcologies[arcID].ownership + V.arcologies[arcID].PCminority + V.arcologies[arcID].minority < 10) {
V.arcologies[arcID].ownership += 10;
......@@ -273,6 +271,34 @@ App.Neighbor.Interact = function() {
return frag;
}
/**
* How much does it cost to buy x percent of a given arcology
* @param {FC.ArcologyState} arc
* @param {number} percent
* @returns {number}
*/
function buyValue(arc, percent) {
const baseValue = 500 * arc.prosperity;
// scale the demand in such a way that buying twice in a row costs the same as buying double once.
const scaledDemand = arc.demandFactor + (DEMAND_PER_PERCENT * (percent / 2));
const scalingFactor = 1 + (scaledDemand / 100);
return Math.round(baseValue * scalingFactor * percent);
}
/**
* How much does the player get when selling x percent of a given arcology
* @param {FC.ArcologyState} arc
* @param {number} percent
* @returns {number}
*/
function sellValue(arc, percent) {
const baseValue = 500 * arc.prosperity;
// scale the demand in such a way that selling twice in a row gives the same as selling double once.
const scaledDemand = arc.demandFactor - (DEMAND_PER_PERCENT * (percent / 2));
const scalingFactor = 1 + (scaledDemand / 100);
return Math.round(baseValue * scalingFactor * percent);
}
/** Create a div containing actions specific to arcologies that are under the player's control
* @param {number} arcID
* @returns {Element}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment