예제 #1
0
        public bool Reload()
        {
            bool          retVal = false;
            RuntimeWeapon c      = w_manager.GetCurrent();

            if (c.curAmmo < c.w_actual.stats.base_magAmmo)
            {
                if (c.w_actual.stats.base_magAmmo <= c.curCarrying)
                {
                    c.curAmmo      = c.w_actual.stats.base_magAmmo;
                    c.curCarrying -= c.curAmmo;
                }
                else
                {
                    c.curAmmo     = c.curCarrying;
                    c.curCarrying = 0;
                }

                retVal = true;
                anim.CrossFade("Rifle Reload", 0.2f);
                states.isInteracting = true;

                if (c.w_actual.audio.reload != null)
                {
                    c.w_hook.PlayAudio(c.w_actual.audio.reload);
                }
            }


            return(retVal);
        }
예제 #2
0
        public void EquipRuntimeWeapon(RuntimeWeapon rw) //Switch weapon (Primary / secondary) + Spawn / dispawn weapon on holster
        {
            if (w_manager.GetCurrent() != null)
            {
                UnequipWeapon(w_manager.GetCurrent());
            }

            if (rw.m_instance == null)
            {
                return;
            }

            Transform p = anim.GetBoneTransform(HumanBodyBones.RightHand);

            rw.m_instance.transform.parent           = p;
            rw.m_instance.transform.localPosition    = Vector3.zero;
            rw.m_instance.transform.localEulerAngles = Vector3.zero;
            rw.m_instance.transform.localScale       = Vector3.one;

            rw.m_instance.SetActive(true);
            a_hook.EquipWeapon(rw);
            rw.w_hook.Init();

            anim.SetFloat(StaticStrings.weaponType, rw.w_actual.weaponType);
            w_manager.SetCurrent(rw);
        }
예제 #3
0
        public void CreateRuntimeWeapon(string id, ref RuntimeWeapon r_w_m)
        {
            if (r_w_m.m_instance != null)
            {
                Destroy(r_w_m.m_instance);
            }

            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            Weapon        w  = r_manager.GetWeapon(id);
            RuntimeWeapon rw = r_manager.runtime.WeaponToRuntimeWeapon(w);

            GameObject go = Instantiate(w.modelPrefab);

            rw.m_instance = go;
            rw.w_actual   = w;
            rw.w_hook     = go.GetComponent <WeaponHook>();
            //go.SetActive(false);

            Transform b = character.GetBone(rw.w_actual.holsterBone);

            go.transform.parent           = b;
            go.transform.localPosition    = Vector3.zero;
            go.transform.localEulerAngles = Vector3.zero;
            go.transform.localScale       = Vector3.one;

            r_w_m = rw;
        }
예제 #4
0
        public void UnequipWeapon(RuntimeWeapon rw) //Switch weapon (Primary / secondary) + Spawn / dispawn weapon on holster
        {
            Transform b = character.GetBone(rw.w_actual.holsterBone);

            rw.m_instance.transform.parent           = b;
            rw.m_instance.transform.localPosition    = Vector3.zero;
            rw.m_instance.transform.localEulerAngles = Vector3.zero;
            rw.m_instance.transform.localScale       = Vector3.one;
        }
예제 #5
0
        public RuntimeWeapon WeaponToRuntimeWeapon(Weapon w)
        {
            RuntimeWeapon rw = new RuntimeWeapon();

            rw.w_actual    = w;
            rw.stats       = w.stats;
            rw.curAmmo     = w.stats.GetMagAmmo();
            rw.curCarrying = w.stats.GetMaxCarrying();
            runtime_weapons.Add(rw);
            return(rw);
        }
예제 #6
0
        public void RemoveRuntimeWeapon(RuntimeWeapon rw)
        {
            if (rw.m_instance)
            {
                Destroy(rw.m_instance);
            }

            if (runtime_weapons.Contains(rw))
            {
                runtime_weapons.Remove(rw);
            }
        }
예제 #7
0
        public void EquipWeapon(RuntimeWeapon rw)
        {
            Weapon w = rw.w_actual;

            lh_target = rw.w_hook.leftHandIK;

            rh_target.localPosition    = w.m_h_ik.pos;
            rh_target.localEulerAngles = w.m_h_ik.rot;
            basePosition    = w.m_h_ik.pos;
            baseRotation    = w.m_h_ik.rot;
            onIdleDisableOh = rw.w_actual.onIdleDisableOh;
        }
예제 #8
0
        public void GetHit(StatesManager s, RuntimeWeapon c, HitPosition hp)
        {
            HumanBodyBones t = HumanBodyBones.Chest;

            if (hp != null)
            {
                t = hp.bone;
            }

            float baseDamage = c.stats.GetDamage();

            //float baseDamage = 25;


            switch (t)
            {
            case HumanBodyBones.Head:
                anim.Play("damage 2");
                baseDamage *= 2;
                baseDamage += Random.Range(-5, 5);
                break;

            case HumanBodyBones.Chest:
                anim.Play("damage 2");
                baseDamage += Random.Range(-12, 12);
                break;

            case HumanBodyBones.LeftUpperArm:
                baseDamage *= .5f;
                anim.Play("damage 1");
                baseDamage += Random.Range(-12, 12);
                break;

            case HumanBodyBones.RightUpperArm:
                baseDamage *= .5f;
                anim.Play("damage 1");
                baseDamage += Random.Range(-12, 12);
                break;
            }

            health -= Mathf.RoundToInt(baseDamage);
            if (health < 0)
            {
                a_hook.enabled = false;
                StartCoroutine(EnableRagdoll_AfterDelay(.1f));
                states.isDead = true;
            }
        }
예제 #9
0
        public bool ShootWeapon(float t)
        {
            bool retVal = false;

            RuntimeWeapon c = w_manager.GetCurrent();

            if (c.curAmmo > 0)
            {
                if (t - c.lastFired > c.w_actual.stats.base_fireRate)
                {
                    c.lastFired = t;
                    retVal      = true;
                    c.ShootWeapon();
                    a_hook.RecoilAnim();
                    HandleShootingLogic(c);
                }
            }

            return(retVal);
        }
예제 #10
0
        void HandleShootingLogic(RuntimeWeapon c)
        {
            Vector3 origin = a_hook.aimPivot.position;

            origin += a_hook.aimPivot.forward * 0.5f;


            for (int i = 0; i < c.w_actual.stats.bulletAmount; i++)
            {
                Vector3 targetPosition = inp.aimPosition;
                Vector3 offset         = mTransform.forward;
                offset += mTransform.up;

                float spread = c.w_actual.stats.GetSpread();
                spread *= 0.01f;

                if (inp.targetSpread < 0.1f)
                {
                    inp.targetSpread = 1;
                }

                spread *= inp.targetSpread;
                spread *= 0.5f;

                offset.x       *= Random.Range(-spread, spread);
                offset.y       *= Random.Range(-spread, spread);
                offset.z       *= Random.Range(-spread, spread);
                targetPosition += offset;

                Vector3    targetDirection = targetPosition - origin;
                bool       isHit           = false;
                RaycastHit hit             = Ballistics.RaycastShoot(origin, targetDirection, ref isHit, ignoreLayers);

                if (isHit)
                {
                    HandleDamage(hit, c, targetDirection);
                }
            }
        }
예제 #11
0
        void HandleDamage(RaycastHit h, RuntimeWeapon c, Vector3 d)
        {
            Rigidbody rigid = h.transform.GetComponent <Rigidbody>();

            if (rigid != null)
            {
                if (!rigid.isKinematic)
                {
                    rigid.AddForceAtPosition(d * 20, h.point, ForceMode.Impulse);
                }
            }

            StatesManager st = h.transform.GetComponentInParent <StatesManager>();

            if (st != null)
            {
                if (st != this)
                {
                    if (st.states.isDead)
                    {
                        return;
                    }

                    HitPosition hitPos = h.transform.GetComponent <HitPosition>();
                    GameObject  p      = objPool.RequestObject("BloodSplat_FX");
                    p.transform.position = h.point;
                    st.GetHit(this, c, hitPos);
                }
            }
            else
            {
                GameObject p = objPool.RequestObject("bullet_hit");
                p.transform.position = h.point;
                p.transform.LookAt(a_hook.aimPivot.position);
            }
        }
예제 #12
0
 public void  SetCurrent(RuntimeWeapon rw)
 {
     curWeapon = rw;
 }
예제 #13
0
 public void UpdatePlayerReferencesForWeapon(RuntimeWeapon r)
 {
     p_references.curAmmo.value     = r.curAmmo;
     p_references.curCarrying.value = r.curCarrying;
 }