public void RemovePlayerFromSessionAndReturnUpdatedPlayers_Should_RemovePlayerFromPlayerCard() { //Arrange var removePlayer = "david"; var removedPlayerCardDto = new PlayerCardDto { UserName = removePlayer }; var _sessionKey = EnumHelper.ScoreCardViewModelSessionKey.ScoreCardViewModel.ToString(); var sessionModel = new ScoreCardDto { PlayerCards = new List <PlayerCardDto> { new PlayerCardDto { UserName = removePlayer }, } }; _sessionStorageMock.Setup(x => x.Get(_sessionKey)).Returns(sessionModel); _sessionStorageMock.Setup(x => x.Save(_sessionKey, sessionModel)); //Act var result = _sut.RemovePlayerFromSessionAndReturnUpdatedPlayers(removePlayer); //Assert Assert.DoesNotContain(removedPlayerCardDto, result); }
public async Task <bool> UpdateTeamDetail(PlayerCardDto teamDetail) { TeamDetail td = _content.TeamDetails.FirstOrDefault(x => x.UserId == teamDetail.userId && x.Position == teamDetail.CardPosition); td.PlayerId = teamDetail.PlayerId; _content.TeamDetails.Update(td); return(await _content.SaveChangesAsync() > 0); }
/// <summary> /// 保存一下卡牌数据 /// </summary> ///1 21dian 2爆牌 3不要 /// <param name="state"></param> /// <param name="isDouble"></param> public void SaveList(int state, bool isDouble) { PlayerCardDto playerCardDto = new PlayerCardDto(); playerCardDto.CardList.AddRange(player.CardList); playerCardDto.CardState = state; playerCardDto.Weight = CardWeight21.GetWeight(player.CardList); playerCardDto.isDouble = isDouble; player.SpliteCardListList.Add(playerCardDto); }
/// <summary> /// 保存一下卡牌数据 /// </summary> /// <param name="userId"></param> /// <param name="state"></param> /// <param name="isDouble"></param> public void SaveListByUserId(int userId, int state, bool isDouble) { int position = getPosition(userId); PlayerCardDto playerCardDto = new PlayerCardDto(); playerCardDto.CardList.AddRange(PlayerList[position - 1].CardList); playerCardDto.CardState = state; playerCardDto.Weight = MultiCardWeight21.GetWeight(PlayerList[position - 1].CardList); playerCardDto.isDouble = isDouble; PlayerList[position - 1].CardListList.Add(playerCardDto); }
public async Task <IActionResult> UpdateTeamDetailRecord(PlayerCardDto playerDto) { // _logger.LogInformation("Demo Logging Information in Index Method"); // Need to get the correct Id for the current cardPosition for the User var existingTeamDetailForPosition = _repo.GetTeamDetailForPosition(playerDto.userId, playerDto.CardPosition); // _logger.LogInformation("existing teamDetail for position is now being set"); if (existingTeamDetailForPosition != null) { // This needs to be updated var teamDetailToUpdate = new TeamDetail { Active = 1, Captain = playerDto.isCaptain, Emergency = playerDto.isEmergency, Id = existingTeamDetailForPosition.Id, PlayerId = playerDto.PlayerId, Position = playerDto.CardPosition, SixthMan = playerDto.isSixthMan, UserId = playerDto.userId }; // Now need to call the update method of the TeamDetail // _logger.LogInformation("About to call to the Update Team Detail Repo"); var updateSalary = await _repo.UpdateTeamDetail(teamDetailToUpdate); // _logger.LogInformation("Returned from the Update Team Detail repo - with status of: " + updateSalary); return(StatusCode(201)); } else { // This is a new Team Detail record - realistically it should never get here var teamDetailToCreate = new TeamDetail { Captain = playerDto.isCaptain, Emergency = playerDto.isEmergency, SixthMan = playerDto.isSixthMan, Active = 1, PlayerId = playerDto.PlayerId, Position = playerDto.CardPosition, UserId = playerDto.userId }; var createdTeamDetail = await _repo.CreateTeamDetailRecord(teamDetailToCreate); return(StatusCode(201)); } }
public async Task <IActionResult> UpdateSubTeamDetailRecord(PlayerCardDto playerDtos) { var teamDetail = await _repo.UpdateTeamDetail(playerDtos); return(StatusCode(201)); }
private void gameOver(_21MutiFightRoom room) { //给庄家发牌 brocast(room, OpCode._21Multi, _21MultiCode.TURN_DEALER_BRO, null, null); //把所有的state遍历一遍,都爆牌了就不用要了 while (room.GetDealerWeight() < 17) { CardDto card = room.DealerHit(); brocast(room, OpCode._21Multi, _21MultiCode.DEALER_HIT_BRO, card, null); } //结算 //结算对象 GameOverDto gameOverDto = new GameOverDto(); //todo 写一个总结算的对象,把玩家信息和这轮游戏的信息都发过去 状态 1 2 3 4 5 //庄家的权值 int dealerWeight = room.GetDealerWeight(); gameOverDto.dealerWeight = dealerWeight; for (int i = 0; i < 4; i++) { //不为空 if (room.PlayerList[i] != null) { List <int> StateList = new List <int>(); List <int> WeightList = new List <int>(); List <int> WinBeenList = new List <int>(); UserModel um = userCache.GetModelById(room.PlayerList[i].UserId); //ClientPeer client = userCache.GetClientPeer(room.PlayerList[i].UserId); int wager = room.PlayerList[i].Wager; //一名掉线玩家 if (room.LeaveUIdList.Contains(room.PlayerList[i].UserId)) { //扣双倍豆 um.Been -= wager * 2; gameOverDto.isLeaveList[i] = true; WinBeenList.Add(-wager * 2); gameOverDto.playerWinBeenListList[i] = WinBeenList; } //正常玩家 else { //每一把牌经验豆子结算 for (int j = 0; j < room.PlayerList[i].CardListList.Count; j++) { int multi = 1; PlayerCardDto tempPlayerCardDto = room.PlayerList[i].CardListList[j]; int tempWeight = tempPlayerCardDto.Weight; WeightList.Add(tempWeight); int tempState = tempPlayerCardDto.CardState; bool tempIsDouble = tempPlayerCardDto.isDouble; if (tempIsDouble) { multi = 2; } //21点 if (tempState == 1) { um.Been += (int)(wager * 1.5); WinBeenList.Add((int)(wager * 1.5)); StateList.Add(1); um.Exp += 150; } //闲家爆牌 else if (tempState == 2) { um.Been -= wager * multi; WinBeenList.Add(-wager * multi); if (multi == 1) { StateList.Add(2); } else { StateList.Add(3); } um.Exp += 50; } //不要 权值小于 else if (tempState == 3) { //庄家爆牌 if (dealerWeight > 21) { um.Been += wager * multi; WinBeenList.Add(wager * multi); if (multi == 1) { StateList.Add(6); } else { StateList.Add(4); } um.Exp += 100; } //闲家点大 else if (dealerWeight < tempWeight) { um.Been += wager * multi; WinBeenList.Add(wager * multi); if (multi == 1) { StateList.Add(6); } else { StateList.Add(4); } um.Exp += 100; } //庄家点大 else if (dealerWeight > tempWeight) { um.Been -= wager * multi; WinBeenList.Add(-wager * multi); if (multi == 1) { StateList.Add(7); } else { StateList.Add(5); } um.Exp += 50; } //平局 else { WinBeenList.Add(0); StateList.Add(8); um.Exp += 75; } } } } gameOverDto.playerWeightListList[i] = WeightList; gameOverDto.playerStateListList[i] = StateList; gameOverDto.playerWinBeenListList[i] = WinBeenList; int maxExp = um.Lv * 100; while (maxExp <= um.Exp) { um.Lv++; um.Exp -= maxExp; maxExp = um.Lv * 100; } userCache.Update(um); UserDto dto = new UserDto(um.Id, um.Name, um.Been, um.WinCount, um.LoseCount, um.RunCount, um.Lv, um.Exp); gameOverDto.userDtoList[i] = dto; } } //掉线的 不用发了,改一下这个函数 主要用在overpanel brocast(room, OpCode._21Multi, _21MultiCode.OVER_BRO, gameOverDto, null); //房间设置为等待 fightCache.SetRoomWait(room); //删除离开列表里的用户 foreach (int uid in room.LeaveUIdList) { fightCache.Leave(uid); } //重置房间 room.resetRoom(); }
public void gameOver(int userId, SingleRoom room, int whichwin) { UserModel um = userCache.GetModelById(userId); ClientPeer client = userCache.GetClientPeer(userId); int wager = room.Wager; SingleOverDto odto = new SingleOverDto(); switch (whichwin) { case 1: { int dealerWeight = room.GetDealerWeight(); odto.dealerWeight = dealerWeight; //21点,和庄家比 获胜或平局 if (dealerWeight != 21) //获胜 { um.Been += (int)(1.5 * wager); um.Exp += 150; odto.dealerState = 3; odto.playerStateList.Add(1); odto.playerWeightList.Add(room.GetPlayerWeight()); odto.playerWinBeenList.Add((int)(1.5 * wager)); } else { um.Exp += 75; odto.dealerState = 1; odto.playerStateList.Add(0); odto.playerWeightList.Add(room.GetPlayerWeight()); odto.playerWinBeenList.Add((int)(0)); } break; } case 2: //闲家爆牌 case 4: //庄家获胜 { int dealerWeight = room.GetDealerWeight(); odto.dealerWeight = dealerWeight; odto.dealerState = 3; um.Been -= wager * room.Multiple; um.Exp += 50; odto.playerWeightList.Add(room.GetPlayerWeight()); odto.playerWinBeenList.Add(-(wager * room.Multiple)); if (room.Multiple == 2) { if (room.GetPlayerWeight() > 21) //加倍爆牌 { odto.playerStateList.Add(3); } else { odto.playerStateList.Add(5); //加倍输 } } else { if (room.GetPlayerWeight() > 21) //加倍爆牌 { odto.playerStateList.Add(2); } else { odto.playerStateList.Add(7); //加倍输 } } break; } case 3: //庄家爆牌,闲家获胜 case 5: { int dealerWeight = room.GetDealerWeight(); odto.dealerWeight = dealerWeight; if (room.GetDealerWeight() > 21) //爆牌 { odto.dealerState = 2; } else { odto.dealerState = 3; } um.Been += wager * room.Multiple; odto.playerWinBeenList.Add(wager * room.Multiple); odto.playerWeightList.Add(room.GetPlayerWeight()); if (room.Multiple == 2) //加倍赢 { odto.playerStateList.Add(4); } else { odto.playerStateList.Add(6); //赢 } um.Exp += 100; break; } case 6: { int dealerWeight = room.GetDealerWeight(); odto.dealerWeight = dealerWeight; odto.dealerState = 3; odto.playerWinBeenList.Add(0); odto.playerWeightList.Add(room.GetPlayerWeight()); odto.playerStateList.Add(8); //平 um.Exp += 75; break; } case 7: { //看看是不是全爆牌了 bool isallboom = room.isAllBoom(); //这个是让客户端翻面 client.Send(OpCode._21Single, _21SingleCode.NGET_SRES, null); if (!isallboom) { while (room.GetDealerWeight() < 17) { CardDto carddto = room.GetOneDealerCard(); client.Send(OpCode._21Single, _21SingleCode.ADD_DCARD_SRES, carddto); } } int dealerWeight = room.GetDealerWeight(); odto.dealerWeight = dealerWeight; if (room.DealerCardList.Count == 2 && room.GetDealerWeight() == 21) //庄家是21点 { odto.dealerState = 1; } else if (room.GetDealerWeight() > 21) { odto.dealerState = 2; } else { odto.dealerState = 3; } for (int j = 0; j < room.player.SpliteCardListList.Count; j++) { int multi = 1; PlayerCardDto tempPlayerCardDto = room.player.SpliteCardListList[j]; int tempWeight = tempPlayerCardDto.Weight; odto.playerWeightList.Add(tempWeight); int tempState = tempPlayerCardDto.CardState; bool tempIsDouble = tempPlayerCardDto.isDouble; if (tempIsDouble) { multi = 2; } //21点 if (tempState == 1) { if (dealerWeight == 1) //平局 { odto.playerWinBeenList.Add(0); odto.playerStateList.Add(0); um.Exp += 75; } else { um.Been += (int)(wager * 1.5); odto.playerWinBeenList.Add((int)(wager * 1.5)); odto.playerStateList.Add(1); um.Exp += 150; } } //闲家爆牌 else if (tempState == 2) { um.Been -= wager * multi; odto.playerWinBeenList.Add(-wager * multi); if (multi == 1) { odto.playerStateList.Add(2); } else { odto.playerStateList.Add(3); } um.Exp += 50; } //不要 权值小于 else if (tempState == 3) { //庄家爆牌 if (dealerWeight > 21) { um.Been += wager * multi; odto.playerWinBeenList.Add(wager * multi); if (multi == 1) { odto.playerStateList.Add(6); } else { odto.playerStateList.Add(4); } um.Exp += 100; } //闲家点大 else if (dealerWeight < tempWeight) { um.Been += wager * multi; odto.playerWinBeenList.Add(wager * multi); if (multi == 1) { odto.playerStateList.Add(6); } else { odto.playerStateList.Add(4); } um.Exp += 100; } //庄家点大 else if (dealerWeight > tempWeight) { um.Been -= wager * multi; odto.playerWinBeenList.Add(-wager * multi); if (multi == 1) { odto.playerStateList.Add(7); } else { odto.playerStateList.Add(5); } um.Exp += 50; } //平局 else { odto.playerWinBeenList.Add(0); odto.playerStateList.Add(8); um.Exp += 75; } } } //double sum = room.computeWinOrLoss(); //um.Been += (int)(sum * wager); //um.Exp += 50 * room.player.SplitNum; //清理工作 room.player.SplitNum = 1; room.splitClear(); break; } default: break; } int maxExp = um.Lv * 100; while (maxExp <= um.Exp) { um.Lv++; um.Exp -= maxExp; maxExp = um.Lv * 100; } userCache.Update(um); UserDto dto = new UserDto(um.Id, um.Name, um.Been, um.WinCount, um.LoseCount, um.RunCount, um.Lv, um.Exp); //SingleOverDto odto = new SingleOverDto(dto, whichwin); odto.userDto = dto; client.Send(OpCode._21Single, _21SingleCode.OVER_SRES, odto); room.player.CardList.Clear(); room.DealerCardList.Clear(); Thread.Sleep(100); CountStrategyDto countStrategyDto = room.libraryModel.GetCountStrategyDto(); client.Send(OpCode._21Single, _21SingleCode.COUNT_STRATEGY_SRES, countStrategyDto); }
public async Task <IEnumerable <PlayerCardDto> > GetPlayerCardsForUser(int userId) { var teamDetails = await _content.TeamDetails.Where(x => x.UserId == userId).ToListAsync(); List <PlayerCardDto> playerCardsList = new List <PlayerCardDto>(); // Now is where I need to update things // Need to go through and set each player card for (var pos = 1; pos <= 13; pos++) { // Position 1 var matched = 0; for (var i = 0; i < teamDetails.Count; i++) { TeamDetail detail = teamDetails[i]; if (detail.Position == pos) { // Need to get the player object Player player = await _content.Players.FirstOrDefaultAsync(p => p.PlayerId == detail.PlayerId); // Get the last score for the player PlayerScores ps = _content.PlayerScores.OrderByDescending(x => x.GameDate).FirstOrDefault(p => p.PlayerId == detail.PlayerId); int averageScore = 0; int lastScore = 0; if (ps == null) { lastScore = 0; } else { averageScore = this.GetAverageScoreForPlayer(player.PlayerId); lastScore = ps.Score; } PlayerCardDto pgDto = new PlayerCardDto(); pgDto.PlayerId = detail.PlayerId; pgDto.averageScore = averageScore; pgDto.CardPosition = pos; pgDto.CardPositionText = GetPositionText(pos); pgDto.FirstName = player.FirstName; pgDto.lastScore = lastScore; pgDto.PlayerPosition = player.PositionOne; pgDto.PlayerPositionTwo = player.PositionTwo; pgDto.PlayerPositionThree = player.PositionThree; pgDto.Price = player.Price; pgDto.Surname = player.Surname; pgDto.Team = player.Team; pgDto.isCaptain = detail.Captain; pgDto.isSixthMan = detail.SixthMan; pgDto.isEmergency = detail.Emergency; playerCardsList.Add(pgDto); matched = 1; } } if (matched == 0) { // no match was found, need to add empty player card PlayerCardDto pgDto = new PlayerCardDto(); pgDto.PlayerId = 0; pgDto.averageScore = 0; pgDto.CardPosition = pos; pgDto.CardPositionText = GetPositionText(pos); pgDto.FirstName = ""; pgDto.lastScore = 0; pgDto.PlayerPosition = 0; pgDto.PlayerPositionTwo = 0; pgDto.PlayerPositionThree = 0; pgDto.Price = 0; pgDto.Surname = ""; pgDto.Team = ""; playerCardsList.Add(pgDto); } } return(playerCardsList); }