mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-29 23:15:55 -04:00
281 lines
9.0 KiB
Plaintext
281 lines
9.0 KiB
Plaintext
include library.ai_lib;
|
|
include library.battlefield;
|
|
include library.bio_engineer;
|
|
include library.buff;
|
|
include library.create;
|
|
include library.dot;
|
|
include library.features;
|
|
include library.hq;
|
|
include library.locations;
|
|
include library.mustafar;
|
|
include library.pclib;
|
|
include library.pet_lib;
|
|
include library.prose;
|
|
include library.player_structure;
|
|
include library.regions;
|
|
include library.skill;
|
|
include library.utils;
|
|
include library.space_crafting;
|
|
include library.space_transition;
|
|
include library.weapons;
|
|
include java.util.StringTokenizer;
|
|
|
|
|
|
const string CREATURE_TABLE = "datatables/mob/creatures.iff";
|
|
const string STAT_BALANCE_TABLE = "datatables/mob/stat_balance.iff";
|
|
|
|
const boolean CONST_FLAG_DO_LOGGING = true;
|
|
|
|
messageHandler checkDifficulty()
|
|
{
|
|
|
|
int intRawDifficulty = getLevel(self);
|
|
sendSystemMessageTestingOnly(self, "getLevel returned "+intRawDifficulty);
|
|
if(intRawDifficulty==0)
|
|
{
|
|
sendSystemMessageTestingOnly(self, "you lost your difficulty!");
|
|
deltadictionary dctScriptVars = self.getScriptVars();
|
|
sendSystemMessageTestingOnly(self, "Scriptvars are "+dctScriptVars.toString());
|
|
|
|
}
|
|
messageTo(self, "checkDifficulty", null, 3, false);
|
|
return SCRIPT_CONTINUE;
|
|
|
|
|
|
}
|
|
|
|
void debugLogging(string section, string message)
|
|
{
|
|
if (CONST_FLAG_DO_LOGGING)
|
|
LOG("working/balancetest/"+section, message);
|
|
}
|
|
|
|
trigger OnHearSpeech(obj_id objSpeaker, string strText)
|
|
{
|
|
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> Enter");
|
|
|
|
if(objSpeaker!=self)
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 1");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if(strText.indexOf("b ") < 0)
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 2 - index is: "+strText.indexOf("b "));
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
StringTokenizer st = new StringTokenizer(strText);
|
|
int numArgs = st.countTokens();
|
|
string actionUnlock = st.nextToken();
|
|
string actionName = st.nextToken();
|
|
|
|
//sendSystemMessageTestingOnly(self, "Token 1 = "+actionUnlock+" Token 2 = "+actionName+" num of args is: "+numArgs);
|
|
if(actionName.equals("help"))
|
|
{
|
|
sendSystemMessageTestingOnly(self, "REMINDER: key phrases for balancetest are: or 'b wipe' or 'b spawn <creatureName>' or 'b newlevel <level>'");
|
|
sendSystemMessageTestingOnly(self, " 'b clev <creature level>' or 'b wdam <mindamage> <maxdamage>' (can enter just one damage value to set both same)' ");
|
|
sendSystemMessageTestingOnly(self, " 'b newlevel <newlevel> will mod all current and following creatures. A <newlevel> value of 0 will remove a stored level delta variable ");
|
|
}
|
|
else if(actionName.equals("clev"))
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 3");
|
|
if(numArgs < 3)
|
|
{
|
|
sendSystemMessageTestingOnly(self, "You've got to have at least TWO arguments to spawn a creature 'b clev <creature level> ");
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 4");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
string levelStr = st.nextToken();
|
|
int level = utils.stringToInt(levelStr);
|
|
|
|
sendSystemMessageTestingOnly(self, "creature level selected: "+level);
|
|
|
|
//pick a creature
|
|
dictionary creatureDict = null;
|
|
resizeable string[] validCreatureNames = new string[0];
|
|
int[] creatureTabLevels = dataTableGetIntColumn(CREATURE_TABLE, "BaseLevel");
|
|
for (int i = 0; i < creatureTabLevels.length; i++)
|
|
{
|
|
if(creatureTabLevels[i] == level)
|
|
{
|
|
creatureDict = dataTableGetRow( CREATURE_TABLE, i );
|
|
float aggressiveness = creatureDict.getFloat("aggressive");
|
|
string creatureName = creatureDict.getString("creatureName");
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> Checking a creature: "+creatureName+" its aggressiveness is: "+aggressiveness);
|
|
if(aggressiveness > 0.0)
|
|
utils.addElement(validCreatureNames, creatureName);
|
|
}
|
|
}
|
|
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> TOTAL MATCHES FOUND IS: "+validCreatureNames.length );
|
|
|
|
if (validCreatureNames.length > 0)
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 7");
|
|
int matchNumber = 1;
|
|
if (validCreatureNames.length>1)
|
|
matchNumber=rand(1,validCreatureNames.length);
|
|
creatureDict = dataTableGetRow( CREATURE_TABLE, validCreatureNames[matchNumber-1] );
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessageTestingOnly(self, "no matches in creatures.tab found for level: "+level);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
if ( creatureDict == null )
|
|
{
|
|
sendSystemMessageTestingOnly(self, "no creatures found at level: "+level);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else
|
|
sendSystemMessageTestingOnly(self, "creature selected for spawn is: "+creatureDict.getString("creatureName"));
|
|
|
|
string creatureName = creatureDict.getString("creatureName");
|
|
utils.setScriptVar(self,"clev_creature",creatureName);
|
|
utils.setScriptVar(self,"clev_creature_level",level);
|
|
|
|
}
|
|
else if(actionName.equals("spawn"))
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 8");
|
|
if(!utils.hasScriptVar(self,"clev_creature"))
|
|
{
|
|
sendSystemMessageTestingOnly(self, "no you haven't selected a creature to spawn");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
int creaturelevel = utils.getIntScriptVar(self,"clev_creature_level");
|
|
string creatureName = utils.getStringScriptVar(self,"clev_creature");
|
|
sendSystemMessageTestingOnly(self, "we're going to try to spawn the level "+creaturelevel+" creature, the "+ creatureName);
|
|
int newCreatureLevel = 0;
|
|
if (utils.hasScriptVar(self,"newCreatureLevel"))
|
|
{
|
|
newCreatureLevel = utils.getIntScriptVar(self,"newCreatureLevel");
|
|
sendSystemMessageTestingOnly(self, " and going to re-level the creature to be "+newCreatureLevel);
|
|
}
|
|
int numCreatures = 1;
|
|
if(numArgs == 3)
|
|
{
|
|
string numberOfCreaturesStr = st.nextToken();
|
|
int numberOfCreatures = utils.stringToInt(numberOfCreaturesStr);
|
|
if (numberOfCreatures == 9)
|
|
numCreatures = rand(1,10);
|
|
else
|
|
numCreatures = numberOfCreatures;
|
|
}
|
|
obj_id[] spawnedCreatures = new obj_id[numCreatures];
|
|
|
|
//spawn location
|
|
location here = getLocation(self);
|
|
for (int i = 0; i < numCreatures; i++)
|
|
{
|
|
location spawnLoc = locations.getGoodLocationAroundLocation(here, 1f, 1f, 4f, 4f);
|
|
if ( spawnLoc == null )
|
|
{
|
|
sendSystemMessageTestingOnly(self, " spawnLoc was NULL ");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
obj_id mob = create.createCreature( creatureName, spawnLoc, creaturelevel, true, false );
|
|
if(!isIdValid(mob))
|
|
sendSystemMessageTestingOnly(self, "invalid objid on the creature we just tried to spawn. OH NO!");
|
|
else
|
|
{
|
|
spawnedCreatures[i] = mob;
|
|
if(newCreatureLevel > 0)
|
|
reLevelMob(mob, newCreatureLevel);
|
|
}
|
|
}
|
|
if (spawnedCreatures != null)
|
|
utils.setScriptVar(self,"spawnedCreatures",spawnedCreatures);
|
|
}
|
|
else if(actionName.equals("wdam"))
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 9");
|
|
//weapon damage here
|
|
string damageStr = st.nextToken();
|
|
int damageValue = utils.stringToInt(damageStr);
|
|
|
|
|
|
obj_id weapon = getCurrentWeapon(self);
|
|
if (!isIdValid(weapon))
|
|
sendSystemMessageTestingOnly(self, "bad weapon - objId was: "+weapon);
|
|
if (getWeaponType(weapon) != WEAPON_TYPE_UNARMED)
|
|
{
|
|
setWeaponMinDamage( weapon, damageValue);
|
|
setWeaponMaxDamage( weapon, damageValue);
|
|
weapons.setWeaponData(weapon);
|
|
}
|
|
}
|
|
else if(actionName.equals("newlevel"))
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 10");
|
|
string reLevelStr = st.nextToken();
|
|
int newLevel = utils.stringToInt(reLevelStr);
|
|
|
|
if (newLevel == 0)
|
|
{
|
|
if (utils.hasScriptVar(self,"newCreatureLevel"))
|
|
{
|
|
sendSystemMessageTestingOnly(self, "Removed existing creature level delta value");
|
|
utils.removeScriptVar(self,"newCreatureLevel");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(utils.setScriptVar(self,"newCreatureLevel", newLevel))
|
|
sendSystemMessageTestingOnly(self, "All creatures spawned will now be set to level "+newLevel);
|
|
}
|
|
|
|
if(utils.hasScriptVar(self,"spawnedCreatures"))
|
|
{
|
|
obj_id[] mobsToRelevel = utils.getObjIdArrayScriptVar(self,"spawnedCreatures");
|
|
int reLeveledMobCounter = 0;
|
|
for (int i = 0; i < mobsToRelevel.length; i++)
|
|
{
|
|
if(isIdValid(mobsToRelevel[i]) && !ai_lib.aiIsDead(mobsToRelevel[i]))
|
|
{
|
|
reLevelMob(mobsToRelevel[i], newLevel);
|
|
reLeveledMobCounter++;
|
|
}
|
|
|
|
}
|
|
if(reLeveledMobCounter > 0)
|
|
sendSystemMessageTestingOnly(self, "A total of "+reLeveledMobCounter+" creatures were re-set to be level "+newLevel);
|
|
}
|
|
}
|
|
else if(actionName.equals("wipe"))
|
|
{
|
|
debugLogging("//// OnHearSpeech: ", "////>>>> 11");
|
|
if(!utils.hasScriptVar(self,"spawnedCreatures"))
|
|
sendSystemMessageTestingOnly(self, "No apparent creature to destroy. Couldn't find obj_id scripvar. OH NO!");
|
|
else
|
|
{
|
|
obj_id[] mobsToDestroy = utils.getObjIdArrayScriptVar(self,"spawnedCreatures");
|
|
for (int i = 0; i < mobsToDestroy.length; i++)
|
|
{
|
|
if(isIdValid(mobsToDestroy[i]))
|
|
destroyObject(mobsToDestroy[i]);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessageTestingOnly(self, "valid trigger phrases for balancetest script are: 'wdam #' for weapon damage value and 'clev #' for creature level.");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
|
|
|
|
void reLevelMob(obj_id mob, int level)
|
|
{
|
|
obj_id self = getSelf();
|
|
string creatureName = utils.getStringScriptVar(self,"clev_creature");
|
|
dictionary creatureDict = utils.dataTableGetRow( CREATURE_TABLE, creatureName );
|
|
create.initializeCreature( mob, creatureName, creatureDict, level );
|
|
return ;
|
|
}
|