Ejemplo n.º 1
0
        // 注册所有战斗消息
        public override void RegisterBattleMessageHandlers(IBattlemessageProvider bmp)
        {
            base.RegisterBattleMessageHandlers(bmp);

            bmp.HandleMsg("ExchangeBattleCards", (player, data) =>
            {
                var g1 = data.ReadInt();
                var n1 = data.ReadInt();
                var g2 = data.ReadInt();
                var n2 = data.ReadInt();

                Battle.ExchangeBattleCards(g1, n1, g2, n2);
            });

            bmp.HandleMsg("FireActiveSkill", (player, data) =>
            {
                var warriorID = data.ReadInt();
                var skillName = data.ReadString();
                var warrior   = Battle.Map.GetByID <Warrior>(warriorID);
                var skill     = warrior.GetActiveSkillByName(skillName);
                Battle.FireSkill(skill);
            });

            bmp.HandleMsg("FireActiveSkillAt", (player, data) =>
            {
                var warriorID = data.ReadInt();
                var skillName = data.ReadString();
                var x         = data.ReadInt();
                var y         = data.ReadInt();
                var warrior   = Battle.Map.GetByID <Warrior>(warriorID);
                var skill     = warrior.GetActiveSkillByName(skillName);
                Battle.FireSkillAt(skill, x, y);
            });

            bmp.HandleMsg("UseItem2", (player, data) =>
            {
                var itemID   = data.ReadInt();
                var targetID = data.ReadInt();
                var item     = Battle.Map.GetByID <ItemOnMap>(itemID);
                var target   = Battle.Map.GetByID <Warrior>(targetID);
                Battle.UseItem2(item as ItemOnMap, target);
            });

            bmp.HandleMsg("SortingBattleCards", (player, data) =>
            {
                var warriorID = data.ReadInt();
                var warrior   = Battle.Map.GetByID <Warrior>(warriorID);
                Battle.SortBattleCard(warrior);
            });
        }
Ejemplo n.º 2
0
        public virtual void RegisterBattleMessageHandlers(IBattlemessageProvider bmp)
        {
            bmp.OnMessageIn = (int seqNo, byte[] data) =>
            {
                if (seqNo > Battle.Replay.Messages.Count)
                {
                    Battle.Replay.Messages.Add(data);
                    ReplayChanged?.Invoke();
                }
            };

            bmp.HandleMsg("ExchangeWarroirsPosition", (player, data) =>
            {
                var fx = data.ReadInt();
                var fy = data.ReadInt();
                var tx = data.ReadInt();
                var ty = data.ReadInt();
                Battle.ExchangeWarroirsPosition(fx, fy, tx, ty);
            });

            bmp.HandleMsg("PlayerPrepared", (player, data) =>
            {
                Battle.PlayerPrepared(player);
            });

            bmp.HandleMsg("MoveOnPath", (player, data) =>
            {
                var id        = data.ReadInt();
                var pathXYArr = data.ReadIntArr();

                var warrior = Battle.Map.GetByID <Warrior>(id);
                warrior.MovingPath.Clear();
                warrior.MovingPath.AddRange(pathXYArr);

                Battle.MoveOnPath(warrior);
            });

            bmp.HandleMsg("Attack", (player, data) =>
            {
                var attackerID = data.ReadInt();
                var targetID   = data.ReadInt();

                var attacker = Battle.Map.GetByID <Warrior>(attackerID);
                var target   = Battle.Map.GetByID <Warrior>(targetID);

                if (attacker is Hero)
                {
                    Battle.Attack(attacker, target);
                }
            });

            bmp.HandleMsg("MoveOnPathAndAttack", (player, data) =>
            {
                var attackerID = data.ReadInt();
                var pathXYArr  = data.ReadIntArr();
                var targetID   = data.ReadInt();

                var attacker = Battle.Map.GetByID <Warrior>(attackerID);
                attacker.MovingPath.Clear();
                attacker.MovingPath.AddRange(pathXYArr);
                var target = Battle.Map.GetByID <Warrior>(targetID);

                if (attacker is Hero)
                {
                    Battle.MoveOnPathAndAttack(attacker, target);
                }
            });

            bmp.HandleMsg("ActionDone", (player, data) =>
            {
                Battle.ActionDone(player);
            });
        }