Files
dsrc/sku.0/sys.server/compiled/game/script/space/crafting/component.script
T

477 lines
21 KiB
Plaintext

include library.space_crafting;
include library.space_transition;
include library.space_utils;
include library.static_item;
include library.utils;
// ----------------------------------------------------------------------
// TRIGGERS
// ----------------------------------------------------------------------
trigger OnInitialize()
{
string template = getTemplateName(self);
if(template == null || template.equals(""))
return SCRIPT_CONTINUE;
if(template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk") && !template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk5"))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + getName(self) + " was discovered and has initiated a collection reactor deletion/replacement messageTo.");
messageTo(self, "startCollectionReactorReplacement", null, 2, false);
}
return SCRIPT_CONTINUE;
}
trigger OnAttach()
{
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
menu_info_data data = mi.getMenuItemByType(menu_info_types.ITEM_USE);
string_id strSpam = new string_id("space/space_interaction", "repair_single_kit");
mi.addRootMenu(menu_info_types.ITEM_USE, strSpam);
strSpam = new string_id("space/space_interaction", "repair_all_kits");
mi.addRootMenu(menu_info_types.ITEM_ACTIVATE, strSpam);
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id objPlayer, int item)
{
if (item == menu_info_types.ITEM_USE)
{
//resizeable obj_id[] getRepairKitsForItem(obj_id objPlayer, int intSlot)
string strComponentType = getShipComponentDescriptorTypeName(getShipComponentDescriptorType(self));
resizeable obj_id[] objKits = space_crafting.getRepairKitsForItem(objPlayer, strComponentType);
if((objKits==null)||(objKits.length==0))
{
string_id strSpam = new string_id("space/space_interaction", "no_kits");
sendSystemMessage(objPlayer, strSpam);
return SCRIPT_CONTINUE;
}
else
{
space_crafting.repairComponentInInventory(self, objKits, objPlayer);
}
}
else if (item == menu_info_types.ITEM_ACTIVATE)
{
//resizeable obj_id[] getRepairKitsForItem(obj_id objPlayer, int intSlot)
string strComponentType = getShipComponentDescriptorTypeName(getShipComponentDescriptorType(self));
resizeable obj_id[] objKits = space_crafting.getRepairKitsForItem(objPlayer, strComponentType);
if((objKits==null)||(objKits.length==0))
{
string_id strSpam = new string_id("space/space_interaction", "no_kits");
sendSystemMessage(objPlayer, strSpam);
return SCRIPT_CONTINUE;
}
else
{
resizeable obj_id[] objNewKits = new obj_id[1];
objNewKits = utils.addElement(objNewKits, objKits[0]);
space_crafting.repairComponentInInventory(self, objKits, objPlayer);
}
}
return SCRIPT_CONTINUE;
}
/*
trigger OnTransferred(obj_id sourceContainer, obj_id destContainer, obj_id transferer)
{
if(!isValidId(self))
return SCRIPT_CONTINUE;
blog("component_fix", "INIT - OnTransferred Test check");
string template = getTemplateName(self);
blog("component_fix", "INIT - OnTransferred template: "+template);
if(template == null || template.equals(""))
return SCRIPT_CONTINUE;
blog("component_fix", "INIT - OnTransferred template valid");
if(!template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk"))
{
blog("component_fix", "INIT - OnTransferred I am not collection_reward_reactor_01_mk");
return SCRIPT_CONTINUE;
}
else if(template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk5"))
{
blog("component_fix", "INIT - OnTransferred I am collection_reward_reactor_01_mk5");
return SCRIPT_CONTINUE;
}
blog("component_fix", "INIT - OnTransferred I am a reactor.");
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + getName(self) + " object was transferred to a container. We will try to force reinit of the object so that the reactor becomes a schematic upon receipt by the player.");
blog("component_fix", "INIT - IS IN BAZAAR OR VENDOR");
messageTo(self, "handlerReInitialize", null, 1, false);
return SCRIPT_CONTINUE;
}
*/
trigger OnAboutToBeTransferred(obj_id destContainer, obj_id transferer)
{
blog("component_fix", "INIT - OnAboutToBeTransferred Test check");
string template = getTemplateName(self);
blog("component_fix", "INIT - OnAboutToBeTransferred template: "+template);
if(template == null || template.equals(""))
return SCRIPT_CONTINUE;
if(!template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk"))
{
blog("component_fix", "INIT - OnTransferred I am not collection_reward_reactor_01_mk");
return SCRIPT_CONTINUE;
}
else if(template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk5"))
{
blog("component_fix", "INIT - OnTransferred I am collection_reward_reactor_01_mk5");
return SCRIPT_CONTINUE;
}
blog("component_fix", "INIT - OnAboutToBeTransferred I am a bad reactor");
string objectName = getName(self);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " was discovered and is about to be transferred.");
if(utils.isBazaarObject(destContainer) || utils.isVendorObject(destContainer))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " was discovered and was about to be placed for sale. ABORTING!");
blog("component_fix", "INIT - IS VENDOR/BAZAAR ABORT");
messageTo(self, "handlerReInitialize", null, 0, false);
return SCRIPT_OVERRIDE;
}
//THE PROBLEM HERE IS THAT NOTHING, NOT EVEN GODMODE, WILL ALLOW THE ITEMS TO BE CRAFTED
messageTo(self, "handlerReInitialize", null, 1, false);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
// MESSAGEHANDLERS
// ----------------------------------------------------------------------
//QA Force Initialization Message Handler to avoid having to restart server or login/logout to retest.
messageHandler forceCollectionReactorInit ()
{
string template = getTemplateName(self);
if(template == null || template.equals(""))
return SCRIPT_CONTINUE;
if(template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk") && !template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk5"))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + getName(self) + " has been forced by someone in godmode. The reactor was discovered and has initiated a collection reactor deletion/replacement messageTo.");
messageTo(self, "startCollectionReactorReplacement", null, 2, false);
}
return SCRIPT_CONTINUE;
}
messageHandler startCollectionReactorReplacement ()
{
string objectName = getName(self);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " has started the eval stage of the collection reactor deletion/replacement.");
string template = getTemplateName(self);
if(template == null || template.equals(""))
return SCRIPT_CONTINUE;
if(template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk"))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is template: " +template);
if(template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk5"))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is not the template we want, bailing out. This object remains unchanged: " +template);
return SCRIPT_CONTINUE;
}
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is template: " +template + " and needs to be swapped out with a schematic.");
blog("component_fix", "INIT - FOUND COLLECTION REACTOR: "+template);
obj_id container = utils.getContainedBy(self);
blog("component_fix", "INIT - CONTAINER: "+container);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in container: " +container);
if (!isIdValid(container))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in container: " +container +" is not valid. Bailing out");
return SCRIPT_CONTINUE;
}
if(!utils.isContainer(container))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in container: " +container +" and this is not a backpack or other player container. Maybe it is a cell in a house.");
if(!utils.isNestedWithinAPlayer(container))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in container: " +container +" and is not nested in player.");
blog("component_fix", "INIT - ISNT IN PLAYER: "+container);
boolean success = getUsableContainer(self, container);
if (success)
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " will be destroyed and has been replaced with a schematic.");
blog("component_fix", "INIT - ITEM PLACED IN CELL: "+container);
return SCRIPT_CONTINUE;
}
else
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " could not be replaced and will not be destroyed. This is a major issue.");
blog("component_fix", "INIT - ITEM FAILED TO BE CREATED IN CELL: "+container);
return SCRIPT_CONTINUE;
}
}
}
if(utils.isInBazaar(self))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in a Vendor. We will try to force reinit of the object so that the reactor becomes a schematic upon receipt by the player.");
blog("component_fix", "INIT - IN BAZAAR");
messageTo(self, "handlerReInitialize", null, 5.0f, false);
return SCRIPT_CONTINUE;
}
else if(utils.isInVendor(self))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in a Vendor. We will try to force reinit of the object so that the reactor becomes a schematic upon receipt by the player.");
blog("component_fix", "INIT - IN VENDOR");
messageTo(self, "handlerReInitialize", null, 5.0f, false);
return SCRIPT_CONTINUE;
}
if (getContainerType(container) != 2) // 2= CT_volume
{
container = utils.getInventoryContainer(container);
if (getContainerType(container) != 2)
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " could not be replaced because it resides in a psuedo container. Container type: "+getContainerType(container));
LOG( "component_fix", objectName + "("+self + ") could not be made because we failed the inventory container check. Container type: "+getContainerType(container));
return SCRIPT_CONTINUE;
}
}
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " will be destroyed and has been replaced with a schematic.");
blog("component_fix", "INIT - PLAYER CONTAINER VALID: "+container);
boolean finalStatus = uninstallDeleteReplaceCollectionReactor(self, container);
if(!finalStatus)
{
blog("component_fix", "INIT - OPJECT NOT CREATED IN PLAYER");
}
//customer service log
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " was discovered and has initiated a collection reactor deletion/replacement.");
}
return SCRIPT_CONTINUE;
}
messageHandler destroyDeprecatedCollectionReactor ()
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + getName(self) + " is about to be destroyed. Good bye world!");
destroyObject(self);
return SCRIPT_CONTINUE;
}
messageHandler handlerReInitialize()
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + getName(self) + " is being reinitialized. This message is currently initiated due to the object being in a vendor.");
Object[] newParams = new Object[1];
newParams [0] = self;
blog("component_fix", "INIT - REININT HANDLER");
utils.callTrigger("OnInitialize", newParams);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
// FUNCTIONS
// ----------------------------------------------------------------------
boolean getUsableContainer(obj_id self, obj_id container)
{
string objectName = getName(self);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in an unknown location: (" + container + ") so we go through this function to see if we can swap out the object safely");
if(!isIdValid(container))
return false;
if(utils.isInBazaar(self))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in a Vendor. We will try to force reinit of the object so that the reactor becomes a schematic upon receipt by the player.");
blog("component_fix", "INIT - IN BAZAAR");
messageTo(self, "handlerReInitialize", null, 0, false);
return false;
}
else if(utils.isInVendor(self))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in a Vendor. We will try to force reinit of the object so that the reactor becomes a schematic upon receipt by the player.");
blog("component_fix", "INIT - IN VENDOR");
messageTo(self, "handlerReInitialize", null, 0, false);
return false;
}
string template = getTemplateName(container);
blog("component_fix", "INIT - CELL TEMPLATE: "+template);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in an unknown location: (" + container + "). The template is ("+template+")");
if(template.equals("object/cell/cell.iff"))
{
blog("component_fix", "INIT - CELL FOUND");
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in a Cell. We will swap out the reactor with the correct schematic at the location of the reactor.");
location compLoc = getLocation(self);
blog("component_fix", "INIT - LOCATION: "+compLoc);
if(!isValidLocation(compLoc, 1.f))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in a Cell and the location received is not valid. We have no choice but to abort. The bugged reactor will remain in: "+container);
blog("component_fix", "INIT - LOCATION NOT VALID");
return false;
}
boolean finalStatus = uninstallDeleteReplaceCollectionReactor(self, container, compLoc);
if(!finalStatus)
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " could not be replaced with a schematic for some reason. We have no choice but to abort. The bugged reactor will remain in: "+container);
blog("component_fix", "INIT - FAILED TO CREATE OBJECT IN CELL!!!!");
return false;
}
blog("component_fix", "INIT - CREATED/REPLACED IN CELL !!!!");
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " Was successfully replaced with a schematic. We are green for deletion from container: "+container);
messageTo(self, "destroyDeprecatedCollectionReactor", null, 0, false);
return true;
}
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is in a location we didn't plan for: "+container +". We must abort the process and hope the player moves the reactor to a new location soon.");
blog("component_fix", "INIT - THIS OBJECT IN UNKNOWN LOCATION!!!!");
return false;
}
boolean uninstallDeleteReplaceCollectionReactor(obj_id self, obj_id container)
{
string objectName = getName(self);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is about to start the replacement process. We are assuming the object is in the player inventory or a container somewhere in a structure.");
if(!isIdValid(container))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " somehow shows it is in an invalid container. Aborting.");
return false;
}
return uninstallDeleteReplaceCollectionReactor(self, container, null);
}
boolean uninstallDeleteReplaceCollectionReactor(obj_id self, obj_id container, location objLocation)
{
string objectName = getName(self);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " has started the replacement process. ");
if(!isIdValid(container))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " somehow shows it is in an invalid container. Aborting.");
return false;
}
blog("component_fix", "INIT - uninstallDeleteReplaceCollectionReactor CONTAINER: "+container);
string template = getTemplateName(self);
if(!template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk"))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " somehow mistakingly made it this far. It is not the reactor we want. Aborting.");
return false;
}
if(template.startsWith("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk5"))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " somehow mistakingly made it this far. Since it is the Mark 5 reactor it is not the reactor we want. Aborting.");
return false;
}
boolean issuedNew = false;
obj_id newItem = null;
string markVersion = "";
string replacementSchematic = "";
if(template.equals("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk1.iff"))
{
markVersion = "1";
replacementSchematic = space_crafting.COLLECTION_REWARD_REACTOR_MK1_V2;
}
else if(template.equals("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk2.iff"))
{
markVersion = "2";
replacementSchematic = space_crafting.COLLECTION_REWARD_REACTOR_MK2_V2;
}
else if(template.equals("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk3.iff"))
{
markVersion = "3";
replacementSchematic = space_crafting.COLLECTION_REWARD_REACTOR_MK3_V2;
}
else if(template.equals("object/tangible/ship/crafted/reactor/collection_reward_reactor_01_mk4.iff"))
{
markVersion = "4";
replacementSchematic = space_crafting.COLLECTION_REWARD_REACTOR_MK4_V2;
}
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " IS MARK "+markVersion+" and will be replace with "+replacementSchematic+".");
blog("component_fix", "Component: (" + self + ") " + objectName + " IS MARK "+markVersion+" and will be replace with "+replacementSchematic+".");
if(markVersion == null || markVersion.equals(""))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " WAS NOT REPLACED with a new schematic because the reactor version could not be determined. Could have been a Mark 5 reactor and we dont care about mark 5.");
blog("component_fix", "INIT - Could not find correct reactor version, maybe this is mark 5.");
return false;
}
if(replacementSchematic == null || replacementSchematic.equals(""))
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " WAS NOT REPLACED with a new schematic because the replacemen schematic was not resolved.");
blog("component_fix", "INIT - Could not find correct schematic version.");
return false;
}
blog("component_fix", "INIT - FOUND Mark "+markVersion+" REACTOR");
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is a Mark "+markVersion+" Reactor (AKA Koensayr Star Synthesis Archtype) and will be replaced with a new Mark "+markVersion+" schematic.");
if(objLocation != null)
{
blog("component_fix", "INIT - LOCATION NOT NULL, CREATING IN CELL: ");
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is a Mark "+markVersion+" Reactor and is located at: ("+ objLocation +") in container: ("+ container +") will be replaced with a new Mark "+markVersion+" schematic: "+replacementSchematic+".");
newItem = static_item.createNewItemFunction(replacementSchematic, container, objLocation);
}
else
{
blog("component_fix", "INIT - CREATE IN PLAYER CONTAINER: "+container);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is a Mark "+markVersion+" Reactor in container: ("+ container +") will be replaced with a new Mark 1 schematic: "+replacementSchematic+".");
newItem = static_item.createNewItemFunction(replacementSchematic, container);
}
if(isIdValid(newItem))
{
//CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is a Mark "+markVersion+" Reactor in container: ("+ container +") and CANNOT BE REPLACED with a new Mark 1 schematic: "+replacementSchematic+". It is possible the container is full or there is another unforseen issue logged.");
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " is a Mark "+markVersion+" Reactor in container: ("+ container +") and HAS BEEN REPLACED with a new Mark 1 schematic: "+replacementSchematic+".");
blog("component_fix", "INIT - CREATED NEW SCHEMATIC: ");
issuedNew = true;
}
if(!issuedNew)
{
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " WAS NOT REPLACED with a new schematic.");
blog("component_fix", "INIT - FAILED TO CREATE NEW SCHEMATIC!!!!!!!!!!!! ");
return false;
}
//so for some reason the server creating objects on the floor of a house causes them not to persist
//so lets we manually do it
if(isObjectPersisted(self) && !isObjectPersisted(newItem))
persistObject(newItem);
CustomerServiceLog("ShipComponents","Component: (" + self + ") " + objectName + " Was successfully replaced with a schematic. We are green for deletion from container: "+container);
messageTo(self, "destroyDeprecatedCollectionReactor", null, 0, false);
return true;
}
boolean blog(string category, string msg)
{
//LOG(category, msg);
return true;
}