cdrandin

Untitled

Mar 8th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 20.62 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6. using DarkTonic.MasterAudio;
  7. using Devdog.InventorySystem;
  8.  
  9. public class Character : MonoBehaviour
  10. {
  11.     public List<CharacterState> states = new List<CharacterState>();
  12.    
  13.     public static List<Character> characters = new List<Character>();
  14.     public static List<Character> playerCharacters = new List<Character>();
  15.     public static List<Character> aiCharacters = new List<Character>();
  16.  
  17.     public string name;
  18.     public string[] abilityNames;
  19.     public List<string> weaponIDs = new List<string>(); // this will help associate which ability is from what weapon
  20.     public List<Ability> uninitializedAbilities = new List<Ability>();
  21.  
  22.     public List<Buff> buffs = new List<Buff>();
  23.     public List<Buffable> buffables = new List<Buffable>();
  24.  
  25.     public Color targetColor = Color.white;
  26.      
  27.     private bool _initialized = false;
  28.     private bool followFinger = false;
  29.  
  30.     [Header ("Primary Stats")]
  31.     // Use combatStats, as they calculate final values.
  32.     public int currentHealth = 100;
  33.     public int maxHealth = 100;
  34.     public int strength = 0;
  35.     public int dexterity = 0;
  36.     public int will = 0;
  37.  
  38.     [Header ("Secondary Stats")]
  39.     public CharacterShields characterShields = new CharacterShields();
  40.     public float meleeEvasionChance = 0.0f;
  41.  
  42.     public CombatStats combatStats = null;
  43.  
  44.     [Header ("Interface Elements")]
  45.     public Text healthLabel = null;
  46.     public GameObject powerIcon = null;
  47.  
  48.     [Header ("Casting Stuff")]
  49.     public GameObject castingCanvas = null;
  50.     public Image castingAbilityImage = null;
  51.     public Text castingAbilityTimerLabel = null;
  52.     public Image castingAbilityBar = null;
  53.  
  54.     public GameObject portrait = null;
  55.     public PortraitCallbackHandler portraitCallbackHandler = null;
  56.  
  57.     private float snapSpeed = 5.0f;
  58.     private List<GameObject> validTargets = new List<GameObject>();
  59.     public List<GameObject> abilityDocks = new List<GameObject>();
  60.     public List<Ability> abilities = new List<Ability>();
  61.     public Ability currentAbilityInUse = null;
  62.     public GameObject dock = null;
  63.     public EncounterNode node = null;
  64.    
  65.     public List<GameObject> deathEffects = new List<GameObject>();
  66.  
  67.     public Animator animator = null;
  68.  
  69.     private StateMachineEngine _stateMachine = null;
  70.  
  71.     public string ID = "";
  72.  
  73.     #region Events and Delegates
  74.     public delegate void PlayerDeathEventHandler(string name);
  75.     public event PlayerDeathEventHandler onPlayerDeath;
  76.     public event PlayerDeathEventHandler onAIDeath;
  77.  
  78.     public delegate void InitializedEventHandler(Character character);
  79.     public event InitializedEventHandler onInitialized;
  80.  
  81.     public delegate void SpawnedEventHandler(Character character);
  82.     public event SpawnedEventHandler onSpawned;
  83.  
  84.     public delegate void MadeActiveEventHandler();
  85.     public event MadeActiveEventHandler onMadeActive;
  86.    
  87.     public delegate void MadeInactiveEventHandler();
  88.     public event MadeInactiveEventHandler onMadeInactive;
  89.  
  90.     public delegate void OnDamagedByHandler(Character character);
  91.     public event OnDamagedByHandler onDamagedByHandler;
  92.     public event OnDamagedByHandler onDamagedByOnceHandler;
  93.  
  94.     public delegate void OnHealedByHandler(Character character);
  95.     public event OnHealedByHandler onHealedByHandler;
  96.  
  97.     #endregion
  98.  
  99.     #region Properties
  100.     public StateMachineEngine StateMachine{get{if (_stateMachine == null){_stateMachine = gameObject.AddComponent<StateMachineEngine>();}return _stateMachine;}}
  101.     public bool Initialized {get{return _initialized;}set{_initialized = value;}}
  102.     #endregion
  103.  
  104.     #region Unity Callbacks
  105.     protected virtual void Awake()
  106.     {
  107.         characters.Add(this);
  108.         targetColor = new Color(1.5f, 1.5f, 1.5f, 1.5f);
  109.  
  110.         StateMachine.Initialize<CharacterState>(this);
  111.         StateMachine.ChangeState(CharacterState.NONE); // HACK: Possible, to force AI to have abilities to display, however, when ability used it disappears
  112.     }
  113.  
  114.     // Use this for initialization
  115.     protected virtual void Start ()
  116.     {
  117.         AddBuff(new Flying(this));
  118.     }
  119.    
  120.     // Update is called once per frame
  121.     protected virtual void Update ()
  122.     {
  123.         states = StateMachine.GetStates<CharacterState>();
  124.  
  125.         Renderer renderer = portrait.GetComponent<Renderer>();
  126.         renderer.material.color = Color.Lerp(renderer.material.color, targetColor, Time.deltaTime * 10.0f);
  127.     }
  128.    
  129.     protected virtual void OnMouseDown()
  130.     {
  131.    
  132.     }
  133.    
  134.     protected virtual void OnMouseUp()
  135.     {
  136.  
  137.     }
  138.    
  139.     protected virtual void OnTriggerEnter(Collider other)
  140.     {
  141.         if (other.gameObject.tag == "Player")
  142.         {
  143.             validTargets.Add (other.gameObject);
  144.         }
  145.     }
  146.    
  147.     protected virtual void OnTriggerExit(Collider other)
  148.     {
  149.         if (other.gameObject.tag == "Player")
  150.         {
  151.             validTargets.Remove (other.gameObject);
  152.         }
  153.     }
  154.  
  155.     protected virtual void OnDestroy ()
  156.     {
  157.         Character.characters.Remove(this);
  158.         Destroy(this._stateMachine);
  159.     }
  160.  
  161.     public virtual void Destroy()
  162.     {
  163.         this.OnDestroy();
  164.         GameObject.Destroy(this.gameObject);
  165.     }
  166.  
  167.     #endregion
  168.  
  169.     #region Event Callbacks
  170.     public virtual void OnAbilitySelectingTarget(Ability ability)
  171.     {
  172.         if (Ability.CheckTarget(ability, this))
  173.         {
  174.             StateMachine.AddConcurrentState(CharacterState.TARGETABLE);
  175.         }
  176.  
  177.         if (!StateMachine.GetState<CharacterState>(CharacterState.TARGETABLE))
  178.         {
  179.             StateMachine.AddConcurrentState(CharacterState.UNTARGETABLE);
  180.         }
  181.     }
  182.  
  183.     public virtual void OnAbilityFinishedSelectingTarget(Ability ability)
  184.     {
  185.         StateMachine.RemoveConcurrentState(CharacterState.TARGETABLE);
  186.         StateMachine.RemoveConcurrentState(CharacterState.UNTARGETABLE);
  187.     }
  188.  
  189.     // Not sure if this kind of specifics is needed, maybe one will suffice
  190.     public virtual void OnDamagedBy(Character character)
  191.     {
  192.         if(onDamagedByOnceHandler != null)
  193.         {
  194.             onDamagedByOnceHandler(character);
  195.             onDamagedByOnceHandler = null;
  196.         }
  197.  
  198.         if(onDamagedByHandler != null)
  199.             onDamagedByHandler(character);
  200.     }
  201.  
  202.     public virtual void OnHealedBy(Character character)
  203.     {
  204.         if(onHealedByHandler != null)
  205.             onHealedByHandler(character);
  206.     }
  207.     #endregion
  208.  
  209.     #region Instance Methods
  210.     public virtual void Initialize(PartyMemberData partyMember, GameObject dock)
  211.     {
  212.         this.name = partyMember.name.Replace("*", "");
  213.         this.dock = dock;
  214.         node = this.dock.GetComponent<EncounterNode>();
  215.         node.Occupy(this);
  216.         gameObject.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
  217.  
  218.         LoadCharacterData(partyMember);
  219.         this.SetupCombatStats();
  220.     }
  221.  
  222.     public virtual void Initialize(string name, GameObject dock)
  223.     {
  224.         this.name = name;
  225.         this.dock = dock;
  226.         node = this.dock.GetComponent<EncounterNode>();
  227.         node.Occupy(this);
  228.         gameObject.transform.localScale = new Vector3(0.15f, 0.15f, 0.15f);
  229.         LoadCharacterData(name);
  230.  
  231.         this.SetupCombatStats();
  232.     }
  233.  
  234.     private void UpdateCombatStats()
  235.     {
  236.         this.strength = this.combatStats.str;
  237.         this.dexterity = this.combatStats.dex;
  238.         this.will = this.combatStats.will;
  239.     }
  240.  
  241.     private void SetupCombatStats()
  242.     {
  243.         // ONLY FOR PLAYER FOR THE TIME BEING TILL STATS GET UNIFIED BETTER
  244.         //
  245.  
  246.         // HACK: No nice way of collectively getting an accurate reading of stats
  247.         //      and this is mainly to get it for the test scenario stat input way.
  248. //      if(PlayerPrefs.HasKey(ScenarioTestV3UIManager.combat_stats_key) && this.gameObject.tag == "Player")
  249. //      {
  250. //          JSON.JSONObject jo = JSON.JSONObject.Parse(PlayerPrefs.GetString(ScenarioTestV3UIManager.combat_stats_key));
  251. //          Debug.Log(this.name);
  252. //          JSON.JSONObject hero = jo[this.name].Obj;
  253. //
  254. //          int health = 0;
  255. //          int spirit = 0;
  256. //          int strength = 0;
  257. //          int dexerity = 0;
  258. //          int will = 0;
  259. //
  260. //          if(hero.ContainsKey("health"))
  261. //              health = (int)hero["health"].Number;
  262. //
  263. //          if(hero.ContainsKey("spirit"))
  264. //              spirit = (int)hero["spirit"].Number;
  265. //     
  266. //          if(hero.ContainsKey("strength"))
  267. //              strength = (int)hero["strength"].Number;
  268. //     
  269. //          if(hero.ContainsKey("dexerity"))
  270. //              dexerity = (int)hero["dexerity"].Number;
  271. //     
  272. //          if(hero.ContainsKey("will"))
  273. //              will = (int)hero["will"].Number;
  274. //
  275. //          // load up combat stats
  276. //          this.combatStats = this.gameObject.AddComponent<CombatStats>(); // Probably doesn't need MonoBehaviour
  277. //          this.combatStats.Initialize(health, spirit, strength, dexerity, will);
  278. //
  279. //          // now setup stats for player
  280. //          this.currentHealth = this.maxHealth = this.combatStats.hp;
  281. //
  282. //          // HACK very coupling. Currently in place till stat stuff gets in place
  283. ////            GameManager.Instance.playerCurrentSpirit = GameManager.Instance.playerMaxSpirit = this.combatStats.spirit;
  284. //          GameManager.Instance.playerMaxSpirit = this.combatStats.spirit;
  285. //          this.UpdateCombatStats();
  286. //      }
  287.  
  288.         // Not using GetStatsForPartyMember since the testing tool would currently just be overwritting it
  289.         //      this.combatStats.Initialize(GameStateManager.instance.GetStatsForPartyMember(this.name), this.maxHealth, 0);
  290.     }
  291.  
  292.     public void MoveToEncounterNode(EncounterNode encounterNode)
  293.     {
  294.         dock = encounterNode.gameObject;
  295.         node.Vacate(this);
  296.         node = encounterNode;
  297.         node.Occupy(this);
  298.     }
  299.  
  300.     public virtual void ApplyDamageBy(Character character, int damage)
  301.     {
  302. //      this.ApplyDamage(damage);
  303.         this.OnDamagedBy(character);
  304.     }
  305.  
  306.     public virtual void ApplyDamage (int damage)
  307.     {
  308.         if (currentHealth <= 0)
  309.         {
  310.             if(tag == "Player")
  311.             {
  312.                 if (onPlayerDeath != null)
  313.                 {
  314.                     onPlayerDeath(name);
  315.                 }
  316.             }
  317.             else if(tag == "AI")
  318.             {
  319.                 if(onAIDeath != null)
  320.                 {
  321.                     onAIDeath(name);
  322.                 }
  323.             }
  324.         }
  325.     }
  326.  
  327.     public virtual void ApplyHealth(int amount)
  328.     {
  329. //      this.currentHealth = Mathf.Clamp(this.currentHealth + amount, 0, this.maxHealth);
  330.     }
  331.  
  332.     public virtual void ApplyHealthBy(Character character, int amount)
  333.     {
  334. //      this.ApplyHealth(amount);
  335.         this.OnHealedBy(character);
  336.     }
  337.  
  338.     public void CharacterGUIText(string message, Color color = new Color(), float speed = 1f, float duration = 1f)
  339.     {
  340.         GameObject prefab = (GameObject) Resources.Load("FloatingText");
  341.         GameObject go = (GameObject)Instantiate(prefab);
  342.         go.transform.position = gameObject.transform.position + Vector3.up ;
  343.         go.GetComponent<FloatingText>().Initialize(message, color, speed, duration);
  344.     }
  345.  
  346.     public void DamageGUIText(int damage)
  347.     {
  348.         if(damage == int.MaxValue || damage == 0) return;
  349.  
  350.         this.CharacterGUIText(damage.ToString(), Color.white, 1.0f, 2.0f);
  351.     }
  352.  
  353.     public void EffectGUIText(string message)
  354.     {
  355.         this.CharacterGUIText(message, Color.yellow, 2.0f, 1.0f);
  356.     }
  357.  
  358.     public void HealthGUIText(int amount)
  359.     {
  360.         if(amount == int.MaxValue || amount == 0) return;
  361.  
  362.         this.CharacterGUIText(amount.ToString(), Color.green, 1.0f, 2.0f);
  363.     }
  364.  
  365.     public virtual void UpdateHealthLabel()
  366.     {
  367.         healthLabel.text = currentHealth.ToString();
  368.     }
  369.  
  370.     public static bool CheckAvailability(Character character)
  371.     {
  372.         if (character.StateMachine.GetState(CharacterState.INACTIVE))
  373.         {
  374.             foreach(Ability ability in character.abilities)
  375.             {
  376.                 List<Character> targets = new List<Character>(Ability.GetTargets(ability));
  377.                 if (targets.Count > 0)
  378.                 {
  379.                     return true;
  380.                 }
  381. //              if (targets.Count <= 0)
  382. //              {
  383. //                  return false; // shouldn't be returning false so soon, check other abilities
  384. //              }
  385. //              return true;
  386.             }
  387.         }
  388.         return false;
  389.     }
  390.  
  391.     public void AddBuff(Buff buff)
  392.     {
  393.         buff.Initialize();
  394.         buffs.Add(buff);
  395.     }
  396.     #endregion
  397.  
  398.     #region Event Callbacks
  399.     public virtual void OnAbilityInitialized(Ability ability)
  400.     {
  401.         abilities.Add(ability);
  402.  
  403. //      if(ability.isPowerAbility && this.powerIcon != null)
  404. //      {
  405. //          this.powerIcon.SetActive(true);
  406. //      }
  407.     }
  408.  
  409.     public virtual void OnEncounterFinishedInitializing()
  410.     {
  411.    
  412.     }
  413.     #endregion
  414.  
  415.     #region Server Methods and Callbacks
  416.     public virtual void LoadCharacterData(string name)
  417.     {
  418.    
  419.     }
  420.  
  421.     public virtual void LoadCharacterData(PartyMemberData partyMember)
  422.     {
  423.     }
  424.    
  425.     public virtual void OnCharacterDataLoaded(Response response)
  426.     {
  427.         StateMachine.ChangeState(CharacterState.INITIALIZING);
  428.     }
  429.     #endregion
  430.  
  431.     #region Animation Callbacks
  432.     public virtual void OnFinishedSpawning()
  433.     {
  434.         if (onSpawned != null)
  435.         {
  436.             onSpawned(this);
  437.         }
  438.     }
  439.  
  440.     public virtual void OnFlipLiveFinished()
  441.     {
  442.         CameraController.Instance.RemoveLookTarget();
  443.         GameObject prefab = (GameObject) Resources.Load("FloatingText");
  444.         GameObject go = (GameObject)Instantiate(prefab);
  445.         go.transform.position = gameObject.transform.position + Vector3.up ;
  446.         go.GetComponent<FloatingText>().Initialize("Second Wind!", Color.yellow, 1.0f, 2.0f);
  447.  
  448.         animator.CrossFade("Idle", 0.1f);
  449.         StateMachine.ChangeState(CharacterState.INACTIVE);
  450.     }
  451.    
  452.     public virtual void OnFlipDieFinished()
  453.     {
  454.         CameraController.Instance.RemoveLookTarget();
  455.         animator.CrossFade("Idle", 0.1f);
  456.         foreach (GameObject deathEffect in deathEffects)
  457.         {
  458.             Instantiate(deathEffect, transform.position, Quaternion.identity);
  459.         }
  460.         if (onPlayerDeath != null)
  461.         {
  462.             onPlayerDeath(name);
  463.         }
  464.         StateMachine.ChangeState(CharacterState.DEAD);
  465.     }
  466.     #endregion
  467.  
  468.     #region INITIALIZING State Callbacks
  469.     protected virtual void INITIALIZING_Enter()
  470.     {
  471.         //GUIManager.Instance.RegisterPlayer(this);
  472.         portraitCallbackHandler.onFlipLiveFinished += OnFlipLiveFinished;
  473.         portraitCallbackHandler.onFlipDieFinished += OnFlipDieFinished;
  474.         portraitCallbackHandler.onFinishedSpawning += OnFinishedSpawning;
  475.         UpdateHealthLabel();
  476.  
  477.         AbilityTable abilityTable = TableManager.Instance.GetUserTable<AbilityTable>("AbilityTable");
  478.  
  479.         for (int i = 0; i < abilityNames.Length; i++)
  480.         {
  481.             if (i < abilityDocks.Count)
  482.             {
  483.                 if(abilityNames[i].Length == 0)
  484.                 {
  485.                     continue;
  486.                 };
  487.  
  488.                 GameObject go = null;
  489.                 Debug.Log(abilityNames[i]);
  490.                 try
  491.                 {
  492.                     AbilityTableItem item = abilityTable.TableData.GetItem(abilityNames[i]);
  493.                     go = (GameObject)Instantiate((Resources.Load("Abilities/" + item.ResourcePath, typeof(GameObject))) as GameObject, abilityDocks[i].transform.position, transform.rotation);
  494.  
  495.                     Ability ability = go.GetComponent<Ability>();
  496.  
  497.                     // update values from database, currently ID is the path to the ability. EX) _Marc's Proposed Abilities/...
  498.                     ability.ID = item.ID;
  499.                 }
  500.                 catch(System.Exception e)
  501.                 {
  502.                     Debug.LogError(string.Format("Ability error {0}: {1}", abilityNames[i], e));
  503.                     // Error gets thrown when ally comed into play but ability still gets load and works. idk wtf
  504.                     Debug.Log(this.name);
  505.                     return;
  506.                 }
  507.  
  508.                 go.transform.Rotate(Vector3.up * 180.0f);
  509.  
  510.                 uninitializedAbilities.Add (go.GetComponent<Ability>());
  511.  
  512.                 uninitializedAbilities[uninitializedAbilities.Count - 1].Initialize(this, abilityDocks[i]);
  513.                 uninitializedAbilities[uninitializedAbilities.Count - 1].onInitialized += this.OnAbilityInitialized;
  514.  
  515.                 EquipmentTable equipmentTable = TableManager.Instance.GetUserTable<EquipmentTable>("WeaponTable");
  516.                 if(equipmentTable != null && this.weaponIDs.Count > 0)
  517.                 {
  518.                     if(equipmentTable.TableData.ContainsItem(this.weaponIDs[i]))
  519.                     {
  520.                         EquipmentTableItem item = equipmentTable.TableData.GetItem(this.weaponIDs[i]);
  521.  
  522.                         if(item.Stats.ContainsKey("MINDMG") && item.Stats.ContainsKey("MAXDMG"))
  523.                         {
  524.                             uninitializedAbilities[uninitializedAbilities.Count - 1].SetItemBaseDamageLimit(item.Stats["MINDMG"], item.Stats["MAXDMG"]);
  525.                         }
  526.                     }
  527.                 }
  528.  
  529.                 // NOT SURE IF THIS IS BEST WAY TO DO THIS
  530.                 if(uninitializedAbilities[uninitializedAbilities.Count - 1].abilityChargeUI != null)
  531.                 {
  532.                     uninitializedAbilities[uninitializedAbilities.Count - 1].abilityChargeUI.Initialize();
  533.                    
  534.                     switch(i)
  535.                     {
  536.                     case 0:
  537.                     case 1:
  538.                         uninitializedAbilities[uninitializedAbilities.Count - 1].abilityChargeUI.SetChargePosition(AbilityChargeUI.AbilityChargePosition.LEFT);
  539.                         break;
  540.                     case 2:
  541.                         uninitializedAbilities[uninitializedAbilities.Count - 1].abilityChargeUI.SetChargePosition(AbilityChargeUI.AbilityChargePosition.TOP);
  542.                         break;
  543.                     case 3:
  544.                     case 4:
  545.                         uninitializedAbilities[uninitializedAbilities.Count - 1].abilityChargeUI.SetChargePosition(AbilityChargeUI.AbilityChargePosition.RIGHT);
  546.                         break;
  547.                     }
  548.                 }
  549.             }
  550.             else
  551.             {
  552.                 Debug.LogError ("Character has more abilities than ability slots!");
  553.                 Debug.Log(this.name);
  554.             }
  555.         }
  556.     }
  557.  
  558.     protected virtual void INITIALIZING_Update()
  559.     {
  560.         if (abilities.Count >= uninitializedAbilities.Count)
  561.         {
  562.             uninitializedAbilities = new List<Ability>();
  563.             if (onInitialized != null)
  564.             {
  565.                 onInitialized(this);
  566.             }
  567.         }
  568.     }
  569.  
  570.     protected virtual void INITIALIZING_Exit()
  571.     {
  572.         uninitializedAbilities.Clear();
  573.     }
  574.     #endregion
  575.  
  576.     #region SPAWNING State Callbacks
  577.     protected virtual void SPAWNING_Enter()
  578.     {
  579.         transform.position = dock.transform.position;
  580.         animator.Play("SpawnFromGround");
  581.     }
  582.    
  583.     protected virtual void SPAWNING_Update()
  584.     {
  585.  
  586.     }
  587.    
  588.     protected virtual void SPAWNING_Exit()
  589.     {
  590.  
  591.     }
  592.     #endregion
  593.  
  594.     #region ACTIVE State Callbacks
  595.     protected virtual void ACTIVE_Enter()
  596.     {
  597.         //CharacterGreetingAudio
  598.         MasterAudio.PlaySound (name +"Greeting");
  599.  
  600.         if (onMadeActive != null)
  601.         {
  602.             onMadeActive();
  603.         }
  604.     }
  605.  
  606.     protected virtual void ACTIVE_Update()
  607.     {
  608.         gameObject.transform.localScale = Vector3.Lerp(gameObject.transform.localScale, new Vector3(0.3f, 0.3f, 0.3f), Time.deltaTime * 5.0f);
  609.         foreach (Ability ability in abilities)
  610.         {
  611.             ability.gameObject.transform.localScale = Vector3.Lerp(ability.gameObject.transform.localScale, new Vector3(0.07f, 0.07f, 0.07f), Time.deltaTime * 5.0f);
  612.         }
  613.  
  614.         if (followFinger)
  615.         {
  616.             Vector3 v3 = Input.mousePosition;
  617.             v3.z = 10.0f;
  618.             v3 = Camera.main.ScreenToWorldPoint(v3);
  619.             transform.position = new Vector3(v3.x, dock.transform.position.y, v3.z) + Vector3.up * 0.1f;
  620.         }
  621.         else
  622.         {
  623.             transform.position = Vector3.Slerp(transform.position, dock.transform.position, Time.deltaTime * snapSpeed);
  624.         }
  625.     }
  626.  
  627.     protected virtual void ACTIVE_Exit()
  628.     {
  629.  
  630.     }
  631.     #endregion
  632.  
  633.     #region INACTIVE State Callbacks
  634.     protected virtual void INACTIVE_Enter()
  635.     {
  636.     }
  637.    
  638.     protected virtual void INACTIVE_Update()
  639.     {
  640.         transform.position = Vector3.Slerp(transform.position, dock.transform.position, Time.deltaTime * snapSpeed);
  641.         gameObject.transform.localScale = Vector3.Lerp(gameObject.transform.localScale, new Vector3(0.15f, 0.15f, 0.15f), Time.deltaTime * 5.0f);
  642.         foreach (Ability ability in abilities)
  643.         {
  644.             ability.gameObject.transform.localScale = Vector3.Lerp(ability.gameObject.transform.localScale, Vector3.zero, Time.deltaTime * 5.0f);
  645.         }
  646.     }
  647.    
  648.     protected virtual void INACTIVE_Exit()
  649.     {
  650.        
  651.     }
  652.     #endregion
  653.  
  654.     #region TARGETABLE State Callbacks
  655.     protected virtual void TARGETABLE_Enter()
  656.     {
  657.         targetColor = new Color(targetColor.r + Globals.DIMMER_VALUE, targetColor.g + Globals.DIMMER_VALUE, targetColor.b + Globals.DIMMER_VALUE, targetColor.a);
  658.     }
  659.    
  660.     protected virtual void TARGETABLE_Update()
  661.     {
  662.        
  663.     }
  664.    
  665.     protected virtual void TARGETABLE_Exit()
  666.     {
  667.         targetColor = new Color(targetColor.r - Globals.DIMMER_VALUE, targetColor.g - Globals.DIMMER_VALUE, targetColor.b - Globals.DIMMER_VALUE, targetColor.a);
  668.     }
  669.     #endregion
  670.    
  671.     #region TARGETABLE State Callbacks
  672.     protected virtual void UNTARGETABLE_Enter()
  673.     {
  674.         targetColor = new Color(targetColor.r - Globals.DIMMER_VALUE, targetColor.g - Globals.DIMMER_VALUE, targetColor.b - Globals.DIMMER_VALUE, targetColor.a);
  675.         gameObject.GetComponent<Collider>().enabled = false;
  676.     }
  677.    
  678.     protected virtual void UNTARGETABLE_Update()
  679.     {
  680.        
  681.     }
  682.    
  683.     protected virtual void UNTARGETABLE_Exit()
  684.     {
  685.         targetColor = new Color(targetColor.r + Globals.DIMMER_VALUE, targetColor.g + Globals.DIMMER_VALUE, targetColor.b + Globals.DIMMER_VALUE, targetColor.a);
  686.         gameObject.GetComponent<Collider>().enabled = true;
  687.     }
  688.     #endregion
  689.  
  690.     #region DEAD State Callbacks
  691.     protected virtual void DEAD_Enter()
  692.     {
  693.         foreach (Ability ability in Ability.abilities)
  694.         {
  695.             ability.onSelectingTarget -= this.OnAbilitySelectingTarget;
  696.             ability.onFinishedSelectingTarget -= this.OnAbilityFinishedSelectingTarget;
  697.         }
  698.         node.Vacate(this);
  699.         gameObject.SetActive(false);
  700.     }
  701.  
  702.     protected virtual void DEAD_Update()
  703.     {
  704.    
  705.     }
  706.  
  707.     protected virtual void DEAD_Exit()
  708.     {
  709.  
  710.     }
  711.     #endregion
  712.  
  713.     #region LOOTING State Callbacks
  714.     protected virtual void LOOTING_Enter()
  715.     {
  716.  
  717.     }
  718.    
  719.     protected virtual void LOOTING_Update()
  720.     {
  721.         gameObject.transform.localScale = Vector3.Lerp(gameObject.transform.localScale, new Vector3(0.15f, 0.15f, 0.15f), Time.deltaTime * 5.0f);
  722.         transform.position = Vector3.Slerp(transform.position, dock.transform.position, Time.deltaTime * snapSpeed);
  723.         foreach (Ability ability in abilities)
  724.         {
  725.             ability.gameObject.transform.localScale = Vector3.Lerp(ability.gameObject.transform.localScale, Vector3.zero, Time.deltaTime * 5.0f);
  726.         }
  727.     }
  728.    
  729.     protected virtual void LOOTING_Exit()
  730.     {
  731.        
  732.     }
  733.     #endregion
  734. }
  735.  
  736. public enum CharacterState{ NONE, INITIALIZING, SPAWNING, INACTIVE, ACTIVE, DEAD, TARGETABLE, UNTARGETABLE, CASTING, LOOTING}
Advertisement
Add Comment
Please, Sign In to add comment