public void LateInit() { if (this.TargetingBehavior != TargetingType.Timed) { this.cachedTransform.position = this.Position.ToVector3(); this.speedPerFrame = this.Speed / 32L; } switch (this.TargetingBehavior) { case TargetingType.Timed: if (this.Delay == 0) { this.CountDown--; this.Hit(); } else { this.CountDown = this.Delay; } break; case TargetingType.Homing: long f = this.Position.ToVector2d().Distance(this.TargetPosition); long timeToHit = f.Div(this.Speed); if (this._visualArc) { this.arcStartHeight = this.Position.z; this.arcStartVerticalSpeed = (this.TargetHeight - this.Position.z).Div(timeToHit) + timeToHit.Mul(Gravity); } else { this.linearHeightSpeed = (this.TargetHeight - Position.z).Div(timeToHit).Abs(); } break; case TargetingType.Free: Vector3d vel = this.Direction; vel.Mul(speedPerFrame); this.Velocity = vel; if (this.CanRotate) { this.cachedTransform.LookAt(this.Forward.ToVector3()); } break; } if (this.onInitialize.IsNotNull()) { this.onInitialize.Invoke(); } if (UseEffects) { EffectManager.LazyCreateEffect(this.StartEffect, this.Position.ToVector3(), this.cachedTransform.rotation); } }
private void Hit() { if (this.TargetingBehavior == TargetingType.Homing && this.HitBehavior == HitType.Single && this.Target.SpawnVersion != this.TargetVersion) { ProjectileManager.EndProjectile(this); return; } this.OnHit(); if (this.onHit.IsNotNull()) { this.onHit.Invoke(); } if (this.UseEffects) { if (this.AttachEndEffectToTarget) { LSEffect lSEffect = EffectManager.CreateEffect(this.EndEffect); lSEffect.CachedTransform.parent = this.Target.VisualCenter; lSEffect.CachedTransform.localPosition = Vector3.up; lSEffect.Initialize(); } else { { EffectManager.LazyCreateEffect(this.EndEffect, this.cachedTransform.position, this.cachedTransform.rotation); } } } ProjectileManager.EndProjectile(this); }
public void LateInit() { long f = this.Position.Distance(this.TargetPosition); this.timeToHit = f.ToFloat() / this.Speed.ToFloat(); if (this.TargetingBehavior != TargetingType.Timed) { this.cachedTransform.position = this.Position.ToVector3(this.CurrentHeight); this.speedPerFrame = this.Speed / 32L; } TrajectoryType trajectory = this.Trajectory; if (trajectory != TrajectoryType.Linear) { if (trajectory == TrajectoryType.Arc) { this.arcStartHeight = this.CurrentHeight; this.arcStartVerticalSpeed = (this.TargetHeight - this.CurrentHeight) / this.timeToHit - -9.8f * this.timeToHit; Vector2 vector = (this.TargetPosition.ToVector2() - this.Position.ToVector2()) / this.timeToHit; this.arcStartVelocity = new Vector3(vector.x, this.arcStartVerticalSpeed, vector.y); } } else { this.HeightSpeed = (this.TargetHeight - this.CurrentHeight) / this.timeToHit; } switch (this.TargetingBehavior) { case TargetingType.Timed: if (this.Delay == 0) { this.CountDown--; this.Hit(); } else { this.CountDown = this.Delay; } break; case TargetingType.Positional: this.targetDirection = this.TargetPosition - this.Position; this.targetDirection.Normalize(); this.targetDirection *= this.speedPerFrame; if (this.CanRotate) { this.cachedTransform.LookAt(this.TargetPosition.ToVector3(this.TargetHeight)); } break; } if (this.onInitialize.IsNotNull()) { this.onInitialize.Invoke(); } EffectManager.LazyCreateEffect(this.StartEffect, this.Source.CachedTransform.position); }
public void LateInit() { if (this.TargetingBehavior != TargetingType.Timed) { this.cachedTransform.position = this.Position.ToVector3(); this.speedPerFrame = this.Speed / 32L; } switch (this.TargetingBehavior) { case TargetingType.Timed: this.CountDown = this.Delay; break; case TargetingType.Positional: case TargetingType.Homing: long f = this.Position.ToVector2d().Distance(this.TargetPosition); long timeToHit = f.Div(this.Speed); if (this._visualArc) { this.arcStartHeight = this.Position.z; if (timeToHit > 0) { this.arcStartVerticalSpeed = (this.TargetHeight - this.Position.z).Div(timeToHit) + timeToHit.Mul(Gravity); } } else { if (timeToHit > 0) { this.linearHeightSpeed = (this.TargetHeight - Position.z).Div(timeToHit).Abs() / LockstepManager.FrameRate; } } Forward = TargetPosition - this.Position.ToVector2d(); Forward.Normalize(); break; case TargetingType.Free: Vector3d vel = this.Direction; vel.Mul(speedPerFrame); this.Velocity = vel; break; } if (this.CanRotate) { this.cachedTransform.LookAt(this.Direction.ToVector3()); } this.UpdateVisuals(); if (this.onInitialize.IsNotNull()) { this.onInitialize.Invoke(); } if (UseEffects) { LSEffect effect = EffectManager.LazyCreateEffect(this.StartFX, this.Position.ToVector3(), this.cachedTransform.rotation); if (effect != null) { effect.StartPos = this.Position.ToVector3(); effect.EndPos = this.TargetPosition.ToVector3(this.TargetHeight.ToFloat()); if (this.Target != null) { effect.Target = Target.transform; } } } }