Esempio n. 1
0
    public override void Fire(GameObject owner)
    {
        GameObject newSpell = Instantiate(spellPrefab, transform.position + (transform.forward * offsetForward), transform.rotation);

        ThrownObject to = newSpell.GetComponent <ThrownObject>();

        if (to != null)
        {
            to.SetTarget(GetPlayerPos());
        }
    }
Esempio n. 2
0
    void OnTriggerStay2D(Collider2D coll)
    {
        ThrownObject to = coll.gameObject.GetComponent <ThrownObject>();

        if (coll.gameObject.CompareTag("PlayerAttack") &&
            coll.gameObject.layer != 15 &&     //PiecesCollision
            ((to != null && to.breakableBreaksOnCollision) ||
             (to == null && coll.gameObject.transform.parent.parent.parent.GetComponent <Animator>().GetBool("isAttacking"))))
        {
            BreakObject();
        }
    }
Esempio n. 3
0
    protected virtual void Awake()
    {
        _rigidbody       = this.gameObject.GetComponent <Rigidbody>();
        _damageOnTouch   = this.gameObject.GetComponent <DamageOnTouch>();
        _aiBehaviour     = this.gameObject.GetComponent <MoreMountains.LDJAM42.AIBehaviour>();
        _agentController = this.gameObject.GetComponent <AgentController>();
        _wandering       = this.gameObject.GetComponent <ProjectilesWandering>();
        _health          = this.gameObject.GetComponent <Health>();
        _thrownObject    = this.gameObject.GetComponent <ThrownObject>();

        Ripple.Stop();

        _initialDrag = _rigidbody.drag;
        _initialMass = _rigidbody.mass;
    }
Esempio n. 4
0
    public void throwWeapon()
    {
        if (weaponPossession.weaponID > -1 && weaponPossession.weaponID != 2)         //2 = Time Whip
        {
            if (throwFXObject && nextFXdelay < 0f)
            {
                GameObject FX = Instantiate(throwFXObject, transform.position, Quaternion.Euler(0f, 0f, 0f));
                nextFXdelay = MINIMUM_TIME_BETWEEN_FX;
            }

            GameObject   thrownObject       = Instantiate(weaponPossession.gameObject, transform.position, Quaternion.Euler(0f, 0f, 0f));
            ThrownObject thrownObjectScript = thrownObject.AddComponent <ThrownObject>();

            thrownObjectScript.startPos       = weaponPossession.transform.position;
            thrownObject.transform.localScale = new Vector2(2f, 2f);

            thrownObjectScript.breakableBreaksOnCollision = weaponPossession.weaponID == 0 ? false : true;

            Vector3 velocity = Vector3.zero;
            int     dir      = animator.GetInteger("direction");
            if (dir == 0)
            {
                velocity.x = 0;
                velocity.y = throwSpeed;
                thrownObject.transform.rotation = Quaternion.Euler(0f, 0f, -90f);
            }
            else if (dir == 1)
            {
                velocity.x = throwSpeed;
                velocity.y = 0;
            }
            else if (dir == 2)
            {
                velocity.x = 0;
                velocity.y = -throwSpeed;
                thrownObject.transform.rotation = Quaternion.Euler(0f, 0f, 90f);
            }
            else if (dir == 3)
            {
                velocity.x = -throwSpeed;
                velocity.y = 0;
            }
            thrownObjectScript.throwVelocity = velocity;
            thrownObjectScript.throwRotation = 0f;

            weaponPossession.weaponID = -1;
        }
    }
Esempio n. 5
0
    private bool EnemyDamageOnThrownObject(Collider2D coll, ThrownObject to)
    {
        if (coll.gameObject.name.Contains("PL_ATT"))
        {
            hpDamage = thrownObjectDamage / defenseFactor;

            //no knockback on thrown object
            knockbackValue = 0f;

            if (breakAttackOnHit)
            {
                GetComponent <EnemyAI>().stopAttacking();
            }

            isHit = true;
            OnHit.Invoke( );
            hitDirection = to.GetDirection();
            return(true);
        }
        return(false);
    }
Esempio n. 6
0
    void OnTriggerStay2D(Collider2D coll)
    {
        if (invulnerabilityTimer <= 0f)
        {
            for (int i = 0; i < hitTags.Length; i++)
            {
                if (coll.gameObject.tag == hitTags[i])
                {
                    ThrownObject to = coll.gameObject.GetComponent <ThrownObject>();

                    if (coll.gameObject.GetComponent <DamageObject>() != null ||
                        (coll.gameObject.name.Contains("EM_ATT") && (coll.gameObject.transform.parent != null && coll.gameObject.transform.parent.parent != null && coll.gameObject.transform.parent.parent != null && (coll.gameObject.transform.parent.parent.parent.GetComponent <EnemyAI>().isAttacking || coll.gameObject.transform.parent.parent.parent.GetComponent <Animator>().GetBool("isAttacking")))))
                    {
                        if (PlayerDamage(coll))
                        {
                            break;
                        }
                    }
                    else if (to != null && to.throwVelocity != Vector3.zero)
                    {
                        if (EnemyDamageOnThrownObject(coll, to))
                        {
                            break;
                        }
                    }
                    else if (coll.gameObject.transform.parent != null && coll.gameObject.transform.parent.parent != null && coll.gameObject.transform.parent.parent != null && coll.gameObject.transform.parent.parent.parent.GetComponent <Animator>().GetBool("isAttacking"))
                    {
                        if (EnemyDamage(coll))
                        {
                            break;
                        }
                    }
                }
            }
        }
    }
Esempio n. 7
0
    public override void SendCommand(HumanCharCommands command)
    {
        //following commands are not given by AI or user. All commands that will unlock the body go here

        if(IsBodyLocked)
        {
            return;
        }

        //following commands are given by AI or user, and can be locked
        CurrentAnimState.SendCommand(command);

        if(command == HumanCharCommands.Crouch)
        {
            CapsuleCollider collider = GetComponent<CapsuleCollider>();
            collider.height = 1.3f;
            collider.center = new Vector3(0, 0.6f, 0);

        }

        if(command == HumanCharCommands.StopCrouch)
        {
            CapsuleCollider collider = GetComponent<CapsuleCollider>();
            collider.height = 1.7f;
            collider.center = new Vector3(0, 1, 0);
        }

        if(command == HumanCharCommands.Aim && GetCurrentAnimWeapon() != WeaponAnimType.Unarmed && CurrentStance != HumanStances.Sprint)
        {
            if(ActionState == HumanActionStates.None)
            {
                UpperBodyState = HumanUpperBodyStates.Aim;
                MyAimIK.solver.SmoothEnable(2.5f);
                MyLeftHandIK.SmoothEnable();
                MyHeadIK.solver.SmoothDisable();
                MyAnimator.SetBool("IsAiming", true);
                //StartCoroutine(WaitAndEnableAimIK(0.2f));
            }
            else if(ActionState == HumanActionStates.SwitchWeapon)
            {
                UpperBodyState = HumanUpperBodyStates.Aim;
            }
        }

        if(command == HumanCharCommands.StopAim && ActionState == HumanActionStates.None)
        {
            UpperBodyState = HumanUpperBodyStates.Idle;
            MyAimIK.solver.SmoothDisable(9);
            MyHeadIK.solver.SmoothEnable();
            MyAnimator.SetBool("IsAiming", false);

            if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
            {
                MyLeftHandIK.SmoothDisable(9);
            }
            //Debug.Log("stopping aim");
        }

        if(command == HumanCharCommands.Sprint)
        {

            if(CurrentStance == HumanStances.Crouch || CurrentStance == HumanStances.CrouchRun)
            {
                CurrentStance = HumanStances.CrouchRun;
            }
            else
            {
                CurrentStance = HumanStances.Sprint;
                MyAimIK.solver.SmoothDisable();
                MyHeadIK.solver.SmoothDisable();
            }
        }

        if(command == HumanCharCommands.StopSprint)
        {
            if(UpperBodyState == HumanUpperBodyStates.Aim)
            {
                MyAimIK.solver.SmoothEnable();
            }

            if(CurrentStance == HumanStances.CrouchRun || CurrentStance == HumanStances.Crouch)
            {
                CurrentStance = HumanStances.Crouch;
            }
            else
            {
                CurrentStance = HumanStances.Run;
            }
            MyHeadIK.solver.SmoothEnable();
        }

        if(command == HumanCharCommands.SwitchWeapon2)
        {
            Debug.Log("current human action state " + ActionState);
            if(ActionState == HumanActionStates.None)
            {
                MyLeftHandIK.SmoothDisable(15);
                MyAimIK.solver.SmoothDisable(9);
                MyAnimator.SetInteger("WeaponType", 2);
                SwitchWeapon("AK47");

                ActionState = HumanActionStates.SwitchWeapon;
            }
        }

        if(command == HumanCharCommands.SwitchWeapon1)
        {
            if(ActionState == HumanActionStates.None)
            {
                if(UpperBodyState == HumanUpperBodyStates.Aim)
                {
                    //MyLeftHandIK.SmoothEnable();
                }
                else
                {

                }
                MyLeftHandIK.SmoothDisable(15);
                MyAimIK.solver.SmoothDisable(9);
                MyAnimator.SetInteger("WeaponType", 1);
                SwitchWeapon("44MagnumRevolver");

                ActionState = HumanActionStates.SwitchWeapon;
            }
        }

        if(command == HumanCharCommands.Unarm)
        {
            if(ActionState == HumanActionStates.None)
            {
                MyLeftHandIK.SmoothDisable();
                UpperBodyState = HumanUpperBodyStates.Idle;
                MyAimIK.solver.SmoothDisable();
                MyHeadIK.solver.SmoothEnable();
                MyAnimator.SetBool("IsAiming", false);
                MyAnimator.SetInteger("WeaponType", 0);
                SwitchWeapon("");

                ActionState = HumanActionStates.SwitchWeapon;
            }
        }

        if(command == HumanCharCommands.PullTrigger)
        {
            if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim)
            {
                return;
            }

            if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
            {
                //
                this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerPull();

            }
        }

        if(command == HumanCharCommands.ReleaseTrigger)
        {
            if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim)
            {
                return;
            }

            if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
            {
                //
                this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerRelease();

            }
        }

        if(command == HumanCharCommands.Reload)
        {
            if(ActionState == HumanActionStates.None && this.MyReference.CurrentWeapon != null)
            {
                if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
                {
                    MyAimIK.solver.SmoothDisable();
                    MyAnimator.SetTrigger("Reload");

                    MyLeftHandIK.SmoothDisable();

                }

                MyHeadIK.solver.SmoothDisable();

                ActionState = HumanActionStates.Reload;

            }
        }

        if(command == HumanCharCommands.CancelReload)
        {
            if(ActionState == HumanActionStates.Reload && this.MyReference.CurrentWeapon != null)
            {
                Debug.Log("cancel reload");
                if(UpperBodyState == HumanUpperBodyStates.Aim)
                {
                    MyAimIK.solver.SmoothEnable();
                    MyAnimator.SetTrigger("CancelReload");
                }
                else
                {
                    MyAnimator.SetTrigger("CancelReload");
                }

                if(MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
                {
                    MyLeftHandIK.SmoothEnable();
                }
                else
                {
                    Debug.Log("done reloading pistol " + UpperBodyState);
                    if(UpperBodyState == HumanUpperBodyStates.Aim)
                    {
                        MyLeftHandIK.SmoothEnable();
                    }
                    else
                    {
                        MyLeftHandIK.SmoothDisable();
                    }
                }

                MyHeadIK.solver.SmoothEnable();
                ActionState = HumanActionStates.None;
            }
        }

        if(command == HumanCharCommands.ThrowGrenade)
        {
            if(ActionState != HumanActionStates.None)
            {
                return;
            }

            if(UpperBodyState == HumanUpperBodyStates.Aim)
            {
                //MyAimIK.solver.SmoothDisable();
            }

            if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
            {
                MyLeftHandIK.SmoothEnable();
            }

            //MyHeadIK.solver.SmoothDisable(1);

            //move weapon to torso mount so that right hand is free
            if(this.MyReference.CurrentWeapon != null)
            {
                this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform;
            }
            MyAnimator.SetTrigger("ThrowGrenade");

            _throwTarget = this.AimPoint;
            _throwDir = this.AimPoint - transform.position;
            IsBodyLocked = true;

            ActionState = HumanActionStates.Throw;

            _thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load("TestGrenade"))).GetComponent<ThrownObject>();
            _thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = true;

            _thrownObjectInHand.transform.parent = this.MyReference.RightHandWeaponMount.transform;
            _thrownObjectInHand.transform.localPosition = _thrownObjectInHand.InHandPosition;
            _thrownObjectInHand.transform.localEulerAngles = _thrownObjectInHand.InHandRotation;
        }
    }
Esempio n. 8
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (type == MechanicType.Auto_Switch)
        {
            if (collision.gameObject.name.Contains("Player"))
            {
                state = true;

                triggered = weightRequired;

                if (aud != null && stateChangeSound != null && TogglesValues.sound)
                {
                    aud.PlayOneShot(stateChangeSound, state ? 1f : 0.5f);
                }
            }
        }
        else if (type == MechanicType.Switch)
        {
            ThrownObject to = collision.gameObject.GetComponent <ThrownObject>();

            if (collision.gameObject.tag == "PlayerAttack" && to == null)
            {
                if (collision.gameObject.transform.parent.parent.parent.gameObject.GetComponent <Animator>().GetBool("isAttacking"))
                {
                    state = !state;

                    triggered = weightRequired;

                    if (aud != null && stateChangeSound != null && TogglesValues.sound)
                    {
                        aud.PlayOneShot(stateChangeSound, state ? 1f : 0.5f);
                    }
                }
            }
        }
        else if (type == MechanicType.Wall_Switch)
        {
            if (collision.gameObject.tag == "PlayerAttack")
            {
                state = !state;

                ThrownObject to = collision.gameObject.GetComponent <ThrownObject>();

                if (to != null)
                {
                    collision.gameObject.tag = "Untagged";
                }

                triggered = weightRequired;

                if (aud != null && stateChangeSound != null && TogglesValues.sound)
                {
                    aud.PlayOneShot(stateChangeSound, state ? 1f : 0.5f);
                }
            }
        }
        else if (type == MechanicType.Pressure_Plate)
        {
            WeightMechanic weightMech = collision.gameObject.GetComponent <WeightMechanic>();

            if (weightMech != null)
            {
                triggered += weightMech.weight;

                bool prevState = state;
                state = triggered >= weightRequired;

                if (state != prevState)
                {
                    if (aud != null && stateChangeSound != null && TogglesValues.sound)
                    {
                        aud.PlayOneShot(stateChangeSound, state ? 1f : 0.5f);
                    }
                }
            }
        }
        else
        {
            triggered = weightRequired;
        }
    }
Esempio n. 9
0
	public override void SendCommand(CharacterCommands command)
	{
		if(!IsBodyLocked && !IsMoveLocked)
		{
			CurrentAnimState.SendCommand(command);
		}


		//following commands are not given by AI or user. All commands that will unlock the body go here
		if(command == CharacterCommands.StopAim)
		{
			if(ActionState == HumanActionStates.None)
			{
				MyAI.WeaponSystem.StopFiringRangedWeapon();
				UpperBodyState = HumanUpperBodyStates.Idle;
				MyAimIK.solver.SmoothDisable(6);
				MyHeadIK.SmoothEnable();
				MyAnimator.SetBool("IsAiming", false);
				MyReference.Flashlight.transform.localEulerAngles = new Vector3(27, 0, 0);

				if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol || GetCurrentAnimWeapon() == WeaponAnimType.Grenade)
				{
					MyLeftHandIK.InstantDisable();
				}
			}
			else
			{
				UpperBodyState = HumanUpperBodyStates.Idle;
			}

			_isHipAiming = false;
			//Debug.LogError("stopping aim " + ActionState + " " + this.name);
		}

		if(command == CharacterCommands.Cancel)
		{
			if(ActionState == HumanActionStates.Strangle)
			{
				ActionState = HumanActionStates.None;
				MyAnimator.SetTrigger("Cancel");

				Vector3 lineOfSight = _strangleTarget.transform.position - transform.position;
				transform.position = _strangleTarget.transform.position - lineOfSight.normalized;

				if(_strangleTarget.IsAlive)
				{
					_strangleTarget.IsBodyLocked = false;
					_strangleTarget.MyAnimator.SetTrigger("Cancel");
					_strangleTarget = null;
				}

				IsBodyLocked = false;
				MyNavAgent.enabled = true;

			}
		}

		if(command == CharacterCommands.RightAttack)
		{
			ActionState = HumanActionStates.Melee;
			_meleeStrikeStage = 0;

			MyAnimator.SetTrigger("RightAttack");
			IsMoveLocked = true;
			MyHeadIK.SmoothDisable(9);

			Debug.Log("starting right attack");
		}

		if(command == CharacterCommands.LeftAttack)
		{
			ActionState = HumanActionStates.Melee;
			_meleeStrikeStage = 0;

			Vector3 lookDir = LookTarget.position - transform.position;
			lookDir = new Vector3(lookDir.x, 0, lookDir.z);

			Vector3 destDir = MyNavAgent.velocity.normalized; 
			destDir = new Vector3(destDir.x, 0, destDir.z);
			float lookDestAngle = Vector3.Angle(lookDir, destDir);

			if(MyNavAgent.velocity.magnitude > 0f && lookDestAngle < 70)
			{
				MyAnimator.SetTrigger("ComboAttack");
			}
			else
			{
				MyAnimator.SetTrigger("LeftAttack");
				IsMoveLocked = true;
			}
			MyHeadIK.SmoothDisable(9);

			Debug.Log("starting left attack");
		}

		if(command == CharacterCommands.Block)
		{
			ActionState = HumanActionStates.Block;
			this.MyLeftHandIK.Target = MyReference.CurrentWeapon.GetComponent<Weapon>().ForeGrip;
			this.MyLeftHandIK.SmoothEnable(20);
			_meleeStrikeStage = 0;
			MyAnimator.SetTrigger("Block");
			IsMoveLocked = true;

		}





		if(IsBodyLocked)
		{
			return;
		}

		//following commands are given by AI or user, and can be locked


		if(command == CharacterCommands.Crouch)
		{
			CapsuleCollider collider = GetComponent<CapsuleCollider>();
			collider.height = 1f;
			collider.center = new Vector3(0, 0.5f, 0);

		}

		if(command == CharacterCommands.StopCrouch)
		{
			CapsuleCollider collider = GetComponent<CapsuleCollider>();
			collider.height = 1.7f;
			collider.center = new Vector3(0, 1, 0);
		}

	
		if((command == CharacterCommands.Aim || command == CharacterCommands.HipAim) && CurrentStance != HumanStances.Sprint)
		{
			if(MyAI.ControlType != AIControlType.Player)
				Debug.Log("action state " + ActionState + " weapon type " + GetCurrentAnimWeapon() + " upper body state " + UpperBodyState);

			if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && GetCurrentAnimWeapon() != WeaponAnimType.Unarmed && !MyAnimator.GetBool("IsAiming"))
			{
				if(MyAI.ControlType != AIControlType.Player)
					Debug.Log(command);

				if(GetCurrentAnimWeapon() == WeaponAnimType.Grenade || GetCurrentAnimWeapon() == WeaponAnimType.Tool)
				{
					MyLeftHandIK.SmoothDisable(6);
					UpperBodyState = HumanUpperBodyStates.HalfAim;
				}
				else
				{
					
					UpperBodyState = HumanUpperBodyStates.Aim;
					if(GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
					{
						MyLeftHandIK.InstantDisable();
					}
					MyLeftHandIK.SmoothEnable(6);
					MyAimIK.solver.InstantDisable();
					MyAimIK.solver.CurvedEnable(6f);
					//if(GetCurrentAnimWeapon() != WeaponAnimType.Melee)
					{
						MyHeadIK.InstantDisable();
					}
					MyAnimator.SetBool("IsAiming", true);
					if(MyAI.ControlType != AIControlType.Player)
						Debug.LogError("Animation parameter IsAiming has been set");
					MyReference.Flashlight.transform.localEulerAngles = new Vector3(0, 0, 0);
				}
					
				/*
				//draw a new grenade if there isn't one
				if(GetCurrentAnimWeapon() == WeaponAnimType.Grenade)
				{
					if(_thrownObjectInHand == null)
					{
						DrawNextGrenade();
					}
				}
				*/

			}
			else if(ActionState == HumanActionStates.SwitchWeapon)
			{
				
				if(UpperBodyState == HumanUpperBodyStates.Aim && !MyAnimator.GetBool("IsAiming"))
				{
					
					MyLeftHandIK.InstantDisable();
					MyLeftHandIK.SmoothEnable(6);
					MyAimIK.solver.InstantDisable();
					MyAimIK.solver.SmoothEnable(6f);
					MyHeadIK.InstantDisable();
					MyAnimator.SetBool("IsAiming", true);
					if(MyAI.ControlType != AIControlType.Player)
						Debug.LogError("Animation parameter IsAiming has been set");
					MyReference.Flashlight.transform.localEulerAngles = new Vector3(0, 0, 0);
				}
				else
				{
					UpperBodyState = HumanUpperBodyStates.Aim;
				}

			}
			else if(GetCurrentAnimWeapon() == WeaponAnimType.Unarmed)
			{
				SendCommand(MyAI.WeaponSystem.GetBestWeaponChoice());

			}


			if(command == CharacterCommands.HipAim)
			{
				_isHipAiming = true;
			}
			else if(command == CharacterCommands.Aim)
			{
				_isHipAiming = false;
			}
		}



		if(command == CharacterCommands.Sprint)
		{

			/*
			if(CurrentStance == HumanStances.Crouch || CurrentStance == HumanStances.CrouchRun)
			{
				CurrentStance = HumanStances.CrouchRun;
			}
			else*/
			{
				CurrentStance = HumanStances.Sprint;
				MyAimIK.solver.SmoothDisable();
				MyHeadIK.InstantDisable();
			}
		}

		if(command == CharacterCommands.StopSprint)
		{
			if(UpperBodyState == HumanUpperBodyStates.Aim)
			{
				MyAimIK.solver.SmoothEnable();
			}

			if(CurrentStance == HumanStances.CrouchRun || CurrentStance == HumanStances.Crouch)
			{
				CurrentStance = HumanStances.Crouch;
			}
			else
			{
				CurrentStance = HumanStances.Run;
			}
			MyHeadIK.SmoothEnable();
		}

		if(command == CharacterCommands.SwitchWeapon2)
		{
			if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && MyAI.WeaponSystem.PrimaryWeapon != null)
			{
				CsDebug.Inst.CharLog(this, "Start switching weapon2");
				MyLeftHandIK.SmoothDisable(15);
				MyAimIK.solver.SmoothDisable(9);

				//SwitchWeapon(Inventory.RifleSlot);
				_weaponToSwitch = Inventory.RifleSlot;
				if(MyAI.WeaponSystem.PrimaryWeapon.IsRanged)
				{
					MyAnimator.SetInteger("WeaponType", 2);
				}
				else
				{
					MyAnimator.SetInteger("WeaponType", 3);
				}

				ActionState = HumanActionStates.SwitchWeapon;
			}
		}

		if(command == CharacterCommands.SwitchWeapon1)
		{
			if((ActionState == HumanActionStates.None || ActionState == HumanActionStates.Twitch) && MyAI.WeaponSystem.SideArm != null)
			{
				if(UpperBodyState == HumanUpperBodyStates.Aim)
				{
					//MyLeftHandIK.SmoothEnable();
				}
				else
				{
					
				}
				MyLeftHandIK.SmoothDisable(15);
				MyAimIK.solver.SmoothDisable(9);
				MyAnimator.SetInteger("WeaponType", 1);
				//SwitchWeapon(Inventory.SideArmSlot);
				_weaponToSwitch = Inventory.SideArmSlot;

				ActionState = HumanActionStates.SwitchWeapon;
			}
		}

		if(command == CharacterCommands.SwitchThrown)
		{
			if(ActionState == HumanActionStates.None)
			{

				MyLeftHandIK.SmoothDisable(6);
				MyAimIK.solver.SmoothDisable(9);
				MyAnimator.SetInteger("WeaponType", -1);
				//SwitchWeapon(Inventory.ThrowSlot);
				_weaponToSwitch = Inventory.ThrowSlot;

				ActionState = HumanActionStates.SwitchWeapon;
			}
		}

		if(command == CharacterCommands.SwitchTool)
		{
			if(ActionState == HumanActionStates.None)
			{
				GameObject.Destroy(this.MyReference.CurrentWeapon);
				if(_thrownObjectInHand != null)
				{
					GameObject.Destroy(_thrownObjectInHand.gameObject);
				}

				MyLeftHandIK.SmoothDisable(6);
				MyAimIK.solver.SmoothDisable(9);
				MyAnimator.SetInteger("WeaponType", -2);
				//SwitchWeapon("ThrowingRock");

				ActionState = HumanActionStates.SwitchWeapon;
			}
		}

		if(command == CharacterCommands.Unarm)
		{
			if(ActionState == HumanActionStates.None)
			{
				MyLeftHandIK.SmoothDisable();
				UpperBodyState = HumanUpperBodyStates.Idle;
				MyAimIK.solver.SmoothDisable();
				MyHeadIK.SmoothEnable();
				MyAnimator.SetBool("IsAiming", false);
				MyAnimator.SetInteger("WeaponType", 0);
				//SwitchWeapon(null);
				_weaponToSwitch = null;

				ActionState = HumanActionStates.SwitchWeapon;
			}
		}

		if(command == CharacterCommands.PullTrigger)
		{
			if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim)
			{
				return;
			}

			if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
			{
				//
				this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerPull();


			}
		}

		if(command == CharacterCommands.ReleaseTrigger)
		{
			if(ActionState != HumanActionStates.None || UpperBodyState != HumanUpperBodyStates.Aim)
			{
				return;
			}

			if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
			{
				//
				this.MyReference.CurrentWeapon.GetComponent<Gun>().TriggerRelease();


			}
		}


		if(command == CharacterCommands.Reload)
		{
			if(ActionState == HumanActionStates.None && this.MyReference.CurrentWeapon != null)
			{
				GunMagazine magazine = this.MyReference.CurrentWeapon.GetComponent<GunMagazine>();
				if(magazine != null && magazine.AmmoLeft < magazine.MaxCapacity)
				{
					GridItemData ammo = this.Inventory.FindItemInBackpack(magazine.LoadedAmmoID);
					if(ammo != null)
					{
						if(GetCurrentAnimWeapon() == WeaponAnimType.Longgun || GetCurrentAnimWeapon() == WeaponAnimType.Pistol)
						{
							MyAimIK.solver.SmoothDisable(12);
							MyAnimator.SetInteger("ReloadType", (int)magazine.ReloadType);
							MyAnimator.SetTrigger("Reload");
							
							MyLeftHandIK.SmoothDisable();

						}

						MyHeadIK.SmoothDisable();
							
						ActionState = HumanActionStates.Reload;
					}
				}

			}
		}



		if(command == CharacterCommands.CancelReload)
		{
			if(ActionState == HumanActionStates.Reload && this.MyReference.CurrentWeapon != null)
			{
				
				Debug.Log("cancel reload");
				ActionState = HumanActionStates.None;

				if(UpperBodyState == HumanUpperBodyStates.Aim)
				{
					MyAimIK.solver.SmoothEnable();
					MyAnimator.SetTrigger("CancelReload");
				}
				else
				{
					MyAnimator.SetTrigger("CancelReload");
				}

				if(MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
				{
					MyLeftHandIK.SmoothEnable();
				}
				else
				{
					Debug.Log("done reloading pistol " + UpperBodyState);
					if(UpperBodyState == HumanUpperBodyStates.Aim)
					{
						MyLeftHandIK.SmoothEnable();
					}
					else
					{
						//MyLeftHandIK.SmoothDisable();
						SendCommand(CharacterCommands.StopAim);
					}
				}

				MyHeadIK.SmoothEnable();

			}
		}



		if(command == CharacterCommands.Throw || command == CharacterCommands.LowThrow)
		{
			if(ActionState != HumanActionStates.None)
			{
				return;
			}

			if(_thrownObjectInHand == null)
			{
				DrawNextGrenade();
			}


			MyAimIK.solver.SmoothDisable(15);
			if(command == CharacterCommands.LowThrow)
			{
				MyAnimator.SetTrigger("LowThrow");
				_isLowThrow = true;
			}
			else
			{
				MyAnimator.SetTrigger("Throw");
				_isLowThrow = false;
			}

			_throwTarget = this.AimPoint;
			Quaternion rotation = Quaternion.LookRotation(this.AimPoint - transform.position);
			transform.rotation = rotation;
			IsBodyLocked = true;
			Debug.Log("Throw triggered");
		}

		if(command == CharacterCommands.ThrowGrenade)
		{
			if(ActionState != HumanActionStates.None)
			{
				return;
			}

			if(UpperBodyState != HumanUpperBodyStates.Aim)
			{
				//MyAimIK.solver.transform = this.MyReference.TorsoWeaponMount.transform;
			}

			SendCommand(CharacterCommands.CancelReload);

			if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
			{
				MyLeftHandIK.SmoothEnable();
			}

			//MyHeadIK.SmoothDisable(1);

			//move weapon to torso mount so that right hand is free
			if(this.MyReference.CurrentWeapon != null)
			{
				this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform;
			}
			MyAnimator.SetTrigger("ThrowGrenade");

			_throwTarget = this.AimPoint;

			_throwDir = this.AimPoint - transform.position;
			IsBodyLocked = true;
			Quaternion rotation = Quaternion.LookRotation(new Vector3(_throwDir.x, 0, _throwDir.z));
			transform.rotation = rotation;

			ActionState = HumanActionStates.Throw;

			_thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load("PipeGrenade"))).GetComponent<ThrownObject>();
			Explosive explosive = _thrownObjectInHand.GetComponent<Explosive>();
			if(explosive != null)
			{
				explosive.Attacker = this;
			}

			_thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = true;

			_thrownObjectInHand.transform.parent = this.MyReference.RightHandWeaponMount.transform;
			_thrownObjectInHand.transform.localPosition = _thrownObjectInHand.InHandPosition;
			_thrownObjectInHand.transform.localEulerAngles = _thrownObjectInHand.InHandRotation;
		}

		if(command == CharacterCommands.UseTool)
		{
			if(ActionState != HumanActionStates.None || MyAI.BlackBoard.TargetEnemy == null)
			{
				return;
			}

			//check if the target enemy is close enough and angle between character and enemy is less than 45
			if(Vector3.Distance(MyAI.BlackBoard.TargetEnemy.transform.position, transform.position) > 2 || 
				Vector3.Angle(MyAI.BlackBoard.TargetEnemy.transform.forward, transform.forward) > 45)
			{
				return;
			}

			Vector3 lineOfSight = MyAI.BlackBoard.TargetEnemy.transform.position - transform.position;
			//check if angle between character facing and target line of sight is less than 45
			if(Vector3.Angle(lineOfSight, transform.forward) > 45)
			{
				return;
			}

			//stop movement
			SendCommand(CharacterCommands.Idle);
			IsBodyLocked = true;
			MyNavAgent.enabled = false;

			//place player right behind target
			transform.position = MyAI.BlackBoard.TargetEnemy.transform.position - lineOfSight.normalized * 0.25f;

			//align player facing direction to enemy's
			lineOfSight = new Vector3(lineOfSight.x, 0, lineOfSight.z);
			Quaternion rotation = Quaternion.LookRotation(lineOfSight);
			transform.rotation = rotation;

			MyAnimator.SetTrigger("Strangle");
			_strangleTarget = MyAI.BlackBoard.TargetEnemy;

			SendCommand(CharacterCommands.StopAim);
			ActionState = HumanActionStates.Strangle;
		}

		if(command == CharacterCommands.Pickup)
		{
			if(ActionState != HumanActionStates.None || MyAI.BlackBoard.PickupTarget == null)
			{
				return;
			}

			//move weapon to torso mount so that right hand is free
			if(this.MyReference.CurrentWeapon != null && MyAnimator.GetInteger("WeaponType") == (int)WeaponAnimType.Longgun)
			{
				this.MyReference.CurrentWeapon.transform.parent = this.MyReference.TorsoWeaponMount.transform;
			}
			MyAnimator.SetTrigger("TakeObject");


		}

		if(command == CharacterCommands.Loot)
		{
			if(ActionState != HumanActionStates.None)
			{
				return;
			}
			GameObject useTarget = MyAI.BlackBoard.UseTarget;
			Character target = MyAI.BlackBoard.InteractTarget;

			if(target != null && target.MyStatus.Health <= 0)
			{
				if(this.MyAI.ControlType == AIControlType.Player)
				{
					UIEventHandler.Instance.TriggerLootBody();

				}
			}
			else if(useTarget != null)
			{
				//open chest
				Chest chest = useTarget.GetComponent<Chest>();
				if(chest != null)
				{
					
					//open UI 
					UIEventHandler.Instance.TriggerLootChest();
				}
			}

		}

		if(command == CharacterCommands.Talk)
		{
			if(ActionState != HumanActionStates.None)
			{
				return;
			}
			Debug.Log("opening dialog");
			Character target = MyAI.BlackBoard.InteractTarget;

			if(target != null && target.MyStatus.Health > 0)
			{
				if(this.MyAI.ControlType == AIControlType.Player)
				{
					UIEventHandler.Instance.TriggerDialogue();

				}
			}

		}

		if(command == CharacterCommands.SetAlert)
		{
			float ambient = RenderSettings.ambientIntensity;

			if(MyAI.BlackBoard.GuardLevel == 1)
			{
				//weapon holstered; only turn on flash light (if has one) when completely dark
				if(MyReference.CurrentWeapon != null)
				{
					SendCommand(CharacterCommands.Unarm);
				}
				if(MyReference.Flashlight != null)
				{
					if(ambient <= 0.3f)
					{
						MyReference.Flashlight.Toggle(true);
					}
					else
					{
						MyReference.Flashlight.Toggle(false);
					}
				}
			}
			else if(MyAI.BlackBoard.GuardLevel >= 2)
			{
				if(MyReference.CurrentWeapon == null)
				{
					SendCommand(MyAI.WeaponSystem.GetBestWeaponChoice());
				}

				if(MyReference.Flashlight != null)
				{
					if(ambient <= 0.5f)
					{
						MyReference.Flashlight.Toggle(true);
					}
					else
					{
						MyReference.Flashlight.Toggle(false);
					}
				}
			}

		}



	}
Esempio n. 10
0
	private void DrawNextGrenade()
	{
		//first remove anything in hand already
		if(_thrownObjectInHand != null)
		{
			GameObject.Destroy(_thrownObjectInHand.gameObject);
		}

		//check what kind of item is in thrown slot
		Item throwItem = this.Inventory.ThrowSlot;
		if(throwItem == null)
		{
			//we are going to throw a rock
			_thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load("ThrowingRock"))).GetComponent<ThrownObject>();
		}
		else
		{
			
			_thrownObjectInHand = ((GameObject)GameObject.Instantiate(Resources.Load(throwItem.PrefabName))).GetComponent<ThrownObject>();
		}


		_thrownObjectInHand.Thrower = this;
		Explosive explosive = _thrownObjectInHand.GetComponent<Explosive>();
		if(explosive != null)
		{
			explosive.Attacker = this;
		}

		_thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = true;

		_thrownObjectInHand.transform.parent = this.MyReference.RightHandWeaponMount.transform;
		_thrownObjectInHand.transform.localPosition = _thrownObjectInHand.InHandPosition;
		_thrownObjectInHand.transform.localEulerAngles = _thrownObjectInHand.InHandRotation;

		//this.MyAimIK.solver.transform = _thrownObjectInHand.transform.Find("AimTransform");
		//AimTransform = this.MyAimIK.solver.transform;

		this.MyAimIK.solver.transform = this.MyReference.TorsoWeaponMount.transform;
		AimTransform = this.MyAimIK.solver.transform;
	}
Esempio n. 11
0
	public void OnThrowLeaveHand()
	{
		_thrownObjectInHand.transform.parent = null;
		Vector3 distance = _throwTarget - transform.position;

		float magnitude = Mathf.Clamp(distance.magnitude, 10, 15);
		Vector3 direction = distance.normalized;

		/*
		if(UpperBodyState == HumanUpperBodyStates.HalfAim)
		{
			//direction = MyAimIK.solver.transform.forward;
			direction = distance.normalized;
		}
		*/




		_thrownObjectInHand.transform.position = this.MyReference.RightHandWeaponMount.transform.position + direction * 1f;

		Vector3 throwForce = (direction * 2 + Vector3.up).normalized * (magnitude * 0.8f);
		if(_isLowThrow)
		{
			throwForce = direction.normalized * (magnitude * 0.8f);
		}

		_thrownObjectInHand.GetComponent<Rigidbody>().isKinematic = false;
		_thrownObjectInHand.GetComponent<Rigidbody>().AddForce(throwForce, ForceMode.Impulse);
		_thrownObjectInHand.GetComponent<Rigidbody>().AddTorque((transform.right + transform.up) * 6, ForceMode.Impulse);
		_thrownObjectInHand.IsThrown = true;
		Explosive explosive = _thrownObjectInHand.GetComponent<Explosive>();
		if(explosive != null)
		{
			explosive.IsEnabled = true;
		}


		_thrownObjectInHand = null;

		if(this.Inventory.ThrowSlot != null)
		{
			//remove either one of the items in backpack or remove the one in bodyslot
			GridItemData itemInBackpack = this.Inventory.FindItemInBackpack(this.Inventory.ThrowSlot.ID);
			if(itemInBackpack != null)
			{
				Item itemToRemove = itemInBackpack.Item;
				this.Inventory.RemoveItemFromBackpack(itemToRemove);
			}
			else
			{
				this.Inventory.ThrowSlot = null;
			}
		}
	}