예제 #1
0
    public void Update()
    {
        RuntimeWeapon rw = playerController.playerWeapon.GetCurrent();

        iconWeapon.sprite = rw.weapon.icon;
        textAmmo.text     = rw.curAmmo + "/" + rw.curCarryingAmmo;
    }
예제 #2
0
    void HandleShooting(RuntimeWeapon c)
    {
        //Vector3 origin = animatorHook.aimPivot.position;
        Vector3 origin = playerCamera.rayCamera.position;

        origin += playerCamera.rayCamera.forward * 0.5f;

        Vector3 targetPosition  = inputVariables.aimPosition;
        Vector3 targetDirection = targetPosition - origin;

        bool isHit = false;

        Debug.DrawRay(origin, targetPosition);
        RaycastHit hit = Ballistics.RaycastShoot(origin, targetDirection, ref isHit, ignoreLayer);

        //RaycastHit hit;
        //if (Physics.Raycast(origin, targetDirection, out hit, 200, ignoreLayer))

        /*
         * if (Physics.Raycast(origin, targetDirection, out hit, 100, ignoreLayer))
         * {
         *  isHit = true;
         * }
         */


        if (isHit)
        {
            HandleBulletHit(hit, c);
        }
    }
예제 #3
0
        public void Init(StateManager st)
        {
            states = st;

            if (rh_weapons.Count > 0)
            {
                rightHandWeapon = WeaponToRuntimeWeapon(ResourcesManager.singleton.GetWeapon(rh_weapons[0]));
            }

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

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

            hasLeftHandWeapon = (leftHandWeapon != null);

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

            pr.InitPlayer(st);
            CloseParryCollider();
        }
예제 #4
0
    public bool Reload()
    {
        bool          retVal = false;
        RuntimeWeapon c      = playerWeapon.GetCurrent();

        if (c.curAmmo < c.weapon.magazineAmmo)
        {
            playerWeapon.GetCurrent().m_instance.SendMessage("OnReloadStart", 0, SendMessageOptions.DontRequireReceiver);

            if (c.weapon.magazineAmmo <= c.curCarryingAmmo)
            {
                c.curAmmo          = c.weapon.magazineAmmo;
                c.curCarryingAmmo -= c.curAmmo;
            }
            else
            {
                c.curAmmo         = c.curCarryingAmmo;
                c.curCarryingAmmo = 0;
            }

            retVal = true;
            animator.CrossFade("Rifle Reload", 0.2f);
            controllerStates.isAiming      = false;
            controllerStates.isInteracting = true;
        }

        return(retVal);
    }
예제 #5
0
        void EquipWeapon(RuntimeWeapon rw, bool isLeft)
        {
            Vector3   p   = Vector3.zero;
            Vector3   e   = Vector3.zero;
            Vector3   s   = new Vector3(35, 35, 35);
            Transform par = null;

            if (isLeft)
            {
                p   = rw.w_actual.lh_position.pos;
                e   = rw.w_actual.lh_position.eulers;
                par = anim.GetBoneTransform(HumanBodyBones.LeftHand);
            }
            else
            {
                p   = rw.w_actual.rh_position.pos;
                e   = rw.w_actual.rh_position.eulers;
                par = anim.GetBoneTransform(HumanBodyBones.RightHand);
            }
            rw.instance.transform.parent           = par;
            rw.instance.transform.localPosition    = p;
            rw.instance.transform.localEulerAngles = e;
            rw.instance.transform.localScale       = s;

            rw.instance.SetActive(true);
        }
예제 #6
0
    public void EquipWeapon(RuntimeWeapon w, bool isLeft = false)
    {
        if (isLeft)
        {
            if (leftHandWeapon != null)
            {
                leftHandWeapon.weaponModel.SetActive(false);
            }

            leftHandWeapon = w;
        }
        else
        {
            if (rightHandWeapon != null)
            {
                rightHandWeapon.weaponModel.SetActive(false);
            }

            rightHandWeapon = w;
        }

        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;
        Item         i      = ResourcesManager.singleton.GetItem(w.instance.item_id, ItemType.weapon);

        uiSlot.UpdateSlot((isLeft) ? UI.QSlotType.lh : UI.QSlotType.rh, i.icon);
        w.weaponModel.SetActive(true);
    }
예제 #7
0
    public void RemoveRuntimeWeapon(RuntimeWeapon rw)
    {
        //if (rw.m_instance)
        //    Destroy(rw.m_instance);

        if (runtimeWeapons.Contains(rw))
        {
            runtimeWeapons.Remove(rw);
        }
    }
예제 #8
0
		public string topHalfAnimatorLayerName = "RevolverTopHalf"; //for custom animations

		//Will Instiate Runtime Object of this Scriptable Object
		public void Init()
		{
			runtime = new RuntimeWeapon();

			CreateModel();


			runtime.lastFired = 0;
			runtime.currentBullets = numBullets;
			runtime.magazineCapacity = magazineCapacity;
			runtime.magazineSize = magazineCapacity;
		}
예제 #9
0
    public RuntimeWeapon WeaponToRuntimeWeapon(Weapon w)
    {
        RuntimeWeapon rw = new RuntimeWeapon();

        rw.weapon          = w;
        rw.curAmmo         = w.magazineAmmo;
        rw.curCarryingAmmo = w.maxAmmo;

        runtimeWeapons.Add(rw);

        return(rw);
    }
예제 #10
0
    void HandleBulletHit(RaycastHit hit, RuntimeWeapon rw)
    {
        //if Hit enemy ?
        if (hit.transform.gameObject.layer == 10)
        {
            hit.transform.SendMessage("OnHit", rw.weapon.damageWeapon, SendMessageOptions.DontRequireReceiver);
            GameObject blood = Instantiate(resourcesManager.prefabBloodFx, hit.point, Quaternion.identity);
            Destroy(blood, 1f);
        }

        //else ?
    }
예제 #11
0
    public void EquipWeapon(RuntimeWeapon rw)
    {
        Weapon w = rw.weapon;

        lh_target = rw.weaponHook.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;

        onIdleDiableOh = rw.weapon.onIdleDiableOh;
    }
예제 #12
0
        //Will Instiate Runtime Object of this Scriptable Object
        public void Init()
        {
            runtime = new RuntimeWeapon();

            runtime.modelInstance = Instantiate(modelPrefab);
            runtime.weaponFX      = runtime.modelInstance.GetComponent <WeaponFX>();
            if (runtime.weaponFX == null)
            {
                runtime.weaponFX = runtime.modelInstance.AddComponent <WeaponFX>();
            }
            runtime.weaponFX.Init();

            runtime.lastFired      = 0;
            runtime.currentBullets = magazineBullets;
        }
예제 #13
0
        public void EquipWeapon(RuntimeWeapon weapon, bool isLeft = false)
        {
            string targetIdle = weapon.instance.oh_idle;

            targetIdle += (isLeft) ? "_l" : "_r";
            states.anim.SetBool(StaticStrings.mirror, isLeft);
            states.anim.Play(StaticStrings.changeWeapon);
            states.anim.Play(targetIdle);

            QuickSlot uiSlot = QuickSlot.singleton;

            uiSlot.UpdateSlot((isLeft) ? QSlotType.lh : QSlotType.rh, weapon.instance.icon);

            weapon.weaponModel.SetActive(true);
        }
예제 #14
0
        void WeaponToRuntime(Item obj, ref RuntimeWeapon slot)
        {
            Weapon     w  = (Weapon)obj;
            GameObject go = Instantiate(w.modelPrefab) as GameObject;

            go.SetActive(false);
            RuntimeWeapon rw = new RuntimeWeapon
            {
                instance = go,
                w_actual = w
            };

            slot = rw;
            r_manager.runtime.RegisterRW(rw);
        }
예제 #15
0
    public void EquipRuntimeWeapon(RuntimeWeapon rw)
    {
        if (playerWeapon.GetCurrent() != null)
        {
            animator.CrossFade("Switch", 0.2f);
            controllerStates.isAiming      = false;
            switchingWeapon                = true;
            controllerStates.isInteracting = true;
            UnEquipWeapon(playerWeapon.GetCurrent());
        }

        rw.m_instance.SetActive(true);
        animatorHook.EquipWeapon(rw);

        animator.SetFloat(StaticStrings.animParamWeaponType, rw.weapon.WeaponType);
        playerWeapon.SetCurrent(rw);
    }
예제 #16
0
        int GetCarryingAmmo()
        {
            RuntimeWeapon   t_weapon  = playerState.value.inventory.curWeapon;
            Ammo            t_ammo    = t_weapon.ammoType;
            AmmoInInventory t_invAmmo = null;

            for (int i = 0; i < playerState.value.inventory.ammos.Count; i++)
            {
                if (playerState.value.inventory.ammos[i].ammoType == t_ammo)
                {
                    t_invAmmo = playerState.value.inventory.ammos[i];
                    break;
                }
            }

            getNewCarryingAmmo = false;

            return(t_invAmmo.amount);
        }
예제 #17
0
    public void CreateRuntimeWeapon(string id, ref RuntimeWeapon r_w_m)
    {
        Weapon        w  = resourcesManager.GetWeapon(id);
        RuntimeWeapon rw = runtimeRef.WeaponToRuntimeWeapon(w);

        GameObject go = Instantiate(w.modelPrefab);

        rw.m_instance = go;
        rw.weapon     = w;
        rw.weaponHook = go.GetComponent <WeaponHook>();
        go.SetActive(false);

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

        go.transform.SetParent(p);
        go.transform.localPosition    = Vector3.zero;
        go.transform.localEulerAngles = Vector3.zero;
        go.transform.localScale       = Vector3.one;

        r_w_m = rw;
    }
예제 #18
0
        public RuntimeWeapon WeaponToRuntimeWeapon(Weapon w, bool isLeft = false)
        {
            GameObject    go   = new GameObject();
            RuntimeWeapon inst = go.AddComponent <RuntimeWeapon>();

            inst.instance = new Weapon();
            StaticFunctions.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;
            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);

            return(inst);
        }
예제 #19
0
    public RuntimeWeapon WeaponToRuntimeWeapon(Weapon w, bool isLeft = false)
    {
        GameObject    go   = new GameObject();
        RuntimeWeapon inst = go.AddComponent <RuntimeWeapon>();

        go.name = w.item_id;

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

        inst.weaponStats = new WeaponStats();
        WeaponStats w_stats = ResourcesManager.singleton.GetWeaponStats(w.item_id);

        StaticFunctions.DeepCopyWeaponStats(w_stats, inst.weaponStats);

        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);


        inst.weaponModel.SetActive(false);

        return(inst);
    }
예제 #20
0
        public string topHalfAnimatorLayerName = "RevolverTopHalf";         //for custom animations

        //Will Instiate Runtime Object of this Scriptable Object
        public void Init()
        {
            runtime = new RuntimeWeapon();

            runtime.modelInstance = Instantiate(modelPrefab);
            runtime.weaponTip     = runtime.modelInstance.transform.Find("WeaponTip");
            runtime.weaponFX      = runtime.modelInstance.GetComponent <WeaponFX>();
            if (runtime.weaponFX == null)
            {
                runtime.weaponFX = runtime.modelInstance.AddComponent <WeaponFX>();
            }
            runtime.weaponFX.Init(runtime.weaponTip, fireAudio);

            if (runtime.weaponTip)
            {
                runtime.weaponTip.SetParent(null);                 //Detach
            }

            ballistics.Init(this);

            runtime.lastFired      = 0;
            runtime.currentBullets = magazineBullets;
        }
예제 #21
0
    public bool ShootWeapon(float t)
    {
        bool retVal = false;

        RuntimeWeapon c = playerWeapon.GetCurrent();

        if (c.curAmmo > 0)
        {
            if (t - c.lastFired > c.weapon.fireRate)
            {
                c.lastFired = t;
                retVal      = true;
                c.ShootWeapon();
                animatorHook.RecoilAnim();
                HandleShooting(c);
            }
        }
        else
        {
            Reload();
        }

        return(retVal);
    }
예제 #22
0
        public override void Tick(float delta)
        {
            if (playerState.value.isDead)
            {
                return;
            }

            if (getNewCarryingAmmo)
            {
                carryingAmmo = GetCarryingAmmo();
            }

            if (playerState.value.wantsToReload || carryingAmmo == -1 || playerState.value.animHook.curWeapon != curWeapon)
            {
                if (playerState.value.animHook.curWeapon != curWeapon)
                {
                    curWeapon = playerState.value.animHook.curWeapon;
                }

                getNewCarryingAmmo = true;
            }

            text.text = playerState.value.inventory.curWeapon.currentBullets.ToString() + "/" + carryingAmmo.ToString();
        }
예제 #23
0
 public void UnEquipWeapon(RuntimeWeapon rw)
 {
     rw.m_instance.SetActive(false);
 }
예제 #24
0
 public override void Init()
 {
     playerState = UIUpdater.singleton.playerState;
     text        = GetComponent <TextMeshProUGUI>();
     curWeapon   = playerState.value.inventory.curWeapon;
 }
예제 #25
0
    public void LoadInventory()
    {
        unarmedRuntime = WeaponToRuntimeWeapon(ResourcesManager.singleton.GetWeapon(unarmedId), false);

        for (int i = 0; i < rh_weapons.Count; i++)
        {
            RuntimeWeapon rw = WeaponToRuntimeWeapon(ResourcesManager.singleton.GetWeapon(rh_weapons[i]));
            r_r_weapons.Add(rw);
        }
        for (int i = 0; i < lh_weapons.Count; i++)
        {
            RuntimeWeapon rw = WeaponToRuntimeWeapon(ResourcesManager.singleton.GetWeapon(lh_weapons[i]), true);
            r_l_weapons.Add(rw);
        }

        if (r_r_weapons.Count > 0)
        {
            if (r_index > r_r_weapons.Count - 1)
            {
                r_index = 0;
            }
            rightHandWeapon = r_r_weapons[r_index];
        }
        if (r_l_weapons.Count > 0)
        {
            if (l_index > r_l_weapons.Count - 1)
            {
                l_index = 0;
            }
            leftHandWeapon = r_l_weapons[l_index];
        }

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

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

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

        for (int i = 0; i < consumable_items.Count; i++)
        {
            RuntimeConsumable c = ConsumableToRuntimeConsumable(ResourcesManager.singleton.GetConsumable(consumable_items[i]));
            r_consumables.Add(c);
        }

        if (r_consumables.Count > 0)
        {
            if (c_index > r_consumables.Count - 1)
            {
                c_index = 0;
            }
            EquipConsumable(r_consumables[c_index]);
        }

        hasLeftHandWeapon = (leftHandWeapon != null);

        InitAllDamageColliders(states);
        CloseAllDamageColliders();
    }
예제 #26
0
 public void SetCurrent(RuntimeWeapon rw)
 {
     curWeapon = rw;
 }