public void turnEndTest() { Game game = new Game(new UnitTestGameEnv()); TestFrontend[] frontends = new TestFrontend[2]; frontends[0] = new TestFrontend(); frontends[1] = new TestFrontend(); game.addPlayer(frontends[0], new int[] { 1000, 1, 1, 1, 1, 1 }); game.addPlayer(frontends[1], new int[] { 2000, 1, 1, 1, 1, 1 }); game.init(); int firstPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[0]; int secondPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[1]; game.initReplace(0, new int[0]); game.initReplace(1, new int[0]); game.turnEnd(firstPlayerIndex); EventWitness witness = frontends[0].witnessList.Find(e => { return(e.eventName == "onTurnEnd"); }); Assert.IsNotNull(witness); Assert.AreEqual(firstPlayerIndex, witness.getVar <int>("playerIndex")); witness = frontends[0].witnessList[frontends[0].witnessList.IndexOf(witness) + 1]; Assert.AreEqual("onTurnStart", witness.eventName); Assert.AreEqual(secondPlayerIndex, witness.getVar <int>("playerIndex")); }
public void tiredTest() { Game game = new Game(new UnitTestGameEnv()); TestFrontend[] frontends = new TestFrontend[2]; frontends[0] = new TestFrontend(); frontends[1] = new TestFrontend(); game.addPlayer(frontends[0], new int[] { 1000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); game.addPlayer(frontends[1], new int[] { 2000, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }); game.init(); int firstPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[0]; int secondPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[1]; game.initReplace(0, new int[0]); game.initReplace(1, new int[0]); for (int i = 0; i < 8; i++) { game.turnEnd(firstPlayerIndex); game.turnEnd(secondPlayerIndex); } EventWitness witness = frontends[0].witnessList[frontends[0].witnessList.Count - 1].child[2]; Assert.AreEqual("onTired", witness.eventName); Assert.AreEqual(firstPlayerIndex, witness.getVar <int>("playerIndex")); witness = witness.child[0]; Assert.AreEqual("onDamage", witness.eventName); Assert.AreEqual(1, witness.getVar <int[]>("amounts")[0]); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback = null) { var gem = witness.getVar <int>("value"); var PlayerID = witness.getVar <int>("playerIndex"); deck.GetUserBoard(PlayerID).SetGem(-1, gem); return(false); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback = null) { var propName = witness.getVar <string>("propName"); var changeType = witness.getVar <PropertyChangeType>("changeType"); var val = witness.getVar <object>("value"); DebugUtils.LogNoImpl($"将{propName}设置为{val}的方法未定义."); return(false); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback = null) { int player = witness.getVar <int>("playerIndex"); int cardRID = witness.getVar <int>("cardRID"); int cardDID = witness.getVar <int>("cardDID", false); deck.GetUserBoard(player).DrawCard(new CardID(cardDID, cardRID), callback); return(true); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback = null) { var player = witness.getVar <int>("playerIndex"); deck.onTurnEnd(player); return(false); }
public void useTest() { Game game = new Game(new UnitTestGameEnv()); TestFrontend[] frontends = new TestFrontend[2]; frontends[0] = new TestFrontend(); frontends[1] = new TestFrontend(); game.addPlayer(frontends[0], new int[] { 1000, 1, 1, 1, 1, 1 }); game.addPlayer(frontends[1], new int[] { 2000, 1, 1, 1, 1, 1 }); game.init(); int firstPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[0]; game.initReplace(0, new int[0]); game.initReplace(1, new int[0]); int p0c0 = frontends[0].witnessList[0].getVar <int[][]>("initCardsRID")[firstPlayerIndex][0]; game.use(firstPlayerIndex, p0c0, 0, new int[0]); EventWitness witness = frontends[0].witnessList.Find(e => { return(e.eventName == "onUse"); }); Assert.IsNotNull(witness); Assert.AreEqual(firstPlayerIndex, witness.getVar <int>("playerIndex")); Assert.AreEqual(p0c0, witness.getVar <int>("cardRID")); Assert.AreEqual(1, witness.getVar <int>("cardDID")); Assert.AreEqual(0, witness.getVar <int>("targetPosition")); Assert.AreEqual(0, witness.getVar <int[]>("targetCardsRID").Length); Assert.AreEqual("onGemChange", witness.child[0].eventName); Assert.AreEqual(1, witness.child[0].getVar <int>("value")); Assert.AreEqual("onSummon", witness.child[1].eventName); Assert.AreEqual(firstPlayerIndex, witness.child[1].getVar <int>("playerIndex")); Assert.AreEqual(1, witness.child[1].getVar <int>("cardDID")); Assert.AreEqual(0, witness.child[1].getVar <int>("position")); witness = frontends[1].witnessList.Find(e => { return(e.eventName == "onUse"); }); Assert.IsNotNull(witness); Assert.AreEqual(firstPlayerIndex, witness.getVar <int>("playerIndex")); Assert.AreEqual(p0c0, witness.getVar <int>("cardRID")); Assert.AreEqual(1, witness.getVar <int>("cardDID")); Assert.AreEqual(0, witness.getVar <int>("targetPosition")); Assert.AreEqual(0, witness.getVar <int[]>("targetCardsRID").Length); Assert.AreEqual("onGemChange", witness.child[0].eventName); Assert.AreEqual(1, witness.child[0].getVar <int>("value")); Assert.AreEqual("onSummon", witness.child[1].eventName); Assert.AreEqual(firstPlayerIndex, witness.child[1].getVar <int>("playerIndex")); Assert.AreEqual(1, witness.child[1].getVar <int>("cardDID")); Assert.AreEqual(0, witness.child[1].getVar <int>("position")); }
public AutoEventArgs(EventWitness witness) { eventName = witness.eventName; foreach (string varName in witness.getVarNames()) { setProp(varName, witness.getVar(varName)); } }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback = null) { var player = witness.getVar <int>("playerIndex"); deck.CommonDeck.RoundStart(deck.selfID == player); return(false); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback) { int player = witness.getVar <int>("playerIndex"); int[] originalRID = witness.getVar <int[]>("originCardsRID"); int[] cardsRID = witness.getVar <int[]>("replacedCardsRID"); int[] cardsDID = witness.getVar <int[]>("replacedCardsDID", false); DebugUtils.NullCheck(cardsRID, "replacedCardsRID"); DebugUtils.NullCheck(originalRID, "originCardsRID"); if (cardsDID == null) { cardsDID = new int[cardsRID.Length]; } deck.GetUserBoard(player).ThrowCardsWithReplace(CardID.ToCardIDs(originalRID), CardID.ToCardIDs(cardsDID, cardsRID), callback); return(true); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback = null) { int playerIndex = witness.getVar <int>("playerIndex"); int cardRID = witness.getVar <int>("cardRID"); int cardDID = witness.getVar <int>("cardDID"); // 随从位置 int position = witness.getVar <int>("position"); var arg = new RetinueSummonEventArgs() { CardDID = cardDID, CardRID = cardRID, PlayerID = playerIndex, Position = position }; deck.RecvEvent(arg, callback); return(true); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback = null) { int playerIndex = witness.getVar <int>("playerIndex"); int cardRID = witness.getVar <int>("cardRID"); int cardDID = witness.getVar <int>("cardDID"); int targetPosition = witness.getVar <int>("targetPosition"); int[] targetCardRID = witness.getVar <int[]>("targetCardsRID"); UseCardEventArgs args; if (targetPosition == -1) { if (targetCardRID.Length == 0) { args = new UseCardEventArgs(); } else { args = new UseCardWithTargetArgs(targetCardRID); } } else { if (targetCardRID.Length == 0) { args = new UseCardWithPositionArgs(targetPosition); } else { args = new UseCardWithTargetPositionArgs(targetPosition, targetCardRID); } } args.CardRID = cardRID; args.CardDID = cardDID; args.PlayerID = playerIndex; deck.RecvEvent(args, callback); return(true); }
protected override bool witnessSuccessHandler(EventWitness witness, DeckController deck, GenericAction callback) { // 角色卡的DefineID int[] charactersDID = witness.getVar <int[]>("masterCardsDID"); // 角色卡的RuntimeID int[] charactersRID = witness.getVar <int[]>("masterCardsRID"); // 玩家卡组 int[] userCards = witness.getVar <int[]>("deck"); // 玩家顺序 int[] playerOrder = witness.getVar <int[]>("sortedPlayersIndex"); // 初始手牌DefineID int[] initHandCard = witness.getVar <int[]>("initCardsDID"); // 初始手牌RuntimeID int[][] initCardsRID = witness.getVar <int[][]>("initCardsRID"); DebugUtils.NullCheck(charactersDID, "charactersDID"); DebugUtils.NullCheck(charactersRID, "charactersRID"); DebugUtils.NullCheck(userCards, "userCards"); DebugUtils.NullCheck(playerOrder, "playerOrder"); DebugUtils.NullCheck(initHandCard, "initHandCard"); DebugUtils.NullCheck(initCardsRID, "initCardsRID"); if (charactersDID.Length != charactersRID.Length) { throw new LengthNotMatchException(charactersDID.Length, charactersRID.Length); } deck.SetPlayer(playerOrder, CardID.ToCardIDs(charactersDID, charactersRID)); deck.SetInitHandcard(initHandCard, initCardsRID); // 先抽卡再设置deck,防止deck中的被抽走( deck.SelfBoard.SetDeck(userCards); return(false); }
public void winTest() { Game game = new Game(new UnitTestGameEnv()); TestFrontend[] frontends = new TestFrontend[2]; frontends[0] = new TestFrontend(); frontends[1] = new TestFrontend(); game.addPlayer(frontends[0], new int[] { 1000, 1, 1, 1, 1, 1 }); game.addPlayer(frontends[1], new int[] { 2000, 1, 1, 1, 1, 1 }); game.init(); int firstPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[0]; int secondPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[1]; int cardRID = frontends[0].witnessList[0].getVar <int[][]>("initCardsRID")[firstPlayerIndex][0]; int targetCardRID = frontends[1].witnessList[0].getVar <int[]>("masterCardsRID")[secondPlayerIndex]; game.initReplace(0, new int[0]); game.initReplace(1, new int[0]); game.use(firstPlayerIndex, cardRID, 0, new int[0]); for (int i = 0; i < 30; i++) { game.turnEnd(firstPlayerIndex); game.turnEnd(secondPlayerIndex); game.attack(firstPlayerIndex, cardRID, targetCardRID); } EventWitness witness = frontends[0].witnessList[frontends[0].witnessList.Count - 1]; Assert.AreEqual("onAttack", witness.eventName); witness = witness.child[0]; Assert.AreEqual("onDamage", witness.eventName); witness = witness.child[0]; Assert.AreEqual("onDeath", witness.eventName); witness = witness.child[0]; Assert.AreEqual("onGameEnd", witness.eventName); Assert.AreEqual(1, witness.getVar <int[]>("winnerPlayersIndex").Length); Assert.AreEqual(firstPlayerIndex, witness.getVar <int[]>("winnerPlayersIndex")[0]); }
public void attackTest() { Game game = new Game(new UnitTestGameEnv()); TestFrontend[] frontends = new TestFrontend[2]; frontends[0] = new TestFrontend(); frontends[1] = new TestFrontend(); game.addPlayer(frontends[0], new int[] { 1000, 1, 1, 1, 1, 1 }); game.addPlayer(frontends[1], new int[] { 2000, 1, 1, 1, 1, 1 }); game.init(); int firstPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[0]; int secondPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[1]; int p0c0 = frontends[0].witnessList[0].getVar <int[][]>("initCardsRID")[firstPlayerIndex][0]; int p1c0 = frontends[1].witnessList[0].getVar <int[][]>("initCardsRID")[secondPlayerIndex][0]; game.initReplace(0, new int[0]); game.initReplace(1, new int[0]); game.use(firstPlayerIndex, p0c0, 0, new int[0]); game.turnEnd(firstPlayerIndex); game.use(secondPlayerIndex, p1c0, 0, new int[0]); game.turnEnd(secondPlayerIndex); game.attack(firstPlayerIndex, p0c0, p1c0); EventWitness witness = frontends[0].witnessList.Find(e => { return(e.eventName == "onAttack"); }); Assert.AreEqual(firstPlayerIndex, witness.getVar <int>("playerIndex")); Assert.AreEqual(p0c0, witness.getVar <int>("cardRID")); Assert.AreEqual(p1c0, witness.getVar <int>("targetCardRID")); witness = witness.child[0]; Assert.AreEqual("onDamage", witness.eventName); Assert.AreEqual(p0c0, witness.getVar <int[]>("cardsRID")[0]); Assert.AreEqual(p1c0, witness.getVar <int[]>("cardsRID")[1]); Assert.AreEqual(1, witness.getVar <int[]>("amounts")[0]); Assert.AreEqual(1, witness.getVar <int[]>("amounts")[1]); witness = witness.child[0]; Assert.AreEqual("onDeath", witness.eventName); Assert.AreEqual(p0c0, witness.getVar <int[]>("cardsRID")[0]); Assert.AreEqual(p1c0, witness.getVar <int[]>("cardsRID")[1]); }
/// <summary> /// 处理各种Witness /// </summary> /// <param name="witness"></param> /// <param name="deck"></param> /// <param name="callback"></param> public virtual void HandleWitness(EventWitness witness, DeckController deck, GenericAction callback = null) { var error = witness.getVar <ErrorCode>("code", false); if (error != ErrorCode.none) { if (!witnessFailHandler(witness, error, deck, callback)) { callback?.Invoke(this, null); } } else { if (!witnessSuccessHandler(witness, deck, callback)) { callback?.Invoke(this, null); } } }
public void initReplaceTest() { Game game = new Game(new UnitTestGameEnv()); TestFrontend[] frontends = new TestFrontend[2]; frontends[0] = new TestFrontend(); frontends[1] = new TestFrontend(); game.addPlayer(frontends[0], new int[] { 1000, 1, 1, 1, 1, 1 }); game.addPlayer(frontends[1], new int[] { 2000, 1, 1, 1, 1, 1 }); game.init(); int p0c0 = frontends[0].witnessList[0].getVar <int[][]>("initCardsRID")[0][0]; game.initReplace(0, new int[] { p0c0 }); int p1c0 = frontends[1].witnessList[0].getVar <int[][]>("initCardsRID")[1][0]; int p1c1 = frontends[1].witnessList[0].getVar <int[][]>("initCardsRID")[1][1]; game.initReplace(1, new int[] { p1c0, p1c1 }); Assert.AreEqual(5, frontends[0].witnessList.Count); EventWitness witness = frontends[0].witnessList[1]; Assert.AreEqual("onInitReplace", witness.eventName); Assert.AreEqual(0, witness.getVar <int>("playerIndex")); Assert.AreEqual(1, witness.getVar <int[]>("replacedCardsRID").Length); witness = frontends[0].witnessList[2]; Assert.AreEqual("onInitReplace", witness.eventName); Assert.AreEqual(1, witness.getVar <int>("playerIndex")); Assert.AreEqual(2, witness.getVar <int[]>("replacedCardsRID").Length); witness = frontends[0].witnessList[3]; Assert.AreEqual("onStart", witness.eventName); //玩家回合开始 witness = frontends[0].witnessList[4]; Assert.AreEqual("onTurnStart", witness.eventName); int firstPlayerIndex = frontends[0].witnessList[0].getVar <int[]>("sortedPlayersIndex")[0]; Assert.AreEqual(firstPlayerIndex, witness.getVar <int>("playerIndex")); //增加法力水晶并充满 Assert.AreEqual("onMaxGemChange", witness.child[0].eventName); Assert.AreEqual(1, witness.child[0].getVar <int>("value")); Assert.AreEqual("onGemChange", witness.child[1].eventName); Assert.AreEqual(1, witness.child[1].getVar <int>("value")); //抽一张卡 Assert.AreEqual("onDraw", witness.child[2].eventName); Assert.AreEqual(firstPlayerIndex, witness.child[2].getVar <int>("playerIndex")); Assert.AreEqual(5, frontends[1].witnessList.Count); witness = frontends[1].witnessList[1]; Assert.AreEqual("onInitReplace", witness.eventName); Assert.AreEqual(0, witness.getVar <int>("playerIndex")); Assert.AreEqual(1, witness.getVar <int[]>("replacedCardsRID").Length); witness = frontends[1].witnessList[2]; Assert.AreEqual("onInitReplace", witness.eventName); Assert.AreEqual(1, witness.getVar <int>("playerIndex")); Assert.AreEqual(2, witness.getVar <int[]>("replacedCardsRID").Length); witness = frontends[1].witnessList[3]; Assert.AreEqual("onStart", witness.eventName); //玩家回合开始 witness = frontends[1].witnessList[4]; Assert.AreEqual("onTurnStart", witness.eventName); Assert.AreEqual(firstPlayerIndex, witness.getVar <int>("playerIndex")); //增加法力水晶并充满 Assert.AreEqual("onMaxGemChange", witness.child[0].eventName); Assert.AreEqual(1, witness.child[0].getVar <int>("value")); Assert.AreEqual("onGemChange", witness.child[1].eventName); Assert.AreEqual(1, witness.child[1].getVar <int>("value")); //抽一张卡 Assert.AreEqual("onDraw", witness.child[2].eventName); Assert.AreEqual(firstPlayerIndex, witness.child[2].getVar <int>("playerIndex")); }
public void initTest() { Game game = new Game(new UnitTestGameEnv()); TestFrontend[] frontends = new TestFrontend[2]; frontends[0] = new TestFrontend(); frontends[1] = new TestFrontend(); game.addPlayer(frontends[0], new int[] { 1000, 1, 1, 1, 1, 1 }); game.addPlayer(frontends[1], new int[] { 2000, 1, 1, 1, 1, 1 }); game.init(); Assert.AreEqual(1, frontends[0].witnessList.Count); EventWitness witness = frontends[0].witnessList[0]; Assert.AreEqual("onInit", witness.eventName); Assert.AreEqual(1000, witness.getVar <int[]>("masterCardsDID")[0]); Assert.AreEqual(2000, witness.getVar <int[]>("masterCardsDID")[1]); Assert.AreEqual(2, witness.getVar <int[]>("sortedPlayersIndex").Length); bool isFirstPlayer = witness.getVar <int[]>("sortedPlayersIndex")[0] == 0; Assert.AreEqual(2, witness.getVar <int[][]>("initCardsRID").Length); Assert.AreEqual(isFirstPlayer ? 3 : 4, witness.getVar <int[][]>("initCardsRID")[0].Length); Assert.AreEqual(isFirstPlayer ? 3 : 4, witness.getVar <int[]>("initCardsDID").Length); Assert.AreEqual(isFirstPlayer ? 2 : 1, witness.getVar <int[]>("deck").Length); Assert.AreEqual(1, frontends[1].witnessList.Count); witness = frontends[1].witnessList[0]; Assert.AreEqual("onInit", witness.eventName); Assert.AreEqual(1000, witness.getVar <int[]>("masterCardsDID")[0]); Assert.AreEqual(2000, witness.getVar <int[]>("masterCardsDID")[1]); Assert.AreEqual(2, witness.getVar <int[]>("sortedPlayersIndex").Length); isFirstPlayer = witness.getVar <int[]>("sortedPlayersIndex")[0] == 1; Assert.AreEqual(2, witness.getVar <int[][]>("initCardsRID").Length); Assert.AreEqual(isFirstPlayer ? 3 : 4, witness.getVar <int[][]>("initCardsRID")[1].Length); Assert.AreEqual(isFirstPlayer ? 3 : 4, witness.getVar <int[]>("initCardsDID").Length); Assert.AreEqual(isFirstPlayer ? 2 : 1, witness.getVar <int[]>("deck").Length); }