// Spawn FromWeapon internal static void SpawnFromWeapon(Firearms weapon) { Projectile tmpProjectile = weapon.currentSlot.projectileObject.SpawnCopy(weapon.projectileOuter.position, weapon.projectileOuter.rotation); // tmpProjectile.hitMask = weapon.hitMask; tmpProjectile.owner = weapon.owner; tmpProjectile.damage += weapon.addDamage; tmpProjectile.speed += weapon.addSpeed; // tmpProjectile.Configure(); }
// Change Weapon private static IEnumerator ChangeWeapon() { while (FirstPersonWeaponSway.isPlaying) { yield return(null); } if (FirstPersonWeaponSway.ironsightZoomed) { FirstPersonWeaponSway.IronsightUnzoom(); while (FirstPersonWeaponSway.ironsightZooming) { yield return(null); } } if (weaponGo.activeSelf) { if (weaponsCount > 0) { m_Audio.PlayOneShot(m_Instance.switchWeapon); } weaponGo.GetComponentInChildren <FirstPersonWeaponSway>().DropoutAnimation(); } while (FirstPersonWeaponSway.isChanging) { yield return(null); } weaponGo.SetActive(false); if (weaponIndex >= 0) { isSubweapon = false; m_Weapon = m_Instance.weapons[weaponIndex].weapon; weaponGo = m_Weapon.gameObject; m_Firearm = m_Weapon as Firearms; weaponGo.SetActive(true); weaponGo.GetComponentInChildren <FirstPersonWeaponSway>().DropinAnimation(); } UpdateHud(true); }
// Start void Start() { for (int i = 0; i < weapons.Length; i++) { WeaponSlot currentSlot = weapons[i]; GameObject currentGO = currentSlot.weapon.gameObject; currentGO.SetActive(true); if (currentSlot.type == EWeaponType.Thrown) { Firearms tmpFA = currentSlot.weapon as Firearms; if (!tmpFA.isEmpty || !AmmoBackpack.IsEmpty(tmpFA.currentSlot.ammoIndex)) { currentSlot.available = true; } else if (AmmoBackpack.IsEmpty(tmpFA.currentSlot.ammoIndex) && tmpFA.isEmpty) { currentSlot.available = false; } } if (weaponsCount >= maxWeapons && currentSlot.type == EWeaponType.Standart) { DropWeapon(i); } else if (currentSlot.available && currentSlot.type == EWeaponType.Standart) { weaponsCount++; } currentGO.SetActive(false); } for (int i = weaponIndex; i < weapons.Length; i++) { if (i != weaponIndex && weapons[i].available) { weaponIndex = i; StartCoroutine(ChangeWeapon()); break; } } UpdateHud(); UpdateInformerAndCrosshair(); }
// Spawn FromWeapon internal static void SpawnFromWeapon(Firearms weapon) { Shell tmpShell = weapon.currentSlot.projectileObject.shellObject; if (tmpShell != null) { if (weapon.shellOuter == null) { Debug.LogError("ERROR: Shell Outer is not setup! Error in: " + weapon.name); return; } tmpShell = tmpShell.SpawnCopy(weapon.shellOuter.position, Random.rotation); tmpShell.Configure(weapon.shellOuter.forward * Random.Range(weapon.shelloutForce * .75f, weapon.shelloutForce * 1.25f) / 45f); } }
// Awake void Awake() { weaponIndex = -1; weaponsCount = 0; isSubweapon = false; instance = this; maxWeapons = Mathf.Clamp(1, maxWeapons, weapons.Length); m_Audio = this.GetComponent <AudioSource>(); m_Audio.outputAudioMixerGroup = GameSettings.SFXOutput; m_Weapon = weapons[0].weapon; weaponGo = m_Weapon.gameObject; m_Firearm = m_Weapon as Firearms; }
// Awake void Awake() { isChanging = false; ironsightZoomed = ironsightZooming = false; halfBorderSize = borderSize / 2.75f; fullBorderSize = borderSize; m_Transform = transform; m_Parent = m_Transform.parent; m_Animation = GetComponentInChildren <Animation>(); dropinRotation = m_Transform.localEulerAngles; if (fireClip != null) { m_Animation[fireClip.name].speed = fireAnimSpeed; } if (reloadClip != null) { m_Animation[reloadClip.name].speed = reloadAnimSpeed; } parentPosition = m_Parent.localPosition; m_Firearm = GetComponentInParent <Firearms>(); if (m_Firearm != null) { nativeDispersion = m_Firearm.dispersion; } else { meleeWeapon = true; useIronsighting = false; } SetPivot(); m_Parent.localPosition = noisePosition = nativePosition; }
// Switch To SubWeapon internal static void SwitchToSubWeapon() { if (bespoken || weaponIndex < 0 || isMelee || m_Instance.weapons[weaponIndex].subWeapon == null) { return; } if (isSubweapon) { m_Weapon = m_Instance.weapons[weaponIndex].weapon; isSubweapon = false; } else { m_Weapon = m_Instance.weapons[weaponIndex].subWeapon; isSubweapon = true; } m_Firearm = m_Weapon as Firearms; m_Audio.PlayOneShot(m_Instance.subWeaponOnOff); UpdateHud(); }
// Pickup Weapon internal static bool PickupWeapon(int index, bool isFArms = false, int ammoAmount = 0) { WeaponSlot currentSlot = m_Instance.weapons[index]; if (currentSlot.available) { return(false); } currentSlot.available = true; if (isFArms) { Firearms tmpFA = currentSlot.weapon as Firearms; tmpFA.currentSlot.currentAmmo = Mathf.Min(tmpFA.maxAmmo, ammoAmount); } if (weaponsCount < m_Instance.maxWeapons) { if (weaponIndex < 0) { weaponIndex = index; m_Instance.StartCoroutine(ChangeWeapon()); } CalculateWeaponsCount(); } else { if (currentSlot.type == EWeaponType.Standart) { DropWeapon(weaponIndex, index); } } return(true); }
// Drop Weapon private static void DropWeapon(int index, int newIndex = -1) { if (index < 0) { for (int i = 0; i < size; i++) { if (newIndex != i && m_Instance.weapons[i].available && m_Instance.weapons[i].type == EWeaponType.Standart) { DropWeapon(i, newIndex); return; } } for (int i = 0; i < size; i++) { if (m_Instance.weapons[i].available && m_Instance.weapons[i].type == EWeaponType.Standart) { DropWeapon(i); return; } } return; } WeaponSlot currentSlot = m_Instance.weapons[index]; if (weaponsCount < 1 || !currentSlot.available) { return; } if (currentSlot.type != EWeaponType.Standart) { for (int i = 0; i < size; i++) { if (newIndex != i && m_Instance.weapons[i].available && m_Instance.weapons[i].type == EWeaponType.Standart) { DropWeapon(i); return; } } for (int i = 0; i < size; i++) { if (m_Instance.weapons[i].available && m_Instance.weapons[i].type == EWeaponType.Standart) { DropWeapon(i); return; } } } if (currentSlot.dropout != null) { Transform playerTR = PlayerCharacter.Instance.m_Transform; Rigidbody droppedWeapon = currentSlot.dropout.SpawnCopy(playerTR.forward * .2f + PlayerCamera.m_Transform.position + Vector3.up * .1f, Random.rotation); droppedWeapon.AddForce(playerTR.forward * (4f * droppedWeapon.mass), ForceMode.Impulse); droppedWeapon.AddRelativeTorque(Vector3.up * (Random.value > .5f ? 15f : -15f), ForceMode.Impulse); Firearms tmpFA = currentSlot.weapon as Firearms; if (tmpFA != null) { IPickup tmpPickup = droppedWeapon.GetComponent <IPickup>(); if (tmpPickup != null) { tmpPickup.Amount = tmpFA.currentSlot.currentAmmo; } else { tmpPickup = droppedWeapon.gameObject.AddComponent <Pickup>(); tmpPickup.Amount = tmpFA.currentSlot.currentAmmo; tmpPickup.WeaponIndex = index; tmpPickup.AmmoIndex = tmpFA.currentSlot.ammoIndex; tmpPickup.PickupType = EPickupType.Firearms; } } } else { Debug.LogError("ERROR: Dropout item is null! Item index in weapons: " + index); } currentSlot.weapon.gameObject.SetActive(false); currentSlot.available = false; if (newIndex > -1) { weaponIndex = newIndex; m_Instance.StartCoroutine(ChangeWeapon()); } CalculateWeaponsCount(); if (weaponsCount < m_Instance.maxWeapons) { m_Audio.PlayOneShot(m_Instance.switchWeapon); } UpdateHud(true); }