mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
603 lines
16 KiB
Plaintext
603 lines
16 KiB
Plaintext
// ======================================================================
|
|
//
|
|
// chassis_npc.script
|
|
//
|
|
//
|
|
//
|
|
// Created with SwgConversationEditor 1.36 - DO NOT EDIT THIS AUTO-GENERATED FILE!
|
|
//
|
|
// ======================================================================
|
|
|
|
// ======================================================================
|
|
// Library Includes
|
|
// ======================================================================
|
|
|
|
include library.ai_lib;
|
|
include library.chat;
|
|
include library.money;
|
|
include library.space_crafting;
|
|
include library.space_transition;
|
|
include library.sui;
|
|
include library.travel;
|
|
include library.utils;
|
|
|
|
// ======================================================================
|
|
// Script Constants
|
|
// ======================================================================
|
|
|
|
string c_stringFile = "conversation/chassis_npc";
|
|
|
|
// ======================================================================
|
|
// Script Conditions
|
|
// ======================================================================
|
|
|
|
boolean chassis_npc_condition__defaultCondition (obj_id player, obj_id npc)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
boolean chassis_npc_condition_hasLoot (obj_id player, obj_id npc)
|
|
{
|
|
return space_crafting.hasLootToSell(player);
|
|
}
|
|
|
|
// ======================================================================
|
|
// Script Actions
|
|
// ======================================================================
|
|
|
|
void chassis_npc_action_showComponentList (obj_id player, obj_id npc)
|
|
{
|
|
space_crafting.purchaseChassisFromBroker(player, npc);
|
|
}
|
|
|
|
messageHandler handleCheckShip()
|
|
{
|
|
const string TBL = "datatables/space_crafting/chassis_npc.iff";
|
|
const string STF = "chassis_npc";
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
|
|
if (!isIdValid(player))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
int idx = sui.getListboxSelectedRow(params);
|
|
int bp = sui.getIntButtonPressed(params);
|
|
|
|
utils.setScriptVar(player, "chassis_npc.row", idx);
|
|
utils.setScriptVar(player, "chassis_npc.bp", bp);
|
|
|
|
if (idx == -1 || bp == -1)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
obj_id[] deeds = utils.getObjIdArrayScriptVar(player, "chassis_npc.deed");
|
|
|
|
if (deeds == null || deeds.length <= 0)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
string type = getStringObjVar(deeds[idx], "shiptype");
|
|
|
|
string skill = dataTableGetString(TBL, type, 3);
|
|
|
|
string_id msg = new string_id(STF, "can_use");
|
|
|
|
if (!hasSkill(player, skill))
|
|
msg = new string_id(STF, "cannot_use");
|
|
|
|
if (type == "firespray")
|
|
if (hasSkill(player, "pilot_rebel_navy_master") || hasSkill(player, "pilot_imperial_navy_master") ||
|
|
hasSkill(player, "pilot_neutral_master"))
|
|
msg = new string_id(STF, "can_use");
|
|
|
|
string message = utils.packStringId(msg);
|
|
string_id headerId = new string_id(STF, "confirm_transaction");
|
|
string header = utils.packStringId(headerId);
|
|
int pid = sui.msgbox(self, player, message, 2, header , 0, "handleBuyShip");
|
|
|
|
if (pid <= -1)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
return SCRIPT_CONTINUE;
|
|
|
|
}
|
|
|
|
messageHandler handleBuyShip()
|
|
{
|
|
const string TBL = "datatables/space_crafting/chassis_npc.iff";
|
|
const string STF = "chassis_npc";
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
|
|
if (!isIdValid(player))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
int button = sui.getIntButtonPressed(params);
|
|
|
|
|
|
|
|
if (button == 1)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
|
|
int idx = utils.getIntScriptVar(player, "chassis_npc.row");
|
|
int bp = utils.getIntScriptVar(player, "chassis_npc.bp");
|
|
utils.removeScriptVar(player, "chassis_npc.row");
|
|
utils.removeScriptVar(player, "chassis_npc.bp");
|
|
|
|
if (idx == -1 || bp == -1)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
obj_id inv = utils.getInventoryContainer(player);
|
|
|
|
if (!isIdValid(inv))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int[] prices = utils.getIntArrayScriptVar(player, "chassis_npc.price");
|
|
obj_id[] deeds = utils.getObjIdArrayScriptVar(player, "chassis_npc.deed");
|
|
|
|
if (deeds == null || deeds.length <= 0)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
string type = getStringObjVar(deeds[idx], "shiptype");
|
|
|
|
obj_id datapad = utils.getDatapad(player);
|
|
|
|
if (!isIdValid(datapad))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
|
|
int price = dataTableGetInt(TBL, type, 1);
|
|
|
|
obj_id deed = deeds[idx];
|
|
|
|
|
|
int playerCash = getTotalMoney(player);
|
|
if (bp == sui.BP_CANCEL)
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else
|
|
{
|
|
if (utils.getContainingPlayer(deed) == player)
|
|
{
|
|
float mass = getFloatObjVar(deed, "ship_chassis.mass");
|
|
float hp = getFloatObjVar(deed, "ship_chassis.hp");
|
|
obj_id pcd = space_crafting.createDeedFromBlueprints(player, type, inv, mass, hp);
|
|
if (isIdValid(pcd))
|
|
{
|
|
dictionary d = new dictionary();
|
|
d.put("player", player);
|
|
d.put("deed", pcd);
|
|
d.put("price", price);
|
|
d.put("blueprints", deed);
|
|
money.requestPayment(player, self, price, "handleChassisTransaction", d, false);
|
|
|
|
}
|
|
else
|
|
{
|
|
string_id msgInvFull = new string_id (STF, "inv_full");
|
|
chat.chat(self, player, msgInvFull);
|
|
destroyObject(pcd);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
cleanUpScriptVars(player);
|
|
}
|
|
else
|
|
{
|
|
string_id msgNotInInv = new string_id (STF, "not_in_inv");
|
|
chat.chat(self, player, msgNotInInv);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleChassisTransaction()
|
|
{
|
|
const string STF = "chassis_npc";
|
|
if ( params == null || params.isEmpty() )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
obj_id player = params.getObjId("player");
|
|
obj_id deed = params.getObjId("deed");
|
|
int price = params.getInt("price");
|
|
obj_id blueprints = params.getObjId("blueprints");
|
|
|
|
if ( !isIdValid(player) || !isIdValid(deed) || price < 1 )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if ( params.getInt(money.DICT_CODE) == money.RET_FAIL )
|
|
{
|
|
chat.chat(self, player, new string_id(STF,"no_money"));
|
|
destroyObject(deed);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
string strParkingLocation = travel.getTravelPointName(getTopMostContainer(self));
|
|
if(strParkingLocation!=null)
|
|
{
|
|
setObjVar(deed, "strParkingLocation", strParkingLocation);
|
|
}
|
|
else
|
|
{
|
|
setName(deed, "This pcd was made in a starport without a landing location");
|
|
}
|
|
|
|
string_id msgBoughtChassis = new string_id (STF, "bought_chassis");
|
|
chat.chat(self, player, msgBoughtChassis);
|
|
CustomerServiceLog("chassis_broker", "%TU CHANGED BLUEPRINT "+blueprints+ " ("+getTemplateName(blueprints)+") "+" INTO DEED " + deed + " (" + getTemplateName(deed)+ ") " + " FOR " + price + " CREDITS AT THIS BROKER: " + self, player);
|
|
playMusic(player, "sound/music_acq_academic.snd");
|
|
destroyObject(blueprints);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
void cleanUpScriptVars(obj_id player)
|
|
{
|
|
const string SCRIPTVAR_CHASSIS_SUI = "chassis_npc.sui";
|
|
|
|
utils.removeScriptVar(player, SCRIPTVAR_CHASSIS_SUI);
|
|
utils.removeScriptVar(player, "chassis_npc.price");
|
|
utils.removeBatchScriptVar(player, "chassis_npc.type");
|
|
utils.removeScriptVar(player, "chassis_npc.deed");
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
void chassis_npc_action_sellComponents (obj_id player, obj_id npc)
|
|
{
|
|
space_crafting.sellComponentsToBroker(player, npc);
|
|
}
|
|
|
|
|
|
|
|
messageHandler sellLootComponents()
|
|
{
|
|
|
|
obj_id objPlayer= sui.getPlayerId(params);
|
|
|
|
if (!isIdValid(objPlayer))
|
|
{
|
|
LOG("space", "Invalid player");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int idx = sui.getListboxSelectedRow(params);
|
|
int bp = sui.getIntButtonPressed(params);
|
|
|
|
if (idx == -1 || bp == -1)
|
|
{
|
|
LOG("space", "Invalid index");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else if ( bp != sui.BP_OK )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id[] objLootToSell= utils.getObjIdArrayScriptVar(objPlayer, "objLootToSell");
|
|
|
|
if (objLootToSell == null || objLootToSell.length <= 0)
|
|
{
|
|
LOG("space", "No loot");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
if(idx>objLootToSell.length-1)
|
|
{
|
|
LOG("space", "really bad index");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
obj_id objItem = objLootToSell[idx];
|
|
if(space_crafting.sellLootItem(objPlayer, self, objItem))
|
|
{
|
|
space_crafting.sellComponentsToBroker(objPlayer, self);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ======================================================================
|
|
// Script %TO Tokens
|
|
// ======================================================================
|
|
|
|
string chassis_npc_tokenTO_tokenTO0001 (obj_id player, obj_id npc)
|
|
{
|
|
return new string();
|
|
}
|
|
|
|
// ======================================================================
|
|
// Script %DI Tokens
|
|
// ======================================================================
|
|
|
|
// ======================================================================
|
|
// Script %DF Tokens
|
|
// ======================================================================
|
|
|
|
// ======================================================================
|
|
// handleBranch<n> Functions
|
|
// ======================================================================
|
|
|
|
int chassis_npc_handleBranch1 (obj_id player, obj_id npc, string_id response)
|
|
{
|
|
//-- [BRANCH NOTE]
|
|
//-- NPC: Hello. I can construct a ship chassis for you if you are holding a set of chassis blueprints.
|
|
|
|
//-- [RESPONSE NOTE]
|
|
//-- PLAYER: (SELL COMPONENTS)
|
|
if (response == "s_94e3013f")
|
|
{
|
|
//-- [NOTE]
|
|
if (chassis_npc_condition_hasLoot (player, npc))
|
|
{
|
|
chassis_npc_action_sellComponents (player, npc);
|
|
|
|
//-- NPC: Let's see what you have to sell...
|
|
string_id message = new string_id (c_stringFile, "s_aae81853");
|
|
utils.removeScriptVar (player, "conversation.chassis_npc.branchId");
|
|
|
|
npcEndConversationWithMessage (player, message);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//-- [NOTE]
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
//-- NPC: You don't have anything to sell me.
|
|
string_id message = new string_id (c_stringFile, "s_3310c404");
|
|
utils.removeScriptVar (player, "conversation.chassis_npc.branchId");
|
|
|
|
npcEndConversationWithMessage (player, message);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
}
|
|
|
|
//-- [RESPONSE NOTE]
|
|
//-- PLAYER: (ASSEMBLE SHIP CHASSIS)
|
|
if (response == "s_2f553ea8")
|
|
{
|
|
//-- [NOTE]
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
doAnimationAction (npc, "explain");
|
|
|
|
chassis_npc_action_showComponentList (player, npc);
|
|
|
|
//-- NPC: Let me see if you have any blueprints I can work with...
|
|
string_id message = new string_id (c_stringFile, "s_bcb592f");
|
|
utils.removeScriptVar (player, "conversation.chassis_npc.branchId");
|
|
|
|
npcEndConversationWithMessage (player, message);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
}
|
|
|
|
//-- [RESPONSE NOTE]
|
|
//-- PLAYER: How do I assemble a ship?
|
|
if (response == "s_93a92e8")
|
|
{
|
|
//-- [NOTE]
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
doAnimationAction (npc, "explain");
|
|
|
|
//-- NPC: You need to procure a set of chassis blueprints from a Shipwright. Once you have the blueprints, you must come to a chassis dealer to have the chassis built to your specifications.
|
|
string_id message = new string_id (c_stringFile, "s_37386aa2");
|
|
utils.removeScriptVar (player, "conversation.chassis_npc.branchId");
|
|
|
|
npcEndConversationWithMessage (player, message);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
}
|
|
|
|
//-- [RESPONSE NOTE]
|
|
//-- PLAYER: I'll come back later.
|
|
if (response == "s_42d3759c")
|
|
{
|
|
//-- [NOTE]
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
doAnimationAction (npc, "shrug_shoulders");
|
|
|
|
//-- NPC: I'll be here.
|
|
string_id message = new string_id (c_stringFile, "s_37f48153");
|
|
utils.removeScriptVar (player, "conversation.chassis_npc.branchId");
|
|
|
|
npcEndConversationWithMessage (player, message);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
}
|
|
|
|
return SCRIPT_DEFAULT;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
// ======================================================================
|
|
// User Script Triggers
|
|
// ======================================================================
|
|
|
|
trigger OnInitialize ()
|
|
{
|
|
if ((!isMob (self)) || (isPlayer (self)))
|
|
detachScript(self, "conversation.chassis_npc");
|
|
|
|
setCondition (self, CONDITION_CONVERSABLE);
|
|
setInvulnerable( self, true );
|
|
setCondition( self, CONDITION_SPACE_INTERESTING );
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnAttach ()
|
|
{
|
|
setCondition (self, CONDITION_CONVERSABLE);
|
|
setInvulnerable( self, true );
|
|
setCondition( self, CONDITION_SPACE_INTERESTING );
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuRequest (obj_id player, menu_info menuInfo)
|
|
{
|
|
int menu = menuInfo.addRootMenu (menu_info_types.CONVERSE_START, null);
|
|
menu_info_data menuInfoData = menuInfo.getMenuItemById (menu);
|
|
menuInfoData.setServerNotify (false);
|
|
setCondition (self, CONDITION_CONVERSABLE);
|
|
|
|
if ( !hasObjVar(self, "chassis_broker.alreadyHasName") )
|
|
{
|
|
string_id name = new string_id("chassis_npc", "npc_name");
|
|
setName(self, name);
|
|
}
|
|
|
|
setInvulnerable(self, true);
|
|
faceTo(self, player);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnIncapacitated (obj_id killer)
|
|
{
|
|
clearCondition (self, CONDITION_CONVERSABLE);
|
|
detachScript (self, "conversation.chassis_npc");
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ======================================================================
|
|
// Script Triggers
|
|
// ======================================================================
|
|
|
|
//-- This function should move to base_class.java
|
|
boolean npcStartConversation(obj_id player, obj_id npc, string convoName, string_id greetingId, prose_package greetingProse, string_id[] responses)
|
|
{
|
|
Object[] objects = new Object[responses.length];
|
|
System.arraycopy(responses, 0, objects, 0, responses.length);
|
|
return npcStartConversation(player, npc, convoName, greetingId, greetingProse, objects);
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
trigger OnStartNpcConversation (obj_id player)
|
|
{
|
|
obj_id npc = self;
|
|
|
|
if (ai_lib.isInCombat (npc) || ai_lib.isInCombat (player))
|
|
return SCRIPT_OVERRIDE;
|
|
|
|
//-- [NOTE]
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
doAnimationAction (npc, "wave1");
|
|
|
|
//-- NPC: Hello. I can construct a ship chassis for you if you are holding a set of chassis blueprints.
|
|
string_id message = new string_id (c_stringFile, "s_9ed93871");
|
|
int numberOfResponses = 0;
|
|
|
|
boolean hasResponse = false;
|
|
|
|
//-- PLAYER: (SELL COMPONENTS)
|
|
boolean hasResponse0 = false;
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
++numberOfResponses;
|
|
hasResponse = true;
|
|
hasResponse0 = true;
|
|
}
|
|
|
|
//-- PLAYER: (ASSEMBLE SHIP CHASSIS)
|
|
boolean hasResponse1 = false;
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
++numberOfResponses;
|
|
hasResponse = true;
|
|
hasResponse1 = true;
|
|
}
|
|
|
|
//-- PLAYER: How do I assemble a ship?
|
|
boolean hasResponse2 = false;
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
++numberOfResponses;
|
|
hasResponse = true;
|
|
hasResponse2 = true;
|
|
}
|
|
|
|
//-- PLAYER: I'll come back later.
|
|
boolean hasResponse3 = false;
|
|
if (chassis_npc_condition__defaultCondition (player, npc))
|
|
{
|
|
++numberOfResponses;
|
|
hasResponse = true;
|
|
hasResponse3 = true;
|
|
}
|
|
|
|
if (hasResponse)
|
|
{
|
|
int responseIndex = 0;
|
|
string_id responses [] = new string_id [numberOfResponses];
|
|
|
|
if (hasResponse0)
|
|
responses [responseIndex++] = new string_id (c_stringFile, "s_94e3013f");
|
|
|
|
if (hasResponse1)
|
|
responses [responseIndex++] = new string_id (c_stringFile, "s_2f553ea8");
|
|
|
|
if (hasResponse2)
|
|
responses [responseIndex++] = new string_id (c_stringFile, "s_93a92e8");
|
|
|
|
if (hasResponse3)
|
|
responses [responseIndex++] = new string_id (c_stringFile, "s_42d3759c");
|
|
|
|
utils.setScriptVar (player, "conversation.chassis_npc.branchId", 1);
|
|
|
|
npcStartConversation (player, npc, "chassis_npc", message, responses);
|
|
}
|
|
else
|
|
{
|
|
chat.chat (npc, player, message);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
chat.chat (npc, "Error: All conditions for OnStartNpcConversation were false.");
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
trigger OnNpcConversationResponse (string conversationId, obj_id player, string_id response)
|
|
{
|
|
if (conversationId != "chassis_npc")
|
|
return SCRIPT_CONTINUE;
|
|
|
|
obj_id npc = self;
|
|
|
|
int branchId = utils.getIntScriptVar (player, "conversation.chassis_npc.branchId");
|
|
|
|
if (branchId == 1 && chassis_npc_handleBranch1 (player, npc, response) == SCRIPT_CONTINUE)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
chat.chat (npc, "Error: Fell through all branches and responses for OnNpcConversationResponse.");
|
|
|
|
utils.removeScriptVar (player, "conversation.chassis_npc.branchId");
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ======================================================================
|
|
|