Darkhitori

vAmmoManager/AddAmmo

Jan 14th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. //Darkhitori v1.0
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using Invector;
  6. using Invector.ItemManager;
  7.  
  8. namespace HutongGames.PlayMaker.Actions
  9. {
  10.     [ActionCategory("Invector/vAmmoManager")]
  11.     [Tooltip(" ")]
  12.     public class vAM_AddAmmo : FsmStateAction
  13.     {
  14.         [RequiredField]
  15.         [CheckForComponent(typeof(vAmmoManager))]
  16.         public FsmOwnerDefault gameObject;
  17.        
  18.         public enum AddAmmo
  19.         {
  20.             ammoName_id_amount,
  21.             id_amount,
  22.             item
  23.         }
  24.        
  25.         public AddAmmo methods;
  26.        
  27.         public FsmString ammoName;
  28.        
  29.         public FsmInt id;
  30.        
  31.         public FsmInt amount;
  32.        
  33.         [ObjectType(typeof(vItem))]
  34.         public FsmObject item;
  35.        
  36.         public FsmBool everyFrame;
  37.  
  38.         vAmmoManager theScript;
  39.  
  40.         public override void Reset()
  41.         {
  42.             gameObject = null;
  43.             methods = AddAmmo.ammoName_id_amount;
  44.             ammoName = "";
  45.             id = null;
  46.             amount = null;
  47.             item = null;
  48.             everyFrame = true;
  49.         }
  50.        
  51.         public override void OnEnter()
  52.         {
  53.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  54.  
  55.             theScript = go.GetComponent<vAmmoManager>();
  56.  
  57.  
  58.             if (!everyFrame.Value)
  59.             {
  60.                 DoTheMagic();
  61.                 Finish();
  62.             }
  63.  
  64.         }
  65.  
  66.         public override void OnUpdate()
  67.         {
  68.             if (everyFrame.Value)
  69.             {
  70.                 DoTheMagic();
  71.             }
  72.         }
  73.  
  74.         void DoTheMagic()
  75.         {
  76.             var go = Fsm.GetOwnerDefaultTarget(gameObject);
  77.             if (go == null)
  78.             {
  79.                 return;
  80.             }
  81.            
  82.             switch(methods)
  83.             {
  84.             case AddAmmo.ammoName_id_amount:
  85.                 theScript.AddAmmo(ammoName.Value, id.Value, amount.Value);
  86.                 break;
  87.             case AddAmmo.id_amount:
  88.                 theScript.AddAmmo(id.Value, amount.Value);
  89.                 break;
  90.             case AddAmmo.item:
  91.                 var aItem = item.Value as vItem;
  92.                 if (aItem == null)
  93.                 {
  94.                     return;
  95.                 }
  96.                 theScript.AddAmmo(aItem);
  97.                 break;
  98.             }
  99.                        
  100.         }
  101.  
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment