private void Start() { if (targetID != null) { ResourceManager rm = GameManager.GetResourcesManager(); Weapon targetWeapon = (Weapon)rm.GetItemInstance(targetID); weapon = targetWeapon.InitNewRuntimeWeapon(); weapon.weaponInstance.transform.position = transform.position; weapon.weaponInstance.transform.rotation = transform.rotation; weapon.weaponInstance.AddComponent <EquipWeapon>(); weapon.weaponInstance.GetComponent <EquipWeapon>().weapon = weapon; weapon.weaponInstance.GetComponent <Collider>().enabled = true; Rigidbody rb = weapon.weaponInstance.AddComponent <Rigidbody>(); rb.mass = 0.1f; rb.drag = 0; rb.angularDrag = 0; rb.interpolation = RigidbodyInterpolation.Extrapolate; rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; Destroy(gameObject); } }
public void Interact(StateManager state) { //Set state weapon to be this ones replacement RuntimeWeapon stateWeapon = state.inventory.curWeapon; stateWeapon.weaponInstance.transform.parent = this.transform.parent; stateWeapon.weaponInstance.GetComponent <Collider>().enabled = true; stateWeapon.weaponInstance.AddComponent <EquipWeapon>(); stateWeapon.weaponInstance.GetComponent <EquipWeapon>().weapon = stateWeapon; Rigidbody rb = stateWeapon.weaponInstance.AddComponent <Rigidbody>(); rb.mass = 0.1f; rb.drag = 0; rb.angularDrag = 0; rb.interpolation = RigidbodyInterpolation.Extrapolate; rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; //Add this weapon to the state manager Destroy(weapon.weaponInstance.gameObject.GetComponent <Rigidbody>()); weapon.weaponInstance.GetComponent <Collider>().enabled = false; state.inventory.curWeapon = weapon; state.animHook.LoadWeapon(weapon); Destroy(this); }
public RuntimeWeapon InitNewRuntimeWeapon() { RuntimeWeapon runtime = new RuntimeWeapon(); runtime.weaponInstance = Instantiate(model) as GameObject; runtime.weaponHook = runtime.weaponInstance.GetComponent <WeaponHook>(); runtime.weaponHook.Init(shootingAudio, reloadingAudio); runtime.weaponInstance.GetComponentInChildren <Collider>().enabled = false; runtime.currentBullets = magazineBullets; runtime.magazineBullets = magazineBullets; runtime.fireRate = fireRate; runtime.isAutomatic = isAutomatic; runtime.ammoType = ammoType; runtime.rhAimingPos = rhAimingPosition.value; runtime.rhAimingRot = rhAimingRotation.value; runtime.rhHipfirePos = rhHipfirePosition.value; runtime.rhHipfireRot = rhHipfireRotation.value; runtime.weaponModelPosOffset = weaponModelPosOffset.value; runtime.weaponModelRotOffset = weaponModelRotOffset.value; runtime.ballistics = ballistics; return(runtime); }
public override void Execute(StateManager state) { RuntimeWeapon t_weapon = state.inventory.curWeapon; Ammo t_ammo = t_weapon.ammoType; AmmoInInventory t_invAmmo = null; for (int i = 0; i < state.inventory.ammos.Count; i++) { if (state.inventory.ammos[i].ammoType == t_ammo) { t_invAmmo = state.inventory.ammos[i]; break; } } int amount_To_Reload = t_invAmmo.amount >= t_weapon.magazineBullets - t_weapon.currentBullets ? t_weapon.magazineBullets - t_weapon.currentBullets : t_invAmmo.amount; state.animHook.PlayReloadAnim(); state.inventory.curWeapon.weaponHook.Reload(); t_invAmmo.amount -= amount_To_Reload; t_weapon.currentBullets += amount_To_Reload; if (t_weapon.currentBullets > t_weapon.magazineBullets) { Debug.Log(t_weapon.weaponInstance.name + " has more bullets than is allowed in its' magazine!"); } }
public override bool CheckCondition(StateManager state) { bool retVal = false; RuntimeWeapon t_weapon = state.inventory.curWeapon; Ammo t_ammo = t_weapon.ammoType; AmmoInInventory t_invAmmo = null; switch (state.type) { case StateManagerType.player: if (state.wantsToReload) { for (int i = 0; i < state.inventory.ammos.Count; i++) { if (state.inventory.ammos[i].ammoType == t_ammo) { t_invAmmo = state.inventory.ammos[i]; break; } } if (t_invAmmo.amount > 0 && t_weapon.currentBullets < t_weapon.magazineBullets) { retVal = true; } } break; case StateManagerType.guard: for (int i = 0; i < state.inventory.ammos.Count; i++) { if (state.inventory.ammos[i].ammoType == t_ammo) { t_invAmmo = state.inventory.ammos[i]; break; } } if (t_invAmmo.amount > 0 && t_weapon.currentBullets == 0) { retVal = true; } break; default: break; } return(retVal); }
public override void Execute(StateManager state) { RuntimeWeapon runtimeWeapon = state.inventory.curWeapon; if (runtimeWeapon.isAutomatic) { switch (state.type) { case StateManagerType.player: if (state.wantsToShoot && canIShoot.CheckCondition(state)) { if (Time.realtimeSinceStartup - runtimeWeapon.weaponHook.lastFired < runtimeWeapon.fireRate + 0.1f) //0.1f is the buffer time to shoot { runtimeWeapon.weaponHook.consecutiveShots += 1; } else { runtimeWeapon.weaponHook.consecutiveShots = 0; } } else if (Time.realtimeSinceStartup - runtimeWeapon.weaponHook.lastFired >= runtimeWeapon.fireRate + 0.1f) { runtimeWeapon.weaponHook.consecutiveShots = 0; } break; case StateManagerType.guard: if (canIShoot.CheckCondition(state)) { if (Time.realtimeSinceStartup - runtimeWeapon.weaponHook.lastFired < runtimeWeapon.fireRate + 0.1f) //0.1f is the buffer time to shoot { runtimeWeapon.weaponHook.consecutiveShots += 1; } else { runtimeWeapon.weaponHook.consecutiveShots = 0; } } else if (Time.realtimeSinceStartup - runtimeWeapon.weaponHook.lastFired >= runtimeWeapon.fireRate + 0.1f) { runtimeWeapon.weaponHook.consecutiveShots = 0; } break; default: break; } } else { runtimeWeapon.weaponHook.consecutiveShots = 0; } }
public override void Execute(StateManager state) { state.animHook.StopShootAnim(); w = state.inventory.curWeapon; state.wantsToShoot = false; w.weaponHook.lastFired = Time.realtimeSinceStartup; w.weaponHook.Shoot(); state.animHook.PlayShootAnim(); w.ballistics.Execute(state); w.currentBullets--; }
public override void Execute(StateManager state) { RuntimeWeapon stateWeapon = state.inventory.curWeapon; stateWeapon.weaponInstance.transform.parent = GameObject.Find("Environment/Items").transform; stateWeapon.weaponInstance.GetComponent <Collider>().enabled = true; stateWeapon.weaponInstance.AddComponent <EquipWeapon>(); stateWeapon.weaponInstance.GetComponent <EquipWeapon>().weapon = stateWeapon; Rigidbody rb = stateWeapon.weaponInstance.AddComponent <Rigidbody>(); rb.mass = 0.1f; rb.drag = 0; rb.angularDrag = 0; rb.interpolation = RigidbodyInterpolation.Extrapolate; rb.collisionDetectionMode = CollisionDetectionMode.ContinuousDynamic; state.inventory.curWeapon = null; }
public void LoadWeapon(RuntimeWeapon w) { curWeapon = w; rhHipPos = curWeapon.rhHipfirePos; rhHipRot = curWeapon.rhHipfireRot; rhAimPos = curWeapon.rhAimingPos; rhAimRot = curWeapon.rhAimingRot; weaponLocalPos = curWeapon.weaponModelPosOffset; weaponLocalRot = curWeapon.weaponModelRotOffset; curWeapon.weaponInstance.transform.parent = anim.GetBoneTransform(HumanBodyBones.RightHand).transform; curWeapon.weaponInstance.transform.localPosition = weaponLocalPos; curWeapon.weaponInstance.transform.localEulerAngles = weaponLocalRot; HandleRightHandTargetTransform(); leftHandTarget = w.weaponHook.leftHandIK; }
public override bool CheckCondition(StateManager state) { bool retVal = false; RuntimeWeapon w = state.inventory.curWeapon; switch (state.type) { case StateManagerType.player: if (state.wantsToShoot) { if (w.currentBullets > 0) { if (Time.realtimeSinceStartup - w.weaponHook.lastFired > w.fireRate) { retVal = true; } } } break; case StateManagerType.guard: if (!state.isInteracting && !state.isPerformingAction) { if (w.currentBullets > 0) { if (Time.realtimeSinceStartup - w.weaponHook.lastFired > w.fireRate) { retVal = true; } } } break; default: break; } return(retVal); }