Skip to content

Commit

Permalink
demonic possession effect now works in online
Browse files Browse the repository at this point in the history
  • Loading branch information
pdcook committed Jun 23, 2021
1 parent 23c2b51 commit fa9d528
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 51 deletions.
122 changes: 79 additions & 43 deletions PCE/MonoBehaviours/DemonicPossessionEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ void Update()
// if the player is not active (i.e. simulated) then clear all effects
if (!(bool)Traverse.Create(this.player.data.playerVel).Field("simulated").GetValue())
{
this.ClearEffects();
if (PhotonNetwork.OfflineMode)
{
// offline mode
this.RPCA_ClearEffects();
}
else if (base.GetComponent<PhotonView>().IsMine)
{
base.GetComponent<PhotonView>().RPC("RPCA_ClearEffects", RpcTarget.All, new object[] { });
}
return;
}
// get and apply a new effect if things are ready
Expand All @@ -97,12 +105,28 @@ void Update()
this.ready = false;
this.GetNewEffect();
this.GetNewDuration();
this.ApplyCurrentEffect();
if (PhotonNetwork.OfflineMode)
{
// offline mode
this.RPCA_ApplyCurrentEffect();
}
else if (base.GetComponent<PhotonView>().IsMine)
{
base.GetComponent<PhotonView>().RPC("RPCA_ApplyCurrentEffect", RpcTarget.All, new object[] { });
}
}
// if the duration of the effect has passed, clear all effects
else if (Time.time >= this.timeOfLastEffect + this.effectDuration)
{
this.ClearEffects();
if (PhotonNetwork.OfflineMode)
{
// offline mode
this.RPCA_ClearEffects();
}
else if (base.GetComponent<PhotonView>().IsMine)
{
base.GetComponent<PhotonView>().RPC("RPCA_ClearEffects", RpcTarget.All, new object[] { });
}
}

float rx = (float)this.rng.NextGaussianDouble();
Expand All @@ -115,7 +139,15 @@ void Update()
}
public void OnDestroy()
{
this.ClearEffects();
if (PhotonNetwork.OfflineMode)
{
// offline mode
this.RPCA_ClearEffects();
}
else if (base.GetComponent<PhotonView>().IsMine)
{
base.GetComponent<PhotonView>().RPC("RPCA_ClearEffects", RpcTarget.All, new object[] { });
}
}
public void GetNewDuration()
{
Expand Down Expand Up @@ -145,22 +177,7 @@ public void GetNewEffect()
base.GetComponent<PhotonView>().RPC("RPCA_SetNewEffectID", RpcTarget.All, new object[] { newEffectID });
}
}
public void ApplyCurrentEffect()
{
this.currentEffects = this.effectFuncs[this.effectID](this.player, this.gun, this.gunAmmo, this.data, this.health, this.gravity, this.block, this.statModifiers);

// only add a color flash if there isn't already one active
if (this.player.gameObject.GetComponent<ColorFlash>() == null)
{
ColorFlash thisColorFlash = this.player.gameObject.GetOrAddComponent<ColorFlash>();
thisColorFlash.SetNumberOfFlashes(3);
thisColorFlash.SetDuration(0.25f);
thisColorFlash.SetDelayBetweenFlashes(0.25f);
thisColorFlash.SetColorMax(Color.black);
thisColorFlash.SetColorMin(Color.black);
}
this.ResetEffectTimer();
}

public void ResetEffectTimer()
{
this.timeOfLastEffect = Time.time;
Expand All @@ -169,30 +186,7 @@ public void Destroy()
{
UnityEngine.Object.Destroy(this);
}
public void ClearEffects()
{
if (this.currentEffects != null)
{
foreach (MonoBehaviour currentEffect in this.currentEffects)
{
if (currentEffect != null)
{
Destroy(currentEffect);
}
}
}
this.currentEffects = new List<MonoBehaviour>();
if (!this.ready && this.framesWaited < this.framesToWait)
{
this.framesWaited++;
}
else if (!this.ready)
{
this.framesWaited = 0;
this.ready = true;
}

}
public List<MonoBehaviour> Effect_NoGravityEffect(Player player, Gun gun, GunAmmo gunAmmo, CharacterData data, HealthHandler health, Gravity gravity, Block block, CharacterStatModifiers characterStats)
{
GravityEffect effect = player.gameObject.GetOrAddComponent<GravityEffect>();
Expand Down Expand Up @@ -389,6 +383,48 @@ public void RPCA_SetNewDuration(float duration)
{
this.effectDuration = duration;
}
[PunRPC]
public void RPCA_ApplyCurrentEffect()
{
this.currentEffects = this.effectFuncs[this.effectID](this.player, this.gun, this.gunAmmo, this.data, this.health, this.gravity, this.block, this.statModifiers);

// only add a color flash if there isn't already one active
if (this.player.gameObject.GetComponent<ColorFlash>() == null)
{
ColorFlash thisColorFlash = this.player.gameObject.GetOrAddComponent<ColorFlash>();
thisColorFlash.SetNumberOfFlashes(3);
thisColorFlash.SetDuration(0.25f);
thisColorFlash.SetDelayBetweenFlashes(0.25f);
thisColorFlash.SetColorMax(Color.black);
thisColorFlash.SetColorMin(Color.black);
}
this.ResetEffectTimer();
}
[PunRPC]
public void RPCA_ClearEffects()
{
if (this.currentEffects != null)
{
foreach (MonoBehaviour currentEffect in this.currentEffects)
{
if (currentEffect != null)
{
Destroy(currentEffect);
}
}
}
this.currentEffects = new List<MonoBehaviour>();
if (!this.ready && this.framesWaited < this.framesToWait)
{
this.framesWaited++;
}
else if (!this.ready)
{
this.framesWaited = 0;
this.ready = true;
}

}

}
}
27 changes: 19 additions & 8 deletions PCE/MonoBehaviours/SpawnBulletsEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,39 @@ private void Shoot()
num /= (1f + this.gunToShootFrom.projectileSpeed * 0.5f) * 0.5f;
directionToShootThisBullet += Vector3.Cross(directionToShootThisBullet, Vector3.forward) * num * d;
}
GameObject gameObject = PhotonNetwork.Instantiate(this.gunToShootFrom.projectiles[i].objectToSpawn.gameObject.name, this.positionToShootFrom, Quaternion.LookRotation(directionToShootThisBullet), 0, null);

if (PhotonNetwork.OfflineMode)
if ((bool)typeof(Gun).InvokeMember("CheckIsMine", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, this.gunToShootFrom, new object[] { }))
{
typeof(ProjectileInit).InvokeMember("OFFLINE_Init_SeparateGun", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, gameObject.GetComponent<ProjectileInit>(), new object[] { base.GetComponentInParent<Player>().playerID, (int)Traverse.Create(this.gunToShootFrom).Field("gunID").GetValue(), currentNumberOfProjectiles, 1f, UnityEngine.Random.Range(0f, 1f)});
}
else
{
gameObject.GetComponent<PhotonView>().RPC("RPCA_Init_SeparateGun", RpcTarget.All, new object[]

GameObject gameObject = PhotonNetwork.Instantiate(this.gunToShootFrom.projectiles[i].objectToSpawn.gameObject.name, this.positionToShootFrom, Quaternion.LookRotation(directionToShootThisBullet), 0, null);

if (PhotonNetwork.OfflineMode)
{
typeof(ProjectileInit).InvokeMember("OFFLINE_Init_SeparateGun", BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic, null, gameObject.GetComponent<ProjectileInit>(), new object[] { base.GetComponentInParent<Player>().playerID, (int)Traverse.Create(this.gunToShootFrom).Field("gunID").GetValue(), currentNumberOfProjectiles, 1f, UnityEngine.Random.Range(0f, 1f) });

}
else
{
gameObject.GetComponent<PhotonView>().RPC("RPCA_Init_SeparateGun", RpcTarget.All, new object[]
{

base.GetComponentInParent<CharacterData>().view.OwnerActorNr,
(int)Traverse.Create(this.gunToShootFrom).Field("gunID").GetValue(),
currentNumberOfProjectiles,
1f,
UnityEngine.Random.Range(0f, 1f)
});
});
}
}
}
}
this.ResetTimer();

}
private void RPCA_Shoot(int numProj, float dmgM, float seed)
{
this.gunToShootFrom.BulletInit(base.gameObject, numProj, dmgM, seed, true);
}
public void SetGun(Gun gun)
{
this.gunToShootFrom = this.gameObject.AddComponent<Gun>();
Expand Down

0 comments on commit fa9d528

Please sign in to comment.