mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
383 lines
13 KiB
Plaintext
383 lines
13 KiB
Plaintext
include library.beast_lib;
|
|
include library.callable;
|
|
include library.player_structure;
|
|
include library.prose;
|
|
include library.sui;
|
|
include library.tcg;
|
|
include library.utils;
|
|
|
|
//LOGGING
|
|
const boolean LOGGING_ON = false;
|
|
const string LOGGING_CATEGORY = "tcg_barn";
|
|
|
|
trigger OnAttach()
|
|
{
|
|
setName(self, "a ranch hand");
|
|
messageTo(self, "handleSetRanchandName", null, 2, false);
|
|
messageTo(self, "showRoamingBeastsSoon", null, 2, false);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleSetRanchandName()
|
|
{
|
|
string ranchhandName = "a ranch hand";
|
|
|
|
obj_id building = getTopMostContainer(self);
|
|
if ( isIdValid(building) )
|
|
{
|
|
string buildingOwnerName = getStringObjVar(building, player_structure.VAR_OWNER);
|
|
if ( buildingOwnerName != null && buildingOwnerName.length() > 0 )
|
|
{
|
|
ranchhandName = "" + toUpper(buildingOwnerName, 0) + "'s ranch hand";
|
|
}
|
|
}
|
|
|
|
setName(self, ranchhandName);
|
|
setObjVar(self, "unmoveable", 1);
|
|
setObjVar(self, "noEject", 1);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnAboutToBeTransferred(obj_id destContainer, obj_id transferer)
|
|
{
|
|
obj_id destContainerContainer = getContainedBy(destContainer);
|
|
string destContainerContainerTemplate = getTemplateName(destContainerContainer);
|
|
if ( destContainerContainerTemplate.indexOf("barn_no_planet_restriction") > -1 )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
sendSystemMessage(transferer, new string_id ("tcg","barn_ranchhand_cannot_transfer"));
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
|
|
messageHandler OnPack()
|
|
{
|
|
obj_id barnCell = getObjIdObjVar(self, tcg.RANCHHAND_CELL);
|
|
if(isValidId(barnCell))
|
|
removeObjVar(barnCell, tcg.RANCHHAND_CELLCHECK);
|
|
|
|
destroyObject(self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleBarnBeastStorage()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
if ( isIdValid(player) )
|
|
{
|
|
location myLoc = getLocation(self);
|
|
location playerLoc = getLocation(player);
|
|
if ( myLoc.cell != playerLoc.cell )
|
|
{
|
|
sendSystemMessage(player, new string_id ("tcg","barn_ranchhand_not_in_same_cell"));
|
|
}
|
|
else
|
|
{
|
|
// Determine which button was pressed.
|
|
int button = sui.getIntButtonPressed( params );
|
|
if ( button == sui.BP_CANCEL )
|
|
{
|
|
}
|
|
else
|
|
{
|
|
int beast_selected = sui.getListboxSelectedRow(params);
|
|
if (beast_selected > -1 )
|
|
{
|
|
obj_id[] beastControlDevices = utils.getObjIdArrayScriptVar(player, "barnRanchHand.handleBarnBeastStorage");
|
|
if ( beastControlDevices != null && beastControlDevices.length > 0 )
|
|
{
|
|
if ( beast_selected < beastControlDevices.length )
|
|
{
|
|
obj_id selectedBeastControlDevice = beastControlDevices[beast_selected];
|
|
if ( isIdValid(selectedBeastControlDevice) )
|
|
{
|
|
obj_id barn = getTopMostContainer(self);
|
|
if( isIdValid(barn) )
|
|
{
|
|
string_id message = new string_id ("tcg","barn_beast_storage_failed");
|
|
string petName = beast_lib.getBCDBeastName(selectedBeastControlDevice);
|
|
|
|
if ( tcg.transferBeastControlDeviceToBarn(selectedBeastControlDevice, player, barn) )
|
|
{
|
|
message = new string_id ("tcg","barn_beast_stored_in_barn");
|
|
CustomerServiceLog( "playerStructure", "Player: "+player+" "+getPlayerName(player)+" successfully stored beast control device in barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
}
|
|
|
|
prose_package pp = prose.getPackage(message, player, player);
|
|
prose.setTO(pp, petName);
|
|
sendSystemMessageProse(player, pp);
|
|
|
|
if ( beast_lib.getTotalBeastControlDevices(player) > 0 && tcg.getTotalBarnStoredBeastsFromRanchhand(self) <= 40 )
|
|
{
|
|
tcg.barnStoreBeastPrompt(player, self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessage(player, new string_id ("tcg","barn_beast_transfer_failed_invalid"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( utils.hasScriptVar(player, "barnRanchHand.handleBarnBeastStorage") )
|
|
{
|
|
utils.removeScriptVar(player, "barnRanchHand.handleBarnBeastStorage");
|
|
}
|
|
if ( utils.hasScriptVar(player, "barnRanchHand.pid") )
|
|
{
|
|
utils.removeScriptVar(player, "barnRanchHand.pid");
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleBarnBeastReclaim()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
if ( isIdValid(player) )
|
|
{
|
|
location myLoc = getLocation(self);
|
|
location playerLoc = getLocation(player);
|
|
if ( myLoc.cell != playerLoc.cell )
|
|
{
|
|
sendSystemMessage(player, new string_id ("tcg","barn_ranchhand_not_in_same_cell"));
|
|
}
|
|
else
|
|
{
|
|
// Determine which button was pressed.
|
|
int button = sui.getIntButtonPressed( params );
|
|
if ( button == sui.BP_CANCEL )
|
|
{
|
|
}
|
|
else
|
|
{
|
|
int beast_selected = sui.getListboxSelectedRow(params);
|
|
if (beast_selected > -1 )
|
|
{
|
|
string[] beastStorageSlots = utils.getStringArrayScriptVar(player, "barnRanchHand.handleBarnBeastReclaim");
|
|
if ( beastStorageSlots != null && beastStorageSlots.length > 0 )
|
|
{
|
|
if ( beast_selected < beastStorageSlots.length )
|
|
{
|
|
string selectedBeastStorageSlot = beastStorageSlots[beast_selected];
|
|
if ( selectedBeastStorageSlot != null && selectedBeastStorageSlot.length() > 0 )
|
|
{
|
|
obj_id barn = getTopMostContainer(self);
|
|
if( isIdValid(barn) )
|
|
{
|
|
string_id message = new string_id ("tcg","barn_beast_reclaimed_failed");
|
|
string petName = "Unknown";
|
|
if ( hasObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".beast.beastName") )
|
|
{
|
|
petName = getStringObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".beast.beastName");
|
|
}
|
|
else if ( hasObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".tempName") )
|
|
{
|
|
petName = getStringObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".tempName");
|
|
}
|
|
|
|
obj_id transferedBCD = tcg.transferBeastControlDeviceFromBarn(selectedBeastStorageSlot, player, barn);
|
|
if ( isIdValid(transferedBCD) )
|
|
{
|
|
message = new string_id ("tcg","barn_beast_reclaimed_to_you");
|
|
petName = beast_lib.getBCDBeastName(transferedBCD);
|
|
CustomerServiceLog( "playerStructure", "Player: "+player+" "+getPlayerName(player)+" successfully claimed beast control device: "+transferedBCD+" from barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
}
|
|
|
|
prose_package pp = prose.getPackage(message, player, player);
|
|
prose.setTO(pp, petName);
|
|
sendSystemMessageProse(player, pp);
|
|
|
|
if ( tcg.getTotalBarnStoredBeastsFromRanchhand(self) > 0 && !callable.hasMaxStoredCombatPets(player) )
|
|
{
|
|
tcg.barnReclaimBeastPrompt(player, barn, self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessage(player, new string_id ("tcg","barn_beast_transfer_failed_invalid"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ( utils.hasScriptVar(player, "barnRanchHand.handleBarnBeastReclaim") )
|
|
{
|
|
utils.removeScriptVar(player, "barnRanchHand.handleBarnBeastReclaim");
|
|
}
|
|
if ( utils.hasScriptVar(player, "barnRanchHand.pid") )
|
|
{
|
|
utils.removeScriptVar(player, "barnRanchHand.pid");
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleBarnBeastDisplay()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
if ( isIdValid(player) )
|
|
{
|
|
location myLoc = getLocation(self);
|
|
location playerLoc = getLocation(player);
|
|
if ( myLoc.cell != playerLoc.cell )
|
|
{
|
|
sendSystemMessage(player, new string_id ("tcg","barn_ranchhand_not_in_same_cell"));
|
|
}
|
|
else
|
|
{
|
|
// Determine which button was pressed.
|
|
int button = sui.getIntButtonPressed( params );
|
|
if ( button == sui.BP_CANCEL )
|
|
{
|
|
}
|
|
else
|
|
{
|
|
int beast_selected = sui.getListboxSelectedRow(params);
|
|
if (beast_selected > -1 )
|
|
{
|
|
string[] beastStorageSlots = utils.getStringArrayScriptVar(player, "barnRanchHand.handleBarnBeastDisplay");
|
|
if ( beastStorageSlots != null && beastStorageSlots.length > 0 )
|
|
{
|
|
if ( beast_selected < beastStorageSlots.length )
|
|
{
|
|
string selectedBeastStorageSlot = beastStorageSlots[beast_selected];
|
|
if ( selectedBeastStorageSlot != null && selectedBeastStorageSlot.length() > 0 )
|
|
{
|
|
obj_id barn = getTopMostContainer(self);
|
|
if( isIdValid(barn) )
|
|
{
|
|
string_id message = new string_id ("tcg","barn_beast_display_failed");
|
|
string petName = "Unknown";
|
|
if ( hasObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".beast.beastName") )
|
|
{
|
|
petName = getStringObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".beast.beastName");
|
|
}
|
|
else if ( hasObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".tempName") )
|
|
{
|
|
petName = getStringObjVar(barn, "barnStorage."+selectedBeastStorageSlot+".tempName");
|
|
}
|
|
|
|
if (hasObjVar(barn, "barnStorage."+selectedBeastStorageSlot+"."+tcg.BEAST_ROAMING) )
|
|
{
|
|
obj_id displayedBeast = utils.getObjIdObjVar(barn, "barnStorage."+selectedBeastStorageSlot+"."+tcg.BEAST_ROAMING);
|
|
if ( isIdValid(displayedBeast) && exists(displayedBeast) )
|
|
{
|
|
blog("barn_ranchhand = handleBarnBeastDisplay ---- Destroying beast: "+displayedBeast);
|
|
CustomerServiceLog( "playerStructure", "Player: "+player+" "+getPlayerName(player)+" has stored a previously roaming/displayed beast: "+displayedBeast+" in barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
destroyObject(displayedBeast);
|
|
removeObjVar(barn, "barnStorage."+selectedBeastStorageSlot+"."+tcg.BEAST_ROAMING);
|
|
message = new string_id ("tcg","barn_beast_display_stored");
|
|
}
|
|
else if (isIdValid(displayedBeast) && !exists(displayedBeast))
|
|
{
|
|
CustomerServiceLog( "playerStructure", "Player: "+player+" "+getPlayerName(player)+" stored a barn beast "+(displayedBeast)+" that used to be roaming/displayed in the barn but for some reason is no longer valid. The issue was corrected and the beast can now roam/be displayed roaming in barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
blog("barn_ranchhand = handleBarnBeastDisplay ---- Destroying beast OBJVAR ONLY: "+displayedBeast);
|
|
removeObjVar(barn, "barnStorage."+selectedBeastStorageSlot+"."+tcg.BEAST_ROAMING);
|
|
}
|
|
else
|
|
{
|
|
CustomerServiceLog( "playerStructure", "Player: "+player+" "+getPlayerName(player)+" could not store a roming displayed barn beast. The beast OID was invalid in barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
message = new string_id ("tcg","barn_beast_display_storage_failed");
|
|
removeObjVar(barn, "barnStorage."+selectedBeastStorageSlot+"."+tcg.BEAST_ROAMING);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
obj_id beastToDisplay = tcg.barnDisplayBeast(self, selectedBeastStorageSlot, barn);
|
|
if(isIdValid(beastToDisplay))
|
|
{
|
|
CustomerServiceLog( "playerStructure", "Player: "+player+" "+getPlayerName(player)+" has created a roaming/displayed representation of their barn beast: "+beastToDisplay+" in barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
message = new string_id ("tcg","barn_beast_display_success");
|
|
}
|
|
else
|
|
{
|
|
CustomerServiceLog( "playerStructure", "Player: "+player+" "+getPlayerName(player)+" has FAILED to create a roaming/displayed representation of their barn beast slot: "+selectedBeastStorageSlot+" in barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
message = new string_id ("tcg","barn_beast_display_failed");
|
|
}
|
|
}
|
|
|
|
prose_package pp = prose.getPackage(message, player, player);
|
|
prose.setTO(pp, petName);
|
|
sendSystemMessageProse(player, pp);
|
|
|
|
if ( tcg.getTotalBarnStoredBeastsFromRanchhand(self) > 0 )
|
|
{
|
|
tcg.barnDisplayBeastPrompt(player, barn, self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessage(player, new string_id ("tcg","barn_beast_display_failed_invalid"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( utils.hasScriptVar(player, "barnRanchHand.handleBarnBeastDisplay") )
|
|
{
|
|
utils.removeScriptVar(player, "barnRanchHand.handleBarnBeastDisplay");
|
|
}
|
|
if ( utils.hasScriptVar(player, "barnRanchHand.pid") )
|
|
{
|
|
utils.removeScriptVar(player, "barnRanchHand.pid");
|
|
}
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler showRoamingBeastsSoon()
|
|
{
|
|
obj_id barn = getTopMostContainer(self);
|
|
if(!isIdValid(barn) || !exists(barn))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if(!tcg.showRoamingBeasts(barn, self))
|
|
{
|
|
CustomerServiceLog( "playerStructure", "Ranchhand: "+self+" "+getPlayerName(self)+" has FAILED to create a roaming/displayed representation in its barn: "+barn+" located at: "+getLocation(barn)+".");
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
boolean blog(string msg)
|
|
{
|
|
if(LOGGING_ON && msg != null && !msg.equals(""))
|
|
LOG(LOGGING_CATEGORY, msg);
|
|
return true;
|
|
}
|
|
|