public HitLogUserControl(object par) { InitializeComponent(); repos = new HitLogRepository(); combatLogList = repos.GetAll().Where(x => x.CombatLogId == (int)par).ToList(); usersDataGrid.Update(); usersDataGrid.DataSource = combatLogList; }
public HitLogUserControl() { InitializeComponent(); repos = new HitLogRepository(); combatLogList = repos.GetAll().ToList(); usersDataGrid.Update(); usersDataGrid.DataSource = combatLogList; }
public HitLog Turn(BodyPart player1punch, BodyPart player1block, BodyPart player2punch, BodyPart player2block) { HitLog log = new HitLog(); // round preparation player1.SetBlock(player1block); player2.SetBlock(player2block); if (player2 is NPC) { player2punch = (BodyPart)(new Random().Next(5)); } // Бьет первый игрок log.FirstPalyerHitValue = player2.GetHit(player1punch, new FightPapams(player1.Straight, player1.Agility)); log.FirstPalyerPart = player1punch; log.FirstPalyerResult = log.FirstPalyerHitValue != 0 ? TurnResult.Wound : TurnResult.Miss; // Бьет второй игрок log.SecondPlayerHitValue = player1.GetHit(player2punch, new FightPapams(player2.Straight, player2.Agility)); log.SecondPlayerPart = player2punch; log.SecondPlayerResult = log.SecondPlayerHitValue != 0 ? TurnResult.Wound : TurnResult.Miss; log.FirstPlayerCurrentHp = player1.Hp; log.SecondPlayerCurrentHp = player2.Hp; combatLog.CombatHitLogs.Add(log); // Проверка смерти игрока и награда победителя if ((player1.Hp <= 0) && (player2.Hp > 0)) // player2 win { if (!(player2 is NPC)) { int oldExp = player2.Exp; player2.AddExp((int)(player1.MaxHp * ((double)(player1.Straight + player1.Stamina + player1.Agility) / (double)(player2.Straight + player2.Stamina + player2.Agility)))); combatLog.CombatTime = DateTime.Now; combatLog.Exp = 0; repos.GetAll().Where(x => x.PlayerDTOId == (player2 as Player).PlayerId).First().Exp = player2.Exp; repos.Save(); combatLogRep.Add(combatLog); //repos.Update((Player)player2); // need save } combatLog.Result = GameResult.Loss; } if ((player2.Hp <= 0) && (player1.Hp > 0)) // player1 win { int oldExp = player1.Exp; player1.AddExp((int)(player2.MaxHp * ((double)(player2.Straight + player2.Stamina + player2.Agility) / (double)(player1.Straight + player1.Stamina + player1.Agility)))); combatLog.CombatTime = DateTime.Now; combatLog.Result = GameResult.Win; combatLog.Exp = player1.Exp - oldExp; PlayerDTO pl = repos.GetAll().Where(x => x.PlayerDTOId == (player1 as Player).PlayerId).First(); pl.Exp = player1.Exp; repos.Save(); combatLogRep.Add(combatLog); //repos.Update((Player)player1); // need save } if ((player1.Hp <= 0) && (player2.Hp <= 0)) // draw { combatLog.CombatTime = DateTime.Now; combatLog.Result = GameResult.Draw; combatLog.Exp = 0; combatLogRep.Add(combatLog); // need save } log.CombatLogId = combatLog.CombatLogId; HitLogRepository hitLogRep = new HitLogRepository(); hitLogRep.Add(log); return(log); }