示例#1
0
    IEnumerator FireSkillAniAt(ActiveSkill skill, int x, int y)
    {
        var avatar            = BattleStage.GetAvatarByWarrior(skill.Owner);
        var MapAvatar         = avatar.gameObject.transform.Find("_MapWarrior");
        var skeletonAnimation = MapAvatar.GetComponent <SkeletonAnimation>();

        skeletonAnimation.AnimationState.SetAnimation(0, "skill", false);
        yield return(new WaitForSeconds(2.0f));

        skeletonAnimation.AnimationState.SetAnimation(0, "idle", true);
    }
示例#2
0
 // 清除范围显示
 public void RemoveShowRange()
 {
     BattleStage.RemoveTile(Range);
     BattleStage.Map.ForeachObjs((x, y, obj) =>
     {
         if (obj is Warrior)
         {
             var avatar = BattleStage.GetAvatarByWarrior(obj as Warrior);
             avatar.FriendSkillDec.SetActive(false);
             avatar.EnemySkillDec.SetActive(false);
         }
     });
 }
示例#3
0
    IEnumerator FireSkillAni(ActiveSkill skill)
    {
        var avatar            = BattleStage.GetAvatarByWarrior(skill.Owner);
        var MapAvatar         = avatar.gameObject.transform.Find("_MapWarrior");
        var skeletonAnimation = MapAvatar.GetComponent <SkeletonAnimation>();

        skeletonAnimation.AnimationState.SetAnimation(0, "skill", false);
        yield return(new WaitForSeconds(2.0f));

        // 如果是变身技能需要重新载入Idle动画
        if (skill.Owner is ITransformable)
        {
            avatar.SetIdleAnimation(skill.Owner);
        }
        else
        {
            skeletonAnimation.AnimationState.SetAnimation(0, "idle", true);
        }
    }
示例#4
0
    // 显示范围
    public void ShowRange(int cx, int cy, ActiveSkill skill, Action <int, int> onSelPos)
    {
        Debug.Assert(Range.Count == 0, "path asasrange is not empty now.");
        this.onSelPos = onSelPos;
        var map = BattleStage.Map;

        // 如果无释放范围的技能
        if (!(skill is ISkillWithRange))
        {
            // 需要过滤目标
            if (skill is ISkillWithTargetFilter)
            {
                var targetList = (skill as ISkillWithTargetFilter).AllAvaliableTargets();
                FC.For(targetList.Count, (i) =>
                {
                    var warrior = targetList[i] as Warrior;
                    if (warrior != null)
                    {
                        // 建立用于显示技能范围的地块
                        var avatar  = BattleStage.GetAvatarByWarrior(warrior);
                        var mapTile = BattleStage.CreateMapTile(avatar.X, avatar.Y);
                        mapTile.gameObject.SetActive(false);
                        Range.Add(mapTile);

                        // 显示人物身上的技能标识
                        if (warrior.Team == skill.Owner.Team)
                        {
                            avatar.FriendSkillDec.SetActive(true);
                        }
                        else
                        {
                            avatar.EnemySkillDec.SetActive(true);
                        }
                    }
                    else
                    {
                        Debug.Assert(warrior != null, "the target is not warrior");
                    }
                });
            }
        }
        else // 有释放范围的技能
        {
            var range = (skill as ISkillWithRange).Range;
            FC.SquareFor(cx, cy, range, (x, y) =>
            {
                if (x < 0 || x >= map.Width || y < 0 || y >= map.Height)
                {
                    return;
                }
                var obj = map.GetAt <BattleMapObj>(x, y);
                if (MU.ManhattanDist(x, y, cx, cy) == range)
                {
                    if (obj == null || (obj != null && obj is Hero))
                    {
                        var tile = BattleStage.CreateMapTile(x, y);
                        Range.Add(tile);
                    }
                }
            });
        }
    }
示例#5
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);
        };
    }