mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
256 lines
7.4 KiB
Plaintext
256 lines
7.4 KiB
Plaintext
include library.utils;
|
|
include library.jedi;
|
|
include library.pclib;
|
|
include library.static_item;
|
|
include library.weapons;
|
|
|
|
const string_id SID_NO_PARTS_TO_RECOVER = new string_id("jedi_spam", "no_parts_to_recover");
|
|
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
//do not mess with static stuff
|
|
if(static_item.isStaticItem(self))
|
|
return SCRIPT_CONTINUE;
|
|
else
|
|
{
|
|
//make sure our min/max range is set to correct distance
|
|
if(!utils.isNestedWithinANpcCreature(self))
|
|
weapons.validateWeaponRange(self);
|
|
}
|
|
weapons.setWeaponData(self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
|
|
{
|
|
if (canManipulate(player, self, false, true, 15, true))
|
|
{
|
|
string saberCert = getStringObjVar(self, "weapon.strCertUsed");
|
|
|
|
if (hasObjVar(self, "crafting_components")) // old saber
|
|
{
|
|
if (saberCert != null)
|
|
{
|
|
if (saberCert.equals("cert_onehandlightsaber") ||
|
|
saberCert.equals("cert_twohandlightsaber") ||
|
|
saberCert.equals("cert_polearmlightsaber"))
|
|
{
|
|
mi.addRootMenu (menu_info_types.SERVER_MENU1, new string_id("jedi_spam","dismantle_saber"));
|
|
}
|
|
}
|
|
}
|
|
else // new saber
|
|
{
|
|
menu_info_data mid = mi.getMenuItemByType(menu_info_types.SERVER_PET_OPEN);
|
|
if ( mid != null )
|
|
mid.setServerNotify(true);
|
|
else
|
|
mi.addRootMenu (menu_info_types.SERVER_PET_OPEN, new string_id("jedi_spam","open_saber"));
|
|
}
|
|
}
|
|
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if (canManipulate(player, self, false, true, 15, true))
|
|
{
|
|
if (item == menu_info_types.SERVER_MENU1)
|
|
{
|
|
dismantleSaber(player);
|
|
}
|
|
|
|
if (item == menu_info_types.SERVER_PET_OPEN)
|
|
{
|
|
openSaber(player);
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
void openSaber(obj_id player)
|
|
{
|
|
obj_id self = getSelf();
|
|
obj_id inv = getObjectInSlot(self, "saber_inv");
|
|
|
|
utils.requestContainerOpen(player, inv);
|
|
}
|
|
|
|
|
|
messageHandler handleResetSaberStats()
|
|
{
|
|
jedi.resetSaberStats(self);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
messageHandler decaySaberCrystal()
|
|
{
|
|
int amount = params.getInt("amount");
|
|
obj_id player = params.getObjId("owner");
|
|
|
|
obj_id inv = getObjectInSlot(self, "saber_inv");
|
|
obj_id[] contents = getContents(inv);
|
|
|
|
if (contents == null || contents.length == 0)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
|
|
obj_id crystal = contents[rand(0, contents.length-1)];
|
|
|
|
int hp = getHitpoints(crystal);
|
|
if (hp > 0)
|
|
{
|
|
pclib.damageAndDecayItem(crystal, amount);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/*
|
|
trigger OnGetAttributes(obj_id player, string[] names, string[] attribs)
|
|
{
|
|
int idx = utils.getValidAttributeIndex(names);
|
|
if (idx == -1)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
if (hasObjVar(self, jedi.VAR_SABER_BASE + "." + jedi.VAR_FORCE))
|
|
{
|
|
names[idx] = "forcecost";
|
|
int attrib = (int)getFloatObjVar(self, jedi.VAR_SABER_BASE + "." + jedi.VAR_FORCE);
|
|
attribs[idx] = Integer.toString(attrib);
|
|
idx++;
|
|
if (idx >= names.length)
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
*/
|
|
|
|
void dismantleSaber(obj_id player)
|
|
{
|
|
obj_id self = getSelf();
|
|
|
|
int minDamage = (int)getFloatObjVar(self, "crafting_components.minDamage");
|
|
int maxDamage = (int)getFloatObjVar(self, "crafting_components.maxDamage");
|
|
|
|
CustomerServiceLog("jedi_saber", "%TU saber dismantling, had a Min Damage of " + minDamage + " and a Max Damage of " + maxDamage, player);
|
|
//LOG("jedi_saber", "%TU saber dismantling, had a Min Damage of " + minDamage + " and a Max Damage of " + maxDamage, player);
|
|
|
|
int generation = 0;
|
|
string template = getTemplateName(self);
|
|
|
|
if (template.endsWith("gen2.iff"))
|
|
generation = 2;
|
|
else if (template.endsWith("gen3.iff"))
|
|
generation = 3;
|
|
else if (template.endsWith("gen4.iff"))
|
|
generation = 4;
|
|
else if (template.endsWith("gen5.iff"))
|
|
generation = 5;
|
|
|
|
CustomerServiceLog("jedi_saber", "%TU saber dismantling, was a generation " + generation + " saber.", player);
|
|
//LOG("jedi_saber", "%TU saber dismantling, was a generation " + generation + " saber.", player);
|
|
|
|
int[] generationList = dataTableGetIntColumn("datatables/jedi/saber_conversion.iff", "generation");
|
|
|
|
resizeable dictionary[] saberList = new dictionary[0];
|
|
|
|
for (int i = 0; i < generationList.length; i++)
|
|
{
|
|
if (generationList[i] == generation)
|
|
{
|
|
saberList = utils.addElement(saberList, dataTableGetRow("datatables/jedi/saber_conversion.iff", i));
|
|
}
|
|
}
|
|
|
|
int idx = -1;
|
|
for (int i = 0; i < saberList.size(); i++)
|
|
{
|
|
if (minDamage >= saberList[i].getInt("minDamage") && maxDamage >= saberList[i].getInt("maxDamage"))
|
|
idx++;
|
|
else
|
|
break;
|
|
}
|
|
|
|
if (idx >= saberList.size())
|
|
{
|
|
sendSystemMessage(player, new string_id("jedi_spam", "saber_cant_convert"));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
int pearlCount = generation-1;
|
|
int pearlLevel = 25;
|
|
|
|
if (idx > -1)
|
|
{
|
|
pearlCount = saberList[idx].getInt("pearlCount");
|
|
pearlLevel = saberList[idx].getInt("pearlLevel");
|
|
}
|
|
|
|
if (pearlCount < 1)
|
|
{
|
|
sendSystemMessage(player, SID_NO_PARTS_TO_RECOVER);
|
|
CustomerServiceLog("jedi_saber", "%TU saber dismantling, No pearls to recover from a training saber.", player);
|
|
return;
|
|
}
|
|
|
|
CustomerServiceLog("jedi_saber", "%TU saber dismantling, Initial pearlCount is " + pearlCount + " and Initial PeralLevel is " + pearlLevel, player);
|
|
//LOG("jedi_saber", "%TU saber dismantling, Initial pearlCount is " + pearlCount + " and Initial PeralLevel is " + pearlLevel, player);
|
|
|
|
if (hasObjVar(self, "slicing.hacked"))
|
|
{
|
|
sendSystemMessage(player, new string_id("jedi_spam", "saber_convert_sliced"));
|
|
|
|
pearlLevel = pearlLevel - (pearlLevel / 5);
|
|
}
|
|
|
|
obj_id inventory = utils.getInventoryContainer(player);
|
|
int invSpace = getVolumeFree(inventory);
|
|
|
|
//LOG("jedi_saber", "%TU saber dismantling, inventory space = " + invSpace, player);
|
|
//LOG("jedi_saber", "%TU saber dismantling, inventory size = " + getTotalVolume(inventory), player);
|
|
//LOG("jedi_saber", "%TU saber dismantling, inventory used = " + getFilledVolume(inventory), player);
|
|
|
|
if (invSpace < pearlCount)
|
|
{
|
|
CustomerServiceLog("jedi_saber", "%TU saber dismantling, Didn't add any pearls because Inventory of player was full.", player);
|
|
//LOG("jedi_saber", "%TU saber dismantling, Didn't add any pearls because Inventory of player was full.", player);
|
|
sendSystemMessage(player, new string_id("jedi_spam", "saber_convert_full"));
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < pearlCount; i++)
|
|
{
|
|
obj_id pearl = createObject("object/tangible/component/weapon/lightsaber/lightsaber_module_krayt_dragon_pearl.iff", inventory, "");
|
|
|
|
if (pearl == null)
|
|
{
|
|
CustomerServiceLog("jedi_saber", "ERROR:: %TU saber dismantling, Level " + pearlLevel + "Pearl unable to be created.", player);
|
|
//LOG("jedi_saber", "ERROR:: %TU saber dismantling, Level " + pearlLevel + "Pearl unable to be created.", player);
|
|
}
|
|
else
|
|
{
|
|
//LOG("jedi", "Setting pearl level "+pearlLevel+" on pearl("+pearl+")");
|
|
CustomerServiceLog("jedi_saber", "%TU saber dismantling, Pearl Level set to " + pearlLevel + "for Pearl " + pearl + ".", player);
|
|
//LOG("jedi_saber", "%TU saber dismantling, Pearl Level set to " + pearlLevel + "for Pearl " + pearl + ".", player);
|
|
setObjVar(pearl, jedi.VAR_CRYSTAL_STATS + "." + jedi.VAR_LEVEL, pearlLevel);
|
|
}
|
|
}
|
|
|
|
CustomerServiceLog("jedi_saber", "%TU saber dismantling, completed dismantling saber and destroyed the object which was %TT.", player, self);
|
|
//LOG("jedi_saber", "%TU saber dismantling, completed dismantling saber and destroyed the object which was %TT.", player, self);
|
|
destroyObject(self);
|
|
|
|
sendSystemMessage(player, new string_id("jedi_spam", "saber_convert_complete"));
|
|
return;
|
|
}
|
|
}
|
|
} |