/// <summary> /// Gets the state as a string. /// </summary> public string GetStateAsString(ForceFieldState state) { string stateAsString = ""; switch (state) { case ForceFieldState.Offline: stateAsString = "offline"; break; case ForceFieldState.Initializing: stateAsString = "initializing"; break; case ForceFieldState.Charging: stateAsString = "charging"; break; case ForceFieldState.Sustaining: stateAsString = "sustaining"; break; case ForceFieldState.Discharging: stateAsString = "discharging"; break; } return(stateAsString); }
/// <summary> /// Gets the state as a string. /// </summary> public string GetStateAsString(ForceFieldState state) { string stateAsString = ""; switch (state) { case ForceFieldState.Offline: stateAsString = "offline"; break; case ForceFieldState.Initializing: int initializationProgressInPercent = Mathf.RoundToInt(((float)this.initializationElapsedTimeInTicks / (float)this.properties.initializationDurationInTicks) * 100f); stateAsString = "initializing (" + initializationProgressInPercent + " %)"; break; case ForceFieldState.Charging: stateAsString = "charging"; break; case ForceFieldState.Sustaining: stateAsString = "sustaining"; if ((this.forceFieldCharge < this.properties.forceFieldMaxCharge) && ((this.powerComp.PowerNet.CurrentEnergyGainRate() / CompPower.WattsToWattDaysPerTick) < -this.properties.powerOutputDuringCharge)) { stateAsString += " (not enough power to charge)"; } break; case ForceFieldState.Discharging: stateAsString = "discharging"; break; } return(stateAsString); }
public void TreatRocketProjectile(ProjectileWithAngle projectileWithAngle) { float rocketAbsorbtionCost = this.properties.forceFieldMaxCharge * this.properties.rocketAbsorbtionProportion; if (this.forceFieldCharge > rocketAbsorbtionCost) { this.forceFieldCharge -= rocketAbsorbtionCost; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; SoundDefOf.EnergyShield_Broken.PlayOneShot(new TargetInfo(projectileWithAngle.projectile.Position, this.Map)); } SoundInfo soundInfo = SoundInfo.InMap(new TargetInfo(projectileWithAngle.projectile.Position, this.Map), MaintenanceType.None); SoundDefOf.Thunder_OnMap.PlayOneShot(soundInfo); GenExplosion.DoExplosion(projectileWithAngle.projectile.Position, this.Map, 1.9f, DamageDefOf.Flame, projectileWithAngle.projectile); projectileWithAngle.projectile.Destroy(); ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition); } else { // Force field charge is too low to repel a rocket. this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } }
/// <summary> /// Reset shield when moving it. /// </summary> public override void DeSpawn(DestroyMode mode = DestroyMode.Vanish) { this.effectCells.Clear(); this.forceFieldState = ForceFieldState.Offline; this.forceFieldCharge = 0; base.DeSpawn(mode); }
public ForceField(Vector2 position, int crystalRequired) : base(position) { this._forceFieldState = new ActiveState(this); this._crystalRequired = crystalRequired; this._animationPlayer = new LoopedAnimation(this, "Sprites/Props/ForceField", 6); this.Properties.Set(GameObjectProperties.EffectOfShot, EffectOfShot.Reflection); this.Properties.Set(GameObjectProperties.DrawOrder, (int)SpriteDrawOrder.ForceField); this.Properties.Set(GameObjectProperties.DeadlyToTouch, true); }
public void TreatStandardProjectile(ProjectileWithAngle projectileWithAngle) { this.forceFieldCharge -= projectileWithAngle.projectile.def.projectile.damageAmountBase; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } projectileWithAngle.projectile.Destroy(); ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition); }
public void TreatStandardProjectile(ProjectileWithAngle projectileWithAngle) { this.forceFieldCharge -= projectileWithAngle.projectile.def.projectile.GetDamageAmount(1f); if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; SoundDefOf.EnergyShield_Broken.PlayOneShot(new TargetInfo(projectileWithAngle.projectile.Position, this.Map)); } else { SoundDefOf.EnergyShield_AbsorbDamage.PlayOneShot(new TargetInfo(projectileWithAngle.projectile.Position, this.Map)); } projectileWithAngle.projectile.Destroy(); ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition); }
public void TreatRocketProjectile(ProjectileWithAngle projectileWithAngle) { float rocketAbsorbtionCost = ForceFieldGeneratorProperties.forceFieldMaxCharge * ForceFieldGeneratorProperties.rocketAbsorbtionProportion; if (this.forceFieldCharge > rocketAbsorbtionCost) { this.forceFieldCharge -= rocketAbsorbtionCost; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } SoundInfo soundInfo = SoundInfo.InWorld(projectileWithAngle.projectile.Position, MaintenanceType.None); SoundDefOf.Thunder_OnMap.PlayOneShot(soundInfo); GenExplosion.DoExplosion(projectileWithAngle.projectile.Position, 1.9f, DamageDefOf.Flame, null, null, null); projectileWithAngle.projectile.Destroy(); ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition); } else { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } }
public void TreatExplosiveProjectile(ProjectileWithAngle projectileWithAngle) { if (this.forceFieldCharge < ForceFieldGeneratorProperties.explosiveRepelCharge) { // Force field charge is too low to repell an explosive. return; } this.forceFieldCharge -= ForceFieldGeneratorProperties.explosiveRepelCharge; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } Projectile deflectedProjectile = ThingMaker.MakeThing(projectileWithAngle.projectile.def) as Projectile; GenSpawn.Spawn(deflectedProjectile, projectileWithAngle.projectile.Position); float rebounceAngleInDegrees = (180f - projectileWithAngle.incidentAngle); float rebounceAngleInRadians = (float)(rebounceAngleInDegrees * Math.PI / 180f); float rebounceVectorMagnitude = Rand.Range(1.5f, 3.5f); Vector3 rebounceVector = new Vector3(0f, 0f, 0f); float xSign = +1f; float zSign = +1f; Thing projectileLauncher = ReflectionHelper.GetInstanceField(typeof(Projectile), projectileWithAngle.projectile, "launcher") as Thing; if (projectileLauncher == null) { Log.Warning("M&Co. ForceField mod: projectileLauncher is null!"); return; } if (this.Rotation == Rot4.North) { if (projectileWithAngle.projectile.Position.x >= projectileLauncher.Position.x) { xSign = +1f; } else { xSign = -1f; } zSign = +1f; } else if (this.Rotation == Rot4.East) { if (projectileWithAngle.projectile.Position.z >= projectileLauncher.Position.z) { zSign = +1f; } else { zSign = -1f; } xSign = +1f; } else if (this.Rotation == Rot4.South) { if (projectileWithAngle.projectile.Position.x >= projectileLauncher.Position.x) { xSign = +1f; } else { xSign = -1f; } zSign = -1f; } else // West. { if (projectileWithAngle.projectile.Position.z >= projectileLauncher.Position.z) { zSign = +1f; } else { zSign = -1f; } xSign = -1f; } rebounceVector = new Vector3(xSign * rebounceVectorMagnitude * (float)Math.Sin(rebounceAngleInRadians), 0f, zSign * rebounceVectorMagnitude * (float)Math.Cos(rebounceAngleInRadians)); TargetInfo rebounceCell = new TargetInfo((projectileWithAngle.projectile.ExactPosition + rebounceVector).ToIntVec3()); deflectedProjectile.Launch(this, projectileWithAngle.projectile.ExactPosition, rebounceCell); projectileWithAngle.projectile.Destroy(); ActivateMatrixAbsorbtionEffect(projectileWithAngle.projectile.ExactPosition); }
// ===================== Main treatment ===================== public override void Tick() { base.Tick(); if (this.powerComp.PowerOn) { switch (this.forceFieldState) { case ForceFieldState.Offline: this.powerComp.powerOutputInt = -10; if (((this.powerComp.PowerNet.CurrentEnergyGainRate() / CompPower.WattsToWattDaysPerTick) >= -ForceFieldGeneratorProperties.powerOutputDuringInitialization) || (this.powerComp.PowerNet.CurrentStoredEnergy() > 0)) { this.initializationElapsedTimeInTicks = 0; this.forceFieldState = ForceFieldState.Initializing; } break; case ForceFieldState.Initializing: this.powerComp.powerOutputInt = ForceFieldGeneratorProperties.powerOutputDuringInitialization; this.initializationElapsedTimeInTicks++; if (this.initializationElapsedTimeInTicks >= ForceFieldGeneratorProperties.initializationDurationInTicks) { this.forceFieldState = ForceFieldState.Charging; this.forceFieldCharge = (10f / 100) * ForceFieldGeneratorProperties.forceFieldMaxCharge; } break; case ForceFieldState.Charging: this.powerComp.powerOutputInt = ForceFieldGeneratorProperties.powerOutputDuringCharge; this.forceFieldCharge += ForceFieldGeneratorProperties.forceFieldMaxCharge / (float)ForceFieldGeneratorProperties.chargeDurationInTicks; if (this.forceFieldCharge >= ForceFieldGeneratorProperties.forceFieldMaxCharge) { this.forceFieldCharge = ForceFieldGeneratorProperties.forceFieldMaxCharge; this.forceFieldState = ForceFieldState.Sustaining; } break; case ForceFieldState.Sustaining: this.powerComp.powerOutputInt = ForceFieldGeneratorProperties.powerOutputDuringSustain; if (this.forceFieldCharge < ForceFieldGeneratorProperties.forceFieldMaxCharge) { this.forceFieldState = ForceFieldState.Charging; } break; case ForceFieldState.Discharging: this.powerComp.powerOutputInt = ForceFieldGeneratorProperties.powerOutputDuringDischarge; if ((this.powerComp.PowerNet.CurrentEnergyGainRate() / CompPower.WattsToWattDaysPerTick) >= -ForceFieldGeneratorProperties.powerOutputDuringCharge) { this.forceFieldState = ForceFieldState.Charging; } else { this.forceFieldCharge -= ForceFieldGeneratorProperties.forceFieldMaxCharge / (float)ForceFieldGeneratorProperties.dischargeDurationInTicks; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } } break; } } else // Power is off. { switch (this.forceFieldState) { case ForceFieldState.Offline: this.powerComp.powerOutputInt = -10; break; case ForceFieldState.Initializing: this.forceFieldState = ForceFieldState.Offline; break; case ForceFieldState.Charging: case ForceFieldState.Sustaining: this.forceFieldState = ForceFieldState.Discharging; break; case ForceFieldState.Discharging: this.powerComp.powerOutputInt = ForceFieldGeneratorProperties.powerOutputDuringDischarge; this.forceFieldCharge -= ForceFieldGeneratorProperties.forceFieldMaxCharge / (float)ForceFieldGeneratorProperties.dischargeDurationInTicks; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } break; } } if (this.forceFieldCharge > 0) { TryAbsorbIncomingProjectiles(); } ComputeDrawingParameters(); }
// ===================== Main treatment ===================== /// <summary> /// Adjust power consumption acording to the state. /// Try to absorb a projectile if force field is charged. /// </summary> public override void Tick() { base.Tick(); if (this.powerComp.PowerOn) { switch (this.forceFieldState) { case ForceFieldState.Offline: this.powerComp.powerOutputInt = -10; // Just a small energy drain so it only starts initialization when power is available. if (PowerGridHasEnoughPower(this.properties.powerOutputDuringInitialization)) { this.initializationElapsedTimeInTicks = 0; this.forceFieldState = ForceFieldState.Initializing; } break; case ForceFieldState.Initializing: this.powerComp.powerOutputInt = this.properties.powerOutputDuringInitialization; this.initializationElapsedTimeInTicks++; if (this.initializationElapsedTimeInTicks >= this.properties.initializationDurationInTicks) { this.forceFieldState = ForceFieldState.Sustaining; this.forceFieldCharge = Mathf.Max((10f / 100f) * this.properties.forceFieldMaxCharge, this.forceFieldCharge); SoundDefOf.EnergyShield_Reset.PlayOneShot(new TargetInfo(this.Position, this.Map)); } break; case ForceFieldState.Sustaining: this.powerComp.powerOutputInt = this.properties.powerOutputDuringSustain; if ((this.forceFieldCharge < this.properties.forceFieldMaxCharge) && PowerGridHasEnoughPower(this.properties.powerOutputDuringCharge - this.properties.powerOutputDuringSustain)) { this.forceFieldState = ForceFieldState.Charging; } break; case ForceFieldState.Charging: this.powerComp.powerOutputInt = this.properties.powerOutputDuringCharge; this.forceFieldCharge += this.properties.forceFieldMaxCharge / (float)this.properties.chargeDurationInTicks; if (this.forceFieldCharge >= this.properties.forceFieldMaxCharge) { this.forceFieldCharge = this.properties.forceFieldMaxCharge; this.forceFieldState = ForceFieldState.Sustaining; } break; case ForceFieldState.Discharging: this.powerComp.powerOutputInt = this.properties.powerOutputDuringSustain; if (PowerGridHasEnoughPower(this.properties.powerOutputDuringSustain)) { this.forceFieldState = ForceFieldState.Sustaining; } else { this.forceFieldCharge -= this.properties.forceFieldMaxCharge / (float)this.properties.dischargeDurationInTicks; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } } break; } } else // Power is off. { switch (this.forceFieldState) { case ForceFieldState.Offline: this.powerComp.powerOutputInt = -10; break; case ForceFieldState.Initializing: this.forceFieldState = ForceFieldState.Offline; break; case ForceFieldState.Charging: case ForceFieldState.Sustaining: this.forceFieldState = ForceFieldState.Discharging; break; case ForceFieldState.Discharging: this.powerComp.powerOutputInt = this.properties.powerOutputDuringSustain; this.forceFieldCharge -= this.properties.forceFieldMaxCharge / (float)this.properties.dischargeDurationInTicks; if (this.forceFieldCharge <= 0) { this.forceFieldCharge = 0; this.forceFieldState = ForceFieldState.Offline; } break; } } if (this.forceFieldCharge > 0) { TryAbsorbIncomingProjectiles(); } UpdateDrawingParameters(); }
/// <summary> /// Gets the state as a string. /// </summary> public string GetStateAsString(ForceFieldState state) { string stateAsString = ""; switch (state) { case ForceFieldState.Offline: stateAsString = "offline"; break; case ForceFieldState.Initializing: stateAsString = "initializing"; break; case ForceFieldState.Charging: stateAsString = "charging"; break; case ForceFieldState.Sustaining: stateAsString = "sustaining"; break; case ForceFieldState.Discharging: stateAsString = "discharging"; break; } return (stateAsString); }