Advertisement
Alceris

Untitled

Jun 25th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.10 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3.  
  4. using Microsoft.Xna.Framework;
  5.  
  6. using Terraria;
  7. using Terraria.ID;
  8. using Terraria.ModLoader;
  9.  
  10. namespace TimeStop
  11. {
  12. public class TimeStop : Mod
  13.  
  14. {
  15. public static int timeStopped;
  16. public static int preSpawnRate = -1;
  17. public enum MyMessageType : byte
  18. {
  19. timeStopBegan = 0,
  20. timeStopEnded = 1
  21. }
  22. public TimeStop()
  23. {
  24. Properties = new ModProperties()
  25. {
  26. Autoload = true,
  27. };
  28. }
  29. public override void HandlePacket(BinaryReader reader, int whoAmI)
  30. {
  31. // First we want to get the type of message that has been sent, so we can process its contents correctly.
  32. MyMessageType type = (MyMessageType)reader.ReadByte();
  33.  
  34. switch (type)
  35. {
  36. case MyMessageType.timeStopBegan:
  37. StopTime();
  38. break;
  39.  
  40. case MyMessageType.timeStopEnded:
  41. StartTime();
  42. break;
  43. }
  44. }
  45.  
  46. public void StopTime()
  47. {
  48. timeStopped = 600;
  49.  
  50. Main.NewText("Time Stop!");
  51.  
  52. for (int i = 0; i < 200; ++i)
  53. {
  54. if (Main.npc[i].active)
  55. {
  56. StopNPC(Main.npc[i]);
  57. }
  58. }
  59. for (int p = 0; p < 1000; ++p)
  60. {
  61. TimeStopPlayer mp = Main.player[Main.projectile[p].owner].GetModPlayer<TimeStopPlayer>(this);
  62. if (Main.projectile[p].active && (mp.stoppedTime != true || Main.projectile[p].melee == false || Main.projectile[p].friendly == false || Main.projectile[p].npcProj == true))
  63. {
  64. StopProj(Main.projectile[p]);
  65. }
  66. }
  67. }
  68. public void StartTime()
  69. {
  70. timeStopped = 0;
  71.  
  72. Main.NewText("Time Start!");
  73.  
  74. for (int i = 0; i < 200; ++i)
  75. {
  76. if (Main.npc[i].active)
  77. {
  78. StartNPC(Main.npc[i]);
  79. }
  80. for (int p = 0; p < 1000; ++p)
  81. {
  82. TimeStopPlayer mp = Main.player[Main.projectile[p].owner].GetModPlayer<TimeStopPlayer>(this);
  83. if (Main.projectile[p].active && (mp.stoppedTime != true || Main.projectile[p].melee == false || Main.projectile[p].friendly == false || Main.projectile[p].npcProj == true))
  84. {
  85. StartProj(Main.projectile[p]);
  86. }
  87. }
  88. }
  89. }
  90.  
  91. private void StopNPC(NPC npc)
  92. {
  93. TimeStopNPCInfo npcinfo = npc.GetModInfo<TimeStopNPCInfo>(this);
  94.  
  95. npcinfo.preTimeStopVel = npc.velocity;
  96. npcinfo.timeStopPos = npc.position;
  97. npcinfo.preTimeStopDam = npc.damage;
  98. npcinfo.timeStopFrame = npc.frame;
  99. npcinfo.preTimeStopGrav = npc.noGravity;
  100.  
  101. npc.damage = 0;
  102. npc.noGravity = true;
  103. }
  104. private void StartNPC(NPC npc)
  105. {
  106. TimeStopNPCInfo npcinfo = npc.GetModInfo<TimeStopNPCInfo>(this);
  107.  
  108. npc.noGravity = false;
  109. npc.velocity = npcinfo.preTimeStopVel;
  110. npc.damage = npcinfo.preTimeStopDam;
  111. }
  112. private void StopProj(Projectile projectile)
  113. {
  114. TimeStopProjectileInfo projinfo = projectile.GetModInfo<TimeStopProjectileInfo>(this);
  115.  
  116. // projinfo.preTimeStopVel = projectile.velocity;
  117. // projinfo.preTimeStopDam = projectile.damage;
  118. // projectile.velocity = Vector2.Zero;
  119. // projectile.damage = 0;
  120. }
  121. private void StartProj(Projectile projectile)
  122. {
  123. TimeStopProjectileInfo projinfo = projectile.GetModInfo<TimeStopProjectileInfo>(this);
  124.  
  125. projectile.velocity = projinfo.preTimeStopVel;
  126. projectile.damage = projinfo.preTimeStopDam;
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement