Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- //PUT THE AI BELOW THE SPELL SCRIPT OTHERWISE SPELLS WILL NOT WORK!
- //ALL SPELL NAMES MUST MATCH THE NAME OF THE PREFAB THEY ARE ATTACHED TO EXACTLY!
- namespace Assets.Scripts
- {
- public abstract class AbstractAI : MonoBehaviour
- {
- //Various Variables used throughout the script
- GameObject Player;
- Transform Target;
- //bool SpellGet = false;
- //bool SpellsGot = false;
- bool CanCast = false;
- bool Casting = false;
- bool Cast = false;
- bool CanAttack = false;
- Transform[] SpellsArray;
- Transform[] DeliveryMethodArray;
- //These are the values to be changed with each enemy
- float MinimumRange;
- float CurrentRange;
- float CurrentMoveSpeed;
- int CurrentHealth;
- float StrikeRange;
- float SpellRange;
- //These are the starting values, they are to be returned when a debuff ends
- int MaxHealth;
- float MaxMoveSpeed;
- float MaxRange;
- //AI Booleans
- bool Offensive = false;
- bool Defensive = false;
- bool Misc = false;
- bool SendMessage = false;
- // Use this for initialization
- void Start()
- {
- //Puts all of the children on this gameObject into an object array (Used in the spells section of the script)
- SpellsArray = new Transform[transform.childCount];
- //Max Stats Set
- SpellRange = 10;
- StrikeRange = 5;
- MaxHealth = 10;
- MaxMoveSpeed = 10;
- MaxRange = 25;
- //Current Stats Set
- CurrentHealth = MaxHealth;
- CurrentMoveSpeed = MaxMoveSpeed;
- CurrentRange = MaxRange;
- //Transforms and GO Set
- Player = GameObject.FindGameObjectWithTag("Player");
- Target = Player.transform;
- SpellsArray = PopulateSpellArray();
- DeliveryMethodArray = DeliveryMethodHandling(SpellsArray);
- }
- // Update is called once per frame
- void Update()
- {
- //--------------------------------------------------------- BASIC EVENTS AND STATISTICS
- //Range Check
- CurrentRange = Vector2.Distance(new Vector2(transform.position.x, transform.position.y), new Vector2(Target.position.x, Target.position.y));
- //On Death
- if (CurrentHealth == 0)
- {
- Destroy(gameObject);
- }
- //----------------------------------------------------------NORMALIZED PATTERN AND LOGIC
- //Normalized Range Logic
- if (MinimumRange < CurrentRange)
- {
- }
- if (MinimumRange > CurrentRange)
- {
- gameObject.transform.position = new Vector2(Mathf.MoveTowards(transform.position.x, Target.position.x, CurrentMoveSpeed), 0);
- }
- //-------------------------------------------------------------ATTACKING LOGIC
- //Melee Range Check
- if (CurrentRange < StrikeRange)
- {
- CanAttack = true;
- }
- else
- {
- CanAttack = false;
- }
- //Spell Range Check
- if (CurrentRange < SpellRange)
- {
- CanCast = true;
- }
- else
- {
- CanCast = false;
- }
- //----------------------------------------------------------------- AI WINDOW HANDLING
- //Offensive Window (0)
- if (Offensive == true && DeliveryMethodArray[0] != null)
- {
- DeliveryMethodArray[0].SendMessage("SendMessageTrue");
- }
- //Defensive Window (1)
- if (Defensive == true && DeliveryMethodArray[1] != null)
- {
- DeliveryMethodArray[1].SendMessage("SendMessageTrue");
- }
- //Misc Window (2)
- if (Misc == true && DeliveryMethodArray[2] != null)
- {
- DeliveryMethodArray[2].SendMessage("SendMessageTrue");
- }
- }
- //---------------------------------------------------------------------------METHOD HANDLING--------------------------------------------------------------------------------
- public Transform[] PopulateSpellArray()
- {
- Transform[] ChildArray = new Transform[transform.childCount];
- for (int i = 0; i < transform.childCount; i++)
- {
- ChildArray[i] = transform.GetChild(i);
- }
- return ChildArray;
- }
- //This takes all of the delivery methods from the children of the gameObject and puts them into a transform array. Each Delivery method can then be called upon to spawn its
- //Missile
- public Transform[] DeliveryMethodHandling(Transform[] TA)
- {
- List<Transform> DeliveryList = new List<Transform>();
- Transform[] DeliveryArray = new Transform[transform.childCount];
- foreach (Transform T in TA)
- {
- if (!DeliveryList.Contains(T))
- {
- DeliveryList.Add(T);
- }
- }
- for (int i = 0; i < transform.childCount; i++)
- {
- if (!DeliveryArray[i] == DeliveryList[i])
- {
- DeliveryArray[i] = DeliveryList[i];
- }
- }
- return DeliveryArray;
- }
- class MessageHandling : AbstractDelivery
- {
- public void SendMessageTrue()
- {
- MessageRecieved = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement