160 lines
5.6 KiB
Plaintext
160 lines
5.6 KiB
Plaintext
#include "nw_o0_itemmaker"
|
|
|
|
const string ITEMS_UPADTE_2DA = "item_updates";
|
|
const string ITEM_COLUMN_2DA = "ITEM";
|
|
const string REPLACEMENT_COLUMN_2DA = "REPLACEMENT";
|
|
const string ALL_ITEMS_STRING = "all_items_string";
|
|
const string REPLACEMENT_ITEM = "replacement_item";
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: Name: BuildItemsForUpdateString
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
Basically builds a one long string of all
|
|
the item tags that are to be removed/replaced/etc.
|
|
Each item tag in the string is comma seperated.
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Elvin
|
|
//:: Created On: 04-Dec-2004
|
|
//:://////////////////////////////////////////////
|
|
void BuildItemsForUpdateString()
|
|
{
|
|
int nItemCount = 0;
|
|
string sItemTag = "";
|
|
string sAllItems = "";
|
|
|
|
sItemTag = Get2DAString(ITEMS_UPADTE_2DA, ITEM_COLUMN_2DA, nItemCount);
|
|
while(sItemTag != "")
|
|
{
|
|
sAllItems += (sItemTag + ",");
|
|
sItemTag = Get2DAString(ITEMS_UPADTE_2DA, ITEM_COLUMN_2DA, nItemCount);
|
|
nItemCount++;
|
|
}
|
|
|
|
SetLocalString(GetModule(), ALL_ITEMS_STRING, sAllItems);
|
|
}
|
|
|
|
//::///////////////////////////////////////////////
|
|
//:: Name: UpdateCharEquipment
|
|
//:://////////////////////////////////////////////
|
|
/*
|
|
Updates all the items on a PC, if they require
|
|
removing/replacing/etc.
|
|
*/
|
|
//:://////////////////////////////////////////////
|
|
//:: Created By: Elvin
|
|
//:: Created On: 04-Dec-2004
|
|
void UpdateCharEquipment(object oPC)
|
|
{
|
|
// Get the big long string containing all the item tags that are
|
|
// to be replaced.
|
|
string sAllItemsString = GetLocalString(GetModule(), ALL_ITEMS_STRING);
|
|
int nCreateItemCount = 0;
|
|
|
|
object oItem = GetFirstItemInInventory(oPC);
|
|
int nNumber = 0;
|
|
while(GetIsObjectValid(oItem))
|
|
{
|
|
int nItemCount = 0;
|
|
string sItemTag = "";
|
|
string sReplaceResRef = "";
|
|
int nGoldCompensation = 0;
|
|
string sInventItemTag = GetTag(oItem);
|
|
|
|
// Get first item tag (in the items column) in the 2da file
|
|
sItemTag = Get2DAString(ITEMS_UPADTE_2DA, ITEM_COLUMN_2DA, nItemCount);
|
|
|
|
// If the item tag is a sub string of the string that contains ALL
|
|
// the items, then this item is among those that need updating
|
|
if(FindSubString(sAllItemsString, sInventItemTag) != -1)
|
|
{
|
|
// If an item tag was found
|
|
while(sItemTag != "")
|
|
{
|
|
if( sItemTag == sInventItemTag )
|
|
{
|
|
// Get ResRef of replacement item/gold
|
|
sReplaceResRef = Get2DAString(ITEMS_UPADTE_2DA, REPLACEMENT_COLUMN_2DA, nItemCount);
|
|
|
|
DestroyObject(oItem);
|
|
nGoldCompensation = StringToInt(sReplaceResRef);
|
|
|
|
// If replacement is a number, then the player gets gold
|
|
// in return
|
|
if(nGoldCompensation > 0 )
|
|
{
|
|
GiveGoldToCreature(oPC, nGoldCompensation);
|
|
}
|
|
// Else if the ResRef is not an empty string, then
|
|
// the player gets a replacement item.
|
|
else if(sReplaceResRef != "")
|
|
{
|
|
SetLocalArrayString(oPC, REPLACEMENT_ITEM, nCreateItemCount, sReplaceResRef);
|
|
nCreateItemCount++;
|
|
}
|
|
}
|
|
// Get next item in 2da file
|
|
nItemCount++;
|
|
sItemTag = Get2DAString(ITEMS_UPADTE_2DA, ITEM_COLUMN_2DA, nItemCount);
|
|
sReplaceResRef = "";
|
|
}
|
|
}
|
|
oItem = GetNextItemInInventory(oPC);
|
|
}
|
|
|
|
// Now do the same for all the equipped items
|
|
int nSlot;
|
|
for(nSlot = 0; nSlot <= NUM_INVENTORY_SLOTS; nSlot++ )
|
|
{
|
|
oItem = GetItemInSlot(nSlot);
|
|
string sEquippedItemTag = GetTag(oItem);
|
|
int nItemCount = 0;
|
|
string sItemTag = "";
|
|
string sReplaceResRef = "";
|
|
int nGoldCompensation = 0;
|
|
|
|
if(GetIsObjectValid(oItem) && FindSubString(sAllItemsString, sEquippedItemTag) != -1)
|
|
{
|
|
sItemTag = Get2DAString(ITEMS_UPADTE_2DA, ITEM_COLUMN_2DA, nItemCount);
|
|
while(sItemTag != "")
|
|
{
|
|
if(sEquippedItemTag == sItemTag)
|
|
{
|
|
sReplaceResRef = Get2DAString(ITEMS_UPADTE_2DA, REPLACEMENT_COLUMN_2DA, nItemCount);
|
|
nGoldCompensation = StringToInt(sReplaceResRef);
|
|
DestroyObject(oItem);
|
|
|
|
// If replacement is a number, then the player gets gold
|
|
// in return
|
|
if(nGoldCompensation > 0 )
|
|
{
|
|
GiveGoldToCreature(oPC, nGoldCompensation);
|
|
}
|
|
// Else if the ResRef is not an empty string, then
|
|
// the player gets a replacement item.
|
|
else if(sReplaceResRef != "")
|
|
{
|
|
SetLocalArrayString(oPC, REPLACEMENT_ITEM, nCreateItemCount, sReplaceResRef);
|
|
nCreateItemCount++;
|
|
}
|
|
}
|
|
|
|
nItemCount++;
|
|
sItemTag = Get2DAString(ITEMS_UPADTE_2DA, ITEM_COLUMN_2DA, nItemCount);
|
|
sReplaceResRef = "";
|
|
}
|
|
}
|
|
}
|
|
|
|
if( nCreateItemCount > 0 )
|
|
{
|
|
int nCount;
|
|
string sResRef;
|
|
for( nCount = 0; nCount < nCreateItemCount; nCount++)
|
|
{ sResRef = GetLocalArrayString(oPC, REPLACEMENT_ITEM, nCount);
|
|
CreateItemOnObject(sResRef, oPC);
|
|
}
|
|
}
|
|
}
|