public static decimal GetCompanyCost(this CountryPolicy policy, Entity entity) { switch (entity.GetEntityType()) { case EntityTypeEnum.Citizen: { return(policy.CitizenCompanyCost); } case EntityTypeEnum.Organisation: { return(policy.OrganisationCompanyCost); } case EntityTypeEnum.Country: { return(0m); } default: { throw new NotImplementedException(); } } }
public async Task SetCountryPolicyAsync( [FromBody] CountryPolicy param) { ErrorCode.NotSupportedError.Throw(); var info = CountryPolicyTypeInfoes.Get(param.Type); if (!info.HasData) { ErrorCode.InvalidParameterError.Throw(); } using (var repo = MainRepository.WithReadAndWrite()) { var system = await repo.System.GetAsync(); var chara = await repo.Character.GetByIdAsync(this.AuthData.CharacterId).GetOrErrorAsync(ErrorCode.LoginCharacterNotFoundError); var country = await repo.Country.GetAliveByIdAsync(chara.CountryId).GetOrErrorAsync(ErrorCode.CountryNotFoundError); var posts = await repo.Country.GetCharacterPostsAsync(chara.Id); if (!posts.Any(p => p.Type.CanPolicy())) { ErrorCode.NotPermissionError.Throw(); } var isSucceed = await CountryService.SetPolicyAndSaveAsync(repo, country, param.Type); if (!isSucceed) { ErrorCode.InvalidOperationError.Throw(); } } }
public ActualLawViewModel(CountryPolicy policy) { CurrencySymbol = Persistent.Countries.GetCountryCurrency(policy.CountryID).Symbol; CitizenFee = policy.CitizenFee; CitizenCompanyCost = policy.CitizenCompanyCost; OrganisationCompanyCost = policy.OrganisationCompanyCost; NormalJobMarketFee = policy.NormalJobMarketFee; ContractJobMarketFee = policy.ContractJobMarketFee; MinimumContractLength = policy.MinimumContractLength; MaximumContractLength = policy.MaximumContractLength; NormalCongressVotingWinPercentage = (double)policy.NormalCongressVotingWinPercentage; PartyFoundingFee = policy.PartyFoundingFee; PartyPresidentCadenceLength = policy.PartyPresidentCadenceLength; CongressCadenceLength = policy.CongressCadenceLength; CongressVotingLength = policy.CongressVotingLength; PresidentCadenceLength = policy.PresidentCadenceLength; OrganisationCreateCost = policy.OrganisationCreateCost; MarketOfferCost = policy.MarketOfferCost; NewspaperCreateCost = policy.NewspaperCreateCost; ArticleTax = (double)policy.ArticleTax; MonetaryTaxRate = (double)policy.MonetaryTaxRate; MinimumMonetaryTax = (double)policy.MinimumMonetaryTax; TreasuryLawAllowHolder = (LawAllowHolderEnum)policy.TreasuryVisibilityLawAllowHolderID; NationalCompanyBuildLawAllowHolder = (LawAllowHolderEnum)policy.CountryCompanyBuildLawAllowHolder; MinimalWage = policy.MinimalWage; }
public MonetaryOfferCost GetMonetaryOfferCost(int sellCurrencyID, int buyCurrencyID, int amount, double rate, MonetaryOfferTypeEnum offerType) { var usedCurrencyID = GetUsedCurrencyID(offerType, sellCurrencyID, buyCurrencyID); var currencyCountry = Persistent.Countries.FirstOrDefault(c => c.CurrencyID == usedCurrencyID); CountryPolicy policy = null; if (currencyCountry != null) { policy = countryRepository.GetCountryPolicyById(currencyCountry.ID); } var usedCurrency = Persistent.Currencies.GetById(usedCurrencyID); var offerCost = amount * (offerType == MonetaryOfferTypeEnum.Buy ? rate : 1); var tax = CalculateTax(offerCost, (double)(policy?.MonetaryTaxRate ?? 0), (double)(policy?.MinimumMonetaryTax ?? 0)); return(new MonetaryOfferCost() { OfferCost = offerCost, TaxCost = tax, Currency = usedCurrency }); }
private void AddMoreVotingTypesBasedOnPolicy(CountryPolicy countryPolicy) { if (countryPolicy.CountryCompanyBuildLawAllowHolder == (int)LawAllowHolderEnum.Congress || countryPolicy.CountryCompanyBuildLawAllowHolder == (int)LawAllowHolderEnum.PresidentAndCongress) { AddMoreVotingTypesBasedOnPolicy(VotingTypeEnum.CreateNationalCompany); } VotingTypes = VotingTypes.OrderBy(vt => vt.Text) .ToList(); }
public void CorrectBadPolicy_CorrectMaximumAccordingToMinimumTestBoth_Test() { var policy = new CountryPolicy() { MinimumContractLength = 66, MaximumContractLength = 20 }; countrySerivce.CorrectBadPolicy(ref policy); Assert.AreEqual(Constants.ContractMaximumLength, policy.MaximumContractLength); }
public void CorrectBadPolicy_CorrectMaximumContractLengthTooLong_Test() { var policy = new CountryPolicy() { MaximumContractLength = Constants.ContractMaximumLength + 50 }; countrySerivce.CorrectBadPolicy(ref policy); Assert.AreEqual(Constants.ContractMaximumLength, policy.MaximumContractLength); }
public void CorrectBadPolicy_CorrectMinimalContractLength_Test() { var policy = new CountryPolicy() { MinimumContractLength = 0 }; countrySerivce.CorrectBadPolicy(ref policy); Assert.AreEqual(Constants.ContractMinimumLength, policy.MinimumContractLength); }
public void CorrectBadPolicy_SmallMinimalVotingPercentage_Test() { var policy = new CountryPolicy() { NormalCongressVotingWinPercentage = 0.01m }; countrySerivce.CorrectBadPolicy(ref policy); Assert.AreEqual(Constants.MinimalVotingPercentage / 100m, policy.NormalCongressVotingWinPercentage); }
public void CorrectBadPolicy_CorrectOutOfBoundsVotingPercentage_Test() { decimal startPercentage = 1.1m; var policy = new CountryPolicy() { NormalCongressVotingWinPercentage = startPercentage }; countrySerivce.CorrectBadPolicy(ref policy); Assert.AreEqual(Constants.MaximalVotingPercentage / 100m, policy.NormalCongressVotingWinPercentage); }
public void CorrectBadPolicy_CorrectMinimalVotingPercentage_Test() { decimal startPercentage = 0.6m; var policy = new CountryPolicy() { NormalCongressVotingWinPercentage = startPercentage }; countrySerivce.CorrectBadPolicy(ref policy); Assert.AreEqual(startPercentage, policy.NormalCongressVotingWinPercentage); }
public CountryPolicyViewModel(CountryPolicy policy) { CountryName = policy.Country.Entity.Name; CountryID = policy.Country.ID; CitizenFee = (double)policy.CitizenFee; CitizenCompanyCost = (double)policy.CitizenCompanyCost; OrganisationCompanyCost = (double)policy.OrganisationCompanyCost; NormalJobMarketFee = (double)policy.NormalJobMarketFee; ContractJobMarketFee = (double)policy.ContractJobMarketFee; MinimumContractLength = policy.MinimumContractLength; MaximumContractLength = policy.MaximumContractLength; NormalCongressVotingWinPercentage = (double)policy.NormalCongressVotingWinPercentage; PartFoundingFee = (double)policy.PartyFoundingFee; PartyPresidentCadenceLength = policy.PartyPresidentCadenceLength; CongressCadenceLength = policy.CongressCadenceLength; CongressVotingLength = policy.CongressVotingLength; }
public MonetaryOffer CreateOffer(CreateMonetaryOfferParam param) { using (var transaction = transactionScopeProvider.CreateTransactionScope()) { if (param.IsValid == false) { throw new ArgumentException("Invalid CreateMonetaryOfferParam"); } int usedCurrencyID = getUsedCurrencyID(param); var country = Persistent.Countries.FirstOrDefault(c => c.CurrencyID == usedCurrencyID); CountryPolicy policy = null; if (country != null) { policy = countryRepository.GetCountryPolicyById(country.ID); } var entity = param.Seller; var offer = new MonetaryOffer() { Amount = param.Amount.Value, BuyCurrencyID = param.BuyCurrency.ID, OfferTypeID = (int)param.OfferType, Rate = (decimal)param.Rate.Value, SellCurrencyID = param.SellCurency.ID, SellerID = param.Seller.EntityID, Tax = policy?.MonetaryTaxRate ?? 0, MinimumTax = policy?.MinimumMonetaryTax ?? 0, TaxReservedMoney = (decimal)CalculateTax(param.Amount.Value * (param.OfferType == MonetaryOfferTypeEnum.Buy ? param.Rate.Value : 1), ((double?)policy?.MonetaryTaxRate) ?? 0.0, ((double?)policy?.MinimumMonetaryTax) ?? 0.0), OfferReservedMoney = (decimal)(param.Amount.Value * (param.OfferType == MonetaryOfferTypeEnum.Buy ? param.Rate.Value : 1)), AmountSold = 0, ValueOfSold = 0 }; ReserveMoneyFromEntity(entity, offer); monetaryOfferRepository.Add(offer); tryToBuySell(offer); monetaryOfferRepository.SaveChanges(); transaction.Complete(); return(offer); } }
public void CorrectBadPolicy(ref CountryPolicy policy) { if (policy.NormalCongressVotingWinPercentage < (Constants.MinimalVotingPercentage / 100m)) { policy.NormalCongressVotingWinPercentage = (Constants.MinimalVotingPercentage / 100m); } if (policy.NormalCongressVotingWinPercentage > (Constants.MaximalVotingPercentage / 100m)) { policy.NormalCongressVotingWinPercentage = (Constants.MaximalVotingPercentage / 100m); } if (policy.NormalCongressVotingWinPercentage > 1m) { policy.NormalCongressVotingWinPercentage = 1m; } if (policy.MinimumContractLength < Constants.ContractMinimumLength) { policy.MinimumContractLength = Constants.ContractMinimumLength; } if (policy.MinimumContractLength > Constants.ContractMaximumLength) { policy.MinimumContractLength = Constants.ContractMaximumLength; } //----------------------------------------------------------------------- if (policy.MaximumContractLength > Constants.ContractMaximumLength) { policy.MaximumContractLength = Constants.ContractMaximumLength; } if (policy.MaximumContractLength < policy.MinimumContractLength) { policy.MaximumContractLength = policy.MinimumContractLength; } }
public static async Task <bool> SetPolicyAndSaveAsync(MainRepository repo, Country country, CountryPolicyType type, CountryPolicyStatus status = CountryPolicyStatus.Available, bool isCheckSubjects = true) { return(true); var info = CountryPolicyTypeInfoes.Get(type); if (!info.HasData) { return(false); } var policies = await repo.Country.GetPoliciesAsync(country.Id); var old = policies.FirstOrDefault(p => p.Type == type); if (old != null && old.Status == CountryPolicyStatus.Available) { return(false); } var oldStatus = old?.Status ?? CountryPolicyStatus.Unadopted; if (status == CountryPolicyStatus.Available && country.PolicyPoint < info.Data.GetRequestedPoint(oldStatus)) { return(false); } if (isCheckSubjects && info.Data.SubjectAppear != null && !info.Data.SubjectAppear(policies.Where(p => p.Status == CountryPolicyStatus.Available).Select(p => p.Type))) { return(false); } var system = await repo.System.GetAsync(); var param = new CountryPolicy { CountryId = country.Id, Status = status, Type = type, GameDate = system.GameDateTime.Year >= Config.UpdateStartYear ? system.GameDateTime : new GameDateTime { Year = Config.UpdateStartYear, Month = 1, }, }; if (status == CountryPolicyStatus.Available) { country.PolicyPoint -= info.Data.GetRequestedPoint(oldStatus); if (info.Data.AvailableDuring > 0) { status = param.Status = CountryPolicyStatus.Availabling; } // 採用した瞬間に効果を発揮する政策 await RunCountryPolicyAsync(repo, country, type); } if (old != null) { repo.Country.RemovePolicy(old); } await repo.Country.AddPolicyAsync(param); await repo.SaveChangesAsync(); await StatusStreaming.Default.SendCountryAsync(ApiData.From(param), country.Id); await StatusStreaming.Default.SendCountryAsync(ApiData.From(country), country.Id); await StatusStreaming.Default.SendAllAsync(ApiData.From(new CountryForAnonymous(country))); foreach (CountryPolicyType boostType in info.Data.Effects.Where(e => e.Type == CountryPolicyEffectType.BoostWith).Select(e => e.Value)) { var boostInfo = CountryPolicyTypeInfoes.Get(boostType); if (boostInfo.HasData) { await SetPolicyAndSaveAsync(repo, country, boostType, CountryPolicyStatus.Boosted); } } return(true); }
/// <summary> /// 政策スライダーを構文解析する /// </summary> /// <param name="lexer">字句解析器</param> /// <returns>政策スライダー</returns> private static CountryPolicy ParsePolicy(TextLexer lexer) { // = Token token = lexer.GetToken(); if (token.Type != TokenType.Equal) { Log.InvalidToken(LogCategory, token, lexer); return null; } // { token = lexer.GetToken(); if (token.Type != TokenType.OpenBrace) { Log.InvalidToken(LogCategory, token, lexer); return null; } CountryPolicy policy = new CountryPolicy(); while (true) { token = lexer.GetToken(); // ファイルの終端 if (token == null) { break; } // } (セクション終端) if (token.Type == TokenType.CloseBrace) { break; } // 無効なトークン if (token.Type != TokenType.Identifier) { Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); continue; } string keyword = token.Value as string; if (string.IsNullOrEmpty(keyword)) { continue; } keyword = keyword.ToLower(); // date if (keyword.Equals("date")) { GameDate date = ParseDate(lexer); if (date == null) { Log.InvalidSection(LogCategory, "date", lexer); continue; } // スライダー移動可能日時 policy.Date = date; continue; } // democratic if (keyword.Equals("democratic")) { int? n = ParseInt(lexer); if (!n.HasValue) { Log.InvalidClause(LogCategory, "democratic", lexer); continue; } if (n < 1 || n > 10) { Log.OutOfRange(LogCategory, "democratic", n, lexer); continue; } // 民主的 - 独裁的 policy.Democratic = (int) n; continue; } // political_left if (keyword.Equals("political_left")) { int? n = ParseInt(lexer); if (!n.HasValue) { Log.InvalidClause(LogCategory, "political_left", lexer); continue; } if (n < 1 || n > 10) { Log.OutOfRange(LogCategory, "political_left", n, lexer); continue; } // 政治的左派 - 政治的右派 policy.PoliticalLeft = (int) n; continue; } // freedom if (keyword.Equals("freedom")) { int? n = ParseInt(lexer); if (!n.HasValue) { Log.InvalidClause(LogCategory, "freedom", lexer); continue; } if (n < 1 || n > 10) { Log.OutOfRange(LogCategory, "freedom", n, lexer); continue; } // 開放社会 - 閉鎖社会 policy.Freedom = (int) n; continue; } // free_market if (keyword.Equals("free_market")) { int? n = ParseInt(lexer); if (!n.HasValue) { Log.InvalidClause(LogCategory, "freedom", lexer); continue; } if (n < 1 || n > 10) { Log.OutOfRange(LogCategory, "freedom", n, lexer); continue; } // 自由経済 - 中央計画経済 policy.FreeMarket = (int) n; continue; } // professional_army if (keyword.Equals("professional_army")) { int? n = ParseInt(lexer); if (!n.HasValue) { Log.InvalidClause(LogCategory, "professional_army", lexer); continue; } if (n < 1 || n > 10) { Log.OutOfRange(LogCategory, "professional_army", n, lexer); continue; } // 常備軍 - 徴兵軍 (DH Fullでは動員 - 復員) policy.ProfessionalArmy = (int) n; continue; } // defense_lobby if (keyword.Equals("defense_lobby")) { int? n = ParseInt(lexer); if (!n.HasValue) { Log.InvalidClause(LogCategory, "defense_lobby", lexer); continue; } if (n < 1 || n > 10) { Log.OutOfRange(LogCategory, "defense_lobby", n, lexer); continue; } // タカ派 - ハト派 policy.DefenseLobby = (int) n; continue; } // interventionism if (keyword.Equals("interventionism")) { int? n = ParseInt(lexer); if (!n.HasValue) { Log.InvalidClause(LogCategory, "interventionism", lexer); continue; } if (n < 1 || n > 10) { Log.OutOfRange(LogCategory, "interventionism", n, lexer); continue; } // 介入主義 - 孤立主義 policy.Interventionism = (int) n; continue; } // 無効なトークン Log.InvalidToken(LogCategory, token, lexer); lexer.SkipLine(); } return policy; }