Advertisement
davinatoratoe

Restore.cs

Aug 31st, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.97 KB | None | 0 0
  1. //'Import' necessary packages
  2. using System;
  3. using TShockAPI;
  4. using Terraria;
  5. using TerrariaApi.Server;
  6. using System.Timers;
  7.  
  8. namespace Restore
  9. {
  10.     //Version of TShock API
  11.     [ApiVersion(1,16)]
  12.  
  13.     public class Restore : TerrariaPlugin
  14.     {
  15.        
  16.         //Get version of plugin
  17.         public override Version Version
  18.         {
  19.             get { return new Version(1, 0); }
  20.         }
  21.        
  22.         //Name the plugin
  23.         public override string Name
  24.         {
  25.             get { return "Restore"; }
  26.         }
  27.        
  28.         //Who created the plugin
  29.         public override string Author
  30.         {
  31.             get { return "MrGgggg243"; }
  32.         }
  33.        
  34.         //Describe the plugin (not necessary)
  35.         public override string Description
  36.         {
  37.             get { return "[FMG] Designed to refill health and mana"; }
  38.         }
  39.  
  40.         //Variables
  41.         private Timer restoreTimer = new Timer(1000);
  42.         public TSPlayer player;
  43.         public Boolean HPMode = false;
  44.         public Boolean ManaMode = false;
  45.         public Int32 maxHP = 0;
  46.         public Int32 curHP = 0;
  47.         public Int32 maxMana = 0;
  48.         public Int32 curMana = 0;
  49.  
  50.         //Will be run first by TShock
  51.         //-x will be run after TShock API loads
  52.         //+x will be run before TShock API loads
  53.         public Restore(Main game)
  54.             : base(game)
  55.         {
  56.             Order = +4;
  57.         }
  58.  
  59.         //Main code area
  60.         public override void Initialize()
  61.         {
  62.             //Setup hooks
  63.             ServerApi.Hooks.ServerLeave.Register(this, OnLeave);
  64.  
  65.             //Code for creating a command
  66.             //new Command(permissions, method, command)
  67.             Commands.ChatCommands.Add(new Command("fmg.restore", CallRestore, "restore"));
  68.            
  69.             restoreTimer.Elapsed += new ElapsedEventHandler(restoreTimer_Elapsed);
  70.             restoreTimer.Interval = 1000;
  71.             restoreTimer.AutoReset = true;
  72.             restoreTimer.Enabled = false;
  73.         }
  74.  
  75.         private void CallRestore(CommandArgs args)
  76.         {
  77.             string cmd = "help";
  78.  
  79.             if (args.Parameters.Count > 0)
  80.             {
  81.                 cmd = args.Parameters[0].ToLower();
  82.             }
  83.  
  84.             switch (cmd)
  85.             {
  86.                 case "help":
  87.                     Help(args);
  88.                     break;
  89.                 case "hp":
  90.                 case "health":
  91.                     RestoreHp(args);
  92.                     break;
  93.                 case "mana":
  94.                     RestoreMana(args);
  95.                     break;
  96.                 default:
  97.                     Help(args);
  98.                     break;
  99.             }
  100.         }
  101.  
  102.         private void restoreTimer_Elapsed(object sender, ElapsedEventArgs e)
  103.         {
  104.             player.SendMessage("Timer", Color.Aqua);
  105.             if (ManaMode)
  106.             {
  107.                 if (!Main.player[player.Index].hostile)
  108.                 {
  109.                     if (HPMode || ManaMode)
  110.                     {
  111.                         maxHP = Main.player[player.Index].statLifeMax;
  112.                         curHP = Main.player[player.Index].statLife;
  113.                         if (curHP < maxHP)
  114.                         {
  115.                             Main.player[player.Index].HealEffect(maxHP, false);
  116.                         }
  117.                     }
  118.                     if (ManaMode)
  119.                     {
  120.                         maxMana = Main.player[player.Index].statManaMax;
  121.                         curMana = Main.player[player.Index].statMana;
  122.                         if (curMana < maxMana)
  123.                         {
  124.                             Main.player[player.Index].ManaEffect(maxMana);
  125.                         }
  126.                     }
  127.                 }
  128.                 else
  129.                 {
  130.                     player.SendMessage("FMG Restore - /restore cannot be used while in PVP and his been disabled.", Color.Aqua);
  131.                     HPMode = false;
  132.                     ManaMode = false;
  133.                 }
  134.             }
  135.             //restoreTimer.Enabled = true;
  136.         }
  137.  
  138.         private void RestoreHp(CommandArgs args)
  139.         {
  140.             var plr = args.Player;
  141.             if (!Main.player[plr.Index].hostile)
  142.             {
  143.                 if (!HPMode)
  144.                 {
  145.                     HPMode = true;
  146.                     plr.SendMessage("FMG Success - You now have infinite health.", Color.Aqua);
  147.                     restoreTimer.Start();
  148.                 }
  149.                 else if (HPMode)
  150.                 {
  151.                     HPMode = false;
  152.                     plr.SendMessage("FMG Success - You now no longer have infinite health.", Color.Aqua);
  153.                     restoreTimer.Stop();
  154.                 }
  155.             }
  156.             else
  157.             {
  158.                 plr.SendMessage("FMG Error - /restore cannot be used while in PVP", Color.Aqua);
  159.             }
  160.         }
  161.  
  162.         private void RestoreMana(CommandArgs args)
  163.         {
  164.             var plr = args.Player;
  165.             if (!Main.player[plr.Index].hostile)
  166.             {
  167.                 if (!ManaMode)
  168.                 {
  169.                     ManaMode = true;
  170.                     plr.SendMessage("FMG Success - You now have infinite mana.", Color.Aqua);
  171.                     restoreTimer.Start();
  172.                 }
  173.                 else if (ManaMode)
  174.                 {
  175.                     ManaMode = false;
  176.                     plr.SendMessage("FMG Success - You now no longer have infinite mana.", Color.Aqua);
  177.                     restoreTimer.Stop();
  178.                 }
  179.             }
  180.             else
  181.             {
  182.                 plr.SendMessage("FMG Error - /restore cannot be used while in PVP", Color.Aqua);
  183.             }
  184.         }
  185.  
  186.         private void OnLeave(LeaveEventArgs args)
  187.         {
  188.             HPMode = false;
  189.             ManaMode = false;
  190.         }
  191.  
  192.         private void Help(CommandArgs args)
  193.         {
  194.             args.Player.SendMessage("FMG Restore - Help:", Color.Aqua);
  195.             args.Player.SendMessage("   /restore <hp/health-mana> - restore a player's health or mana", Color.Aqua);
  196.         }
  197.  
  198.     }
  199. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement