Added pen & paper & rafhot's expanded creature abilities

Added pen & paper & rafhot's expanded creature abilities
This commit is contained in:
Jaysyn904
2023-06-25 01:31:42 -04:00
parent 7debaedd2a
commit d4680a7df3
560 changed files with 22117 additions and 27806 deletions

Binary file not shown.

View File

@@ -0,0 +1,143 @@
//#include "inc_array"
#include "nwnx_time"
// nwnx_data also includes inc_array, so don't double dip.
#include "nwnx_data"
void Log(string msg)
{
WriteTimestampedLogEntry(msg);
}
void TestArrayOnModule()
{
string array = "test";
// By default, temporary arrays are created on the module.
Array_PushBack_Str(array, "BItem1");
Array_PushBack_Str(array, "AItem2");
Array_PushBack_Str(array, "AItem3");
Array_PushBack_Str(array, "BItem2");
Array_Debug_Dump(array, "After first load");
int foo = Array_Find_Str(array, "AItem3");
Log("Found element AItem3 at index = " + IntToString(foo));
Array_Set_Str(array, 2, "Suck it up...");
Array_Debug_Dump(array, "After set 2 = 'Suck it up...'");
Array_Erase(array, 1);
Array_Debug_Dump(array, "After delete 1");
Array_PushBack_Str(array, "MItem1");
Array_PushBack_Str(array, "QItem2");
Array_PushBack_Str(array, "NItem3");
Array_PushBack_Str(array, "KItem2");
Array_Debug_Dump(array, "After add more");
Array_SortAscending(array);
Array_Debug_Dump(array, "After sort");
Array_Shuffle(array);
Array_Debug_Dump(array, "After shuffle");
Log( (Array_Contains_Str(array, "NItem3")) ? "Passed.. found it" : "Failed.. should have found it" );
Log( (Array_Contains_Str(array, "KItem2")) ? "Passed.. found it" : "Failed.. should have found it" );
Log( (Array_Contains_Str(array, "xxxxxx")) ? "Failed.. not found" : "Passed.. should not exist" );
Array_Clear(array);
// Load up the array with 100 entries
int i;
struct NWNX_Time_HighResTimestamp b;
b = NWNX_Time_GetHighResTimeStamp();
Log("Start Time: " + IntToString(b.seconds) + "." + IntToString(b.microseconds));
for (i=0; i<1000; i++)
{
Array_PushBack_Str(array, IntToString(d100()) + " xxx " + IntToString(i));
}
b = NWNX_Time_GetHighResTimeStamp();
Log("Loaded 1000: " + IntToString(b.seconds) + "." + IntToString(b.microseconds));
Array_Shuffle(array);
b = NWNX_Time_GetHighResTimeStamp();
Log("Shuffled 1000: " + IntToString(b.seconds) + "." + IntToString(b.microseconds));
for (i=5; i<995; i++)
{
// Delete the third entry a bunch of times
Array_Erase(array, 3);
}
b = NWNX_Time_GetHighResTimeStamp();
Log("Delete ~990: " + IntToString(b.seconds) + "." + IntToString(b.microseconds));
Array_Debug_Dump(array, "After mass insert/delete");
}
void TestArrayOnChicken()
{
string array="chicken";
// Let's create an array "on" our favorite creature: the deadly nw_chicken
// Note - arrays aren't really attached to the item, but the module, and they
// are tagged with the objects string representation.
object oCreature = CreateObject(OBJECT_TYPE_CREATURE, "nw_chicken", GetStartingLocation());
if (!GetIsObjectValid(oCreature))
{
Log("NWNX_Creature test: Failed to create creature");
return;
}
Array_PushBack_Str(array, "BItem1", oCreature);
Array_PushBack_Str(array, "AItem2", oCreature);
Array_PushBack_Str(array, "AItem3", oCreature);
Array_PushBack_Str(array, "BItem2", oCreature);
Array_Debug_Dump(array, "After Chicken array load", oCreature);
}
void TestNWNXArray()
{
Log("");
Log("Start NWNX_Data test.");
string array = "test2";
NWNX_Data_Array_PushBack_Str(GetModule(), array, "XItem1");
NWNX_Data_Array_PushBack_Str(GetModule(), array, "ZItem2");
NWNX_Data_Array_PushBack_Str(GetModule(), array, "ZItem3");
NWNX_Data_Array_PushBack_Str(GetModule(), array, "XItem2");
Array_Debug_Dump(array, "After first load");
int foo = NWNX_Data_Array_Find_Str(GetModule(), array, "ZItem3");
Log("Found element AItem3 at index = " + IntToString(foo));
NWNX_Data_Array_Set_Str(GetModule(), array, 2, "Suck it up...");
Array_Debug_Dump(array, "After set 2 = 'Suck it up...'");
NWNX_Data_Array_Erase(NWNX_DATA_TYPE_STRING, GetModule(), array, 1);
Array_Debug_Dump(array, "After delete 1");
NWNX_Data_Array_PushBack_Str(GetModule(), array, "MItem1");
NWNX_Data_Array_PushBack_Str(GetModule(), array, "QItem2");
NWNX_Data_Array_PushBack_Str(GetModule(), array, "NItem3");
NWNX_Data_Array_PushBack_Str(GetModule(), array, "KItem2");
Array_Debug_Dump(array, "After add more");
NWNX_Data_Array_SortAscending(NWNX_DATA_TYPE_STRING, GetModule(), array);
Array_Debug_Dump(array, "After sort");
}
// Uncomment and assign to some event click.
/* */
void main()
{
Log("Start");
TestArrayOnModule();
TestArrayOnChicken();
TestNWNXArray();
}
/* */

View File

@@ -0,0 +1,504 @@
#include "nwnx_regex"
/// @addtogroup data Data
/// @brief Provides a number of data structures for NWN code to use (simulated arrays)
/// @{
/// @file nwnx_data.nss
const int INVALID_INDEX = -1;
const int TYPE_FLOAT = 0;
const int TYPE_INTEGER = 1;
const int TYPE_OBJECT = 2;
const int TYPE_STRING = 3;
/// @defgroup data_array_at Array At
/// @brief Returns the element at the index.
/// @ingroup data
/// @param obj The object.
/// @param tag The tag.
/// @param index The index.
/// @return The element of associated type.
/// @{
string Array_At_Str(string tag, int index, object obj=OBJECT_INVALID);
float Array_At_Flt(string tag, int index, object obj=OBJECT_INVALID);
int Array_At_Int(string tag, int index, object obj=OBJECT_INVALID);
object Array_At_Obj(string tag, int index, object obj=OBJECT_INVALID);
/// @}
/// Clears the entire array, such that size==0.
void Array_Clear(string tag, object obj=OBJECT_INVALID);
/// @defgroup data_array_contains Array Contains
/// @brief Checks if array contains the element.
/// @ingroup data
/// @param obj The object.
/// @param tag The tag.
/// @param element The element.
/// @return TRUE if the collection contains the element.
/// @{
int Array_Contains_Flt(string tag, float element, object obj=OBJECT_INVALID);
int Array_Contains_Int(string tag, int element, object obj=OBJECT_INVALID);
int Array_Contains_Obj(string tag, object element, object obj=OBJECT_INVALID);
int Array_Contains_Str(string tag, string element, object obj=OBJECT_INVALID);
/// @}
/// Copies the array of name otherTag over the array of name tag.
void Array_Copy(string tag, string otherTag, object obj=OBJECT_INVALID);
/// Erases the element at index, and shuffles any elements from index size-1 to index + 1 left.
void Array_Erase(string tag, int index, object obj=OBJECT_INVALID);
/// @defgroup data_array_find Array Find
/// @brief Get the index at which the element is located.
/// @ingroup data
/// @param obj The object.
/// @param tag The tag.
/// @param element The element.
/// @return Returns the index at which the element is located, or ARRAY_INVALID_INDEX.
/// @{
int Array_Find_Flt(string tag, float element, object obj=OBJECT_INVALID);
int Array_Find_Int(string tag, int element, object obj=OBJECT_INVALID);
int Array_Find_Obj(string tag, object element, object obj=OBJECT_INVALID);
int Array_Find_Str(string tag, string element, object obj=OBJECT_INVALID);
/// @}
/// @defgroup data_array_insert Array Insert
/// @brief Inserts the element at the index, where size > index >= 0.
/// @ingroup data
/// @param obj The object.
/// @param tag The tag.
/// @param index The index.
/// @param element The element.
/// @{
void Array_Insert_Flt(string tag, int index, float element, object obj=OBJECT_INVALID);
void Array_Insert_Int(string tag, int index, int element, object obj=OBJECT_INVALID);
void Array_Insert_Obj(string tag, int index, object element, object obj=OBJECT_INVALID);
void Array_Insert_Str(string tag, int index, string element, object obj=OBJECT_INVALID);
/// @}
/// @defgroup data_array_pushback Array Pushback
/// @brief Pushes an element to the back of the collection.
/// @remark Functionally identical to an insert at index size-1.
/// @ingroup data
/// @param obj The object.
/// @param tag The tag.
/// @param element The element.
/// @{
void Array_PushBack_Flt(string tag, float element, object obj=OBJECT_INVALID);
void Array_PushBack_Int(string tag, int element, object obj=OBJECT_INVALID);
void Array_PushBack_Obj(string tag, object element, object obj=OBJECT_INVALID);
void Array_PushBack_Str(string tag, string element, object obj=OBJECT_INVALID);
/// @}
/// Resizes the array. If the array is shrinking, it chops off elements at the ned.
void Array_Resize(string tag, int size, object obj=OBJECT_INVALID);
/// Reorders the array such each possible permutation of elements has equal probability of appearance.
void Array_Shuffle(string tag, object obj=OBJECT_INVALID);
/// Returns the size of the array.
int Array_Size(string tag, object obj=OBJECT_INVALID);
/// Sorts the collection based on descending order.
void Array_SortAscending(string tag, int type=TYPE_STRING, object obj=OBJECT_INVALID);
/// Sorts the collection based on descending order.
void Array_SortDescending(string tag, int type=TYPE_STRING, object obj=OBJECT_INVALID);
/// @defgroup data_array_set Array Set
/// @brief Sets the element at the index, where size > index >= 0.
/// @ingroup data
/// @param obj The object.
/// @param tag The tag.
/// @param index The index.
/// @param element The element.
/// @{
void Array_Set_Flt(string tag, int index, float element, object obj=OBJECT_INVALID);
void Array_Set_Int(string tag, int index, int element, object obj=OBJECT_INVALID);
void Array_Set_Obj(string tag, int index, object element, object obj=OBJECT_INVALID);
void Array_Set_Str(string tag, int index, string element, object obj=OBJECT_INVALID);
/// @}
/// @}
//
// Local Utility Functions.
//
string GetTableName(string tag, object obj=OBJECT_INVALID, int bare=FALSE) {
if (obj == OBJECT_INVALID)
obj = GetModule();
string sName = "array_" + ObjectToString(obj) + "_" + tag;
// Remove invalid characters from the tag rather than failing.
string sCleansed = NWNX_Regex_Replace(sName, "[^A-Za-z0-9_\$@#]", "");
// But provide some feedback.
if (GetStringLength(sName) != GetStringLength(sCleansed) || GetStringLength(sCleansed) == 0) {
WriteTimestampedLogEntry("WARNING: Invalid table name detected for array with tag <" + tag + ">. Only characters (a-zA-Z0-9), _, @, $ and # are allowed. Using <"+sCleansed+"> instead.");
}
// BARE returns just the table name with no wrapping.
if (bare == TRUE) {
return sCleansed;
}
// Table name wraped in quotes to avoid token expansion.
return "\""+sCleansed+"\"";
}
string GetTableCreateString(string tag, object obj=OBJECT_INVALID) {
// for simplicity sake, everything is turned into a string. Possible enhancement
// to create specific tables for int/float/whatever.
return "CREATE TABLE IF NOT EXISTS " + GetTableName(tag, obj) + " ( ind INTEGER PRIMARY KEY, value TEXT )";
}
int TableExists(string tag, object obj=OBJECT_INVALID) {
string stmt = "SELECT name FROM sqlite_master WHERE type = 'table' AND name = @tablename;";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindString(sqlQuery, "@tablename", GetTableName(tag, obj, TRUE));
return SqlStep(sqlQuery);
}
void ExecuteStatement(string statement, object obj=OBJECT_INVALID) {
if (obj == OBJECT_INVALID)
obj = GetModule();
// There's no direct "execute this.." everything has to be prepared then executed.
//WriteTimestampedLogEntry("SQL: " + statement);
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), statement);
SqlStep(sqlQuery);
}
void CreateArrayTable(string tag, object obj=OBJECT_INVALID) {
string createStatement = GetTableCreateString(tag, obj);
ExecuteStatement(createStatement, obj);
}
// Get the table row count. Returns -1 on error (0 is a valid number of rows in a table)
int GetRowCount(string tag, object obj=OBJECT_INVALID) {
if (obj == OBJECT_INVALID)
obj = GetModule();
CreateArrayTable(tag, obj);
string stmt = "SELECT COUNT(1) FROM " + GetTableName(tag, obj);
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
if ( SqlStep(sqlQuery) ) {
return SqlGetInt(sqlQuery, 0);
}
return -1;
}
////////////////////////////////////////////////////////////////////////////////
// return the value contained in location "index"
string Array_At_Str(string tag, int index, object obj=OBJECT_INVALID)
{
// Just "create if not exists" to ensure it exists for the insert.
CreateArrayTable(tag, obj);
string stmt = "SELECT value FROM " + GetTableName(tag, obj) + " WHERE ind = @ind";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindInt(sqlQuery, "@ind", index);
if ( SqlStep(sqlQuery) ) {
return SqlGetString(sqlQuery, 0);
}
return "";
}
float Array_At_Flt(string tag, int index, object obj=OBJECT_INVALID)
{
string st = Array_At_Str(tag, index, obj);
if (st == "") {
return 0.0;
}
return StringToFloat(st);
}
int Array_At_Int(string tag, int index, object obj=OBJECT_INVALID)
{
string st = Array_At_Str(tag, index, obj);
if (st == "") {
return 0;
}
return StringToInt(st);
}
object Array_At_Obj(string tag, int index, object obj=OBJECT_INVALID)
{
string st = Array_At_Str(tag, index, obj);
if (st == "") {
return OBJECT_INVALID;
}
return StringToObject(st);
}
void Array_Clear(string tag, object obj=OBJECT_INVALID)
{
ExecuteStatement("delete from "+GetTableName(tag, obj), obj);
}
////////////////////////////////////////////////////////////////////////////////
// Return true/value (1/0) if the array contains the value "element"
int Array_Contains_Str(string tag, string element, object obj=OBJECT_INVALID)
{
CreateArrayTable(tag, obj);
string stmt = "SELECT COUNT(1) FROM "+GetTableName(tag, obj)+" WHERE value = @element";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindString(sqlQuery, "@element", element);
int pos = -1;
if ( SqlStep(sqlQuery) ) {
pos = SqlGetInt(sqlQuery, 0);
if (pos > 0) {
return TRUE;
}
}
return FALSE;
}
int Array_Contains_Flt(string tag, float element, object obj=OBJECT_INVALID)
{
return Array_Contains_Str(tag, FloatToString(element), obj);
}
int Array_Contains_Int(string tag, int element, object obj=OBJECT_INVALID)
{
return Array_Contains_Str(tag, IntToString(element), obj);
}
int Array_Contains_Obj(string tag, object element, object obj=OBJECT_INVALID)
{
return Array_Contains_Str(tag, ObjectToString(element), obj);
}
////////////////////////////////////////////////////////////////////////////////
void Array_Copy(string tag, string otherTag, object obj=OBJECT_INVALID)
{
CreateArrayTable(otherTag, obj);
ExecuteStatement("INSERT INTO "+GetTableName(otherTag, obj)+" SELECT * FROM "+GetTableName(tag, obj), obj);
}
////////////////////////////////////////////////////////////////////////////////
void Array_Erase(string tag, int index, object obj=OBJECT_INVALID)
{
int rows = GetRowCount(tag, obj);
// Silently fail if "index" is outside the range of valid indicies.
if (index >= 0 && index < rows) {
string stmt = "DELETE FROM "+GetTableName(tag, obj)+" WHERE ind = @ind";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindInt(sqlQuery, "@ind", index);
SqlStep(sqlQuery);
stmt = "UPDATE "+GetTableName(tag, obj)+" SET ind = ind - 1 WHERE ind > @ind";
sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindInt(sqlQuery, "@ind", index);
SqlStep(sqlQuery);
}
}
////////////////////////////////////////////////////////////////////////////////
// return the index in the array containing "element"
// if not found, return INVALID_INDEX
int Array_Find_Str(string tag, string element, object obj=OBJECT_INVALID)
{
string stmt = "SELECT IFNULL(MIN(ind),@invalid_index) FROM "+GetTableName(tag, obj)+" WHERE value = @element";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindInt(sqlQuery, "@invalid_index", INVALID_INDEX);
SqlBindString(sqlQuery, "@element", element);
if ( SqlStep(sqlQuery) ) {
return SqlGetInt(sqlQuery, 0);
}
return INVALID_INDEX;
}
int Array_Find_Flt(string tag, float element, object obj=OBJECT_INVALID)
{
return Array_Find_Str(tag, FloatToString(element), obj);
}
int Array_Find_Int(string tag, int element, object obj=OBJECT_INVALID)
{
return Array_Find_Str(tag, IntToString(element), obj);
}
int Array_Find_Obj(string tag, object element, object obj=OBJECT_INVALID)
{
return Array_Find_Str(tag, ObjectToString(element), obj);
}
////////////////////////////////////////////////////////////////////////////////
// Insert a new element into position 'index'. If index is beyond the number of rows in the array,
// this will quietly fail. This could be changed if you wanted to support sparse
// arrays.
void Array_Insert_Str(string tag, int index, string element, object obj=OBJECT_INVALID)
{
int rows = GetRowCount(tag, obj);
// Index numbers are off by one, much like C arrays, so for "rows=10" - values are 0-9.
// It's not unreasonable to fail if you try to insert ind=10 into an array who's indexes
// only go to 9, but I guess it doesn't hurt as long as we're not allowing gaps in
// index numbers.
if (index >= 0 && index <= rows) {
// index is passed as an integer, so immune (as far as I know) to SQL injection for a one shot query.
ExecuteStatement("UPDATE "+GetTableName(tag, obj)+" SET ind = ind + 1 WHERE ind >= "+IntToString(index), obj);
// Element, however, is not.
string stmt = "INSERT INTO "+GetTableName(tag, obj)+" VALUES ( @ind, @element )";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindInt(sqlQuery, "@ind", index);
SqlBindString(sqlQuery, "@element", element);
SqlStep(sqlQuery);
}
}
void Array_Insert_Flt(string tag, int index, float element, object obj=OBJECT_INVALID)
{
Array_Insert_Str(tag, index, FloatToString(element), obj);
}
void Array_Insert_Int(string tag, int index, int element, object obj=OBJECT_INVALID)
{
Array_Insert_Str(tag, index, IntToString(element), obj);
}
void Array_Insert_Obj(string tag, int index, object element, object obj=OBJECT_INVALID)
{
Array_Insert_Str(tag, index, ObjectToString(element), obj);
}
////////////////////////////////////////////////////////////////////////////////
// Insert a new element at the end of the array.
void Array_PushBack_Str(string tag, string element, object obj=OBJECT_INVALID)
{
// If rowCount = 10, indexes are from 0 to 9, so this becomes the 11th entry at index 10.
int rowCount = GetRowCount(tag, obj);
string stmt = "INSERT INTO "+GetTableName(tag, obj)+" VALUES ( @ind, @element )";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindInt(sqlQuery, "@ind", rowCount);
SqlBindString(sqlQuery, "@element", element);
SqlStep(sqlQuery);
}
void Array_PushBack_Flt(string tag, float element, object obj=OBJECT_INVALID)
{
Array_PushBack_Str(tag, FloatToString(element), obj);
}
void Array_PushBack_Int(string tag, int element, object obj=OBJECT_INVALID)
{
Array_PushBack_Str(tag, IntToString(element), obj);
}
void Array_PushBack_Obj(string tag, object element, object obj=OBJECT_INVALID)
{
Array_PushBack_Str(tag, ObjectToString(element), obj);
}
////////////////////////////////////////////////////////////////////////////////
// Cuts the array off at size 'size'. Elements beyond size are removed.
void Array_Resize(string tag, int size, object obj=OBJECT_INVALID)
{
// Int immune to sql injection so easier to one-shot it.
ExecuteStatement("DELETE FROM "+GetTableName(tag, obj)+" WHERE ind >= " + IntToString(size), obj);
}
////////////////////////////////////////////////////////////////////////////////
void Array_Shuffle(string tag, object obj=OBJECT_INVALID)
{
string table = GetTableName(tag, obj, TRUE);
ExecuteStatement("CREATE TABLE " +table+ "_temp AS SELECT ROW_NUMBER() OVER(ORDER BY RANDOM())-1, value FROM " +table, obj);
ExecuteStatement("DELETE FROM " +table , obj);
ExecuteStatement("INSERT INTO " +table+ " SELECT * FROM " +table+ "_temp", obj);
ExecuteStatement("DROP TABLE " +table+ "_TEMP", obj);
}
////////////////////////////////////////////////////////////////////////////////
int Array_Size(string tag, object obj=OBJECT_INVALID)
{
return GetRowCount(tag, obj);
}
////////////////////////////////////////////////////////////////////////////////
// Sort the array by value according to 'direction' (ASC or DESC).
// Supplying a type allows for correct numerical sorting of integers or floats.
void Array_Sort(string tag, string dir="ASC", int type=TYPE_STRING, object obj=OBJECT_INVALID)
{
string table = GetTableName(tag, obj, TRUE);
string direction = GetStringUpperCase(dir);
if ( ! (direction == "ASC" || direction == "DESC") ) {
WriteTimestampedLogEntry("WARNING: Invalid sort direction <" + direction + "> supplied. Defaulting to ASC.");
direction = "ASC";
}
// default orderBy for strings.
string orderBy = "ORDER BY value " + direction;
switch(type) {
case TYPE_INTEGER:
orderBy = "ORDER BY CAST(value AS INTEGER)" + direction;
break;
case TYPE_FLOAT:
orderBy = "ORDER BY CAST(value AS DECIMAL)" + direction;
break;
}
ExecuteStatement("CREATE TABLE " +table+ "_temp AS SELECT ROW_NUMBER() OVER(" + orderBy + ")-1, value FROM " +table, obj);
ExecuteStatement("DELETE FROM " +table, obj);
ExecuteStatement("INSERT INTO " +table+ " SELECT * FROM " +table+ "_temp", obj);
ExecuteStatement("DROP TABLE " +table+ "_temp", obj);
}
void Array_SortAscending(string tag, int type=TYPE_STRING, object obj=OBJECT_INVALID)
{
Array_Sort(tag, "ASC", type, obj);
}
void Array_SortDescending(string tag, int type=TYPE_STRING, object obj=OBJECT_INVALID)
{
Array_Sort(tag, "DESC", type, obj);
}
////////////////////////////////////////////////////////////////////////////////
// Set the value of array index 'index' to a 'element'
// This will quietly eat values if index > array size
void Array_Set_Str(string tag, int index, string element, object obj=OBJECT_INVALID)
{
int rows = GetRowCount(tag, obj);
if (index >= 0 && index <= rows) {
string stmt = "UPDATE "+GetTableName(tag, obj)+" SET value = @element WHERE ind = @ind";
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
SqlBindInt(sqlQuery, "@ind", index);
SqlBindString(sqlQuery, "@element", element);
SqlStep(sqlQuery);
}
}
void Array_Set_Flt(string tag, int index, float element, object obj=OBJECT_INVALID)
{
Array_Set_Str(tag, index, FloatToString(element), obj);
}
void Array_Set_Int(string tag, int index, int element, object obj=OBJECT_INVALID)
{
Array_Set_Str(tag, index, IntToString(element), obj);
}
void Array_Set_Obj(string tag, int index, object element, object obj=OBJECT_INVALID)
{
Array_Set_Str(tag, index, ObjectToString(element), obj);
}
void Array_Debug_Dump(string tag, string title = "xxx", object obj=OBJECT_INVALID) {
if (title != "xxx") {
WriteTimestampedLogEntry("== " + title + " ======================================");
}
WriteTimestampedLogEntry("Table name = " + GetTableName(tag, obj));
string stmt = "SELECT ind, value FROM " + GetTableName(tag, obj);
sqlquery sqlQuery = SqlPrepareQueryObject(GetModule(), stmt);
int ind = -1;
string value = "";
while ( SqlStep(sqlQuery) ) {
ind = SqlGetInt(sqlQuery, 0);
value = SqlGetString(sqlQuery, 1);
WriteTimestampedLogEntry(tag + "[" + IntToString(ind) + "] = " + value);
}
}

View File

@@ -0,0 +1,86 @@
//::///////////////////////////////////////////////
//:: Barbarian Rage
//:: NW_S1_BarbRage
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
The Str and Con of the Barbarian increases,
Will Save are +2, AC -2.
Greater Rage starts at level 15.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Aug 13, 2001
//:://////////////////////////////////////////////
#include "x2_i0_spells"
void main()
{
if(!GetHasFeatEffect(FEAT_BARBARIAN_RAGE))
{
//Declare major variables
int nLevel = GetLevelByClass(CLASS_TYPE_BARBARIAN);
int nIncrease;
int nSave;
effect eDmg;
effect eAtk;
effect eHP;
eDmg = SupernaturalEffect(eDmg);
if (nLevel < 15)
{
nIncrease = 4;
nSave = 2;
//Added to compensate for +12 Cap
eDmg = EffectDamageIncrease(DAMAGE_BONUS_4, DAMAGE_TYPE_BLUDGEONING);
eAtk = EffectAttackIncrease(2);
eAtk = SupernaturalEffect(eAtk);
eHP = EffectTemporaryHitpoints(nLevel * 3);
eHP = SupernaturalEffect(eHP);
}
else
{
nIncrease = 6;
nSave = 3;
//Added to compensate for +12 Cap
eDmg = EffectDamageIncrease(DAMAGE_BONUS_6, DAMAGE_TYPE_BLUDGEONING);
eAtk = EffectAttackIncrease(4);
eAtk = SupernaturalEffect(eAtk);
eHP = EffectTemporaryHitpoints(nLevel * 4);
eHP = SupernaturalEffect(eHP);
}
PlayVoiceChat(VOICE_CHAT_BATTLECRY1);
//Determine the duration by getting the con modifier after being modified
int nCon = 3 + GetAbilityModifier(ABILITY_CONSTITUTION) + nIncrease;
effect eStr = EffectAbilityIncrease(ABILITY_CONSTITUTION, nIncrease);
effect eCon = EffectAbilityIncrease(ABILITY_STRENGTH, nIncrease);
effect eSave = EffectSavingThrowIncrease(SAVING_THROW_WILL, nSave);
effect eAC = EffectACDecrease(2, AC_DODGE_BONUS);
effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
effect eLink = EffectLinkEffects(eCon, eStr);
eLink = EffectLinkEffects(eLink, eSave);
eLink = EffectLinkEffects(eLink, eAC);
eLink = EffectLinkEffects(eLink, eDur);
SignalEvent(OBJECT_SELF, EventSpellCastAt(OBJECT_SELF, SPELLABILITY_BARBARIAN_RAGE, FALSE));
//Make effect extraordinary
eLink = ExtraordinaryEffect(eLink);
effect eVis = EffectVisualEffect(VFX_IMP_IMPROVE_ABILITY_SCORE); //Change to the Rage VFX
if (nCon > 0)
{
//Apply the VFX impact and effects
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, OBJECT_SELF, RoundsToSeconds(nCon));
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, OBJECT_SELF) ;
//This part was added by Guile to offset +12 Cap.
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eAtk, OBJECT_SELF, RoundsToSeconds(nCon));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eDmg, OBJECT_SELF, RoundsToSeconds(nCon));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eHP, OBJECT_SELF, RoundsToSeconds(nCon));
// 2003-07-08, Georg: Rage Epic Feat Handling
CheckAndApplyEpicRageFeats(nCon);
}
}
}

View File

@@ -0,0 +1,425 @@
//::///////////////////////////////////////////////
//:: Bard Song
//:: NW_S2_BardSong
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
This spells applies bonuses to all of the
bard's allies within 30ft for a set duration of
10 rounds.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Feb 25, 2002
//:://////////////////////////////////////////////
//:: Last Updated By: Georg Zoeller Oct 1, 2003
/*
bugfix by Kovi 2002.07.30
- loosing temporary hp resulted in loosing the other bonuses
*/
#include "x0_i0_spells"
void main()
{
if (GetHasEffect(EFFECT_TYPE_SILENCE,OBJECT_SELF))
{
FloatingTextStrRefOnCreature(85764,OBJECT_SELF); // not useable when silenced
return;
}
string sTag = GetTag(OBJECT_SELF);
if (sTag == "x0_hen_dee" || sTag == "x2_hen_deekin")
{
// * Deekin has a chance of singing a doom song
// * same effect, better tune
if (Random(100) + 1 > 80)
{
// the Xp2 Deekin knows more than one doom song
if (d3() ==1 && sTag == "x2_hen_deekin")
{
DelayCommand(0.0, PlaySound("vs_nx2deekM_050"));
}
else
{
DelayCommand(0.0, PlaySound("vs_nx0deekM_074"));
DelayCommand(5.0, PlaySound("vs_nx0deekM_074"));
}
}
}
//Declare major variables
int nLevel = GetLevelByClass(CLASS_TYPE_BARD);
int nRanks = GetSkillRank(SKILL_PERFORM);
int nChr = GetAbilityModifier(ABILITY_CHARISMA);
int nPerform = nRanks;
int nDuration = 10; //+ nChr;
effect eAttack;
effect eDamage;
effect eWill;
effect eFort;
effect eReflex;
effect eHP;
effect eAC;
effect eSkill;
int nAttack;
int nDamage;
int nWill;
int nFort;
int nReflex;
int nHP;
int nAC;
int nSkill;
//Check to see if the caster has Lasting Impression and increase duration.
if(GetHasFeat(870))
{
nDuration *= 10;
}
// lingering song
if(GetHasFeat(424)) // lingering song
{
nDuration += 5;
}
//SpeakString("Level: " + IntToString(nLevel) + " Ranks: " + IntToString(nRanks));
if(nPerform >= 90 && nLevel >= 30)
{
nAttack = 4;
nDamage = 6;
nWill = 4;
nFort = 4;
nReflex = 4;
nHP = 70;
nAC = 5;
nSkill = 20;
}
else if(nPerform >= 85 && nLevel >= 29)
{
nAttack = 4;
nDamage = 5;
nWill = 4;
nFort = 4;
nReflex = 4;
nHP = 65;
nAC = 5;
nSkill = 19;
}
else if(nPerform >= 85 && nLevel >= 28)
{
nAttack = 3;
nDamage = 5;
nWill = 4;
nFort = 4;
nReflex = 4;
nHP = 60;
nAC = 5;
nSkill = 18;
}
else if(nPerform >= 80 && nLevel >= 27)
{
nAttack = 3;
nDamage = 4;
nWill = 3;
nFort = 3;
nReflex = 3;
nHP = 55;
nAC = 5;
nSkill = 17;
}
else if(nPerform >= 75 && nLevel >= 26)
{
nAttack = 3;
nDamage = 3;
nWill = 3;
nFort = 3;
nReflex = 3;
nHP = 50;
nAC = 4;
nSkill = 16;
}
else if(nPerform >= 70 && nLevel >= 25)
{
nAttack = 3;
nDamage = 3;
nWill = 3;
nFort = 3;
nReflex = 3;
nHP = 45;
nAC = 4;
nSkill = 15;
}
else if(nPerform >= 65 && nLevel >= 24)
{
nAttack = 3;
nDamage = 3;
nWill = 3;
nFort = 3;
nReflex = 3;
nHP = 50;
nAC = 4;
nSkill = 14;
}
else if(nPerform >= 60 && nLevel >= 23)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 3;
nReflex = 3;
nHP = 45;
nAC = 4;
nSkill = 13;
}
else if(nPerform >= 60 && nLevel >= 22)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 2;
nReflex = 2;
nHP = 40;
nAC = 4;
nSkill = 12;
}
else if(nPerform >= 55 && nLevel >= 21)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 2;
nReflex = 2;
nHP = 35;
nAC = 4;
nSkill = 10;
}
else if(nPerform >= 50 && nLevel >= 20)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 2;
nReflex = 2;
nHP = 30;
nAC = 3;
nSkill = 9;
}
else if(nPerform >= 45 && nLevel >= 19)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 2;
nReflex = 2;
nHP = 28;
nAC = 3;
nSkill = 8;
}
else if(nPerform >= 40 && nLevel >= 18)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 2;
nReflex = 2;
nHP = 24;
nAC = 3;
nSkill = 6;
}
else if(nPerform >= 35 && nLevel >= 17)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 2;
nReflex = 2;
nHP = 22;
nAC = 3;
nSkill = 5;
}
else if(nPerform >= 30 && nLevel >= 16)
{
nAttack = 2;
nDamage = 3;
nWill = 3;
nFort = 2;
nReflex = 2;
nHP = 20;
nAC = 3;
nSkill = 4;
}
else if(nPerform >= 24 && nLevel >= 15)
{
nAttack = 2;
nDamage = 3;
nWill = 2;
nFort = 2;
nReflex = 2;
nHP = 16;
nAC = 3;
nSkill = 3;
}
else if(nPerform >= 21 && nLevel >= 14)
{
nAttack = 2;
nDamage = 3;
nWill = 1;
nFort = 1;
nReflex = 1;
nHP = 16;
nAC = 2;
nSkill = 2;
}
else if(nPerform >= 18 && nLevel >= 11)
{
nAttack = 2;
nDamage = 2;
nWill = 1;
nFort = 1;
nReflex = 1;
nHP = 8;
nAC = 2;
nSkill = 2;
}
else if(nPerform >= 15 && nLevel >= 8)
{
nAttack = 2;
nDamage = 2;
nWill = 1;
nFort = 1;
nReflex = 1;
nHP = 8;
nAC = 0;
nSkill = 1;
}
else if(nPerform >= 12 && nLevel >= 6)
{
nAttack = 1;
nDamage = 2;
nWill = 1;
nFort = 1;
nReflex = 1;
nHP = 0;
nAC = 0;
nSkill = 1;
}
else if(nPerform >= 9 && nLevel >= 3)
{
nAttack = 1;
nDamage = 2;
nWill = 1;
nFort = 1;
nReflex = 0;
nHP = 0;
nAC = 0;
nSkill = 0;
}
else if(nPerform >= 6 && nLevel >= 2)
{
nAttack = 1;
nDamage = 1;
nWill = 1;
nFort = 0;
nReflex = 0;
nHP = 0;
nAC = 0;
nSkill = 0;
}
else if(nPerform >= 3 && nLevel >= 1)
{
nAttack = 1;
nDamage = 1;
nWill = 0;
nFort = 0;
nReflex = 0;
nHP = 0;
nAC = 0;
nSkill = 0;
}
effect eVis = EffectVisualEffect(VFX_DUR_BARD_SONG);
eAttack = EffectAttackIncrease(nAttack);
eDamage = EffectDamageIncrease(nDamage, DAMAGE_TYPE_BLUDGEONING);
effect eLink = EffectLinkEffects(eAttack, eDamage);
if(nWill > 0)
{
eWill = EffectSavingThrowIncrease(SAVING_THROW_WILL, nWill);
eLink = EffectLinkEffects(eLink, eWill);
}
if(nFort > 0)
{
eFort = EffectSavingThrowIncrease(SAVING_THROW_FORT, nFort);
eLink = EffectLinkEffects(eLink, eFort);
}
if(nReflex > 0)
{
eReflex = EffectSavingThrowIncrease(SAVING_THROW_REFLEX, nReflex);
eLink = EffectLinkEffects(eLink, eReflex);
}
if(nHP > 0)
{
//SpeakString("HP Bonus " + IntToString(nHP));
eHP = EffectTemporaryHitpoints(nHP);
// eLink = EffectLinkEffects(eLink, eHP);
}
if(nAC > 0)
{
eAC = EffectACIncrease(nAC, AC_DODGE_BONUS);
eLink = EffectLinkEffects(eLink, eAC);
}
if(nSkill > 0)
{
eSkill = EffectSkillIncrease(SKILL_ALL_SKILLS, nSkill);
eLink = EffectLinkEffects(eLink, eSkill);
}
effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
eLink = EffectLinkEffects(eLink, eDur);
effect eImpact = EffectVisualEffect(VFX_IMP_HEAD_SONIC);
effect eFNF = EffectVisualEffect(VFX_FNF_LOS_NORMAL_30);
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eFNF, GetLocation(OBJECT_SELF));
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(OBJECT_SELF));
eHP = ExtraordinaryEffect(eHP);
eLink = ExtraordinaryEffect(eLink);
while(GetIsObjectValid(oTarget))
{
if(!GetHasFeatEffect(FEAT_BARD_SONGS, oTarget) && !GetHasSpellEffect(GetSpellId(),oTarget))
{
// * GZ Oct 2003: If we are silenced, we can not benefit from bard song
if (!GetHasEffect(EFFECT_TYPE_SILENCE,oTarget) && !GetHasEffect(EFFECT_TYPE_DEAF,oTarget))
{
if(oTarget == OBJECT_SELF)
{
effect eLinkBard = EffectLinkEffects(eLink, eVis);
eLinkBard = ExtraordinaryEffect(eLinkBard);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLinkBard, oTarget, RoundsToSeconds(nDuration));
if (nHP > 0)
{
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eHP, oTarget, RoundsToSeconds(nDuration));
}
}
else if(GetIsFriend(oTarget))
{
ApplyEffectToObject(DURATION_TYPE_INSTANT, eImpact, oTarget);
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, RoundsToSeconds(nDuration));
if (nHP > 0)
{
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eHP, oTarget, RoundsToSeconds(nDuration));
}
}
}
}
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_COLOSSAL, GetLocation(OBJECT_SELF));
}
}

View File

@@ -0,0 +1,31 @@
//::///////////////////////////////////////////////
//:: Wholeness of Body
//:: NW_S2_Wholeness
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
The monk is able to heal twice his level in HP
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Aug 14, 2001
//:://////////////////////////////////////////////
/*
bugfix by Japetus
- didn't healed the correct amount
*/
void main()
{
//Declare major variables
int nLevel = GetLevelByClass(CLASS_TYPE_MONK)*2;
effect eHeal = EffectHeal(nLevel);
effect eVis = EffectVisualEffect(VFX_IMP_HEALING_M);
SignalEvent(OBJECT_SELF, EventSpellCastAt(OBJECT_SELF, SPELLABILITY_WHOLENESS_OF_BODY, FALSE));
//Apply the VFX impact and effects
ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, OBJECT_SELF);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, OBJECT_SELF);
}

View File

@@ -0,0 +1,102 @@
//::///////////////////////////////////////////////
//:: x1_s2_imbuearrow
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
Imbue Arrow
- creates a fireball arrow that when it explodes
acts like a fireball.
- Must have shortbow or longbow in hand.
GZ: Updated
*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////
#include "X0_I0_SPELLS"
void main()
{
//Declare major variables
object oCaster = OBJECT_SELF;
int nCasterLvl = GetLevelByClass(CLASS_TYPE_ARCANE_ARCHER,oCaster); // * get a bonus of +10 to make this useful for arcane archer
int nDamage;
float fDelay;
effect eExplode = EffectVisualEffect(VFX_FNF_FIREBALL);
effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);
effect eDam;
//Get the spell target location as opposed to the spell target.
location lTarget = GetSpellTargetLocation();
//Limit Caster level for the purposes of damage
if (nCasterLvl > 16)
{
nCasterLvl = 16 + ((nCasterLvl-10)/2); // add some epic progression of 1d6 per 2 levels after 10
}
else // * preserve minimum damage of 10d6
{
nCasterLvl = 10;
}
object oTarget = GetSpellTargetObject();
// * GZ: Add arrow damage if targeted on creature...
if (GetIsObjectValid(oTarget ))
{
if (spellsIsTarget(oTarget, SPELL_TARGET_SELECTIVEHOSTILE, OBJECT_SELF))
{
int nTouch = TouchAttackRanged(oTarget, TRUE);
if (nTouch > 0)
{
nDamage = ArcaneArcherDamageDoneByBow(nTouch ==2);
int nBonus = ArcaneArcherCalculateBonus() ;
effect ePhysical = EffectDamage(nDamage, DAMAGE_TYPE_PIERCING,IPGetDamagePowerConstantFromNumber(nBonus));
effect eMagic = EffectDamage(nBonus, DAMAGE_TYPE_MAGICAL);
ApplyEffectToObject(DURATION_TYPE_INSTANT, ePhysical, oTarget);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eMagic, oTarget);
}
}
}
//Apply the fireball explosion at the location captured above.
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eExplode, lTarget);
//Declare the spell shape, size and the location. Capture the first target object in the shape.
oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lTarget, TRUE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR | OBJECT_TYPE_PLACEABLE);
//Cycle through the targets within the spell shape until an invalid object is captured.
while (GetIsObjectValid(oTarget))
{
if(spellsIsTarget(oTarget, SPELL_TARGET_SELECTIVEHOSTILE, OBJECT_SELF) == TRUE)
{
//Fire cast spell at event for the specified target
SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, GetSpellId(), TRUE));
//Get the distance between the explosion and the target to calculate delay
fDelay = GetDistanceBetweenLocations(lTarget, GetLocation(oTarget))/20;
if (!MyResistSpell(OBJECT_SELF, oTarget, fDelay))
{
//Roll damage for each target
nDamage = d6(nCasterLvl);
//Resolve metamagic
//Adjust the damage based on the Reflex Save, Evasion and Improved Evasion.
nDamage = GetReflexAdjustedDamage(nDamage, oTarget, GetSpellSaveDC(), SAVING_THROW_TYPE_FIRE);
//Set the damage effect
eDam = EffectDamage(nDamage, DAMAGE_TYPE_FIRE);
if(nDamage > 0)
{
// Apply effects to the currently selected target.
DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget));
//This visual effect is applied to the target object not the location as above. This visual effect
//represents the flame that erupts on the target not on the ground.
DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget));
}
}
}
//Select the next target within the spell shape.
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lTarget, TRUE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR | OBJECT_TYPE_PLACEABLE);
}
}