void Shoot() { if (Time.time > NextFire) { NextFire = Time.time + RateofFire; currentammo--; GunAS.PlayOneShot(ShootAC); StartCoroutine(WeaponEffects()); if (Physics.Raycast(ShootPoint.position, ShootPoint.forward, out Hit, WeaponRange)) { if (Hit.transform.tag == "Enemy") { Debug.Log("Hit Enemy"); EnemyHealth EnemyHealthScript = Hit.transform.GetComponent <EnemyHealth>(); EnemyHealthScript.DeductHealth(damageEnemy); currentammo = currentammo + 10000; } else { Debug.Log("Hit Something Else"); } if (Hit.transform.tag == "Ammo") { Debug.Log("Got Ammo!"); AmmoPickup AmmoPickupScript = Hit.transform.GetComponent <AmmoPickup>(); AmmoPickupScript.DeductHealth(damageAmmo); currentammo = currentammo + 10000; } } } }
public void InstantiateObject() { GameObject objectToInstantiate = Instantiate(options [currentOption].prefab, transform.position, Quaternion.identity); if (options [currentOption].type == PlayerDeadOptionType.MOB) { Base_Mob mob = objectToInstantiate.GetComponent <Base_Mob> (); mob.Ini(null, playerTag.Id, playerTag.Team, true); } else if (options [currentOption].type == PlayerDeadOptionType.POWERUP) { PickupRespawn pickup = objectToInstantiate.GetComponent <PickupRespawn> (); pickup.duration = -1f; PickupGun gun = objectToInstantiate.GetComponent <PickupGun> (); if (gun != null) { return; } Powerup powerup = objectToInstantiate.GetComponent <Powerup> (); if (powerup != null) { powerup.SetValue(options[currentOption].baseValue); return; } AmmoPickup ammo = objectToInstantiate.GetComponent <AmmoPickup> (); if (ammo != null) { ammo.SetValue((int)options [currentOption].baseValue); return; } } }
public static void DoubleKeys(Action <AmmoPickup, PlayerController> acshon, AmmoPickup key, PlayerController player) { acshon(key, player); foreach (PassiveItem passives in player.passiveItems) { if (passives is AmmoEnhancer) { bool VibeCheck = false; foreach (Gun gunk in player.inventory.AllGuns) { if (gunk.ammo != gunk.AdjustedMaxAmmo && !(gunk.InfiniteAmmo) && gunk.CanGainAmmo) { VibeCheck = true; } } if (VibeCheck) { int randomGun; do { randomGun = UnityEngine.Random.Range(0, player.inventory.AllGuns.Count); } while (player.inventory.AllGuns[randomGun].ammo == player.inventory.AllGuns[randomGun].AdjustedMaxAmmo && (player.inventory.AllGuns[randomGun].InfiniteAmmo) && player.inventory.AllGuns[randomGun].CanGainAmmo); player.inventory.AllGuns[randomGun].GainAmmo(player.inventory.AllGuns[randomGun].AdjustedMaxAmmo - player.inventory.AllGuns[randomGun].ammo); player.BloopItemAboveHead(itemator.sprite); } } } }
public bool UseAmmoPickup(AmmoPickup ammoPickup) { int type = ammoPickup.GetAmmoType(); ammo[type] += ammoPickup.GetAmmoCount(); //TODO: ammo count limitation ammoPickup.SetAmmoCount(0); return(true); }
protected override void DoEffect(PlayerController user) { IPlayerInteractable nearestInteractable = user.CurrentRoom.GetNearestInteractable(user.CenterPosition, 3f, user); if (!(nearestInteractable is AmmoPickup)) { return; } AmmoPickup rerollChest = nearestInteractable as AmmoPickup; Instantiate <GameObject>(EasyVFXDatabase.BloodiedScarfPoofVFX, rerollChest.sprite.WorldCenter, Quaternion.identity); Destroy(rerollChest.gameObject); AkSoundEngine.PostEvent("Play_OBJ_ammo_suck_01", gameObject); int bighead = UnityEngine.Random.Range(1, 11); if (bighead == 1) { this.ApplyStat(user, PlayerStats.StatType.Damage, 0.15f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 2) { this.ApplyStat(user, PlayerStats.StatType.Health, 1f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 3) { this.ApplyStat(user, PlayerStats.StatType.Coolness, 1f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 4) { this.ApplyStat(user, PlayerStats.StatType.MovementSpeed, 0.15f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 5) { this.ApplyStat(user, PlayerStats.StatType.AdditionalClipCapacityMultiplier, 0.15f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 6) { this.ApplyStat(user, PlayerStats.StatType.AmmoCapacityMultiplier, 0.15f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 7) { this.ApplyStat(user, PlayerStats.StatType.AdditionalBlanksPerFloor, 1f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 8) { this.ApplyStat(user, PlayerStats.StatType.RateOfFire, 0.15f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 9) { this.ApplyStat(user, PlayerStats.StatType.ReloadSpeed, 0.15f, StatModifier.ModifyMethod.ADDITIVE); } if (bighead == 10) { this.ApplyStat(user, PlayerStats.StatType.RangeMultiplier, 0.15f, StatModifier.ModifyMethod.ADDITIVE); } }
protected override void Awake() { base.Awake(); AmmoPickup ammoPickup = (AmmoPickup)_pickupItem; _shooter = ammoPickup.Shooter; _rateOfFireText = transform.Find("Container Panel/Info Panel/Rate Of Fire Info/Rate Of Fire Text").GetComponent <Text>(); }
private void Start() { //spawning the item at this position GameObject itemCopy = Instantiate(pickup, transform.position, transform.rotation); //getting the code from the new object and setting the spawn to this spawn point AmmoPickup itemCode = itemCopy.GetComponent <AmmoPickup>(); itemCode.spawn = this; }
//Checking collision with ammo pickups and adding ammunition to all guns void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.collider.GetComponent <AmmoPickup>() != null) { AmmoPickup ammoPickup = hit.collider.GetComponent <AmmoPickup>(); rifleAmmo.RifleAmmunition += ammoPickup.ammo; pistolAmmo.PistolAmmunition += (int)ammoPickup.ammo / 2; shotgunAmmo.ShotgunAmmunition += (int)ammoPickup.ammo / 4; Destroy(ammoPickup.gameObject); } }
public static PickupItem CreateFromPrefab(GameObject prefab, Vector2 position, int count, int type) { GameObject instance = Instantiate(prefab); AmmoPickup item = instance.GetComponent <AmmoPickup>(); item.SetPosition(position); item.SetAmmoCount(count); item.SetAmmoType(type); return(item); }
public void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag.Equals("Pickupable")) { Debug.Log("Player has picked up an object [" + collision.gameObject.name + "]"); collision.gameObject.SetActive(false); // Send message to all child objects to ensure ammo is updated AmmoPickup ammoPickup = collision.GetComponent <AmmoPickup>(); BroadcastMessage("OnAmmoPickup", ammoPickup); } }
public bool HandleEquipItem(AmmoPickup item, bool equip, bool opposite = false) { int itemIndex = 0; for (int i = 0; i < _allItems.Count; i++) { if (_allItems[i] == item) { itemIndex = i; break; } } SavedData savedData = JsonUtility.FromJson <SavedData>(PlayerPrefs.GetString(SAVED_DATA_NAME)); if (savedData == null) { savedData = new SavedData(); } bool alreadyEquipped = false; foreach (int equippedItem in savedData.EquippedItems) { if (equippedItem == itemIndex) { alreadyEquipped = true; } } // Sometimes we don't use the equip parameter, but rather use the opposite of the current value if (opposite) { equip = !alreadyEquipped; } if (equip && !alreadyEquipped) { savedData.EquippedItems.Add(itemIndex); Save(savedData); } if (!equip && alreadyEquipped) { savedData.EquippedItems.RemoveAll(index => index == itemIndex); Save(savedData); } return(equip); }
void spawnPickup() { if (ammoPickupPrefab != null && hpPickupPrefab != null) { int rand = Random.Range(0, 3); if (rand == 1) { GameObject go = Instantiate(ammoPickupPrefab, this.transform.position, this.transform.rotation) as GameObject; int amount = Random.Range(30, 90); AmmoPickup ammo = go.GetComponent <AmmoPickup>(); if (ammo != null) { ammo.amount = amount; } } else if (rand == 2) { GameObject go = Instantiate(hpPickupPrefab, this.transform.position, this.transform.rotation) as GameObject; int amount = Random.Range(25, 100); HeathPickup hpPickup = go.GetComponent <HeathPickup>(); ArmorPickup apPickup = go.GetComponent <ArmorPickup>(); if (hpPickup != null && apPickup != null) { hpPickup.amount = amount; apPickup.amount = amount; } } else if (rand == 3) { int amount = 0; GameObject goAmmo = Instantiate(ammoPickupPrefab, this.transform.position, this.transform.rotation) as GameObject; GameObject goHp = Instantiate(hpPickupPrefab, this.transform.position, this.transform.rotation) as GameObject; amount = Random.Range(30, 90); AmmoPickup ammo = goAmmo.GetComponent <AmmoPickup>(); if (ammo != null) { ammo.amount = amount; } amount = Random.Range(25, 100); HeathPickup hpPickup = goHp.GetComponent <HeathPickup>(); ArmorPickup apPickup = goHp.GetComponent <ArmorPickup>(); if (hpPickup != null && apPickup != null) { hpPickup.amount = amount; apPickup.amount = amount; } } } }
//KS - Attempt to set agents target to the closest active ammo if ammo is needed, returns false if this is not currently possible or they already have ammo. public bool SetTargetToClosestActiveAmmo() { if (HasAmmo()) { return(false); } //KS - Agent already has an ammo target. if (targetObject != null) { AmmoPickup targetAmmo = targetObject.GetComponent <AmmoPickup>(); if (targetAmmo && targetAmmo.IsPickupActive()) { return(true); } } //KS - Find closest ammo target GameObject target = null; if (World.ammoTiles.Count > 0) { float closestDistance = -1; for (int i = 0; i < World.ammoTiles.Count; i++) { //KS - If not active skip. if (!World.ammoTiles[i].pickupComponent.IsPickupActive()) { continue; } float distance = Vector3.Distance(transform.position, World.ammoTiles[i].mTileObject.transform.position); if (distance < closestDistance || closestDistance < 0.0f) { closestDistance = distance; target = World.ammoTiles[i].mTileObject; } } } if (target) { SetTarget(target); } return(target != null); }
private void Update() { Ray ray = FPSCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2)); RaycastHit hitInfo; interactText.text = ("[" + interactKey + "] " + "Interact"); if (debugRay == true) { Debug.DrawRay(ray.origin, ray.direction * interactRange, Color.yellow); } if (Physics.Raycast(ray, out hitInfo, interactRange)) { if (hitInfo.collider.gameObject.layer == 8) { interactText.enabled = true; } else if (hitInfo.collider.gameObject.layer != 8) { interactText.enabled = false; } if (Input.GetKeyDown(interactKey)) { if (hitInfo.collider.tag == "WeaponPickup") { WeaponPickup weaponPickup = hitInfo.collider.GetComponent <WeaponPickup>(); weaponPickup.Interact(); } else if (hitInfo.collider.tag == "AmmoPickup") { AmmoPickup ammoPickup = hitInfo.collider.GetComponent <AmmoPickup>(); ammoPickup.Interact(); } } } else { interactText.enabled = false; } }
public static void doEffect(Action <DebrisObject> orig, DebrisObject spawnedItem) { try { orig(spawnedItem); if (GameManager.Instance.AnyPlayerHasPickupID(AmmoTrapID)) { AmmoPickup itemness = spawnedItem.gameObject.GetComponent <AmmoPickup>(); if (itemness != null) { itemness.IgnoredByRat = true; } } } catch (Exception e) { ETGModConsole.Log(e.Message); ETGModConsole.Log(e.StackTrace); } }
public void AddAmmo(AmmoPickup pickup) { switch (pickup.getAmmoType()) { case AMMOTYPE.ASSAULT: getWeapon(WEAPON_TYPE.ASSAULT).AddAmmo(pickup as AssaultAmmo); break; case AMMOTYPE.SHOTGUN: getWeapon(WEAPON_TYPE.SHOTGUN).AddAmmo(pickup as ShotgunAmmo); break; case AMMOTYPE.GRENADE: getWeapon(WEAPON_TYPE.GRENADE).AddAmmo(pickup as GrenadeAmmo); break; default: break; } }
public void OnAmmoPickup(AmmoPickup ammoPickup) { AmmoInfo value; if (ammoData.TryGetValue(ammoPickup.type, out value)) { Debug.Log("Ammo has increaed for " + ammoPickup.type); value.currentCount = (uint)Mathf.Clamp(ammoPickup.count, 0, value.max); ammoData[ammoPickup.type] = value; if (activeAmmo.type == ammoPickup.type) { updateUiAmmoAmmount(value); } } else { Debug.LogWarning("Item Type does not exists in the manager [" + ammoPickup.type.ToString() + "]"); } }
public WEAPON_TYPE GetWeaponForAmmo(AmmoPickup ammo) { WEAPON_TYPE weapon = WEAPON_TYPE.NULL; switch (ammo.getAmmoType()) { case AMMOTYPE.ASSAULT: weapon = WEAPON_TYPE.ASSAULT; break; case AMMOTYPE.SHOTGUN: weapon = WEAPON_TYPE.SHOTGUN; break; case AMMOTYPE.GRENADE: weapon = WEAPON_TYPE.GRENADE; break; } return(weapon); }
void PickUp() { RaycastHit hit; if (Physics.Raycast(c.transform.position, transform.forward, out hit, 1000.0f, bulletMask)) { Debug.DrawRay(c.transform.position, transform.forward * hit.distance, Color.cyan); AmmoPickup am = hit.transform.GetComponent <AmmoPickup>(); if (am != null) { spareAmmunition += am.Pickup(); GameUIController.UpdateSpareAmmo(spareAmmunition); } } else { Debug.DrawRay(c.transform.position, transform.forward * 1000.0f, Color.blue); } }
private void Update() { //if the item is got it starts the respawn timer if (itemGot) { time += Time.deltaTime; //if the time reaches respawn time then the item will be instantiated if (time >= respawnTime) { //spawning the item at this position GameObject itemCopy = Instantiate(pickup, transform.position, transform.rotation); //getting the code from the new object and setting the spawn to this spawn point AmmoPickup itemCode = itemCopy.GetComponent <AmmoPickup>(); itemCode.spawn = this; //resetting values time = 0; itemGot = false; } } }
public void InitializeProjectile() { hit = false; falling = false; AmmoPickupComponent = GetComponent <AmmoPickup>(); AmmoPickupComponent.enabled = false; myRigidbody = GetComponent <Rigidbody>(); myBoxCol = GetComponent <BoxCollider>(); myMeshRenderer = GetComponent <MeshRenderer>(); myMeshRenderer.enabled = false; //reset collider size to original, smaller arrow sized value for more realistic, narrower collisions myBoxCol.size = initialColSize; startTime = Time.time; myRigidbody.isKinematic = false; myBoxCol.isTrigger = true; transform.gameObject.tag = "Untagged"; //don't allow arrow to be grabbed in flight transform.parent = AzuObjectPool.instance.transform; transform.localScale = scale; DeleteEmptyObj(); //delete the empty object used last time for this arrow (empty parent obj prevents arrow from inheriting hit collider's scale) }
void InteractionInput() { if (dead) { return; } RaycastHit hit; if (Input.GetKeyDown(KeyCode.E)) { if (Physics.SphereCast(mainCamera.transform.position, .1f, mainCamera.transform.forward, out hit, maxInteractDistance, InteractionLayer)) { if (hit.collider.GetComponent <Equipment>()) { currentEquipment?.gameObject.SetActive(false); hit.collider.GetComponent <Equipment>().enabled = true; Manager.uiEquipmentSlots.AddSlot(hit.collider.GetComponent <Equipment>()); Manager.uiEquipmentSlots.CurrentSlotIndex = Manager.uiEquipmentSlots.SlotCount - 1; currentEquipment = hit.collider.GetComponent <Equipment>(); hit.collider.enabled = false; currentEquipment.transform.parent = equipmentPosition; currentEquipment.transform.localPosition = Vector3.zero; currentEquipment.transform.localRotation = Quaternion.identity; currentEquipment.animator.enabled = true; UpdateAmmoUI(); } else if (hit.collider.GetComponent <Interactable>()) { hit.collider.GetComponent <Interactable>().Interact(); } else if (hit.collider.GetComponent <AmmoPickup>()) { AmmoPickup ap = hit.collider.GetComponent <AmmoPickup>(); switch (hit.collider.GetComponent <AmmoPickup>().ammoType) { case AmmoPickup.AmmoType.Pistol: pistolAmmoCount += ap.Pickup(); break; case AmmoPickup.AmmoType.Rifle: rifleAmmoCount += ap.Pickup(); break; } currentEquipment?.GetComponent <Gun>()?.RefreshAmmoCountUI(); } else if (hit.collider.GetComponent <Key>()) { keys.Add(hit.collider.GetComponent <Key>().getKey()); } else if (hit.collider.GetComponent <Log>()) { Manager.AddLog(hit.collider.GetComponent <Log>().GetTextAsset()); Manager.instance.ShowHelp("Press G to toggle logs", 3); } hit.collider.GetComponent <PhysicalButton>()?.Press(); } } if (Input.GetMouseButtonDown(0)) { currentEquipment?.Interact(); } if (Input.GetKeyDown(KeyCode.R)) { currentEquipment?.GetComponent <Gun>()?.AttemptReload(); } if (Input.GetKeyDown(KeyCode.G)) { Manager.ToggleLog(); } if (Input.GetAxis("Mouse ScrollWheel") != 0 && Manager.uiEquipmentSlots.SlotCount > 0) { if (Input.GetAxis("Mouse ScrollWheel") > 0) { Manager.uiEquipmentSlots.CurrentSlotIndex--; } if (Input.GetAxis("Mouse ScrollWheel") < 0) { Manager.uiEquipmentSlots.CurrentSlotIndex++; } currentEquipment?.gameObject.SetActive(false); currentEquipment = Manager.uiEquipmentSlots.CurrentSlot.Equipment; currentEquipment?.gameObject.SetActive(true); if (!currentEquipment) { CrosshairManager.currentCrosshairSetting = crosshairSettingNone; } UpdateAmmoUI(); } }
public void AddAmmo(AmmoPickup pickup) { ammo += pickup.getAmmoValue(); }
public static void ammoPickupHookMethod(Action <AmmoPickup, PlayerController> orig, AmmoPickup self, PlayerController player) { orig(self, player); //ETGModConsole.Log("Ammo pickup was triggered"); if (player.HasPickupID(Gungeon.Game.Items["nn:ammolite"].PickupObjectId)) { if (canGiveDMG) { if (player.CurrentGun.GetComponent <AmmoliteModifier>()) { AmmoliteModifier ammoliteMod = player.CurrentGun.GetComponent <AmmoliteModifier>(); ammoliteMod.TimesPickedUpAmmo += 1; } else { player.CurrentGun.gameObject.AddComponent <AmmoliteModifier>(); } canGiveDMG = false; } else { canGiveDMG = true; } } }
public void OnPickupEnter(AmmoPickup pickup) { ammo += 20; }
public static void ammoInteractHookMethod(Action <AmmoPickup, PlayerController> orig, AmmoPickup self, PlayerController player) { if (player.CurrentGun && OverrideNoCheckIDs.Contains(player.CurrentGun.PickupObjectId)) { if (RoomHandler.unassignedInteractableObjects.Contains(self)) { RoomHandler.unassignedInteractableObjects.Remove(self); } SpriteOutlineManager.RemoveOutlineFromSprite(self.sprite, true); self.Pickup(player); } else if (player.CurrentGun && !player.CurrentGun.CanGainAmmo) { GameUIRoot.Instance.InformNeedsReload(player, new Vector3(player.specRigidbody.UnitCenter.x - player.transform.position.x, 1.25f, 0f), 1f, "#RELOAD_FULL"); return; } else { orig(self, player); } }
public static void ammoPickupHookMethod(Action <AmmoPickup, PlayerController> orig, AmmoPickup self, PlayerController player) { if (player.CurrentGun && player.CurrentGun.PickupObjectId == Blankannon.BlankannonId) { if (player.CurrentGun.CurrentAmmo == player.CurrentGun.AdjustedMaxAmmo) { HandleFuckedUpGunAmmoPickup(self, player); } LootEngine.GivePrefabToPlayer(PickupObjectDatabase.GetById(224).gameObject, player); } orig(self, player); if (player.HasPickupID(MengerAmmoBox.MengerAmmoBoxID)) { if (self.mode == AmmoPickup.AmmoPickupMode.FULL_AMMO) { for (int i = 0; i < player.inventory.AllGuns.Count; i++) { if (player.inventory.AllGuns[i] && player.CurrentGun != player.inventory.AllGuns[i]) { player.inventory.AllGuns[i].GainAmmo(Mathf.FloorToInt((float)player.inventory.AllGuns[i].AdjustedMaxAmmo * 0.2f)); } } player.CurrentGun.ForceImmediateReload(false); if (GameManager.Instance.CurrentGameType == GameManager.GameType.COOP_2_PLAYER) { PlayerController otherPlayer = GameManager.Instance.GetOtherPlayer(player); if (!otherPlayer.IsGhost) { for (int j = 0; j < otherPlayer.inventory.AllGuns.Count; j++) { if (otherPlayer.inventory.AllGuns[j]) { otherPlayer.inventory.AllGuns[j].GainAmmo(Mathf.FloorToInt((float)otherPlayer.inventory.AllGuns[j].AdjustedMaxAmmo * 0.2f)); } } otherPlayer.CurrentGun.ForceImmediateReload(false); } } } else if (self.mode == AmmoPickup.AmmoPickupMode.SPREAD_AMMO) { if (player.CurrentGun != null && player.CurrentGun.CanGainAmmo) { player.CurrentGun.GainAmmo(player.CurrentGun.AdjustedMaxAmmo); player.CurrentGun.ForceImmediateReload(false); } } } if (player.HasPickupID(BloodyAmmo.BloodyAmmoID)) { int bloodyAmount = player.GetNumberOfItemInInventory(BloodyAmmo.BloodyAmmoID); for (int i = 0; i < bloodyAmount; i++) { player.healthHaver.ApplyHealing(0.5f); if (player.characterIdentity == PlayableCharacters.Robot) { LootEngine.GivePrefabToPlayer(PickupObjectDatabase.GetById(120).gameObject, player); } } } }
public static void HandleFuckedUpGunAmmoPickup(AmmoPickup pickup, PlayerController player) { if (pickup.mode == AmmoPickup.AmmoPickupMode.FULL_AMMO) { string @string = StringTableManager.GetString("#AMMO_SINGLE_GUN_REFILLED_HEADER"); string description = player.CurrentGun.GetComponent <EncounterTrackable>().journalData.GetPrimaryDisplayName(false) + " " + StringTableManager.GetString("#AMMO_SINGLE_GUN_REFILLED_BODY"); tk2dBaseSprite sprite = player.CurrentGun.GetSprite(); if (!GameUIRoot.Instance.BossHealthBarVisible) { GameUIRoot.Instance.notificationController.DoCustomNotification(@string, description, sprite.Collection, sprite.spriteId, UINotificationController.NotificationColor.SILVER, false, false); } } else if (pickup.mode == AmmoPickup.AmmoPickupMode.SPREAD_AMMO) { for (int i = 0; i < player.inventory.AllGuns.Count; i++) { if (player.inventory.AllGuns[i] && player.CurrentGun != player.inventory.AllGuns[i]) { player.inventory.AllGuns[i].GainAmmo(Mathf.FloorToInt((float)player.inventory.AllGuns[i].AdjustedMaxAmmo * pickup.SpreadAmmoOtherGunsPercent)); } } player.CurrentGun.ForceImmediateReload(false); if (GameManager.Instance.CurrentGameType == GameManager.GameType.COOP_2_PLAYER) { PlayerController otherPlayer = GameManager.Instance.GetOtherPlayer(player); if (!otherPlayer.IsGhost) { for (int j = 0; j < otherPlayer.inventory.AllGuns.Count; j++) { if (otherPlayer.inventory.AllGuns[j]) { otherPlayer.inventory.AllGuns[j].GainAmmo(Mathf.FloorToInt((float)otherPlayer.inventory.AllGuns[j].AdjustedMaxAmmo * pickup.SpreadAmmoOtherGunsPercent)); } } otherPlayer.CurrentGun.ForceImmediateReload(false); } } string string2 = StringTableManager.GetString("#AMMO_SINGLE_GUN_REFILLED_HEADER"); string string3 = StringTableManager.GetString("#AMMO_SPREAD_REFILLED_BODY"); tk2dBaseSprite sprite2 = pickup.sprite; if (!GameUIRoot.Instance.BossHealthBarVisible) { GameUIRoot.Instance.notificationController.DoCustomNotification(string2, string3, sprite2.Collection, sprite2.spriteId, UINotificationController.NotificationColor.SILVER, false, false); } } FieldInfo field = typeof(AmmoPickup).GetField("m_pickedUp", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(pickup, false); FieldInfo field2 = typeof(AmmoPickup).GetField("m_isBeingEyedByRat", BindingFlags.Instance | BindingFlags.NonPublic); field2.SetValue(pickup, false); var type = typeof(AmmoPickup); var func = type.GetMethod("GetRidOfMinimapIcon", BindingFlags.Instance | BindingFlags.NonPublic); var ret = func.Invoke(pickup.gameObject.GetComponent <AmmoPickup>(), null); if (pickup.pickupVFX != null) { player.PlayEffectOnActor(pickup.pickupVFX, Vector3.zero, true, false, false); } UnityEngine.Object.Destroy(pickup.gameObject); AkSoundEngine.PostEvent("Play_OBJ_ammo_pickup_01", pickup.gameObject); }
void Start() { Instance = this; }
void FixedUpdate() { //set up external script references Ironsights IronsightsComponent = GetComponent <Ironsights>(); FPSRigidBodyWalker FPSWalkerComponent = GetComponent <FPSRigidBodyWalker>(); PlayerWeapons PlayerWeaponsComponent = weaponObj.GetComponent <PlayerWeapons>(); WeaponBehavior WeaponBehaviorComponent = PlayerWeaponsComponent.weaponOrder[PlayerWeaponsComponent.currentWeapon].GetComponent <WeaponBehavior>(); //Exit application if escape is pressed if (Input.GetKey(exitGame)) { if (Application.isEditor || Application.isWebPlayer) { //Application.Quit();//not used } else { //use this quit method because Application.Quit(); can cause crashes on exit in Unity 4 //if this issue is resolved in a newer Unity version, use Application.Quit here instead System.Diagnostics.Process.GetCurrentProcess().Kill(); } } //Restart level if v is pressed if (Input.GetKey(restartScene)) { Time.timeScale = 1.0f; //set timescale to 1.0f so fadeout wont take longer if bullet time is active GameObject llf = Instantiate(levelLoadFadeObj) as GameObject; //Create instance of levelLoadFadeObj //call FadeAndLoadLevel function with fadein argument set to false //in levelLoadFadeObj to restart level and fade screen out from black on level load llf.GetComponent <LevelLoadFade>().FadeAndLoadLevel(Color.black, 2.0f, false); //set restarting var to true to be accessed by FPSRigidBodyWalker script to stop rigidbody movement restarting = true; // Disable all scripts to deactivate player control upon player death foreach (var c in children) { Component[] coms = c.GetComponentsInChildren <MonoBehaviour>(); foreach (var b in coms) { MonoBehaviour p = b as MonoBehaviour; if (p) { p.enabled = false; } } } } //toggle or hold zooming state by determining if zoom button is pressed or held if (Input.GetKey(zoom) && WeaponBehaviorComponent.canZoom && !(FPSWalkerComponent.climbing && FPSWalkerComponent.lowerGunForClimb)) { if (!zoomStartState) { zoomStart = Time.time; //track time that zoom button was pressed zoomStartState = true; //perform these actions only once zoomEndState = false; if (zoomEnd - zoomStart < zoomDelay * Time.timeScale) //if button is tapped, toggle zoom state { if (!zoomed) { zoomed = true; } else { zoomed = false; } } } } else { if (!zoomEndState) { zoomEnd = Time.time; //track time that zoom button was released zoomEndState = true; zoomStartState = false; if (zoomEnd - zoomStart > zoomDelay * Time.timeScale) //if releasing zoom button after holding it down, stop zooming { zoomed = false; } } } //track when player stopped zooming to allow for delay of reticle becoming visible again if (zoomed) { zoomBtnState = false; //only perform this action once per button press } else { if (!zoomBtnState) { zoomStopTime = Time.time; zoomBtnState = true; } } //enable and disable crosshair based on various states like reloading and zooming if (IronsightsComponent.reloading || zoomed) { //don't disable reticle if player is using a melee weapon or if player is unarmed if (WeaponBehaviorComponent.meleeSwingDelay == 0 && !WeaponBehaviorComponent.unarmed) { if (crosshairVisibleState) { //disable the GUITexture element of the instantiated crosshair object //and set state so this action will only happen once. CrosshairGuiObjInstance.GetComponent <GUITexture>().enabled = false; crosshairVisibleState = false; } } } else { //Because of the method that is used for non magazine reloads, an additional check is needed here //to make the reticle appear after the last bullet reload time has elapsed. Proceed with no check //for magazine reloads. if ((WeaponBehaviorComponent.bulletsPerClip != WeaponBehaviorComponent.bulletsToReload && WeaponBehaviorComponent.reloadLastStartTime + WeaponBehaviorComponent.reloadLastTime < Time.time) || WeaponBehaviorComponent.bulletsPerClip == WeaponBehaviorComponent.bulletsToReload) { //allow a delay before enabling crosshair again to let the gun return to neutral position //by checking the zoomStopTime value if (!crosshairVisibleState && (zoomStopTime + 0.2f < Time.time)) { CrosshairGuiObjInstance.GetComponent <GUITexture>().enabled = true; crosshairVisibleState = true; } } } if (WeaponBehaviorComponent.showAimingCrosshair) { reticleColor.a = 0.25f; CrosshairGuiObjInstance.GetComponent <GUITexture>().color = reticleColor; } else { //make alpha of aiming reticle zero/transparent reticleColor.a = 0.0f; //set alpha of aiming reticle at start to prevent it from showing, but allow item pickup hand reticle CrosshairGuiObjInstance.GetComponent <GUITexture>().color = reticleColor; } //Pick up items RaycastHit hit; if (!IronsightsComponent.reloading && //no item pickup when reloading !WeaponBehaviorComponent.lastReload && //no item pickup when when reloading last round in non magazine reload !PlayerWeaponsComponent.switching && //no item pickup when switching weapons (!FPSWalkerComponent.canRun || FPSWalkerComponent.inputY == 0) //no item pickup when sprinting //there is a small delay between the end of canRun and the start of sprintSwitching (in PlayerWeapons script), //so track actual time that sprinting stopped to avoid the small time gap where the pickup hand shows briefly && ((FPSWalkerComponent.sprintStopTime + 0.4f) < Time.time)) { //raycast a line from the main camera's origin using a point extended forward from camera position/origin as a target to get the direction of the raycast //and scale the distance of the raycast based on the playerHeightMod value in the FPSRigidbodyWalker script if (Physics.Raycast(mainCamTransform.position, ((mainCamTransform.position + mainCamTransform.forward * (5.0f + (FPSWalkerComponent.playerHeightMod * 0.25f))) - mainCamTransform.position).normalized, out hit, 2.0f + FPSWalkerComponent.playerHeightMod, rayMask)) { if (hit.collider.gameObject.tag == "Usable") //if the object hit by the raycast is a pickup item and has the "Usable" tag { if (pickUpBtnState && Input.GetKey(use)) { //run the PickUpItem function in the pickup object's script hit.collider.SendMessageUpwards("PickUpItem", SendMessageOptions.DontRequireReceiver); //run the ActivateObject function of this object's script if it has the "Usable" tag hit.collider.SendMessageUpwards("ActivateObject", SendMessageOptions.DontRequireReceiver); pickUpBtnState = false; FPSWalkerComponent.cancelSprint = true; } //determine if pickup item is using a custom pickup reticle and if so set pickupTex to custom reticle if (pickUpBtnState) //check pickUpBtnState to prevent reticle from briefly showing custom/general pickup icon briefly when picking up last weapon before maxWeapons are obtained //determine if item under reticle is a weapon pickup { if (hit.collider.gameObject.GetComponent <WeaponPickup>()) { //set up external script references WeaponBehavior PickupWeaponBehaviorComponent = PlayerWeaponsComponent.weaponOrder[hit.collider.gameObject.GetComponent <WeaponPickup>().weaponNumber].GetComponent <WeaponBehavior>(); WeaponPickup WeaponPickupComponent = hit.collider.gameObject.GetComponent <WeaponPickup>(); if (PlayerWeaponsComponent.totalWeapons == PlayerWeaponsComponent.maxWeapons && //player has maximum weapons PickupWeaponBehaviorComponent.addsToTotalWeaps) //weapon adds to total inventory //player does not have weapon under reticle { if (!PickupWeaponBehaviorComponent.haveWeapon //and weapon under reticle hasn't been picked up from an item with removeOnUse set to false && !PickupWeaponBehaviorComponent.dropWillDupe) { if (!useSwapReticle) //if useSwapReticle is true, display swap reticle when item under reticle will replace current weapon { if (WeaponPickupComponent.weaponPickupReticle) { //display custom weapon pickup reticle if the weapon item has one defined pickupTex = WeaponPickupComponent.weaponPickupReticle; } else { //weapon has no custom pickup reticle, just show general pickup reticle pickupTex = pickupReticle; } } else { //display weapon swap reticle if player has max weapons and can swap held weapon for pickup under reticle pickupTex = swapReticle; } } else { //weapon under reticle is not removed on use and is in player's inventory, so show cantPickup reticle if (!WeaponPickupComponent.removeOnUse) { pickupTex = noPickupReticle; } else //weapon is removed on use, so show standard or custom pickup reticle { if (WeaponPickupComponent.weaponPickupReticle) { //display custom weapon pickup reticle if the weapon item has one defined pickupTex = WeaponPickupComponent.weaponPickupReticle; } else { //weapon has no custom pickup reticle, just show general pickup reticle pickupTex = pickupReticle; } } } } else //total weapons not at maximum and weapon under reticle does not add to inventory { if (!PickupWeaponBehaviorComponent.haveWeapon && !PickupWeaponBehaviorComponent.dropWillDupe || WeaponPickupComponent.removeOnUse) { if (WeaponPickupComponent.weaponPickupReticle) { //display custom weapon pickup reticle if the weapon item has one defined pickupTex = WeaponPickupComponent.weaponPickupReticle; } else { //weapon has no custom pickup reticle, just show general pickup reticle pickupTex = pickupReticle; } } else { pickupTex = noPickupReticle; } } //determine if item under reticle is a health pickup } else if (hit.collider.gameObject.GetComponent <HealthPickup>()) { //set up external script references HealthPickup HealthPickupComponent = hit.collider.gameObject.GetComponent <HealthPickup>(); if (HealthPickupComponent.healthPickupReticle) { pickupTex = HealthPickupComponent.healthPickupReticle; } else { pickupTex = pickupReticle; } //determine if item under reticle is an ammo pickup } else if (hit.collider.gameObject.GetComponent <AmmoPickup>()) { //set up external script references AmmoPickup AmmoPickupComponent = hit.collider.gameObject.GetComponent <AmmoPickup>(); if (AmmoPickupComponent.ammoPickupReticle) { pickupTex = AmmoPickupComponent.ammoPickupReticle; } else { pickupTex = pickupReticle; } } else { pickupTex = pickupReticle; } } UpdateReticle(false); //show pickupReticle if raycast hits a pickup item } else { if (crosshairTextureState) { UpdateReticle(true); //show aiming reticle crosshair if item is not a pickup item } } } else { if (crosshairTextureState) { UpdateReticle(true); //show aiming reticle crosshair if raycast hits nothing } } } else { if (crosshairTextureState) { UpdateReticle(true); //show aiming reticle crosshair if reloading, switching weapons, or sprinting } } //only register one press of E key to make player have to press button again to pickup items instead of holding E if (Input.GetKey(use)) { pickUpBtnState = false; } else { pickUpBtnState = true; } }