Ejemplo n.º 1
0
        //New Player
        public PlayerManager(string name)
        {
            if (name != "")
            {
                var db = new Project2NetContext();
                var rand = MainWindow.Random;
                //Randomisation du point de départ
                var x = rand.Next(-500, 500);
                var y = rand.Next(-500, 500);
                var temp = db.Cells.FirstOrDefault(cell => cell.PosX == x && cell.PosY == y);

                if (temp != null)
                {
                    Player = new Player
                        {
                            Name = name, 
                            MaxHp = 500, 
                            Hp = 500, 
                            Xp = 0, 
                            CurrentCellId = temp.Id
                        };
                }
                else
                {
                    var cellM = new CellManager(x, y);
                    Player = new Player
                        {
                            Name = name,
                            MaxHp = 500,
                            Hp = 500,
                            Xp = 0,
                            CurrentCellId = cellM.Cell.Id
                        };
                }
                var weaponM = new WeaponManager(0, true);

                Player.WeaponInventory = new Collection<Weapon>
                    {
                        weaponM.Weapon
                    };
                Player.ObjectInventory = new Collection<Item>();

                db.Players.Add(Player);
                db.SaveChanges();
            }
            else
            {
                Player = null;
            }
        }
        private void StayAlive_Click(object sender, RoutedEventArgs e)
        {
            var db = new Project2NetContext();
            var playerM = MainWindow.SelectedPlayerViewModel.ActivePlayerManager;
            if (playerM.Player != null)
            {
                playerM.Player.Xp = playerM.Player.Xp - 300;
                if (playerM.Player.Xp <= 0) playerM.Player.Xp = 0;
                playerM.Player.MaxHp = 500 + ((int)Math.Floor((double)playerM.Player.Xp / 100)) * 150;
                playerM.Player.Hp = playerM.Player.MaxHp;
                var itemList = playerM.Player.ObjectInventory.ToList();
                foreach (var item in itemList)
                {
                    playerM.Player.ObjectInventory.Remove(item);
                    var itemD = (from i in db.Items
                                 where i.Id == item.Id
                                 select i).FirstOrDefault();
                    db.Items.Remove(itemD);
                }

                var weaponList = playerM.Player.WeaponInventory.ToList();
                foreach (var weapon in weaponList)
                {
                    playerM.Player.WeaponInventory.Remove(weapon);
                    var weaponD = (from i in db.Weapons
                                   where i.Id == weapon.Id
                                   select i).FirstOrDefault();
                    db.Weapons.Remove(weaponD);
                }
                db.SaveChanges();
                var weaponM = new WeaponManager(playerM.Player.Xp, true);
                playerM.Player.WeaponInventory.Add(weaponM.Weapon);
                MainWindow.SelectedPlayerViewModel.ActivePlayerManager.Player = playerM.Player;
                MainWindow.SelectedPlayerViewModel.ActivePlayerManager.Save();
                MainWindow.SelectedPlayerViewModel.Weapons.Clear();
                MainWindow.SelectedPlayerViewModel.Items.Clear();
                var weaponAdded = MainWindow.SelectedPlayerViewModel.ActivePlayerManager.AddWeapon();
                MainWindow.SelectedPlayerViewModel.Weapons.Add(weaponAdded);

                MessageBox.Show("Vous vous sentez Renaitre !");
                MainWindow.SelectedPlayerViewModel.RefreshMainUi();

                SoundHelper.PlayFromCategory(SoundHelper.Categories.Normal);
                NavigationHelper.MoveToPage(MainWindow.SelectedPlayerView);
            }
        }
Ejemplo n.º 3
0
        public Weapon DropWeapon(int id)
        {
            using (var db = new Project2NetContext())
            {
                var player = (from p in db.Players
                              where p.Id == Player.Id
                              select p).FirstOrDefault();

                if (player == null) return null;
                var weaponM = new WeaponManager((from w in player.WeaponInventory
                                                 where w.Id == id
                                                 select w).FirstOrDefault());
                player.Hp = Player.Hp;
                player.MaxHp = Player.MaxHp;
                player.Xp = Player.Xp;
                player.CurrentCellId = Player.CurrentCellId;
                player.WeaponInventory.Remove(weaponM.Weapon);
                var weapon = (from w in db.Weapons
                              where w.Id == weaponM.Weapon.Id
                              select w).FirstOrDefault();
                db.Weapons.Remove(weapon);
                db.SaveChanges();
                return weapon;
            }
        }
Ejemplo n.º 4
0
 public Weapon AddWeapon()
 {
     var db = new Project2NetContext();
     var player = (from p in db.Players
                   where p.Id == Player.Id
                   select p).FirstOrDefault();
     var weaponM = new WeaponManager(Player.Xp);
     if (player != null)
     {
         player.Hp = Player.Hp;
         player.MaxHp = Player.MaxHp;
         player.Xp = Player.Xp;
         player.CurrentCellId = Player.CurrentCellId;
         player.WeaponInventory.Add(weaponM.Weapon);
         //Copie en local
         Player.WeaponInventory = player.WeaponInventory;
     }
     db.SaveChanges();
     return weaponM.Weapon;
 }