/* * Remove a target, regardless of it being a pull or push target. */ public bool RemoveTarget(Magnetic target, bool startWithPullTargets = false) { // Try to remove target from both arrays, if necessary if (startWithPullTargets) { if (PullTargets.RemoveTarget(target)) { return(true); } else { return(PushTargets.RemoveTarget(target)); } } else { if (PushTargets.RemoveTarget(target)) { return(true); } else { return(PullTargets.RemoveTarget(target)); } } }
// Assign a vacuous target when none others are selected. // If target is null, stop vacuously targeting. protected void SetVacuousTarget(Magnetic target, bool usingIron = true) { if (target == null) { if (usingIron) { RemovePullTargetAt(0); VacuousPullTarget = null; } else { RemovePushTargetAt(0); VacuousPushTarget = null; } } else { if (usingIron) { RemovePullTargetAt(0); VacuousPullTarget = target; PullTargets.AddTarget(target, this); } else { RemovePushTargetAt(0); VacuousPushTarget = target; PushTargets.AddTarget(target, this); } } }
public virtual void Clear(bool clearTargets = true) { base.Clear(); if (clearTargets) { IronPulling = false; SteelPushing = false; } else // prevents calling of StopOn____Targets { ironPulling = false; steelPushing = false; } IronBurnPercentageTarget = 0; SteelBurnPercentageTarget = 0; IronPassiveBurn = 0; SteelPassiveBurn = 0; PullTargets.Clear(true, clearTargets); PushTargets.Clear(true, clearTargets); lastExpectedAllomancerAcceleration = Vector3.zero; //lastExpectedAllomancerVelocityChange = Vector3.zero; //LastExpectedAllomancerEnergyUsed = 0; LastAllomancerVelocity = Vector3.zero; LastNetForceOnAllomancer = Vector3.zero; LastAllomanticForce = Vector3.zero; LastAnchoredPushBoost = Vector3.zero; LastMaximumNetForce = Vector3.zero; }
private void IncrementNumberOfTargets() { PullTargets.IncrementSize(); PushTargets.IncrementSize(); HUD.BurnPercentageMeter.SetMetalLineCountText(PullTargets.Size.ToString()); }
public void RemoveAllTargets() { PullTargets.Clear(); PushTargets.Clear(); HUD.TargetOverlayController.Clear(); }
public virtual void StopBurning() { if (IsBurning) { PullTargets.Clear(); PushTargets.Clear(); IronBurnPercentageTarget = 0; SteelBurnPercentageTarget = 0; IsBurning = false; lastWasPulling = false; lastWasPushing = false; } }
/* * Add a target * If it's a pullTarget, remove it from pullTargets and move it to pushTargets */ public void AddPushTarget(Magnetic target) { StartBurning(false); if (HasSteel) { if (VacuouslyPushTargeting) { SetVacuousTarget(null, steel); } if (PullTargets.IsTarget(target)) { PullTargets.RemoveTarget(target, false); } if (target != null) { if (PushTargets.AddTarget(target, this)) { CalculateForce(target, PushTargets.NetCharge(), PushTargets.SumOfCharges(), steel); } } } }
public void RemovePushTargetAt(int index) { PushTargets.RemoveTargetAt(index); }
public bool RemovePushTarget(Magnetic target) { return(PushTargets.RemoveTarget(target)); }
/* * Every frame: Calculate and apply forces to targets being pushed on. * Drain metal reserves. */ private void FixedUpdate() { if (!PauseMenu.IsPaused) { if (IsBurning) { // Remove all targets that are out of pushing range // For Mouse/Keyboard, Iron and Steel burn percentages are equal, so it's somewhat redundant to specify PullTargets.RemoveAllOutOfRange(IronBurnPercentageTarget, this); PushTargets.RemoveAllOutOfRange(SteelBurnPercentageTarget, this); // Calculate net charges to know how pushes will be distributed amongst targets float netPullTargetsCharge = PullTargets.NetCharge(); float netPushTargetsCharge = PushTargets.NetCharge(); float sumPullTargetsCharge = PullTargets.SumOfCharges(); float sumPushTargetsCharge = PushTargets.SumOfCharges(); // Calculate Allomantic Forces and APBs // Execute AFs and APBs on target and Allomancer if (PullingOnPullTargets) { for (int i = 0; i < PullTargets.Count; i++) { CalculateForce(PullTargets[i], netPullTargetsCharge, sumPullTargetsCharge, iron); AddForce(PullTargets[i]); BurnIron(PullTargets[i].LastNetForceOnAllomancer.magnitude); } } else if (PushingOnPullTargets) { for (int i = 0; i < PullTargets.Count; i++) { CalculateForce(PullTargets[i], netPullTargetsCharge, sumPullTargetsCharge, steel); AddForce(PullTargets[i]); BurnSteel(PullTargets[i].LastNetForceOnAllomancer.magnitude); } } else if (HasPullTarget) { for (int i = 0; i < PullTargets.Count; i++) { CalculateForce(PullTargets[i], netPullTargetsCharge, sumPullTargetsCharge, iron); } } if (PullingOnPushTargets) { for (int i = 0; i < PushTargets.Count; i++) { CalculateForce(PushTargets[i], netPushTargetsCharge, sumPushTargetsCharge, iron); AddForce(PushTargets[i]); BurnIron(PushTargets[i].LastNetForceOnAllomancer.magnitude); } } else if (PushingOnPushTargets) { for (int i = 0; i < PushTargets.Count; i++) { CalculateForce(PushTargets[i], netPushTargetsCharge, sumPushTargetsCharge, steel); AddForce(PushTargets[i]); BurnSteel(PushTargets[i].LastNetForceOnAllomancer.magnitude); } } else if (HasPushTarget) { for (int i = 0; i < PushTargets.Count; i++) { CalculateForce(PushTargets[i], netPushTargetsCharge, sumPushTargetsCharge, steel); } } // Consume iron or steel for passively burning, depending on which metal was last used to push/pull if (HasIron && lastWasPulling || !HasSteel) { IronReserve.Mass += IronPassiveBurn * gramsPerSecondPassiveBurn * Time.fixedDeltaTime; } else if (HasSteel && lastWasPushing || !HasIron) { SteelReserve.Mass += SteelPassiveBurn * gramsPerSecondPassiveBurn * Time.fixedDeltaTime; } else { IronReserve.Mass += IronPassiveBurn * gramsPerSecondPassiveBurn * Time.fixedDeltaTime / 2; SteelReserve.Mass += SteelPassiveBurn * gramsPerSecondPassiveBurn * Time.fixedDeltaTime / 2; } // If out of metals, stop burning. if (!HasIron) { if (HasPullTarget) { PullTargets.Clear(); } if (!HasSteel) { StopBurning(); } } if (!HasSteel) { if (HasPushTarget) { PushTargets.Clear(); } } lastWasPulling = (lastWasPulling || IronPulling) && !SteelPushing; lastWasPushing = (lastWasPushing || SteelPushing) && !IronPulling; // Update variables for calculating APBs and the like for next frame LastAllomancerVelocity = rb.velocity; LastAllomanticForce = thisFrameAllomanticForce; thisFrameAllomanticForce = Vector3.zero; LastAnchoredPushBoost = thisFrameAnchoredPushBoost; thisFrameAnchoredPushBoost = Vector3.zero; LastMaximumNetForce = thisFrameMaximumNetForce; thisFrameMaximumNetForce = Vector3.zero; LastNetForceOnAllomancer = LastAllomanticForce + LastAnchoredPushBoost; lastExpectedAllomancerAcceleration = LastNetForceOnAllomancer / rb.mass; } } }
/* * Searches all Magnetics in the scene for those that are within detection range of the player. * Shows metal lines drawing from them to the player. * Returns the Magnetic "closest" of these to the center of the screen. * * If targetedLineColors is false, then push/pullTargets will not have specially colored lines (i.e. red, green, light blue) * * Rules for the metal lines: * - The WIDTH of the line is dependant on the MASS of the target * - The BRIGHTNESS of the line is dependent on the DISTANCE from the player * - The LIGHT SABER FACTOR is dependent on the FORCE acting on the target. If the metal is not a target, it is 1. */ public Magnetic SearchForMetals(bool targetedLineColors = true) { float greatestWeight = 0; Magnetic centerObject = null; bool mustCalculateCenter = true; // If the player is directly looking at a magnetic's collider //if (Physics.SphereCast(CameraController.ActiveCamera.transform.position, .5f, CameraController.ActiveCamera.transform.forward, out RaycastHit hit, 500, GameManager.Layer_IgnorePlayer)) { if (Physics.Raycast(CameraController.ActiveCamera.transform.position, CameraController.ActiveCamera.transform.forward, out RaycastHit hit, 500, GameManager.Layer_IgnorePlayer)) { Magnetic target = hit.collider.GetComponentInParent <Magnetic>(); if (target && target.IsInRange(this, GreaterPassiveBurn)) { centerObject = target; mustCalculateCenter = false; } } // If the player is not directly looking at a magnetic, select the one closest to the center of the screen for (int i = 0; i < GameManager.MagneticsInScene.Count; i++) { Magnetic target = GameManager.MagneticsInScene[i]; if (target.isActiveAndEnabled && target != Player.PlayerMagnetic) { if (mustCalculateCenter) // If player is not directly looking at magnetic, calculate which is closest { float weight = SetLineProperties(target); // If looking for the object at the center of the screen // If the Magnetic could be targeted if (targetedLineColors && weight > lineWeightThreshold) { // IF the new Magnetic is closer to the center of the screen than the previous most-center Magnetic // and IF the new Magnetic is in range if (weight > greatestWeight) { greatestWeight = weight; centerObject = target; } } } else // If player is directly looking at magnetic, just set line properties { SetLineProperties(target); } } } if (centerObject) { // Make the blue line to the center object brighter centerObject.BrightenLine(); } if (targetedLineColors) { // Update metal lines for Pull/PushTargets if (PullingOnPullTargets) { PullTargets.UpdateBlueLines(true, IronBurnPercentageTarget, CenterOfMass); } else if (PushingOnPullTargets) { PullTargets.UpdateBlueLines(true, SteelBurnPercentageTarget, CenterOfMass); } else if (HasPullTarget) { PullTargets.UpdateBlueLines(true, 0, CenterOfMass); } if (PullingOnPushTargets) { PushTargets.UpdateBlueLines(false, IronBurnPercentageTarget, CenterOfMass); } else if (PushingOnPushTargets) { PushTargets.UpdateBlueLines(false, SteelBurnPercentageTarget, CenterOfMass); } else if (HasPushTarget) { PushTargets.UpdateBlueLines(false, 0, CenterOfMass); } } return(centerObject); }