Files
dsrc/sku.0/sys.server/compiled/game/script/terminal/terminal_skill.script
T

231 lines
5.8 KiB
Plaintext

/***** INCLUDES ********************************************************/
include library.sui;
include library.skill;
include library.utils;
include library.prose;
/***** INHERITS ********************************************************/
inherits terminal.base.terminal_add_use;
/***** CONSTANTS *******************************************************/
const string SKILL_TBL = "datatables/skill/skills.iff";
const string SKILL_TERMINAL_TBL = "datatables/skill/skill_terminal.iff";
const string_id SID_TERMINAL_PROMPT = new string_id("skill_teacher","skill_terminal_prompt");
const string_id SID_TERMINAL_TITLE = new string_id("skill_teacher","skill_terminal_title");
const string_id SID_TERMINAL_DISABLED = new string_id("skill_teacher","skill_terminal_disabled");
const string_id SID_TERMINAL_DENIED = new string_id("skill_teacher","skill_terminal_denied");
const string_id SID_TERMINAL_MAX_SKILLS = new string_id("skill_teacher","skill_terminal_max_skills");
const string_id PROSE_GRANT_SKILL = new string_id("skill_teacher","skill_terminal_grant");
/***** TRIGGERS ********************************************************/
trigger OnAttach()
{
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
setName(self, "Correspondent Terminal");
return SCRIPT_CONTINUE;
}
/* SCRIPT DISABLED - skill_terminal.iff deleted
trigger OnObjectMenuSelect(obj_id player, int item)
{
string enabled = toLower(getConfigSetting("GameServer", "enableSkillTerminals"));
if (enabled == null || !enabled.equals("true"))
{
sendSystemMessage(player, SID_TERMINAL_DISABLED);
return SCRIPT_CONTINUE;
}
if ( item == menu_info_types.ITEM_USE )
{
string[] skillList = getLearnableSkillList(player);
if (skillList == null)
{
sendSystemMessage(player, SID_TERMINAL_DENIED);
return SCRIPT_CONTINUE;
}
else if (skillList.length == 0)
{
sendSystemMessage(player, SID_TERMINAL_MAX_SKILLS);
return SCRIPT_CONTINUE;
}
else
{
string playerPath = "data." + player;
if (utils.hasScriptVar(self, playerPath + ".sui_pid"))
{
int old_pid = utils.getIntScriptVar(self, playerPath + ".sui_pid");
sui.closeSUI(player, old_pid);
utils.removeScriptVarTree(self, playerPath);
}
utils.setBatchScriptVar(self, playerPath + ".skill_list", skillList);
string prompt = utils.packStringId(SID_TERMINAL_PROMPT);
string title = utils.packStringId(SID_TERMINAL_TITLE);
int pid = sui.listbox(self, player, prompt, sui.OK_CANCEL, title, convertSkillListNames(skillList), "handleSkillSelect");
utils.setScriptVar(self, playerPath + ".sui_pid", pid);
}
}
return SCRIPT_CONTINUE;
}
*/
/***** FUNCTIONS *******************************************************/
/* SCRIPT DISABLED - skill_terminal.iff deleted
string[] getLearnableSkillList(obj_id player)
{
string[] learnableSkillList = getTotalSkillList(player);
if (learnableSkillList == null)
return null;
resizeable string[] skillList = new string[0];
for (int i = 0; i < learnableSkillList.length; i++)
{
if (hasSkill(player, learnableSkillList[i]))
continue;
if (skill.hasRequiredSkillsForSkillPurchase(player, learnableSkillList[i]))
{
skillList = utils.addElement(skillList, learnableSkillList[i]);
}
}
return skillList;
}
string[] getTotalSkillList(obj_id player)
{
string[] masterSkillList = getMasterSkillList(player);
if (masterSkillList == null)
return null;
resizeable string[] skillList = new string[0];
for (int i = 0; i < masterSkillList.length; i++)
{
skillList = utils.addElement(skillList, masterSkillList[i]);
string[] tmp = skill.getAllRequiredSkills(masterSkillList[i]);
if ( (tmp == null) || (tmp.length == 0) )
{
}
else
{
for (int n = 0; n < tmp.length; n++)
{
int pos = utils.getElementPositionInArray(skillList, tmp[n]);
if ( pos == -1 )
{
skillList = utils.addElement(skillList, tmp[n]);
}
}
}
}
return skillList;
}
string[] getMasterSkillList(obj_id player)
{
string tblSkillList = dataTableGetString(SKILL_TERMINAL_TBL, player.toString(), "skillList");
if (tblSkillList == null || tblSkillList.equals(""))
return null;
resizeable string[] masterSkillList = new string [0];
java.util.StringTokenizer skills = new java.util.StringTokenizer(toLower(tblSkillList),",");
while ( skills.hasMoreTokens() )
{
string skillName = skills.nextToken();
if (skillName != null && !skillName.equals(""))
{
masterSkillList = utils.addElement(masterSkillList, skillName);
//LOG("skill_terminal", "MasterSkillList: " + skillName + " - read from datatable.");
}
}
return masterSkillList;
}
string[] convertSkillListNames(string[] skillList)
{
for (int i = 0; i < skillList.length; i++)
{
skillList[i] = "@skl_n:" + skillList[i];
}
return skillList;
}
*/
/***** MESSAGEHANDLERS *************************************************/
/* SCRIPT DISABLED - skill_terminal.iff deleted
messageHandler handleSkillSelect()
{
int idx = sui.getListboxSelectedRow(params);
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if ( btn == sui.BP_CANCEL )
{
return SCRIPT_CONTINUE;
}
if (exists(player))
{
string playerPath = "data." + player;
if (utils.hasScriptVar(self, playerPath + ".sui_pid"))
{
string[] skillList = utils.getStringBatchScriptVar(self, playerPath + ".skill_list");
string skillName = skillList[idx];
boolean granted = skill.grantSkillToPlayer(player, skillName);
string_id sid_skillName = new string_id("skl_n",skillName);
prose_package skillGranted = prose.getPackage(PROSE_GRANT_SKILL, sid_skillName);
sendSystemMessageProse(player, skillGranted);
//sendSystemMessageTestingOnly(player, "Granted skill:" + skillName + " = " + granted);
utils.removeScriptVarTree(self, playerPath);
}
}
return SCRIPT_CONTINUE;
}
*/