Exemple #1
0
        public async Task <Item> CreateItem(Item item, ObjectId playerId)
        {
            var db      = dbClient.GetDatabase("game");
            var players = db.GetCollection <Player>("players");
            var filter  = Builders <Player> .Filter.Eq("id", playerId);

            var result = players.Find(filter).SingleOrDefault();

            result.ItemList.Add(item);

            itemList.Add(item);
            if (item.Type == "Sword")
            {
                for (int i = 0; i < playerList.Count; i++)
                {
                    if (playerList[i].id == playerId)
                    {
                        if (playerList[i].Level < 3)
                        {
                            GameRuleValidation argEx = new GameRuleValidation("Game Rule Validation: Player must be at least level 3 to hold this item");
                            throw argEx;
                        }
                    }
                }
            }
            return(item);
        }
 public async Task <Item> CreateItem(Item item, Guid playerId)
 {
     itemList.Add(item);
     if (item.Type == "Sword")
     {
         for (int i = 0; i < playerList.Count; i++)
         {
             if (playerList[i].Id == playerId)
             {
                 if (playerList[i].Level < 3)
                 {
                     GameRuleValidation argEx = new GameRuleValidation("Game Rule Validation: Player must be at least level 3 to hold this item");
                     throw argEx;
                 }
             }
         }
     }
     return(item);
 }