void RenderShareOfferSlider(AcquisitionConditions conditions, long price) { var ourCompanyCost = Economy.GetCompanyCost(Q, MyCompany); var sharePercent = conditions.ByShares; // ; var maxAllowedShareCost = 25 * ourCompanyCost / 100; var shareCost = Mathf.Clamp(sharePercent * price / 100, 0, maxAllowedShareCost); sharePercent = (int)(shareCost * 100 / price); Slider.minValue = 0; Slider.maxValue = 100; Slider.maxValue = Mathf.Clamp(maxAllowedShareCost * 100 / price, 0, 100); var sharePartOfCompany = shareCost * 100 / ourCompanyCost; var cash = price - shareCost; SharePercentage.text = $"You will pay {Format.Money(cash)} with cash and give {sharePartOfCompany}% of your company shares (worth ${Format.Money(shareCost)})"; }
void RenderProposalStatus(bool willAcceptOffer, long progress, AcquisitionConditions SellerOffer) { var cost = Economy.CostOf(SelectedCompany, Q); Response.text = $"Cash: {Format.Money(SellerOffer.Price)} (Real valuation = {Format.Money(cost)})"; var o = AcquisitionOffer; if (o.Turn == AcquisitionTurn.Seller) { // ProposalStatus Response.text += "\nThey will respond in a month or so"; //if (!ScheduleUtils.IsTimerRunning(Q)) // ProposalStatus.text += Visuals.Negative("Unpause") + " to get their response"; } //else //{ // //var status = $"{progress}% of owners want to accept your offer"; // //var textDescription = willAcceptOffer ? Visuals.Positive("They will accept offer!") : Visuals.Negative("They will not accept offer!"); // //ProposalStatus.text = status; // + "\n" + textDescription; //} ProgressText.text = progress + "%"; ProgressText.color = Visuals.GetColorPositiveOrNegative(willAcceptOffer); }
void DecreaseCompanyPrice(GameEntity offer, int targetId, int shareholderId) { var o = offer.acquisitionOffer; var cost = Economy.GetCompanyCost(gameContext, targetId); var Kmin = Companies.GetRandomAcquisitionPriceModifier(targetId, shareholderId); var Kbuyer = o.BuyerOffer.Price * 1f / cost; var Kseller = 2 * Kmin - Kbuyer; var KsellerRandomised = Kseller * Random.Range(0.85f, 1.15f); var newPrice = Mathf.Max(KsellerRandomised, Kmin, Kbuyer) * cost; var sellerConditions = new AcquisitionConditions { Price = (long)newPrice, ByCash = (long)newPrice, ByShares = 0, KeepLeaderAsCEO = o.SellerOffer.KeepLeaderAsCEO }; offer.ReplaceAcquisitionOffer(targetId, shareholderId, AcquisitionTurn.Buyer, o.BuyerOffer, sellerConditions); var investor = Investments.GetInvestorById(gameContext, shareholderId); if (investor.isControlledByPlayer) { NotificationUtils.AddPopup(gameContext, new PopupMessageAcquisitionOfferResponse(targetId, shareholderId)); } }
public static GameEntity CreateAcquisitionOffer(GameContext gameContext, int companyId, int buyerInvestorId) { var offer = gameContext.CreateEntity(); var cost = Economy.GetCompanyCost(gameContext, companyId); var buyerOffer = new AcquisitionConditions { Price = cost, ByCash = cost, ByShares = 0, KeepLeaderAsCEO = true }; var sellerOffer = new AcquisitionConditions { Price = cost * 4, ByCash = cost * 4, ByShares = 0, KeepLeaderAsCEO = true }; offer.AddAcquisitionOffer(companyId, buyerInvestorId, AcquisitionTurn.Buyer, buyerOffer, sellerOffer); var playerIsInvestor = GetInvestorById(gameContext, buyerInvestorId).isControlledByPlayer; if (playerIsInvestor) { Debug.Log("Create acquisition offer: " + GetCompanyName(gameContext, companyId)); } return(offer); }
void SendNewSellerOffer(GameEntity offer, GameEntity target, int shareholderId) { var o = offer.acquisitionOffer; var newPrice = GetNewPrice(target, shareholderId, o.BuyerOffer); var sellerConditions = new AcquisitionConditions { Price = newPrice, ByCash = newPrice, ByShares = 0, KeepLeaderAsCEO = o.SellerOffer.KeepLeaderAsCEO }; offer.acquisitionOffer.Turn = AcquisitionTurn.Buyer; offer.acquisitionOffer.SellerOffer = sellerConditions; //offer.ReplaceAcquisitionOffer(target.company.Id, shareholderId, AcquisitionTurn.Buyer, o.BuyerOffer, sellerConditions); var investor = Investments.GetInvestor(gameContext, shareholderId); if (investor.isControlledByPlayer) { NotificationUtils.AddPopup(gameContext, new PopupMessageAcquisitionOfferResponse(target.company.Id, shareholderId)); } }
public static GameEntity CreateAcquisitionOffer(GameContext gameContext, GameEntity company, GameEntity buyer) { var offer = gameContext.CreateEntity(); var cost = Economy.CostOf(company, gameContext); var buyerOffer = new AcquisitionConditions { Price = cost, ByCash = cost, ByShares = 0, KeepLeaderAsCEO = true }; var sellerOffer = new AcquisitionConditions { Price = cost * 4, ByCash = cost * 4, ByShares = 0, KeepLeaderAsCEO = true }; offer.AddAcquisitionOffer(company.company.Id, buyer.shareholder.Id, AcquisitionTurn.Buyer, buyerOffer, sellerOffer); if (buyer.isControlledByPlayer) { Debug.Log("Create acquisition offer: " + GetName(company)); } return(offer); }
public void ReplacePreviousAcquisitionOffers(AcquisitionConditions newBuyerOffer, AcquisitionConditions newSellerOffer) { var index = GameComponentsLookup.PreviousAcquisitionOffers; var component = (PreviousAcquisitionOffersComponent)CreateComponent(index, typeof(PreviousAcquisitionOffersComponent)); component.BuyerOffer = newBuyerOffer; component.SellerOffer = newSellerOffer; ReplaceComponent(index, component); }
void RespondToOffers(GameEntity[] offers, int offerCount) { var sortedOffers = offers.OrderByDescending(o => o.acquisitionOffer.BuyerOffer.Price); var maxOffer = sortedOffers.First(); var maxOfferedPrice = maxOffer.acquisitionOffer.BuyerOffer.Price; List <int> toRemove = new List <int>(); var CompanyId = maxOffer.acquisitionOffer.CompanyId; var newSellerOffer = new AcquisitionConditions { ByCash = maxOfferedPrice, Price = maxOfferedPrice, ByShares = 0, KeepLeaderAsCEO = true, }; for (var i = 0; i < offerCount; i++) { var o = offers[i]; var offer = o.acquisitionOffer; // increase prices to meet expectations var counterOffer = GetNewCounterOffer(o, CompanyId, offer.BuyerId, maxOfferedPrice); if (counterOffer.Price < maxOfferedPrice) { toRemove.Add(offer.BuyerId); continue; } o.ReplaceAcquisitionOffer( CompanyId, offer.BuyerId, AcquisitionTurn.Buyer, counterOffer, newSellerOffer); } foreach (var buyerId in toRemove) { Companies.RejectAcquisitionOffer(gameContext, CompanyId, buyerId); } var remainingOffers = Companies.GetAcquisitionOffersToCompany(gameContext, CompanyId); if (remainingOffers.Count() == 1) { Debug.Log("WON IN COMPETITION FOR COMPANY " + Companies.Get(gameContext, CompanyId)); AcceptOffer(CompanyId, remainingOffers.First().acquisitionOffer.BuyerId); } }
long GetNewPrice(GameEntity target, int shareholderId, AcquisitionConditions BuyerOffer) { var cost = Economy.CostOf(target, gameContext); var Kmin = Companies.GetRandomAcquisitionPriceModifier(target.company.Id, shareholderId); var Kbuyer = BuyerOffer.Price * 1f / cost; var Kseller = 2 * Kmin - Kbuyer; var KsellerRandomised = Kseller * Random.Range(0.85f, 1.15f); var newPrice = (double)Mathf.Max(KsellerRandomised, Kmin, Kbuyer) * cost; return((long)newPrice); }
AcquisitionConditions GetBestAcquisitionOffer(GameEntity[] offers, GameEntity target) { var sortedOffers = offers.OrderByDescending(o => o.acquisitionOffer.BuyerOffer.Price); var maxOffer = sortedOffers.First(); var maxOfferedPrice = maxOffer.acquisitionOffer.BuyerOffer.Price; var newSellerOffer = new AcquisitionConditions { ByCash = maxOfferedPrice, Price = maxOfferedPrice, ByShares = 0, KeepLeaderAsCEO = true, }; return(newSellerOffer); }
void RenderCashOffer(AcquisitionConditions BuyerOffer, AcquisitionTurn turn) { var cost = Economy.CostOf(SelectedCompany, Q); long price = BuyerOffer.Price; string overpriceText = ""; if (price > cost) { var overprice = Mathf.Ceil(price * 10 / cost); overpriceText = $" ({(overprice / 10)}x)"; } Offer.text = Format.Money(price) + overpriceText; CashOfferInput.text = price.ToString(); Draw(CashOfferInput, turn == AcquisitionTurn.Buyer); Draw(CashOfferContainer, turn == AcquisitionTurn.Buyer); }
void RenderShareOffer(AcquisitionConditions conditions) { long price = conditions.Price; SharesOfferInput.text = conditions.ByShares.ToString(); var ourCompanyCost = Economy.CostOf(MyCompany, Q); var maxAllowedShareCost = 25 * ourCompanyCost / 100; var shareCost = Mathf.Clamp(conditions.ByShares * price / 100, 0, maxAllowedShareCost); Slider.minValue = 0; Slider.maxValue = Mathf.Clamp(maxAllowedShareCost * 100 / price, 0, 100); var sharePartOfCompany = shareCost * 100 / ourCompanyCost; var cash = price - shareCost; SharePercentage.text = $"You will pay {Format.Money(cash)} with cash and give {sharePartOfCompany}% of your company shares (worth ${Format.Money(shareCost)})"; }
public void ReplaceAcquisitionOffer(int newCompanyId, int newBuyerId, AcquisitionTurn newTurn, AcquisitionConditions newBuyerOffer, AcquisitionConditions newSellerOffer) { var index = GameComponentsLookup.AcquisitionOffer; var component = (AcquisitionOfferComponent)CreateComponent(index, typeof(AcquisitionOfferComponent)); component.CompanyId = newCompanyId; component.BuyerId = newBuyerId; component.Turn = newTurn; component.BuyerOffer = newBuyerOffer; component.SellerOffer = newSellerOffer; ReplaceComponent(index, component); }
public static void TweakAcquisitionConditions(GameContext gameContext, int companyId, int buyerInvestorId, AcquisitionConditions newConditions) { var off = GetAcquisitionOffer(gameContext, companyId, buyerInvestorId); off.ReplaceAcquisitionOffer( companyId, buyerInvestorId, off.acquisitionOffer.Turn, newConditions, off.acquisitionOffer.SellerOffer ); }
public bool IsBetterThan(AcquisitionConditions offer) { return(this.Price >= offer.Price); }
public static void TweakAcquisitionConditions(GameContext gameContext, GameEntity company, GameEntity buyer, AcquisitionConditions newConditions) { var off = GetAcquisitionOffer(gameContext, company, buyer); off.ReplaceAcquisitionOffer( company.company.Id, buyer.shareholder.Id, off.acquisitionOffer.Turn, newConditions, off.acquisitionOffer.SellerOffer ); }