Rubies wrote...
If I understand that right, you mean having a struct or a function that returns the total damage and damage type, and then pass them through to the DealDamage function in turn?
What I meant was to have your functions return effects or already linked effects. This way you can apply your entire damage amount at once. Instead of several uses of the ApplyEffect function. this will also open the functions up to be more usefull in other scripts.
I changed things a little bit so you can see what I meant. Of cource I am not verry good at changing comments either. So a lot of the old comments will just not make since.
The strange formating was just so some of the long functions would not wrape
// -----------------------------------------------------------------------------//
// OnEquipped script that records data about the currently equipped weapon's damage.
// Deals damage info on oPC in slot nSlot.
// slot 0 is the base damage, while slots 1+ are from item properties.
//
// nType is the code from baseitems.2da for slot 0, and an IP_CONST_DAMAGETYPE_*
// constant otherwise.
// nDice is the number of dice rolled.
// nSides is the number of sides of the dice rolled.
// Deals damage info to oTarget from oPC about any item properties oWeapon may have.
void CalculateDamage(object oPC, object oTarget, object oWeapon, int nDamageModifier, int nAddedDamage);
// Deals damage info about oWeapon on oPC.
effect GetWeaponBaseDamage(object oPC, object oTarget, object oWeapon, int nDamageModifier, int nAddedDamage);
// Deals damage info on oPC about any item properties oWeapon may have.
effect GetWeaponBonusDamage(object oPC, object oTarget, object oWeapon, int nDamageModifier, int nAddedDamage);
// Gets the Damage effect, modified by nDamageModifier.
effect GetDamageEffect(int IsBaseDamage, object oPC, object oTarget, int nDamageType, int nNumberOfDie, int nDamagePerDie, int nDamageModifier, int nAddedDamage);
// Deals damage info to oTarget from oPC about any item properties oWeapon may have.
void CalculateDamage(object oPC, object oTarget, object oWeapon, int nDamageModifier, int nAddedDamage)
{
effect eBase=GetWeaponBaseDamage(oPC, oTarget, oWeapon, nDamageModifier, nAddedDamage);
effect eBonus=GetWeaponBonusDamage(oPC,oTarget,oWeapon,nDamageModifier,nAddedDamage);
effect eTotal = EffectLinkEffects(eBonus ,eBase);
ApplyEffectToObject(DURATION_TYPE_INSTANT, eTotal, oTarget);
}
// Deals damage info about oWeapon on oPC.
effect GetWeaponBaseDamage(object oPC, object oTarget, object oWeapon, int nDamageModifier, int nAddedDamage)
{
// Get the info from the .2da file.
int nBaseItem = GetBaseItemType(oWeapon);
int nType = StringToInt(Get2DAString("baseitems", "WeaponType", nBaseItem));
int nDice = StringToInt(Get2DAString("baseitems", "NumDice", nBaseItem));
int nSides = StringToInt(Get2DAString("baseitems", "DieToRoll", nBaseItem));
// Convert it into a correctly usable damage type.
switch(nType)
{
case 0: nType = DAMAGE_TYPE_PIERCING; break;// Piercing
case 1: nType = DAMAGE_TYPE_PIERCING; break;// Piercing
case 2: nType = DAMAGE_TYPE_BLUDGEONING; break;// Bludgeoning
case 3: nType = DAMAGE_TYPE_SLASHING; break;// Slashing
case 4: nType = DAMAGE_TYPE_PIERCING; break;// Piercing+Slashing - Disabled
case 5: nType = DAMAGE_TYPE_BLUDGEONING; break;// Bludgeoning+Piercing - Disabled
}
// Deal the info.
return GetDamageEffect(1, oPC, oTarget, nType, nDice,
nSides, nDamageModifier, nAddedDamage);
}
// Deals damage info on oPC about any item properties oWeapon may have.
effect GetWeaponBonusDamage(object oPC, object oTarget, object oWeapon, int nDamageModifier, int nAddedDamage)
{
int nType, nDice, nSides, nCost,nNotFirstPass; // Set and used in the loop.
effect eDamage;
// Loop through the item properties.
itemproperty iProp = GetFirstItemProperty(oWeapon);
while (GetIsItemPropertyValid(iProp) )
{
// Look for damage bonuses.
if (GetItemPropertyType(iProp) == ITEM_PROPERTY_DAMAGE_BONUS)
{
// Get info about the damage bonus.
nCost = GetItemPropertyCostTableValue(iProp);
nType = GetItemPropertySubType(iProp);
nDice = StringToInt(Get2DAString("iprp_damagecost", "NumDice", nCost));
nSides = StringToInt(Get2DAString("iprp_damagecost", "Die", nCost));
// Convert it into a correctly usable damage type.
if (nType > 2) nType += -2;
nType = 1<<nType;
// Record this info.
if (nNotFirstPass) eDamage= EffectLinkEffects
(
GetDamageEffect
(
0, // Prams forGetDamageEffect
oPC,
oTarget,
nType,
nDice,
nSides,
nDamageModifier,
nAddedDamage
),
eDamage
);
else
{
eDamage =GetDamageEffect
(
0, // Prams forGetDamageEffect
oPC,
oTarget,
nType,
nDice,
nSides,
nDamageModifier,
nAddedDamage
);
nNotFirstPass = 1;
}
}
// Update the loop.
iProp = GetNextItemProperty(oWeapon);
}
return eDamage;
}
// .
effect GetDamageEffect(int IsBaseDamage, object oPC, object oTarget, int nDamageType, int nNumberOfDie, int nDamagePerDie, int nDamageModifier, int nAddedDamage)
{
// If it's flat damage, make sure it's flat, otherwise XdX.
int nBaseDamage, nTotalDamage;
if (nNumberOfDie >= 1)
{
do nBaseDamage += Random(nDamagePerDie)+1; while( nNumberOfDie--);
}
else
{
nBaseDamage = 1*nDamagePerDie;
}
// Final calculations.
nTotalDamage = nBaseDamage;
nTotalDamage += IsBaseDamage * ((nDamageModifier-1) * nBaseDamage + nAddedDamage);
return EffectDamage(nTotalDamage, nDamageType);
}
//void main(){}