/******************************************************************************/
/*!
\file Aiden_Cvengros_Knockback_Function.cs
\author Aiden Cvengros
\par email: aiden.cvengros\@digipen.edu
\date 2021.11.23
\brief
This file contains the knockback potion's functionality to blast enemies away from the center of the potion area.
Functions include:
+ PotionFunction
+ PotionDrinkFunction
Copyright © 2019 DigiPen (USA) Corporation.
*/
/******************************************************************************/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Makes the knockback potion an item that can be created in the Unity editor
[CreateAssetMenu(fileName = "New Potion", menuName = "Item/KnockbackPotion")]
// Knockback potion class is derived from base potion item class.
public class Knockback_Function : PotionItem
{
public Transform transform; // Holds the center of the potion area
public GameObject Explosion_Radius; // The splash prefab of the potion
public int damage; // How much damage the knockback potion deals
// This function runs the potion effect when splashed on a target
public override void PotionFunction(GameObject hitObject)
{
// Gets the health component of the affected target
HealthPool pool = hitObject.GetComponent<HealthPool>();
// Checks that a valid HealthPool component was found
if (pool != null)
{
// Applies affliction to deactivate enemy pathfinding so the knockback takes priority over AI movement
pool.AddAffliction(Afflictions.Deactivate, 0, 0.5f, 0.3f);
// Deals the damage of the potion
pool.DealDamage(damage + PlayerLook.damageBuffs / 4, DamageTypes.Blunt);
}
// Checks that the target has a valid rigidbody to be knocked back
if(hitObject.GetComponent<Rigidbody>())
{
// Gets vector for direction between the target and the center of the potion area
Vector3 distanceVec = hitObject.transform.position - transform.position;
distanceVec.Normalize();
// Standardizes the vertical force to prevent unwanted height boosts
distanceVec = new Vector3(distanceVec.x, 0.1f, distanceVec.z);
// Applies knockback force
hitObject.GetComponent<Rigidbody>().AddForce(distanceVec * Amount);
}
}
// This function runs the potion effect when the player drinks the potion
public override void PotionDrinkFunction(GameObject player)
{
// The knockback potion drink effect spawns a knockback effect on the player's location, knocking away nearby enemies
// Gets the position the potion area should be in relative to the player
Vector3 potionPosition = player.transform.position;
potionPosition.y -= 1f;
// Creates the potion area and associated particle effect
GameObject obj = Instantiate(Explosion_Radius, potionPosition, Quaternion.identity);
GameObject puddleParticles = Instantiate(PuddleParticles, potionPosition, Quaternion.Euler(90, 0, 0));
// Orients the potion area to be right-side-up
obj.transform.forward = Vector3.up;
obj.transform.localScale = new Vector3(Radius * PlayerLook.radiusUpBuffs, Radius * PlayerLook.radiusUpBuffs, 2.0f);
// Sets the new potion area to have the knockback potion effect
obj.GetComponent<Potion_Radius>().potion = this;
}
}