Example #1
0
    /*
     * Add a target
     * If it's a pushTarget, remove it from pushTargets and move it to pullTargets
     */
    public void AddPullTarget(Magnetic target)
    {
        StartBurning(true);
        if (HasIron)
        {
            if (VacuouslyPullTargeting)
            {
                SetVacuousTarget(null, iron);
            }

            if (PushTargets.IsTarget(target))
            {
                PushTargets.RemoveTarget(target, false);
            }
            if (target != null)
            {
                if (PullTargets.AddTarget(target, this))
                {
                    CalculateForce(target, PullTargets.NetCharge(), PullTargets.SumOfCharges(), iron);
                }
            }
        }
    }
Example #2
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;
            }
        }
    }