// Created by Zunath #include "adv_include" #include "inc_mysql_tables" #include "nwnx_structs" //#include "zep_inc_main" // The max percentage any item's durability can be const int DURABILITY_ITEM_MAX = 100; // Base percent chance of losing durability on an item. Default: 2 const int DECAY_LOSS_CHANCE = 2; // Returns oItem's current level of durability // Returns -1 if the item does not have the durability item property // Returns 0-100 if successful int DCY_GetItemDurability(object oItem); // Sets an item's durability to iDurability // Only works for items which have the durability item property void DCY_SetItemDurability(object oItem, int iDurability); // Runs the item decaying process for oPC on oItem. // oPC must be a valid PC object // oItem must be a valid item with the durability item property // iDecayChanceModifier can be used to increase the chance of the decaying process to happen // iDecayAmountModifier can be used to increase the percentage of durability lost void DCY_RunItemDecay(object oPC, object oItem, int iDecayChanceModifier = 0, int iDecayAmountModifier = 0, int iDisplayMessage = TRUE); // Restores some lost durability to oItem. // If the item does not have the durability item property, it cannot be repaired and oPC will be informed // oPC must be a valid PC object // oItem must be a valid item with durability // iAmount is the amount of durability to recover void DCY_RunItemRepair(object oPC, object oItem, int iAmount); int DCY_GetItemDurability(object oItem) { int iCostID = DCY_CanItemHaveDurability(oItem); // No item property - item doesn't wear down if(iCostID == -1) return -1; return StringToInt(GetMySQLData(FUS_MYSQL_LOOKUP, "Durability", iCostID)); } void DCY_SetItemDurability(object oItem, int iDurability) { int iCostID = DCY_CanItemHaveDurability(oItem); // Can't set durability on an item that doesn't have the item property already if(iCostID == -1) return; // Safety check to make sure new durability isn't set out of bounds if(iDurability > DURABILITY_ITEM_MAX) iDurability = DURABILITY_ITEM_MAX; else if(iDurability < 0) iDurability = 0; // Replace existing item durability with the new value. int iIPID = StringToInt(GetMySQLData(FUS_MYSQL_LOOKUP, "ID", iDurability, "Durability")); itemproperty ipItemDurability = ItemPropertyDirect(ITEM_PROPERTY_ITEM_DURABILITY, 0, 35, iIPID, 0, 0); IPSafeAddItemProperty(oItem, ipItemDurability, 0.0f, X2_IP_ADDPROP_POLICY_REPLACE_EXISTING, FALSE, TRUE); } void DCY_RunItemDecay(object oPC, object oItem, int iDecayChanceModifier = 0, int iDecayAmountModifier = 0, int iDisplayMessage = TRUE) { // Item decay doesn't run for any items if Invincible is in effect if(GetPlotFlag(oPC)) return; int iDurability = DCY_GetItemDurability(oItem); // Grant a bonus to their roll, depending on player's luck attribute int iRoll = d100(1); string sItemName = GetName(oItem, TRUE); // Take the base decay loss chance and subtract it by player's skill in Maintenance. int iDC = DECAY_LOSS_CHANCE + iDecayChanceModifier; // Player failed the roll - lower durability by a few points if(iRoll <= iDC) { // Lose 1-4 points plus iDecayAmountModifier iRoll = d4(1) + iDecayAmountModifier; if(iRoll < 1){iRoll = 1;} iDurability = iDurability - iRoll; // Durability has hit 0% - force PC to unequip the item immediately by copying it and destroying the old one if(iDurability <= 0) { object oCopy = CopyItem(oItem, oPC, TRUE); DestroyObject(oItem); DCY_SetItemDurability(oCopy, 0); DeleteLocalInt(oCopy, GUN_TEMP_GUN_EQUIPPED); if(iDisplayMessage) { SendMessageToPC(oPC, ColorTokenRed() + "Your " + sItemName + " has broken!" + ColorTokenEnd()); } } // Update the item's durability and change its name else { // Inform player that their weapon has decayed if(iDisplayMessage) { SendMessageToPC(oPC, ColorTokenRed() + "Your " + sItemName + " has been damaged. (" + IntToString(iDurability) + "%)" + ColorTokenEnd()); } DCY_SetItemDurability(oItem, iDurability); } } } void DCY_RunItemRepair(object oPC, object oItem, int iAmount) { // Prevent repairing for less than 1% if(iAmount < 1) return; int iDurability = DCY_GetItemDurability(oItem); // Item has no durability - inform player they can't repair it if(iDurability == -1) { SendMessageToPC(oPC, ColorTokenRed() + "You cannot repair that item."); return; } iDurability = iDurability + iAmount; // Prevent durability from going over maximum percentage if(iDurability > DURABILITY_ITEM_MAX) iDurability = DURABILITY_ITEM_MAX; DCY_SetItemDurability(oItem, iDurability); SendMessageToPC(oPC, ColorTokenGreen() + "You repaired your " + GetName(oItem, TRUE) + ". (" + IntToString(iDurability) + "%)" + ColorTokenEnd()); } // Error checking //void main(){}