示例#1
0
    public override void OnStartDragging(float x, float y)
    {
        if (currentSelAvatar != null)
        {
            currentSelAvatar.Color = MapAvatar.ColorDefault;
            currentSelAvatar       = null;
        }

        WorldPos2MapPos(x, y, out float gx, out float gy);
        var avatar = BattleStage.GetAvatarAt((int)gx, (int)gy);

        if (avatar == null || avatar.Warrior.Team != Room.PlayerMe)
        {
            base.OnStartDragging(x, y);
            return;
        }

        // 显示指针,并隐藏准备拖拽的对象
        currentSelAvatar = avatar;
        PointerIndicator.SetActive(true);
        PointerIndicator.GetComponent <PoniterIndicator>().SetIdleAnimation(currentSelAvatar);
        PointerIndicator.transform.position = currentSelAvatar.transform.position;
        dragPointerOffset = new Vector2(PointerIndicator.transform.position.x - x, PointerIndicator.transform.position.y - y);
        currentSelAvatar.gameObject.SetActive(false);
    }
示例#2
0
    public override void OnClicked(float x, float y)
    {
        WorldPos2MapPos(x, y, out float gx, out float gy);
        var avatar = BattleStage.GetAvatarAt((int)gx, (int)gy);

        if (currentSelAvatar == null && avatar != null && avatar.Warrior.Team == Room.PlayerMe)
        {
            // 选中要移动的角色
            currentSelAvatar        = avatar;
            avatar.IsShowClickFrame = true;
        }
        else if (currentSelAvatar != null)
        {
            // 交换角色位置
            var mapTile = BattleStage.GetMapTileAt((int)gx, (int)gy);
            currentSelAvatar.IsShowClickFrame = false;
            if (mapTile != null && mapTile.MapData.RespawnForChamp == false)
            {
                currentSelAvatar = null;
                return;
            }
            Room.DoExchangeWarroirsPosition(currentSelAvatar.X, currentSelAvatar.Y, (int)gx, (int)gy);
            currentSelAvatar = null;
        }
    }
示例#3
0
    public void SetIdleAnimation(MapAvatar avater)
    {
        GameObject MapWarrior = avater.gameObject;

        skeletonAnimation.skeletonDataAsset = MapWarrior.transform.Find("_MapWarrior").GetComponent <SkeletonAnimation>().skeletonDataAsset;
        skeletonAnimation.Initialize(true);
        Mesh.sortingOrder = 8;
        skeletonAnimation.AnimationState.SetAnimation(0, "idle", true);
    }
示例#4
0
    // 设置角色位置
    public void SetAvatarPosition(MapAvatar avatar, int x, int y)
    {
        if (avatar != null)
        {
            avatar.X = x;
            avatar.Y = y;
        }

        Avatars[x, y] = avatar;
    }
示例#5
0
    // 根据角色获取 Avatar
    public MapAvatar GetAvatarByWarrior(Warrior warrior)
    {
        MapAvatar avatar = null;

        ForeachAvatar((x, y, a) =>
        {
            if (a != null && a.Warrior == warrior)
            {
                avatar = a;
            }
        }, () => avatar == null);

        Debug.Assert(avatar != null, "warrior should have a avatar in battle map");
        return(avatar);
    }
示例#6
0
    public IEnumerator SetSkillAttackAnimation(MapAvatar warrior, MapAvatar target)
    {
        gameObject.SetActive(true);
        var attackerAvatar = warrior.transform.Find("_MapWarrior");
        var targetAvatar   = target.transform.Find("_MapWarrior");

        if (warrior.Warrior.Team == 1) // 如果攻击方是己方
        {
            champSkeleton.skeletonDataAsset = attackerAvatar.GetComponent <SkeletonAnimation>().skeletonDataAsset;
            enemySkeleton.skeletonDataAsset = targetAvatar.GetComponent <SkeletonAnimation>().skeletonDataAsset;
            champSkeleton.Initialize(true);
            enemySkeleton.Initialize(true);
            enemySkeleton.skeleton.scaleX = -1;
            champSkeleton.AnimationState.SetAnimation(0, "skill", false);
            yield return(new WaitForSeconds(0.5f));

            enemySkeleton.AnimationState.SetAnimation(0, "hurt", false);
            yield return(new WaitForSeconds(0.3f));

            enemySkeleton.AnimationState.SetAnimation(0, "idle", false);
            yield return(new WaitForSeconds(0.7f));
        }
        else
        { //如果攻击方是敌军
            enemySkeleton.skeletonDataAsset = attackerAvatar.GetComponent <SkeletonAnimation>().skeletonDataAsset;
            champSkeleton.skeletonDataAsset = targetAvatar.GetComponent <SkeletonAnimation>().skeletonDataAsset;
            champSkeleton.Initialize(true);
            enemySkeleton.Initialize(true);
            enemySkeleton.skeleton.scaleX = -1;
            enemySkeleton.AnimationState.SetAnimation(0, "attack", false); // 目前的怪物没有技能攻击用普通攻击代替
            yield return(new WaitForSeconds(0.5f));

            champSkeleton.AnimationState.SetAnimation(0, "hurt", false);
            yield return(new WaitForSeconds(0.3f));

            champSkeleton.AnimationState.SetAnimation(0, "idle", false);
            yield return(new WaitForSeconds(0.7f));
        }
        gameObject.SetActive(false);
    }
示例#7
0
    public override void OnEndDragging(float fx, float fy, float tx, float ty)
    {
        WorldPos2MapPos(fx, fy, out float gfx, out float gfy);
        WorldPos2MapPos(tx, ty, out float gtx, out float gty);
        var mapTile = BattleStage.GetMapTileAt((int)gtx, (int)gty);

        if (currentSelAvatar == null)
        {
            return;
        }

        // 隐藏指针,执行交换操作,并显示被拖拽对象
        PointerIndicator.SetActive(false);
        currentSelAvatar.gameObject.SetActive(true);
        currentSelAvatar.IsShowClickFrame = false;
        currentSelAvatar = null;

        if (mapTile != null && mapTile.MapData.RespawnForChamp == false)
        {
            return;
        }
        Room.DoExchangeWarroirsPosition((int)gfx, (int)gfy, (int)gtx, (int)gty);
    }
示例#8
0
 IEnumerator MakeDyingImpl(MapAvatar avatar)
 {
     BattleStage.BattleScene.GetComponent <BattleScene>().WarriorDying(avatar);
     yield return(new WaitForSeconds(0.8f));
 }
示例#9
0
 // 角色死亡
 public MapAniPlayer MakeDying(MapAvatar avatar) => Add(MakeDyingImpl(avatar));
示例#10
0
    public static void SetupEventHandler(this BattleStage BattleStage, BattleRoomClient room)
    {
        var bt        = BattleStage.Battle as BattlePVE;
        var aniPlayer = BattleStage.GetComponent <MapAniPlayer>();

        // 角色位置变化
        room.Battle.OnWarriorPositionExchanged += (int fromX, int fromY, int toX, int toY) =>
        {
            aniPlayer.Op(() =>
            {
                var avFrom = BattleStage.Avatars[fromX, fromY];
                var avTo   = BattleStage.Avatars[toX, toY];

                BattleStage.SetAvatarPosition(avFrom, toX, toY);
                BattleStage.SetAvatarPosition(avTo, fromX, fromY);
            });
        };

        // 回合开始
        room.Battle.OnNextRoundStarted += (int player) =>
        {
            if (player != room.PlayerMe)
            {
                return;
            }

            BattleStage.ForeachAvatar((x, y, avatar) =>
            {
                var doRefresh = avatar.DelayRefreshAttrs();
                aniPlayer.Op(doRefresh);
            });
        };

        // 角色攻击
        room.Battle.OnWarriorAttack += (Warrior attacker, Warrior target, List <Warrior> addTars, Dictionary <Warrior, int> dhps, Dictionary <Warrior, int> dess, Skill skill, HashSet <string> flags) =>
        {
            var attackerAvatar    = BattleStage.GetAvatarByWarrior(attacker);
            var targetAvatar      = BattleStage.GetAvatarByWarrior(target);
            var doAttackerRefresh = attackerAvatar.DelayRefreshAttrs();
            var doTargetRefresh   = attackerAvatar.DelayRefreshAttrs();
            if (flags.Contains("SkillAttack"))
            {
                aniPlayer.SkillAttacking(attackerAvatar, targetAvatar).OnEnded(() => { doAttackerRefresh(); doTargetRefresh(); });
            }
            else
            {
                aniPlayer.MakeAttacking2(attackerAvatar, targetAvatar).OnEnded(() => { doAttackerRefresh(); doTargetRefresh(); });
            }
        };

        // 角色扣血显示
        bt.OnAddHP += (warrior, dhp) =>
        {
            aniPlayer.Op(() =>
            {
                var battleScene = BattleStage.BattleScene.GetComponent <BattleScene>();
                battleScene.CreateLostHP(warrior, dhp);
            });
        };

        // 角色移动
        room.Battle.OnWarriorMovingOnPath += (Warrior warrior, int x, int y, List <int> path, bool ignoreMoveRangeRestrict) =>
        {
            var tx = path[path.Count - 2];
            var ty = path[path.Count - 1];

            MapAvatar avatar = BattleStage.GetAvatarByWarrior(warrior);
            Debug.Assert(avatar != null && avatar.Warrior == warrior, "the avatar is not just on the start position");

            var doRefresh = avatar.DelayRefreshAttrs();
            aniPlayer.MakeMovingOnPath(
                avatar.transform, 5,
                FC.ToArray(path, (i, p, doSkip) => i % 2 == 0 ? p + avatar.CenterOffset.x : p + avatar.CenterOffset.y)
                ).OnEnded(() =>
            {
                BattleStage.SetAvatarPosition(null, x, y);
                BattleStage.SetAvatarPosition(avatar, tx, ty);
                doRefresh();
            });
        };

        // 回合开始
        room.Battle.OnNextRoundStarted += (int team) =>
        {
            BattleStage.ForeachAvatar((x, y, avatar) =>
            {
                if (avatar.Warrior.Team != team)
                {
                    return;
                }

                var doRefresh = avatar.DelayRefreshAttrs();
                aniPlayer.Op(doRefresh);
            });
        };

        // 回合结束
        room.Battle.OnActionDone += (int team) =>
        {
            aniPlayer.Op(() =>
            {
                var op = BattleStage.CurrentOpLayer as InBattleOps;
                op.RemoveShowAttackRange();
                op.RemoveMovingPathRange();
                op.ClearPath();
            });

            BattleStage.ForeachAvatar((x, y, avatar) =>
            {
                if (avatar.Warrior.Team != team)
                {
                    return;
                }

                var doRefresh = avatar.DelayRefreshAttrs();
                aniPlayer.Op(doRefresh);
            });
        };

        // 角色死亡
        room.Battle.OnWarriorDying += (Warrior warrior) =>
        {
            var avatar = BattleStage.GetAvatarByWarrior(warrior);
            aniPlayer.MakeDying(avatar).OnEnded(
                () =>
            {
                BattleStage.SetAvatarPosition(null, avatar.X, avatar.Y);
                avatar.transform.SetParent(null);
                BattleStage.Destroy(avatar.gameObject);
            }
                );
        };

        // 使用道具
        (room.Battle as BattlePVE).OnUseItem2 += (Avocat.ItemOnMap item, Warrior target) =>
        {
            var mapItem = BattleStage.GetMapItemByItem(item);
            var avatar  = BattleStage.GetAvatarByWarrior(target);

            var doRefresh = avatar.DelayRefreshAttrs();
            aniPlayer.MakeAttacking1(mapItem, avatar).OnEnded(
                () =>
            {
                doRefresh();
                BattleStage.Items[mapItem.X, mapItem.Y] = null;
                mapItem.transform.SetParent(null);
                BattleStage.Destroy(mapItem.gameObject);
            }
                );
        };

        bt.OnPlayerPrepared += (int player) =>
        {
            aniPlayer.Op(() =>
            {
                if (room.Battle.AllPrepared)
                {
                    BattleStage.StartFighting();
                }
            });
        };

        bt.OnAddHP += (warrior, dhp) =>
        {
            var doRefresh = BattleStage.GetAvatarByWarrior(warrior).DelayRefreshAttrs();
            aniPlayer.Op(doRefresh);
        };

        bt.OnAddATK += (warrior, dATK) =>
        {
            var doRefresh = BattleStage.GetAvatarByWarrior(warrior).DelayRefreshAttrs();
            aniPlayer.Op(doRefresh);
        };

        bt.OnAddES += (warrior, des) =>
        {
            var doRefresh = BattleStage.GetAvatarByWarrior(warrior).DelayRefreshAttrs();
            aniPlayer.Op(doRefresh);
        };

        bt.OnTransfrom += (warrior, state) =>
        {
            var doRefresh = BattleStage.GetAvatarByWarrior(warrior).DelayRefreshAttrs();
            aniPlayer.Op(doRefresh);
        };

        bt.OnAddWarrior += (x, y, warrior) =>
        {
            aniPlayer.Op(() => BattleStage.CreateWarriorAvatar(x, y, warrior));
        };

        bt.OnTimeBackTriggered += (BattleReplay replay) =>
        {
            aniPlayer.Op(() => BattleStage.OnTimeBackTriggered(replay));
        };

        bt.BeforeFireSkill += (ActiveSkill skill) =>
        {
            aniPlayer.FireSkill(skill);
        };

        bt.BeforeFireSkillAt += (ActiveSkill skill, int x, int y) =>
        {
            aniPlayer.FireSkillAt(skill, x, y);
        };
    }
示例#11
0
    public void WarriorDying(MapAvatar avatar)
    {
        var warriorAnimation = avatar.transform.Find("_MapWarrior").GetComponent <SkeletonAnimation>();

        warriorAnimation.AnimationState.SetAnimation(0, "die", false);
    }