Example #1
0
    // 创建场景显示对象
    public void Build(BattleRoomClient room, Action <BattleReplay> onTimeBackTriggered)
    {
        ClearMap();

        Room = room;

        BuildMapGrids();
        BuildMapItems();
        BuildAvatars();

        PreparingOps    = new PreparingOps(this);  // 准备阶段
        InBattleOps     = new InBattleOps(this);   // 战斗内一般阶段
        UseMapItemOps   = new UseMapItemOps(this); // 战斗内地形改造阶段
        PosSelOps       = new PosSelOps(this);     //  战斗内释放技能阶段
        SkillPreviewOps = new SkillPreviewOps(this);

        OnTimeBackTriggered = onTimeBackTriggered;

        // 将场景中心移动到屏幕中心
        MapRoot.transform.localPosition = new Vector3(-Map.Width / 2, Map.Height / 2, 0);

        // 将底部响应操作的层铺满整个屏幕
        var sws = SceneWorldSize;

        MapGround.transform.localPosition = new Vector3(-sws.x / 2, sws.y / 2, 0);
        MapGround.transform.localScale    = new Vector3(sws.x, sws.y, 1);
    }
Example #2
0
    public static void SetupEventHandler(this CombatTestDriver CombatTestDriver, BattleRoomClient room)
    {
        var bt = CombatTestDriver.BattleStage.Battle as BattlePVE;

        room.Battle.OnPlayerPrepared += (int player) =>
        {
            if (room.Battle.AllPrepared)
            {
                CombatTestDriver.PreparingUI.SetActive(false);
            }
        };

        room.Battle.OnBattleEnded += (winner) =>
        {
            CombatTestDriver.GameOverUI.SetActive(true);
            CombatTestDriver.GameOverUI.transform.Find("Title").GetComponent <Text>().text = winner == room.PlayerMe ? "Win" : "Lose";
        };
    }
Example #3
0
    public static void SetupUIHandler(this BattleStage BattleStage, BattleRoomClient room)
    {
        var bt            = BattleStage.Battle as BattlePVE;
        var aniPlayer     = BattleStage.GetComponent <MapAniPlayer>();
        var stageUI       = BattleStage.BattleStageUIRoot.GetComponent <BattleStageUI>();
        var characterui   = stageUI.CharacterInfoUI;
        var skillButtonUI = stageUI.SkillButtonUI;

        bt.OnAddHP += (warrior, dhp) =>
        {
            var warriorInfo = characterui.GetWarriorInfo(warrior);
            aniPlayer.Op(() =>
            {
                characterui.UpdateWarriorInfo(warrior, warriorInfo);
            });
        };

        //bt.OnAddHP += (warrior, dhp) =>
        //{
        //    aniPlayer.Op(() => skillButtonUI.UpdateSkill(warrior));
        //};

        bt.OnWarriorAttack += (attacker, target, addTars, dhps, dess, skill, flags) =>
        {
            var warriorInfo = characterui.GetWarriorInfo(target);
            aniPlayer.Op(() => characterui.UpdateWarriorInfo(target, warriorInfo));
        };

        bt.OnWarriorAttack += (warrior, target, addTars, dhps, dess, skill, flags) =>
        {
            aniPlayer.Op(() => skillButtonUI.UpdateSkillState(bt.Energy, (BattleStage.CurrentOpLayer as InBattleOps)?.CurrentSelWarrior));
        };

        //bt.AfterAttack += (warrior, target, skill, flags) =>
        //{
        //    aniPlayer.Op(() => characterui.UpdateWarriorInfo((BattleStage.CurrentOpLayer as InBattleOps)?.CurrentSelWarrior));
        //};

        //bt.AfterAttack += (warrior, target, skill, flags) =>
        //{
        //    aniPlayer.Op(() => skillButtonUI.UpdateSkillState(bt.Energy, (BattleStage.CurrentOpLayer as InBattleOps)?.CurrentSelWarrior));
        //};

        bt.OnAddES += (warrior, des) =>
        {
            var warriorInfo = characterui.GetWarriorInfo(warrior);
            aniPlayer.Op(() => characterui.UpdateWarriorInfo(warrior, warriorInfo));
        };

        bt.OnAddATK += (warrior, dATK) =>
        {
            var warriorInfo = characterui.GetWarriorInfo(warrior);
            aniPlayer.Op(() => characterui.UpdateWarriorInfo(warrior, warriorInfo));
        };

        bt.OnTransfrom += (warrior, state) =>
        {
            var warriorInfo = characterui.GetWarriorInfo(warrior);
            aniPlayer.Op(() => characterui.UpdateWarriorInfo(warrior, warriorInfo));
        };

        bt.OnSetActionFlag += (warrior, isMoved, isActionDone, isSkillReleased) =>
        {
            // 如果英雄完成回合则动作显示技能框
            if (isActionDone)
            {
                stageUI.SkillButtonUI.UpdateSkillState((BattleStage.Battle as BattlePVE).Energy, warrior);
            }
        };

        // 回合结束清除左上角信息栏显示
        bt.OnActionDone += (int team) =>
        {
            stageUI.CharacterInfoUI.gameObject.SetActive(false);
            stageUI.obstacleUI.gameObject.SetActive(false);
        };

        // 角色死亡清除信息栏显示
        bt.OnWarriorDying += (warrior) =>
        {
            aniPlayer.Op(() => characterui.gameObject.SetActive(false));
        };
    }
Example #4
0
    // 开始游戏,可能是新游戏,也可能是播放录像
    public void StartGame(BattleReplay battleReplay = null)
    {
        var map = new BattleMap(10, 6, (x, y) => TileType.Grass); // test map
        var s   = DateTime.Now.ToLocalTime().ToString();
        var bt  = new BattlePVE(map, 0, new PlayerInfo {
            ID = "tester:" + s, Name = "战斗测试:" + s
        });                                                                                        // test battle
        var p = new Player();

        // 载入地图
        if (battleReplay == null)
        {
            map.MapInfo       = MapReader.ReloadMapInfo();
            bt.Replay.MapName = MapReader.MapNameList[MapReader.ArrayIndex];
        }
        else
        {
            MapReader.ReloadMapByName(battleReplay.MapName);
            map.MapInfo = MapReader.Map;
        }

        map.GetRespawnPlace();

        // 配置buff显示列表
        BattleStageUI.CharacterInfoUI.BuffDisplayList = Configuration.Config(new BuffToDisplay());

        // npcs
        FC.For(3, (i) =>
        {
            bt.AddWarriorAt(map.RespawnForEnemy[i].X, map.RespawnForEnemy[i].Y, Configuration.Config(new Boar(map)
            {
                Team = 2
            }));
        });

        // heros

        // 黛丽万
        var dlw = Configuration.Config(new DaiLiWan(bt)
        {
            Team = 1
        });

        dlw.AddRune(new DaiLiWanRune1());
        dlw.AddRune(new DaiLiWanRune2());
        dlw.AddRune(new DaiLiWanRune3());
        dlw.AddRune(new DaiLiWanRune4());
        dlw.RunAllRune2PrepareBattle();
        bt.AddWarriorAt(map.RespawnForChamp[0].X, map.RespawnForChamp[0].Y, dlw);

        // 洛里斯
        var lls = Configuration.Config(new LuoLiSi(bt)
        {
            Team = 1
        });

        lls.AddRune(new LuoLiSiRune1());
        lls.AddRune(new LuoLiSiRune2());
        lls.AddRune(new LuoLiSiRune3());
        lls.AddRune(new LuoLiSiRune4());
        lls.RunAllRune2PrepareBattle();
        bt.AddWarriorAt(map.RespawnForChamp[1].X, map.RespawnForChamp[1].Y, lls);

        // 巴洛克
        var blk = Configuration.Config(new BaLuoKe(bt)
        {
            Team = 1
        });

        blk.AddRune(new BaLuoKeRune1());
        blk.AddRune(new BaLuoKeRune2());
        blk.AddRune(new BaLuoKeRune3());
        blk.AddRune(new BaLuoKeRune4());
        blk.RunAllRune2PrepareBattle();
        bt.AddWarriorAt(map.RespawnForChamp[2].X, map.RespawnForChamp[2].Y, blk);

        // 游川隐
        var ycy = Configuration.Config(new YouChuanYin(bt)
        {
            Team = 1
        });

        ycy.AddRune(new YouChuanYinRune1());
        ycy.AddRune(new YouChuanYinRune2());
        ycy.AddRune(new YouChuanYinRune3());
        ycy.AddRune(new YouChuanYinRune4());
        ycy.RunAllRune2PrepareBattle();
        bt.AddWarriorAt(map.RespawnForChamp[3].X, map.RespawnForChamp[3].Y, ycy);

        // 装备
        var e1 = new Equip();

        e1.AddAttr(new CollageAdd()
        {
            P0 = 1
        });
        e1.AddAttr(new StartAddShd()
        {
            P0 = 50
        });
        e1.AddAttr(new BackNoRange());
        e1.AddAttr(new Spurt()
        {
            P0 = -50
        });
        p.AddEquip(e1);

        p.OnPreparingBattle(bt);

        // items
        // bt.AddItemAt(7, 2, Configuration.Config(new Trunk(map)));
        // bt.AddItemAt(7, 4, Configuration.Config(new Rock(map)));

        // test room
        var room = new BattleRoomClient(new BattlePVERoom(bt))
        {
            PlayerMe = 1
        };

        room.BattleRoom.ReplayChanged += () =>
        {
            if (!Recoder.Exists(bt.Replay))
            {
                Recoder.AddReplay(bt.Replay);
            }

            Recoder.SaveAll();
        };

        // setup the fake message loop
        room.BMS = msgLooper;
        msgLooper.Clear();
        room.RegisterBattleMessageHandlers(msgLooper);

        // build up the whole scene
        BattleStage.Build(room, (replay) =>
        {
            // var aniPlayer = BattleStage.GetComponent<MapAniPlayer>();
            // aniPlayer.AnimationTimeScaleFactor = 10000;
            StartGame();
            PlayReplay(replay);
        });

        // link the logic event to the stage and ui logic
        BattleStage.SetupEventHandler(room);
        BattleStage.SetupUIHandler(room);
        BattleStageUI.SetupEventHandler(room);
        this.SetupEventHandler(room);

        StartingUI.SetActive(false);
        PreparingUI.SetActive(true);
        BattleStage.gameObject.SetActive(true);
        BattleStage.StartPreparing();
    }
Example #5
0
    public static void SetupEventHandler(this BattleStageUI BattleStageUI, BattleRoomClient room)
    {
        var bt        = BattleStageUI.BattleStage.Battle as BattlePVE;
        var aniPlayer = BattleStageUI.AniPlayer;

        bt.OnPlayerPrepared += (int player) =>
        {
            if (room.Battle.AllPrepared)
            {
                aniPlayer.Op(() =>
                {
                    BattleStageUI.ActioDoneBtn.gameObject.SetActive(true);
                    BattleStageUI.gameObject.SetActive(true);
                    BattleStageUI.CardArea.RefreshEnergy(bt.Energy, bt.MaxEnergy);
                    //  BattleStageUI.SkillButtonUI.UpdateSkillState(bt.Energy);
                    BattleStageUI.RefreshItemUsage(bt.CardUsage);
                });
            }
        };

        bt.OnBattleEnded += (winner) =>
        {
            aniPlayer.Op(() => BattleStageUI.gameObject.SetActive(false));
        };

        bt.OnActionDone += (player) =>
        {
            if (player != room.PlayerMe)
            {
                return;
            }

            aniPlayer.Op(() => BattleStageUI.CardArea.RefreshCardsAvailable(bt.AvailableCards));
        };

        bt.OnAddBattleCard += (card) =>
        {
            aniPlayer.Op(() => BattleStageUI.CardArea.RefreshCardsAvailable(bt.AvailableCards));
        };

        bt.OnNextRoundStarted += (player) =>
        {
            if (player != room.PlayerMe)
            {
                return;
            }

            aniPlayer.Op(() =>
            {
                var availableCards = new List <BattleCard>();
                availableCards.AddRange(bt.AvailableCards);
                BattleStageUI.CardArea.RefreshCardsAvailable(availableCards);
            });
        };

        bt.OnCardsConsumed += (warrior, cards) =>
        {
            if (warrior.Team != room.PlayerMe)
            {
                return;
            }

            aniPlayer.Op(() =>
            {
                var availableCards = new List <BattleCard>();
                availableCards.AddRange(bt.AvailableCards);
                BattleStageUI.CardArea.RefreshCardsAvailable(availableCards);
            });
        };

        bt.OnBattleCardsExchange += (int g1, int n1, int g2, int n2) =>
        {
            aniPlayer.Op(() =>
            {
                BattleStageUI.CardArea.RefreshCardsAvailable(bt.AvailableCards);
                BattleStageUI.CardArea.RefreshCardsStarshed(bt.StashedCards);
            });
        };

        // 自动排序卡牌时刷新UI
        bt.OnSortBattleCard += (warrior, availableCards) =>
        {
            aniPlayer.Op(() =>
            {
                BattleStageUI.CardArea.RefreshCardsAvailable(availableCards);
            });
        };

        bt.OnAddEN += (den) => aniPlayer.Op(() => BattleStageUI.CardArea.RefreshEnergy(bt.Energy, bt.MaxEnergy));
        bt.OnAddEN += (den) => aniPlayer.Op(() => BattleStageUI.SkillButtonUI.UpdateSkillState(bt.Energy, (BattleStageUI.BattleStage.CurrentOpLayer as InBattleOps)?.CurrentSelWarrior));
        bt.OnAddCardDissambleValue += (dv) => aniPlayer.Op(() => BattleStageUI.RefreshItemUsage(bt.CardUsage));

        InBattleOps.OnCurrentWarriorChanged += () => aniPlayer.Op(() => BattleStageUI.CardArea.RefreshEnergy(bt.Energy, bt.MaxEnergy));
        InBattleOps.OnCurrentWarriorChanged += () => aniPlayer.Op(() => BattleStageUI.RefreshItemUsage(bt.CardUsage));

        BattleStageUI.BattleStage.Battle.OnPlayerPrepared += (int num) =>
        {
            var CardAreaTransform = BattleStageUI.CardArea.transform;
            CardAreaTransform.parent.gameObject.SetActive(true);
        };

        BattleStageUI.BattleStage.Battle.OnPlayerPrepared += (int num) =>
        {
            BattleStageUI.BattleStage.ForeachAvatar((x, y, avatar) =>
            {
                avatar.IsShowClickFrame = false;
            });
        };

        BattleStageUI.BattleStage.Battle.OnPlayerPrepared += (int num) =>
        {
            BattleStageUI.BattleStage.ForeachMapTile((x, y, mapTile) =>
            {
                mapTile.transform.Find("RespawnPlace").gameObject.SetActive(false);
            });
        };
    }
Example #6
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);
        };
    }