public override BehaviorResult Update() { base.Update(); if (!m_initialized) { SpeculativeRigidbody specRigidbody = m_aiActor.specRigidbody; specRigidbody.OnCollision = (Action <CollisionData>)Delegate.Combine(specRigidbody.OnCollision, new Action <CollisionData>(OnCollision)); m_initialized = true; } BehaviorResult behaviorResult = base.Update(); if (behaviorResult != BehaviorResult.Continue) { return(behaviorResult); } if (!IsReady()) { return(BehaviorResult.Continue); } if (!m_aiActor.TargetRigidbody) { return(BehaviorResult.Continue); } Vector2 vector = m_aiActor.TargetRigidbody.specRigidbody.GetUnitCenter(ColliderType.HitBox); if (leadAmount > 0f) { Vector2 b = vector + m_aiActor.TargetRigidbody.specRigidbody.Velocity * 0.75f; b = BraveMathCollege.GetPredictedPosition(vector, m_aiActor.TargetVelocity, m_aiActor.specRigidbody.UnitCenter, chargeSpeed); vector = Vector2.Lerp(vector, b, leadAmount); } float num = Vector2.Distance(m_aiActor.specRigidbody.UnitCenter, vector); if (num > minRange) { if (!string.IsNullOrEmpty(primeAnim) || primeTime > 0f) { State = FireState.Priming; } else { State = FireState.Charging; } m_updateEveryFrame = true; return(BehaviorResult.RunContinuous); } return(BehaviorResult.Continue); }
private void BeginState(FireState state) { switch (state) { case FireState.Idle: if (HideGun) { m_aiShooter.ToggleGunAndHandRenderers(true, "ChargeBehavior"); } m_aiActor.BehaviorOverridesVelocity = false; m_aiAnimator.LockFacingDirection = false; break; case FireState.Priming: if (HideGun) { m_aiShooter.ToggleGunAndHandRenderers(false, "ChargeBehavior"); } m_aiAnimator.PlayUntilFinished(primeAnim, true, null, -1f, false); if (primeTime > 0f) { m_timer = primeTime; } else { m_timer = m_aiAnimator.CurrentClipLength; } if (stopDuringPrime) { m_aiActor.ClearPath(); m_aiActor.BehaviorOverridesVelocity = true; m_aiActor.BehaviorVelocity = Vector2.zero; } else { m_aiActor.BehaviorOverridesVelocity = true; m_aiActor.BehaviorVelocity = m_aiActor.specRigidbody.Velocity; } break; case FireState.Charging: if (HideGun) { m_aiShooter.ToggleGunAndHandRenderers(false, "ChargeBehavior"); } m_chargeTime = 0f; Vector2 vector = m_aiActor.TargetRigidbody.specRigidbody.GetUnitCenter(ColliderType.HitBox); if (leadAmount > 0f) { Vector2 b = vector + m_aiActor.TargetRigidbody.specRigidbody.Velocity * 0.75f; b = BraveMathCollege.GetPredictedPosition(vector, m_aiActor.TargetVelocity, m_aiActor.specRigidbody.UnitCenter, chargeSpeed); vector = Vector2.Lerp(vector, b, leadAmount); } m_aiActor.ClearPath(); m_aiActor.BehaviorOverridesVelocity = true; m_currentSpeed = ((chargeAcceleration <= 0f) ? chargeSpeed : 0f); m_chargeDirection = (vector - m_aiActor.specRigidbody.UnitCenter).ToAngle(); m_aiActor.BehaviorVelocity = BraveMathCollege.DegreesToVector(m_chargeDirection, m_currentSpeed); m_aiAnimator.LockFacingDirection = true; m_aiAnimator.FacingDirection = m_chargeDirection; m_aiActor.CollisionKnockbackStrength = chargeKnockback; m_aiActor.CollisionDamage = chargeDamage; if (hitVfx) { VFXObject vfxobject = new VFXObject(); vfxobject.effect = hitVfx; VFXComplex vfxcomplex = new VFXComplex(); vfxcomplex.effects = new VFXObject[] { vfxobject }; VFXPool vfxpool = new VFXPool(); vfxpool.type = VFXPoolType.Single; vfxpool.effects = new VFXComplex[] { vfxcomplex }; m_aiActor.CollisionVFX = vfxpool; } if (nonActorHitVfx) { VFXObject vfxobject2 = new VFXObject(); vfxobject2.effect = nonActorHitVfx; VFXComplex vfxcomplex2 = new VFXComplex(); vfxcomplex2.effects = new VFXObject[] { vfxobject2 }; VFXPool vfxpool2 = new VFXPool(); vfxpool2.type = VFXPoolType.Single; vfxpool2.effects = new VFXComplex[] { vfxcomplex2 }; m_aiActor.NonActorCollisionVFX = vfxpool2; } m_aiActor.PathableTiles = (CellTypes.FLOOR | CellTypes.PIT); if (switchCollidersOnCharge) { m_enemyCollider.CollisionLayer = CollisionLayer.TileBlocker; m_enemyHitbox.Enabled = false; m_projectileCollider.Enabled = true; } m_aiActor.DoDustUps = chargeDustUps; m_aiActor.DustUpInterval = chargeDustUpInterval; m_aiAnimator.PlayUntilFinished(chargeAnim, true, null, -1f, false); if (launchVfx) { SpawnManager.SpawnVFX(launchVfx, m_aiActor.specRigidbody.UnitCenter, Quaternion.identity); } if (trailVfx) { m_trailVfx = SpawnManager.SpawnParticleSystem(trailVfx, m_aiActor.sprite.WorldCenter, Quaternion.Euler(0f, 0f, m_chargeDirection)); if (trailVfxParent) { m_trailVfx.transform.parent = trailVfxParent; } else { m_trailVfx.transform.parent = m_aiActor.transform; } ParticleKiller component = m_trailVfx.GetComponent <ParticleKiller>(); if (component != null) { component.Awake(); } } if (bulletScript != null && !bulletScript.IsNull) { Fire(); } m_aiActor.specRigidbody.ForceRegenerate(null, null); break; case FireState.Bouncing: m_aiAnimator.PlayUntilFinished(hitAnim, true, null, -1f, false); break; } }