コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: SharesQueries.cs プロジェクト: dqchess/Corporations
        public static long GetSharesCost(GameContext context, int companyId, int investorId)
        {
            var c = Get(context, companyId);

            int shares = GetAmountOfShares(context, companyId, investorId);
            int total  = GetTotalShares(c.shareholders.Shareholders);

            return(Economy.GetCompanyCost(context, c.company.Id) * shares / total);
        }
コード例 #3
0
        public static bool IsShareholderWillAcceptCorporationOffer(int companyId, int shareholderId, GameContext gameContext)
        {
            var cost = Economy.GetCompanyCost(gameContext, companyId);

            var baseDesireToSellCompany = GetBaseDesireToSellShares(gameContext, companyId, shareholderId);
            var wantsToSellShares       = true || baseDesireToSellCompany == 1;


            var corporationCost = Economy.GetCompanyCost(gameContext, companyId);
            var isSmallComparedToCorporation = cost * 100 < 15 * corporationCost;

            return(wantsToSellShares && isSmallComparedToCorporation);
        }
コード例 #4
0
ファイル: MarketSize.cs プロジェクト: dqchess/Corporations
        internal static long GetMarketSize(GameContext gameContext, NicheType nicheType)
        {
            var products = GetProductsOnMarket(gameContext, nicheType);

            try
            {
                var sum = products
                          .Sum(p => Economy.GetCompanyCost(gameContext, p.company.Id));

                return(sum);
            }
            catch
            {
                Debug.LogWarning("Get market size of " + Enums.GetFormattedNicheName(nicheType));
            }

            return(0);

            //return products.Select(p => CompanyEconomyUtils.GetProductCompanyBaseCost(gameContext, p.company.Id)).Sum();
        }
コード例 #5
0
        public static void SpawnProposals(GameContext context, int companyId)
        {
            long cost = Economy.GetCompanyCost(context, companyId);
            var  c    = Get(context, companyId);

            var potentialInvestors = GetPotentialInvestors(context, companyId);
            var investorsCount     = potentialInvestors.Length;

            foreach (var potentialInvestor in potentialInvestors)
            {
                var modifier = (50 + UnityEngine.Random.Range(0, 100));

                long valuation     = cost * modifier / 100;
                var  ShareholderId = potentialInvestor.shareholder.Id;

                long offer = valuation / 10;
                var  max   = GetMaxInvestingAmountForInvestorType(potentialInvestor);

                if (offer > max)
                {
                    offer = max;
                }

                var p = new InvestmentProposal
                {
                    Valuation     = valuation,
                    Offer         = valuation / 10,
                    ShareholderId = ShareholderId,
                    InvestorBonus = InvestorBonus.None,
                    WasAccepted   = false
                };

                // you cannot invest in yourself!
                if (c.hasShareholder && c.shareholder.Id == ShareholderId)
                {
                    continue;
                }

                AddInvestmentProposal(context, companyId, p);
            }
        }
コード例 #6
0
        internal static void AcceptInvestmentProposal(GameContext gameContext, int companyId, int investorId)
        {
            var p = GetInvestmentProposal(gameContext, companyId, investorId);

            //if (p == null)
            //    return;

            long cost = Economy.GetCompanyCost(gameContext, companyId);

            var  allShares = (long)GetTotalShares(gameContext, companyId);
            long shares    = allShares * p.Offer / cost;



            AddShareholder(gameContext, companyId, investorId, (int)shares);

            Economy.IncreaseCompanyBalance(gameContext, companyId, p.Offer);
            Economy.DecreaseInvestmentFunds(gameContext, investorId, p.Offer);

            MarkProposalAsAccepted(gameContext, companyId, investorId);
        }
コード例 #7
0
        public static void JoinCorporation(GameContext gameContext, int companyId, int buyerInvestorId)
        {
            var target      = Get(gameContext, companyId);
            var corporation = Investments.GetCompanyByInvestorId(gameContext, buyerInvestorId);

            var shareholders = GetShareholders(target);

            int[] array = new int[shareholders.Keys.Count];


            var corporationCost = Economy.GetCompanyCost(gameContext, corporation);
            var targetCost      = Economy.GetCompanyCost(gameContext, target);

            var corporationShares = Companies.GetTotalShares(gameContext, companyId);
            var emitedShares      = corporationShares * targetCost / corporationCost;

            // give shares in corporation to shareholders of integratable company
            foreach (var shareholderId in array)
            {
                var percentOfSharesInPreviousCompany = GetShareSize(gameContext, companyId, shareholderId);

                var newShare = emitedShares * percentOfSharesInPreviousCompany / 100;

                AddShares(gameContext, corporation, shareholderId, (int)newShare);
                Debug.Log($"investor {GetInvestorName(gameContext, shareholderId)} will get {(int)newShare} shares of corporation {corporation.company.Name}");
            }


            foreach (var shareholderId in array)
            {
                RemoveShareholder(target, shareholderId);
            }
            AddShareholder(gameContext, companyId, buyerInvestorId, 100);
            target.isIndependentCompany = false;

            NotifyAboutCorporateAcquisition(gameContext, buyerInvestorId, companyId);
        }
コード例 #8
0
 public static bool IsMeetsIPOCompanyCostRequirement(GameContext gameContext, int companyId)
 {
     return(Economy.GetCompanyCost(gameContext, companyId) > Balance.IPO_REQUIREMENTS_COMPANY_COST);
 }