public static UseResponse UseCode(string code) { UseResponse useResp = new UseResponse(); if (string.IsNullOrWhiteSpace(code)) { useResp.Notification = "Missing CardCode"; useResp.UseCodeStatus = Protocol.UseCodeEnum.Error; return(useResp); } using (var context = new EPSContext()) { CardCode cardCode = GetCardCode(context, code); if (cardCode != null && string.IsNullOrWhiteSpace(cardCode.Used)) { cardCode.Used = DateTime.Now.ToString(); context.SaveChanges(); useResp.UseCodeStatus = Protocol.UseCodeEnum.Used; } else if (!string.IsNullOrWhiteSpace(cardCode.Used)) { useResp.Notification = $"Card code:{code.ToUpper()} alredy used"; useResp.UseCodeStatus = Protocol.UseCodeEnum.AlreadyUsed; } else { useResp.Notification = $"No such code:{code.ToUpper()}"; useResp.UseCodeStatus = Protocol.UseCodeEnum.NoCode; } return(useResp); } }
public IEnumerator calcActionsTest_Turn1() { THHGame game = TestGameflow.initGameWithoutPlayers(null, GameOption.Default); THHPlayer player = game.createPlayer(1, "玩家1", game.getCardDefine <TestMaster>(), Enumerable.Repeat(game.getCardDefine <TestServant>(), 30)); game.createPlayer(2, "玩家2", game.getCardDefine <TestMaster>(), Enumerable.Repeat(game.getCardDefine <TestServant>(), 30)); game.logger.log("Force Init"); AI ai = new AI(game, player, false); _ = game.run(); yield return(new WaitForSeconds(.1f)); game.players[0].cmdInitReplace(game); game.players[1].cmdInitReplace(game); yield return(new WaitForSeconds(.1f)); if (game.sortedPlayers[0] != player) { game.sortedPlayers[0].cmdTurnEnd(game); yield return(new WaitForSeconds(.1f)); } var actions = ai.calcActions(game, player); Assert.AreEqual(player.hand.count, actions.Count); UseResponse use = actions.Keys.First() as UseResponse; Assert.NotNull(use); }
public static bool ThrewException <E>(this UseResponse response, out E e, bool doNotClear) where E : Exception { if ((((int)response) >= -16) && (((int)response) <= -10)) { return(Useable.GetLastException <E>(out e, doNotClear)); } e = null; return(false); }
public static bool ThrewException(this UseResponse response, out Exception e, bool doNotClear) { if ((int)response >= -16 && (int)response <= -10) { return(Useable.GetLastException(out e, doNotClear)); } e = null; return(false); }
public static bool Succeeded(this UseResponse response) { bool flag = ((int)response) >= 0; if (!flag) { LogWarning <string>("Did not succeed " + response); } return(flag); }
public static bool Succeeded(this UseResponse response) { bool flag = (int)response >= 0; if (!flag) { UseableUtility.LogWarning <string>(string.Concat("Did not succeed ", response)); } return(flag); }
public void TestItemsUseXmlGetAttributes() { string xml = @"<roar tick=""135571857913""> <items> <use status=""ok""/> </items> <server> <item_use item_id=""232839631""/> </server> </roar>" ; System.Xml.XmlElement nn = RoarExtensions.CreateXmlElement(xml); Roar.DataConversion.Responses.Items.Use use_parser = new Roar.DataConversion.Responses.Items.Use(); UseResponse response = use_parser.Build(nn); Assert.IsNotNull(response); }
public static bool ThrewException(this UseResponse response, out Exception e) { return(response.ThrewException(out e, false)); }
public static bool Checked(this UseResponse response) { return((((int)response) < -16) || (((int)response) > 0)); }
public static bool Checked(this UseResponse response) { return((int)response < -16 ? true : (int)response > 0); }
/// <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>(); UseResponse use; if (player.skill.isUsable(game, player, out _)) { if (player.skill.isNeedTarget(game, out var targets)) { foreach (var target in targets) { use = new UseResponse() { cardId = player.skill.id, targetsId = new int[] { target.id } }; responseDic.Add(use, calcActionValue(use, game, player, game.getOpponent(player))); } } else { use = new UseResponse() { cardId = player.skill.id }; responseDic.Add(use, calcActionValue(use, game, player, game.getOpponent(player))); } } 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(game) + card.getLife(game)); } } else { responseDic.Add(new UseResponse() { cardId = card.id, position = i }, card.getAttack(game) + card.getLife(game)); } } } else { if (card.isNeedTarget(game, out var targets)) { foreach (var target in targets) { use = new UseResponse() { cardId = card.id, targetsId = new int[] { target.id } }; responseDic.Add(use, calcActionValue(use, game, player, game.getOpponent(player))); } } else { use = new UseResponse() { cardId = card.id }; responseDic.Add(use, calcActionValue(use, game, player, game.getOpponent(player))); } } } if (player.master.canAttack(game)) { THHPlayer opponent = game.getOpponent(player); if (player.master.isAttackable(game, player, opponent.master, out _)) { int value = player.master.getAttack(game) > opponent.master.getCurrentLife(game) ? opponent.master.getLife(game) : player.master.getAttack(game); 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(game) > target.getCurrentLife(game) ? target.getAttack(game) + target.getCurrentLife(game) : player.master.getAttack(game); value += player.master.getCurrentLife(game) > target.getAttack(game) ? -target.getAttack(game) : -player.master.getLife(game); responseDic.Add(new AttackResponse() { cardId = player.master.id, targetId = target.id }, value); } } foreach (var servant in player.field) { if (!servant.canAttack(game)) { continue; } THHPlayer opponent = game.getOpponent(player); if (servant.isAttackable(game, player, opponent.master, out _)) { int value = servant.getAttack(game) > opponent.master.getCurrentLife(game) ? opponent.master.getLife(game) : servant.getAttack(game); 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(game) > target.getCurrentLife(game) ? target.getAttack(game) + target.getCurrentLife(game) : servant.getAttack(game); value += servant.getCurrentLife(game) > target.getAttack(game) ? -target.getAttack(game) : -servant.getLife(game); responseDic.Add(new AttackResponse() { cardId = servant.id, targetId = target.id }, value); } } return(responseDic); }