///────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── /// <summary> ///Get a Callback From the RiderCombat Layer Weapons States /// </summary> public virtual void WeaponSound(int SoundID) { if (Active_IMWeapon != null) { Active_IMWeapon.PlaySound(SoundID); } }
///────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── /// <summary> /// Unequip Weapon from Holders or from Inventory /// </summary> public virtual void Unequip_Weapon() { _weaponType = WeaponType.None; SetAction(WeaponActions.Unequip); LinkAnimator(); if (Active_IMWeapon == null) { return; } if (debug) { Debug.Log("Unequip_Weapon"); } Active_IMWeapon.Unequiped(); //Let the weapon know that it has been unequiped OnUnequipWeapon.Invoke(ActiveWeapon); //Let the rider know that the weapon has been unequiped. if (UseHolders) //If Use Holders Parent the ActiveMWeapon the the Holder { ActiveWeapon.transform.parent = ActiveHolderTransform.transform; //Parent the weapon to his original holder StartCoroutine(SmoothWeaponTransition(ActiveWeapon.transform, Vector3.zero, Vector3.zero, 0.3f)); } else if (UseInventory && !AlreadyInstantiated && ActiveWeapon) { Destroy(ActiveWeapon); } activeWeapon = null; }
///────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── /// <summary> /// Sets the weapon that are in the Inventory /// </summary> /// <param name="Next_Weapon">Game object that it should have an IMWeapon Interface</param> public virtual void SetWeaponByInventory(GameObject Next_Weapon) { StopAllCoroutines(); if (!rider.IsRiding) { return; //Work Only when is riding else Skip } if (Next_Weapon == null) //That means Store the weapon { if (ActiveWeapon) { Store_Weapon(); //Debug.Log("Active Weapon NOT NULL Store the Active Weapon"); } return; } IMWeapon Next_IMWeapon = Next_Weapon.GetComponent <IMWeapon>(); if (Next_IMWeapon == null) { if (ActiveWeapon) { Store_Weapon(); //Debug.Log("Active Weapon NOT NULL and Store because Next Weapon is not Compatible"); } return; //If the Next Weapon doesnot have the IMWeapon Interface dismiss... the next weapon is not compatible } if (Active_IMWeapon == null) { if (!AlreadyInstantiated) { Next_Weapon = Instantiate(Next_Weapon, rider.transform); //Instanciate the Weapon GameObject Next_Weapon.SetActive(false); } SetActiveWeapon(Next_Weapon); Draw_Weapon(); //Debug.Log("Active weapon is NULL so DRAW"); return; } if (Active_IMWeapon.Equals(Next_IMWeapon)) //Option 2 If the Weapon has the Same ID { if (!IsInCombatMode) { Draw_Weapon(); //Debug.Log("Active weapon is the same as the NEXT Weapon and we are NOT in COmbat so DRAW"); } else { Store_Weapon(); //Debug.Log("Active weapon is the same as the NEXT Weapon and we ARE in COmbat so STORE"); } } else //If the weapons are different Swap it { StartCoroutine(SwapWeaponsInventory(Next_Weapon)); //Debug.Log("Active weapon is DIFFERENT to the NEXT weapon so Switch" + Next_Weapon); } }
///────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── /// <summary> /// Equip Weapon from Holders or from Inventory /// </summary> public virtual void Equip_Weapon() { SetAction(WeaponActions.Equip); //Set the Action to Equip isInCombatMode = true; if (Active_IMWeapon == null) { return; } if (debug) { Debug.Log("Equip_Weapon"); } Active_IMWeapon.HitMask = HitMask; //Update the Hit Mask in the weapon if (UseHolders) //If Use Holders Means that the weapons are on the Holders { if (ActiveHolderTransform.transform.childCount > 0) //If there's a Weapon on the Holder { SetActiveWeapon(ActiveHolderTransform.GetChild(0).gameObject); //Set the Active Weapon as the First Child Inside the Holder ActiveWeapon.transform.parent = Active_IMWeapon.RightHand ? RightHandEquipPoint : LeftHandEquipPoint; //Parent the Active Weapon to the Right/Left Hand Active_IMWeapon.Holder = ActiveHolderSide; StartCoroutine(SmoothWeaponTransition (ActiveWeapon.transform, Active_IMWeapon.PositionOffset, Active_IMWeapon.RotationOffset, 0.3f)); //Smoothly put the weapon in the hand } } else if (UseInventory) //If Use Inventory means that the weapons are on the inventory { if (!AlreadyInstantiated) //Do this if the Instantiation is not handled Externally { ActiveWeapon.transform.parent = Active_IMWeapon.RightHand ? RightHandEquipPoint : LeftHandEquipPoint; //Parent the Active Weapon to the Right/Left Hand ActiveWeapon.transform.localPosition = Active_IMWeapon.PositionOffset; //Set the Correct Position ActiveWeapon.transform.localEulerAngles = Active_IMWeapon.RotationOffset; //Set the Correct Rotation } ActiveWeapon.gameObject.SetActive(true); //Set the Game Object Instance Active } Active_IMWeapon.Equiped(); //Inform the weapon that it has been equipped OnEquipWeapon.Invoke(ActiveWeapon); //Let everybody know that the weapon is equipped if (ActiveAbility) { ActiveAbility.ActivateAbility(); //Call For the first activation of the weapon when first Equipped } }
///────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── /// <summary> /// If the Rider had a weapon before mounting.. equip it. /// The weapon need an |IMWeapon| Interface, if not it wont be equiped /// </summary> public virtual void SetWeaponBeforeMounting(GameObject weapon) { if (weapon == null) { return; } if (weapon.GetComponent <IMWeapon>() == null) { return; //If the weapon doesn't have IMweapon Interface do nothing } /// Try the set to false the weapon if is not a Prefab /// SetActiveWeapon(weapon); isInCombatMode = true; Active_IMWeapon.Equiped(); //Let the weapon know that it has been Equiped EnableMountAttack(false); SetActiveHolder(Active_IMWeapon.Holder); //Set the Active Holder for the Active Weapon _weaponType = GetWeaponType(); //Set the Weapon Type SetAction(WeaponActions.Idle); SetWeaponIdleAnimState(Active_IMWeapon.RightHand); //Set the Correct Idle Hands Animations Active_IMWeapon.HitMask = HitMask; //Link the Hit Mask ActiveAbility = CombatAbilities.Find(ability => ability.WeaponType() == GetWeaponType()); //Find the Ability for the IMWeapon if (ActiveAbility) { ActiveAbility.ActivateAbility(); } else { Debug.LogWarning("The Weapon is combatible but there's no Combat Ability available for it, please Add the matching ability it on the list of Combat Abilities"); } OnEquipWeapon.Invoke(ActiveWeapon); LinkAnimator(); }