public void RoundToInt(string cost) { int itemCost = 0; if (cost[0] == '$') { itemCost = YarnGeneral.IntFromVariableName(cost, ds.Storage); } else { itemCost = Mathf.CeilToInt(float.Parse(cost)); } ds.Storage.SetValue("$rounded_num", itemCost); }
public void CheckAffordability(string cost) { int itemCost = 0; if (cost[0] == '$') { itemCost = YarnGeneral.IntFromVariableName(cost, ds.Storage); } else { itemCost = Mathf.CeilToInt(float.Parse(cost)); } ds.Storage.SetValue("$can_afford", Globals.GameVars.playerShipVariables.ship.currency >= itemCost); }
public void PayAmount(string cost) { int itemCost = 0; if (cost[0] == '$') { itemCost = YarnGeneral.IntFromVariableName(cost, ds.Storage); } else { itemCost = Mathf.RoundToInt(float.Parse(cost)); } Globals.GameVars.playerShipVariables.ship.currency -= itemCost; ds.UpdateMoney(); }
public void CalculateNeededResources() { owedResources.Clear(); float currentDr = Globals.GameVars.playerShipVariables.ship.currency; ds.Storage.SetValue("$drachma", currentDr); float cost = ds.Storage.GetValue("$final_cost").AsNumber; float owedDr = cost - currentDr; Debug.Log($"Taxes remaining: {owedDr}dr"); MetaResource[] sortedResources = Globals.GameVars.masterResourceList.OrderBy(x => x.trading_priority).ToArray(); Resource[] playerResources = Globals.GameVars.playerShipVariables.ship.cargo; for (int i = 0; i < sortedResources.Length; i++) { //If it's something that can be demanded (ie not water or food)... if (sortedResources[i].trading_priority != 100) { //If you have any of it... int id = sortedResources[i].id; if (playerResources[id].amount_kg > 0) { //Do you have enough to completely cover your costs? float value = OneCargoValue(playerResources[id], playerResources[id].amount_kg); Resource r; if (value >= owedDr) { //If you do have more than enough, check how much is enough int amt; for (amt = 1; amt < Mathf.FloorToInt(playerResources[id].amount_kg); amt++) { float currentCost = OneCargoValue(playerResources[id], amt); if (currentCost >= owedDr) { break; } } value = OneCargoValue(playerResources[id], amt); r = new Resource(playerResources[id].name, amt); Debug.Log($"Paying {amt}kg of {r.name}: value {value}dr"); } else { //Otherwise, you'll need to add all of it and keep going r = new Resource(playerResources[id].name, playerResources[id].amount_kg); Debug.Log($"Paying {r.amount_kg}kg of {r.name}: value {value}dr"); } owedDr -= value; Debug.Log($"Taxes remaining: {owedDr}dr"); owedResources.Add(r); //If you've got enough value, end the loop if (owedDr <= 0) { break; } } } } ds.Storage.SetValue("$demanded_resources_value", cost - owedDr); ds.Storage.SetValue("$demanded_resources", YarnGeneral.FormatList(owedResources)); }