Ejemplo n.º 1
0
    public void UpdateBodyStatusPlayer()
    {
        HumanCharacter player        = GameManager.Inst.PlayerControl.SelectedPC;
        float          movementSpeed = player.GetComponent <CharacterController>().velocity.magnitude;

        //stamina
        if (player.CurrentStance == HumanStances.Sprint && movementSpeed > 0.1f)
        {
            //reduce stamina
            float delta = Time.deltaTime * 20 * StaminaReduceMult;
            Stamina -= delta;
            Energy  -= delta * 1f;
            if (Stamina <= 0)
            {
                player.SendCommand(CharacterCommands.StopSprint);
            }
        }
        else if (MaxCarryWeight < CarryWeight && movementSpeed > 0.1f)
        {
            float delta = Time.deltaTime * 5 * StaminaReduceMult;
            Stamina -= delta;

            Energy -= delta * 1f;
        }
        else if (player.ActionState == HumanActionStates.None && (player.UpperBodyState == HumanUpperBodyStates.None || player.UpperBodyState == HumanUpperBodyStates.Idle))
        {
            float delta = 0;
            if (movementSpeed > 0.1f)
            {
                delta    = Time.deltaTime * StaminaRestoreSpeed * 0.5f;
                Stamina += delta;
            }
            else
            {
                delta    = Time.deltaTime * StaminaRestoreSpeed;
                Stamina += delta;
            }
        }

        if (Stamina < 0)
        {
            Stamina   = 0;
            IsResting = true;
        }
        else if (Stamina > MaxStamina)
        {
            Stamina = MaxStamina;
        }

        if (IsResting && Stamina > 20)
        {
            IsResting = false;
        }

        if (Energy < 0)
        {
            Energy = 0;
        }
        else if (Energy > MaxEnergy)
        {
            Energy = MaxEnergy;
        }
    }
Ejemplo n.º 2
0
    private void SlowUpdate()
    {
        _updateTimer   = 0;
        _updateTimeout = UnityEngine.Random.Range(1f, 4f);



        //find a new destination to move to
        Vector3 newDest;

        if (AI.RandomPoint(transform.position, new Vector3(15f, 1f, 15f), out newDest))
        {
            Agent.destination = newDest;
        }

        HumanCharacter player = GameManager.Inst.PlayerControl.SelectedPC;

        //check if player is within range and visible
        if (Vector3.Distance(player.transform.position, transform.position) < 5)
        {
            RaycastHit checkHit;
            float      colliderHeight = player.GetComponent <CapsuleCollider>().height;
            Vector3    rayTarget      = player.transform.position + Vector3.up * colliderHeight * 0.5f;
            Ray        ray            = new Ray(transform.position, rayTarget - transform.position);
            if (Physics.Raycast(ray, out checkHit))
            {
                if (checkHit.collider.gameObject == player.gameObject)
                {
                    //now move lightening target to player and apply damage
                    Arc.target = player.MyReference.TorsoWeaponMount;
                    Damage damage = new Damage();
                    damage.Type        = DamageType.Explosive;
                    damage.BlastDamage = 25;
                    damage.IsCritical  = true;
                    player.SendDamage(damage, checkHit.normal * -1, null, null);
                    PlayLighteningSound();
                    return;
                }
            }
        }

        float      dist      = 30;
        GameObject candidate = null;

        foreach (GameObject target in _targets)
        {
            float tempDist = Vector3.Distance(target.transform.position, transform.position);
            if (tempDist < dist)
            {
                candidate = target;
                dist      = tempDist;
            }

            //turn off any lights
            Lamp lamp = target.GetComponent <Lamp>();
            if (lamp != null && lamp.IsOn)
            {
                lamp.Toggle();
            }
        }

        if (candidate != null)
        {
            Arc.target = candidate;
            PlayLighteningSound();
            //check if target is a lamp
            Lamp lamp = candidate.GetComponent <Lamp>();
            if (lamp != null && !lamp.IsOn)
            {
                lamp.Toggle();
            }
            return;
        }
    }