예제 #1
0
        public static void InitializeTeamTaskIfNotPending(GameEntity product, int date, GameContext gameContext, TeamTask task)
        {
            if (task.IsPending)
                return;

            task.StartDate = date;

            if (task.IsMarketingTask)
            {
                var channelId = (task as TeamTaskChannelActivity).ChannelId;
                var channel = Markets.GetMarketingChannel(gameContext, channelId);

                if (!Marketing.IsActiveInChannel(product, channelId))
                {
                    var cost = Marketing.GetChannelCost(product, channelId);
                    var payer = Companies.GetPayer(product, gameContext);

                    if (Companies.Pay(payer, cost, "Marketing " + channel))
                    {
                        Marketing.EnableChannelActivity(product, channel);

                        var gain = Marketing.GetChannelClientGain(product, channelId);
                        Marketing.AddClients(product, gain);

                        var duration = Marketing.GetCampaignDuration(product, gain);
                        task.EndDate = date + duration;
                    }
                }
            }
        }
예제 #2
0
        public static Func <ChannelInfo, bool> IsCanAffordChannel(GameEntity company, long spareBudget) => c =>
        {
            var adCost = Marketing.GetChannelCost(company, c.ID);

            if (adCost == 0)
            {
                return(true);
            }

            return(spareBudget > adCost);
        };
예제 #3
0
        public static Func <ChannelInfo, bool> IsCanMaintainChannel(GameEntity company, long spareBudget) => c =>
        {
            var adCost = Marketing.GetChannelCost(company, c.ID);

            if (adCost == 0)
            {
                return(true);
            }

            return(spareBudget > adCost || Marketing.IsActiveInChannel(company, c.ID));
        };
예제 #4
0
        public static IEnumerable <ChannelInfo> GetMaintainableMarketingChannels(GameEntity product, GameContext gameContext)
        {
            var payer   = product.isFlagship ? Companies.GetPlayerCompany(gameContext) : product;
            int periods = product.isFlagship ? 10 * 4 : 1;

            var profit      = Economy.GetProfit(gameContext, payer);
            var spareBudget = profit;

            var channels = new List <ChannelInfo>();

            var allChannels  = GetAllMarketingChannels(product).OrderBy(c => Marketing.GetChannelCost(product, c.ID)).ToList();
            var spareBudget2 = Economy.BalanceOf(payer); // spareBudget +

            if (profit < 0)
            {
                spareBudget2 += profit;
            }

            for (var i = 0; i < allChannels.Count(); i++)
            {
                var c      = allChannels[i];
                var adCost = Marketing.GetChannelCost(product, c.ID);

                if (Marketing.IsActiveInChannel(product, c.ID) || adCost == 0)
                {
                    channels.Add(c);
                    continue;
                }

                // 5, cause some channels take too much time to recover
                if (adCost > spareBudget2)
                {
                    if (product.isFlagship)
                    {
                        //Debug.Log("not enough money for " + c.ID + " " + Format.Money(adCost * 3) + " spare=" + Format.Money(spareBudget2));
                    }
                    break;
                }

                channels.Add(c);
                spareBudget2 -= adCost;
            }

            return(channels);

            return(allChannels
                   .Where(IsCanMaintainChannel(product, spareBudget))
                   );
        }
예제 #5
0
        public static TeamResource GetTaskCost(GameEntity company, TeamTask teamTask, GameContext gameContext)
        {
            if (teamTask.IsFeatureUpgrade)
            {
                var cost = GetFeatureUpgradeCost(company, teamTask);

                return new TeamResource(0, 0, 0, cost, 0);
            }

            if (teamTask.IsMarketingTask)
            {
                var cost = Marketing.GetChannelCost(company, (teamTask as TeamTaskChannelActivity).ChannelId);

                return new TeamResource(cost);
            }

            return new TeamResource(0);
        }