Esempio n. 1
0
        private static async Task ReleaseCharacterAsync(MainRepository repo, CharacterItem item, Character chara, CharacterItemStatus newStatus)
        {
            if ((item.Status != CharacterItemStatus.CharacterHold && item.Status != CharacterItemStatus.CharacterPending) || (chara != null && item.CharacterId != chara.Id))
            {
                return;
            }

            if (chara != null && item.Status == CharacterItemStatus.CharacterHold)
            {
                var strong     = (short)item.GetSumOfValues(CharacterItemEffectType.Strong);
                var intellect  = (short)item.GetSumOfValues(CharacterItemEffectType.Intellect);
                var leadership = (short)item.GetSumOfValues(CharacterItemEffectType.Leadership);
                var popularity = (short)item.GetSumOfValues(CharacterItemEffectType.Popularity);

                chara.Strong     -= strong;
                chara.Intellect  -= intellect;
                chara.Leadership -= leadership;
                chara.Popularity -= popularity;
            }

            item.Status      = newStatus;
            item.CharacterId = 0;

            if (newStatus == CharacterItemStatus.TownHidden || newStatus == CharacterItemStatus.TownOnSale)
            {
                if (chara == null)
                {
                    var towns = await repo.Town.GetAllAsync();

                    item.TownId = RandomService.Next(towns).Id;
                }
                else
                {
                    item.TownId = chara.TownId;
                }
            }

            if (chara != null)
            {
                await CharacterService.StreamCharacterAsync(repo, chara);
            }
            await StatusStreaming.Default.SendAllAsync(ApiData.From(item));
        }
Esempio n. 2
0
        public static async Task SetCharacterAsync(MainRepository repo, CharacterItem item, Character chara)
        {
            if (item.Status == CharacterItemStatus.CharacterHold)
            {
                if (item.CharacterId == chara.Id)
                {
                    return;
                }

                var oldChara = await repo.Character.GetByIdAsync(item.CharacterId);

                if (oldChara.HasData)
                {
                    await ReleaseCharacterAsync(repo, item, oldChara.Data);
                }
            }

            var strong     = (short)item.GetSumOfValues(CharacterItemEffectType.Strong);
            var intellect  = (short)item.GetSumOfValues(CharacterItemEffectType.Intellect);
            var leadership = (short)item.GetSumOfValues(CharacterItemEffectType.Leadership);
            var popularity = (short)item.GetSumOfValues(CharacterItemEffectType.Popularity);

            chara.Strong     += strong;
            chara.Intellect  += intellect;
            chara.Leadership += leadership;
            chara.Popularity += popularity;

            item.Status      = CharacterItemStatus.CharacterHold;
            item.CharacterId = chara.Id;
            item.TownId      = 0;

            var infoOptional = CharacterItemInfoes.Get(item.Type);

            if (infoOptional.HasData)
            {
                var info = infoOptional.Data;
                if (info.IsResource)
                {
                    var characterItems = await repo.Character.GetItemsAsync(chara.Id);

                    var resource = characterItems.FirstOrDefault(i => i.Id != item.Id && i.Status == CharacterItemStatus.CharacterHold && i.Type == item.Type);
                    if (resource != null)
                    {
                        // 2つの資源アイテムを統合
                        resource.Resource += item.Resource;
                        item.Status        = CharacterItemStatus.CharacterSpent;
                        item.CharacterId   = 0;
                        item.Resource      = 0;
                        await StatusStreaming.Default.SendAllAsync(ApiData.From(resource));
                    }
                    else
                    {
                        // 今の資源アイテムがそのまま所持物となる
                        item.IsAvailable = true;
                    }
                }
            }

            await CharacterService.StreamCharacterAsync(repo, chara);

            await StatusStreaming.Default.SendAllAsync(ApiData.From(item));
        }