Exemple #1
0
        private async Task <WareModel> Computed(WareEntity ware, PlayerWareEntity playerWare)
        {
            var wareModel = _mapper.Map <WareModel>(ware);

            wareModel.PlayerWareId = playerWare.Id;
            wareModel.Number       = playerWare.Number;
            wareModel.Status       = playerWare.Status;

            var wareEffectAttr = new WareEffectAttr();
            var effects        = JsonConvert.DeserializeObject <List <WareEffect> >(ware.Effect);

            foreach (var effect in effects)
            {
                foreach (var attr in effect.Attrs)
                {
                    int.TryParse(attr.Val, out int val);

                    switch (attr.Attr)
                    {
                    case "Atk":
                        wareEffectAttr.Atk += val;
                        break;

                    case "Def":
                        wareEffectAttr.Def += val;
                        break;

                    case "Hp":
                        wareEffectAttr.Hp += val;
                        break;

                    case "Mp":
                        wareEffectAttr.Mp += val;
                        break;
                    }
                }
            }

            wareModel.WareEffect = wareEffectAttr;

            return(await Task.FromResult(wareModel));
        }
Exemple #2
0
        private async Task <WareEffectAttr> Computed(int playerId)
        {
            var wareEffectAttr = new WareEffectAttr();
            var playerWares    = await _playerWareDomainService.GetAll(playerId);

            var ids = playerWares.Where(x => x.Status == WareStatusEnum.装备).Select(x => x.WareId).ToList();

            var wareQuery = await _wareDomainService.GetAll();

            var wares = wareQuery.Where(x => ids.Contains(x.Id));

            foreach (var item in wares)
            {
                var effects = JsonConvert.DeserializeObject <List <WareEffect> >(item.Effect);
                foreach (var effect in effects)
                {
                    foreach (var attr in effect.Attrs)
                    {
                        int.TryParse(attr.Val, out int val);

                        switch (attr.Attr)
                        {
                        case "Atk":
                            wareEffectAttr.Atk += val;
                            break;

                        case "Def":
                            wareEffectAttr.Def += val;
                            break;
                        }
                    }
                }
            }

            return(wareEffectAttr);
        }