//------------------------------------------------ // slicing_weapon.scriptlib // Brandon Reinhart //------------------------------------------------ //------------------------------------------------ // Include //------------------------------------------------ include library.prose; include library.slicing; include library.utils; include library.jedi; include library.weapons; include library.xp; include library.powerup; //------------------------------------------------ // Constants //------------------------------------------------ const string_id SID_SLICE = new string_id("slicing/slicing", "slice"); const string_id SID_REPAIR = new string_id("slicing/slicing", "repair"); const string_id SID_NO_KIT = new string_id("slicing/slicing", "no_weapon_kit"); const string_id SID_DAM_MOD = new string_id("slicing/slicing", "dam_mod"); const string_id SID_SPD_MOD = new string_id("slicing/slicing", "spd_mod"); const string_id SID_CRIT_MOD = new string_id("slicing/slicing", "crit_mod"); const string_id SID_FAIL_WEAPON = new string_id("slicing/slicing", "fail_weapon"); const string_id SID_WEAPON_AT_MAX = new string_id("slicing/slicing", "weapon_at_max"); const string_id SID_NOT_IN_INV = new string_id("slicing/slicing", "not_in_inv"); const string_id SID_FAILED_NO_EQUIP = new string_id("slicing/slicing", "failed_no_equip"); const string_id SID_SLICE_APPLIED = new string_id("slicing/slicing", "slice_applied"); const string SLICE_TABLE = "datatables/smuggler/slice_weapon.iff"; //------------------------------------------------ // OnAttach //------------------------------------------------ trigger OnAttach() { //detach us. detachScript( self, "item.slicing.slicing_weapon" ); return SCRIPT_CONTINUE; } //------------------------------------------------ // OnInitialize //------------------------------------------------ trigger OnInitialize() { // We should not be able to slice lightsabers if ( jedi.isLightsaber(self) ) { if ( !hasScript(self, "systems.jedi.saber_base") ) attachScript( self, "systems.jedi.saber_base" ); } detachScript( self, "item.slicing.slicing_weapon" ); return SCRIPT_CONTINUE; } //------------------------------------------------ // OnObjectMenuRequest //------------------------------------------------ /* // BLOCK MODIFIED FOR NPE/CLICKY-COMBAT - RcT - 10/12/05 trigger OnObjectMenuRequest( obj_id player, menu_info mi ) { if ( hasSkill( player, "combat_smuggler_novice" ) ) { int cust = getIntObjVar( self, "slice.customized" ); if ( cust == 100 ) return SCRIPT_CONTINUE; // Make sure we are in the player's inventory. obj_id pInv = utils.getInventoryContainer( player ); if ( !isIdValid(pInv) ) return SCRIPT_CONTINUE; if ( !contains( pInv, self ) ) return SCRIPT_CONTINUE; // weapon with powerup cannot be sliced if ( powerup.hasPowerUpInstalled( self ) ) return SCRIPT_CONTINUE; mi.addRootMenu( menu_info_types.SERVER_MENU5, SID_SLICE ); } return SCRIPT_CONTINUE; } //------------------------------------------------ // OnObjectMenuSelect //------------------------------------------------ trigger OnObjectMenuSelect( obj_id player, int item ) { // Item was used. if ( item == menu_info_types.SERVER_MENU5 ) { // You can only slice this if you have the correct skill. if ( hasObjVar( self, "slicing.hacked" ) || !hasSkill( player, "combat_smuggler_novice" ) ) return SCRIPT_CONTINUE; int cust = getIntObjVar( self, "slice.customized" ); if ( cust == 100 ) return SCRIPT_CONTINUE; // Make sure we are in the player's inventory. obj_id pInv = utils.getInventoryContainer( player ); if ( !isIdValid(pInv) ) return SCRIPT_CONTINUE; if ( !contains( pInv, self ) ) return SCRIPT_CONTINUE; // weapon with powerup cannot be sliced if ( powerup.hasPowerUpInstalled( self ) ) return SCRIPT_CONTINUE; // Begin the slicing game. slicing.startSlicing( player, self, "finishSlicing", "weapon" ); } return SCRIPT_CONTINUE; } */ //------------------------------------------------ // finishSlicing //------------------------------------------------ messageHandler finishSlicing() { if ( params == null ) return SCRIPT_CONTINUE; // Make sure we are in the player's inventory. obj_id player = params.getObjId( "player" ); obj_id pInv = utils.getInventoryContainer( player ); if ( !isIdValid(pInv) ) return SCRIPT_CONTINUE; if ( !contains( pInv, self ) ) { sendSystemMessage( player, SID_NOT_IN_INV ); return SCRIPT_CONTINUE; } // weapon with powerup cannot be sliced if ( powerup.hasPowerUpInstalled( self ) ) return SCRIPT_CONTINUE; int success = params.getInt( "success" ); int row = params.getInt( "row" ); if ( success == 1 ) { // We successfully applied the slice. dictionary effect = dataTableGetRow( SLICE_TABLE, row ); string slice_name = effect.getString( "SLICE" ); string stat = effect.getString( "STAT" ); int slice_cost = effect.getInt( "COST" ); int slice_amount = effect.getInt( "AMOUNT" ); // Apply the effect. boolean asuccess = false; if ( stat == "fire_rate" ) { asuccess = applyFireRateChange( self, player, slice_amount ); } else if ( stat == "damage" ) { asuccess = applyDamageChange( self, player, slice_amount ); } else if ( stat == "crit_chance" ) { asuccess = applyCritChance( self, player, slice_amount ); } if ( asuccess ) { // Add the cost to the weapon's current customized complexity. int weapon_cust = getIntObjVar( self, "slice.customized" ); weapon_cust += slice_cost; setObjVar( self, "slice.customized", weapon_cust ); // Remember the rank this weapon is sliced to. setObjVar( self, "slice.rank."+stat, effect.getInt( "RANK" ) ); // General notification. prose_package pp = prose.getPackage( SID_SLICE_APPLIED, new string_id( "slicing/slicing_weapon", slice_name ) ); sendSystemMessageProse( player, pp ); // Mark us as being hacked! setObjVar( self, "slicing.new_hacked", 1 ); // Update our attributes. sendDirtyAttributesNotification( self ); } } else { // We failed to apply the slice. // Currently this doesn't happen. } return SCRIPT_CONTINUE; } //------------------------------------------------ // applyFireRateChange //------------------------------------------------ boolean applyFireRateChange( obj_id self, obj_id player, int slice_amount ) { // Get the weapon's speed ranges. string template = getTemplateName( self ); float pctBonus = slice_amount / 100.0f; float spdLow = (float) weapons.getSpeedLow( template, weapons.VIA_TEMPLATE ); spdLow /= 100.0f; // Get the current weapon speed. float spd = getWeaponAttackSpeed( self ); // If we've had our speed sliced in the past, use the orginal weapon speed as a baseline. if ( hasObjVar( self, "slice.old_fire_rate" ) ) spd = getFloatObjVar( self, "slice.old_fire_rate" ); //sendSystemMessageTestingOnly( player, "Baseline Speed: " + spd ); if ( spd < (spdLow * 0.7f) ) { sendSystemMessage( player, SID_WEAPON_AT_MAX ); return false; } // Apply the speed bonus. setObjVar( self, "slice.old_fire_rate", spd ); spd -= spd * pctBonus; if ( spd < (spdLow * 0.7f) ) spd = (spdLow * 0.7f); //sendSystemMessageTestingOnly( player, "New Speed: " + spd ); setWeaponAttackSpeed( self, spd ); // Notify the player. int mod = (int)(pctBonus * 100); prose_package pp =prose.getPackage( SID_SPD_MOD, mod ); sendSystemMessageProse( player, pp ); // Record the change. setObjVar( self, "slice.fire_rate", slice_amount ); return true; } //------------------------------------------------ // applyDamageChange //------------------------------------------------ boolean applyDamageChange( obj_id self, obj_id player, int slice_amount ) { // Get the weapon's damage ranges. string template = getTemplateName( self ); float minDamLow = (float)weapons.getMinDamageLow(template, weapons.VIA_TEMPLATE); float minDamHigh = (float)weapons.getMinDamageHigh(template, weapons.VIA_TEMPLATE); float maxDamLow = (float)weapons.getMaxDamageLow(template, weapons.VIA_TEMPLATE); float maxDamHigh = (float)weapons.getMaxDamageHigh(template, weapons.VIA_TEMPLATE); float minDamRange = minDamHigh - minDamLow; float maxDamRange = maxDamHigh - maxDamLow; // See if we're already pegged at max (30% increase over template max). float minDam = (float)getWeaponMinDamage(self); float maxDam = (float)getWeaponMaxDamage(self); if ( (minDam > (minDamHigh * 1.3f)) || (maxDam > (maxDamHigh * 1.3f)) ) { sendSystemMessage(player, SID_WEAPON_AT_MAX); return false; } if ( hasObjVar( self, "slice.old_min_dam" ) ) minDam = getFloatObjVar( self, "slice.old_min_dam" ); if ( hasObjVar( self, "slice.old_max_dam" ) ) maxDam = getFloatObjVar( self, "slice.old_max_dam" ); // Apply our bonus. setObjVar( self, "slice.old_min_dam", minDam ); setObjVar( self, "slice.old_max_dam", maxDam ); //sendSystemMessageTestingOnly( player, "Baseline Damage: " + minDam+"/"+maxDam ); float pctBonus = slice_amount / 100.0f; minDam += minDam * pctBonus; maxDam += maxDam * pctBonus; //sendSystemMessageTestingOnly( player, "New Damage: " + minDam+"/"+maxDam ); // Bound & store the results. if ( minDam > (minDamHigh * 1.3f) ) minDam = (minDamHigh * 1.3f); if ( maxDam > (maxDamHigh * 1.3f) ) maxDam = (maxDamHigh * 1.3f); setWeaponMinDamage( self, (int)minDam ); setWeaponMaxDamage( self, (int)maxDam ); // Notify the player. int mod = (int)(pctBonus * 100); prose_package pp = prose.getPackage( SID_DAM_MOD, mod ); sendSystemMessageProse( player, pp ); // Record the change. setObjVar( self, "slice.damage", slice_amount ); return true; } //------------------------------------------------ // applyCritChance //------------------------------------------------ boolean applyCritChance( obj_id self, obj_id player, int slice_amount ) { // Notify the player. prose_package pp = prose.getPackage( SID_CRIT_MOD, slice_amount ); sendSystemMessageProse( player, pp ); // Record the change. setObjVar( self, "slice.crit_chance", slice_amount ); return true; } //------------------------------------------------ // OnGetAttributes //------------------------------------------------ /* // BLOCK MODIFIED FOR NPE/CLICKY-COMBAT - RcT - 10/12/05 trigger OnGetAttributes( obj_id player, string[] names, string[] attribs ) { if ( hasObjVar( self, "slice" ) ) { int idx = utils.getValidAttributeIndex( names ); if ( idx == -1 ) return SCRIPT_CONTINUE; // Customization int weapon_cust = getIntObjVar( self, "slice.customized" ); names[idx] = "wpn_cust"; attribs[idx] = weapon_cust + "%"; idx++; // Increased Rate of Fire if ( hasObjVar( self, "slice.fire_rate" ) ) { int fire_rate = getIntObjVar( self, "slice.fire_rate" ); names[idx] = "wpn_fire_rate"; attribs[idx] = fire_rate + "%"; idx++; } // Enhanced Damage if ( hasObjVar( self, "slice.damage" ) ) { int damage = getIntObjVar( self, "slice.damage" ); names[idx] = "wpn_damage"; attribs[idx] = damage + "%"; idx++; } // Crit Chance if ( hasObjVar( self, "slice.crit_chance" ) ) { int crit_chance = getIntObjVar( self, "slice.crit_chance" ); names[idx] = "wpn_crit_chance"; attribs[idx] = crit_chance + "%"; idx++; } } return SCRIPT_CONTINUE; } */