Initial upload
Initial upload. PRC8 has been added. Module compiles, PRC's default AI & treasure scripts have been integrated. Started work on top hak for SLA / Ability / Scripting modifications.
This commit is contained in:
277
_module/nss/jw_persist_store.nss
Normal file
277
_module/nss/jw_persist_store.nss
Normal file
@@ -0,0 +1,277 @@
|
||||
// Gets the items this store should have and puts them on the store
|
||||
void GetStoreItemsFromDatabase(int nNumber);
|
||||
// Initiate all our stores
|
||||
void InitiateStores();
|
||||
// Gets store number nNumber from the Database
|
||||
object GetStorefromDatabase(int nNumber);
|
||||
// Saves the store to the databse for later retieval
|
||||
void SaveStoretoDatabase(object oStore, int nNumber);
|
||||
// Saves the store's items to the database. nNumber is the number of the store
|
||||
void SaveStoreItemstoDatabase(int nNumber);
|
||||
// Saves all our persistent stores to the databse
|
||||
void SaveStores();
|
||||
// Returns item inventory number nInventoryNumber on oStore
|
||||
object GetItemonStoreInventory(object oStore, int nInventoryNumber);
|
||||
// Makes oItem the nNinventoryNumber item on oStore
|
||||
void SetItemOnStoreInventory(object oItem, object oStore, int nInventoryNumber);
|
||||
// Returns persistent store number nNumber
|
||||
object GetStoreFromModule(int nNumber);
|
||||
// Makes oStore the module store number nNumber
|
||||
void AddStoreToModule(object oStore, int nNumber);
|
||||
// Sets the number of persistent stores this module currently has
|
||||
void SetStoreNumbersinModule(int nNumber);
|
||||
// Returns the number of persistent stores this module currently has
|
||||
int GetStoreNumbersinModule();
|
||||
// Sets the number of persistent items this store holds
|
||||
void SetStoreItemsHeld(object oStore, int nNumber);
|
||||
// Gets the number of persistent items this store holds
|
||||
int GetStoreItemsHeld(object oStore);
|
||||
// Runs when oStore sells oObject
|
||||
void JWStoreSoldItem(object oObject, object oStore);
|
||||
// Runs when oStore buys oObject
|
||||
void JWStoreBoughtItem(object oObject, object oStore);
|
||||
// Gets the number of stores currently in the module
|
||||
|
||||
|
||||
|
||||
void JWStoreSoldItem(object oObject, object oStore)
|
||||
{
|
||||
// just delete our local ints
|
||||
int nInventoryNumber=GetLocalInt(oObject,"item");
|
||||
SendMessageToAllDMs("running store sold item script");
|
||||
// This was not a saved object
|
||||
if (nInventoryNumber==0)
|
||||
{
|
||||
SendMessageToAllDMs("this was not a saved object");
|
||||
return;
|
||||
}
|
||||
DeleteLocalInt(oObject,"item");
|
||||
SetItemOnStoreInventory(OBJECT_INVALID,oStore,nInventoryNumber);
|
||||
SendMessageToAllDMs("deleting a store's local object");
|
||||
}
|
||||
|
||||
void JWStoreBoughtItem(object oObject, object oStore)
|
||||
{
|
||||
if (GetBaseItemType(oObject)==BASE_ITEM_KEY)
|
||||
{
|
||||
DestroyObject(oObject);
|
||||
return;
|
||||
}
|
||||
string sItemTag=GetTag(oObject);
|
||||
string sLeft=GetStringLeft(sItemTag,3);
|
||||
if ((sLeft!="ccr")&&(sLeft!="ctr")&&(sLeft!="tra"))
|
||||
{
|
||||
DestroyObject(oObject);
|
||||
return;
|
||||
}
|
||||
|
||||
int nStoreInventory=GetStoreItemsHeld(oStore);
|
||||
|
||||
if (nStoreInventory==0)
|
||||
{
|
||||
// This store doesn't exist yet - make it
|
||||
int nNumberofStores=GetStoreNumbersinModule();
|
||||
nNumberofStores=nNumberofStores+1;
|
||||
SetStoreNumbersinModule(nNumberofStores);
|
||||
AddStoreToModule(oStore,nNumberofStores);
|
||||
}
|
||||
//push our inventroy up one
|
||||
nStoreInventory=nStoreInventory+1;
|
||||
if (nStoreInventory>30)
|
||||
{
|
||||
nStoreInventory=1;
|
||||
}
|
||||
//Save our inventory
|
||||
SetStoreItemsHeld(oStore,nStoreInventory);
|
||||
|
||||
object oOldStock=GetItemonStoreInventory(oStore,nStoreInventory);
|
||||
// If we still have old stock, destroy it
|
||||
if (GetIsObjectValid(oOldStock)||GetItemPossessor(oOldStock)==oStore)
|
||||
{
|
||||
DestroyObject(oOldStock);
|
||||
}
|
||||
|
||||
// ok tell our item which number it is
|
||||
SetLocalInt(oObject,"item",nStoreInventory);
|
||||
// Set our store to have the item
|
||||
SetItemOnStoreInventory(oObject,oStore,nStoreInventory);
|
||||
}
|
||||
|
||||
|
||||
// Sets the number of persistent items this store holds
|
||||
void SetStoreItemsHeld(object oStore, int nNumber)
|
||||
{
|
||||
SetLocalInt(oStore,"numitems",nNumber);
|
||||
}
|
||||
// Gets the number of persistent items this store holds
|
||||
int GetStoreItemsHeld(object oStore)
|
||||
{
|
||||
return GetLocalInt(oStore,"numitems");
|
||||
}
|
||||
|
||||
// Sets the number of persistent stores this module currently has
|
||||
void SetStoreNumbersinModule(int nNumber)
|
||||
{
|
||||
SetLocalInt(GetModule(),"numstores",nNumber);
|
||||
}
|
||||
// Returns the number of persistent stores this module currently has
|
||||
int GetStoreNumbersinModule()
|
||||
{
|
||||
return GetLocalInt(GetModule(),"numstores");
|
||||
}
|
||||
|
||||
// Returns persistent store number nNumber
|
||||
object GetStoreFromModule(int nNumber)
|
||||
{
|
||||
string sString=GetLocalString(GetModule(),"store"+IntToString(nNumber));
|
||||
return GetObjectByTag(sString);
|
||||
}
|
||||
|
||||
// Makes oStore the module store number nNumber
|
||||
void AddStoreToModule(object oStore, int nNumber)
|
||||
{
|
||||
SetLocalString(GetModule(),"store"+IntToString(nNumber),GetTag(oStore));
|
||||
}
|
||||
|
||||
void SetItemOnStoreInventory(object oItem, object oStore, int nInventoryNumber)
|
||||
{
|
||||
SetLocalObject(oStore,"inventory"+IntToString(nInventoryNumber),oItem);
|
||||
}
|
||||
|
||||
object GetItemonStoreInventory(object oStore, int nInventoryNumber)
|
||||
{
|
||||
return GetLocalObject(oStore,"inventory"+IntToString(nInventoryNumber));
|
||||
}
|
||||
|
||||
void SaveStores()
|
||||
{
|
||||
int nIdx;
|
||||
object oStore;
|
||||
|
||||
|
||||
|
||||
int nNumberOfStores=GetStoreNumbersinModule();
|
||||
if (nNumberOfStores==0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// First save the store number
|
||||
SetCampaignInt("NEW_WORLD","numberofstores",nNumberOfStores);
|
||||
|
||||
// go through the stores
|
||||
for(nIdx=1; nIdx<=nNumberOfStores; nIdx++)
|
||||
{
|
||||
oStore=GetStoreFromModule(nIdx);
|
||||
if ((GetIsObjectValid(oStore))&&(GetObjectType(oStore)==OBJECT_TYPE_STORE))
|
||||
{
|
||||
SaveStoretoDatabase(oStore,nIdx);
|
||||
SendMessageToAllDMs("saving store number "+IntToString(nIdx));
|
||||
SaveStoreItemstoDatabase(nIdx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SaveStoreItemstoDatabase(int nNumber)
|
||||
{
|
||||
int nIdx;
|
||||
object oStore=GetStoreFromModule(nNumber);
|
||||
object oItem;
|
||||
if ((!GetIsObjectValid(oStore))||(GetObjectType(oStore)!=OBJECT_TYPE_STORE))
|
||||
{
|
||||
return;
|
||||
}
|
||||
for(nIdx=1; nIdx<=30; nIdx++)
|
||||
{
|
||||
// Go through every item
|
||||
oItem=GetItemonStoreInventory(oStore,nIdx);
|
||||
if (GetIsObjectValid(oItem))
|
||||
{
|
||||
StoreCampaignObject("NEW_WORLD","storeobject"+IntToString(nIdx)+"on"+IntToString(nNumber),oItem);
|
||||
SendMessageToAllDMs("saving store inventory under the name "+"storeobject"+IntToString(nIdx)+"on"+IntToString(nNumber));
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
DeleteCampaignVariable("NEW_WORLD","storeobject"+IntToString(nIdx)+"on"+IntToString(nNumber));
|
||||
SendMessageToAllDMs("saving store invalid object under the name "+"storeobject"+IntToString(nIdx)+"on"+IntToString(nNumber));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SaveStoretoDatabase(object oStore, int nNumber)
|
||||
{
|
||||
SetCampaignString("NEW_WORLD","storetag"+IntToString(nNumber),GetTag(oStore));
|
||||
}
|
||||
|
||||
object GetStorefromDatabase(int nNumber)
|
||||
{
|
||||
string sStoreTag=GetCampaignString("NEW_WORLD","storetag"+IntToString(nNumber));
|
||||
object oStore=GetObjectByTag(sStoreTag);
|
||||
if ((GetIsObjectValid(oStore))&&(GetObjectType(oStore)==OBJECT_TYPE_STORE))
|
||||
{
|
||||
return oStore;
|
||||
}
|
||||
else
|
||||
{
|
||||
return OBJECT_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
void InitiateStores()
|
||||
{
|
||||
int nNumberOfStores=GetCampaignInt("NEW_WORLD","numberofstores");
|
||||
if (nNumberOfStores==0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// Set this as our module number of stores
|
||||
SetStoreNumbersinModule(nNumberOfStores);
|
||||
SendMessageToAllDMs("our module has this many stores "+IntToString(nNumberOfStores));
|
||||
// go through our stores one by one
|
||||
object oStore;
|
||||
int nIdx;
|
||||
for(nIdx=1; nIdx<=nNumberOfStores; nIdx++)
|
||||
{
|
||||
oStore=GetStorefromDatabase(nIdx);
|
||||
if (GetIsObjectValid(oStore))
|
||||
{
|
||||
SendMessageToAllDMs("adding store to module number "+IntToString(nIdx));
|
||||
AddStoreToModule(oStore,nIdx);
|
||||
GetStoreItemsFromDatabase(nIdx);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Gets the items this store should have and puts them on the store
|
||||
void GetStoreItemsFromDatabase(int nNumber)
|
||||
{
|
||||
object oStore=GetStoreFromModule(nNumber);
|
||||
object oItem;
|
||||
int nIdx;
|
||||
location lLoc=GetLocation(GetWaypointByTag("jw_store_failure_wp"));
|
||||
int nCounter;
|
||||
for(nIdx=1; nIdx<=30; nIdx++)
|
||||
{
|
||||
nCounter=0;
|
||||
// Go through every item
|
||||
oItem=RetrieveCampaignObject("NEW_WORLD","storeobject"+IntToString(nIdx)+"on"+IntToString(nNumber),lLoc,oStore);
|
||||
if (GetIsObjectValid(oItem))
|
||||
{
|
||||
nCounter=nCounter+1;
|
||||
SetItemOnStoreInventory(oItem,oStore,nIdx);
|
||||
SendMessageToAllDMs("adding item to store "+IntToString(nNumber)+" and it is item number "+IntToString(nIdx));
|
||||
// ok tell our item which number it is
|
||||
SetLocalInt(oItem,"item",nIdx);
|
||||
}
|
||||
else
|
||||
|
||||
{
|
||||
SendMessageToAllDMs("the following store item was invalid "+IntToString(nNumber)+" and it is item number "+IntToString(nIdx));
|
||||
}
|
||||
}
|
||||
SetStoreItemsHeld(oStore,nCounter);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user