Пример #1
0
        public override async Task InputAsync(MainRepository repo, uint characterId, IEnumerable <GameDateTime> gameDates, params CharacterCommandParameter[] options)
        {
            var type = (FormationType)options.FirstOrDefault(p => p.Type == 1).Or(ErrorCode.LackOfCommandParameter).NumberValue;
            var info = FormationTypeInfoes.Get(type);

            if (!info.HasData)
            {
                ErrorCode.InvalidCommandParameter.Throw();
            }
            await repo.CharacterCommand.SetAsync(characterId, this.Type, gameDates, options);
        }
Пример #2
0
        public override async Task ExecuteAsync(MainRepository repo, Character character, IEnumerable <CharacterCommandParameter> options, CommandSystemData game)
        {
            var formationTypeOptional = options.FirstOrDefault(p => p.Type == 1).ToOptional();

            if (!formationTypeOptional.HasData)
            {
                await game.CharacterLogAsync("陣形変更のパラメータが不正です。<emerge>管理者にお問い合わせください</emerge>");
            }
            else
            {
                var type = (FormationType)formationTypeOptional.Data.NumberValue;
                var info = FormationTypeInfoes.Get(type);

                if (!info.HasData)
                {
                    await game.CharacterLogAsync($"ID: {(short)type} の陣形が見つかりません。<emerge>管理者にお問い合わせください</emerge>");

                    return;
                }
                if (type == character.FormationType)
                {
                    await game.CharacterLogAsync("すでにその陣形になっています");

                    return;
                }

                var formations = await repo.Character.GetFormationsAsync(character.Id);

                if (type != FormationType.Normal && !formations.Any(f => f.Type == type))
                {
                    await game.CharacterLogAsync($"陣形 {info.Data.Name} はまだ獲得していません");

                    return;
                }

                character.Contribution += 30;
                character.AddLeadershipEx(50);
                character.SkillPoint++;
                character.FormationType = type;
                await game.CharacterLogAsync($"陣形を {info.Data.Name} に変更しました");
            }
        }
Пример #3
0
        public static async Task <string> SpendCharacterAsync(MainRepository repo, CharacterItem item, Character chara, bool isWithEffect = true)
        {
            await ReleaseCharacterAsync(repo, item, chara, CharacterItemStatus.CharacterSpent);

            if (!isWithEffect)
            {
                return(string.Empty);
            }

            var info = item.GetInfo();

            if (info.HasData && info.Data.UsingEffects != null)
            {
                var logs = new List <string>();
                foreach (var effect in info.Data.UsingEffects)
                {
                    if (effect.Type == CharacterItemEffectType.Money)
                    {
                        chara.Money += effect.Value;
                        logs.Add($"金 <num>+{effect.Value}</num>");
                    }
                    if (effect.Type == CharacterItemEffectType.SkillPoint)
                    {
                        chara.SkillPoint += effect.Value;
                        logs.Add($"技能P <num>+{effect.Value}</num>");
                    }
                    if (effect.Type == CharacterItemEffectType.TerroristEnemy)
                    {
                        await repo.DelayEffect.AddAsync(new DelayEffect
                        {
                            Type = DelayEffectType.TerroristEnemy,
                        });

                        logs.Add($"異民族敵性化");
                    }
                    if (effect.Type == CharacterItemEffectType.AppearKokin)
                    {
                        await repo.DelayEffect.AddAsync(new DelayEffect
                        {
                            Type = DelayEffectType.AppearKokin,
                        });

                        logs.Add($"黄巾出現");
                    }
                    if (effect.Type == CharacterItemEffectType.DiscountSoldierPercentageWithResource)
                    {
                        logs.Add("特定兵種割引");
                    }
                    if (effect.Type == CharacterItemEffectType.FormationEx)
                    {
                        var formation = await repo.Character.GetFormationAsync(chara.Id, chara.FormationType);

                        if (formation != null)
                        {
                            var i = FormationTypeInfoes.Get(chara.FormationType);
                            if (i.HasData)
                            {
                                formation.Experience += effect.Value;
                                i.Data.CheckLevelUp(formation);
                                await StatusStreaming.Default.SendCharacterAsync(ApiData.From(formation), chara.Id);

                                logs.Add($"陣形経験値 <num>{effect.Value}</num>");
                            }
                        }
                    }
                    if (effect.Type == CharacterItemEffectType.IntellectEx)
                    {
                        chara.AddIntellectEx((short)effect.Value);
                        logs.Add($"知力経験値 <num>{effect.Value}</num>");
                    }
                    if (effect.Type == CharacterItemEffectType.AddSubBuildingExtraSize)
                    {
                        var townOptional = await repo.Town.GetByIdAsync(chara.TownId);

                        if (townOptional.HasData)
                        {
                            townOptional.Data.TownSubBuildingExtraSpace += (short)effect.Value;
                            logs.Add($"<town>{townOptional.Data.Name}</town> の敷地 <num>+{effect.Value}</num>");
                            await StatusStreaming.Default.SendTownToAllAsync(ApiData.From(townOptional.Data), repo);
                        }
                        else
                        {
                            logs.Add($"<emerge>エラー: 都市が見つかりませんでした ID: {chara.TownId}</emerge>");
                        }
                    }
                    if (effect.Type == CharacterItemEffectType.CheckGyokuji)
                    {
                        var countries = await repo.Country.GetAllAsync();

                        var country = countries.FirstOrDefault(c => c.GyokujiStatus == CountryGyokujiStatus.HasGenuine);
                        if (country != null)
                        {
                            logs.Add($"本物の玉璽を所持する国: <country>{country.Name}</country>");
                        }
                        else
                        {
                            logs.Add("本物の玉璽を所持する国: なし");
                        }
                    }
                    if (effect.Type == CharacterItemEffectType.Skill)
                    {
                        var i = CharacterSkillInfoes.Get((CharacterSkillType)effect.Value);
                        if (i.HasData)
                        {
                            var skills = await repo.Character.GetSkillsAsync(chara.Id);

                            if (!skills.Any(s => s.Status == CharacterSkillStatus.Available && (int)s.Type == effect.Value))
                            {
                                var skill = new CharacterSkill
                                {
                                    CharacterId = chara.Id,
                                    Status      = CharacterSkillStatus.Available,
                                    Type        = (CharacterSkillType)effect.Value,
                                };
                                await repo.Character.AddSkillAsync(skill);

                                await StatusStreaming.Default.SendCharacterAsync(ApiData.From(skill), chara.Id);
                            }
                            logs.Add("技能 " + i.Data.Name);
                        }
                        else
                        {
                            logs.Add($"<emerge>エラー: {effect.Value} の技能は存在しません。管理者にお問い合わせください");
                        }
                    }
                }

                return(logs.Count > 0 ? string.Join("と", logs) : string.Empty);
            }

            return(string.Empty);
        }
Пример #4
0
        public override async Task ExecuteAsync(MainRepository repo, Character character, IEnumerable <CharacterCommandParameter> options, CommandSystemData game)
        {
            var formationTypeOptional = options.FirstOrDefault(p => p.Type == 1).ToOptional();

            if (!formationTypeOptional.HasData)
            {
                await game.CharacterLogAsync("陣形獲得のパラメータが不正です。<emerge>管理者にお問い合わせください</emerge>");
            }
            //else if (character.Money < 1000)
            //{
            //  await game.CharacterLogAsync("陣形獲得の金が足りません");
            //}
            else
            {
                var countryOptional = await repo.Country.GetAliveByIdAsync(character.CountryId);

                var type = (FormationType)formationTypeOptional.Data.NumberValue;
                var info = FormationTypeInfoes.Get(type);

                if (!info.HasData)
                {
                    await game.CharacterLogAsync($"ID: {(short)type} の陣形が見つかりません。<emerge>管理者にお問い合わせください</emerge>");

                    return;
                }
                if (!info.Data.CanGetByCommand)
                {
                    await game.CharacterLogAsync($"陣形 {info.Data.Name} は、コマンドからは獲得できません");

                    return;
                }
                if (!info.Data.IsAvailable)
                {
                    await game.CharacterLogAsync($"陣形 {info.Data.Name} は、現在無効です。<emerge>管理者にお問い合わせください</emerge>");

                    return;
                }

                var formations = await repo.Character.GetFormationsAsync(character.Id);

                if (formations.Any(f => f.Type == type))
                {
                    await game.CharacterLogAsync($"陣形 {info.Data.Name} は、すでに獲得しています");

                    return;
                }
                if (info.Data.SubjectAppear != null && !info.Data.SubjectAppear(formations))
                {
                    await game.CharacterLogAsync($"陣形 {info.Data.Name} の獲得に必要な条件を満たしていません");

                    return;
                }

                var skills = await repo.Character.GetSkillsAsync(character.Id);

                var formationMax = 2 + skills.GetSumOfValues(CharacterSkillEffectType.FormationMax);
                if (formations.Count(f => f.Type != FormationType.Normal) + 1 > formationMax)
                {
                    await game.CharacterLogAsync($"陣形 {info.Data.Name} を獲得しようとしましたが、あなたが一度に所有できる陣形は {formationMax} までです");

                    return;
                }

                if (countryOptional.HasData)
                {
                    character.Contribution += 30;
                }
                character.AddLeadershipEx(50);
                //character.Money -= 1000;
                character.SkillPoint++;

                var formation = new Formation
                {
                    Type        = type,
                    CharacterId = character.Id,
                    Level       = 1,
                };
                await repo.Character.AddFormationAsync(formation);

                await repo.SaveChangesAsync();

                await StatusStreaming.Default.SendCharacterAsync(ApiData.From(formation), character.Id);

                await game.CharacterLogAsync($"陣形 {info.Data.Name} を獲得しました");
            }
        }
Пример #5
0
        private static void CheckEntryStatus(GameDateTime current, string ipAddress, Character chara, string password, CharacterIcon icon, Town town, Country country, bool isCountryFree)
        {
            if (string.IsNullOrEmpty(ipAddress))
            {
                ErrorCode.InvalidIpAddressError.Throw();
            }

            if (string.IsNullOrEmpty(password))
            {
                ErrorCode.LackOfParameterError.Throw();
            }
            if (password.Length < 4 || password.Length > 12)
            {
                ErrorCode.StringLengthError.Throw(new ErrorCode.RangeErrorParameter("password", password.Length, 4, 12));
            }
            if (string.IsNullOrEmpty(chara.Name))
            {
                ErrorCode.LackOfNameParameterError.Throw();
            }
            if (chara.Name.Contains('_'))
            {
                ErrorCode.NotPermissionError.Throw();
            }
            if (chara.Name.Length < 1 || chara.Name.Length > 12)
            {
                ErrorCode.StringLengthError.Throw(new ErrorCode.RangeErrorParameter("name", chara.Name.Length, 1, 12));
            }
            if (string.IsNullOrEmpty(chara.AliasId))
            {
                ErrorCode.LackOfParameterError.Throw();
            }
            if (chara.AliasId.Length < 4 || chara.AliasId.Length > 12)
            {
                ErrorCode.StringLengthError.Throw(new ErrorCode.RangeErrorParameter("aliasId", chara.AliasId.Length, 4, 12));
            }

            if (icon.Type == CharacterIconType.Default)
            {
                var iconIdStr = icon.FileName.Split('.');
                if (uint.TryParse(iconIdStr[0], out uint iconId))
                {
                    if (iconId < 0 || iconId > 99)
                    {
                        ErrorCode.CharacterIconNotFoundError.Throw();
                    }
                }
                else
                {
                    ErrorCode.CharacterIconNotFoundError.Throw();
                }
            }
            else if (icon.Type == CharacterIconType.Gravatar)
            {
                if (string.IsNullOrEmpty(icon.FileName))
                {
                    ErrorCode.LackOfParameterError.Throw();
                }
            }
            else
            {
                ErrorCode.InvalidParameterError.Throw();
            }

            if (chara.From == CharacterFrom.Unknown)
            {
                ErrorCode.LackOfParameterError.Throw();
            }

            var formation = FormationTypeInfoes.Get(chara.FormationType);

            if (formation.HasData)
            {
                if (!formation.Data.IsAvailable)
                {
                    ErrorCode.InvalidParameterError.Throw();
                }
            }

            var attributeMax    = GetAttributeMax(current);
            var attributeSumMax = GetAttributeSumMax(current);

            if (chara.Strong < 5 || chara.Intellect < 5 || chara.Leadership < 5 || chara.Popularity < 5)
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("attribute", 0, 5, attributeMax));
            }
            if (chara.Strong > attributeMax || chara.Intellect > attributeMax || chara.Leadership > attributeMax || chara.Popularity > attributeMax)
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("attribute", 0, 5, attributeMax));
            }
            if (chara.Strong + chara.Intellect + chara.Leadership + chara.Popularity < attributeSumMax - 2) // -2は新規登録情報入力途中に変動した場合の対応
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("sumOfAttribute", 0, attributeSumMax, attributeSumMax));
            }
            if (chara.Strong + chara.Intellect + chara.Leadership + chara.Popularity > attributeSumMax)
            {
                ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("sumOfAttribute", 0, attributeSumMax, attributeSumMax));
            }

            if (country != null && (!string.IsNullOrEmpty(country.Name) || country.CountryColorId != 0))
            {
                if (country.CountryColorId < 1 || country.CountryColorId > Config.CountryColorMax)
                {
                    ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("countryColor", country.CountryColorId, 1, Config.CountryColorMax));
                }
                if (string.IsNullOrEmpty(country.Name) || country.Name.Length < 1 || country.Name.Length > 8)
                {
                    ErrorCode.NumberRangeError.Throw(new ErrorCode.RangeErrorParameter("countryName", country.Name.Length, 1, 8));
                }
                if (town.CountryId > 0)
                {
                    ErrorCode.CantPublisAtSuchTownhError.Throw();
                }
            }
            else
            {
                if (town.CountryId <= 0 && !isCountryFree)
                {
                    ErrorCode.CantJoinAtSuchTownhError.Throw();
                }
            }
        }