public Func <Card, bool> Filter(ActionParameter actionParameter) { UserContext user = actionParameter.GameContext.GetUserContextByMyCard(actionParameter.PrimaryCard); var targets = actionParameter.GameContext.DeskCards.GetDeskServantsByIsFirst(user.IsFirst ? false : true).ToList(); return(new Func <Card, bool>(c => c.CardInGameCode == targets[RandomUtil.CreateRandomInt(0, targets.Count() - 1)].CardInGameCode)); }
public IActionOutputParameter Action(ActionParameter actionParameter) { int dropCount = actionParameter.DropCount; UserContext uc = actionParameter.UserContext; if (actionParameter.DropCardType == PickType.随机 && uc.HandCards.Count() > 0) { List <int> dropList = new List <int>(); for (int i = 0; i < uc.HandCards.Count(); i++) { dropList.Add(i); } if (dropList.Count < dropCount) { dropCount = dropList.Count; } List <int> dropIdx = RandomUtil.CreateRandomInt(0, dropList.Count - 1, dropCount).OrderByDescending(c => c).ToList(); foreach (int idx in dropIdx) { Card card = uc.HandCards.ToList()[idx]; card.CardLocation = CardLocation.坟场; } } return(null); }
/// <summary> /// 开局换牌 /// </summary> /// <param name="userCode"></param> /// <param name="lstInitCardIndex"></param> public void SwitchCard(string userCode, List <int> lstInitCardIndex, IShortCodeService shortCodeService) { UserContext uc = GameContext.Players.First(c => c.Player.UserCode == userCode); if (lstInitCardIndex != null && lstInitCardIndex.Count > 0) { List <int> newIdx = RandomUtil.CreateRandomInt(0, uc.StockCards.Count() - 1, lstInitCardIndex.Count); newIdx = newIdx.OrderByDescending(c => c).ToList(); foreach (int i in newIdx) { uc.StockCards.ToList()[i].CardLocation = CardLocation.手牌; } lstInitCardIndex = lstInitCardIndex.OrderByDescending(c => c).ToList(); foreach (int i in lstInitCardIndex) { uc.InitCards.ToList()[i].CardLocation = CardLocation.牌库; } } else { uc.AllCards.Where(c => c.CardLocation == CardLocation.InitCard).ToList().ForEach(c => c.CardLocation = CardLocation.手牌); } //打乱牌库顺序 int count = uc.AllCards.Count; List <int> newIndex = RandomUtil.CreateRandomInt(0, 100, count); newIndex.Sort(delegate(int a, int b) { return(RandomUtil.CreateRandomInt(-1, 1)); }); for (int i = 0; i < newIndex.Count; i++) { uc.AllCards[i].Sort = newIndex[i]; } uc.SwitchDone = true; //双方都换完牌后的流程 if (GameContext.Players.First(c => c.Player.UserCode != userCode).SwitchDone) { var firstUser = GameContext.Players.First(c => c.IsFirst); //先手玩家换完牌后再抽一张牌 var addCard = firstUser.StockCards.First(); addCard.CardLocation = CardLocation.手牌; var secondUser = GameContext.Players.First(c => c.IsFirst == false); //后手玩家添加一枚幸运币 var luckyCoin = new CreateNewCardInControllerAction <LuckyCoin>().Action(new ActionParameter() { GameContext = GameContext, UserContext = secondUser }) as LuckyCoin; luckyCoin.CardLocation = CardLocation.手牌; secondUser.IsActivation = false; TurnEnd(shortCodeService); } GameContext.Settlement(); }
public Func <Card, bool> Filter(ActionParameter actionParameter) { Q qat = GameActivator <Q> .CreateInstance(); List <Card> lstCardLib = actionParameter.GameContext.GameCache.GetAllCard(); List <Card> servants = lstCardLib.Where(c => c.Cost == qat.Number && c.CardType == CardType.随从 && c.Profession == Profession.Neutral && c.IsDerivative == false).ToList(); BaseServant servant = servants[RandomUtil.CreateRandomInt(0, servants.Count - 1)] as BaseServant; return(new Func <Card, bool>(c => c.CardCode == servant.CardCode)); }
public IEnumerable <Card> Filter(IList <Card> cards, ActionParameter baseActionParameter) { int num = GameActivator <NUM> .CreateInstance().GetNumber(baseActionParameter); num = num > cards.Count ? cards.Count : num; List <int> indexs = RandomUtil.CreateRandomInt(0, cards.Count - 1, num); List <Card> resultCards = new List <Card>(); foreach (int i in indexs) { resultCards.Add(cards[i]); } return(resultCards); }
public Func <Card, bool> Filter(ActionParameter actionParameter) { var targets = actionParameter.GameContext.DeskCards.GetDeskCardsByIsFirst(actionParameter.GameContext.GetUserContextByMyCard(actionParameter.SecondaryCard).IsFirst). Where(c => c != null).ToList(); return(new Func <Card, bool>(c => c != null && c.CardInGameCode == targets[RandomUtil.CreateRandomInt(0, targets.Count - 1)].CardInGameCode)); }
public void GameStart(GameModel game, PlayerModel firstPlayer, PlayerModel secondPlayer, List <UserCardGroupDetailModel> firstCardGroup, List <UserCardGroupDetailModel> secondCardGroup, string firstUserProfession, string secondUserProfession) { #region 加载玩家卡组 UserContext firstUser = new UserContext { UserCode = firstPlayer.UserCode, Player = firstPlayer, IsActivation = true, IsFirst = true, AllCards = new List <Card>() }; List <Card> lstCardLib = _gameCache.GetAllCard(); int cardInGameIndex = 0; foreach (var cg in firstCardGroup) { Card libCard = lstCardLib.First(c => c.CardCode == cg.CardCode); var card = Activator.CreateInstance(libCard.GetType()) as Card; card.CardInGameCode = cardInGameIndex.ToString(); card.IsFirstPlayerCard = true; firstUser.AllCards.Add(card); cardInGameIndex++; } UserContext secondUser = new UserContext { UserCode = secondPlayer.UserCode, Player = secondPlayer, IsActivation = true, IsFirst = false, AllCards = new List <Card>() }; secondCardGroup.ForEach(delegate(UserCardGroupDetailModel detail) { Card libCard = lstCardLib.First(c => c.CardCode == detail.CardCode); var card = Activator.CreateInstance(libCard.GetType()) as Card; card.CardInGameCode = cardInGameIndex.ToString(); card.IsFirstPlayerCard = false; secondUser.AllCards.Add(card); cardInGameIndex++; }); //secondUser.StockCards = secondUser.AllCards; GameContext = new GameContext { Players = new List <UserContext>(), DeskCards = null, GameCode = game.GameCode, CurrentTurnCode = game.CurrentTurnCode, NextTurnCode = game.NextTurnCode, GameStatus = GameStatus.进行中, GameCache = _gameCache }; GameContext.Players.Add(firstUser); GameContext.Players.Add(secondUser); #endregion #region 初始化开场选牌 int firstPickUpCount = 4; List <int> lstRndIndex = RandomUtil.CreateRandomInt(0, GameContext.Players.First(c => c.IsFirst).AllCards.Count - 1, firstPickUpCount); for (int i = 0; i < lstRndIndex.Count; i++) { if (i < lstRndIndex.Count - 1) { //lstFirstPickUpCard.Add(GameContext.Players.First(c => c.IsFirst).AllCards[lstRndIndex[i]]); GameContext.Players.First(c => c.IsFirst).AllCards[lstRndIndex[i]].CardLocation = CardLocation.InitCard; } //lstSecondPickUpCard.Add(GameContext.Players.First(c => c.IsFirst == false).AllCards[lstRndIndex[i]]); GameContext.Players.First(c => c.IsFirst == false).AllCards[lstRndIndex[i]].CardLocation = CardLocation.InitCard; } BaseHero firstHero = null, secondHero = null; switch (firstUserProfession) { case "Druid": firstHero = new Druid(); break; case "Hunter": firstHero = new Hunter(); break; case "Mage": firstHero = new Mage(); break; case "Paladin": firstHero = new Paladin(); break; case "Priest": firstHero = new Priest(); break; case "Rogue": firstHero = new Rogue(); break; case "Shaman": firstHero = new Shaman(); break; case "Warlock": firstHero = new Warlock(); break; case "Warrior": firstHero = new Warrior(); break; } switch (secondUserProfession) { case "Druid": secondHero = new Druid(); break; case "Hunter": secondHero = new Hunter(); break; case "Mage": secondHero = new Mage(); break; case "Paladin": secondHero = new Paladin(); break; case "Priest": secondHero = new Priest(); break; case "Rogue": secondHero = new Rogue(); break; case "Shaman": secondHero = new Shaman(); break; case "Warlock": secondHero = new Warlock(); break; case "Warrior": secondHero = new Warrior(); break; } cardInGameIndex++; firstHero.CardLocation = CardLocation.场上; firstHero.CardInGameCode = cardInGameIndex.ToString(); firstHero.DeskIndex = 0; firstHero.IsFirstPlayerCard = true; firstUser.AllCards.Add(firstHero); cardInGameIndex++; secondHero.CardLocation = CardLocation.场上; secondHero.CardInGameCode = cardInGameIndex.ToString(); secondHero.DeskIndex = 8; secondHero.IsFirstPlayerCard = false; secondUser.AllCards.Add(secondHero); GameContext.DeskCards = new DeskBoard() { firstHero, null, null, null, null, null, null, null, secondHero, null, null, null, null, null, null, null }; #endregion GameContext.Settlement(); _gameCache.SetContext(GameContext); }
public Func <Card, bool> Filter(ActionParameter actionParameter) { var targets = actionParameter.GameContext.DeskCards.GetAllBiology().ToList(); return(new Func <Card, bool>(c => c.CardInGameCode == targets[RandomUtil.CreateRandomInt(0, targets.Count() - 1)].CardInGameCode)); }
public int GetNumber(Parameter.ActionParameter actionParameter) { return(RandomUtil.CreateRandomInt(GameActivator <Min> .CreateInstance().GetNumber(actionParameter), GameActivator <Max> .CreateInstance().GetNumber(actionParameter))); }