//Constructeur public Combat(int idPlayer, Cell cell) { PlayerM = new PlayerManager(idPlayer); MonsterM = new MonsterManager(PlayerM.Player, cell); MonsterAttackRate = MonsterM.Monster.AttackRate; PlayerAttackRate = 0; PlayerBonusAttaque = 0; PlayerBonusDefense = 0; MonsterBonusAttaque = 0; MonsterBonusDefense = 0; }
public void ExecRefreshGrid() { _grid.Clear(); ObservableCollection<Cell> tempGrid; using (var db = new Project2NetContext()) { _playerM.Player.CurrentCell = db.Cells.FirstOrDefault(cell => cell.Id == (int)_playerM.Player.CurrentCellId); tempGrid = (from cell in db.Cells where (cell.PosX >= _playerM.Player.CurrentCell.PosX - 2 && cell.PosX <= _playerM.Player.CurrentCell.PosX + 2) && (cell.PosY >= _playerM.Player.CurrentCell.PosY - 2 && cell.PosY <= _playerM.Player.CurrentCell.PosY + 2) select cell).ToObservableCollection(); } for (var a = -2; a <= 2; a++) { for (var b = -2; b <= 2; b++) { var temp = tempGrid.SingleOrDefault( cell => (cell.PosX == _playerM.Player.CurrentCell.PosX + a) && (cell.PosY == _playerM.Player.CurrentCell.PosY + b)); if (temp == null) { temp = new Cell { PosX = _playerM.Player.CurrentCell.PosX + a, PosY = _playerM.Player.CurrentCell.PosX + b, Description = "Case Inexplorée", MonsterGroup = -1, ImageSource = "../Ressources/Images/ground_empty_cell.png", CanMoveTo = "0000", Id = 0, MonsterRate = 0, Visited = false }; } _grid.Add(temp); } } NotifyPropertyChanged("Grid"); }
//Nouvelle Cellule public CellManager(int x, int y, int direction = -1) { using (var db = new Project2NetContext()) { //Random Generator var random = MainWindow.Random; //Nouvelles positions var newX = new int(); var newY = new int(); //Initialisation d'une chaine de chars var canMoveTo = new char[4]; //nord;est;sud;ouest //Index du tableau qui sera fixé var index = new int(); //Case possiblement bloquée var randomCell = new int(); switch (direction) { case -1: //Départ newX = x; newY = y; index = random.Next(0, 4); canMoveTo[index] = '1'; //Case forcément ouverte break; case 0: //nord newX = x; newY = y + 1; index = 2; canMoveTo[index] = '1'; //Case forcément ouverte break; case 1: //est newX = x + 1; newY = y; index = 3; canMoveTo[index] = '1'; //Case forcément ouverte break; case 2: //sud newX = x; newY = y - 1; index = 0; canMoveTo[index] = '1'; //Case forcément ouverte break; case 3: //ouest newX = x - 1; newY = y; index = 1; canMoveTo[index] = '1'; //Case forcément ouverte break; } var existingCell = db.Cells.SingleOrDefault(cell => cell.PosX == newX && cell.PosY == newY); if (existingCell == null) { //Choix d'une case possiblement bloquée do { randomCell = random.Next(0, 4); } while (randomCell == index); //remplissage de l'array de possibilités for (var a = 0; a < 4; a++) { if (a == randomCell) //Si c'est la case possiblement bloquée { if (random.Next(0, 2) == 1) { canMoveTo[a] = '1'; } else { canMoveTo[a] = '0'; } } else if (a != index) //Si c'est pas la case forcément ouverte { canMoveTo[a] = '1'; } } //Min 30 Max 50% de mob rate var monsterRate = random.Next(0, 51); Biome biome = null; biome = GetRandomBiome(); Cell = new Cell { Description = biome.Description, ImageSource = biome.ImageSource, CanMoveTo = ToStringCanMoveTo(canMoveTo), MonsterGroup = biome.MonsterGroup, MonsterRate = monsterRate, PosX = newX, PosY = newY }; db.Cells.Add(Cell); db.SaveChanges(); } else { Cell = existingCell; } } }
//Cellule existante par paramétre public CellManager(Cell cell) { Cell = cell; }
//Cellule existante public CellManager(int id) { using (var db = new Project2NetContext()) { Cell = db.Cells.SingleOrDefault(cell => cell.Id == id); } }
//Crée un monstre en fonction du joueur et de la case(donc du biome) public MonsterManager(Player player, Cell cell) { var monsterLibrary1 = new List<string>() { "Loup enragé", "Ours furieux", "Araignée verte", "Faucon sauvage", "Taureau en rut", "Vipére sournoise", "Bandit de grand chemin", "Chat de chasse",//Utilise ses griffes comme arme de destruction massive }; var monsterLibrary2 = new List<string>() { "Rejeton de magie", "Bête de mana", "Sorcier fou", "Mage noir", "Mage des arcanes", "Sorciére sadique", "Playmobil vivant", //Glauque }; var monsterLibrary3 = new List<string>() { "Nécromancien", "Cerbére", "Essence de chaos", "Satyre lubrique", "Flamme hurlante", "Caniche d'attaque", //Attention, il bave }; var monsterLibrary4 = new List<string>() { "Bandit de la ville basse", "Marchand en colére", "Paysan révolté", "Pillard", "Bête des égouts", "Rick Astley", //NEVER GONNA GIVE YOU UP }; var monsterLibrary5 = new List<string>() { "Guerrier en décomposition", "Squelette", "Liche", "Zombie purulent", "Monstre de chair", "Ballmer Sauvage", //lol }; var random = MainWindow.Random; string selectedMonster; switch (cell.MonsterGroup) { case 1: selectedMonster = monsterLibrary1[random.Next(0, monsterLibrary1.Count)]; break; case 2: selectedMonster = monsterLibrary2[random.Next(0, monsterLibrary2.Count)]; break; case 3: selectedMonster = monsterLibrary3[random.Next(0, monsterLibrary3.Count)]; break; case 4: selectedMonster = monsterLibrary4[random.Next(0, monsterLibrary4.Count)]; break; case 5: selectedMonster = monsterLibrary5[random.Next(0, monsterLibrary5.Count)]; break; default: selectedMonster = monsterLibrary1[random.Next(0, monsterLibrary1.Count)]; break; } var attackRate = 40; var missRate = 30; var health = 60; var damage = 15; var level = (int)Math.Floor((double)player.Xp / 100); var levelBlocked = level > 10 ? 10 : level; MonsterLevel = level; attackRate = random.Next((attackRate + (levelBlocked - 1) * 6), (attackRate + levelBlocked * 6)); missRate = random.Next((missRate - levelBlocked * 3), (missRate - (levelBlocked - 1) * 3)); health = random.Next((health + (level - 1) * 60), (health + level * 60)); MonsterMaxHp = health; damage = damage + level * 15; Monster = new Monster { AttackRate = attackRate, MissRate = missRate, Group = cell.MonsterGroup, Hp = health, Name = selectedMonster, Damage = damage }; }