question

duartedd avatar image
duartedd asked

Request For Addition: Getting a subset list of drop table provision ( high chance and low chance ) or something accessible

Hello

Right now I am trying to get a list of items to show the percentage chance values of the drop table for the container - basically show what they can get from opening a chest via an info button or something that other games have. Give the player an idea of what they can get from the drops and right now with a 6 layer drop table the code is getting pretty intense - maybe there is a way to build something that you can think of to help for the future or perhaps the private preview economy has some features for this?

note my code is still being written - 5 more layers to go for the bottom part and i think should be almost done

thanks!

Daniel

        // get result drop table
        [FunctionName("GetLootTableItems")]
        public static async Task<dynamic> GetLootTableItems(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, ILogger log)
        {
            /* Create the function execution's context through the request */
            var context = await FunctionContext<dynamic>.Create(req);
            var args = context.FunctionArgument;
            
            var resultTables = args["resultTables"]; 
   var serverApi = new PlayFabServerInstanceAPI(context.ApiSettings, context.AuthenticationContext);
          
            var GetItemRandomResultTableReq = new GetRandomResultTablesRequest
            {
               TableIDs = resultTables
            };

            var GetRandomResultTables = await serverApi.GetRandomResultTablesAsync(GetItemRandomResultTableReq);
     var Firstresult =  GetRandomResultTables.Result;
         
        var firstDropResult = CycleThroughDropTables(Firstresult) ;
          DropResultItems secondDropResult = null;
          DropResultItems thirdDropResult = null;
          DropResultItems fourthDropResult = null;
          DropResultItems fifthDropResult = null;
          DropResultItems sixthDropResult = null;
          DropResultItems seventhDropResult = null;


   if (firstDropResult.DropTableNodes.Count > 0) 
   {
       List<string> secondtableids =  new List<String>();
        foreach(var table in firstDropResult.DropTableNodes.Values) 
          secondtableids.Add(table.ResultItem);  

         var getSecondLevelRandomDropTablesReq = new GetRandomResultTablesRequest
            {
               TableIDs = secondtableids
            };

               var getSecondLevelDropTablesResult = await serverApi.GetRandomResultTablesAsync(getSecondLevelRandomDropTablesReq);
              var SecondResult =  getSecondLevelDropTablesResult.Result;
       
                log.LogDebug($"Get second Random Result  Table");
                secondDropResult = CycleThroughDropTables(SecondResult) ;

               if (secondDropResult.DropTableNodes.Count > 0) 
               {
                  List<string> thirdtableids =  new List<String>();
                   foreach(var table in secondDropResult.DropTableNodes.Values) 
                  thirdtableids.Add(table.ResultItem);  

                   var getThirdLevelDroptable = new GetRandomResultTablesRequest
                    {
                       TableIDs = thirdtableids
                    };

                       var getThirdLevelDropTableResult = await serverApi.GetRandomResultTablesAsync(getThirdLevelDroptable);
                      var Thirdresult =  getThirdLevelDropTableResult.Result;
                 
                        log.LogDebug($"Get third Random Result  Table");
                        thirdDropResult = CycleThroughDropTables(Thirdresult);

                                   if (thirdDropResult.DropTableNodes.Count > 0) 
               {
                  List<string> fourthtableids =  new List<String>();
                   foreach(var table in thirdDropResult.DropTableNodes.Values) 
                  fourthtableids.Add(table.ResultItem);  

                   var getFourthLevelDropTablereq = new GetRandomResultTablesRequest
                    {
                       TableIDs = fourthtableids
                    };

                       var getFourthLevelDropTableResult = await serverApi.GetRandomResultTablesAsync(getFourthLevelDropTablereq);
                      var FourthResult =  getFourthLevelDropTableResult.Result;
                 
                        log.LogDebug($"Get fourth Random Result  Table");
                        fourthDropResult = CycleThroughDropTables(FourthResult);
                         
                              if (fourthDropResult.DropTableNodes.Count > 0) 
               {
                  List<string> fifthTableIds =  new List<String>();
                   foreach(var table in fourthDropResult.DropTableNodes.Values) 
                  fifthTableIds.Add(table.ResultItem);  

                   var getFifthLevelDropTableReq = new GetRandomResultTablesRequest
                    {
                       TableIDs = fifthTableIds
                    };

                       var getFifthLevelDropTableResult = await serverApi.GetRandomResultTablesAsync(getFifthLevelDropTableReq);
                      var FifthResult =  getFifthLevelDropTableResult.Result;
                 
                        log.LogDebug($"Get fifth Random Result  Table");
                        fifthDropResult = CycleThroughDropTables(FifthResult);

                                if (fifthDropResult.DropTableNodes.Count > 0) 
               {
                  List<string> sixthtableids =  new List<String>();
                   foreach(var table in fifthDropResult.DropTableNodes.Values) 
                  sixthtableids.Add(table.ResultItem);  

                   var getSixthDropTableReq = new GetRandomResultTablesRequest
                    {
                       TableIDs = sixthtableids
                    };

                       var getSixthDropTableResult = await serverApi.GetRandomResultTablesAsync(getSixthDropTableReq);
                      var sixthResult =  getSixthDropTableResult.Result;
                 
                        log.LogDebug($"Get fifth Random Result  Table");
                        sixthDropResult = CycleThroughDropTables(sixthResult);
                        
                                if (sixthDropResult.DropTableNodes.Count > 0) 
               {
                  List<string> seventhdropids =  new List<String>();
                   foreach(var table in sixthDropResult.DropTableNodes.Values) 
                  seventhdropids.Add(table.ResultItem);  

                   var getSeventhDropReq = new GetRandomResultTablesRequest
                    {
                       TableIDs = seventhdropids
                    };

                       var getSeventhDropResult = await serverApi.GetRandomResultTablesAsync(getSeventhDropReq);
                      var seventhResult =  getSeventhDropResult.Result;
                 
                        log.LogDebug($"Get fifth Random Result  Table");
                        seventhDropResult = CycleThroughDropTables(seventhResult);
               }
               }
               }
               }
               }
     
  
    }
    List<ItemWithPercentage> Items = new List<ItemWithPercentage> ();

                  foreach( var item in firstDropResult.ItemNodes.Values)  
                 Items.Add(new ItemWithPercentage  {
                             PercentageToReceive = item.Weight / firstDropResult.TotalWeight,
                             ItemId = item.ResultItem
                            } ); 

                if (secondDropResult.DropTableNodes.Count > 0 || secondDropResult.ItemNodes.Count > 0) 
                 {
                    
                   foreach ( var item in secondDropResult.ItemNodes)
                  {  

                  var firstDropPercentage = firstDropResult.DropTableNodes[item.Key].Weight / firstDropResult.TotalWeight;
 
                  var currentItemWeightDropPercentage =   item.Value.Weight / secondDropResult.TotalWeight;
                    
                    var totalItemAmount = ((firstDropPercentage / 100) * (currentWeightDropPercentage / 100)) *100;

                  log.LogDebug("firstDropPercentage: " + firstDropPercentage +" currentweightdroppercent: " + currentItemWeightDropPercentage + " total amount: "+  totalItemAmount);
                      Items.Add(new ItemWithPercentage  {
                             PercentageToReceive = totalItemAmount,
                             ItemId = item.Value.ResultItem
                            } );
                  }

                  
                if (thirdDropResult.DropTableNodes.Count > 0 || thirdDropResult.ItemNodes.Count > 0) 
                 {
                    
                   foreach ( var item in thirdDropResult.ItemNodes)
                  {  

                  var secondDropPercentage = secondDropResult.DropTableNodes[item.Key].Weight / secondDropResult.TotalWeight;
                  
                 var firstdropPercentage = firstDropResult.DropTableNodes[secondDropResult.DropTableNodes[item.Key].ResultItem].Weight / firstDropResult.TotalWeight;
                
                  var currentItemWeightDropPercentage =   item.Value.Weight / secondDropResult.TotalWeight;
                    
                    var totalItemAmount = ((firstdropPercentage / 100) * (currentItemWeightDropPercentage / 100) * (secondDropPercentage / 100)) *100;

                  log.LogDebug("firstDropPercentage: " + firstdropPercentage +" currentweightdroppercent: " + currentItemWeightDropPercentage + " secondDropPercentage: "+ secondDropPercentage+ " total amount: "+  totalItemAmount);
             
                      Items.Add(new ItemWithPercentage  {
                             PercentageToReceive = totalItemAmount,
                             ItemId = item.Value.ResultItem
                            } );
                  }
                }

                


                }
               
                
               thirdDropResult 
               fourthDropResult 
               fifthDropResult  
               sixthDropResult  
               seventhDropResult
              






               return true;
        }

  public static DropResultItems CycleThroughDropTables(GetRandomResultTablesResult RandomTables )  {
      var dropresult = new DropResultItems  { 
   };
foreach ( var eachResultTable in RandomTables.Tables.Values)
{ 

//first list of nodes
//total weight amount of first
    foreach(var tableOrItem in eachResultTable.Nodes)
    {
        dropresult.TotalWeight +=  tableOrItem.Weight;
        if (tableOrItem.ResultItemType  == 0) 
        {
                 dropresult.ItemNodes.Add(eachResultTable.TableId,tableOrItem);
        }

        else 
        {  
            
            dropresult.DropTableNodes.Add(eachResultTable.TableId,tableOrItem);
 
        }
    }
    
}

return dropresult;      
    }


10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Seth Du avatar image
Seth Du answered

I believe you need to iterate the nodes, and there is no need to predefine 7 items. Here is an example(I am using Unity, you may modify and add null value check):

var playfabJSON = PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer);

PlayFabServerAPI.GetRandomResultTables(

    new PlayFab.ServerModels.GetRandomResultTablesRequest
    {
        CatalogVersion = "CharacterClasses",
        TableIDs = new List<string> { "DT_CrystalContainer" }
    },
    success => {

        Dictionary<string, float> result = new Dictionary<string, float>();

        foreach (var item in success.Tables["DT_CrystalContainer"].Nodes)
        {
            result[item.ResultItem] = item.Weight / 100f;
        }

        print(playfabJSON.SerializeObject(result));
    },
    failed => { print(failed.GenerateErrorReport()); });

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

duartedd avatar image duartedd commented ·

Hey SethDu - thanks! looks good - think that only iterates through the table of the item that is requested though.
I need to lets say someone wants to see what is possible in the weapon chest - show a subset of 5 items out of the drop table but the drop table has a drop table within a drop table within a drop table (lets say - common weapon drop table ->tier1 drop table -> weaponchestdroptable - the item resides in common weapon drop table

i have to iterate through the first drop table to find the percentage of chance to get to the next drop table and find that chance to find the next drop table chance then i use the weight and divide by the total weight of all items actually since I don't have them equaling up to 100 of all the items in that drop table


Then times everything together to get item drop chance

I did get it to work and probably could have definitely been written better - took me around 500 lines of code though for the functions side.

Was thinking it would be nice to have an api call or an option within the getrandomresult that would return the result of items and their percentages through the entire stack rather then just that specific drop table.

thanks again!

Daniel

0 Likes 0 ·
Seth Du avatar image Seth Du ♦ duartedd commented ·

Recursively calling API in Azure Function is not a good Idea because it will easily exceed the runtime limit. As it is actually a one-time job, my suggestion is to add this main drop table into a bundle or container and store calculated drop details in CUSTOM DATA as a static value.

In the common scenario, clients need to call GetCatalogItems from time to time (or less frequently), and you may cache the catalog information locally for later reference so that the player won't need to send API to request drop details via API. Catalog usually won't change frequently.

0 Likes 0 ·
duartedd avatar image duartedd Seth Du ♦ commented ·

because I already have the 6 or so layer drop tables with like 50 drop tables setup with different layers of the drops tables - what i ended up doing was kind of what you stated. I query the drop tables where containers/bundles use and the result goes into a title data of 'lootprobabilitylist' and that has a list of items with their chance drops for that table within the array list. So I really only do the query once for each drop table to populate the title data and that is it

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.