public RuntimeWeapon WeaponToRuntimeWeapon(Weapon w, bool isLeft = false)
        {
            GameObject    go   = new GameObject();
            RuntimeWeapon inst = go.AddComponent <RuntimeWeapon> ();

            inst.instance = new Weapon();
            StaticFunction.DeepCopyWeapon(w, inst.instance);

            inst.weaponModel = Instantiate(inst.instance.modelPrefab) as GameObject;
            Transform p = states.anim.GetBoneTransform((isLeft) ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);

            inst.weaponModel.transform.parent = p;

            if (isLeft)
            {
                inst.weaponModel.transform.localPosition    = inst.instance.l_model_pos;
                inst.weaponModel.transform.localEulerAngles = inst.instance.l_model_eulers;
            }
            else
            {
                inst.weaponModel.transform.localPosition    = inst.instance.r_model_pos;
                inst.weaponModel.transform.localEulerAngles = inst.instance.r_model_eulers;
            }
            inst.weaponModel.transform.localScale = inst.instance.model_scale;

            inst.w_hook = inst.weaponModel.GetComponentInChildren <WeaponHook> ();
            inst.w_hook.InitDamageColliders(states);

            return(inst);
        }
Exemplo n.º 2
0
        public bool Reload()
        {
            RuntimeWeapon c      = w_manager.GetCurrentWeapon();
            bool          retVal = false;

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

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

            return(retVal);
        }
        public void Init(StateManager st)
        {
            states = st;

            if (rh_weapon.Count > 0)
            {
                rightHandWeapon = WeaponToRuntimeWeapon(ResourcesManager.singleton.GetWeapon(rh_weapon [0]));
            }
            if (lh_weapon.Count > 0)
            {
                leftHandWeapon    = WeaponToRuntimeWeapon(ResourcesManager.singleton.GetWeapon(lh_weapon [0]), true);
                hasLeftHandWeapon = true;
            }

            if (rightHandWeapon != null)
            {
                EquipWeapon(rightHandWeapon);
            }
            if (leftHandWeapon != null)
            {
                EquipWeapon(leftHandWeapon, true);
            }
            hasLeftHandWeapon = (leftHandWeapon != null);

            InitAllDamageCollider(st);
            CloseAllDamageColliders();

            ParryCollider pr = parryCollider.GetComponent <ParryCollider> ();

            pr.InitPlayer(st);
            CloseParryCollider();
        }
Exemplo n.º 4
0
        private void Start()
        {
            mTransform = this.transform;
            rigidbody  = GetComponent <Rigidbody>();

            if (isLocal)
            {
                rigidbody.useGravity  = false;
                rigidbody.angularDrag = 0;
                Cursor.lockState      = CursorLockMode.Locked;
                Cursor.visible        = false;

                RuntimeWeapon mw = Settings.resourcesManager.GetWeaponInstance(mainWeapon);
                RuntimeWeapon sw = Settings.resourcesManager.GetWeaponInstance(secondaryWeapon);
                Equip(mw, 0);
                weapon2 = sw;
            }
            else
            {
                //TODO: setup client references
                animator           = GetComponentInChildren <Animator>();
                ragdollColliders   = animator.transform.GetComponentsInChildren <Collider>();
                ragdollRigidbodies = animator.transform.GetComponentsInChildren <Rigidbody>();
                DisableRagdoll();
            }
        }
Exemplo n.º 5
0
        public void EquipRuntimeWeapon(RuntimeWeapon rw)
        {
            rw.m_instance.SetActive(true);
            a_hook.EquipWeapon(rw);

            anim.SetFloat(StaticStrings.WeaponType, rw.w_actual.WeaponType);
            w_manager.SetCurrentWeapon(rw);
        }
        public void Init()
        {
            runtime = new RuntimeWeapon();
            runtime.modelInstance = Instantiate(modelPrefab) as GameObject;
            runtime.weaponHook    = runtime.modelInstance.GetComponent <WeaponHook>();
            runtime.weaponHook.Init();

            ammoType = GameManagers.GetAmmoPool().GetAmmo(ammoType.name);
        }
Exemplo n.º 7
0
        public RuntimeWeapon WeaponToRuntimeWeapon(Weapon w)
        {
            RuntimeWeapon rw = new RuntimeWeapon();

            rw.w_actual    = w;
            rw.curAmmo     = w.megazineAmmo;
            rw.curCarrying = w.maxAmmo;

            runtime_weapons.Add(rw);
            return(rw);
        }
Exemplo n.º 8
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;
            onDisableOh  = rw.w_actual.onIdleDisableOh;
            basePosition = w.m_h_ik.pos;
            baseRotation = w.m_h_ik.rot;
        }
Exemplo n.º 9
0
        public void RemoveRuntimeWeapon(RuntimeWeapon rw)
        {
            if (rw.m_instance)
            {
                Destroy(rw.m_instance);
            }

            if (runtime_weapons.Contains(rw))
            {
                runtime_weapons.Remove(rw);
            }
        }
        public void EquipWeapon(RuntimeWeapon w, bool isLeft = false)
        {
            string targetIdle = w.instance.oh_idle;

            targetIdle += (isLeft) ? StaticStrings._l : StaticStrings._r;

            states.anim.SetBool(StaticStrings.mirror, isLeft);
            states.anim.Play(StaticStrings.changeWeapon);
            states.anim.Play(targetIdle);

            UI.QuickSlot uiSlot = UI.QuickSlot.singleton;
            uiSlot.UpdateSlot((isLeft) ? UI.QSlotType.lh : UI.QSlotType.rh, w.instance.icon);

            w.weaponModel.SetActive(true);
        }
Exemplo n.º 11
0
        public RuntimeWeapon GetWeaponInstance(string id)
        {
            Item item = GetItem(id);

            if ((item is Weapon) == false)
            {
                return(null);
            }

            Weapon w = (Weapon)item;

            GameObject    go     = Instantiate(w.fps_prefab);
            RuntimeWeapon retVal = go.GetComponent <RuntimeWeapon>();

            retVal.Init(w);
            go.SetActive(false);
            return(retVal);
        }
Exemplo n.º 12
0
        public bool ShootWeapon(float t)
        {
            bool retVal = false;

            RuntimeWeapon c = w_manager.GetCurrentWeapon();

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

            return(retVal);
        }
Exemplo n.º 13
0
        public void EquipWeapon(RuntimeWeapon w, bool isLeft = false)
        {
            if (isLeft)
            {
                if (leftHandWeapon != null)
                {
                    leftHandWeapon.weaponModel.SetActive(false);
                }
                //(2)
                leftHandWeapon = w;
            }
            else
            {
                if (rightHandWeapon != null)
                {
                    rightHandWeapon.weaponModel.SetActive(false);
                }
                //(2)
                rightHandWeapon = w;
            }

            string targetIdle = w.instance.oh_idle;

            targetIdle += (isLeft) ? "_l" : "_r";

            if (isLeft == true)
            {
                for (int i = 0; i < leftHandWeapon.instance.actions.Count; i++)
                {
                    leftHandWeapon.instance.actions[i].mirror = true;
                }
            }

            states.anim.SetBool("mirror", isLeft);
            states.anim.Play("changeWeapon");
            states.anim.Play(targetIdle);

            UI.QuickSlot uiSlot = UI.QuickSlot.singleton;
            uiSlot.UpdateSlot((isLeft) ? UI.QSlotType.lh : UI.QSlotType.rh, w.instance.icon);

            w.weaponModel.SetActive(true);
        }
Exemplo n.º 14
0
        public void CreateRuntimeWeapon(string id, ref RuntimeWeapon r_w_m)
        {
            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 p = anim.GetBoneTransform(HumanBodyBones.RightHand);

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

            r_w_m = rw;
        }
Exemplo n.º 15
0
        void Equip(RuntimeWeapon weapon, int pos)
        {
            if (isLocal == false)
            {
                return;
            }
            else
            {
                if (currentWeapon != null)
                {
                    currentWeapon.gameObject.SetActive(false);
                }

                if (pos == 0)
                {
                    if (weapon1 != null)
                    {
                        //TODO: drop previous weapon
                    }

                    weapon1 = weapon;
                }
                else
                {
                    if (weapon2 != null)
                    {
                        //TODO: drop previous weapon
                    }

                    weapon2 = weapon;
                }

                weapon.transform.parent        = gunParent;
                weapon.transform.localPosition = Vector3.zero;
                weapon.transform.localRotation = Quaternion.identity;
                weapon.gameObject.SetActive(true);

                currentWeapon = weapon;
            }
        }
Exemplo n.º 16
0
        public RuntimeWeapon WeaponToRuntimeWeapon(Weapon w, bool isLeft = false)
        {
            GameObject gO = new GameObject();

            gO.AddComponent <RuntimeWeapon>();
            RuntimeWeapon inst = gO.GetComponent <RuntimeWeapon>();

            inst.instance = new Weapon();
            StaticFunctions.DeepCopyWeapon(w, inst.instance);
            gO.name = w.itemName;

            inst.weaponModel = Instantiate(inst.instance.modelPrefab) as GameObject;
            Transform p = states.anim.GetBoneTransform((isLeft) ? HumanBodyBones.LeftHand : HumanBodyBones.RightHand);

            inst.weaponModel.transform.parent = p;


            inst.weaponModel.transform.localPosition =
                (isLeft) ? inst.instance.l_model_pos : inst.instance.r_model_pos;
            inst.weaponModel.transform.localEulerAngles =
                (isLeft) ? inst.instance.l_model_eulers : inst.instance.r_model_eulers;
            inst.weaponModel.transform.localScale = inst.instance.model_scale;

            inst.w_hook = inst.weaponModel.GetComponentInChildren <WeaponHook>();
            inst.w_hook.InitDamageColliders(states);

            if (isLeft)
            {
                r_l_weapons.Add(inst);
            }
            else
            {
                r_r_weapons.Add(inst);
            }

            // After populate the RuntimeWeapon, turn off the Instantiated weaponModel and let EquipWeapon handling turning on/off the weaponModel.
            inst.weaponModel.SetActive(false);
            return(inst);
        }
Exemplo n.º 17
0
 public void SetCurrentWeapon(RuntimeWeapon wp)
 {
     curWeapon = wp;
 }
Exemplo n.º 18
0
        //*********************** HEY HEY HEY (I)
        //When you first started the game, r_index & l_index will be 0, so EquipWeapon will detect the first name element in the List<string> rh_weapons or List<string> lh_weapons
        //*********************** HEY HEY HEY
        public void LoadInventory()
        {
            //____________Weapons_Init______________
            for (int i = 0; i < rh_weapons.Count; i++)
            {
                WeaponToRuntimeWeapon(ResourceManager.singleton.GetWeapon(rh_weapons[i]));
            }
            for (int i = 0; i < lh_weapons.Count; i++)
            {
                WeaponToRuntimeWeapon(ResourceManager.singleton.GetWeapon(lh_weapons[i]), true);
            }

            if (r_r_weapons.Count > 0)
            {
                if (r_index > r_r_weapons.Count - 1)
                {
                    r_index = 0;
                }

                // Passing values from List<RuntimeWeapon> to RuntimeWeapon reference variable bases on r_index (1)
                rightHandWeapon = r_r_weapons[r_index];
            }

            if (r_l_weapons.Count > 0)
            {
                if (l_index > r_l_weapons.Count - 1)
                {
                    l_index = 0;
                }

                // Passing values from List<RuntimeWeapon> to RuntimeWeapon reference variable bases on l_index (1)
                leftHandWeapon = r_l_weapons[l_index];
            }

            // Initial Equip
            if (rightHandWeapon != null)
            {
                EquipWeapon(rightHandWeapon, false);
            }
            if (leftHandWeapon != null)
            {
                EquipWeapon(leftHandWeapon, true);
            }

            hasLeftHandWeapon = (leftHandWeapon != null);


            //____________Spells_Init___________________
            for (int i = 0; i < spell_items.Count; i++)
            {
                SpellToRuntimeSpell(ResourceManager.singleton.GetSpell(spell_items[i]));
            }

            if (r_spells.Count > 0)
            {
                if (s_index > r_spells.Count - 1)
                {
                    s_index = 0;
                }

                EquipSpells(r_spells[s_index]);
            }

            //____________Consumables_Init______________
            for (int i = 0; i < consumable_items.Count; i++)
            {
                ConsumableToRuntimeConsumable(ResourceManager.singleton.GetConsumable(consumable_items[i]));
            }

            if (r_consum.Count > 0)
            {
                if (c_index > r_consum.Count - 1)
                {
                    c_index = 0;
                }

                EquipConsumable(r_consum[c_index]);
            }

            //______________Colliders_Init_______________
            InitAllDamageColliders(states);
            CloseAllDamageColliders();
        }
Exemplo n.º 19
0
 public void UpdatePlayerReferencesForWeapon(RuntimeWeapon r)
 {
     p_references.curAmmo.value     = r.curAmmo;
     p_references.curCarrying.value = r.curCarrying;
 }