Refractor approach to special creature DNA loot

The point of this change is to get rid of all of the unnecessary DNA loot roll chance scripts located at script.item.dna.* and instead replace it with a proper implementation. There are 2 new columns in creatures.tab (dnaChancePct and dnaItemName) which are parsed during createCreature() and loot events to properly roll for loot chance of the DNA and to add it to a creature's inventory container.
This commit is contained in:
AconiteX
2021-07-13 02:29:08 -04:00
parent 6366bded0e
commit 8a35cd9085
12 changed files with 6788 additions and 7004 deletions
File diff suppressed because it is too large Load Diff
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class barbed_quenker_dna extends script.base_script
{
public barbed_quenker_dna()
{
}
public static final String BARBED_QUENKER_DNA_LOOT_ITEM = "item_barbed_quenker_dna";
public static final int BARBED_QUENKER_DNA_LOOT_CHANCE = 5;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > BARBED_QUENKER_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(BARBED_QUENKER_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class cracktooth_dna extends script.base_script
{
public cracktooth_dna()
{
}
public static final String CRACKTOOTH_NARGLATCH_DNA_LOOT_ITEM = "item_cs_dna_mutated_narglatch";
public static final int CRACKTOOTH_NARGLATCH_DNA_LOOT_CHANCE = 15;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > CRACKTOOTH_NARGLATCH_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(CRACKTOOTH_NARGLATCH_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class hawkbat_dna extends script.base_script
{
public hawkbat_dna()
{
}
public static final String HAWK_BAT_DNA_LOOT_ITEM = "item_cs_dna_hawk_bat";
public static final int HAWK_BAT_DNA_LOOT_CHANCE = 15;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > HAWK_BAT_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(HAWK_BAT_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class razor_angler_dna extends script.base_script
{
public razor_angler_dna()
{
}
public static final String RAZOR_ANGLER_DNA_LOOT_ITEM = "item_razor_angler_dna";
public static final int RAZOR_ANGLER_DNA_LOOT_CHANCE = 15;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > RAZOR_ANGLER_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(RAZOR_ANGLER_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class spider_consort_dna extends script.base_script
{
public spider_consort_dna()
{
}
public static final String SPIDER_CONSORT_DNA_LOOT_ITEM = "item_spiderclan_consort_dna";
public static final int SPIDER_CONSORT_DNA_LOOT_CHANCE = 15;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > SPIDER_CONSORT_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(SPIDER_CONSORT_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class spider_queen_dna extends script.base_script
{
public spider_queen_dna()
{
}
public static final String SPIDER_QUEEN_DNA_LOOT_ITEM = "item_spiderclan_queen_dna";
public static final int SPIDER_QUEEN_DNA_LOOT_CHANCE = 15;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > SPIDER_QUEEN_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(SPIDER_QUEEN_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class unstable_nexu_dna extends script.base_script
{
public unstable_nexu_dna()
{
}
public static final String UNSTABLE_NEXU_DNA_LOOT_ITEM = "item_cs_dna_nexu";
public static final int UNSTABLE_NEXU_DNA_LOOT_CHANCE = 15;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > UNSTABLE_NEXU_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(UNSTABLE_NEXU_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class unstable_reek_dna extends script.base_script
{
public unstable_reek_dna()
{
}
public static final String UNSTABLE_REEK_DNA_LOOT_ITEM = "item_cs_dna_reek";
public static final int UNSTABLE_REEK_DNA_LOOT_CHANCE = 15;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > UNSTABLE_REEK_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(UNSTABLE_REEK_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -1,28 +0,0 @@
package script.item.dna;
import script.dictionary;
import script.library.static_item;
import script.library.utils;
import script.obj_id;
public class vorpal_durni_dna extends script.base_script
{
public vorpal_durni_dna()
{
}
public static final String VORPAL_DURNI_DNA_LOOT_ITEM = "item_vorpal_durni_dna";
public static final int VORPAL_DURNI_DNA_LOOT_CHANCE = 2;
public int aiCorpsePrepared(obj_id self, dictionary params) throws InterruptedException
{
int chanceDna = rand(1, 100);
if (chanceDna > VORPAL_DURNI_DNA_LOOT_CHANCE)
{
return SCRIPT_CONTINUE;
}
obj_id inv = utils.getInventoryContainer(self);
obj_id dna = static_item.createNewItemFunction(VORPAL_DURNI_DNA_LOOT_ITEM, inv);
return SCRIPT_CONTINUE;
}
}
@@ -746,6 +746,13 @@ public class create extends script.base_script
setObjVar(creature, "loot.lootTable", strLootTable);
setObjVar(creature, "loot.numItems", intItems);
}
final float dnaLootPercentageChance = creatureDict.getFloat("dnaChancePct");
final String dnaLootItemName = creatureDict.getString("dnaItemName");
if(dnaLootPercentageChance > 0 && dnaLootItemName != null && static_item.isStaticItem(dnaLootItemName))
{
setObjVar(creature, loot.OBJVAR_DNA_LOOT_CHANCE, dnaLootPercentageChance);
setObjVar(creature, loot.OBJVAR_DNA_LOOT_ITEM_NAME, dnaLootItemName);
}
if (!initializeArmor(creature, creatureDict, dataTableGetInt(STAT_BALANCE_TABLE, armorLevel - 1, diffClassName + "Armor")))
{
LOG("create", "Unable to initialize armor on " + creatureName + "(" + creature + ")");
@@ -120,6 +120,8 @@ public class loot extends script.base_script
public static final String OBJVAR_RLS_LAST_LOOT_TIME = "loot.rls.lastChestAwardTime";
public static final String OBJVAR_RLS_LAST_LOOT_LOCATION = "loot.rls.lastLootedLocation";
public static final String OBJVAR_RLS_LAST_LOOT_CHEST = "loot.rls.lastLootedChest";
public static final String OBJVAR_DNA_LOOT_CHANCE = "loot.dnaLootChance";
public static final String OBJVAR_DNA_LOOT_ITEM_NAME = "loot.dnaLootItemName";
public static boolean addLoot(obj_id target) throws InterruptedException
{
@@ -1127,6 +1129,7 @@ public class loot extends script.base_script
String strTable = getStringObjVar(objCreature, "loot.lootTable");
int intLevel = getIntObjVar(objCreature, "intCombatDifficulty");
int intItems = getIntObjVar(objCreature, "loot.numItems");
rollForSpecialDnaLoot(objCreature, objContainer);
return makeLootInContainer(objContainer, strTable, intItems, intLevel);
}
public static boolean setupLootItems(obj_id objCreature, int intItems) throws InterruptedException
@@ -1139,6 +1142,7 @@ public class loot extends script.base_script
}
String strTable = getStringObjVar(objCreature, "loot.lootTable");
int intLevel = getIntObjVar(objCreature, "intCombatDifficulty");
rollForSpecialDnaLoot(objCreature, objContainer);
return makeLootInContainer(objContainer, strTable, intItems, intLevel);
}
public static boolean makeLootInContainer(obj_id objContainer, String strTable, int intItems, int intLevel) throws InterruptedException
@@ -1161,7 +1165,7 @@ public class loot extends script.base_script
}
if ((strLootTypes == null) || (strLootTypes.length == 0))
{
return boolMadeLoot;
return false;
}
for (int intI = 0; intI < intItems; intI++)
{
@@ -2604,4 +2608,29 @@ public class loot extends script.base_script
return chest;
}
/**
* Rolls for granting special DNA loot during loot grant process.
*
* This replaces a series of scripts that were at item.dna.* for a more
* generic process. Specify the DNA roll chance and DNA roll item name
* in the creatures.iff data table, which are added as ObjVars if they
* are valid during the create.createCreature() process.
*
* @param creature the creature who will hold the loot items
* @param container the container of that creature
*/
public static void rollForSpecialDnaLoot(obj_id creature, obj_id container) throws InterruptedException
{
if(isIdValid(creature) && isIdValid(container))
{
if(hasObjVar(creature, OBJVAR_DNA_LOOT_CHANCE) && hasObjVar(creature, OBJVAR_DNA_LOOT_ITEM_NAME))
{
if(rand(1, 100) > getFloatObjVar(creature, OBJVAR_DNA_LOOT_CHANCE))
{
static_item.createNewItemFunction(getStringObjVar(creature, OBJVAR_DNA_LOOT_ITEM_NAME), container);
}
}
}
}
}