public void SetAbility(WeaponItem weapon, ScriptableUseableAbility newAbility) { ScriptableAbility = newAbility; Modifiers.Clear(); if (weapon) { //override the modifiers to add the attack bonus var attackModifier = ScriptableObject.CreateInstance <ScriptableStatModifier>(); attackModifier.Type = StatType.ATTACK; attackModifier.Amount = weapon.attack; var AbilityModifier = new AbilityModifier(); AbilityModifier.Modifier = attackModifier; AbilityModifier.Stage = ModifierStage.ACTION; AbilityModifier.Target = ModifierTarget.CASTER; Modifiers.Insert(0, AbilityModifier); } if (worldGameObject) { Destroy(worldGameObject); } Initilise(); }
private void SetAbilitySlot(int index, InventoryItem inventoryItem) { ScriptableUseableAbility ability = inventoryItem?.Item as ScriptableUseableAbility; Sprite slotSprite = ability ? ability.Sprite : baseSprite; if (index >= 0) { AbilitySlots[index] = ability; AbilityImages[index].sprite = slotSprite; } else { //index was -1 meaning there was no ability to be set so remove the current player ability PlayerAbility?.SetAbility(null, null); } if (index == 0) { //get the equiped weapon WeaponItem weapon = inventoryItem?.Item as WeaponItem; //if weapon is null try and get the weapon from the equiped slot instead if (!weapon) { switch (Hand) { case HandType.LEFT: weapon = inventoryHandler.itemInventory.leftWeaponSlot.equippedSlot.InventoryItem?.Item as WeaponItem; break; case HandType.RIGHT: weapon = inventoryHandler.itemInventory.rightWeaponSlot.equippedSlot.InventoryItem?.Item as WeaponItem; break; default: break; } } // if the new ability is null then default to the players weapon (Base Attack) if (!ability && BaseAbility) { if (weapon) { PlayerAbility?.SetAbility(weapon, BaseAbility); } else { PlayerAbility?.SetAbility(null, null); } } else { PlayerAbility?.SetAbility(weapon, ability); //also set the players ability } } }
private void updateCooldowns() { for (int i = 0; i < CoolDownImages.Length; i++) { if (!CoolDownImages[i]) { continue; } //get the ability for the cooldown ScriptableUseableAbility ability = handSlots[i].equippedSlot.InventoryItem?.Item as ScriptableUseableAbility; if (!ability) { CoolDownImages[i].enabled = false; continue; } //check the last use time for the ability in the players useable ability hand float lastUseTime = Time.time; if (PlayerAbility.LastUseDictionary.ContainsKey(ability)) { lastUseTime = PlayerAbility.LastUseDictionary[ability]; } float cooldownTime = Mathf.Min((Time.time - lastUseTime) / ability.Cooldown, 1); if (cooldownTime >= 1.0f && CoolDownImages[i].IsActive()) { CoolDownImages[i].enabled = false; } else if (cooldownTime < 1.0f && !CoolDownImages[i].IsActive()) { CoolDownImages[i].enabled = true; } CoolDownImages[i].fillAmount = cooldownTime; } }
protected BaseAbility(UseableAbility useableAbility, CharacterBase ownerCharacter) { this.ability = useableAbility.ScriptableAbility; this.useableAbility = useableAbility; this.ownerCharacter = ownerCharacter; }