Example #1
0
        private async Task Fighting(NpcEntity npc, PlayerEntity player)
        {
            var npcFightingPlayerId = await _redisDb.StringGet <int>(string.Format(RedisKey.NpcFighting, npc.Id));

            if (npcFightingPlayerId != player.Id)
            {
                await _mudProvider.ShowMessage(player.Id, $"【切磋】{npcFightingPlayerId},{player.Id},{npc.Id}");
                await StopAction(npc.Id);

                return;
            }

            await _mudProvider.ShowMessage(player.Id, $"【切磋】[{npc.Name}]正在攻击你。。。");


            await _mudProvider.AddFightingTarget(player.Id, new FightingTargetModel
            {
                TargetId   = npc.Id,
                TargetName = npc.Name,
                Hp         = npc.Hp,
                Mp         = npc.Mp,
                MaxHp      = npc.MaxHp,
                MaxMp      = npc.MaxMp,
                TargetType = TargetTypeEnum.Npc
            });
        }
Example #2
0
        public async Task Handle(MovedEvent message, CancellationToken cancellationToken)
        {
            var player  = message.Player;
            var roomIn  = message.RoomIn;
            var roomOut = message.RoomOut;

            //更新玩家在线数据
            await _chatOnlineProvider.SetPlayerOnline(new PlayerOnlineModel
            {
                IsOnline   = true,
                LastDate   = DateTime.Now,
                Level      = player.Level,
                PlayerName = player.Name,
                PlayerId   = player.Id,
                RoomId     = player.RoomId,
                Gender     = player.Gender,
                Title      = player.Title
            });

            //更新玩家聊天房间
            await _mudProvider.RemoveFromRoom(player.Id, roomOut.Id);

            await _mudProvider.AddToRoom(player.Id, roomIn.Id);

            //更新新房间玩家列表
            var playersIn = await _chatOnlineProvider.GetPlayerList(roomIn.Id);

            await _mudProvider.UpdateRoomPlayerList(roomIn.Id, playersIn);

            //更新旧房间玩家列表
            var playersOut = await _chatOnlineProvider.GetPlayerList(roomOut.Id);

            await _mudProvider.UpdateRoomPlayerList(roomOut.Id, playersOut);


            var roomModel = _mapper.Map <RoomModel>(roomIn);

            await _mudProvider.Move(player.Id, roomModel);

            //更新当前玩家显示的npc列表
            var nps = (await _npcDomainService.GetAll()).Where(x => x.RoomId == roomIn.Id);
            await _mudProvider.UpdatePlayerRoomNpcList(player.Id, nps);


            //输出移动信息
            await _mudProvider.ShowMessage(player.Id, $"你来到了{roomIn.Name}。");

            await _mudProvider.ShowRoomOthersMessage(roomIn.Id, player.Id, $"[{player.Name}] 从{roomOut.Name}走了过来。");

            await _mudProvider.ShowRoomOthersMessage(roomOut.Id, player.Id, $"[{player.Name}] 往{roomIn.Name}离开。");
        }
Example #3
0
        public async Task Execute(int playerId)
        {
            var player = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                _logger.LogDebug($"player == null");
                return;
            }

            var level      = player.Level;
            var levelUpExp = (level * level * level + 60) / 5 * (level * 2 + 60) - 600;

            if (levelUpExp <= player.Exp)
            {
                player.Level += 1;
                player.Point += 1;

                player.Computed();

                await _playerDomainService.Update(player);

                await _bus.RaiseEvent(new PlayerStatusChangedEvent(player)).ConfigureAwait(false);

                await _mudProvider.ShowMessage(player.Id, $"恭喜你升级到 Lv{ player.Level }。");
            }
        }
Example #4
0
        public async Task Execute(NpcStatusModel model)
        {
            int playerId = model.TargetId;
            int npcId    = model.NpcId;
            var player   = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await StopAction(npcId);

                return;
            }
            var npc = await _npcDomainService.Get(npcId);

            if (npc == null)
            {
                await StopAction(npcId);

                return;
            }

            var npcFightingPlayerId = await _redisDb.StringGet <int>(string.Format(RedisKey.NpcFighting, npc.Id));

            if (npcFightingPlayerId != playerId)
            {
                await _mudProvider.ShowMessage(player.Id, $"【切磋】{npcFightingPlayerId},{playerId},{npcId}");
                await StopAction(npcId);

                return;
            }

            await _mudProvider.ShowMessage(player.Id, $"【切磋】[{npc.Name}]正在攻击你。。。");


            await _mudProvider.AddFightingTarget(player.Id, new FightingTargetModel
            {
                TargetId   = npcId,
                TargetName = npc.Name,
                Hp         = npc.Hp,
                Mp         = npc.Mp,
                MaxHp      = npc.MaxHp,
                MaxMp      = npc.MaxMp,
                TargetType = TargetTypeEnum.Npc
            });
        }
Example #5
0
        private async Task DoCommand(PlayerEntity player, NpcEntity npc, int scriptId, string command, List <CaseAttribute> attrs, string input)
        {
            var title   = attrs.FirstOrDefault(x => x.Attr == "Title")?.Val;
            var message = attrs.FirstOrDefault(x => x.Attr == "Message")?.Val;
            var tips    = attrs.FirstOrDefault(x => x.Attr == "Tips")?.Val;

            int.TryParse(attrs.FirstOrDefault(x => x.Attr == "CommandId")?.Val, out int commandId);
            int.TryParse(attrs.FirstOrDefault(x => x.Attr == "QuestId")?.Val, out int questId);



            var key        = $"commandIds_{player.Id}_{npc.Id}_{scriptId}";
            var commandIds = await _redisDb.StringGet <List <int> >(key) ?? new List <int>();

            if (commandId > 0 && !commandIds.Contains(commandId))
            {
                commandIds.Add(commandId);
            }

            await _redisDb.StringSet(key, commandIds);

            var commandEnum = (CommandTypeEnum)Enum.Parse(typeof(CommandTypeEnum), command, true);

            //await _bus.RaiseEvent(new DomainNotification($"command= {command}"));
            switch (commandEnum)
            {
            case CommandTypeEnum.播放对话:
                await _mudProvider.ShowMessage(player.Id, $"{npc.Name}:{message}", MessageTypeEnum.聊天);

                break;

            case CommandTypeEnum.对话选项:
                await _mudProvider.ShowMessage(player.Id, $" → <a href='javascript:;' class='chat' npcId='{npc.Id}' scriptId='{scriptId}' commandId='{commandId}'>{title}</a><br />", MessageTypeEnum.指令);

                break;

            case CommandTypeEnum.输入选项:
                await _mudProvider.ShowMessage(player.Id, $" → <a href = 'javascript:;'>{tips}</a>  <input type = 'text' name='input' style='width:120px;margin-left:10px;' />  <button type = 'button' class='input' style='padding:1px 3px;' npcId='{npc.Id}'  scriptId='{scriptId}'  commandId='{commandId}'> 确定 </button><br />", MessageTypeEnum.指令);

                break;

            case CommandTypeEnum.跳转到分支:
                await DoScript(player, npc, scriptId, commandId);

                break;


            case CommandTypeEnum.领取任务:
                await TakeQuest(player, questId);

                break;

            case CommandTypeEnum.完成任务:
                await ComplateQuest(player, questId);

                break;
            }
        }
Example #6
0
        public async Task Execute(PlayerStatusModel model)
        {
            int playerId = model.PlayerId;
            var player   = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                _logger.LogDebug($"player == null");
                return;
            }

            var online = await _mudOnlineProvider.GetPlayerOnline(playerId);

            if (online == null)
            {
                //玩家离线后,从队列删除,并且修改状态为空闲
                await _recurringQueue.Remove <PlayerStatusModel>(playerId);

                if (player.Status != PlayerStatusEnum.空闲)
                {
                    player.Status = PlayerStatusEnum.空闲;
                    await _playerDomainService.Update(player);

                    await _bus.RaiseEvent(new PlayerStatusChangedEvent(player)).ConfigureAwait(false);
                }
                return;
            }

            if (player.Status != model.Status)
            {
                await _recurringQueue.Remove <PlayerStatusModel>(playerId);

                return;
            }


            //TODO
            switch (model.Status)
            {
            case PlayerStatusEnum.伐木:

                break;
            }

            await _mudProvider.ShowMessage(playerId, $"你正在{model.Status}。。。");
        }
Example #7
0
        public async Task <Unit> Handle(SearchCommand command, CancellationToken cancellationToken)
        {
            var playerId = command.PlayerId;

            await _mudProvider.ShowMessage(playerId, "你什么也没发现。。。");

            if (await Commit())
            {
                //新手任务
                var searchTimes = await _redisDb.StringGet <int>(string.Format(RedisKey.SearchTimes, playerId));

                if (searchTimes <= 0)
                {
                    await _queueHandler.SendQueueMessage(new CompleteQuestNewbieQuestQueue(playerId, NewbieQuestEnum.第一次探索));
                }
                searchTimes++;
                await _redisDb.StringSet(string.Format(RedisKey.SearchTimes, playerId), searchTimes);
            }
            return(Unit.Value);
        }
        private async Task Friend(PlayerEntity player, PlayerEntity relation)
        {
            if (await _redisDb.StringGet <int>(string.Format(RedisKey.RefuseFriend, player.Id, relation.Id)) > 0)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】[{relation.Name}]已拒绝你的申请。");

                return;
            }

            //我加对方
            var playerRelationFrom = await _playerRelationDomainService.Get(x => x.PlayerId == player.Id &&
                                                                            x.RelationId == relation.Id &&
                                                                            x.Type == PlayerRelationTypeEnum.好友);

            //对方加我
            var playerRelationTo = await _playerRelationDomainService.Get(x => x.PlayerId == relation.Id &&
                                                                          x.RelationId == player.Id &&
                                                                          x.Type == PlayerRelationTypeEnum.好友);



            if (playerRelationFrom != null && playerRelationTo != null)
            {
                if (playerRelationTo != null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你们已经是好友。");

                    return;
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你已申请加[{relation.Name}]为好友,请等待对方同意。");

                    return;
                }
            }



            if (playerRelationFrom == null)
            {
                if (playerRelationTo == null)
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你申请加[{relation.Name}]为好友,请等待对方同意。");

                    var content = $"【好友】[{player.Name}]想和你成为好友,到 '社交'->'好友' 界面可以同意或拒绝对方的申请,你也可以直接添加对方为好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}想和你成为好友",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }
                else
                {
                    await _mudProvider.ShowMessage(player.Id, $"【好友】你成功添加[{relation.Name}]为好友。");


                    var content = $"【好友】[{player.Name}]同意了你的申请,你们已成为了好友。";

                    await _emailDomainService.Add(new EmailEntity
                    {
                        ExpiryDate = DateTime.Now.AddDays(30),
                        SendDate   = DateTime.Now,
                        Title      = $"{player.Name}同意了你的好友申请",
                        Content    = content,
                        Type       = EmailTypeEnum.系统,
                        TypeId     = relation.Id
                    });


                    await _mudProvider.ShowMessage(relation.Id, content);
                }


                playerRelationFrom = new PlayerRelationEntity
                {
                    CreatedTime = DateTime.Now,
                    PlayerId    = player.Id,
                    RelationId  = relation.Id,
                    Type        = PlayerRelationTypeEnum.好友
                };
                await _playerRelationDomainService.Add(playerRelationFrom);



                await _queueHandler.SendQueueMessage(new ReceiveEmailQueue(relation.Id));
            }
        }
Example #9
0
        public async Task <Unit> Handle(AgreeFriendCommand command, CancellationToken cancellationToken)
        {
            var playerId   = command.PlayerId;
            var relationId = command.RelationId;
            var player     = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var relation = await _playerDomainService.Get(relationId);

            if (relation == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var playerRelationFrom = await _playerRelationDomainService.Get(x => x.PlayerId == relationId && x.RelationId == playerId && x.Type == PlayerRelationTypeEnum.好友);

            if (playerRelationFrom == null)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】[{relation.Name}]没有申请加你为好友,或者已撤销申请。");

                return(Unit.Value);
            }

            var playerRelationTo = await _playerRelationDomainService.Get(x => x.PlayerId == playerId && x.RelationId == relationId && x.Type == PlayerRelationTypeEnum.好友);

            if (playerRelationTo != null)
            {
                await _mudProvider.ShowMessage(player.Id, $"【好友】你和[{relation.Name}]已经是好友了。");

                return(Unit.Value);
            }


            playerRelationTo = new PlayerRelationEntity
            {
                PlayerId    = playerId,
                RelationId  = relationId,
                Type        = PlayerRelationTypeEnum.好友,
                CreatedTime = DateTime.Now
            };
            await _playerRelationDomainService.Add(playerRelationTo);

            await _mudProvider.ShowMessage(player.Id, $"【好友】你同意了[{relation.Name}]的好友申请。");

            var content = $"【好友】[{player.Name}]同意了你的申请,你们已成为了好友。";

            await _emailDomainService.Add(new EmailEntity
            {
                ExpiryDate = DateTime.Now.AddDays(30),
                SendDate   = DateTime.Now,
                Title      = $"{player.Name}同意了你的好友申请",
                Content    = content,
                Type       = EmailTypeEnum.系统,
                TypeId     = relation.Id
            });


            await _mudProvider.ShowMessage(relation.Id, content);

            return(Unit.Value);
        }
Example #10
0
 public async Task DoWork(PlayerEntity player)
 {
     await _mudProvider.ShowMessage(player.Id, $"你正在{player.Status}。。。");
 }
Example #11
0
        private async Task DoWork(PlayerEntity player)
        {
            await _mudProvider.ShowMessage(player.Id, $"你正在{player.Status}。。。");

            WorkTypeEnum workType = WorkTypeEnum.伐木;

            switch (player.Status)
            {
            case PlayerStatusEnum.伐木:
                workType = WorkTypeEnum.伐木;
                break;

            case PlayerStatusEnum.挖矿:
                workType = WorkTypeEnum.挖矿;
                break;

            case PlayerStatusEnum.打猎:
                workType = WorkTypeEnum.打猎;
                break;

            case PlayerStatusEnum.采药:
                workType = WorkTypeEnum.采药;
                break;

            case PlayerStatusEnum.钓鱼:
                workType = WorkTypeEnum.钓鱼;
                break;

            case PlayerStatusEnum.打工:
                workType = WorkTypeEnum.打工;
                break;

            default:
                return;
            }

            var ids = (await _roomItemDropDomainService.GetAll()).Where(x => x.RoomId == player.RoomId).Select(x => x.ItemDropId).ToList();

            var itemDrop = (await _itemDropDomainService.GetAll()).Where(x => ids.Contains(x.Id)).FirstOrDefault(x => x.WorkType == workType);

            if (itemDrop == null)
            {
                return;
            }


            var itemDropRates = (await _itemDropRateDomainService.GetAll()).Where(x => x.ItemDropId == itemDrop.Id).ToList();

            if (itemDropRates?.Count == 0)
            {
                return;
            }

            var random         = new Random();
            int maxWeight      = 100;//掉落总权重
            var itemDropModels = new List <ItemDropRateModel>();

            foreach (var itemDropRate in itemDropRates.OrderBy(x => x.Order))
            {
                if (itemDropRate.Percent < random.Next(0, 100))
                {
                    continue;
                }

                int number = random.Next(Math.Min(itemDropRate.MinNumber, itemDropRate.MaxNumber), itemDropRate.MaxNumber + 1);
                if (number <= 0)
                {
                    continue;
                }

                //掉落
                maxWeight -= itemDropRate.Weight;

                var itemDropModel = new ItemDropRateModel
                {
                    DropType = itemDropRate.DropType,
                    Number   = number,
                    WareId   = itemDropRate.WareId
                };
                itemDropModels.Add(itemDropModel);



                if (maxWeight <= 0)
                {
                    break;
                }
            }

            if (itemDropModels.Count == 0)
            {
                //没有掉落
                return;
            }

            var           playerAttributeChanged = false;
            List <string> dropContents           = new List <string>();

            foreach (var itemDropModel in itemDropModels)
            {
                switch (itemDropModel.DropType)
                {
                case ItemDropTypeEnum.潜能:
                    playerAttributeChanged = true;
                    player.Pot            += itemDropModel.Number;
                    dropContents.Add($"潜能 +{itemDropModel.Number}");
                    break;

                case ItemDropTypeEnum.经验:
                    playerAttributeChanged = true;
                    player.Exp            += itemDropModel.Number;
                    dropContents.Add($"经验 +{itemDropModel.Number}");
                    break;

                case ItemDropTypeEnum.金钱:
                    playerAttributeChanged = true;
                    player.Money          += itemDropModel.Number;
                    dropContents.Add($" +{itemDropModel.Number.ToMoney()}");
                    break;

                case ItemDropTypeEnum.物品:
                    #region MyRegion
                    int wareId = itemDropModel.WareId;
                    int number = itemDropModel.Number;

                    var ware = await _wareDomainService.Get(wareId);

                    if (ware == null)
                    {
                        continue;
                    }

                    dropContents.Add($"{ware.Name} X{number}");

                    var canStack = ware.Category != WareCategoryEnum.武器;

                    if (canStack)
                    {
                        var playerWare = await _playerWareDomainService.Get(x => x.WareId == ware.Id && x.PlayerId == player.Id);

                        if (playerWare == null)
                        {
                            playerWare = new PlayerWareEntity
                            {
                                IsBind   = false,
                                IsTemp   = false,
                                Level    = 1,
                                Number   = number,
                                Damage   = 0,
                                PlayerId = player.Id,
                                Status   = WareStatusEnum.卸下,
                                WareId   = wareId,
                                WareName = ware.Name
                            };
                            await _playerWareDomainService.Add(playerWare);
                        }
                        else
                        {
                            playerWare.Number += number;
                            await _playerWareDomainService.Update(playerWare);
                        }
                    }
                    else
                    {
                        var playerWare = new PlayerWareEntity
                        {
                            IsBind   = false,
                            IsTemp   = false,
                            Level    = 1,
                            Number   = number,
                            Damage   = 0,
                            PlayerId = player.Id,
                            Status   = WareStatusEnum.卸下,
                            WareId   = wareId,
                            WareName = ware.Name
                        };
                        await _playerWareDomainService.Add(playerWare);
                    }
                    #endregion


                    break;
                }
            }

            if (playerAttributeChanged)
            {
                await _bus.RaiseEvent(new PlayerAttributeChangedEvent(player)).ConfigureAwait(false);
            }


            if (dropContents.Count > 0)
            {
                await _mudProvider.ShowMessage(player.Id, $"获得{ string.Join(",", dropContents)   }。");
            }
        }
Example #12
0
        public async Task <Unit> Handle(QuestCommand command, CancellationToken cancellationToken)
        {
            var playerId = command.PlayerId;
            var questId  = command.QuestId;

            var player = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var quest = await _questDomainService.Get(questId);

            if (quest == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"任务不存在!"));

                return(Unit.Value);
            }

            var playerQuest = await _playerQuestDomainService.Get(x => x.PlayerId == playerId && x.QuestId == questId);

            if (playerQuest != null)
            {
                //已领取
                if (playerQuest.HasTake)
                {
                    await _mudProvider.ShowMessage(playerId, "领取任务成功!");

                    //await _mudProvider.ShowMessage(playerId, quest.InProgressWords);
                    return(Unit.Value);
                }

                //未领取但是之前已经完成过
                switch (quest.Period)
                {
                case QuestPeriodEnum.可重复:
                    await _mudProvider.ShowMessage(playerId, "该任务仅可领取一次,你已经领取过!");

                    return(Unit.Value);

                    break;

                case QuestPeriodEnum.无限制:

                    break;

                case QuestPeriodEnum.每周一次:
                    if (DateTime.Now.Subtract(playerQuest.TakeDate).TotalDays <= 7)
                    {
                        await _mudProvider.ShowMessage(playerId, "该任务每周仅可领取一次,你已经领取过!");

                        return(Unit.Value);
                    }
                    break;

                case QuestPeriodEnum.每天一次:
                    if (DateTime.Now.Subtract(playerQuest.TakeDate).TotalHours <= 24)
                    {
                        await _mudProvider.ShowMessage(playerId, "该任务每天仅可领取一次,你已经领取过!");

                        return(Unit.Value);
                    }
                    break;

                case QuestPeriodEnum.每年一次:
                    if (DateTime.Now.Subtract(playerQuest.TakeDate).TotalDays <= 365)
                    {
                        await _mudProvider.ShowMessage(playerId, "该任务每年仅可领取一次,你已经领取过!");

                        return(Unit.Value);
                    }
                    break;

                case QuestPeriodEnum.每月一次:
                    if (DateTime.Now.Subtract(playerQuest.TakeDate).TotalDays <= 30)
                    {
                        await _mudProvider.ShowMessage(playerId, "该任务每月仅可领取一次,你已经领取过!");

                        return(Unit.Value);
                    }
                    break;
                }
            }

            var checkCondition = await CheckTakeCondition(player, quest.TakeCondition);

            if (!checkCondition.IsSuccess)
            {
                await _bus.RaiseEvent(new DomainNotification($"你还不能领取这个任务 !{checkCondition.ErrorMessage}"));

                return(Unit.Value);
            }

            if (playerQuest == null)
            {
                playerQuest = new PlayerQuestEntity
                {
                    PlayerId     = player.Id,
                    QuestId      = questId,
                    IsComplete   = false,
                    TakeDate     = DateTime.Now,
                    CompleteDate = DateTime.Now,
                    CreateDate   = DateTime.Now,
                    DayTimes     = 1,
                    HasTake      = true,
                    Target       = quest.Target,
                    Times        = 1,
                    UpdateDate   = DateTime.Now
                };
                await _playerQuestDomainService.Add(playerQuest);
            }
            else
            {
                //TODO 领取任务
                playerQuest.HasTake    = true;
                playerQuest.IsComplete = false;
                playerQuest.TakeDate   = DateTime.Now;
                playerQuest.Times     += 1;
                playerQuest.Target     = quest.Target;

                await _playerQuestDomainService.Update(playerQuest);
            }


            if (await Commit())
            {
                await _bus.RaiseEvent(new DomainNotification($"领取任务 {quest.Name} !"));
            }



            return(Unit.Value);
        }
Example #13
0
        public async Task <Unit> Handle(ChatWithNpcCommand command, CancellationToken cancellationToken)
        {
            var playerId = command.PlayerId;
            var player   = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                return(Unit.Value);
            }

            var npcId = command.NpcId;
            var npc   = await _npcDomainService.Get(npcId);

            if (npc == null)
            {
                return(Unit.Value);
            }

            if (npc.Type != NpcTypeEnum.人物)
            {
                await _bus.RaiseEvent(new DomainNotification($"指令 错误!"));

                return(Unit.Value);
            }


            await _mudProvider.ShowMessage(player.Id, $"与 [{npc.Name}] 闲聊中...");

            var chatWithNpcLike = await _redisDb.StringGet <int>(string.Format(RedisKey.ChatWithNpcLike, playerId, npcId));

            if (chatWithNpcLike > 0)
            {
                return(Unit.Value);
            }

            Random random = new Random();

            int kar = Math.Abs(npc.Kar - player.Kar);

            if (random.Next(1, 100) > kar)
            {
                var npcLiking = await _npcLikingDomainService.Get(x => x.PlayerId == player.Id && x.NpcId == npcId);

                if (npcLiking == null)
                {
                    npcLiking = new NpcLikingEntity
                    {
                        CreatedTime = DateTime.Now,
                        NpcId       = npcId,
                        Liking      = 1,
                        PlayerId    = player.Id
                    };
                    await _npcLikingDomainService.Add(npcLiking);
                }
                else
                {
                    if (npcLiking.Liking < 20)
                    {
                        npcLiking.Liking++;
                        await _npcLikingDomainService.Update(npcLiking);
                    }
                }

                await _mudProvider.ShowMessage(player.Id, $"交谈甚欢,与[{npc.Name}]的好感度上升");
            }

            await _bus.RaiseEvent(new ChatWithNpcEvent(playerId, npc.Id)).ConfigureAwait(false);

            return(Unit.Value);
        }
Example #14
0
        public async Task <Unit> Handle(LearnSkillCommand command, CancellationToken cancellationToken)
        {
            var playerId      = command.PlayerId;
            var objectSkillId = command.MySkillId;
            var type          = command.Type;
            var player        = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                return(Unit.Value);
            }

            int skillId          = 0;
            int objectSkillLevel = 0;

            if (type == 1)
            {
                var objectSkill = await _playerSkillDomainService.Get(objectSkillId);

                if (objectSkill == null)
                {
                    return(Unit.Value);
                }
                skillId          = objectSkill.SkillId;
                objectSkillLevel = objectSkill.Level;
            }
            else
            {
                var objectSkill = await _npcSkillDomainService.Get(objectSkillId);

                if (objectSkill == null)
                {
                    return(Unit.Value);
                }
                skillId          = objectSkill.SkillId;
                objectSkillLevel = objectSkill.Level;
            }


            var skill = await _skillDomainService.Get(skillId);

            if (skill == null)
            {
                return(Unit.Value);
            }

            if (player.Pot <= 0)
            {
                await _mudProvider.ShowMessage(player.Id, $"潜能不够,无法修练!");

                return(Unit.Value);
            }

            var needPot = 0;
            var exp     = 0;

            var mySkill = await _playerSkillDomainService.Get(x => x.PlayerId == playerId && x.SkillId == skillId);

            if (mySkill == null)
            {
                needPot = 100;
                exp     = 1;
                if (player.Pot <= needPot)
                {
                    await _mudProvider.ShowMessage(player.Id, $"潜能不够,无法修练!");

                    return(Unit.Value);
                }

                mySkill = new PlayerSkillEntity
                {
                    Exp       = 1,
                    Level     = 1,
                    SkillId   = skillId,
                    PlayerId  = playerId,
                    SkillName = skill.Name
                };
                await _playerSkillDomainService.Add(mySkill);

                player.Pot -= needPot;
                await _playerDomainService.Update(player);

                await _mudProvider.ShowMessage(player.Id, $"你消耗潜能{needPot},学会了[{skill.Name}]!");

                return(Unit.Value);
            }


            if (player.Level * 10 < mySkill.Level)
            {
                await _mudProvider.ShowMessage(player.Id, $"武功最高等级不能超过自身等级的10倍!");

                return(Unit.Value);
            }

            if (mySkill.Level >= objectSkillLevel && !skill.IsBase)
            {
                await _mudProvider.ShowMessage(player.Id, $"你已经无法从对方身上学到什么了!");

                return(Unit.Value);
            }

            var @int         = player.Int * 3 + player.IntAdd;
            var nextLevelExp = (mySkill.Level + 1) * (mySkill.Level + 1) * 50;
            var levelUpExp   = nextLevelExp - mySkill.Level * mySkill.Level * 50;

            Random random = new Random();

            exp     = random.Next(1, levelUpExp / 10);
            needPot = exp * 100 / @int;

            var effect = exp * 1000 / levelUpExp;

            string effectWords;

            if (effect > 80)
            {
                effectWords = "恍然大悟";
            }
            else if (effect > 50)
            {
                effectWords = "有所顿悟";
            }
            else if (effect > 20)
            {
                effectWords = "略有所获";
            }
            else if (effect > 10)
            {
                effectWords = "略有所获";
            }
            else
            {
                effectWords = "似乎没有什么进展";
            }

            player.Pot -= needPot;
            await _playerDomainService.Update(player);

            mySkill.SkillName = skill.Name;
            mySkill.Exp      += exp;
            await _mudProvider.ShowMessage(player.Id, $"你消耗潜能{needPot},{effectWords},[{skill.Name}]经验增加{exp}!");

            if (mySkill.Exp > nextLevelExp)
            {
                mySkill.Level++;
                await _mudProvider.ShowMessage(player.Id, $"[{skill.Name}]等级上升为 Lv.{mySkill.Level}!");
            }



            await _playerSkillDomainService.Update(mySkill);



            await _bus.RaiseEvent(new PlayerAttributeChangedEvent(player)).ConfigureAwait(false);

            return(Unit.Value);
        }
Example #15
0
        public async Task <bool> CheckPlayerMainQuestQueue(CheckPlayerMainQuestQueue message)
        {
            _logger.LogDebug($"Consumer Get Queue {JsonConvert.SerializeObject(message)} ready");

            var playerId = message.PlayerId;

            //已经领取的所有任务
            var myQuests = (await _playerQuestDomainService.GetPlayerQuests(playerId));
            //正在进行的任务
            var myQuestsNotComplete = myQuests.Where(x => !x.IsComplete);
            //所有主线任务
            var mainQuests = (await _questDomainService.GetAll()).Where(x => x.Type == QuestTypeEnum.主线).OrderBy(x => x.SortId);
            //是否有正在进行的主线任务
            var mainQuest = mainQuests.FirstOrDefault(x => myQuestsNotComplete.Select(y => y.QuestId).Contains(x.Id));

            if (mainQuest == null)
            {
                //没有正在进行中的主线任务,找到第一个没有领取的主线任务
                mainQuest = mainQuests.FirstOrDefault(x => !myQuests.Select(y => y.QuestId).Contains(x.Id));
                if (mainQuest != null)
                {
                    //自动领取第一个主线任务
                    var playerQuest = new PlayerQuestEntity
                    {
                        PlayerId     = playerId,
                        QuestId      = mainQuest.Id,
                        IsComplete   = false,
                        TakeDate     = DateTime.Now,
                        CompleteDate = DateTime.Now,
                        CreateDate   = DateTime.Now,
                        DayTimes     = 1,
                        HasTake      = true,
                        Target       = mainQuest.Target,
                        Times        = 1,
                        UpdateDate   = DateTime.Now
                    };
                    await _playerQuestDomainService.Add(playerQuest);

                    await _mudProvider.ShowMessage(playerId, $"已自动激活任务 [{mainQuest.Name}]。");

                    //判断是否第一个任务
                    var isFirst = mainQuests.FirstOrDefault()?.Id == mainQuest.Id;


                    await _mudProvider.ShowQuest(playerId, new { mainQuest, isFirst });
                }
                else
                {
                    //所有主线任务都已完成
                }
            }
            else
            {
                //有正在进行的主线任务

                //判断是否第一个任务
                var isFirst = mainQuests.FirstOrDefault()?.Id == mainQuest.Id;

                await _mudProvider.ShowQuest(playerId, new { mainQuest, isFirst });
            }


            await Commit();

            return(true);
        }
Example #16
0
        public async Task <Unit> Handle(LoadWareCommand command, CancellationToken cancellationToken)
        {
            var myWareId = command.MyWareId;
            var playerId = command.PlayerId;

            var player = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }

            var playerWare = await _playerWareDomainService.Get(myWareId);

            if (playerWare == null || playerWare.PlayerId != playerId)
            {
                await _bus.RaiseEvent(new DomainNotification($"武器不存在!"));

                return(Unit.Value);
            }

            if (playerWare.Status == WareStatusEnum.装备)
            {
                await _bus.RaiseEvent(new DomainNotification($"武器已装备!"));

                return(Unit.Value);
            }

            var ware = await _wareDomainService.Get(playerWare.WareId);

            if (ware == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"武器状态异常!"));

                return(Unit.Value);
            }


            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));

            WareTypeEnum[] wareTypes = null;
            WareEntity     loadWare  = null;

            switch (ware.Type)
            {
            case WareTypeEnum.刀:
            case WareTypeEnum.剑:
            case WareTypeEnum.枪:
                wareTypes = new[] { WareTypeEnum.刀, WareTypeEnum.剑, WareTypeEnum.枪 };
                break;

            case WareTypeEnum.衣服:
                wareTypes = new[] { WareTypeEnum.衣服 };
                break;

            case WareTypeEnum.鞋:
                wareTypes = new[] { WareTypeEnum.鞋 };
                break;

            case WareTypeEnum.帽:
                wareTypes = new[] { WareTypeEnum.帽 };
                break;
            }
            if (wareTypes != null)
            {
                loadWare = wares.FirstOrDefault(x => wareTypes.Contains(x.Type));
            }

            if (loadWare != null)
            {
                await _bus.RaiseEvent(new DomainNotification($"你已经装备了 [{loadWare.Name}]!"));

                return(Unit.Value);
            }


            playerWare.Status = WareStatusEnum.装备;
            await _playerWareDomainService.Update(playerWare);

            var wareEffectAttr = await Computed(playerId);

            player.Atk = wareEffectAttr.Atk;
            player.Def = wareEffectAttr.Def;

            await _playerDomainService.Update(player);

            /*
             * var wareModel = _mapper.Map<WareModel>(ware);
             * wareModel.PlayerWareId = playerWare.Id;
             * wareModel.Number = playerWare.Number;
             * wareModel.Status = playerWare.Status;
             * await _mudProvider.LoadWare(playerId, wareModel);
             */

            var wareModel = await Computed(ware, playerWare);

            await _mudProvider.ShowWare(playerId, wareModel);

            await _mudProvider.ShowMessage(playerId, $"你装备了 [{wareModel.Name}]!");

            return(Unit.Value);
        }
Example #17
0
        public async Task <Unit> Handle(StopActionCommand command, CancellationToken cancellationToken)
        {
            //await _bus.RaiseEvent(new DomainNotification("功能暂时未实现"));

            var playerId = command.PlayerId;
            var player   = await _playerDomainService.Get(playerId);

            if (player == null)
            {
                await _bus.RaiseEvent(new DomainNotification($"角色不存在!"));

                return(Unit.Value);
            }
            var status = player.Status;

            if (status == PlayerStatusEnum.空闲)
            {
                return(Unit.Value);
            }


            player.Status = PlayerStatusEnum.空闲;
            await _playerDomainService.Update(player);

            switch (status)
            {
            case PlayerStatusEnum.打坐:
                await _mudProvider.ShowMessage(playerId, "你停止了打坐。。。");

                break;

            case PlayerStatusEnum.打工:
                await _mudProvider.ShowMessage(playerId, "你停止了打工。。。");

                break;

            case PlayerStatusEnum.伐木:
                await _mudProvider.ShowMessage(playerId, "你停止了伐木。。。");

                break;

            case PlayerStatusEnum.打猎:
                await _mudProvider.ShowMessage(playerId, "你停止了打猎。。。");

                break;

            case PlayerStatusEnum.挖矿:
                await _mudProvider.ShowMessage(playerId, "你停止了挖矿。。。");

                break;

            case PlayerStatusEnum.疗伤:
                await _mudProvider.ShowMessage(playerId, "你停止了疗伤。。。");

                break;

            case PlayerStatusEnum.采药:
                await _mudProvider.ShowMessage(playerId, "你停止了采药。。。");

                break;

            case PlayerStatusEnum.钓鱼:
                await _mudProvider.ShowMessage(playerId, "你停止了钓鱼。。。");

                break;

            default:
                await _mudProvider.ShowMessage(playerId, $"你停止了{status}。。。");

                break;
            }

            await _recurringQueue.Remove <PlayerStatusModel>($"player_{playerId}");

            if (await Commit())
            {
                await _bus.RaiseEvent(new PlayerStatusChangedEvent(player)).ConfigureAwait(false);
            }
            return(Unit.Value);
        }