public async Task <Item> CreateItem(Guid id, NewItem item) { var filter = Builders <Player> .Filter.Eq(p => p.Id, id); Player pl = _collection.Find(filter).FirstAsync().Result; Item i = new Item() { Itemtype = item.ItemType, Id = Guid.NewGuid(), Level = item.Level }; pl.Items.Add(i); var replace = Builders <Player> .Update.Set(player => player.Items, pl.Items); await _collection.UpdateOneAsync(filter, replace); return(await Task.FromResult <Item>(pl.Items[pl.Items.Count - 1])); }
public async Task <Item> CreateItem(Guid id, NewItem item) { Player pelaaja = await _repository.Get(id); try { var rand = new Random(); Item tavara = new Item(); tavara.Id = Guid.NewGuid(); tavara.Level = rand.Next(99 + 1); int arpa = rand.Next(3); if (arpa == 0) { tavara.Itemtype = ItemType.POTION; } if (arpa == 1) { tavara.Itemtype = ItemType.SHIELD; } if (arpa == 2) { if (pelaaja.Level >= 3) { tavara.Itemtype = ItemType.SWORD; } else { //Console.WriteLine(errorHandling.errorString()); customExceptionFilterAttribute.OnException(InvalidLevelException(pelaaja.Level)); } } DateTime start = new DateTime(1995, 1, 1); int range = (DateTime.Today - start).Days; DateTime now = DateTime.Now.AddDays(rand.Next(range)); tavara.CreationDate = now; items.Add(tavara); pelaaja.Items.Add(tavara); await _repository.CreateItem(id, item); //sano sit ku oot valmis testaamaan return(tavara); } catch (HttpStatusCodeException ex) { throw ex; } }
//string gameDevName = "game-dev.txt"; //StreamWriter writer = new StreamWriter("game-dev.txt",false); //public int Score { get; set; } /* * public async Task<Item> CreateItem(Guid id,Item item) * { * File.AppendAllText(gameDevName, JsonConvert.SerializeObject(item) +"\n"); * * * return item; * } */ public async Task <Item> CreateItem(Guid id, NewItem item) { Player p = await Get(id); Item newItem = new Item() { Id = Guid.NewGuid(), }; return(await Task.FromResult <Item>(newItem)); }
public async Task <Item> Create(Guid playerID, NewItem item) { Item i = new Item(); Player p = await repo.Get(item.OwningPlayer); i.OwningPlayer = item.OwningPlayer; if (item.ItemType == "Sword" && p.Level < 3) { throw new RuleNotFollowedException(); } i.Level = item.Level; i.ItemID = Guid.NewGuid(); i.ItemType = item.ItemType; i.CreationDate = DateTime.Now; return(await repo.Create(p.Id, i)); }
public async Task <Item> CreateItem(Guid playerId, NewItem newItem) { return(await _IRepo.CreateItem(playerId, newItem)); }
public Task <Item> Create(Guid id, [FromBody] NewItem item) { return(processor.Create(id, item)); }