示例#1
0
        public Task <Item> ModifyItem(Guid player, Guid id, ModifiedItem item)
        {
            Item searched = new Item();


            string     AllText = File.ReadAllText(path);
            AllPlayers players = JsonConvert.DeserializeObject <AllPlayers>(AllText);



            for (int i = 0; i < players.play.Count; i++)
            {
                if (players.play[i].Id == player)
                {
                    for (int o = 0; o < players.play[i].items.Count; i++)
                    {
                        if (players.play[i].items[o].Id == id)
                        {
                            players.play[i].items[o].Level = item.Level;
                            searched = players.play[i].items[o];
                        }
                    }
                }
            }

            string playerInfo = JsonConvert.SerializeObject(players);

            File.WriteAllText(path, playerInfo);

            return(Task.FromResult(searched));
        }
        UpdateItem(Guid playerId, Guid itemId, ModifiedItem modifiedItem)
        {
            var lines = await ReadLinesFromRepositoryFile(repositoryFilename);

            int playerLineIndex = await GetPlayerLineIndex(playerId, lines);

            if (playerLineIndex < 0)
            {
                throw new GameWebApi.NotFoundException();
            }

            var player    = ParsePlayer(lines[playerLineIndex]);
            int itemIndex = GetPlayerItemIndex(player, itemId);

            if (itemIndex < 0)
            {
                throw new GameWebApi.NotFoundException();
            }

            Item item = player.Items[itemIndex];

            player.Items[itemIndex].Level = modifiedItem.Level ?? player.Items[itemIndex].Level;

            lines[playerLineIndex] = FormatPlayer(player);
            await File.WriteAllLinesAsync(repositoryFilename, lines);

            return(item);
        }
示例#3
0
        public Task <Item> ModifyItem(Guid id, int index, ModifiedItem item)
        {
            Player p = _playerData.Players.Find(pl => pl.Id == id);

            p.ItemList[index].Price    = item.Price;
            p.ItemList[index].ItemType = item.ItemType;
            return(Task.FromResult <Item>(p.ItemList[index]));
        }
示例#4
0
        public Task <Item> UpdateItem(Guid playerId, Guid itemId, ModifiedItem modifiedItem)
        {
            Item newItem = new Item()
            {
                ItemId       = itemId,
                Level        = modifiedItem.Level,
                Type         = modifiedItem.Type,
                CreationDate = DateTime.Now
            };

            return(_repo.UpdateItem(playerId, newItem));
        }
示例#5
0
        public void ModItem(Guid player, Guid id, ModifiedItem item)
        {
            Player top = GetOne(player);

            for (int i = 0; i < top.items.Count; i++)
            {
                if (top.items[i].Id == id)
                {
                    top.items[i].Level = item.Level;
                }
            }
        }
        public async Task <Item> UpdateItem(Guid playerId, Guid itemId, ModifiedItem modifiedItem)
        {
            var player = await GetPlayerById(playerId);

            var item = player.Items.Where(i => i.Id == itemId).First();

            if (item != null)
            {
                item.Level = modifiedItem.Level ?? item.Level;
                await collection.ReplaceOneAsync(PlayerIdFilter(playerId), player);

                return(item);
            }

            throw new ItemNotFoundException();
        }
        public async Task <Item> UpdateItem(Guid playerId, ModifiedItem item)
        {
            var filter = Builders <Player> .Filter.Eq(p => p.Id, playerId);

            Player player = await _playerCollection.Find(filter).FirstAsync();

            for (int i = 0; i < player.itemlist.Count; i++)
            {
                if (player.itemlist[i].Id == item.id)
                {
                    player.itemlist[i].level = item.level;
                    await _playerCollection.ReplaceOneAsync(filter, player);

                    return(player.itemlist[i]);
                }
            }
            return(null);
        }
示例#8
0
        public async Task <Item> ModifyItem(Guid player, Guid id, ModifiedItem item)
        {
            var filter = Builders <Player> .Filter.Eq(p => p.Id, player);

            var player1 = await playercollection.Find(filter).FirstAsync();

            var result = player1.items.First(i => i.Id == id);

            result.Level = item.Level;

            var update = Builders <Player> .Update.Set(p => p.items, player1.items);

            var resulted = await playercollection.UpdateOneAsync(filter, update);

            var result2 = await playercollection.Find(filter).FirstAsync();

            return(result);
        }
示例#9
0
        public async Task <Item> UpdateItem(Guid playerId, ModifiedItem item)
        {
            ModifiedItem modItem = new ModifiedItem();
            Player       p       = await Get(playerId);

            Item i = new Item();

            i.Level = item.Level;
            bool itemFound = false;

            foreach (Item it in p.Items)
            {
                if (it.Id == item.Id)
                {
                    it.Level  = item.Level;
                    i         = it;
                    itemFound = true;
                }
            }

            if (!itemFound)
            {
                Console.WriteLine("Couldnt update item: Player: " + playerId + " doesnt own item " + item.Id);
            }

            if (p != null && itemFound)
            {
                FilterDefinition <Player> filter = Builders <Player> .Filter.Eq(p => p.Id, playerId);

                await playersCollection.ReplaceOneAsync(filter, p);

                Console.WriteLine("Successfully modified players: " + playerId + " " + i.ItemType.ToString() + " level to: " + i.Level);
                return(i);
            }

            return(null);
        }
示例#10
0
        public async Task <Item> UpdateItem(Guid playerId, ModifiedItem item)
        {
            Item   item1    = new Item();
            string itemjson = JsonConvert.DeserializeObject(item1.Id.ToString()) + Environment.NewLine;

            try
            {
                if (path.Contains(item1.Id.ToString()) && path.Contains(playerId.ToString()))
                {
                    await File.WriteAllTextAsync(path, itemjson, Encoding.UTF8);

                    return(item1);
                }
                else
                {
                    return(item1);
                }
            }
            catch (System.Exception e)
            {
                Console.WriteLine(e.Message);
                throw;
            }
        }
示例#11
0
 public async Task <Item> UpdateItem(Guid playerId, Guid itemId, [FromBody] ModifiedItem item)
 {
     return(await _repository.UpdateItem(playerId, itemId, item));
 }
 public Task <Item> UpdateItem(Guid playerId, ModifiedItem item)
 {
     return(_repository.UpdateItem(playerId, item));
 }
示例#13
0
 public Task <Item> UpdateItem(Guid playerId, [FromBody] ModifiedItem item)
 {
     Console.WriteLine("HttpPost: UpdateItem");
     return(repo.UpdateItem(playerId, item));
 }
示例#14
0
 public Task <Item> UpdateItem(Guid playerId, Guid itemId, ModifiedItem item)
 {
     throw new NotImplementedException();
 }
示例#15
0
 public Task <Item> ModifyItem(Guid player, Guid id, ModifiedItem item)
 {
     return(_repository.ModifyItem(player, id, item));
 }
示例#16
0
 public async Task <Item> UpdateItem(Guid playerId, Guid itemId, [FromBody] ModifiedItem modifiedItem)
 => await playerRepository.UpdateItem(playerId, itemId, modifiedItem);