f372b9ccb5
Completed a basic version of configurable dungeon chains. Almost all of the final funcionality is present. However, the configuration is hardcoded at the moment, not read from a file. This was done for testing purposes. I'll add reading from config files soon. Dungeon packs are partially implemented. Built-in and custom dungeons are currently thrown into the default pack, Ruins. The next step is to generalize the dungeon registration code in DungeonHelper so that we can detect dungeon packs, read their config files, and register dungeons with their corresponding pack. dd-export will need to support packs as well. dd-rift will have issues dealing with duplicate dungeon names across packs, but this isn't a major concern and can be dealt with in the long term.
67 lines
1.9 KiB
Java
67 lines
1.9 KiB
Java
package StevenDimDoors.mod_pocketDim.dungeon.pack;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
|
|
import StevenDimDoors.mod_pocketDim.util.WeightedContainer;
|
|
|
|
public class DungeonChainRule
|
|
{
|
|
private final int[] condition;
|
|
private final ArrayList<WeightedContainer<DungeonType>> products;
|
|
|
|
public DungeonChainRule(DungeonChainRuleDefinition source, HashMap<String, DungeonType> nameToTypeMapping)
|
|
{
|
|
ArrayList<String> conditionNames = source.getCondition();
|
|
ArrayList<WeightedContainer<String>> productNames = source.getProducts();
|
|
|
|
//Obtain the IDs of dungeon types in reverse order. Reverse order makes comparing against chain histories easy.
|
|
condition = new int[conditionNames.size()];
|
|
for (int src = 0, dst = condition.length - 1; src < condition.length; src++, dst--)
|
|
{
|
|
condition[dst] = nameToTypeMapping.get(conditionNames.get(src)).ID;
|
|
}
|
|
products = new ArrayList<WeightedContainer<DungeonType>>(productNames.size());
|
|
for (WeightedContainer<String> product : productNames)
|
|
{
|
|
products.add(new WeightedContainer<DungeonType>(nameToTypeMapping.get(product.getData()), product.itemWeight ));
|
|
}
|
|
}
|
|
|
|
public int length()
|
|
{
|
|
return condition.length;
|
|
}
|
|
|
|
public boolean evaluate(int[] typeHistory)
|
|
{
|
|
if (typeHistory.length >= condition.length)
|
|
{
|
|
for (int k = 0; k < condition.length; k++)
|
|
{
|
|
if (condition[k] != 0 && typeHistory[k] != condition[k])
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public ArrayList<WeightedContainer<DungeonType>> products()
|
|
{
|
|
//Create a deep copy of the internal list of products. That way, if the list is modified externally,
|
|
//it won't affect the reference copy inside this rule.
|
|
ArrayList<WeightedContainer<DungeonType>> copy = new ArrayList<WeightedContainer<DungeonType>>(products.size());
|
|
for (WeightedContainer<DungeonType> container : products)
|
|
{
|
|
copy.add(container.clone());
|
|
}
|
|
|
|
return copy;
|
|
}
|
|
}
|