protected bool AddWeaponItem(InventoryItemWeapon inventoryItemWeapon, CollectableWeapon collectableWeapon) { foreach (var w in _weapons) { if (w.Weapon == null) { w.Weapon = inventoryItemWeapon; w.Rounds = collectableWeapon.Rounds; inventoryItemWeapon.Pickup(collectableWeapon.transform.position); return(true); } } return(false); }
public void DropWeapon() { if (weapon != null) { weapon.transform.SetParent(propsManager); // Waffe vom Waffenanker lösen weapon.Drop(); // Waffe fallen lassen weapon = null; // Referenz auf die Waffe löschen } if (network != null) { network.Mode = PropMode.auto; // Waffenposition wieder vom Netzwerk verarbeiten lassen network.On_Network_DataRecieved -= DropWeapon; network = null; // Referenz auf die Netzwerkkomponente löschen } }
// -------------------------------------------------------------------------------------------- // Name : AddWeaponItem // Desc : Adding weapons is actually handled very differently from other // objects. All this function does is record the object we wish // to change to and send out a message to invoke the correct dismount/mount // animations. The ACTUAL pickup is deferred until AssignWeapon function // is called by the Listener. // Note : In DeadEarth the listener is the CharacterManager's which handles syncing // weapon animation. // -------------------------------------------------------------------------------------------- protected bool AddWeaponItem(InventoryItemWeapon inventoryItemWeapon, CollectableWeapon collectableWeapon, bool playAudio) { // Is the weapon we are about to pick up single handled or two handed weapon int mountIndex = (inventoryItemWeapon.weaponType == InventoryWeaponType.SingleHanded) ? 0 : 1; // Create a mount info object to describe the weapon and instance data we wish // to change to. InventoryWeaponMountInfo wmi = new InventoryWeaponMountInfo(); wmi.Weapon = inventoryItemWeapon; wmi.Condition = collectableWeapon.condition; wmi.InGunRounds = collectableWeapon.rounds; // Invoke event so the object in charge of weapon switching and animation (our CharacterManager for example) // can set the process of switching in motion. OnWeaponChange.Invoke(wmi); return(true); }
// Methode die vom Spielercharackter aufgreufen wird wenn er eine Waffe aufnimmt public void DrawWeapon(CollectableWeapon weapon) { if (!weapon || GameObject.ReferenceEquals(this.weapon, weapon)) { return; } // Aktuelle Waffe löschen DropWeapon(); // Waffe aufheben this.weapon = weapon; this.weapon.PickUp(); network = this.weapon.GetComponent <Network_SendTransform>(); // Referenz auf die Netzwerkkomponente merken network.Mode = PropMode.inactive; // Waffenposition nicht mehr über das Netzwerk senden network.On_Network_DataRecieved += DropWeapon; this.weapon.transform.SetParent(transform); // Waffe an den Waffenanker hängen this.weapon.transform.localPosition = new Vector3(); // Am Anker positionieren this.weapon.transform.localRotation = Quaternion.identity; // Am Anker rotieren }
// -------------------------------------------------------------------------------------------- // Name : DropWeaponItem // Desc : Drop the weapon at the specified mount into the scene // -------------------------------------------------------------------------------------------- public override void DropWeaponItem(int mountIndex, bool playAudio = true) { if (mountIndex < 0 || mountIndex >= _weapons.Count) { return; } // Chck we have a valid BackPack mount in the inventory InventoryWeaponMountInfo itemMount = _weapons[mountIndex]; if (itemMount == null || itemMount.Weapon == null) { return; } // This is the weapon we want to drop InventoryItemWeapon weapon = itemMount.Weapon; // Drop it into the scene Vector3 position = _playerPosition != null ? _playerPosition.value : Vector3.zero; position += _playerDirection != null ? _playerDirection.value : Vector3.zero; CollectableWeapon sceneWeapon = weapon.Drop(position, playAudio) as CollectableWeapon; if (sceneWeapon) { // Copy over instance data from mount into proxy sceneWeapon.condition = itemMount.Condition; sceneWeapon.rounds = itemMount.InGunRounds; } // Nullify the slot so it is empty _weapons[mountIndex].Weapon = null; // Broadcast event that this weapon has been dropped OnWeaponDropped.Invoke(weapon); }
private void pickupWeapon(CollectableWeapon weapon) { WeaponController.ActivateWeapon(weapon.WeaponIdentifier); }
public void ReplaceWeapon(bool atStart = false, InventoryWeaponMount theWeaponMount = null, int whichRifle = -1) { if (theWeaponMount.item == null) { return; } // We first get the weapon holder that we are gonna need GameObject weaponHolder = GoneWrong.Player.instance.weaponHolder; // Deciding which rifle we are gonna replace in case the weaponmount item is of type rifle if (whichRifle == -1) { whichRifle = _playerInventory.rifle1.item == null ? 1 : 2; } // Get the weapon to drop InventoryWeaponMount weaponToDrop = null; // We don't drop any weapon if we are the start of the game if (!atStart) { if (theWeaponMount.item.weaponType == WeaponType.Handgun) { weaponToDrop = _playerInventory.handgun; } else if (theWeaponMount.item.weaponType == WeaponType.Melee) { weaponToDrop = _playerInventory.melee; } else if (theWeaponMount.item.weaponType == WeaponType.Rifle) { weaponToDrop = whichRifle == 1 ? _playerInventory.rifle1 : _playerInventory.rifle2; } } // Then we drop the weapon here: if (weaponToDrop != null && weaponToDrop.item != null && weaponToDrop.item.collectableWeapon != null /* We only replace when the weapon that's about to be equipped is different from the existing one*/ && weaponToDrop.item != this._weaponMount.item // We don't have to drop anything if it's the start of the game && !atStart) { // We instantiate the collectable weapon CollectableWeapon collectableWeapon = Instantiate(weaponToDrop.item.collectableWeapon, transform.position, Quaternion.identity); // Then we assign the number of rounds to the collectable weapon collectableWeapon._weaponMount.rounds = weaponToDrop.rounds; // Then we unregister the weapon in player and remove it from the hierarchy // Then we find the weapon to dismiss from the hierarchy through its name string weaponName = collectableWeapon._weaponControl.name; if (weaponHolder != null) { Transform weaponControlTransform = weaponHolder.transform.Find(weaponName + "(Clone)"); // Then once it is unregistered, we just delete it from the hierarchy if (weaponControlTransform != null) { Destroy(weaponControlTransform.gameObject); } } } // We play the pick weapon audio sound if (GoneWrong.AudioManager.instance != null && _pickSound != null) { GoneWrong.AudioManager.instance.PlayOneShotSound(_pickSound, 1, 0, 0); } // Then we replace the weapon mount with the new one if (theWeaponMount.item.weaponType == WeaponType.Handgun) { _playerInventory.handgun = theWeaponMount; } else if (theWeaponMount.item.weaponType == WeaponType.Melee) { _playerInventory.melee = theWeaponMount; } else if (theWeaponMount.item.weaponType == WeaponType.Rifle) { if (whichRifle == 1) { _playerInventory.rifle1 = theWeaponMount; } else { _playerInventory.rifle2 = theWeaponMount; } } // Then we add the weaponControl to the player weaponHolder and register it // We instantiate the weaponControl anywhere in the scene first if (_weaponControl != null) { // Get the temporary position and rotation of the weaponcontrol Vector3 position = _weaponControl.transform.position; Quaternion rotation = _weaponControl.transform.rotation; GoneWrong.WeaponControl weaponControl = Instantiate(_weaponControl); // We make of the weapon holder the parent of the weapon control that we just instantiated if (weaponHolder != null) { weaponControl.transform.parent = weaponHolder.transform; weaponControl.transform.localPosition = position; weaponControl.transform.localRotation = rotation; // If we are at the start of the game (loading the weapon from the saved game or having it in the inventory by default), // then we deactivate the weapon (to increase game performance) if (atStart) { weaponControl.gameObject.SetActive(false); } } } // Then we switch to the raplacing weapon // We don't have to switch to anything if it's the start of the game if (!atStart) { SwitchWeapon(theWeaponMount, whichRifle); /*IEnumerator coroutine = SwitchWeapon(theWeaponMount, whichRifle); * StartCoroutine(coroutine);*/ } // Then we make the collectable weapon disappear from the scene if (!atStart) { Destroy(gameObject); } }