// Assign old active weapon to weapon loot on floor. void EquipWeapon(WeaponPickup weaponOnFloor) { SO_Weapon weapToDrop = charEquippedWeapons.activeWeapon; float weapOnFloorDurability = weaponOnFloor.durability; if (charEquippedWeapons.inactiveWeapon == null) { charEquippedWeapons.inactiveWeapon = charEquippedWeapons.activeWeapon; charEquippedWeapons.activeWeapon = weaponOnFloor.weaponBase; charEquippedWeapons.WeaponSwap(true); charEquippedWeapons.SetActiveWeaponDurability(weapOnFloorDurability); weaponOnFloor.TurnOff(); } else { weaponOnFloor.durability = charEquippedWeapons.GetActiveWeaponDurability(); charEquippedWeapons.activeWeapon = weaponOnFloor.weaponBase; weaponOnFloor.weaponBase = weapToDrop; weaponOnFloor.SwapWeaponLoot(weapToDrop); charEquippedWeapons.WeaponSwap(false); charEquippedWeapons.SetActiveWeaponDurability(weapOnFloorDurability); } // Change the HUD image of the active weapon. HUDManager.playerWeapons.PickUpWeapon(charEquippedWeapons.activeWeapon.weaponSprite, weapOnFloorDurability); Debug.Log("Dropped weapon: " + weapToDrop + " and equipped: " + charEquippedWeapons.activeWeapon); }
public void EquipWeapon(SO_Weapon itemToEquip) { switch (itemToEquip.slot) { case Slot.RIGHT_HANDED: if (rightHandedSlot != null) { UnEquipWeapon(rightHandedSlot); } rightHandedSlot = itemToEquip; weaponBaseDamage += itemToEquip.damage; break; default: break; } foreach (MyButton itButton in myButtonList) { if (itButton.item != null) { if (itButton.item.name == itemToEquip.name) { itButton.EquipItem(); } } } GameObject weaponPrefab = Instantiate(itemToEquip.prefab); weaponPrefab.transform.SetParent(GameManager.Instance.Player.PlayerWeaponAnchor); weaponPrefab.transform.localPosition = Vector3.zero; weaponPrefab.transform.localRotation = Quaternion.Euler(90f, 0f, 0f); crtWeapon = weaponPrefab; }
public void UnEquipWeapon(SO_Weapon itemToUnEquip) { foreach (MyButton itButton in myButtonList) { if (itButton.item != null) { if (itButton.item.name == itemToUnEquip.name) { itButton.UnEquipItem(); break; } } } switch (itemToUnEquip.slot) { case Slot.RIGHT_HANDED: weaponBaseDamage -= itemToUnEquip.damage; Destroy(GameManager.Instance.Player.PlayerWeaponAnchor.GetChild(0).gameObject); crtWeapon = null; rightHandedSlot = null; break; default: break; } }
public void RemoveWeapons(SO_Weapon _Weapon) { weaponsList.Remove(_Weapon); UpdateSlots(); if (weaponsFull == true && weaponsList.Contains(null)) { weaponsFull = false; } }
public void SwapWeaponLoot(SO_Weapon newWeapBase) { weaponBase = newWeapBase; if (!mySpriteR) { mySpriteR = this.GetComponent <SpriteRenderer>(); } mySpriteR.sprite = weaponBase.weaponSprite; // Play newloot anim? }
public void AddWeapon(SO_Weapon _Weapon) { if (this._Weapon != null) { RemoveWeapon(); } this._Weapon = _Weapon; GetBestSpell(out SO_Spell spell, out float spellRatio); npcController.CalculatePower(_Weapon, spell, spellRatio); }
public void AddWeapons(SO_Weapon _Weapon) { for (int n = 0; n < 3; n++) { if (weaponsList[n] == null) { weaponsList[n] = _Weapon; UpdateSlots(); if (!itemsList.Contains(null)) { weaponsFull = true; } break; } } }
// public bool NotInAnAttack() { // if (atkDurCoroutine != null) { // return false; // } // return true; // } // On weapon swap. public void OnWeaponSwap(SO_Weapon activeWeapon, SO_Weapon inactiveWeapon) { chainResetTimer = chainResetDelay; // If the next chain was higher then the max attack chains of the weapon that was just swapped, meaning that its last attack was done. if (nextChain >= inactiveWeapon.attackChains.Length) { nextChain = 0; curChain = 0; } // This is to keep the current chain, if its over the new first weapon's max chain count: set it to the last chain. if (nextChain >= activeWeapon.attackChains.Length) { nextChain = activeWeapon.attackChains.Length - 1; curChain = 0; } // Same as above but if its above the new first weapon's max chain count, set it to first chain. // This is to reset the chain. // nextChain = 0; // curChain = 0; charAtk.ReadyToAttack(true); }
public bool CanISwapWeapon() { // Weapon swap if two weapons are equipped. if (canSwapWeapon) { if (activeWeapon != null && inactiveWeapon != null && !weaponSwapOnCooldown) { SO_Weapon tempWeapon = inactiveWeapon; inactiveWeapon = activeWeapon; activeWeapon = tempWeapon; WeaponSwap(true); // HUD active weapon changes. HUDManager.playerWeapons.SwapActiveWeapon(); // Swap weapon cooldown. weaponSwapOnCooldown = true; StartCoroutine(WeaponSwapCooldown()); } return(true); } return(false); }
public void BreakActiveWeapon() { // Remove from HUD with appropriate effects. HUDManager.playerWeapons.RemoveBrokenWeapon(); // Remove from player with appropriate in-game effects and change the active weapon. StartCoroutine(SpawnWeaponPieces(activeWeapon.SO_brokenPiecesSpawner, Vector2.zero)); // Change weapon. Anything that requires the active weapon that just broke should be done before this. activeWeapon = inactiveWeapon; inactiveWeapon = null; if (activeWeapon != null) { WeaponSwap(true); // HUD active weapon changes. HUDManager.playerWeapons.SwapActiveWeapon(); } else { // No more weapons, what now? charAtk.weapon = null; // Shouldn't change this externally probably. weaponSpriteR.sprite = null; } // Allow the player to attack since the last attack of the weapon that broke was maybe not allowed to finish. Could set a delay for this to the time it would of taken to finish the last attack if it wasn't completed when the weapon broke. charAtk.ReadyToAttack(true); }
public void SpecialAttack() { charAtk.ReadyToAttack(false); mainSpecialSO = charAtk.weapon; SO_WindupFX[0] = mainSpecialSO.specialAttack.sO_AttackFXWindup[0]; SO_HoldFX[0] = mainSpecialSO.specialAttack.sO_AttackFXHold[0]; //print(mainSpecialSO.specialAttack.sO_AttackFXRelease.Length); SO_ReleaseFX.Clear(); for (int i = 0; i < mainSpecialSO.specialAttack.sO_AttackFXRelease.Length; i++) { //print("HELLO"); if (i >= SO_ReleaseFX.Count) { SO_ReleaseFX.Add(mainSpecialSO.specialAttack.sO_AttackFXRelease[i]); } else { SO_ReleaseFX[i] = mainSpecialSO.specialAttack.sO_AttackFXRelease[i]; } } SO_WindupCharMo = mainSpecialSO.specialAttack.sO_CharAtk_Motion; sOWeapoMo = mainSpecialSO.specialAttack.sO_Weapon_Motion; // Perform the special attack. // If the attack is triggered, make sure that the grace period is set back to false since it is used. moIn.attackButtonActions.attackButtonTapInGrace = false; // Disallow weapon swapping. charAtk.equippedWeapons.canSwapWeapon = false; // Stop the previous motion if needed. charAtk.StopPreviousMotion(); // Set the weapon back to its resting position and rotation. Usually the first attack chain's resting values. charAtk.ResetWeaponLocalValues(); // Allow character flip and the weapon to "look at" the mouse. charAtk.ForceCharFlipAndWeaponLookAt(); weaponMotion = charAtk.weaponMotionController.CheckMotionList(sOWeapoMo.weapon_Motion); //windupFX = null; //holdFX = null; //releaseFX = null; releaseFX.Clear(); windupFX[0] = charAtk.atkFXPool.RequestAttackFX(); windupFX[0].inUse = true; holdFX[0] = charAtk.atkFXPool.RequestAttackFX(); holdFX[0].inUse = true; for (int i = 0; i < SO_ReleaseFX.Count; i++) { if (i >= releaseFX.Count) { releaseFX.Add(charAtk.atkFXPool.RequestAttackFX()); } else { releaseFX[i] = charAtk.atkFXPool.RequestAttackFX(); } releaseFX[i].inUse = true; } if (specialAtkCoroutine != null) { specialAtkCoroutine = null; } specialAtkCoroutine = StartCoroutine(InSpecialAttack()); }
// public PolygonCollider2D[] attackColliders; // public bool[] activeAttacks; // public PolygonCollider2D attackCollider; // public List<Collider2D> collidersHit; // public List<Collider2D> collidersDamaged; public IEnumerator AttackCollider(bool attackFromWeaponOne, SO_Weapon sOWeapon, SO_Weapon.AttackChain WeapAtkChain, SO_AttackFX sO_AttackFX, PolygonCollider2D atkFXCol, Transform weapOrigTrans) { // References from the SO_AttackFX. float thisColStart = sO_AttackFX.colStart; float thisColEnd = sO_AttackFX.colEnd; // Set chosen pool attack FX collider off in case the attack FX dosn't use a collider. atkFXCol.enabled = false; SO_ImpactFX sO_ImpactFX = sO_AttackFX.soImpactFX; // Apply the collision shape and offset position to the chosen pool collider. atkFXCol.points = sO_AttackFX.collider.points; atkFXCol.offset = sO_AttackFX.collider.offset; // Set other variables. List <Collider2D> collidersHit = new List <Collider2D>(); List <Collider2D> collidersDamaged = new List <Collider2D>(); float timer = 0f; bool detectCol = false; bool hitAnEnemy = false; // Wait a frame to avoid having the collider appear for a frame at its last position, the atkFX's new position HAS to be set before the collider is enabled. (Maybe specifically for atkFX's that have the same colStart time, first sprite time and moveDelay all set to the same value) yield return(null); while (timer < thisColEnd) { timer += Time.deltaTime; if (timer >= thisColStart && !detectCol) { yield return(null); // If the attack has a collider, enable it otherwise leave it off. if (sO_AttackFX.collider) { atkFXCol.enabled = true; } detectCol = true; yield return(null); } if (detectCol) { // Detect hit collision. Physics2D.OverlapCollider(atkFXCol, hitLayers, collidersHit); foreach (Collider2D col in collidersHit) { if (!collidersDamaged.Contains(col)) { collidersDamaged.Add(col); // If this is an enemy, apply damage. if (col.gameObject.CompareTag("Enemy")) { col.GetComponent <Enemy_Health>().ReceiveDamage(WeapAtkChain.DamageRoll, charEquippedWeapons.activeWeapon.poiseDamage, atkFXCol.transform.position, col.bounds.center); // If at least one enemy is hit apply durability damage to the active weapon. if (!hitAnEnemy) { hitAnEnemy = true; if (sOWeapon.durabilityDamageOnHit) { charEquippedWeapons.DurabilityDamage(attackFromWeaponOne); } } } else if (col.gameObject.CompareTag("Destructible")) { col.GetComponent <Clutter_Health>().ReceiveDamage(WeapAtkChain.DamageRoll, atkFXCol.transform.position, col.bounds.center); } // Hit impact FX. Apply the correct rotation, position, sprites and layerMask to an impactFX. HitImpact.PlayImpactFX(atkFXCol, col.bounds.center, sO_ImpactFX, hitLayers.layerMask, col); // Set camera nudge backwards from the hit. CameraFollow.CameraNudge_St(weapOrigTrans.up, nudgeStrength); // Slow time. Duration to be set by weapon damage, slow to be adjusted (animation curve) by TimeSlow script. TimeSlow.StartTimeSlow(timeSlowDur); //Debug.Log("Collider: " + col.gameObject.name + " was hit! Hit hit, hurraay!"); } } } yield return(null); } if (collidersHit.Count > 0) { collidersHit.Clear(); collidersDamaged.Clear(); } atkFXCol.enabled = false; yield return(null); }