//Function called every time this effect ticks private void ThreatenCharacter() { //If this threatens all enemies if (this.threatenAllEnemies) { CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, this.threatAddedPerTick, true); //If we have a visual for this effect, we need to spawn it on all of the enemies if (this.visualEffect != null) { //Looping through every enemy in this encounter foreach (Character enemy in CombatManager.globalReference.enemyCharactersInCombat) { //Creating the visual effect for this effect CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(enemy); this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform); } } } //If this threatens only the target else { this.characterToEffect.GetComponent <EnemyCombatAI_Basic>().IncreaseThreat(this.characterWhoTriggered, this.threatAddedPerTick); //If we have a visual for this effect, we need to spawn it on the target enemy if (this.visualEffect != null) { //Creating the visual effect for this effect CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(this.characterToEffect); this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform); } } //Counting down the ticks remaining this.ticksLeft -= 1; //If the ticks left hits 0, the effect is over if (this.ticksLeft <= 0) { //If we re-apply the threat, we send the inverse of the initial threat if (this.reapplyThreatWhenRemoved) { //If this threatens all enemies if (this.threatenAllEnemies) { CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, this.initialThreatAdded * -1, true); } //If this threatens only the target else { this.characterToEffect.GetComponent <EnemyCombatAI_Basic>().IncreaseThreat(this.characterWhoTriggered, this.initialThreatAdded * -1); } } //removing this effect this.RemoveEffect(); } }
//Function called when the player's mouse is no longer over this tile public void OnPointerExit(PointerEventData eventData_) { //If a character is moving right now and this tile is in the movement path, we don't stop highlighting if (CombatActionPanelUI.globalReference.selectedAction != null && CombatActionPanelUI.globalReference.selectedAction.GetComponent <MoveAction>()) { //If this tile isn't in the movement path, this tile isn't highlighted if (!CombatActionPanelUI.globalReference.selectedAction.GetComponent <MoveAction>().IsTileInMovementPath(this)) { this.HighlightTile(false); //If we have a character on this tile, we make sure they're hidden again if (this.inActionRange && this.objectOnThisTile != null && this.objectOnThisTile.GetComponent <Character>()) { //Making sure the character isn't the acting character if (CombatManager.globalReference.actingCharacters.Count > 0 && this.objectOnThisTile.GetComponent <Character>() != CombatManager.globalReference.actingCharacters[0]) { //Getting the sprite base for the character CharacterSpriteBase cSprite = CombatManager.globalReference.GetCharacterSprite(this.objectOnThisTile.GetComponent <Character>()); cSprite.MakeSpritesTransparent(); } } } } else { //Stops hilighting this tile's image this.HighlightTile(false); //Stops highlighting any effect radius if there's a selected attack ability this.HighlightEffectRadius(false); //If we have a character on this tile, we make sure they're hidden again if (this.inActionRange && this.objectOnThisTile != null && this.objectOnThisTile.GetComponent <Character>()) { //Making sure the character isn't the acting character if (this.objectOnThisTile.GetComponent <Character>() != CombatManager.globalReference.actingCharacters[0]) { //Getting the sprite base for the character CharacterSpriteBase cSprite = CombatManager.globalReference.GetCharacterSprite(this.objectOnThisTile.GetComponent <Character>()); cSprite.MakeSpritesTransparent(); } } } mouseOverTile = null; }
//Function called from OnEnable and CyclePartyCharacter to set the selected player character sprite private void SetPartyCharSprite() { //Destroying the player sprite that we previously had Destroy(this.playerSprite); //Creating an instance of the newly selected character's sprite base GameObject spriteBase = GameObject.Instantiate(this.selectedCharacter.charSprites.allSprites.spriteBase.gameObject); this.playerSprite = spriteBase.GetComponent <CharacterSpriteBase>(); //Setting the sprite base's position this.playerSprite.transform.localPosition = this.playerCharSpriteLoc.localPosition; //Setting the sprite base's sprites and making it face left this.playerSprite.SetSpriteImages(this.selectedCharacter.charSprites.allSprites, this.selectedCharacter.charInventory); this.playerSprite.SetDirectionFacing(CharacterSpriteBase.DirectionFacing.Left); }
//Function called when the player's mouse starts hovering over this tile public void OnPointerEnter(PointerEventData eventData_) { //Hilighting this tile's image this.HighlightTile(true); mouseOverTile = this; //Highlighting any effect radius if there's a selected attack ability this.HighlightEffectRadius(true); //If we have a character on this tile, we make sure they're visible if (this.inActionRange && this.objectOnThisTile != null && this.objectOnThisTile.GetComponent <Character>()) { //Making sure the character isn't the acting character if (CombatManager.globalReference.actingCharacters.Count > 0 && this.objectOnThisTile.GetComponent <Character>() != CombatManager.globalReference.actingCharacters[0]) { //Getting the sprite base for the character CharacterSpriteBase cSprite = CombatManager.globalReference.GetCharacterSprite(this.objectOnThisTile.GetComponent <Character>()); cSprite.MakeSpritesVisible(); } } }
//Function called whenever this effect heals the target character private void HealCharacter() { //Making sure the character isn't dead before healing if (this.characterToEffect.charPhysState.currentHealth <= 0) { return; } //Seeing if this effect will trigger float triggerRoll = Random.Range(0, 1); if (triggerRoll > this.chanceToTrigger) { //If we roll over the trigger chance, nothing happens and we don't tick return; } //Finding out how much health we heal this tick int damagehealed = Mathf.RoundToInt(Random.Range(this.healPerTickRange.x, this.healPerTickRange.y)); //Finding out if we crit float critRoll = Random.Range(0, 1); bool didThisCrit = false; if (critRoll < this.critChance) { //If we crit this tick, the amount healed is multiplied damagehealed = damagehealed * this.critMultiplier; didThisCrit = true; } //Looping through the perks of the character that used this ability to see if they have any damage type boost perks foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks) { if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && this.healType == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost) { damagehealed += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(this.characterWhoTriggered, didThisCrit, true, this.healType); } } //Looping through the defending character's perks to see if they have any spell resist or absorb perks SpellResistTypes magicResistType = SpellResistTypes.Normal; foreach (Perk defPerk in this.characterToEffect.charPerks.allPerks) { if (defPerk.GetType() == typeof(SpellResistAbsorbPerk)) { SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>(); //Checking to see if the current heal type is the same as this spell resist perk if (resistPerk.typeToResist == this.healType) { //Checking to see if the heal is negated entirely if (resistPerk.negateAllDamage) { magicResistType = SpellResistTypes.Negate; } //Otherwise we just get the amount that it normally resists else { damagehealed -= resistPerk.GetSpellResistAmount(this.characterToEffect, didThisCrit, false); } } } } //Subtracting any magic resistance from the amount that we're trying to heal switch (this.healType) { case CombatManager.DamageType.Arcane: damagehealed -= this.characterToEffect.charInventory.totalArcaneResist; break; case CombatManager.DamageType.Fire: damagehealed -= this.characterToEffect.charInventory.totalFireResist; break; case CombatManager.DamageType.Water: damagehealed -= this.characterToEffect.charInventory.totalWaterResist; break; case CombatManager.DamageType.Electric: damagehealed -= this.characterToEffect.charInventory.totalElectricResist; break; case CombatManager.DamageType.Wind: damagehealed -= this.characterToEffect.charInventory.totalWindResist; break; case CombatManager.DamageType.Nature: damagehealed -= this.characterToEffect.charInventory.totalNatureResist; break; case CombatManager.DamageType.Holy: damagehealed -= this.characterToEffect.charInventory.totalHolyResist; break; case CombatManager.DamageType.Dark: damagehealed -= this.characterToEffect.charInventory.totalDarkResist; break; //Pure damage type has no resist } //Looping through the attacking character's perks to see if there's any bonus threat to add to this effect int bonusThreat = 0; foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks) { //If the perk is a threat boosting perk if (charPerk.GetType() == typeof(ThreatBoostPerk)) { ThreatBoostPerk threatPerk = charPerk.GetComponent <ThreatBoostPerk>(); //If the perk has the same damage type as this HoT or it affects all damage types if (threatPerk.damageTypeToThreaten == this.healType || threatPerk.threatenAllDamageTypes) { bonusThreat += threatPerk.GetAddedActionThreat(damagehealed, didThisCrit, true); } } } //If the heal was negated completely if (magicResistType == SpellResistTypes.Negate) { //Telling the combat manager to display that no damage was healed CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow]; CombatManager.globalReference.DisplayDamageDealt(0, 0, this.healType, healedCharTile, didThisCrit, true); } //Otherwise, the heal happens normally else { //Healing the damage to the effected character this.characterToEffect.charPhysState.HealCharacter(damagehealed); //Telling the combat manager to display the damage healed CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow]; CombatManager.globalReference.DisplayDamageDealt(0, damagehealed, this.healType, healedCharTile, didThisCrit, true); //If the target character and the character who cast this effect are player characters, we need to increase threat if (!this.characterToEffect.GetComponent <EnemyCombatAI_Basic>() && !this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>()) { //Applying threat to all enemies for the amount that's healed CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, damagehealed + bonusThreat, true); } } //Creating the visual effect for this effect CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(this.characterToEffect); this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform); //If this effect isn't unlimited, we need to reduce the ticks remaining if (!this.unlimitedTicks) { this.ticksLeft -= 1; //If there are no more ticks left, this effect is over and the object is destroyed if (this.ticksLeft <= 0) { this.RemoveEffect(); } } }
//Overrided function from Effect.cs to trigger this heal effect public override void TriggerEffect(Character usingCharacter_, Character targetCharacter_, float timeDelay_ = 0) { //Setting the character references of who is attacking and who is being attacked this.characterToEffect = targetCharacter_; this.characterWhoTriggered = usingCharacter_; //Int to hold the heal total for the effect int totalHeal = 0; //Adding the base heal totalHeal += this.baseHeal; //Looping through each individual die rolled for (int d = 0; d < this.diceRolled; ++d) { //Finding the value rolled on the current die totalHeal += Random.Range(1, this.diceSides); } //Rolling to see if this effect crits float critRoll = Random.Range(0, 1); bool isCrit = false; if (critRoll < this.critChance) { totalHeal = Mathf.RoundToInt(totalHeal * this.critMultiplier); } //Looping through the perks of the character that used this ability to see if they have any damage type boost perks foreach (Perk charPerk in usingCharacter_.charPerks.allPerks) { //If the perk boosts a damage type that's the same as this damage (heal) type, we boost it if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && this.type == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost) { totalHeal += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(usingCharacter_, isCrit, false, this.type); } } //Looping through the defending character's perks to see if they have any spell resist or absorb perks SpellResistTypes magicResistType = SpellResistTypes.Normal; foreach (Perk defPerk in this.characterToEffect.charPerks.allPerks) { if (defPerk.GetType() == typeof(SpellResistAbsorbPerk)) { SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>(); //Checking to see if the current heal type is the same as this spell resist perk if (resistPerk.typeToResist == this.type) { //Checking to see if the heal is negated entirely if (resistPerk.negateAllDamage) { magicResistType = SpellResistTypes.Negate; } //Otherwise we just get the amount that it normally resists else { totalHeal -= resistPerk.GetSpellResistAmount(this.characterToEffect, isCrit, false); } } } } //Subtracting the target character's magic resistances switch (this.type) { case CombatManager.DamageType.Slashing: if (targetCharacter_.charInventory.totalSlashingArmor > 0) { totalHeal -= targetCharacter_.charInventory.totalSlashingArmor; } break; case CombatManager.DamageType.Stabbing: if (targetCharacter_.charInventory.totalStabbingArmor > 0) { totalHeal -= targetCharacter_.charInventory.totalStabbingArmor; } break; case CombatManager.DamageType.Crushing: if (targetCharacter_.charInventory.totalCrushingArmor > 0) { totalHeal -= targetCharacter_.charInventory.totalCrushingArmor; } break; case CombatManager.DamageType.Fire: if (targetCharacter_.charInventory.totalFireResist > 0) { totalHeal -= targetCharacter_.charInventory.totalFireResist; } break; case CombatManager.DamageType.Water: if (targetCharacter_.charInventory.totalWaterResist > 0) { totalHeal -= targetCharacter_.charInventory.totalWaterResist; } break; case CombatManager.DamageType.Electric: if (targetCharacter_.charInventory.totalElectricResist > 0) { totalHeal -= targetCharacter_.charInventory.totalElectricResist; } break; case CombatManager.DamageType.Wind: if (targetCharacter_.charInventory.totalWindResist > 0) { totalHeal -= targetCharacter_.charInventory.totalWindResist; } break; case CombatManager.DamageType.Nature: if (targetCharacter_.charInventory.totalNatureResist > 0) { totalHeal -= targetCharacter_.charInventory.totalNatureResist; } break; case CombatManager.DamageType.Arcane: if (targetCharacter_.charInventory.totalArcaneResist > 0) { totalHeal -= targetCharacter_.charInventory.totalArcaneResist; } break; case CombatManager.DamageType.Holy: if (targetCharacter_.charInventory.totalHolyResist > 0) { totalHeal -= targetCharacter_.charInventory.totalHolyResist; } break; case CombatManager.DamageType.Dark: if (targetCharacter_.charInventory.totalDarkResist > 0) { totalHeal -= targetCharacter_.charInventory.totalDarkResist; } break; case CombatManager.DamageType.Bleed: if (targetCharacter_.charInventory.totalBleedResist > 0) { totalHeal -= targetCharacter_.charInventory.totalBleedResist; } break; } //Looping through the attacking character's perks to see if there's any bonus threat to add to this effect int bonusThreat = 0; foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks) { //If the perk is a threat boosting perk if (charPerk.GetType() == typeof(ThreatBoostPerk)) { ThreatBoostPerk threatPerk = charPerk.GetComponent <ThreatBoostPerk>(); //If the perk has the same damage type as this effect or it affects all damage types if (threatPerk.damageTypeToThreaten == this.type || threatPerk.threatenAllDamageTypes) { bonusThreat += threatPerk.GetAddedActionThreat(totalHeal, isCrit, false); } } } //Finding the combat tile that the target character is on CombatTile targetCharTile = CombatManager.globalReference.FindCharactersTile(targetCharacter_); //If the heal was negated completely if (magicResistType == SpellResistTypes.Negate) { //Telling the combat manager to display that no damage was healed CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow]; CombatManager.globalReference.DisplayDamageDealt(0, 0, this.type, healedCharTile, isCrit, true); } //Otherwise, the heal happens normally else { //Healing the damage to the effected character this.characterToEffect.charPhysState.HealCharacter(totalHeal); //Telling the combat manager to display the damage healed CombatTile healedCharTile = CombatManager.globalReference.combatTileGrid[this.characterToEffect.charCombatStats.gridPositionCol][this.characterToEffect.charCombatStats.gridPositionRow]; CombatManager.globalReference.DisplayDamageDealt(0, totalHeal, this.type, healedCharTile, isCrit, true); //If the acting character is a player character, we need to increase the threat against them if (!this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>()) { //If this character DOESN'T have the EnemyCombatAI component, we increase the threat for the character who put this effect on if (!this.characterToEffect.GetComponent <EnemyCombatAI_Basic>()) { //Applying threat to all enemies based on the amount healed CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, totalHeal + bonusThreat, true); } } } //Creating the visual effect for this effect CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(targetCharacter_); this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform); //Destroying this effect once everything is finished up Destroy(this.gameObject); }
//Function called to update the inventory images and weight public void UpdateImages() { //Sets the character image if (this.playerSpriteLoc != null) { //Finding any child objects on this object to remove a previous player image List <GameObject> allChildren = new List <GameObject>(); for (int c = 0; c < this.playerSpriteLoc.transform.childCount; ++c) { allChildren.Add(this.playerSpriteLoc.transform.GetChild(c).gameObject); } //Deleting each child object for (int d = 0; d < allChildren.Count; ++d) { Destroy(allChildren[d].gameObject); } //Creating a new sprite base for the selected character GameObject newSpriteBase = GameObject.Instantiate(this.selectedCharacterInventory.GetComponent <Character>().charSprites.allSprites.spriteBase.gameObject); //Parenting the sprite base to our sprite location object newSpriteBase.transform.SetParent(this.playerSpriteLoc.transform); newSpriteBase.transform.localPosition = new Vector3(); newSpriteBase.transform.localScale = new Vector3(newSpriteBase.transform.localScale.x * this.playerSpriteLoc.transform.localScale.x * 1.2f, newSpriteBase.transform.localScale.y * this.playerSpriteLoc.transform.localScale.y * 1.2f, newSpriteBase.transform.localScale.z * this.playerSpriteLoc.transform.localScale.z); //Getting the reference to the sprite base component CharacterSpriteBase charSprite = newSpriteBase.GetComponent <CharacterSpriteBase>(); //Setting the character sprite base's sprites Character selectedCharacter = this.selectedCharacterInventory.GetComponent <Character>(); charSprite.SetSpriteImages(selectedCharacter.charSprites.allSprites, selectedCharacter.charInventory); charSprite.SetDirectionFacing(this.spriteDirection); } //Sets the character name if (this.selectedCharacterName != null) { Character characterReference = this.selectedCharacterInventory.GetComponent <Character>(); this.selectedCharacterName.text = characterReference.firstName + " " + characterReference.lastName; } //Sets the weight text if (this.selectedCharacterWeight != null) { this.selectedCharacterWeight.text = "Weight: " + this.selectedCharacterInventory.currentWeight; } //Sets the money text if (this.selectedCharacterWallet != null) { this.selectedCharacterWallet.text = "" + this.selectedCharacterInventory.wallet + " $"; } //Sets the armor text if (this.selectedCharacterArmorSlashing != null) { this.selectedCharacterArmorSlashing.text = "" + this.selectedCharacterInventory.totalSlashingArmor; } if (this.selectedCharacterArmorStabbing != null) { this.selectedCharacterArmorStabbing.text = "" + this.selectedCharacterInventory.totalStabbingArmor; } if (this.selectedCharacterArmorCrushing != null) { this.selectedCharacterArmorCrushing.text = "" + this.selectedCharacterInventory.totalCrushingArmor; } //Sets magic resist texts if (this.selectedCharacterResistArcane != null) { this.selectedCharacterResistArcane.text = "" + this.selectedCharacterInventory.totalArcaneResist; } if (this.selectedCharacterResistFire != null) { this.selectedCharacterResistFire.text = "" + this.selectedCharacterInventory.totalFireResist; } if (this.selectedCharacterResistWater != null) { this.selectedCharacterResistWater.text = "" + this.selectedCharacterInventory.totalWaterResist; } if (this.selectedCharacterResistElectric != null) { this.selectedCharacterResistElectric.text = "" + this.selectedCharacterInventory.totalElectricResist; } if (this.selectedCharacterResistWind != null) { this.selectedCharacterResistWind.text = "" + this.selectedCharacterInventory.totalWindResist; } if (this.selectedCharacterResistHoly != null) { this.selectedCharacterResistHoly.text = "" + this.selectedCharacterInventory.totalHolyResist; } if (this.selectedCharacterResistDark != null) { this.selectedCharacterResistDark.text = "" + this.selectedCharacterInventory.totalDarkResist; } if (this.selectedCharacterResistNature != null) { this.selectedCharacterResistNature.text = "" + this.selectedCharacterInventory.totalNatureResist; } //If this inventory displays a character and their armor if (this.inventoryUIType != InventoryType.Bag) { //Sets the image of the head item if (this.selectedCharacterInventory.helm != null) { this.head.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.helm.GetComponent <Item>().icon); this.head.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.head.GetComponent <InventoryButton>().SetButtonIcon(null); this.head.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the torso item if (this.selectedCharacterInventory.chestPiece != null) { this.torso.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.chestPiece.GetComponent <Item>().icon); this.torso.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.torso.GetComponent <InventoryButton>().SetButtonIcon(null); this.torso.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the leg item if (this.selectedCharacterInventory.leggings != null) { this.legs.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.leggings.GetComponent <Item>().icon); this.legs.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.legs.GetComponent <InventoryButton>().SetButtonIcon(null); this.legs.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the feet item if (this.selectedCharacterInventory.shoes != null) { this.feet.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.shoes.GetComponent <Item>().icon); this.feet.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.feet.GetComponent <InventoryButton>().SetButtonIcon(null); this.feet.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the glove item if (this.selectedCharacterInventory.gloves != null) { this.hands.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.gloves.GetComponent <Item>().icon); this.hands.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.hands.GetComponent <InventoryButton>().SetButtonIcon(null); this.hands.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the neck item if (this.selectedCharacterInventory.necklace != null) { this.necklace.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.necklace.GetComponent <Item>().icon); this.necklace.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.necklace.GetComponent <InventoryButton>().SetButtonIcon(null); this.necklace.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the cloak item if (this.selectedCharacterInventory.cloak != null) { this.cloak.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.cloak.GetComponent <Item>().icon); this.cloak.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.cloak.GetComponent <InventoryButton>().SetButtonIcon(null); this.cloak.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the ring item if (this.selectedCharacterInventory.ring != null) { this.ring.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.ring.GetComponent <Item>().icon); this.ring.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.ring.GetComponent <InventoryButton>().SetButtonIcon(null); this.ring.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the right hand item if (this.selectedCharacterInventory.rightHand != null) { this.rightHand.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.rightHand.GetComponent <Item>().icon); this.rightHand.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.rightHand.GetComponent <InventoryButton>().SetButtonIcon(null); this.rightHand.GetComponent <InventoryButton>().slotIsEmpty = true; } //Sets the image of the left hand item if (this.selectedCharacterInventory.leftHand != null) { this.leftHand.GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.leftHand.GetComponent <Item>().icon); this.leftHand.GetComponent <InventoryButton>().slotIsEmpty = false; } else { this.leftHand.GetComponent <InventoryButton>().SetButtonIcon(null); this.leftHand.GetComponent <InventoryButton>().slotIsEmpty = true; } } //Loops through each of the item slots to set their images for (int i = 0; i < this.selectedCharacterInventory.itemSlots.Count; ++i) { //If the current item slot is empty, the image is disabled if (this.selectedCharacterInventory.itemSlots[i] == null) { this.slotImages[i].GetComponent <InventoryButton>().SetButtonIcon(null); this.slotImages[i].GetComponent <InventoryButton>().slotIsEmpty = true; } //If the slot isn't empty, the image is enabled and set to the item's icon else { this.slotImages[i].GetComponent <InventoryButton>().SetButtonIcon(this.selectedCharacterInventory.itemSlots[i].GetComponent <Item>().icon); this.slotImages[i].GetComponent <InventoryButton>().slotIsEmpty = false; } } }
//Function called every frame private void Update() { //If we should be animating this character moving from tile to tile if (this.moveCharacter) { //Increasing the total time that's passed this.currentTimePassed += Time.deltaTime; //If enough time has passed that we've moved one more tile further. We progress the acting character one more tile along the movement path if (this.currentTimePassed >= this.timeToCompleteAction) { //Increasing the index for the number of tiles moved this.currentNumTilesMoved += 1; //Resetting the current movement time this.currentTimePassed = 0; //Moving the character sprite to the new tile position CharacterSpriteBase charSprite = CombatManager.globalReference.GetCharacterSprite(this.actingCharacter); charSprite.transform.position = this.movementPath[this.currentNumTilesMoved].transform.position; //Making sure the sprites are positioned in front of each other correctly CombatManager.globalReference.UpdateCharacterSpriteOrder(); //If the new tile is to the left of the old tile, we face the character left if (this.movementPath[this.currentNumTilesMoved].transform.position.x < this.movementPath[this.currentNumTilesMoved - 1].transform.position.x) { charSprite.SetDirectionFacing(CharacterSpriteBase.DirectionFacing.Left); } //If the new tile is to the right of the old tile, we face the character right else if (this.movementPath[this.currentNumTilesMoved].transform.position.x > this.movementPath[this.currentNumTilesMoved - 1].transform.position.x) { charSprite.SetDirectionFacing(CharacterSpriteBase.DirectionFacing.Right); } //If the new tile is above the old tile, we face the character up else if (this.movementPath[this.currentNumTilesMoved].transform.position.y > this.movementPath[this.currentNumTilesMoved - 1].transform.position.y) { charSprite.SetDirectionFacing(CharacterSpriteBase.DirectionFacing.Up); } //If the new tile is below the old tile, we face the character down else if (this.movementPath[this.currentNumTilesMoved].transform.position.y < this.movementPath[this.currentNumTilesMoved - 1].transform.position.y) { charSprite.SetDirectionFacing(CharacterSpriteBase.DirectionFacing.Down); } //Removing the acting character from the tile they're on CombatManager.globalReference.combatTileGrid[this.actingCharacter.charCombatStats.gridPositionCol][this.actingCharacter.charCombatStats.gridPositionRow].SetObjectOnTile(null, CombatTile.ObjectType.Nothing); //Once the time has passed for this tile, the selected character's position is updated this.actingCharacter.charCombatStats.gridPositionCol = this.movementPath[this.currentNumTilesMoved].col; this.actingCharacter.charCombatStats.gridPositionRow = this.movementPath[this.currentNumTilesMoved].row; CombatManager.globalReference.combatTileGrid[this.actingCharacter.charCombatStats.gridPositionCol][this.actingCharacter.charCombatStats.gridPositionRow].SetObjectOnTile(this.actingCharacter.gameObject, CombatTile.ObjectType.Player); //Looping through and triggering all effects on the moving character that happen during movement foreach (Effect e in this.actingCharacter.charCombatStats.combatEffects) { e.EffectOnMove(); //Checking to see if the acting character has died due to some effect if (this.actingCharacter.GetComponent <PhysicalState>().currentHealth <= 0) { //Clearing the movement path tiles for (int t = this.currentNumTilesMoved; t < this.movementPath.Count; ++t) { this.movementPath[t].GetComponent <Image>().color = new Color(1, 1, 1, this.movementPath[t].inactiveTransparency); } //This game object is destroyed Destroy(this.gameObject); break; } } //If we've moved through all of the tiles on the movement path, this object is destroyed if (this.currentNumTilesMoved + 1 == this.movementPath.Count) { //Setting the character's combat sprite to a stationary position directly on the last tile in our movement path CombatManager.globalReference.GetCharacterSprite(this.actingCharacter).transform.position = this.movementPath[this.movementPath.Count - 1].transform.position; Destroy(this.gameObject); } } } //If there are tiles in the movement path and the mouse is hovering over a combat tile else if (this.movementPath.Count > 0 && CombatTile.mouseOverTile != null) { //If the tile that the mouse is over is connected to the last tile in the current movement path if (this.movementPath[this.movementPath.Count - 1].ourPathPoint.connectedPoints.Contains(CombatTile.mouseOverTile.ourPathPoint) && this.movementPath.Count <= this.range) { //If the tile that the mouse is over isn't already in the movement path and this type of movement allows the user to ignore obstacles if (!this.movementPath.Contains(CombatTile.mouseOverTile)) { //If the tile has no object on it OR if there is an object and the movement action ignores objects if (CombatTile.mouseOverTile.typeOnTile == CombatTile.ObjectType.Nothing || (CombatTile.mouseOverTile.typeOnTile == CombatTile.ObjectType.Object && this.ignoreObstacles) || ((CombatTile.mouseOverTile.typeOnTile == CombatTile.ObjectType.Enemy || CombatTile.mouseOverTile.typeOnTile == CombatTile.ObjectType.Player) && this.ignoreEnemies)) { this.movementPath.Add(CombatTile.mouseOverTile); CombatTile.mouseOverTile.HighlightTile(true); CombatTile.mouseOverTile.SetTileColor(Color.blue); } } //If the tile that the mouse is over IS already in the movement path and isn't the most recent tile else { //Removing all tiles in the movement path that come after this one int indexOfPrevTile = this.movementPath.IndexOf(CombatTile.mouseOverTile) + 1; for (int t = indexOfPrevTile; t < this.movementPath.Count;) { this.movementPath[t].HighlightTile(false); this.movementPath[t].SetTileColor(Color.white); this.movementPath.RemoveAt(t); } } } //If the tile that the mouse is over is NOT connected to the last tile in the current movement path but is still in the path else if (this.movementPath.Contains(CombatTile.mouseOverTile)) { //Removing all tiles in the movement path that come after this one int indexOfPrevTile = this.movementPath.IndexOf(CombatTile.mouseOverTile) + 1; for (int t = indexOfPrevTile; t < this.movementPath.Count;) { this.movementPath[t].HighlightTile(false); this.movementPath[t].SetTileColor(Color.white); this.movementPath.RemoveAt(t); } } //If the tile that the mouse is over is neither on the movement path or on a tile connected to it else { //Making sure the tile that the mouse is over is within this action's range if (CombatTile.mouseOverTile.inActionRange) { //Looping through all of the tiles currently in the movement path and clearing them for (int p = 1; p < this.movementPath.Count; ++p) { this.movementPath[p].HighlightTile(false); this.movementPath[p].SetTileColor(Color.white); } //Use the breadth first search algorithm to find the path to this tile from the player List <CombatTile> newPath = PathfindingAlgorithms.BreadthFirstSearchCombat(this.movementPath[0], CombatTile.mouseOverTile, this.ignoreObstacles, this.ignoreEnemies); if (newPath.Count > 0) { this.movementPath = newPath; } //Looping through each tile that's now in the movement path and coloring it in for (int t = 1; t < this.movementPath.Count; ++t) { this.movementPath[t].HighlightTile(true); this.movementPath[t].GetComponent <Image>().color = Color.blue; } } } } }
//Overrided function from Effect.cs to trigger this damage effect public override void TriggerEffect(Character usingCharacter_, Character targetCharacter_, float timeDelay_ = 0) { //Setting the character references of who is attacking and who is being attacked this.characterToEffect = targetCharacter_; this.characterWhoTriggered = usingCharacter_; //Int to hold all of the damage for the attack int totalDamage = 0; //Adding the base damage totalDamage += this.baseDamage; //Looping through each individual die rolled for (int d = 0; d < this.diceRolled; ++d) { //Finding the value rolled on the current die totalDamage += Random.Range(1, this.diceSides); } //Rolling to see if this effect crits float critRoll = Random.Range(0, 1); bool isCrit = false; if (critRoll < this.critChance) { totalDamage = totalDamage * this.critMultiplier; } //Looping through the perks of the character that used this ability to see if they have any damage type boost perks foreach (Perk charPerk in usingCharacter_.charPerks.allPerks) { //If the perk boosts a damage type that's the same as this damage type, we boost it if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && this.type == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost) { totalDamage += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(usingCharacter_, isCrit, false, this.type); } } //Looping through the defending character's perks to see if they have any spell resist or absorb perks SpellResistTypes magicResistType = SpellResistTypes.Normal; foreach (Perk defPerk in targetCharacter_.charPerks.allPerks) { if (defPerk.GetType() == typeof(SpellResistAbsorbPerk)) { SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>(); //Checking to see if the current damage type is the same as this spell resist perk if (resistPerk.typeToResist == this.type) { //Checking to see if the damage is negated entirely if (resistPerk.negateAllDamage) { //If the resist type for this spell isn't on absorb, we can negate it. ALWAYS have preference to absorb because it heals if (magicResistType != SpellResistTypes.Absorb) { magicResistType = SpellResistTypes.Negate; } } //Checking to see if the damage is absorbed to heal the target else if (resistPerk.absorbDamage) { magicResistType = SpellResistTypes.Absorb; //Applying the damage reduction so the defender isn't healed as much totalDamage -= resistPerk.GetSpellResistAmount(this.characterToEffect, isCrit, false); } //Otherwise we just get the amount that it normally resists else { totalDamage -= resistPerk.GetSpellResistAmount(this.characterToEffect, isCrit, false); } } } } //Subtracting the target character's armor resist and magic resistances switch (this.type) { case CombatManager.DamageType.Slashing: if (targetCharacter_.charInventory.totalSlashingArmor > 0) { totalDamage -= targetCharacter_.charInventory.totalSlashingArmor; } break; case CombatManager.DamageType.Stabbing: if (targetCharacter_.charInventory.totalStabbingArmor > 0) { totalDamage -= targetCharacter_.charInventory.totalStabbingArmor; } break; case CombatManager.DamageType.Crushing: if (targetCharacter_.charInventory.totalCrushingArmor > 0) { totalDamage -= targetCharacter_.charInventory.totalCrushingArmor; } break; case CombatManager.DamageType.Fire: if (targetCharacter_.charInventory.totalFireResist > 0) { totalDamage -= targetCharacter_.charInventory.totalFireResist; } break; case CombatManager.DamageType.Water: if (targetCharacter_.charInventory.totalWaterResist > 0) { totalDamage -= targetCharacter_.charInventory.totalWaterResist; } break; case CombatManager.DamageType.Electric: if (targetCharacter_.charInventory.totalElectricResist > 0) { totalDamage -= targetCharacter_.charInventory.totalElectricResist; } break; case CombatManager.DamageType.Wind: if (targetCharacter_.charInventory.totalWindResist > 0) { totalDamage -= targetCharacter_.charInventory.totalWindResist; } break; case CombatManager.DamageType.Nature: if (targetCharacter_.charInventory.totalNatureResist > 0) { totalDamage -= targetCharacter_.charInventory.totalNatureResist; } break; case CombatManager.DamageType.Arcane: if (targetCharacter_.charInventory.totalArcaneResist > 0) { totalDamage -= targetCharacter_.charInventory.totalArcaneResist; } break; case CombatManager.DamageType.Holy: if (targetCharacter_.charInventory.totalHolyResist > 0) { totalDamage -= targetCharacter_.charInventory.totalHolyResist; } break; case CombatManager.DamageType.Dark: if (targetCharacter_.charInventory.totalDarkResist > 0) { totalDamage -= targetCharacter_.charInventory.totalDarkResist; } break; case CombatManager.DamageType.Bleed: if (targetCharacter_.charInventory.totalBleedResist > 0) { totalDamage -= targetCharacter_.charInventory.totalBleedResist; } break; } //Looping through the attacking character's perks to see if there's any bonus threat to add to this effect int bonusThreat = 0; foreach (Perk charPerk in this.characterWhoTriggered.charPerks.allPerks) { //If the perk is a threat boosting perk if (charPerk.GetType() == typeof(ThreatBoostPerk)) { ThreatBoostPerk threatPerk = charPerk.GetComponent <ThreatBoostPerk>(); //If the perk has the same damage type as this effect or it affects all damage types if (threatPerk.damageTypeToThreaten == this.type || threatPerk.threatenAllDamageTypes) { bonusThreat += threatPerk.GetAddedActionThreat(totalDamage, isCrit, false); } } } //Finding the combat tile that the target character is on CombatTile targetCharTile = CombatManager.globalReference.FindCharactersTile(targetCharacter_); //If the damage was dealt normally if (magicResistType == SpellResistTypes.Normal) { //Dealing damage to the target character and telling the combat manager to display how much was dealt targetCharacter_.charPhysState.DamageCharacter(totalDamage); CombatManager.globalReference.DisplayDamageDealt(timeDelay_, totalDamage, type, targetCharTile, isCrit); //If this character has the EnemyCombatAI component, we increase the threat for the character who put this effect on if (this.characterToEffect.GetComponent <EnemyCombatAI_Basic>()) { //If the character who cast this effect is a player character, we increase threat against the caster if (!this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>()) { //If the attack didn't crit if (!isCrit) { //Applying threat to the targeted character this.characterToEffect.GetComponent <EnemyCombatAI_Basic>().IncreaseThreat(this.characterWhoTriggered, totalDamage + bonusThreat); } //If the attack did crit, we boost threat against all enemies by 25% else { //Finding the bonus amount of threat that's applied to all enemies int boostedThreat = totalDamage + bonusThreat; boostedThreat = Mathf.RoundToInt(boostedThreat * 0.25f); CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, boostedThreat, true); //Applying the rest of the threat to the target character CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, this.characterToEffect, totalDamage + bonusThreat - boostedThreat, false); } } } } //If the damage was negated completely else if (magicResistType == SpellResistTypes.Negate) { //Telling the combat manager to display no damage dealt CombatManager.globalReference.DisplayDamageDealt(timeDelay_, 0, type, targetCharTile, isCrit); } //If the damage was abosrbed and healed the character else if (magicResistType == SpellResistTypes.Absorb) { //Telling the combat manager to display the damage healed targetCharacter_.charPhysState.HealCharacter(totalDamage); CombatManager.globalReference.DisplayDamageDealt(timeDelay_, totalDamage, type, targetCharTile, isCrit, true); //If the caster of this effect and the target are player characters, we increase the threat for the character who put this effect on them if (!this.characterToEffect.GetComponent <EnemyCombatAI_Basic>() && !this.characterWhoTriggered.GetComponent <EnemyCombatAI_Basic>()) { //Applying threat to all enemies for the amount that's healed CombatManager.globalReference.ApplyActionThreat(this.characterWhoTriggered, null, totalDamage + bonusThreat, true); } } //Creating the visual effect for this effect CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(targetCharacter_); this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform); //Increasing the threat to the target based on damage dealt //If the attack is a crit, ALL enemies have their threat increased for 25% of the damage if (isCrit) { //Getting 25% of the damage to pass to all enemies int threatForAll = (totalDamage + bonusThreat) / 4; CombatManager.globalReference.ApplyActionThreat(usingCharacter_, null, threatForAll, true); //Applying the rest of the threat to the target character CombatManager.globalReference.ApplyActionThreat(usingCharacter_, targetCharacter_, (totalDamage + bonusThreat) - threatForAll, false); } //If the attack wasn't a crit, only the target character takes threat else { CombatManager.globalReference.ApplyActionThreat(usingCharacter_, targetCharacter_, totalDamage + bonusThreat, false); } //Destroying this effect once everything is finished up Destroy(this.gameObject); }
//Function called externally from the buttons on the action panel. Tells the combat manager to hilight an action's range public void SelectActionAtIndex(int actionIndex_) { //Clearing all tile highlights before we highlight different ones CombatManager.globalReference.ClearCombatTileHighlights(); //Getting a reference to the character that's currently acting Character actingCharacter = CombatManager.globalReference.actingCharacters[0]; //Finding out which tile the acting character is on CombatTile actingCharsTile = CombatManager.globalReference.FindCharactersTile(actingCharacter); //If the currently selected action is a move action, we need to clear tile highlights along its movement path if (this.selectedAction != null && this.selectedAction.GetComponent <MoveAction>()) { this.selectedAction.GetComponent <MoveAction>().ClearMovePathHighlights(); } //Destroying the game object that holds the currently selected action if (this.selectedAction != null) { Destroy(this.selectedAction.gameObject); } //Creating an instance of the newly selected action prefab object GameObject actionObj = null; //Finding the range of the action based on the button hit int actionRange = 0; switch (this.actionTypeShown) { case Action.ActionType.Major: actionRange = actingCharacter.charActionList.majorActions[actionIndex_].range; actionObj = GameObject.Instantiate(actingCharacter.charActionList.majorActions[actionIndex_].gameObject); //this.selectedAction = actingCharacter.charActionList.standardActions[actionIndex_]; break; case Action.ActionType.Minor: actionRange = actingCharacter.charActionList.minorActions[actionIndex_].range; actionObj = GameObject.Instantiate(actingCharacter.charActionList.minorActions[actionIndex_].gameObject); break; case Action.ActionType.Fast: actionRange = actingCharacter.charActionList.fastActions[actionIndex_].range; actionObj = GameObject.Instantiate(actingCharacter.charActionList.fastActions[actionIndex_].gameObject); break; case Action.ActionType.Massive: actionRange = actingCharacter.charActionList.massiveActions[actionIndex_].range; actionObj = GameObject.Instantiate(actingCharacter.charActionList.massiveActions[actionIndex_].gameObject); break; } //Getting the action component reference from the created action object this.selectedAction = actionObj.GetComponent <Action>(); //Finding out which tiles need to be hilighted if this action isn't a move action List <CombatTile> tilesToHighlight; List <CombatTile> tilesToCheckForCharacters = new List <CombatTile>(); if (!this.selectedAction.GetComponent <MoveAction>()) { tilesToHighlight = PathfindingAlgorithms.FindTilesInActionRange(actingCharsTile, actionRange); tilesToCheckForCharacters = tilesToHighlight; } //If this action is a move action, we have to find the selected tiles based on environment obstacles else { MoveAction ourMoveAct = this.selectedAction.GetComponent <MoveAction>(); //Looping through all of the acting character's perks to see if there are any movement boost perks int rangeModifier = 0; foreach (Perk charPerk in actingCharacter.charPerks.allPerks) { //If the current perk is a movement boost perk that applies to this movement's action type, we apply the number of added spaces if (charPerk.GetType() == typeof(MovementBoostPerk) && ourMoveAct.type == charPerk.GetComponent <MovementBoostPerk>().actionTypeToBoost) { rangeModifier += charPerk.GetComponent <MovementBoostPerk>().addedMovementSpaces; } } //Highlighting all tiles in range tilesToHighlight = PathfindingAlgorithms.FindTilesInActionRange(actingCharsTile, actionRange + rangeModifier, ourMoveAct.ignoreObstacles); tilesToCheckForCharacters = PathfindingAlgorithms.FindTilesInActionRange(actingCharsTile, actionRange + rangeModifier + 1); } //Looping through all tiles in range and hilighting them foreach (CombatTile tile in tilesToHighlight) { tile.inActionRange = true; tile.HighlightTile(false); } //Looping through all of the tiles around the action highlights to check for characters foreach (CombatTile checkedTile in tilesToCheckForCharacters) { //If there's a character sprite on this tile, we hide it a bit if (checkedTile.objectOnThisTile != null) { if (checkedTile.objectOnThisTile.GetComponent <Character>()) { //Getting the sprite base for the character CharacterSpriteBase cSprite = CombatManager.globalReference.GetCharacterSprite(checkedTile.objectOnThisTile.GetComponent <Character>()); //If the character on the tile isn't the one that's acting if (cSprite.ourCharacter != CombatManager.globalReference.actingCharacters[0]) { cSprite.MakeSpritesTransparent(); } } } } //Displays the action's details this.UpdateActionDetailsPanel(); }
//Function called when this effect is applied or removed. private void ApplyStatChanges(bool addingChanges_) { //Looping through each stat modifier that this effect applies foreach (StatModifier mod in this.statChanges) { switch (mod.modifiedStat) { //Increasing the target character's max health case StatModifier.StatName.Health: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charPhysState.currentHealth += Mathf.RoundToInt(mod.amountToChange); this.characterToEffect.charPhysState.maxHealth += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charPhysState.currentHealth -= Mathf.RoundToInt(mod.amountToChange); this.characterToEffect.charPhysState.maxHealth -= Mathf.RoundToInt(mod.amountToChange); } break; //Increasing the target character's combat initiative speed case StatModifier.StatName.Initiative: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charCombatStats.initiativeMod += mod.amountToChange; } //If we're removing the modifier else { this.characterToEffect.charCombatStats.initiativeMod -= mod.amountToChange; } break; //Increasing the target character's combat accuracy case StatModifier.StatName.Accuracy: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charCombatStats.accuracy += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charCombatStats.accuracy -= Mathf.RoundToInt(mod.amountToChange); } break; //Increasing the target character's combat evasion speed case StatModifier.StatName.Evasion: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charCombatStats.evasion += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charCombatStats.evasion -= Mathf.RoundToInt(mod.amountToChange); } break; //Increasing the target character's combat skills case StatModifier.StatName.Unarmed: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Unarmed, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Unarmed, -Mathf.RoundToInt(mod.amountToChange)); } break; //Daggers case StatModifier.StatName.Daggers: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Daggers, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Daggers, -Mathf.RoundToInt(mod.amountToChange)); } break; //Swords case StatModifier.StatName.Swords: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Swords, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Swords, -Mathf.RoundToInt(mod.amountToChange)); } break; //Axes case StatModifier.StatName.Mauls: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Mauls, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Mauls, -Mathf.RoundToInt(mod.amountToChange)); } break; //Spears case StatModifier.StatName.Poles: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Poles, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Poles, -Mathf.RoundToInt(mod.amountToChange)); } break; //Bows case StatModifier.StatName.Bows: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Bows, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Bows, -Mathf.RoundToInt(mod.amountToChange)); } break; //Shields case StatModifier.StatName.Shields: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Shields, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.Shields, -Mathf.RoundToInt(mod.amountToChange)); } break; //Arcane magic case StatModifier.StatName.ArcaneMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.ArcaneMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.ArcaneMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Holy magic case StatModifier.StatName.HolyMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.HolyMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.HolyMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Dark magic case StatModifier.StatName.DarkMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.DarkMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.DarkMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Fire magic case StatModifier.StatName.FireMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.FireMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.FireMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Water magic case StatModifier.StatName.WaterMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.WaterMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.WaterMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Wind magic case StatModifier.StatName.WindMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.WindMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.WindMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Electric magic case StatModifier.StatName.ElectricMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.ElectricMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.ElectricMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Stone magic case StatModifier.StatName.StoneMagic: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.StoneMagic, Mathf.RoundToInt(mod.amountToChange)); } //If we're removing the modifier else { this.characterToEffect.charSkills.ChangeSkillModifier(SkillList.StoneMagic, -Mathf.RoundToInt(mod.amountToChange)); } break; //Armor case StatModifier.StatName.SlashingArmor: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalSlashingArmor += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalSlashingArmor -= Mathf.RoundToInt(mod.amountToChange); } break; //Armor case StatModifier.StatName.StabbingArmor: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalStabbingArmor += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalStabbingArmor -= Mathf.RoundToInt(mod.amountToChange); } break; //Armor case StatModifier.StatName.CrushingArmor: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalCrushingArmor += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalCrushingArmor -= Mathf.RoundToInt(mod.amountToChange); } break; //Arcane resist case StatModifier.StatName.ArcaneResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalArcaneResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalArcaneResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Holy resist case StatModifier.StatName.HolyResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalHolyResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalHolyResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Dark resist case StatModifier.StatName.DarkResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalDarkResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalDarkResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Fire resist case StatModifier.StatName.FireResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalFireResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalFireResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Water resist case StatModifier.StatName.WaterResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalWaterResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalWaterResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Electric resist case StatModifier.StatName.ElectricResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalElectricResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalElectricResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Wind resist case StatModifier.StatName.WindResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalWindResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalWindResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Nature resist case StatModifier.StatName.NatureResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalNatureResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalNatureResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Bleed resist case StatModifier.StatName.BleedResist: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalBleedResist += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalBleedResist -= Mathf.RoundToInt(mod.amountToChange); } break; //Armor case StatModifier.StatName.Armor: //If we're adding the modifier if (addingChanges_) { this.characterToEffect.charInventory.totalPhysicalArmor += Mathf.RoundToInt(mod.amountToChange); } //If we're removing the modifier else { this.characterToEffect.charInventory.totalPhysicalArmor -= Mathf.RoundToInt(mod.amountToChange); } break; } } //If we're adding the effect, we need to create this effect's visual if (addingChanges_) { //Creating the visual effect for this effect CharacterSpriteBase targetCharSprite = CombatManager.globalReference.GetCharacterSprite(this.characterToEffect); this.SpawnVisualAtLocation(targetCharSprite.transform.localPosition, targetCharSprite.transform); } }
//Function inherited from AttackAction.cs and called from CombatManager.cs so we can attack a target public override void PerformAction(CombatTile targetTile_) { //Calling the base function to start the cooldown time this.BeginActionCooldown(); //Reference to the character performing this attack Character actingChar = CombatManager.globalReference.actingCharacters[0]; //Reference to the character that's being attacked Character defendingChar; //Getting the tile that the acting character is on CombatTile actingCharTile = CombatManager.globalReference.FindCharactersTile(actingChar); CharacterSpriteBase cSprite = CombatManager.globalReference.GetCharacterSprite(actingChar); //Setting the direction the acting character faces this.SetDirectionFacing(targetTile_, actingCharTile, cSprite); //Looping through and triggering all combat effects on the acting character that happen on attack foreach (Effect e in actingChar.charCombatStats.combatEffects) { e.EffectOnAttack(); //Checking to see if the character has died due to some effect. If so, we break the loop if (actingChar.charPhysState.currentHealth <= 0) { break; } } //Looping through and creating each of the launched projectiles for this attack Vector3 casterTile = CombatManager.globalReference.FindCharactersTile(CombatManager.globalReference.actingCharacters[0]).transform.position; foreach (ProjectileLauncher projectile in this.projectilesToLaunch) { GameObject newProjectile = GameObject.Instantiate(projectile.gameObject, casterTile, new Quaternion()); //Parenting the projectile to the combat manager canvas newProjectile.transform.SetParent(CombatManager.globalReference.transform); //Telling the projectile to start moving newProjectile.GetComponent <ProjectileLauncher>().StartTravelPath(casterTile, targetTile_.transform.position); } //Making sure there's a character on the targeted tile if (targetTile_.objectOnThisTile != null && targetTile_.objectOnThisTile.GetComponent <Character>()) { defendingChar = targetTile_.objectOnThisTile.GetComponent <Character>(); } //If there isn't a character on the tile, nothing happens because it misses anything it could hit else { //If there are no attack damage rolls (like if the attack was just to inflict an effect) the "Miss" text isn't shown if (this.damageDealt.Count > 0) { CombatManager.globalReference.DisplayMissedAttack(this.timeToCompleteAction, targetTile_); } //If the visual effect doesn't require a hit to be spawned, we create it at the target tile if (this.spawnVisualOnMiss && this.visualEffectOnHit != null) { GameObject visual = GameObject.Instantiate(this.visualEffectOnHit.gameObject, targetTile_.transform.position, new Quaternion(), CombatManager.globalReference.transform); } //Looping through each effect that this attack can apply to see if any don't require the attack to land foreach (AttackEffect efc in this.effectsOnHit) { //If the effect doesn't require the attack to land, it's triggered if (!efc.requireHit) { this.TriggerEffect(efc, targetTile_, actingChar); } } return; } //Before calculating damage, we need to find out if this attack hit. We start by rolling 1d100 to hit and adding this attack's accuracy bonus int hitRoll = this.FindAttackRoll(actingChar, defendingChar); //If the hit roll is still above 20%, they hit. If not, the attack misses if (hitRoll <= CombatManager.baseHitDC) { //If there are no attack damage rolls (like if the attack was just to inflict an effect) the "Miss" text isn't shown if (this.damageDealt.Count > 0) { //Miss CombatManager.globalReference.DisplayMissedAttack(this.timeToCompleteAction, targetTile_); } //If the visual effect doesn't require a hit to be spawned, we create it at the target tile if (this.spawnVisualOnMiss && this.visualEffectOnHit != null) { GameObject visual = GameObject.Instantiate(this.visualEffectOnHit.gameObject, targetTile_.transform.position, new Quaternion(), CombatManager.globalReference.transform); } //Looping through each effect that this attack can apply to see if any don't require the attack to land foreach (AttackEffect efc in this.effectsOnHit) { //If the effect doesn't require the attack to land, it's triggered if (!efc.requireHit) { this.TriggerEffect(efc, targetTile_, actingChar); } } //Giving the attacking character skill EXP for a miss this.GrantSkillEXP(actingChar, this.weaponSkillUsed, true); return; } //Giving the attacking character skill EXP for a hit this.GrantSkillEXP(actingChar, this.weaponSkillUsed, false); //Looping through for each time this action hits for (int h = 0; h < this.numberOfHits; ++h) { //Checking to see if this attack crits float critMultiplier = 1; //Set to 1 in case we don't crit so it won't change anything float critRoll = Random.Range(0, 1); bool isCrit = false; //Float for the bonus damage multiplier from perks float critMultiplierBoost = 0; //Looping through all of the acting character's perks to see if they have perks for crit chance or multiplier foreach (Perk charPerk in actingChar.charPerks.allPerks) { //If the current perk increases crit chance, we need to see if it applies to this attack if (charPerk.GetType() == typeof(CritChanceBoostPerk)) { CritChanceBoostPerk critPerk = charPerk.GetComponent <CritChanceBoostPerk>(); //If the perk applies to this attack's required skill check if (critPerk.boostAllSkills || critPerk.skillCritToBoost == this.weaponSkillUsed) { //If the perk applies to any kind of weapon size or the size requirement matches this action's required size, we increase the crit chance if (critPerk.noSizeRequirement || critPerk.weaponSizeRequirement == this.requiredWeaponHand) { critRoll -= critPerk.critChanceBoost; } } } //If the current perk increases crit damage multipliers, we see if it applies to this attack else if (charPerk.GetType() == typeof(CritMultiplierPerk)) { CritMultiplierPerk critPerk = charPerk.GetComponent <CritMultiplierPerk>(); //If the perk applies to this attack's required skill check if (critPerk.boostAllSkills || critPerk.skillCritToBoost == this.weaponSkillUsed) { //If the perk applies to any kind of weapon size or the size requirement matches this action's required size, we increase the crit chance if (critPerk.noSizeRequirement || critPerk.weaponSizeRequirement == this.requiredWeaponHand) { critMultiplierBoost += critPerk.critMultiplierBoost; } } } } //If the crit roll is below the crit chance, the attack crits and we change the multiplier if (critRoll < this.critChance) { critMultiplier = this.critMultiplier + critMultiplierBoost; isCrit = true; } //Dictionary for the total amount of damage for each type that will be dealt with this attack Dictionary <CombatManager.DamageType, int> damageTypeTotalDamage = new Dictionary <CombatManager.DamageType, int>(); //Dictionary for if all of the spell damage types for if the damage is completely negated Dictionary <CombatManager.DamageType, SpellResistTypes> spellResistDictionary = new Dictionary <CombatManager.DamageType, SpellResistTypes>(); //Initializing the dictionaries correctly this.InitializeDamageDictionaries(damageTypeTotalDamage, spellResistDictionary); //Getting the damage from the used weapon this.GetWeaponDamage(actingChar, damageTypeTotalDamage, h); //Looping through each damage type for this attack foreach (AttackDamage atk in this.damageDealt) { //Int to hold all of the damage for the current attack int atkDamage = 0; //Adding the base damage atkDamage += atk.baseDamage; //Looping through each individual die rolled for (int d = 0; d < atk.diceRolled; ++d) { //Finding the value rolled on the current die atkDamage += Random.Range(1, atk.diceSides); } //Multiplying the damage by the crit multiplier atkDamage = Mathf.RoundToInt(atkDamage * critMultiplier); //Looping through the perks of the character that used this ability to see if they have any damage type boost perks foreach (Perk charPerk in actingChar.charPerks.allPerks) { //If the perk boosts a damage type that's the same as this damage type, we boost it if (charPerk.GetType() == typeof(DamageTypeBoostPerk) && atk.type == charPerk.GetComponent <DamageTypeBoostPerk>().damageTypeToBoost) { atkDamage += charPerk.GetComponent <DamageTypeBoostPerk>().GetDamageBoostAmount(actingChar, isCrit, false, atk.type); } } //Looping through the defending character's perks to see if they have any spell resist or absorb perks foreach (Perk defPerk in defendingChar.charPerks.allPerks) { if (defPerk.GetType() == typeof(SpellResistAbsorbPerk)) { SpellResistAbsorbPerk resistPerk = defPerk.GetComponent <SpellResistAbsorbPerk>(); //Checking to see if the current damage type is the same as this spell resist perk if (resistPerk.typeToResist == atk.type) { //Checking to see if the damage is negated entirely if (resistPerk.negateAllDamage) { //If the resist type for this spell isn't on absorb, we can negate it. ALWAYS have preference to absorb because it heals if (spellResistDictionary[atk.type] != SpellResistTypes.Absorb) { spellResistDictionary[atk.type] = SpellResistTypes.Negate; } } //Checking to see if the damage is absorbed to heal the target else if (resistPerk.absorbDamage) { spellResistDictionary[atk.type] = SpellResistTypes.Absorb; //Applying the damage reduction so the defender isn't healed as much damageTypeTotalDamage[atk.type] -= resistPerk.GetSpellResistAmount(defendingChar, isCrit, false); } //Otherwise we just get the amount that it normally resists else { damageTypeTotalDamage[atk.type] -= resistPerk.GetSpellResistAmount(defendingChar, isCrit, false); } } } } //Adding the current attack's damage to the correct type damageTypeTotalDamage[atk.type] += atkDamage; } //Looping through the attacking character's perks to see if there's any bonus damage to add to this attack foreach (Perk charPerk in actingChar.charPerks.allPerks) { //If the perk is a damage boosting perk, we get the bonus damage from it if (charPerk.GetType() == typeof(SkillDamageBoostPerk)) { int perkDamage = charPerk.GetComponent <SkillDamageBoostPerk>().GetDamageBoostAmount(actingChar, isCrit, false); //Applying the perk's added damage to the correct damage type damageTypeTotalDamage[charPerk.GetComponent <SkillDamageBoostPerk>().damageBoostType] += perkDamage; } } //Subtracting the target's melee and spell damage resistance from our attack damage this.SubtractResistances(damageTypeTotalDamage, defendingChar); //Dealing damage to the target this.DealDamage(damageTypeTotalDamage, spellResistDictionary, defendingChar, targetTile_, isCrit); //Dealing threat to the target this.DealThreat(damageTypeTotalDamage, actingChar, defendingChar, isCrit); //Creating the visual effect at the target tile if it isn't null if (this.visualEffectOnHit != null) { GameObject visual = GameObject.Instantiate(this.visualEffectOnHit.gameObject, targetTile_.transform.position, new Quaternion(), CombatManager.globalReference.transform); } //Looping through each effect that this attack can cause and triggering them foreach (AttackEffect effect in this.effectsOnHit) { this.TriggerEffect(effect, targetTile_, actingChar); } } }