KF2-Server-Extension/ServerExt/Classes/Ext_T_GhostHelper.uc

124 lines
2.8 KiB
Ucode
Raw Normal View History

2017-10-20 02:00:49 +00:00
Class Ext_T_GhostHelper extends Ext_TraitDataStore;
var KFPawn_Human LastDied;
var float LastDiedTimer,TeleTime;
var vector ResPoint,TeleStartPoint;
var ExtSpawnPointHelper SpawnPointer;
var bool bTeleporting,bIsDelayed;
2020-11-28 20:04:55 +00:00
function bool CanResPlayer(KFPawn_Human Other, byte Level)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (bTeleporting)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (LastDied!=None)
2017-10-20 02:00:49 +00:00
LastDied.Health = 9999;
return true;
}
2020-11-28 20:12:58 +00:00
if (LastDied==Other)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Level==1 || LastDiedTimer>WorldInfo.TimeSeconds)
2017-10-20 02:00:49 +00:00
return false;
}
2020-11-28 20:12:58 +00:00
else if (Level==1 && Rand(2)==0)
2017-10-20 02:00:49 +00:00
return false;
LastDied = Other;
bTeleporting = true;
2020-11-28 20:12:58 +00:00
if (SpawnPointer==None)
2017-10-20 02:00:49 +00:00
SpawnPointer = class'ExtSpawnPointHelper'.Static.FindHelper(WorldInfo);
ResPoint = SpawnPointer.PickBestSpawn().Location;
LastDied.FindSpot(vect(36,36,86),ResPoint);
2020-11-28 20:12:58 +00:00
if (VSizeSq(LastDied.Location-ResPoint)<1.f) // Prevent division by zero errors in future.
2017-10-20 02:00:49 +00:00
ResPoint.Z+=5;
Enable('Tick');
StartResurrect();
return true;
}
final function StartResurrect()
{
TeleStartPoint = LastDied.Location;
LastDied.Health = 9999;
LastDied.LastStartTime = WorldInfo.TimeSeconds;
2020-11-28 20:12:58 +00:00
if (ExtHumanPawn(LastDied)!=None)
2017-10-20 02:00:49 +00:00
{
ExtHumanPawn(LastDied).bCanBecomeRagdoll = false;
2020-11-28 20:12:58 +00:00
if (!ExtHumanPawn(LastDied).CanBeRedeemed())
2017-10-20 02:00:49 +00:00
{
bIsDelayed = true;
return;
}
}
LastDied.SetCollision(false);
LastDied.bIgnoreForces = true;
LastDied.bAmbientCreature = true;
LastDied.SetPhysics(PHYS_None);
LastDied.bCollideWorld = false;
TeleTime = FClamp(VSize(ResPoint-TeleStartPoint)/900.f,1.f,10.f);
LastDiedTimer = WorldInfo.TimeSeconds+TeleTime;
}
2020-11-28 20:04:55 +00:00
function Tick(float Delta)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (!bTeleporting)
2017-10-20 02:00:49 +00:00
{
Disable('Tick');
return;
}
2020-11-28 20:12:58 +00:00
if (LastDied==None || LastDied.Health<=0)
2017-10-20 02:00:49 +00:00
{
bTeleporting = false;
return;
}
2020-11-28 20:12:58 +00:00
if (bIsDelayed)
2017-10-20 02:00:49 +00:00
{
bIsDelayed = false;
StartResurrect();
return;
}
Delta = (LastDiedTimer-WorldInfo.TimeSeconds);
2020-11-28 20:12:58 +00:00
if (Delta<=0)
2017-10-20 02:00:49 +00:00
{
EndGhostTeleport();
return;
}
Delta /= TeleTime;
LastDied.Velocity = Normal(ResPoint-TeleStartPoint)*900.f;
LastDied.SetLocation(TeleStartPoint*Delta+ResPoint*(1.f-Delta));
2020-11-28 20:12:58 +00:00
if (LastDied.Physics!=PHYS_None)
2017-10-20 02:00:49 +00:00
LastDied.SetPhysics(PHYS_None);
}
final function EndGhostTeleport()
{
LastDiedTimer = WorldInfo.TimeSeconds+180.f;
bTeleporting = false;
LastDied.Health = LastDied.HealthMax;
LastDied.SetCollision(true);
LastDied.bIgnoreForces = false;
LastDied.bAmbientCreature = false;
LastDied.bCollideWorld = true;
LastDied.FindSpot(vect(36,36,86),ResPoint);
LastDied.SetLocation(ResPoint);
LastDied.SetPhysics(PHYS_Falling);
LastDied.Velocity = vect(0,0,0);
LastDied.LastStartTime = WorldInfo.TimeSeconds; // For spawn protection, if any.
2020-11-28 20:12:58 +00:00
if (LastDied.IsDoingSpecialMove()) // Stop any grabbing zeds.
2017-10-20 02:00:49 +00:00
LastDied.EndSpecialMove();
2020-11-28 20:12:58 +00:00
if (ExtHumanPawn(LastDied)!=None)
2017-10-20 02:00:49 +00:00
ExtHumanPawn(LastDied).bCanBecomeRagdoll = true;
}
function Destroyed()
{
2020-11-28 20:12:58 +00:00
if (bTeleporting && LastDied!=None && LastDied.Health>0)
2017-10-20 02:00:49 +00:00
EndGhostTeleport();
}
defaultproperties
{
}