static async Task effect(THHGame game, Card card) { THHPlayer opponent = game.getOpponent(card.getOwner()); for (int i = 0; i < opponent.field.count; i++) { await card.getOwner().createToken(game, game.getCardDefine <DustElement>()); } await Patchouli.tryMix(game, card); }
static async Task effect(THHGame game, Card card) { THHPlayer opponent = game.getOpponent(card.getOwner()); if (opponent.field.count > 0) { return; } await opponent.field.randomTake(game, 1).damage(game, card, 2); await Patchouli.tryMix(game, card); }
static async Task effect(THHGame game, Card card) { THHPlayer player = card.getOwner(); THHPlayer opponent = game.getOpponent(player); await opponent.field.damage(game, card, player.getSpellDamage(game, 2)); foreach (Card target in opponent.field) { if (target.isDead(game)) { if (player.field.count > 0) { await player.field.random(game).addBuff(game, new GeneratedBuff(ID, new AttackModifier(1), new LifeModifier(1))); } } } await Patchouli.tryMix(game, card); }
/// <summary> /// 计算出可以选择的行动,不包括结束回合。 /// </summary> /// <param name="game"></param> /// <param name="player"></param> /// <returns></returns> public Dictionary <Response, float> calcActions(THHGame game, THHPlayer player) { Dictionary <Response, float> responseDic = new Dictionary <Response, float>(); foreach (var card in player.hand) { if (!card.isUsable(game, player, out _)) { continue; } if (card.define is ServantCardDefine) { for (int i = 0; i < player.field.count + 1; i++) { TouhouCardEngine.Card[] targets = card.getAvaliableTargets(game); if (targets != null) { foreach (var target in targets) { responseDic.Add(new UseResponse() { cardId = card.id, position = i, targetsId = new int[] { target.id } }, card.getAttack() + card.getLife()); } } else { responseDic.Add(new UseResponse() { cardId = card.id, position = i }, card.getAttack() + card.getLife()); } } } else { TouhouCardEngine.Card[] targets = card.getAvaliableTargets(game); if (targets != null && targets.Length > 0) { foreach (var target in targets) { responseDic.Add(new UseResponse() { cardId = card.id, targetsId = new int[] { target.id } }, card.getCost()); } } else { responseDic.Add(new UseResponse() { cardId = card.id }, card.getCost()); } } } if (player.master.canAttack(game, player)) { THHPlayer opponent = game.getOpponent(player); if (player.master.isAttackable(game, player, opponent.master, out _)) { int value = player.master.getAttack() > opponent.master.getCurrentLife() ? opponent.master.getLife() : player.master.getAttack(); responseDic.Add(new AttackResponse() { cardId = player.master.id, targetId = opponent.master.id }, value); } foreach (var target in opponent.field) { if (!player.master.isAttackable(game, player, target, out _)) { continue; } int value = player.master.getAttack() > target.getCurrentLife() ? target.getAttack() + target.getCurrentLife() : player.master.getAttack(); value += player.master.getCurrentLife() > target.getAttack() ? -target.getAttack() : -player.master.getLife(); responseDic.Add(new AttackResponse() { cardId = player.master.id, targetId = target.id }, value); } } foreach (var servant in player.field) { if (!servant.canAttack(game, player)) { continue; } THHPlayer opponent = game.getOpponent(player); if (servant.isAttackable(game, player, opponent.master, out _)) { int value = servant.getAttack() > opponent.master.getCurrentLife() ? opponent.master.getLife() : servant.getAttack(); responseDic.Add(new AttackResponse() { cardId = servant.id, targetId = opponent.master.id }, value); } foreach (var target in opponent.field) { if (!servant.isAttackable(game, player, target, out _)) { continue; } int value = servant.getAttack() > target.getCurrentLife() ? target.getAttack() + target.getCurrentLife() : servant.getAttack(); value += servant.getCurrentLife() > target.getAttack() ? -target.getAttack() : -servant.getLife(); responseDic.Add(new AttackResponse() { cardId = servant.id, targetId = target.id }, value); } } return(responseDic); }
public IEnumerator remotePVPSimulTest() { UnityLogger logger = new UnityLogger(); HostManager host = new GameObject(nameof(HostManager)).AddComponent <HostManager>(); host.logger = logger; ClientManager local = new GameObject(nameof(ClientManager)).AddComponent <ClientManager>(); local.logger = logger; //开房,打开Host,自己加入自己,房间应该有Option RoomInfo roomInfo = new RoomInfo(); roomInfo.setOption(new GameOption()); THHGame localGame = null; local.onConnected += () => { //发送玩家信息 RoomPlayerInfo playerInfo = new RoomPlayerInfo() { id = local.id, name = "玩家" + local.id, }; playerInfo.setDeck(new int[] { Reimu.ID }.Concat(Enumerable.Repeat(DrizzleFairy.ID, 30)).ToArray()); return(local.send(playerInfo)); }; local.onReceive += (id, obj) => { if (obj is RoomPlayerInfo newPlayerInfo) { //收到玩家信息 RoomInfo newRoomInfo = new RoomInfo() { playerList = new List <RoomPlayerInfo>(roomInfo.playerList) }; newRoomInfo.setOption(roomInfo.getOption()); newRoomInfo.playerList.Add(newPlayerInfo); //发送房间信息 return(local.send(newRoomInfo)); } else if (obj is RoomInfo newRoomInfo) { roomInfo = newRoomInfo; //收到房间信息 if (newRoomInfo.playerList.Count > 1) { localGame = TestGameflow.initGameWithoutPlayers("本地游戏", newRoomInfo.getOption()); (localGame.answers as AnswerManager).client = local; foreach (var playerInfo in newRoomInfo.playerList) { localGame.createPlayer(playerInfo.id, "玩家" + playerInfo.id, localGame.getCardDefine <MasterCardDefine>(playerInfo.getDeck()[0]), playerInfo.getDeck().Skip(1).Select(did => localGame.getCardDefine(did))); } localGame.run(); } } return(Task.CompletedTask); }; host.start(); local.start(); yield return(local.join(host.ip, host.port).wait()); Assert.AreEqual(1, roomInfo.playerList.Count); ClientManager remote = new GameObject(nameof(ClientManager)).AddComponent <ClientManager>(); remote.logger = logger; THHGame remoteGame = null; remote.onConnected += () => { //发送玩家信息 RoomPlayerInfo playerInfo = new RoomPlayerInfo() { id = remote.id, name = "玩家" + remote.id }; playerInfo.setDeck(new int[] { Reimu.ID }.Concat(Enumerable.Repeat(DrizzleFairy.ID, 30)).ToArray()); return(remote.send(playerInfo)); }; remote.onReceive += (id, obj) => { if (obj is RoomInfo newRoomInfo) { //收到房间信息 if (newRoomInfo.playerList.Count > 1) { remoteGame = TestGameflow.initGameWithoutPlayers("远端游戏", newRoomInfo.getOption()); (remoteGame.answers as AnswerManager).client = remote; foreach (var playerInfo in newRoomInfo.playerList) { remoteGame.createPlayer(playerInfo.id, "玩家" + playerInfo.id, remoteGame.getCardDefine <MasterCardDefine>(playerInfo.getDeck()[0]), playerInfo.getDeck().Skip(1).Select(did => remoteGame.getCardDefine(did))); } remoteGame.run(); } } return(Task.CompletedTask); }; //加入房间 remote.start(); yield return(remote.join(host.ip, host.port).wait()); //连接了,远程玩家把玩家信息发给本地,本地更新房间信息发给远端和开始游戏。 yield return(new WaitUntil(() => localGame != null && remoteGame != null)); Assert.True(localGame.isRunning); Assert.AreEqual(local.id, localGame.players[0].id); Assert.AreEqual(remote.id, localGame.players[1].id); Assert.True(remoteGame.isRunning); Assert.AreEqual(local.id, remoteGame.players[0].id); Assert.AreEqual(remote.id, remoteGame.players[1].id); THHPlayer localPlayer = localGame.getPlayer(local.id); Assert.AreEqual(0, localPlayer.id); yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is InitReplaceRequest)); Assert.Greater(localPlayer.init.count, 0); localPlayer.cmdInitReplace(localGame); yield return(new WaitUntil(() => localGame.answers.getResponse(localPlayer.id, localGame.answers.getRequests(localPlayer.id).FirstOrDefault()) is InitReplaceResponse)); THHPlayer remotePlayer = remoteGame.getPlayer(remote.id); Assert.AreEqual(1, remotePlayer.id); yield return(new WaitUntil(() => remoteGame.answers.getRequests(remotePlayer.id).FirstOrDefault() is InitReplaceRequest)); Assert.Greater(remotePlayer.init.count, 0); remotePlayer.cmdInitReplace(remoteGame); yield return(new WaitUntil(() => remoteGame.triggers.getRecordedEvents().Any(e => e is THHGame.StartEventArg))); //拍怪 if (localGame.sortedPlayers[0] == localPlayer) { yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is FreeActRequest)); localPlayer.cmdUse(localGame, localPlayer.hand[0], 0); yield return(new WaitUntil(() => localPlayer.field.count > 0)); localPlayer.cmdTurnEnd(localGame); yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer)); } yield return(new WaitUntil(() => remoteGame.answers.getRequests(remotePlayer.id).FirstOrDefault() is FreeActRequest)); remotePlayer.cmdUse(remoteGame, remotePlayer.hand[0], 0); yield return(new WaitUntil(() => remotePlayer.field.count > 0)); remotePlayer.cmdTurnEnd(remoteGame); yield return(new WaitUntil(() => remoteGame.currentPlayer != remotePlayer)); if (localGame.sortedPlayers[0] != localPlayer) { yield return(new WaitUntil(() => localGame.answers.getRequests(localPlayer.id).FirstOrDefault() is FreeActRequest)); localPlayer.cmdUse(localGame, localPlayer.hand[0], 0); yield return(new WaitUntil(() => localPlayer.field.count > 0)); localPlayer.cmdTurnEnd(localGame); yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer)); } do { yield return(new WaitUntil(() => localGame.currentPlayer == localPlayer || remoteGame.currentPlayer == remotePlayer)); if (localGame.currentPlayer == localPlayer) { localPlayer.cmdAttack(localGame, localPlayer.field[0], localGame.getOpponent(localPlayer).master); yield return(new WaitUntil(() => localPlayer.field[0].getAttackTimes(localGame) > 0)); localPlayer.cmdTurnEnd(localGame); yield return(new WaitUntil(() => localGame.currentPlayer != localPlayer)); } else if (remoteGame.currentPlayer == remotePlayer) { remotePlayer.cmdAttack(remoteGame, remotePlayer.field[0], remoteGame.getOpponent(remotePlayer).master); yield return(new WaitUntil(() => remotePlayer.field[0].getAttackTimes(remoteGame) > 0)); remotePlayer.cmdTurnEnd(remoteGame); yield return(new WaitUntil(() => remoteGame.currentPlayer != remotePlayer)); } }while (localGame.isRunning && remoteGame.isRunning); local.disconnect(); remote.disconnect(); yield break; }
static async Task effect(THHGame game, Card card) { await game.getOpponent(card.getOwner()).field.random(game).damage(game, card, 2); await Patchouli.tryMix(game, card); }
static async Task effect(THHGame game, Card card) { await game.getOpponent(card.getOwner()).field.silence(game); await game.getOpponent(card.getOwner()).field.die(game); }
static async Task effect(THHGame game, Card card) { await game.getOpponent(card.owner as THHPlayer).master.damage(game, card, 15); }
static async Task effect(THHGame game, Card card) { await game.getOpponent(card.getOwner()).field.damage(game, card, card.getOwner().getSpellDamage(game, 3)); await Patchouli.tryMix(game, card); }
static async Task effect(THHGame game, Card card) { await card.getOwner().createToken(game, game.getOpponent(card.getOwner()).field.count, game.getCardDefine <DustElement>()); await Patchouli.tryMix(game, card); }