Ejemplo n.º 1
0
 // 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);
         }
     }
 }
Ejemplo n.º 2
0
    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;
    }
Ejemplo n.º 3
0
 /*
  * 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));
         }
     }
 }
    private void IncrementNumberOfTargets()
    {
        PullTargets.IncrementSize();
        PushTargets.IncrementSize();

        HUD.BurnPercentageMeter.SetMetalLineCountText(PullTargets.Size.ToString());
    }
    public void RemoveAllTargets()
    {
        PullTargets.Clear();
        PushTargets.Clear();

        HUD.TargetOverlayController.Clear();
    }
Ejemplo n.º 6
0
 public virtual void StopBurning()
 {
     if (IsBurning)
     {
         PullTargets.Clear();
         PushTargets.Clear();
         IronBurnPercentageTarget  = 0;
         SteelBurnPercentageTarget = 0;
         IsBurning      = false;
         lastWasPulling = false;
         lastWasPushing = false;
     }
 }
Ejemplo n.º 7
0
    /*
     * 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);
                }
            }
        }
    }
Ejemplo n.º 8
0
 public void RemovePullTargetAt(int index)
 {
     PullTargets.RemoveTargetAt(index);
 }
Ejemplo n.º 9
0
 public bool RemovePullTarget(Magnetic target)
 {
     return(PullTargets.RemoveTarget(target));
 }
Ejemplo n.º 10
0
    /*
     * 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;
            }
        }
    }
    /*
     * Read inputs for selecting targets.
     * Update burn percentages.
     * Update blue lines pointing from player to metal.
     */
    private void LateUpdate()
    {
        if (!PauseMenu.IsPaused)
        {
            // Start and Stop Burning metals
            if (IsBurning)
            {
                // Stop burning
                if (Keybinds.StopBurning())
                {
                    StopBurning();
                    timeToStopBurning = 0;
                }
                else
                if (Keybinds.Negate())
                {
                    timeToStopBurning += Time.deltaTime;
                    if (Keybinds.Select() && Keybinds.SelectAlternate() && timeToStopBurning > timeToHoldDown)
                    {
                        //if (Keybinds.IronPulling() && Keybinds.SteelPushing() && timeToStopBurning > timeToHoldDown) {
                        StopBurning();
                        timeToStopBurning = 0;
                    }
                }
                else
                {
                    timeToStopBurning = 0;
                }
            }
            else
            {
                // Start burning
                if (!Keybinds.Negate())
                {
                    if (Keybinds.SelectDown())
                    {
                        StartBurning(true);
                    }
                    else if (Keybinds.SelectAlternateDown())
                    {
                        StartBurning(false);
                    }
                }
            }

            // Could have stopped burning above. Check if the Allomancer is still burning.
            if (IsBurning)
            {
                // Change Burn Percentage Targets, Number of Targets
                // Check scrollwheel for changing the max number of targets and burn percentage, or DPad if using gamepad
                float scrollValue = 0;
                if (SettingsMenu.settingsData.controlScheme == SettingsData.Gamepad)   // Gamepad
                {
                    scrollValue = Keybinds.DPadYAxis();
                    if (SettingsMenu.settingsData.pushControlStyle == 1)
                    {
                        ChangeTargetForceMagnitude(Keybinds.DPadXAxis());
                    }
                }
                else     // Mouse and keyboard
                {
                    if (Keybinds.Negate())
                    {
                        scrollValue = Keybinds.ScrollWheelAxis();
                    }
                    else
                    {
                        if (SettingsMenu.settingsData.pushControlStyle == 0)
                        {
                            ChangeBurnPercentageTarget(Keybinds.ScrollWheelAxis());
                        }
                        else
                        {
                            ChangeTargetForceMagnitude(Keybinds.ScrollWheelAxis());
                        }
                    }
                }
                if (scrollValue > 0)
                {
                    IncrementNumberOfTargets();
                }
                if (scrollValue < 0)
                {
                    DecrementNumberOfTargets();
                }

                // Assign Burn percentage targets based on the previously changed burn percentage/target magnitudes
                if (SettingsMenu.settingsData.pushControlStyle == 0)                     // Percentage
                {
                    if (SettingsMenu.settingsData.controlScheme == SettingsData.Gamepad) // Gamepad
                    {
                        SetPullPercentageTarget(Keybinds.RightBurnPercentage());
                        SetPushPercentageTarget(Keybinds.LeftBurnPercentage());
                    }
                }
                else     // Magnitude
                {
                    if (HasPullTarget || HasPushTarget)
                    {
                        //Debug.Log(player.LastMaximumNetForce);

                        float maxNetForce = (LastMaximumNetForce).magnitude;
                        SetPullPercentageTarget(forceMagnitudeTarget / maxNetForce);
                        SetPushPercentageTarget(forceMagnitudeTarget / maxNetForce);
                    }
                    else
                    {
                        SetPullPercentageTarget(0);
                        SetPushPercentageTarget(0);
                    }
                }

                LerpToBurnPercentages();
                UpdateBurnRateMeter();

                if (Player.CanControlPlayer)
                {
                    // Could have stopped burning above. Check if the Allomancer is still burning.
                    if (IsBurning)
                    {
                        // Swap pull- and push- targets
                        if (Keybinds.NegateDown() && timeToSwapBurning > Time.time)
                        {
                            // Double-tapped, Swap targets
                            PullTargets.SwapContents(PushTargets);
                            // If vacuously targeting, swap statuses of vacuous targets
                            SwapVacuousTargets();
                        }
                        else
                        {
                            if (Keybinds.NegateDown())
                            {
                                timeToSwapBurning = Time.time + timeDoubleTapWindow;
                            }
                        }

                        // Search for Metals

                        bool pulling = Keybinds.IronPulling() && HasIron;// && !(Player.CoinshotMode && Keybinds.SteelPushing()); // in coinshot mode, you cannot push and pull simultaneously
                        bool pushing = Keybinds.SteelPushing() && HasSteel;
                        // If you are trying to push and pull and only have pullTargets, only push. And vice versa
                        if (!HasPushTarget && HasPullTarget)
                        {
                            if (pulling)
                            {
                                pushing = false;
                            }
                        }
                        else
                        if (!HasPullTarget && HasPushTarget)
                        {
                            if (pushing)
                            {
                                pulling = false;
                            }
                        }
                        IronPulling  = pulling;
                        SteelPushing = pushing;

                        // Check input for target selection
                        bool selecting = (Keybinds.Select() || Keybinds.SelectAlternate()) && !Keybinds.Negate();

                        Magnetic target = SearchForMetals();

                        if (target != null)
                        {
                            // highlight the potential target you would select, if you targeted it
                            if (target != HighlightedTarget)
                            {
                                // Remove old target
                                if (HasHighlightedTarget)
                                {
                                    HighlightedTarget.RemoveTargetGlow();
                                }
                                target.AddTargetGlow();
                                HighlightedTarget = target;
                            }
                        }
                        else
                        {
                            // no target near center of screen; remove highlighted target
                            if (HasHighlightedTarget)
                            {
                                HighlightedTarget.RemoveTargetGlow();
                            }
                            HighlightedTarget = null;
                        }

                        // Add/Remove Targets

                        // If vacuously targeting (or should be),
                        if (VacuouslyPullTargeting || !HasPullTarget)
                        {
                            // If starting to pull/push again, replace that old vacuous target with the new target
                            if (Keybinds.PullDown())
                            {
                                SetVacuousTarget(target, iron);
                            }
                            // If releasing push/pull, remove vacuous target
                            if (!Keybinds.IronPulling())
                            {
                                SetVacuousTarget(null, iron);
                            }
                        }
                        // Repeat for steel
                        if (VacuouslyPushTargeting || !HasPushTarget)
                        {
                            if (Keybinds.PushDown())
                            {
                                SetVacuousTarget(target, steel);
                            }
                            if (!Keybinds.SteelPushing())
                            {
                                SetVacuousTarget(null, steel);
                            }
                        }

                        // Manual target selection
                        if (Keybinds.Select() || Keybinds.SelectAlternate())
                        {
                            // Select or Deselect pullTarget and/or pushTarget
                            if (Keybinds.Select() && HasIron)   // Selecting pull target
                            {
                                if (selecting)
                                {
                                    AddPullTarget(target);
                                }
                                else
                                {
                                    if (RemovePullTarget(target))  // If the player is hovering over a pullTarget, instantly remove that one. Keep it highlighted.
                                    {
                                        target.AddTargetGlow();
                                    }
                                    else if (Keybinds.SelectDown() && !RemovePullTarget(target))     // If the highlighted Magnetic is not a pullTarget, remove the oldest pullTarget instead
                                    {
                                        RemovePullTargetAt(0);
                                    }
                                }
                            }
                            if (Keybinds.SelectAlternate() && HasSteel)
                            {
                                if (selecting)
                                {
                                    AddPushTarget(target);
                                }
                                else
                                {
                                    if (RemovePushTarget(target))
                                    {
                                        target.AddTargetGlow();
                                    }
                                    else if (Keybinds.SelectAlternateDown() && !RemovePushTarget(target))
                                    {
                                        RemovePushTargetAt(0);
                                    }
                                }
                            }
                        }
                        RefreshHUD();
                    }
                }
                else     // If the player is not in control, but still burning metals, show blue lines to metals.
                {
                    if (IsBurning)
                    {
                        SearchForMetals(false);
                        LerpToBurnPercentages();
                        UpdateBurnRateMeter();
                        RefreshHUD();
                    }
                }
            }
        }
    }
    /*
     * 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);
    }