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; } } } }
public static IEnumerable <ChannelInfo> GetTheoreticallyPossibleMarketingChannels(GameEntity product) { return (GetAllMarketingChannels(product) .Where(channel => !Marketing.IsActiveInChannel(product, channel.ID)) .Where(c => !product.team.Teams[0].Tasks.Any(t => t.IsPending && t.AreSameTasks(new TeamTaskChannelActivity(c.ID, 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)); };
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)) ); }