Ejemplo n.º 1
0
    void OnTriggerEnter(Collider other)
    {
        WeaponPickUp _PickUp = GetComponentInChildren <WeaponPickUp>();

        if (_PickUp != null)
        {
            //PartManager _PartManager = other.GetComponentInChildren<PartManager>();
            PartManager _PartManager = other.GetComponentInParent <PartManager>();
            if (_PartManager != null)
            {
                switch (_PickUp.m_Type)
                {
                case WeaponPickUp.PickUpType.Barrel:
                    _PartManager.AddBarrel(_PickUp.m_BarrelAttributes.m_Index);
                    Mesh.enabled = false;
                    aSource.PlayOneShot(aClip);
                    break;

                case WeaponPickUp.PickUpType.Stock:
                    _PartManager.AddStock(_PickUp.m_StockAttributes.m_Index);
                    Mesh.enabled = false;
                    aSource.PlayOneShot(aClip);
                    break;

                default:
                    break;
                }

                StartCoroutine(Vanish());
            }
        }
    }
Ejemplo n.º 2
0
 // Use this for initialization
 void Start()
 {
     weapon = FindObjectOfType <WeaponPickUp> ();
     gameObject.SetActive(false);
     thePC  = FindObjectOfType <PlayerController> ();
     UIM    = FindObjectOfType <UIManager> ();
     theInv = FindObjectOfType <Inventory> ();
     //weakpickUp (1);
 }
    private void OnTriggerEnter(Collider other)
    {
        WeaponPickUp weaponPickUp = other.gameObject.GetComponent <WeaponPickUp>();

        if (weaponPickUp != null)
        {
            SwitchWeapon(weaponPickUp.getWeapon());
        }
    }
Ejemplo n.º 4
0
    // Use this for initialization
    void Start()
    {
        CurrentHealth = MaxHealth;

        thePlayerStats = FindObjectOfType <PlayerStats> ();
        theQM          = FindObjectOfType <QuestManager> ();
        theWeapon      = FindObjectOfType <WeaponManager> ();
        FN             = FindObjectOfType <FloatingNumbers> ();
        WPU            = FindObjectOfType <WeaponPickUp> ();
    }
Ejemplo n.º 5
0
 public void setWeapon(GameObject cur, string name, float FireRate, bool gun, bool oneHanded, bool shotgun)
 {
     changingWeapon = true;
     curWeapon      = cur;
     pa.SetNewTorso(sc.getWeaponWalk(name), sc.getWeapon(name));
     this.gun       = gun;
     timerReset     = FireRate;
     timer          = timerReset;
     this.oneHanded = oneHanded;
     this.shotgun   = shotgun;
     curWepScr      = curWeapon.GetComponent <WeaponPickUp>();
 }
Ejemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        anim           = GetComponent <Animator> ();
        myRigidBody    = GetComponent <Rigidbody2D> ();
        sfxMan         = FindObjectOfType <SFXManager> ();
        currentArrows  = FindObjectOfType <Arrows> ();
        activateWeapon = FindObjectOfType <WeaponManager> ();
        theDM          = FindObjectOfType <DialogueManager> ();
        WPU            = FindObjectOfType <WeaponPickUp> ();

        if (!playerExists)
        {
            playerExists = true;
            DontDestroyOnLoad(transform.gameObject);
        }
        else
        {
            Destroy(gameObject);
        }

        canMove = true;

        lastMove = new Vector2(0, -1f);
    }
Ejemplo n.º 7
0
 // Start is called before the first frame update
 void Start()
 {
     weaponPickUp = GameObject.Find("Player").GetComponent <WeaponPickUp>();
     gun          = GameObject.Find("Player").GetComponent <Gun>();
 }
Ejemplo n.º 8
0
 // Start is called before the first frame update
 void Start()
 {
     weaponPickUp = GetComponent <WeaponPickUp>();
 }
Ejemplo n.º 9
0
 private void Start()
 {
     pistol       = GameObject.Find("M1911").GetComponent <Pistol>();
     weaponPickUp = GetComponent <WeaponPickUp>();
 }
Ejemplo n.º 10
0
    /*
     *
     * //
     * // Inheritted from the game's AI base class.
     * //
     *
     * public bool canAttack;
     * public bool goForGuns;
     * public bool attacking;
     * public bool dontAimWhenAttacking;
     * public float reactionTime;
     * public float reactionHitReset;
     * public float range;
     * public float heightRange;
     * public float preferredRange;
     * public float jumpOffset;
     * public float targetingSmoothing;
     * public float velocitySmoothnes;
     * public float startAttackDelay;
     * public Rigidbody target;
     * public Transform behaviourTarget;
     *
     * private Transform aimer;
     * private Fighting fighting;
     * private float counter; // Reset target after a certain amount of time (target reset ticker)
     * private Controller controller;
     * private CharacterInformation targetInformation;
     * private CharacterInformation info;
     * private Transform head;
     * private Movement movement;
     * private float reactionCounter;
     * private float velocity;
     * private ControllerHandler controllerHandler;
     *
     * public AILogic()
     * {
     *  canAttack = true;
     *  goForGuns = true;
     *  reactionTime = 0.4f;
     *  reactionHitReset = -0.5f;
     *  range = 1f;
     *  jumpOffset = 1f;
     *  velocitySmoothnes = 2f;
     *  heightRange = float.PositiveInfinity;
     * }
     *
     * private void Start()
     * {
     *  controllerHandler = ControllerHandler.Instance;
     *  controller = base.GetComponent<Controller>();
     *  info = base.GetComponent<CharacterInformation>();
     *  movement = base.GetComponent<Movement>();
     *  fighting = base.GetComponent<Fighting>();
     *  head = base.GetComponentInChildren<Head>().transform;
     *  SetStats();
     *  aimer = base.GetComponentInChildren<AimTarget>().transform.parent;
     * }
     *
     * private void SetStats()
     * {
     *  movement.forceMultiplier *= UnityEngine.Random.Range(0.5f, 1f);
     * }
     *
     */

    private void UpdateHandler()
    {
        startAttackDelay -= Time.deltaTime;
        var targetPosition = Vector3.zero;

        if (behaviourTarget)
        {
            targetPosition = behaviourTarget.position;
        }
        else if (target)
        {
            targetPosition = target.position;
        }

        // Reset target (presumably to prevent being stuck in certain sittuations)
        if (counter > 1f)
        {
            counter = UnityEngine.Random.Range(-0.5f, 0.5f);
            target  = null;
        }

        if (targetPosition != Vector3.zero && (!targetInformation || !targetInformation.isDead))
        {
            info.paceState = 0;

            if (!dontAimWhenAttacking || !fighting.isSwinging)
            {
                if (targetingSmoothing == 0f)
                {
                    aimer.rotation = Quaternion.LookRotation(targetPosition - head.position);
                }
                else
                {
                    aimer.rotation = Quaternion.Lerp(aimer.rotation, Quaternion.LookRotation(targetPosition - head.position), Time.deltaTime * (5f / targetingSmoothing));
                }
            }

            counter += Time.deltaTime;

            // Move towards the target
            if (Vector3.Distance(head.position, targetPosition) > preferredRange)
            {
                if (targetPosition.z < head.position.z)
                {
                    if (velocitySmoothnes == 0f)
                    {
                        velocity = -1f;
                    }
                    else
                    {
                        velocity = Mathf.Lerp(velocity, -1f, Time.deltaTime * (5f / velocitySmoothnes));
                    }
                }

                if (targetPosition.z > head.position.z)
                {
                    if (velocitySmoothnes == 0f)
                    {
                        velocity = 1f;
                    }
                    else
                    {
                        velocity = Mathf.Lerp(velocity, 1f, Time.deltaTime * (5f / velocitySmoothnes));
                    }
                }

                // (Work-in-progress)
                // Jump if a wall is in the way of the move direction

                //var cubeLayerBitMask = 1 << 23; // Cube bitmask
                //RaycastHit cubeHit;
                //var transformDirection = head.transform.TransformDirection(velocity * Vector3.forward);
                //if (transformDirection != Vector3.up && transformDirection != Vector3.down && Physics.Linecast(head.position, transformDirection, out cubeHit, cubeLayerBitMask) == false)
                //{
                //  Gizmos.DrawLine(head.position, transformDirection, Color.red);
                //  controller.Jump(false, false);
                //}

                controller.Move(velocity);
            }

            // Jump if the target's head is above
            if (targetPosition.y > head.position.y + jumpOffset)
            {
                controller.Jump(false, false);
            }

            attacking = false;
            if (!behaviourTarget && canAttack && startAttackDelay < 0f)
            {
                var currentAttackRange = range;
                attacking = true;

                if (Singleton <TrainerOptions> .Instance.AiAggressiveEnabled)
                {
                    reactionTime = 0.0f;
                }
                else
                {
                    reactionTime = 0.4f;
                }

                if (fighting.weapon)
                {
                    if (fighting.weapon.isGun)
                    {
                        currentAttackRange = 25f;
                        reactionTime       = 0.25f;
                    }
                    else
                    {
                        currentAttackRange = 2f;
                        reactionTime       = 0.25f;
                    }
                }

                var        cubeLayerBitMask = 1 << 23; // Cube bitmask
                RaycastHit cubeHit;
                // Check that the target is in direct line of sight and not obstructed by a wall (cube)
                if (Physics.Linecast(head.position, targetPosition, out cubeHit, cubeLayerBitMask) == false)
                {
                    // Perform an attack if the target is still present and is within range
                    if (target && Vector3.Distance(head.position, targetPosition) < currentAttackRange && targetPosition.y - head.position.y < heightRange)
                    {
                        reactionCounter += Time.deltaTime;

                        if (reactionCounter > reactionTime)
                        {
                            reactionCounter = 0f;
                            controller.Attack();
                        }
                    }
                    else if (reactionCounter > 0f)
                    {
                        reactionCounter -= Time.deltaTime;
                    }
                }
            }
        }
        else if (!behaviourTarget)
        {
            var          closestTargetDistance = 100f;
            WeaponPickUp weaponPickUp          = null;

            if (goForGuns)
            {
                weaponPickUp = UnityEngine.Object.FindObjectOfType <WeaponPickUp>();
            }

            if (weaponPickUp && weaponPickUp.transform.position.y < 10f && controller.fighting.weapon == null)
            {
                // Ensure that the AI has this type of weapon and can pick it up (some AI prefabs have less weapons than others).
                if (weaponPickUp.id < this.controller.fighting.weapons.transform.childCount)
                {
                    target = weaponPickUp.GetComponent <Rigidbody>();
                    return;
                }
            }

            // Find a PC / player to attack
            foreach (var playerController in controllerHandler.players)
            {
                if (playerController != null)
                {
                    var playerCharacterInformation = playerController.GetComponent <CharacterInformation>();

                    // Set target that is not itself and not dead.
                    if (playerController != this.controller && !playerCharacterInformation.isDead)
                    {
                        var torsoTransform = playerController.GetComponentInChildren <Torso>().transform;
                        var targetDistance = Vector3.Distance(head.position, torsoTransform.position);

                        if (targetDistance < closestTargetDistance)
                        {
                            closestTargetDistance = targetDistance;
                            target            = torsoTransform.GetComponent <Rigidbody>();
                            targetInformation = playerCharacterInformation;
                        }
                    }
                }
            }

            // Find an NPC to attack
            // Todo: The choice between attempting to first target a Player/PC or NPC could be randomized.
            // Todo: The below works, however the NPCs need to be on different GameObject layers for them to be able to collide (refer to Controller.SetCollision)

            //if (this.target == null)
            //{
            //    foreach (var characterAlive in MultiplayerManager.mGameManager.hoardHandler.charactersAlive)
            //    {
            //        if (characterAlive != null && characterAlive != this.controller)
            //        {
            //            var characterInformation = characterAlive.GetComponent<CharacterInformation>();
            //            if (!characterInformation.isDead)
            //            {
            //                var torsoTransform = characterAlive.GetComponentInChildren<Torso>().transform;
            //                var targetDistance = Vector3.Distance(this.head.position, torsoTransform.position);
            //                if (targetDistance < closestTargetDistance)
            //                {
            //                    closestTargetDistance = targetDistance;
            //                    this.target = torsoTransform.GetComponent<Rigidbody>();
            //                    this.targetInformation = characterInformation;
            //                }
            //            }
            //        }
            //    }
            //}
        }
    }