protected override void Execute(List <GameEntity> entities) { foreach (var m in Companies.GetAIManagingCompanies(gameContext)) { var products = Companies.GetDaughterProducts(gameContext, m); var importances = products .Select(p => Companies.GetMarketImportanceForCompany(gameContext, m, p.product.Niche)) .ToArray(); var sum = importances.Sum(); if (sum == 0) { sum = 1; } var balance = Economy.BalanceOf(m); for (var i = 0; i < products.Length; i++) { var budget = balance * importances[i] / sum; SupportStartup(products[i], budget); } } }
public void Render(int investorId) { var company = SelectedCompany; Button = GetComponent <Button>(); Hint = GetComponent <Hint>(); var investor = Companies.GetInvestorById(Q, investorId); var cost = Companies.GetSharesCost(Q, company, investor); // TODO we don't always buy companies as Company Group. We can do it as human or investment fund too! var have = Economy.BalanceOf(MyGroupEntity); bool wantsToSell = WillSell(investorId, company.company.Id); bool canAfford = have >= cost; Button.interactable = canAfford && cost > 0 && wantsToSell; int percentage = Companies.GetShareSize(Q, company, investor); var text = $"Buying {percentage}% of shares will cost us ({MyGroupEntity.company.Name}) {Format.Money(cost)}"; var paymentAbility = canAfford ? Visuals.Positive(Format.Money(have)) : Visuals.Negative(Format.Money(have)); //var desireToSell = wantsToSell ? "" string hint = text + "\n We have " + paymentAbility; GetComponent <Hint>().SetHint(hint); }
void RemoveExpensiveTasks(GameEntity product) { var profit = Economy.GetProfit(gameContext, product); var balance = Economy.BalanceOf(product); // we need this amount of money var deficit = balance + profit; var initialDeficit = deficit; // ----------------------------------------- var tasks = product.team.Teams[0].Tasks; var sortedTaks = tasks .Select(t => new { t, cost = Economy.GetTeamTaskCost(product, t) }) .Where(t => t.cost > 0) .OrderByDescending(a => a.cost); foreach (var taskData in sortedTaks) { var cost = taskData.cost; deficit += cost; Teams.RemoveTeamTask(product, gameContext, taskData.t); Companies.Log(product, $"Removed team task: {taskData.t.GetPrettyName()}, which cost was {Format.Money(taskData.cost)}"); if (deficit >= 0) { Companies.LogSuccess(product, $"LAST TASK REMOVAL SAVED COMPANY"); return; } } Companies.Log(product, $"After removing tasks: deficit was {Format.Money(initialDeficit)} to {Format.Money(deficit)}"); }
bool IsHasMoneyOverflow(GameEntity company) { var balance = Economy.BalanceOf(company); var nonCapitalCost = Economy.GetCompanyBaseCost(gameContext, company.company.Id); return(balance > 0.3d * nonCapitalCost); }
//// TODO move to raise investments //public static bool IsCanTakeFastCash(GameContext gameContext, GameEntity company) => !IsHasCashOverflow(gameContext, company); public static bool IsHasCashOverflow(GameContext gameContext, GameEntity company) { var valuation = CostOf(company, gameContext); var balance = Economy.BalanceOf(company); var maxCash = valuation * 7 / 100; return(balance > maxCash); }
void SetHint(float value) { int percent = (int)(value * 100); var c = Companies.Get(Q, MyGroupEntity.company.Id); var total = Economy.BalanceOf(c); var investments = total * percent / 100; Hint.SetHint($"We will invest {Format.Money(investments)}\nOur share size will increase"); }
void PayAIDividends(GameEntity e) { // TODO pay dividends only if all upgrades are set to max and still they have necessary amount of money var balance = Economy.BalanceOf(e); var maintenance = Economy.GetProductMaintenance(e, gameContext); var dividends = balance - maintenance; if (dividends > 0) { Companies.PayDividends(gameContext, e, dividends); } }
public override string RenderValue() { var profit = Economy.GetProfit(Q, MyCompany); var balance = Economy.BalanceOf(MyCompany); var minifiedBalance = Format.Minify(balance); if (Companies.IsHasDaughters(Q, MyCompany)) { return($"{minifiedBalance} {Visuals.PositiveOrNegativeMinified(profit)}"); } return(minifiedBalance); }
void PrintFinancialStatusOfCompany(GameEntity product) { var balance = Economy.BalanceOf(product); var income = Economy.GetIncome(gameContext, product); var maintenance = Economy.GetMaintenance(gameContext, product); var profit = Economy.GetProfit(gameContext, product); Companies.Log(product, $"Balance: " + Format.Money(balance) + ", Profit: " + Visuals.PositiveOrNegativeMinified(profit) + " (Income: " + Visuals.Positive("+" + Format.Money(income)) + " Expenses: " + Visuals.Negative("-" + Format.Money(maintenance)) + ")" ); }
public override void Execute() { try { // LOGS AND PICK Debug.Log("TRY AcquireCompany"); var companyId = Popup.companyId; var buyerId = Popup.buyerInvestorId; Debug.Log("CompanyId=" + companyId + " BuyerId=" + buyerId); var company = Companies.Get(Q, companyId); var investor = Companies.GetInvestorById(Q, buyerId); Debug.Log("AcquireCompanyPopupButton : will buy " + company.company.Name + " as " + Companies.GetInvestorName(investor)); var offer = Companies.GetAcquisitionOffer(Q, company, investor); var bid = offer.acquisitionOffer.BuyerOffer.Price; var balance = Economy.BalanceOf(MyCompany); if (Companies.IsEnoughResources(MyCompany, bid)) { // CONFIRM ACQUISITION Companies.ConfirmAcquisitionOffer(Q, company, investor); // SOUND PlaySound(Assets.Sound.MoneySpent); } else { PlaySound(Assets.Sound.Notification); NotificationUtils.AddSimplePopup(Q, Visuals.Negative("Not enough cash :("), $"You need {Format.Money(bid)}, but only have {Format.Money(balance)}"); } // NAVIGATE NavigateToProjectScreen(companyId); // CLOSE POPUP NotificationUtils.ClosePopup(Q); } catch (Exception ex) { Debug.LogError("Acquire Popup button fail"); Debug.LogError(ex); } }
void PayAIDividends(GameEntity e) { long marketingBudget = 0; if (e.hasProduct) { marketingBudget = Marketing.GetBrandingCost(e, gameContext) + Marketing.GetTargetingCost(e, gameContext); } var dividends = Economy.BalanceOf(e) - Economy.GetCompanyMaintenance(gameContext, e) - marketingBudget; if (dividends > 0) { Companies.PayDividends(gameContext, e, dividends); } }
protected override void Execute(List <GameEntity> entities) { var playerCompany = Companies.GetPlayerCompany(gameContext); if (playerCompany == null) { return; } var profit = Economy.GetProfit(gameContext, playerCompany); var balance = Economy.BalanceOf(playerCompany); var willBecomeBankruptNextDay = balance + profit < 0; if (profit < 0 && willBecomeBankruptNextDay) { NotificationUtils.AddPopup(gameContext, new PopupMessageBankruptcyThreat(playerCompany.company.Id)); } }
public static GameEntity CloseCompany(GameContext context, GameEntity company, bool bankrupt = false) { var balance = Economy.BalanceOf(company); company.companyResourceHistory.Actions.Add(new ResourceTransaction { Tag = "Close company", TeamResource = -balance }); // pay to everyone PayDividends(context, company, balance); // fire everyone NotifyAboutProductSupportEnd(company, context); if (company.hasProduct) { Teams.DismissTeam(company, context); Markets.ReturnUsersWhenCompanyIsClosed(company, context); } RemoveAllPartnerships(company, context); foreach (var holding in GetDaughters(company, context)) { RemoveShareholder(holding, context, company); } RemoveAllShareholders(context, company); //e.ReplaceShareholders(new Dictionary<int, BlockOfShares>()); company.isAlive = false; if (bankrupt) { company.isBankrupt = true; } return(company); }
public void Execute() { if (DateEntity == null) { return; } CheckPressedButtons(); totalTime -= Time.deltaTime; if (totalTime < 0 && isTimerRunning) { var playerCompany = Companies.GetPlayerCompany(gameContext); while (ScheduleUtils.IsLastDayOfPeriod(DateEntity) && Economy.IsWillBecomeBankruptOnNextPeriod(gameContext, playerCompany)) { var profit = Economy.GetProfit(gameContext, playerCompany, true); var profit2 = Economy.GetProfit(gameContext, playerCompany); var balance = Economy.BalanceOf(playerCompany); Debug.Log($"BANKRUPTCY THREAT for {playerCompany.company.Name}. Cash: {Format.Money(balance)}, Profit: {Format.Money(profit2)}\n\n{profit.ToString()}"); TutorialUtils.Unlock(gameContext, TutorialFunctionality.CanRaiseInvestments); TutorialUtils.Unlock(gameContext, TutorialFunctionality.BankruptcyWarning); NotificationUtils.AddPopup(gameContext, new PopupMessageBankruptcyThreat(playerCompany.company.Id)); ScheduleUtils.PauseGame(gameContext); return; } // ResetTimer(); totalTime = 1 / (float)currentSpeed; ScheduleUtils.IncreaseDate(gameContext, 1); } }
void RenderBaseCosts(GameEntity c) { BaseCost.text = "???!!!"; // RenderCosts(Economy.GetCompanyBaseCost(c, Q)); CapitalSize.text = RenderCosts(Economy.BalanceOf(c)); if (c.hasProduct) { ShowProductCompanyLabels(true); ShowGroupLabels(false); AudienceCost.text = RenderCosts(Economy.GetClientBaseCost(c)); IncomeBasedCost.text = "???!!!"; // RenderCosts(Economy.GetCompanyIncomeBasedCost(c, Q)); IncomeBasedCostLabel.text = $"Income X{Economy.GetCompanyCostNicheMultiplier()}"; } else { ShowProductCompanyLabels(false); ShowGroupLabels(true); HoldingCost.text = RenderCosts(Economy.GetGroupCost(c, Q)); } }
public override void Execute() { int companyId = SelectedCompany.company.Id; var c = MyGroupEntity; long Offer = Economy.BalanceOf(c) * Percent / 100; int shareholderId = MyGroupEntity.shareholder.Id; Debug.LogError("Check InvestInControllableCompany"); //Companies.AddInvestmentProposal(Q, companyId, new InvestmentProposal { // ShareholderId = shareholderId, // WasAccepted = false, // Valuation = 0, // Offer = Offer, // InvestorBonus = InvestorBonus.None //}); //Companies.AcceptInvestmentProposal(Q, companyId, shareholderId); }
public override void SetItem <T>(Transform t, T entity) { var product = entity as GameEntity; var users = Marketing.GetUsers(product); var header = $"<b><size=40>#{index + 1} {product.company.Name}</size></b>"; if (product.isFlagship) { header = Visuals.Colorize(header, Colors.COLOR_COMPANY_WHERE_I_AM_CEO); } var marketers = product.team.Teams.Select(t1 => t1.Roles.Values.Count(r => r == WorkerRole.Marketer)).Sum(); var coders = product.team.Teams.Select(t1 => t1.Roles.Values.Count(r => r == WorkerRole.Programmer)).Sum(); var text = header; text += $"\n\n{Format.Minify(users)} users & ({coders}/{marketers}) #{product.creationIndex}"; text += "\nAiming " + Products.GetBestFeatureUpgradePossibility(product, Q).Name; text = GetMarketingActivity(text, product); text += $"\n\nMONEY: " + Format.Money(Economy.BalanceOf(product)); var profit = Economy.GetProfit(Q, product, true); var profitMinified = profit.Minify().MinifyValues(); text += "\n" + profit.ToString(); text += $"\n{GetGoals(product)}\n"; text = GetKeyFeatures(text, product); t.GetComponent <Text>().text = text; //AddIfAbsent<Hint>(t.gameObject).SetHint(profit.ToString()); }
void PayPlayerDividends(GameEntity e) { var dividends = Economy.BalanceOf(e); Companies.PayDividends(gameContext, e, dividends); }
bool IsBankrupt(GameEntity company) => Economy.BalanceOf(company) < 0;
public override string RenderValue() { return(Format.Minify(Economy.BalanceOf(MyGroupEntity))); }
public override string RenderValue() { //return "Cash\n" + Visuals.Colorize(Format.Money(Economy.BalanceOf(MyCompany)), profitable); return(Format.Minify(Economy.BalanceOf(MyCompany))); //return "Cash\n" + Format.Minify(Economy.BalanceOf(MyCompany)); }
public override string RenderValue() => Format.Minify(Economy.BalanceOf(MyCompany));
public override string RenderValue() { return(Format.Minify(Economy.BalanceOf(SelectedCompany))); }