Data structure for magical qualities of an item for a game

325 Views Asked by At

Ok, so the issue is I am trying to make a plugin for a game that has a number of item types similar to how diablo 2 has items. Now like diablo 2 the item has a chance of spawning as magical or rare.

If the item is selected to be magical or rare then it can have prefixes and suffixes.

Now the way it selects a prefix/suffix is: To determine the affixes available use the level column in magicprefix.txt and magicsuffix.txt files as the minimum affixlvl(alvl) required. Then it filters the items by maxlevel (a few cannot appear on higher alvl items), and the appropriate item types and excluded types (excluded item types).

I also need to exclude any affixes that have the same group number as an already selected affix. Then to determine the chance of getting an affix I need to sum the frequencies for that particular type (prefix/suffix) and get the chance of that particular affix by affix_frequency/frequency_sum.

This description was taken from: http://diablo2.diablowiki.net/index.php?title=Item_Generation_v1.09&action=edit&section=18

And link to the various txt files that contains prefix/suffix data: https://code.google.com/p/d2spe/source/browse/trunk/data/global/excel/MagicSuffix.txt https://code.google.com/p/d2spe/source/browse/trunk/data/global/excel/MagicPrefix.txt

What is a good data structure to efficiently access the group of prefixes/suffixes based on the affix level?

Currently I am thinking of just statically generating the groupings and just have a giant lookup table, but it would be much better to store them in a data structure that as input takes the affixLevel, item type, and a list of affixes already on the item. The function would essentially return a group of valid affixes that it can choose from.

1

There are 1 best solutions below

3
On

The easiest way of finding the required prefixes/suffixes would probably be to simply create a list of prefixes and suffixes and seperate lists for all the properties that you wish to filter.

For example:

List<String> prefixes = Arrays.asList("Sturdy", "Strong", "Glorious", "Blessed", "Saintly");
List<String> suffixes = Arrays.asList("of Health", "of Protection", "of Absorption", "of Life", "of Warding");

List<Integer> prefixMinLevel = Arrays.asList(1,3,7,22,59);
List<Integer> suffixMinLevel = Arrays.asList(10,4,8,3,11);

List<Integer> prefixType = Arrays.asList(1,1,1,2,2);
List<Integer> suffixType = Arrays.asList(1,2,3,3,3);

And then simply creating a custom method for retrieving a valid list of prefixes/suffixes based on item:

public List<String> getPrefixList(List<String> prevPrefixes, int itemLevel, int itemType){
    List<String> newPrefixes = new ArrayList<String>();

    for(int i = 0; i < prefixes.size(); i++){
        if(!prevPrefixes.contains(prefixes.get(i)))//Filtering out previous prefixes
        if(itemLevel >= prefixMinLevel.get(i))//Checking item level
        if(itemType == prefixType.get(i)){//Checking item type
            newPrefixes.add(prefixes.get(i));
        }
    }

    return newPrefixes;
}

You could probably create a similar function for the suffixes.

You can also add many different criteria, like item rarity and item value. Then simply add those criteria in lists like the example above, and also add them in the getPrefixList() function.