예제 #1
0
파일: TalkText.cs 프로젝트: hehay/hehayGame
    public void SetInfo(TalkDTO talkDto)
    {
        userid   = talkDto.userid;
        username = talkDto.userName;
        switch (talkDto.talkType)
        {
        case TalkType.Word:
            talkText.color = new Color(0, 0.5f, 1, 1);
            talkText.text  = "【世界】" + username + "说:" + talkDto.text;
            break;

        case TalkType.Scene:
            talkText.color = new Color(0, 1, 0.5f, 1);
            talkText.text  = "【场景】" + username + "说:" + talkDto.text;
            break;

        case TalkType.One:
            talkText.color = Color.magenta;
            if (userid != GameData.UserDto.id)
            {
                talkText.text = "【私聊】" + username + "对你说:" + talkDto.text;
            }
            else
            {
                talkText.text = "【私聊】你对" + username + "说:" + talkDto.text;
            }
            break;

        case TalkType.System:
            talkText.color = new Color((float)40 / 255, (float)40 / 255, (float)40 / 255, 1);
            talkText.text  = "【系统】" + talkDto.text;
            break;
        }
    }
예제 #2
0
파일: MapRoom.cs 프로젝트: hehay/MyServer
 void Talk(UserToken token, TalkDTO talkDto)
 {
     talkDto.userid   = userCache.GetUserId(token);
     talkDto.userName = userCache.GetUserById(talkDto.userid).Name;
     if (talkDto.receiverid >= 0 && talkDto.talkType == TalkType.One)
     {
         Write(token, MapProtocol.Talk_SRES, talkDto);              //发送给自己
         Write(talkDto.receiverid, MapProtocol.Talk_SRES, talkDto); //发送给接收方
     }
     else
     {
         Brocast(MapProtocol.Talk_BRO, talkDto);
     }
 }
예제 #3
0
        public async Task AddTalkAsync(TalkDTO talkDTO)
        {
            var talk = _mapper.Map <Talk>(talkDTO);

            try
            {
                await _unitOfWork.TalkRepo.AddTalkAsync(talk);

                await _unitOfWork.SaveAsync();

                await _unitOfWork.CommitChangesAsync();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #4
0
        public async Task <TalkDTO> GetTalkByTitleAsync(string title)
        {
            TalkDTO talkDTO = null;

            try
            {
                var talk = await _unitOfWork.TalkRepo.GetTalkByTitle(title);

                if (talk != null)
                {
                    talkDTO = _mapper.Map <TalkDTO>(talk);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(talkDTO);
        }
예제 #5
0
    public void OnSendClick()
    {
        if (this.text.text.Length <= 0)
        {
            WarrningManager.warringList.Add(new WarringModel("文本不能为空!", null, 2));
            return;
        }

        TalkDTO talkDto = new TalkDTO();

        talkDto.text       = text.text;
        talkDto.receiverid = -1;
        switch (type)
        {
        case "世界":
            talkDto.talkType = TalkType.Word;
            NetIO.Instance.Write(Protocol.Map, -1, MapProtocol.Talk_CREQ, talkDto);
            break;

        case "场景":
            talkDto.talkType = TalkType.Scene;
            NetIO.Instance.Write(Protocol.Map, SceneManager.GetActiveScene().buildIndex, MapProtocol.Talk_CREQ,
                                 talkDto);
            break;

        case "私聊":
            if (receiverid >= 0)
            {
                talkDto.talkType   = TalkType.One;
                talkDto.receiverid = receiverid;
                NetIO.Instance.Write(Protocol.Map, -1, MapProtocol.Talk_CREQ,
                                     talkDto);
            }
            else
            {
                WarrningManager.warringList.Add(new WarringModel("请选择聊天对象!", null, 2));
            }
            break;
        }
        text.text = "";
        text.ActivateInputField();
    }
예제 #6
0
        public async Task <IActionResult> AddTalk([FromBody] TalkDTO talkDTO)
        {
            try
            {
                if (talkDTO == null)
                {
                    return(BadRequest(new ApiResponse {
                        Status = false, Message = "Bad Request"
                    }));
                }

                await _talkService.AddTalkAsync(talkDTO);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message, $"Failed to add Talk: {DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss.fff")}");
            }
            _logger.LogInformation("Successfully added Talk");
            return(Created("", new ApiResponse {
                Status = true, Message = "Successful"
            }));
        }
예제 #7
0
 public SessionViewModel(TalkDTO talkDto)
 {
     _talkDTO = talkDto;
 }
예제 #8
0
파일: MapRoom.cs 프로젝트: hehay/MyServer
        void Damage(UserToken token, DamageDTO damageDto)
        {
            int          userId       = userCache.GetUserId(token);
            AbsRoleModel attRoleModel = GetRoleModel(userId);;

            damageDto.userid = userId;

            List <int[]> damages = new List <int[]>();

            for (int i = 0; i < damageDto.targets.Length; i++)
            {
                AbsRoleModel targetRoleModel = GetRoleModel(damageDto.targets[i][0]);

                GetValue(token, userId, damageDto.skill, ref attRoleModel, ref targetRoleModel, ref damages);

                if (targetRoleModel.hp <= 0)
                {
                    string kill = "";
                    ExecutorPool.Instance.Executor(delegate
                    {
                        // ReSharper disable once ReturnValueOfPureMethodIsNotUsed

                        if (random.Next(0, 11) > 4)
                        {
                            int index = random.Next(0, inventorys.Length - 1);
                            InventoryItemDTO itemDto = inventoryBiz.AddInventory(token, inventorys[index]);
                            Write(token, Protocol.Inventory, GetArea(), InventoryProtocol.AddInventory_SRES, itemDto);
                            kill = "并且获得斩杀奖励【" + itemDto.inventory.name + "】,别的小伙伴请继续努力!";
                        }
                    });//随机掉物品

                    targetRoleModel.hp = 0;
                    TalkDTO talkDto = new TalkDTO();
                    talkDto.userid   = -1;
                    talkDto.talkType = TalkType.System;
                    talkDto.userName = "******";
                    talkDto.text     = attRoleModel.name + "杀死了" + targetRoleModel.name + "!" + kill;
                    Brocast(MapProtocol.Talk_BRO, talkDto);//广播信息
                    UserDTO attUserDto = attRoleModel as UserDTO;
                    USER    attUser    = userCache.GetUserById(targetRoleModel.id);

                    if (attUserDto != null)
                    {
                        attUser.Money    += attUser.Level * 100;
                        attUserDto.money += attUserDto.level * 100;
                        attUserDto.exp   += 30 * (targetRoleModel.level / attUserDto.level) + attUserDto.level * 5;
                        attUser.Exp      += 30 * (targetRoleModel.level / attUserDto.level) + attUserDto.level * 5;
                        int total_exp = 100 + attUser.Level * 30;
                        while (attUser.Exp >= total_exp)
                        {
                            // 升级
                            attUser.Level++;
                            attUserDto.level++;
                            attUser.Exp      -= total_exp;
                            attUserDto.exp    = attUser.Exp;
                            attUser.Hp       += attUser.Level * 50;
                            attUser.MaxHp    += attUser.Level * 50;
                            attUser.Mp       += attUser.Level * 25;
                            attUser.MaxMp    += attUser.Level * 25;
                            attUserDto.hp    += attUserDto.level * 50;
                            attUserDto.maxHp += attUserDto.level * 50;
                            attUserDto.mp    += attUserDto.level * 25;
                            attUserDto.maxMp += attUserDto.level * 25;
                            total_exp         = 100 + attUser.Level * 30;
                        }
                        Brocast(MapProtocol.Killraward_BRO, attUserDto);//广播杀人
                    }
                    if (targetRoleModel.id >= 0)
                    {
                        // 开启计时任务复活
                        int timeEventId = ScheduleUtil.Instance.Schedule(delegate
                        {
                            UserDTO userDto = targetRoleModel as UserDTO;
                            userDto.hp      = (int)(userDto.maxHp * 0.5f);
                            userDto.mp      = (int)(userDto.maxMp * 0.5f);

                            USER user = userCache.GetUserById(targetRoleModel.id);
                            user.Hp   = (int)(user.MaxHp * 0.5);
                            user.Mp   = (int)(user.MaxMp * 0.5);
                            Brocast(MapProtocol.Revive_BRO, targetRoleModel.id);
                        }, 10);//10秒后复活玩家
                    }
                    else
                    {
                        //TODO 击杀NPC移除NPC数据
                    }
                }
            }
            damageDto.targets = damages.ToArray();
            Brocast(MapProtocol.Damage_BRO, damageDto);
        }
예제 #9
0
    private void TalkSEQS(TalkDTO talkDto)
    {
        GameObject go;
        GameObject alltemp;

        if (talkPool.Count > 0)
        {
            go = talkPool.Pop();
            go.SetActive(true);
        }
        else
        {
            go = Instantiate(prefab);
        }

        switch (talkDto.talkType)
        {
        case TalkType.Word:
            go.transform.SetParent(word.transform, false);
            go.GetComponent <TalkText>().SetInfo(talkDto);
            wordList.Add(go);
            if (wordList.Count > 50)
            {
                wordList.RemoveAt(0);
                wordList[0].gameObject.SetActive(false);
                wordList[0].GetComponent <TalkText>().Clear();
                talkPool.Push(wordList[0]);
            }
            wordScrollbar.value = 0;
            talkText.text      += "<color=#007DFFFF>" + "【世界】" + talkDto.userName + "说:" + talkDto.text + "</color>" + "\n";
            break;

        case TalkType.Scene:
            go.transform.SetParent(scene.transform, false);
            go.GetComponent <TalkText>().SetInfo(talkDto);
            sceneList.Add(go);
            if (sceneList.Count > 50)
            {
                sceneList.RemoveAt(0);
                sceneList[0].gameObject.SetActive(false);
                sceneList[0].GetComponent <TalkText>().Clear();
                talkPool.Push(sceneList[0]);
            }
            sceneScrollbar.value = 0;
            talkText.text       += "<color=#00FF7DFF>" + "【场景】" + talkDto.userName + "说:" + talkDto.text + "</color>" + "\n";
            break;

        case TalkType.System:
            go.transform.SetParent(scene.transform, false);
            go.GetComponent <TalkText>().SetInfo(talkDto);
            sceneList.Add(go);
            if (sceneList.Count > 50)
            {
                sceneList.RemoveAt(0);
                sceneList[0].gameObject.SetActive(false);
                sceneList[0].GetComponent <TalkText>().Clear();
                talkPool.Push(sceneList[0]);
            }
            sceneScrollbar.value = 0;
            talkText.text       += "<color=#282828FF>" + "【系统】" + talkDto.text + "</color>" + "\n";
            break;

        case TalkType.One:
            go.transform.SetParent(one.transform, false);
            go.GetComponent <TalkText>().SetInfo(talkDto);
            oneList.Add(go);
            if (oneList.Count > 50)
            {
                oneList.RemoveAt(0);
                oneList[0].gameObject.SetActive(false);
                oneList[0].GetComponent <TalkText>().Clear();
                talkPool.Push(oneList[0]);
            }
            oneScrollbar.value = 0;
            if (talkDto.userid == GameData.UserDto.id)
            {
                talkText.text += "<color=#FF00FFFF>" + "【私聊】你对" + talkDto.userName + "说:" + talkDto.text + "</color>" + "\n";
            }
            else
            {
                talkText.text += "<color=#FF00FFFF>" + "【私聊】" + talkDto.userName + "对你说:" + talkDto.text + "</color>" + "\n";
            }
            break;
        }
        //string[] talkStrings = talkText.text.Trim('\n').Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
        //List<string> talkList=new List<string>();
        //if (talkStrings.Length > 6)
        //{

        //    talkList.AddRange(talkStrings);
        //    talkList.RemoveAt(0);
        //    talkText.text = String.Empty;
        //}
        //for (int i = 0; i < talkList.Count; i++)
        //{
        //        talkText.text += talkList[i] + "\n";
        //}
        talkTextScrollbar.value = 0;

        if (talkPool.Count > 0)
        {
            alltemp = talkPool.Pop();
            alltemp.SetActive(true);
        }
        else
        {
            alltemp = Instantiate(prefab);
        }
        alltemp.transform.SetParent(all.transform, false);
        alltemp.GetComponent <TalkText>().SetInfo(talkDto);
        allList.Add(alltemp);
        if (allList.Count > 50)
        {
            allList.RemoveAt(0);
            allList[0].gameObject.SetActive(false);
            allList[0].GetComponent <TalkText>().Clear();
            talkPool.Push(allList[0]);
        }
        allScrollbar.value = 0;
    }
예제 #10
0
 private void TalkBro(TalkDTO talkDto)
 {
     TalkSEQS(talkDto);
 }