Example #1
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);
        }