Ejemplo n.º 1
0
        public Item DropItem(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 itemM = new ItemManager((from i in player.ObjectInventory
                                                 where i.Id == id
                                                 select i).FirstOrDefault());
                player.Hp = Player.Hp;
                player.MaxHp = Player.MaxHp;
                player.Xp = Player.Xp;
                player.CurrentCellId = Player.CurrentCellId;
                player.ObjectInventory.Remove(itemM.Item);
                var item = (from w in db.Items
                              where w.Id == itemM.Item.Id
                              select w).FirstOrDefault();
                db.Items.Remove(item);
                db.SaveChanges();
                return item;
            }
        }
Ejemplo n.º 2
0
 public Item AddItem(int type = -1)
 {
     var db = new Project2NetContext();
     var player = (from p in db.Players
                   where p.Id == Player.Id
                   select p).FirstOrDefault();
     var itemM = new ItemManager((int)Math.Floor((double)Player.Xp / 100), type);
     itemM.Item = new Item { ObjectType = db.ItemsTypess.Find(itemM.Item.ObjectType.Id) };
     if (player != null)
     {
         player.Hp = Player.Hp;
         player.MaxHp = Player.MaxHp;
         player.Xp = Player.Xp;
         player.CurrentCellId = Player.CurrentCellId;
         player.ObjectInventory.Add(itemM.Item);
         Player.ObjectInventory = player.ObjectInventory;
     }
     db.SaveChanges();
     return itemM.Item;
 }