/// <summary> /// upon success, drops all the player's weapons /// </summary> protected virtual void TryDropAllWeapons() { if (WeaponHandler == null) { return; } foreach (KeyValuePair <vp_Weapon, vp_ItemIdentifier> w in Inventory.WeaponIdentifiers) { vp_Weapon weapon = w.Key; vp_ItemIdentifier weaponIdentifier = w.Value; // skip if weapon identifier has no item type vp_ItemType itemType = weaponIdentifier.GetItemType(); if (itemType == null) { continue; } // for unitbank weapons, try and set the weapon pickup's ammo // to the amount of ammo in the dropped weapon int units = 0; vp_UnitBankInstance unitBank = Inventory.GetUnitBankInstanceOfWeapon(weapon); if (unitBank != null) { units = unitBank.Count; } // drop the weapon TryDropWeapon(itemType, units, weaponIdentifier.ID); } }
/// <summary> /// upon success, unwields the current weapon of the player and waits /// for a little bit before tossing the weapon /// </summary> public virtual void TryDropCurrentWeapon(float pauseForUnwield = 0.3f) { if (WeaponHandler == null) { return; } if (WeaponHandler.CurrentWeapon == null) { return; } vp_ItemIdentifier identifier = WeaponHandler.CurrentWeapon.GetComponent <vp_ItemIdentifier>(); if (identifier == null) { return; } vp_ItemType itemType = identifier.GetItemType(); if (itemType == null) { return; } int units = Inventory.GetAmmoInCurrentWeapon(); Player.Unwield.Send(); vp_Timer.In(Mathf.Max(pauseForUnwield, 0.0f), () => { TryDropWeapon(itemType, units); }); }
/// <summary> /// tries to drop the currenlty loaded throwing weapon unit in the form /// of an ammo unit (rather than in the form of a weapon) /// </summary> protected virtual void TryDropLoadedThrowingUnit(vp_UnitType unitType) { vp_UnitBankType unitBankType = Inventory.GetThrowingWeaponUnitBankType(unitType); if (unitBankType == null) { return; } for (int v = (WeaponHandler.Weapons.Count - 1); v > -1; v--) { if (WeaponHandler.Weapons[v] == null) { continue; } vp_ItemIdentifier identifier = WeaponHandler.Weapons[v].GetComponent <vp_ItemIdentifier>(); if (identifier == null) { continue; } vp_ItemType iType = identifier.GetItemType(); if (iType == null) { continue; } if (iType != unitBankType) { continue; } for (int u = (Inventory.UnitBankInstances.Count - 1); u > -1; u--) { //Debug.Log("unittype: " + Inventory.UnitBankInstances[u].Type + ", count: " + Inventory.UnitBankInstances[u].Count); if (Inventory.UnitBankInstances[u].UnitType == unitBankType.Unit) { // if the throwing weapon is currently loaded with one unit (likely), move that unit // from the throwing weapon to the internal unitbank and drop it as an ammo clip if (Inventory.UnitBankInstances[u].Count == 1) { // move unit to internal unitbank Inventory.UnitBankInstances[u].DoRemoveUnits(1); vp_UnitBankInstance internalUnitBank = Inventory.GetInternalUnitBank(Inventory.UnitBankInstances[u].UnitType); internalUnitBank.DoAddUnits(1); // drop the moved unit if (TryDropAmmoClip(Inventory.UnitBankInstances[u].UnitType.name, 1)) { //Debug.Log("Dropped: " + Inventory.UnitBankInstances[v].UnitType.name + ",1"); } continue; } } } } }
/// <summary> /// analyzes the player weapons and inventory unitbank and unit types to /// figure out what weapons are throwing weapons, and caches this info /// </summary> protected virtual void StoreThrowingWeaponInfo() { foreach (vp_Weapon weapon in WeaponHandler.Weapons) { // if the weapon's animation type is 'thrown' ... if (!(weapon.AnimationType == (int)vp_Weapon.Type.Thrown)) { continue; } // ... and it has an item identifier ... vp_ItemIdentifier identifier = weapon.GetComponent <vp_ItemIdentifier>(); if (identifier == null) { continue; } // ... and the identifier is for a unitbank ... vp_UnitBankType unitBankType = (identifier.GetItemType() as vp_UnitBankType); if (unitBankType == null) { continue; } // --- then consider it a throwing weapon unitbank type --- // store the unitbank type under its unit type if (!m_ThrowingWeaponUnitBankTypes.ContainsKey(unitBankType.Unit)) { m_ThrowingWeaponUnitBankTypes.Add(unitBankType.Unit, unitBankType); } // store the unit type as known throwing weapon ammo if (!m_ThrowingWeaponUnitTypes.Contains(unitBankType.Unit)) { m_ThrowingWeaponUnitTypes.Add(unitBankType.Unit); } // if the inventory has a unitbank instance for this weapon ... vp_UnitBankInstance unitBankInstance = GetUnitBankInstanceOfWeapon(weapon); if (unitBankInstance == null) { continue; } // ... then store it by its unitbank type if (!m_ThrowingWeaponUnitBankInstances.ContainsKey(unitBankType)) { m_ThrowingWeaponUnitBankInstances.Add(unitBankType, unitBankInstance); } } m_HaveThrowingWeaponInfo = true; }
/// <summary> /// upon success, drops a weapon of the passed 'itemType' /// </summary> public virtual void TryDropWeapon(vp_ItemType itemType, int units = 0, int id = 0) { if (WeaponHandler == null) { return; } if (itemType == null) { return; } if (Player == null) { return; } if (Player.Reload.Active) { return; } if (Player.Attack.Active) { Player.Attack.Stop(); } for (int v = (WeaponHandler.Weapons.Count - 1); v > -1; v--) { if (WeaponHandler.Weapons[v] == null) { continue; } vp_ItemIdentifier identifier = WeaponHandler.Weapons[v].GetComponent <vp_ItemIdentifier>(); if (identifier == null) { continue; } vp_ItemType iType = identifier.GetItemType(); if (iType == null) { continue; } if (iType != itemType) { continue; } if (id <= 0) { TryDropItem(itemType, units, 0); return; } else { TryDropItem(itemType, units, identifier.ID); return; } } }