// HCR v3.0.3 - 18th May, 2005 - SE
//::////////////////////////////////////////////////////////////////////////////
//:: FileName: NW_CH_AC7
//:: OnDeath handler for summons, familiars, animal companions, and henchmen.
//::////////////////////////////////////////////////////////////////////////////
/*
REALFAM is the XP penalty set in hc_defaults, 200 by default - SE
*/
//::////////////////////////////////////////////////////////////////////////////
//::////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
// The Krit, 2008-01-11
// Deleting henchmen-specific stuff so the code is easier to manage on WoG.
// (There are no henchmen on this persistent world.)
// Rest of the code has been simplified.
// -----------------------------------------------------------------------------
//::////////////////////////////////////////////////////////////////////////////
#include "HC_Inc"
// :: Delayed Cleanup for remains of familiars and animal companions ::
// Object created to mark the remains of an animal companion or familiar
// This should be any "note" item. The name and description will be set via script.
const string ASSOCIATE_MARKER_RESREF = "notetoimogen";
// This is the tag the cleanup script will know denotes a fallen familiar/companion.
const string ASSOCIATE_MARKER_TAG = "AssociateRemains"; // must match anewonexit.nss
// -----------------------------------------------------------------------------
// Enforces the XP penalty when oMaster's familiar was killed.
// nXPPen is the amount of XP to lose per sorcerer/wizard level.
void FamiliarXPHit(object oMaster, int nXPPen)
{
// Clean up a local integer. (See nw_ch_ac1 for its purpose.)
DeleteLocalInt(OBJECT_SELF, "FAMMSG");
// Set the death local on the module.
SetLocalInt(oMod, "FAMDIED" + GetPlayerID(oMaster), 1);
// Determine amount of XP penalty set in hc_defaults - 9th Jan, Sir Elric
// Should be per wizard/sorcerer (combined) level -- TK.
nXPPen *= GetLevelByClass(CLASS_TYPE_WIZARD, oMaster) +
GetLevelByClass(CLASS_TYPE_SORCERER, oMaster);
// Halve the penalty on a successful fortitude save.
if ( FortitudeSave(oMaster, 15) > 0 )
nXPPen /= 2;
// Apply the XP penalty via the HC script.
SetLocalInt(oMaster, "TAKEXP", nXPPen);
ExecuteScript("hc_takexp", oMaster);
}
// -----------------------------------------------------------------------------
// Enforces the HP penalty when oMaster's familiar was killed.
void FamiliarHPHit(object oMaster)
{
// Damage is nominally 1d6.
int nDamage = d6();
// However, familiar death can never kill the PC, only wound them.
int nCurrentHP = GetCurrentHitPoints(oMaster);
if ( nDamage >= nCurrentHP )
nDamage = nCurrentHP - 1;
// Apply the hitpoint damage.
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage), oMaster);
}
//::////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------
void main()
{
object oMaster = GetMaster();
// There is only special handling for the death of a PC's associates.
if ( GetIsPC(oMaster) && !GetIsDM(oMaster) && !GetIsDMPossessed(oMaster) )
{
// IMPORTANT: If special handling is allowed for associates of NPC's,
// then the next check needs to be more involved. This is because an
// NPC's familiar and/or animal companion is officially a henchman, as
// far as the game engine is concerned. (By-product of the AI.)
int nAssocType = GetAssociateType(OBJECT_SELF);
// There is only special handling for familiars.
if ( nAssocType == ASSOCIATE_TYPE_FAMILIAR )
{
// Give the PC some feedback regarding the familiar's death.
FloatingTextStrRefOnCreature(63489, oMaster, FALSE);
// Familiar death hurts the master.
// See whether the penalty is XP or HP.
int nXPPen = GetLocalInt(oMod, "REALFAM");
if ( nXPPen > 0 )
FamiliarXPHit(oMaster, nXPPen);
else
FamiliarHPHit(oMaster);
}
// Add item to familiar and animal companion inventory, checkable in cleanup scripts.
if ( ( nAssocType == ASSOCIATE_TYPE_FAMILIAR ) || ( nAssocType == ASSOCIATE_TYPE_ANIMALCOMPANION ) )
{
// Check that the fam/comp had something in inventory
object oAnyItem = GetFirstItemInInventory(OBJECT_SELF);
if ( GetIsObjectValid(oAnyItem) )
{
// Create a note in inventory
object oNote = CreateItemOnObject(ASSOCIATE_MARKER_RESREF, OBJECT_SELF, 1, ASSOCIATE_MARKER_TAG);
SetName(oNote, "Note");
string sDesc = "Here fell " + GetName(OBJECT_SELF) + ", defending " + GetName(oMaster) + ".";
SetDescription(oNote, sDesc);
}
}
}
}
//::////////////////////////////////////////////////////////////////////////////