コード例 #1
0
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理技能升级的请求");

            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.GetRoomByPlayerId(playerId);

            // 获取英雄数据
            DtoHero hero = room.GetDtoHero(playerId);

            if (hero == null || hero.SP < 1)
            {
                return;
            }

            // 获取技能id
            int skillId = (int)request[(byte)ParameterCode.SkillId];

            // 技能升级
            DtoSkill skill = hero.UpgradeSkill(skillId);

            if (skill == null)
            {
                return;
            }

            // 发送升级的技能数据和英雄id
            Dictionary <byte, object> data = new Dictionary <byte, object>();

            data.Add((byte)ParameterCode.DtoSkill, JsonMapper.ToJson(skill));
            data.Add((byte)ParameterCode.PlayerId, playerId);
            SendResponse(peer, request.OperationCode, data);
        }
コード例 #2
0
        /// <summary>
        /// 队伍获得经验
        /// </summary>
        public DtoHero[] TeamGetExp(int teamId, int exp)
        {
            DtoHero[] heros = null;
            int       i     = 0;

            if (teamId == 1)
            {
                heros = new DtoHero[TeamOneHeros.Count];
                foreach (DtoHero hero in TeamOneHeros.Values)
                {
                    hero.AddExp(exp);
                    heros[i++] = hero;
                }
            }
            else if (teamId == 2)
            {
                heros = new DtoHero[TeamTwoHeros.Count];
                foreach (DtoHero hero in TeamTwoHeros.Values)
                {
                    hero.AddExp(exp);
                    heros[i++] = hero;
                }
            }
            return(heros);
        }
コード例 #3
0
ファイル: GetRewardRequest.cs プロジェクト: mengtest/MOBAGame
    public override void OnOperationResponse(OperationResponse response)
    {
        // 获取修改的数据
        DtoHero[] heros = JsonMapper.ToObject <DtoHero[]>(response[(byte)ParameterCode.HerosArray] as string);

        // 更新数据
        for (int i = 0; i < heros.Length; i++)
        {
            DtoHero    hero = heros[i];
            AIBaseCtrl ctrl = BattleData.Instance.CtrlDict.ExTryGet(hero.Id);
            if (ctrl == null)
            {
                return;
            }

            ctrl.Model = hero;
            // 更新自己的数据
            if (ctrl.Model.Id == GameData.HeroData.Id)
            {
                GameData.HeroData = hero;
                (UIManager.Instance.GetPanel(UIPanelType.Battle) as BattlePanel).UpdateView();
            }
        }

        // 自己获得金币
        int heroId = (int)response[(byte)ParameterCode.HeroId];

        if (heroId == GameData.HeroData.Id)
        {
            // 金币音效
            SoundManager.Instance.PlayEffectMusic(Paths.UI_BUY);
        }
    }
コード例 #4
0
        /// <summary>
        /// 英雄获得金币
        /// </summary>
        /// <param name="id"></param>
        /// <param name="coins"></param>
        public int HeroGetCoins(int id, int coins)
        {
            DtoHero hero = GetDtoHero(id);

            if (hero == null)
            {
                return(-1);
            }

            hero.Money += coins;
            return(hero.Id);
        }
コード例 #5
0
        /// <summary>
        /// 根据标识id获取英雄数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DtoHero GetDtoHero(int id)
        {
            DtoHero hero = null;

            if (TeamOneHeros.TryGetValue(id, out hero))
            {
                return(hero);
            }
            if (TeamTwoHeros.TryGetValue(id, out hero))
            {
                return(hero);
            }

            return(null);
        }
コード例 #6
0
        /// <summary>
        /// 根据选择数据获取英雄数据
        /// </summary>
        /// <param name="dto"></param>
        public DtoHero GetDtoHero(DtoSelect dto, int team)
        {
            // 获取英雄模型
            HeroModel model = HeroData.GetHeroData(dto.HeroId);

            if (model == null)
            {
                return(null);
            }

            DtoHero hero = new DtoHero(dto.PlayerId, dto.HeroId, team, model.Hp, model.BaseAttack,
                                       model.BaseDefens, model.AttackDistance, model.AttackInterval, model.Name, model.Mp, model.Speed, model.SkillIds);

            return(hero);
        }
コード例 #7
0
ファイル: BuyItemHandler.cs プロジェクト: mengtest/MOBAGame
        public override void OnOperationRequest(OperationRequest request, SendParameters sendParameters, MobaPeer peer)
        {
            MobaServer.LogInfo("处理购买道具的请求");

            // 获取道具
            int       itemId = (int)request[(byte)ParameterCode.ItemId];
            ItemModel item   = ItemData.GetItem(itemId);

            if (item == null)
            {
                return;
            }

            // 获取房间
            int        playerId = UserManager.GetPlayer(peer.Username).Identification;
            BattleRoom room     = Caches.Battle.GetRoomByPlayerId(playerId);

            if (room == null)
            {
                return;
            }

            // 获取英雄
            DtoHero hero = room.GetDtoHero(playerId);

            // 金币不足
            if (hero.Money < item.Price)
            {
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied, "金币不足");
                return;
            }

            // 开始购买
            if (hero.BuyItem(item))
            {
                // 给所有客户端发送消息 谁买了什么装备
                Dictionary <byte, object> data = new Dictionary <byte, object>();
                data.Add((byte)ParameterCode.DtoHero, JsonMapper.ToJson(hero));
                room.Brocast(OpCode, data);
            }
            else
            {
                SendResponse(peer, request.OperationCode, null, ReturnCode.Falied, "装备已满");
            }
        }
コード例 #8
0
    /// <summary>
    /// 刷新界面
    /// </summary>
    /// <param name="hero"></param>
    public void UpdateView()
    {
        DtoHero hero = GameData.HeroData;

        // 更新状态条
        BarExp.value = (float)hero.Exp / (hero.Level * 300);
        BarHp.value  = (float)hero.CurHp / hero.MaxHp;
        BarMp.value  = (float)hero.CurMp / hero.MaxMp;

        // 更新文本
        TextAttack.text  = hero.Attack.ToString();
        TextDefense.text = hero.Defense.ToString();
        TextLevel.text   = "Lv." + hero.Level;
        TextHp.text      = hero.CurHp + "/" + hero.MaxHp;
        TextMp.text      = hero.CurMp + "/" + hero.MaxMp;
        TextCoins.text   = hero.Money.ToString();
        TextKDA.text     = hero.Kill + "/" + hero.Death;

        // 更新装备栏
        for (int i = 0; i < hero.Equipments.Length; i++)
        {
            if (hero.Equipments[i] != -1)
            {
                Equipments[i].sprite = ResourcesManager.Instance.GetAsset(Paths.RES_EQUIPMENT_UI + hero.Equipments[i]) as Sprite;
                Equipments[i].color  = Color.white;
            }
        }

        // 更新技能栏的升级状态
        if (GameData.HeroData.SP > 0)
        {
            DtoSkill skill = null;
            for (int i = 0; i < hero.Skills.Length; i++)
            {
                skill = hero.Skills[i];
                if (skill != null)
                {
                    ItemSkill item = Skills[i].GetComponent <ItemSkill>();
                    item.UpdataBtnUp();
                }
            }
        }
    }
コード例 #9
0
ファイル: BuyItemRequest.cs プロジェクト: mengtest/MOBAGame
    public override void OnOperationResponse(OperationResponse response)
    {
        if (response.ReturnCode == (byte)ReturnCode.Falied)
        {
            return;
        }

        // 更新数据
        DtoHero hero = JsonMapper.ToObject <DtoHero>(response[(byte)ParameterCode.DtoHero] as string);

        BattleData.Instance.CtrlDict[hero.Id].Model = hero;

        // 如果时自己购买
        if (hero.Id == GameData.HeroCtrl.Model.Id)
        {
            SoundManager.Instance.PlayEffectMusic(Paths.UI_BUY);
            GameData.HeroData = hero;
            (UIManager.Instance.GetPanel(UIPanelType.Battle) as BattlePanel).UpdateView();
        }
    }
コード例 #10
0
    public void InitView()
    {
        // 获取数据
        DtoHero hero = GameData.HeroData;

        // 加载头像
        ResourcesManager.Instance.Load(Paths.RES_HEAD_UI + hero.Name, typeof(Sprite), this);
        // 默认状态
        BarExp.value = 0;
        BarHp.value  = 1;
        BarMp.value  = 1;
        // 赋值
        TextAttack.text  = hero.Attack.ToString();
        TextDefense.text = hero.Defense.ToString();
        TextLevel.text   = "Lv." + hero.Level;
        TextHp.text      = hero.CurHp + "/" + hero.MaxHp;
        TextMp.text      = hero.CurMp + "/" + hero.MaxMp;
        TextCoins.text   = hero.Money.ToString();
        TextKDA.text     = hero.Kill + "/" + hero.Death;

        // 飘字设置
        HUDText.CanvasParent = GameObject.Find("Canvas").transform;

        // 复活倒计时
        TextRebirth.text = ServerConfig.HeroRebirthCD.ToString();
        TextRebirth.gameObject.SetActive(false);

        // 技能设置
        DtoSkill skill = null;

        for (int i = 0; i < hero.Skills.Length; i++)
        {
            skill = hero.Skills[i];
            if (skill != null)
            {
                Skills[i].gameObject.SetActive(true);
                Skills[i].GetComponent <ItemSkill>().Init(skill);
            }
        }
    }