Advertisement
Darkhitori

v_AIController/OnReceiveAttack

Jan 14th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1. //Darkhitori v1.0
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Invector.EventSystems;
  6. using Invector;
  7.  
  8. namespace HutongGames.PlayMaker.Actions
  9. {
  10.     [ActionCategory("Invector/v_AIController")]
  11.     [Tooltip(" ")]
  12.     public class vAIC_OnReceiveAttack : FsmStateAction
  13.     {
  14.         [RequiredField]
  15.         [CheckForComponent(typeof(v_AIController))]
  16.         public FsmOwnerDefault gameObject;
  17.        
  18.         [ActionSection("vDamage")]
  19.         [Tooltip("Apply damage to the Character Health")]
  20.         public FsmInt damageValue;
  21.         [Tooltip("How much stamina the target will lost when blocking this attack")]
  22.         public FsmFloat staminaBlockCost;
  23.         [Tooltip("How much time the stamina of the target will wait to recovery")]
  24.         public FsmFloat staminaRecoveryDelay;
  25.         [Tooltip("Apply damage even if the Character is blocking")]
  26.         public FsmBool ignoreDefense;
  27.         [Tooltip("Activated Ragdoll when hit the Character")]
  28.         public FsmBool activeRagdoll;
  29.         public FsmGameObject sender;
  30.         public FsmGameObject receiver;
  31.         public FsmVector3 hitPosition;
  32.         public FsmInt recoil_id;
  33.         public FsmInt reaction_id;
  34.         public FsmString attackName;
  35.        
  36.         [ActionSection("------------------------")]
  37.         [ObjectType(typeof(vIMeleeFighter))]
  38.         public FsmObject attacker;
  39.        
  40.         public FsmEvent sendEvent;
  41.        
  42.         public FsmBool everyFrame;
  43.  
  44.         v_AIController theScript;
  45.         vDamage dam;
  46.  
  47.  
  48.         public override void Reset()
  49.         {
  50.             gameObject = null;
  51.             damageValue = 15;
  52.             staminaBlockCost = 5;
  53.             staminaRecoveryDelay = 1;
  54.             ignoreDefense = false;
  55.             activeRagdoll = false;
  56.             sender = null;
  57.             receiver = null;
  58.             hitPosition = null;
  59.             recoil_id = null;
  60.             reaction_id = null;
  61.             attackName = "";
  62.             attacker = null;
  63.             sendEvent = null;
  64.             everyFrame = true;
  65.         }
  66.        
  67.         public override void OnEnter()
  68.         {
  69.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  70.  
  71.             theScript = go.GetComponent<v_AIController>();
  72.  
  73.  
  74.             if (!everyFrame.Value)
  75.             {
  76.                 DoTheMagic();
  77.                 Finish();
  78.             }
  79.  
  80.         }
  81.  
  82.         public override void OnUpdate()
  83.         {
  84.             if (everyFrame.Value)
  85.             {
  86.                 DoTheMagic();
  87.             }
  88.         }
  89.  
  90.         void DoTheMagic()
  91.         {
  92.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  93.             if (go == null)
  94.             {
  95.                 return;
  96.             }
  97.            
  98.             var vMelee = attacker.Value as vIMeleeFighter;
  99.             if (vMelee == null)
  100.             {
  101.                 return;
  102.             }
  103.            
  104.             dam.damageValue = damageValue.Value;
  105.             dam.staminaBlockCost = staminaBlockCost.Value;
  106.             dam.staminaRecoveryDelay = staminaRecoveryDelay.Value;
  107.             dam.ignoreDefense = ignoreDefense.Value;
  108.             dam.activeRagdoll = activeRagdoll.Value;
  109.             dam.sender = sender.Value.transform;
  110.             dam.receiver = receiver.Value.transform;
  111.             dam.hitPosition = hitPosition.Value;
  112.             dam.recoil_id = recoil_id.Value;
  113.             dam.reaction_id = reaction_id.Value;
  114.             dam.attackName = attackName.Value;
  115.             var vDam = dam;
  116.            
  117.             theScript.OnReceiveAttack(vDam, vMelee);
  118.             if(sendEvent == null)
  119.             {
  120.                 return;
  121.             }
  122.             else
  123.             {
  124.                 Fsm.Event(sendEvent);
  125.             }
  126.         }
  127.  
  128.     }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement