Advertisement
Darkhitori

vCharacterStandalone/TakeDamage

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