Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using Microsoft.Xna.Framework;
- using Terraria;
- using Terraria.ID;
- using Terraria.ModLoader;
- namespace TimeStop
- {
- public class TimeStop : Mod
- {
- public static int timeStopped;
- public static int preSpawnRate = -1;
- public enum MyMessageType : byte
- {
- timeStopBegan = 0,
- timeStopEnded = 1
- }
- public TimeStop()
- {
- Properties = new ModProperties()
- {
- Autoload = true,
- };
- }
- public override void HandlePacket(BinaryReader reader, int whoAmI)
- {
- // First we want to get the type of message that has been sent, so we can process its contents correctly.
- MyMessageType type = (MyMessageType)reader.ReadByte();
- switch (type)
- {
- case MyMessageType.timeStopBegan:
- StopTime();
- break;
- case MyMessageType.timeStopEnded:
- StartTime();
- break;
- }
- }
- public void StopTime()
- {
- timeStopped = 600;
- Main.NewText("Time Stop!");
- for (int i = 0; i < 200; ++i)
- {
- if (Main.npc[i].active)
- {
- StopNPC(Main.npc[i]);
- }
- }
- for (int p = 0; p < 1000; ++p)
- {
- TimeStopPlayer mp = Main.player[Main.projectile[p].owner].GetModPlayer<TimeStopPlayer>(this);
- if (Main.projectile[p].active && (mp.stoppedTime != true || Main.projectile[p].melee == false || Main.projectile[p].friendly == false || Main.projectile[p].npcProj == true))
- {
- StopProj(Main.projectile[p]);
- }
- }
- }
- public void StartTime()
- {
- timeStopped = 0;
- Main.NewText("Time Start!");
- for (int i = 0; i < 200; ++i)
- {
- if (Main.npc[i].active)
- {
- StartNPC(Main.npc[i]);
- }
- for (int p = 0; p < 1000; ++p)
- {
- TimeStopPlayer mp = Main.player[Main.projectile[p].owner].GetModPlayer<TimeStopPlayer>(this);
- if (Main.projectile[p].active && (mp.stoppedTime != true || Main.projectile[p].melee == false || Main.projectile[p].friendly == false || Main.projectile[p].npcProj == true))
- {
- StartProj(Main.projectile[p]);
- }
- }
- }
- }
- private void StopNPC(NPC npc)
- {
- TimeStopNPCInfo npcinfo = npc.GetModInfo<TimeStopNPCInfo>(this);
- npcinfo.preTimeStopVel = npc.velocity;
- npcinfo.timeStopPos = npc.position;
- npcinfo.preTimeStopDam = npc.damage;
- npcinfo.timeStopFrame = npc.frame;
- npcinfo.preTimeStopGrav = npc.noGravity;
- npc.damage = 0;
- npc.noGravity = true;
- }
- private void StartNPC(NPC npc)
- {
- TimeStopNPCInfo npcinfo = npc.GetModInfo<TimeStopNPCInfo>(this);
- npc.noGravity = false;
- npc.velocity = npcinfo.preTimeStopVel;
- npc.damage = npcinfo.preTimeStopDam;
- }
- private void StopProj(Projectile projectile)
- {
- TimeStopProjectileInfo projinfo = projectile.GetModInfo<TimeStopProjectileInfo>(this);
- // projinfo.preTimeStopVel = projectile.velocity;
- // projinfo.preTimeStopDam = projectile.damage;
- // projectile.velocity = Vector2.Zero;
- // projectile.damage = 0;
- }
- private void StartProj(Projectile projectile)
- {
- TimeStopProjectileInfo projinfo = projectile.GetModInfo<TimeStopProjectileInfo>(this);
- projectile.velocity = projinfo.preTimeStopVel;
- projectile.damage = projinfo.preTimeStopDam;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement