So what is this, in vanilla D2 there is a spell, Chilling Armor that automatically retaliates with an ice bolt, but ofc this doesn't deflect anything, it's just a reaction to an event, so this itself was obviously not very useable for the task ahead (not to mention, the way this is handled client and server side is pretty incosistent and thus not reliable for much else then what they already do with it)
Earlier I've coded a way to add CTC effects to skills, this was also not the best thing for this, as it would mean storing the last missile id somewhere in pUnit, but keep in mind there are missiles that only exist client or server side = mess. So I needed something that isn't stored and just relies on information that should be the same (unless the games are desynced, but if this happens theres little that is reliable so ignore this fact).
Code: Select all
int __fastcall MISSILES_CheckDeflect(D2UnitStrc* pTarget, D2UnitStrc* pMissile, D2UnitStrc* pOwner)
{
// checks the reflect stat, simple
// ADDED 13th Feb, 2009 (by Nefarius)
if ( pOwner == NULL || !CheckMissile(pMissile) || pTarget == NULL )
{
return 0;
}
MissExTxt* pMissEx = GetMissDataEx( pMissile->nIndex );
ASSERT(pMissEx);
if ( pMissEx->flags & MISSTXT_REFLECT )
{
int nChance = D2GetStat(pTarget, STAT_SKILL_DEFLECT_MISSILE);
if ( nChance > 0 )
{
D2CoordStrc pos;
GetCoords(pTarget, &pos);
D2CoordStrc target;
GetCoords(pOwner, &target);
D2SeedStrc seed;
seed.set( ((pos.x - target.y) * (pos.y - target.x)) * (pTarget->nId - pOwner->nId + 1) );
if ( seed.chance( nChance ) )
{
// change the ownership of the missile
// lets see if this works :P
pMissile->fExpansion |= UNITFLAG_HASOWNER;
pMissile->eOwnerType = pTarget->eType;
pMissile->nOwnerId = pTarget->nId;
D2PathStrc* hPath = pMissile->hPath;
ASSERT(hPath);
D2SetPathTarget( hPath, pOwner );
D2SetPathStart( hPath, pMissile );
return 1;
}
}
}
return 0;
}
Here is the effect in action (animated) http://img14.imageshack.us/img14/1985/reflectahamb9.gif
You can see how unlike vanilla the overlay does not "reset" but stacks --- part of what I softcoded a couple of days ago.
Ofc this is nothing like how we will be using the effect in the final version and just a test.
[spoiler]If you've played BG series there is a shield that can reflect beholder rays thats pretty crucial for that one beholder city quest --- think from that point, but ofc there will also be spell deflection spells[/spoiler]
What can and can't be reflected follows a similar logic as Hand of Athena in vanilla and can be specified for each missile.