mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
272 lines
9.1 KiB
Plaintext
272 lines
9.1 KiB
Plaintext
//MagSeal Containers Version 2.0 - James Michener
|
|
//
|
|
//Again allows access to MagSeal Containers - player will now be able to access magseal containers by using a
|
|
//key that is a loot object(rare drop). When used, the 'key' will be consumed - the player will then have access
|
|
//to the magseal container and its items(loot) for 2 minutes before it re-locks.
|
|
//
|
|
//
|
|
include library.collection;
|
|
include library.loot;
|
|
include library.static_item;
|
|
include library.sui;
|
|
include library.utils;
|
|
|
|
//constants
|
|
const string COLLECTION_COLUMN = "collections";
|
|
const string PLAYER_ACCESS_ID = "player_access_id";
|
|
const int lootMin = 0;
|
|
const int lootMax = 2;
|
|
string MAGSEAL_TEMPLATE = "object/tangible/container/loot/placable_loot_crate.iff";
|
|
string MAGSEAL_LOOT_TABLE = "datatables/loot/loot_items/collectible/magseal_loot.iff";
|
|
string_id MAGSEAL_RADIAL_OPEN = new string_id("collection", "magseal_radial");
|
|
string_id DOES_NOT_HAVE_ACCESS = new string_id("collection", "no_magseal_access");
|
|
string_id COUNTDOWN_HAS_BEGUN = new string_id("collection", "magseal_timer_warning");
|
|
string_id NO_ACCESS_MAGSEAL = new string_id("collection", "magseal_no_access");
|
|
string_id MAGSEAL_OCCUPIED = new string_id("collection", "magseal_occupied");
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
if(!utils.isContainer(self))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
string containerTemplate = getTemplateName(self);
|
|
if (containerTemplate.equals(MAGSEAL_TEMPLATE))
|
|
{
|
|
//DESTROY ANY OBJECTS IN THE CONTAINER WHEN INITIALIZED
|
|
obj_id[] contents = getContents(self);
|
|
if(contents != null)
|
|
{
|
|
//messageTo to remove items.
|
|
messageTo(self, "initializeLootContainer", null, 20.0f, false);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else
|
|
{
|
|
destroyObject(self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
|
|
trigger OnAboutToLoseItem(obj_id pInv, obj_id player, obj_id item)
|
|
{
|
|
if(!utils.hasScriptVar(self, PLAYER_ACCESS_ID))
|
|
{
|
|
LOG("sissynoid", "Magseal - NO ScriptVar 'player_access_id' - Bail");
|
|
CustomerServiceLog("CollectionLootChannel: ", "Magseal: no ScriptVar on MagSeal: Player: " + player + " attempting to loot" + item + "from" + self + ".");
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
|
|
obj_id playerId = utils.getObjIdScriptVar(self, PLAYER_ACCESS_ID);
|
|
if(!isIdValid(playerId))
|
|
{
|
|
LOG("sissynoid", "Magseal - Invalid Player ID - Fail");
|
|
CustomerServiceLog("CollectionLootChannel: ", "Magseal: invalid playerId on Magseal: Player: " + player + " attempting to loot" + item + "from" + self + ".");
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
|
|
if(player != playerId)
|
|
{
|
|
LOG("sissynoid", "Magseal - Player ID does not match the Access ID - Fail");
|
|
sendSystemMessage(player, NO_ACCESS_MAGSEAL);
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
|
|
//set the owner of the loot item to the player so he can loot it.
|
|
setOwner(item, player);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnLostItem(obj_id pInv, obj_id player, obj_id item)
|
|
{
|
|
obj_id[] containerContents = getContents(self);
|
|
if(containerContents == null)
|
|
{
|
|
LOG("sissynoid", "Magseal - OnLostItem, Contents are 'null' - Bail");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
if(containerContents.length == 0)
|
|
{
|
|
LOG("sissynoid", "Magseal - OnLostItem, Container has no Items - Removing Player Access ID");
|
|
utils.removeScriptVar(self, PLAYER_ACCESS_ID);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
|
|
{
|
|
LOG("sissynoid", "Magseal - Requesting Magseal Menu");
|
|
mi.addRootMenu(menu_info_types.ITEM_OPEN, MAGSEAL_RADIAL_OPEN);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
LOG("sissynoid", "ENTER Magseal Menu Selection");
|
|
obj_id container = self;
|
|
|
|
if(item == menu_info_types.ITEM_OPEN)
|
|
{
|
|
LOG("sissynoid", "Magseal - Player selected 'OPEN'");
|
|
//Get planet name for loot table
|
|
string planetName = getCurrentSceneName();
|
|
//Check to ensure the player has the correct access key Card.
|
|
obj_id keyCard = utils.getStaticItemInInventory(player, "col_magseal_keycard_" + planetName + "_02_01");
|
|
|
|
if(!isIdValid(keyCard))
|
|
return SCRIPT_CONTINUE;
|
|
//Valid KeyCard - Container is NOT Occupied
|
|
if(!utils.hasScriptVar(container, PLAYER_ACCESS_ID))
|
|
{
|
|
//consume keycard first! If key is not consumed, player will not get access.
|
|
if(consumeKey(player, keyCard, planetName))
|
|
{
|
|
//Key was consumed - mark this player as the owner and give him time to loot
|
|
utils.setScriptVar(container, PLAYER_ACCESS_ID, player);
|
|
int numLootItems = rand(lootMin, lootMax); //roll - how many loot items to give 1-3 items
|
|
|
|
//access loot table - this is junk loot
|
|
string[] lootArray = dataTableGetStringColumnNoDefaults(MAGSEAL_LOOT_TABLE, planetName);
|
|
//make sure the loot table is populated
|
|
if(lootArray == null || lootArray.length <= 0)
|
|
{
|
|
CustomerServiceLog("CollectionLootChannel: ", "BrokenLoot: (DataTable Error in loot_crate.script) for MagSeal Container Collection");
|
|
LOG("sissynoid", "Magseal - Loot Array Null or < 0 - FAIL");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
for(int i = 0; i <= numLootItems; i++)
|
|
{
|
|
//grant 'n' items depending on numLootItems
|
|
int random = rand(0, lootArray.length-1);
|
|
LOG("sissynoid", "Magseal - Player to receive ("+ numLootItems +") items.");
|
|
//create the item(s) *loop*
|
|
obj_id itemId = static_item.createNewItemFunction(lootArray[random], container);
|
|
//make sure the item was created correctly.
|
|
if(!isValidId(itemId) || !exists(itemId))
|
|
{
|
|
LOG("sissynoid", "Magseal - INVALID ITEM CREATION (" + itemId + ")");
|
|
//Customer Service Log for failure to create item
|
|
CustomerServiceLog("CollectionLootChannel: ", "BrokenLoot: " + itemId + "(inValid ID)was not created for player" + player + "for magseal loot from container: " + container);
|
|
}
|
|
}
|
|
//Give player a collection Item. **player gets 1 collection items for each key consumed**
|
|
collection.getRandomCollectionItem(player, container, MAGSEAL_LOOT_TABLE, COLLECTION_COLUMN);
|
|
LOG("sissynoid", "Magseal - Generating Collection Item");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
//Valid KeyCard - Container is Occupied
|
|
else
|
|
{
|
|
obj_id currentUser = utils.getObjIdScriptVar(container, PLAYER_ACCESS_ID);
|
|
LOG("sissynoid", "Magseal - Magseal is Currently Being Used by (" + currentUser + ")");
|
|
if(player != currentUser)
|
|
{
|
|
LOG("sissynoid", "Magseal - Player("+ player +") is not the CurrentUser("+ currentUser +") - FAIL");
|
|
//Player is sent a system message via C
|
|
//Message: You do not have permission to access MagSeal Container.
|
|
sendSystemMessage(player, MAGSEAL_OCCUPIED);
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
boolean consumeKey(obj_id player, obj_id keyCard, string planetName)
|
|
{
|
|
obj_id container = getSelf();
|
|
if(!isIdValid(player) || !isIdValid(keyCard))
|
|
{
|
|
LOG("sissynoid", "Magseal - Invalid Player or KeyCard - return False");
|
|
return false;
|
|
}
|
|
//Destroys the player's keyCard.
|
|
decrementCount(keyCard);
|
|
|
|
//Set the owner so he can loot it.
|
|
setOwner(container, player);
|
|
|
|
//inform the player he has 2 minutes to loot
|
|
sendSystemMessage(player, COUNTDOWN_HAS_BEGUN);
|
|
|
|
dictionary dict = new dictionary();
|
|
dict.put("player", player);
|
|
|
|
//message the container to clean up after 2 minutes
|
|
messageTo(container, "resetContainer", dict, 120, false);
|
|
//modify collection slot value.
|
|
modifyCollectionSlotValue(player, "magseal_" + planetName, 1);
|
|
return true;
|
|
}
|
|
|
|
messageHandler resetContainer()
|
|
{
|
|
obj_id container = getSelf();
|
|
|
|
if(params == null || params.isEmpty())
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
obj_id player = params.getObjId("player");
|
|
|
|
obj_id[] remainingItems = getContents(container);
|
|
if(remainingItems == null)
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
if(remainingItems.length == 0)
|
|
{
|
|
utils.removeScriptVar(container, PLAYER_ACCESS_ID);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
if(remainingItems.length > 0)
|
|
{
|
|
for(int k = 0; k < remainingItems.length; k++)
|
|
{
|
|
CustomerServiceLog("CollectionLootChannel: ", "Magseal: " + "Magseal Timer Expired for " + player + " item: " + remainingItems[k] + " was deleted - as designed.");
|
|
destroyObject(remainingItems[k]);
|
|
}
|
|
utils.removeScriptVar(container, PLAYER_ACCESS_ID);
|
|
}
|
|
|
|
//Return the owner to the container itself - this will prevent people from using it without a card.
|
|
setOwner(container, obj_id.NULL_ID);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler initializeLootContainer()
|
|
{
|
|
obj_id[] contents = getContents(self);
|
|
if(contents != null)
|
|
{
|
|
for(int i = 0; i < contents.length; i++)
|
|
{
|
|
string template = getTemplateName(contents[i]);
|
|
LOG("sissynoid", "Magseal - CONTAINER HAD CONTENTS UPON LOADING! ("+ contents.length +") - ("+ template +") Items");
|
|
destroyObject(contents[i]);
|
|
}
|
|
}
|
|
//remove any objvars on the Magseal containers - these are no longer needed, and are only
|
|
//there because they are persisted in the DB.
|
|
if(hasObjVar(self, "cash_max"))
|
|
removeObjVar(self, "cash_max");
|
|
if(hasObjVar(self, "cash_min"))
|
|
removeObjVar(self, "cash_min");
|
|
if(hasObjVar(self, "items_max"))
|
|
removeObjVar(self, "items_max");
|
|
if(hasObjVar(self, "items_min"))
|
|
removeObjVar(self, "items_min");
|
|
if(hasObjVar(self, "loot_table"))
|
|
removeObjVar(self, "loot_table");
|
|
if(hasObjVar(self, "reset_time"))
|
|
removeObjVar(self, "reset_time");
|
|
if(hasObjVar(self, "unlocked"))
|
|
removeObjVar(self, "unlocked");
|
|
return SCRIPT_CONTINUE;
|
|
} |