Skip to content

Commit

Permalink
Add Weapon Setting ShockProjectileCompensatePing
Browse files Browse the repository at this point in the history
  • Loading branch information
Deaod committed Jul 30, 2024
1 parent 513c7c5 commit cb5b1bf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 8 deletions.
45 changes: 38 additions & 7 deletions Classes/ST_ShockProj.uc
Original file line number Diff line number Diff line change
@@ -1,31 +1,62 @@
class ST_ShockProj extends ShockProj;

var ST_Mutator STM;
var WeaponSettingsRepl WSettings;

// For ShockProjectileTakeDamage
var float Health;

var PlayerPawn InstigatingPlayer;
var vector ExtrapolationDelta;

simulated final function WeaponSettingsRepl FindWeaponSettings() {
local WeaponSettingsRepl S;

foreach AllActors(class'WeaponSettingsRepl', S)
return S;

return none;
}

simulated final function WeaponSettingsRepl GetWeaponSettings() {
if (WSettings != none)
return WSettings;

WSettings = FindWeaponSettings();
return WSettings;
}

simulated function PostBeginPlay() {
if (ROLE == ROLE_Authority) {
if (Instigator != none && Instigator.Role == ROLE_Authority) {
ForEach AllActors(Class'ST_Mutator', STM)
break; // Find master :D
}
if (STM.WeaponSettings.ShockProjectileTakeDamage) {
Health = STM.WeaponSettings.ShockProjectileHealth;

if (STM.WeaponSettings.ShockProjectileTakeDamage) {
Health = STM.WeaponSettings.ShockProjectileHealth;
}
}
Super.PostBeginPlay();
}

simulated function PostNetBeginPlay() {
local PlayerPawn In;
local ST_ShockRifle SR;

super.PostNetBeginPlay();

In = PlayerPawn(Instigator);
if (In != none && Viewport(In.Player) != none)
InstigatingPlayer = In;
if (GetWeaponSettings().ShockProjectileCompensatePing) {
In = PlayerPawn(Instigator);
if (In != none && Viewport(In.Player) != none)
InstigatingPlayer = In;

if (InstigatingPlayer != none) {
SR = ST_ShockRifle(InstigatingPlayer.Weapon);
if (SR != none && SR.LocalDummy != none && SR.LocalDummy.bDeleteMe == false)
SR.LocalDummy.Destroy();
}
} else {
Disable('Tick');
}
}

simulated event Tick(float Delta) {
Expand Down
49 changes: 48 additions & 1 deletion Classes/ST_ShockRifle.uc
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
class ST_ShockRifle extends ShockRifle;

var ST_Mutator STM;

var WeaponSettingsRepl WSettings;

var ST_ShockProj LocalDummy;

simulated final function WeaponSettingsRepl FindWeaponSettings() {
local WeaponSettingsRepl S;

Expand Down Expand Up @@ -171,6 +172,52 @@ state ClientFiring {
}
}

state ClientAltFiring {
simulated function BeginState() {
local Pawn PawnOwner;
local vector X, Y, Z;
local vector Start;

if (GetWeaponSettings().ShockProjectileCompensatePing == false)
return;

PawnOwner = Pawn(Owner);

GetAxes(PawnOwner.ViewRotation,X,Y,Z);
Start = Owner.Location + CalcDrawOffsetClient() + FireOffset.X * X + FireOffset.Y * Y + FireOffset.Z * Z;
LocalDummy = ST_ShockProj(Spawn(AltProjectileClass,,, Start,PawnOwner.ViewRotation));
LocalDummy.RemoteRole = ROLE_None;
LocalDummy.LifeSpan = 0.25;
LocalDummy.bCollideWorld = false;
LocalDummy.SetCollision(false, false, false);
}
}

// compatibility between client and server logic
simulated function vector CalcDrawOffsetClient() {
local vector DrawOffset;
local Pawn PawnOwner;
local vector WeaponBob;

DrawOffset = CalcDrawOffset();

if (Level.NetMode != NM_Client)
return DrawOffset;

PawnOwner = Pawn(Owner);

// correct for EyeHeight differences between server and client
DrawOffset -= (PawnOwner.EyeHeight * vect(0,0,1));
DrawOffset += (PawnOwner.BaseEyeHeight * vect(0,0,1));

// remove WeaponBob, not applied on server
WeaponBob = BobDamping * PawnOwner.WalkBob;
WeaponBob.Z = (0.45 + 0.55 * BobDamping) * PawnOwner.WalkBob.Z;
DrawOffset -= WeaponBob;

return DrawOffset;
}

defaultproperties {
AltProjectileClass=Class'ST_ShockProj'
}
2 changes: 2 additions & 0 deletions Classes/WeaponSettings.uc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var config float ShockProjectileHurtRadius;
var config float ShockProjectileMomentum;
var config bool ShockProjectileBlockBullets;
var config bool ShockProjectileTakeDamage;
var config bool ShockProjectileCompensatePing;
var config float ShockProjectileHealth;
var config float ShockComboDamage;
var config float ShockComboMomentum;
Expand Down Expand Up @@ -257,6 +258,7 @@ defaultproperties
ShockProjectileMomentum=1.0
ShockProjectileBlockBullets=True
ShockProjectileTakeDamage=False
ShockProjectileCompensatePing=False
ShockProjectileHealth=30
ShockComboDamage=165
ShockComboHurtRadius=250
Expand Down
4 changes: 4 additions & 0 deletions Classes/WeaponSettingsRepl.uc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var float ShockProjectileHurtRadius;
var float ShockProjectileMomentum;
var bool ShockProjectileBlockBullets;
var bool ShockProjectileTakeDamage;
var bool ShockProjectileCompensatePing;
var float ShockProjectileHealth;
var float ShockComboDamage;
var float ShockComboMomentum;
Expand Down Expand Up @@ -196,6 +197,7 @@ replication {
ShockProjectileMomentum,
ShockProjectileBlockBullets,
ShockProjectileTakeDamage,
ShockProjectileCompensatePing,
ShockProjectileHealth,
ShockComboDamage,
ShockComboMomentum,
Expand Down Expand Up @@ -517,6 +519,7 @@ function InitFromWeaponSettings(WeaponSettings S) {
ShockProjectileMomentum = S.ShockProjectileMomentum;
ShockProjectileBlockBullets = S.ShockProjectileBlockBullets;
ShockProjectileTakeDamage = S.ShockProjectileTakeDamage;
ShockProjectileCompensatePing = S.ShockProjectileCompensatePing;
ShockProjectileHealth = S.ShockProjectileHealth;
ShockComboDamage = S.ShockComboDamage;
ShockComboMomentum = S.ShockComboMomentum;
Expand Down Expand Up @@ -678,6 +681,7 @@ defaultproperties
ShockProjectileMomentum=1.0
ShockProjectileBlockBullets=False
ShockProjectileTakeDamage=False
ShockProjectileCompensatePing=False
ShockProjectileHealth=30
ShockComboDamage=165
ShockComboHurtRadius=250
Expand Down

0 comments on commit cb5b1bf

Please sign in to comment.