コード例 #1
0
        [UnityTest]//测试 简单召唤行为 并且给怪兽加500点攻击 然后移除
        public IEnumerator Test_NormalCall_NormalBuff()
        {
            var cards    = new int[] { 1, 2, 3, 4, 5 };
            var cardNum  = cards.Length;
            var playerID = 0;
            var model    = BattleManager.Instance.GetPlayerModel(playerID);

            model.InitDeck(cards);
            var attackValue = 500;
            var lifeValue   = 100;
            var config      = new CardConfig()
            {
                Attack = attackValue,
                Lifte  = lifeValue
            };
            var deckList   = model.GetCardList(SiteType.Deck);
            var groundList = model.GetCardList(SiteType.Ground);
            var handleList = model.GetCardList(SiteType.Hand);

            for (int i = 0; i < deckList.Count; i++)
            {
                var card = HandleManager <Card> .Instance.Get(deckList[i]);

                TestHelper.SetInstanceField(card, "m_config", config);
            }
            var       codes1    = new int[] { 103, 116, 103, 115, 114, 127 }; //召唤怪兽
            LBehavior behavior1 = new LBehavior(playerID, codes1);
            var       codes2    = new int[] { 1, 1, 103, 113, 127 };          //抽卡
            LBehavior behavior2 = new LBehavior(playerID, codes2);

            yield return(behavior2.AsynceExecute().ToCoroutine());

            yield return(behavior2.AsynceExecute().ToCoroutine());

            Assert.AreEqual(deckList.Count, 3);
            Assert.AreEqual(handleList.Count, 2, "手牌");
            var callCard = handleList[0];

            BattleManager.Instance.EStation.AddListener(LEventType.ChoseMonsterCard, async x =>
            {
                var data       = HandleManager <EventData_ChoseMonsterCard> .Instance.Get(x);
                data.CardHanle = callCard;
                await UniTask.Yield();
            });
            BattleManager.Instance.EStation.AddListener(LEventType.SelectLocation, async x =>
            {
                var data      = HandleManager <EventData_SelectLocation> .Instance.Get(x);
                data.Location = Vector2Int.one;
                await UniTask.Yield();
            });
            BattleManager.Instance.EStation.AddListener(LEventType.NomalCallSuccess, async x =>
            {
                var data          = HandleManager <EventData_NomalCallSuccess> .Instance.Get(x);
                data.Location     = Vector2Int.one;
                var card          = HandleManager <Card> .Instance.Get(data.CardHandle);
                var monsterHandle = (Handle <Monster>)TestHelper.GetInstanceField(card, "m_monsterHandle");
                var monster       = HandleManager <Monster> .Instance.Get(monsterHandle);
                var location      = (Vector2Int)TestHelper.GetInstanceField(card, "m_location");
                Assert.AreEqual(monster.GetPropVlaue(PropType.Attack), attackValue, "攻击力");
                // Assert.AreEqual(monster.GetMaxLife(), lifeValue, "最大生命");
                Assert.AreEqual(callCard, data.CardHandle);
                Assert.AreEqual(location, Vector2Int.one);
                await UniTask.Yield();
            });
            yield return(behavior1.AsynceExecute().ToCoroutine());

            Assert.AreEqual(deckList.Count, 3);
            Assert.AreEqual(handleList.Count, 1, "最后手牌数");
            Assert.AreEqual(groundList.Count, 1);

            //测试增加攻击力 和 最大生命buff
            behavior1.SetCodes(new int[] { 1, 1000, 1, 1, 1, 1, 125, 124, 118, 1, 500, 1, 0, 1, 1, 125, 124, 118, 127 });
            behavior1.SetData(LBehavior.DataType.BuffHandle, 100);
            behavior1.SetData(LBehavior.DataType.CardHandle, callCard);
            yield return(behavior1.AsynceExecute().ToCoroutine());

            var callMonster = callCard.Get <Card>().GetMonsterHandle().Get <Monster>();

            Assert.AreEqual(callMonster.GetPropVlaue(PropType.Attack), attackValue + 500, "多了500点");
            Assert.AreEqual(callMonster.GetPropVlaue(PropType.MaxLife), lifeValue + 1000, "多了1000点");
            //测试移除攻击力buff
            behavior1.SetCodes(new int[] { 2, 2, 0, 1, 1, 1, 125, 124, 120, 127 });
            behavior1.SetData(LBehavior.DataType.BuffHandle, 100);
            behavior1.SetData(LBehavior.DataType.CardHandle, callCard);
            yield return(behavior1.AsynceExecute().ToCoroutine());

            Assert.AreEqual(callMonster.GetPropVlaue(PropType.Attack), attackValue, "攻击恢复正常");
            Assert.AreEqual(callMonster.GetPropVlaue(PropType.MaxLife), lifeValue, "生命恢复正常");
        }