示例#1
0
 /// <summary>
 /// Finds an item suitable for a given location
 /// </summary>
 /// <param name="location"></param>
 /// <param name="items"></param>
 /// <returns></returns>
 public ItemModel FindItemForLocation(ItemLocationEnum location, List <ItemModel> items)
 {
     foreach (var item in items)
     {
         if (item.Location.ToString() == location.ToString())
         {
             return(item);
         }
     }
     return(null);
 }
        // Asks the server for items based on paramaters
        // Number is th enumber of items to return
        // Level is the Value max for the items
        // Random is to have the value random between 1 and the Level
        // Attribute is a filter to return only items for that attribute, else unknown is used for any
        // Location is a filter to return only items for that location, else unknown is used for any
        //      public async Task<List<Item>> GetItemsFromServerPost(string text, string description, string id, int defense, int speed, int attack, int damage, int range, int position, string imageURI, bool random, bool updateDataBase)//int number, int level, bool random, bool updateDataBase)
        //    {
        //AttributeEnum attribute, ItemLocationEnum location
        //     public async Task<List<Item>> GetItemsFromServerPost(int number, int level, string description, Attributes.AttributeEnum  attribute, ItemLocationEnum location, bool random, bool updateDataBase)
        //   {
        public async Task <List <Item> > GetItemsFromServerPost(int number, int level, Attributes.AttributeEnum attribute, ItemLocationEnum location, bool random, bool updateDataBase)
        {
            // Needs to get items from the server
            // Parse them
            // Then update the database
            // Only update fields on existing items
            // Insert new items
            // Then notify the viewmodel of the change

            // Needs to get items from the server



            var URLComponent = "GetItemListPost/";

            var dict = new Dictionary <string, string>
            {
                { "Number", number.ToString() },
                { "Level", level.ToString() },
                { "Random", random.ToString() },
                { "Attribute", attribute.ToString() },
                { "Location", location.ToString() },
                { "UpdateDatabase", updateDataBase.ToString() }
            };



            // Convert parameters to a key value pairs to a json object
            JObject finalContentJson = (JObject)JToken.FromObject(dict);

            // Make a call to the helper.  URL and Parameters
            var DataResult = await HttpClientService.Instance.GetJsonPostAsync(WebGlobals.WebSiteAPIURL + URLComponent, finalContentJson);

            // Parse them
            var myList = ParseJson(DataResult);

            // Then update the database

            // Use a foreach on myList
            if (updateDataBase)
            {
                foreach (var item in myList)
                {
                    await SQLDataStore.Instance.InsertUpdateAsync_Item(item);
                }

                // When foreach is done, call to the items view model to set needs refresh to true, so it can refetch the list...
                ItemsViewModel.Instance.SetNeedsRefresh(true);
            }

            return(myList);
        }
示例#3
0
        // Creates an Item for the Locatoin and Attribute
        public static Item ItemDefault(ItemLocationEnum itemLocation, AttributeEnum attribute)
        {
            Item myData;

            myData = new Item
            {
                Name        = "Item for " + itemLocation.ToString(),
                Description = "Auto Created",
                ImageURI    = null,

                Range  = 1,
                Damage = 1,
                Value  = 1,

                Attribute = attribute,
                Location  = itemLocation
            };

            return(myData);
        }