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); }
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); }
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; }
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; }
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); }
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 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; }
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; } }
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); }
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); } } }
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); } }
public void SetCurrent(RuntimeWeapon rw) { curWeapon = rw; }
public void UpdatePlayerReferencesForWeapon(RuntimeWeapon r) { p_references.curAmmo.value = r.curAmmo; p_references.curCarrying.value = r.curCarrying; }