상속: Terraria.ModLoader.ModWorld
예제 #1
0
        // Volcano Tremor
        public override Matrix ModifyTransformMatrix(Matrix Transform)
        {
            if (!Main.gameMenu)
            {
                ExampleWorld world = GetModWorld <ExampleWorld>();
                if (world.VolcanoTremorTime > 0)
                {
                    if (world.VolcanoTremorTime % ShakeLength == 0)
                    {
                        ShakeCount       = 0;
                        previousRotation = targetRotation;
                        previousOffsetX  = targetOffsetX;
                        previousOffsetY  = targetOffsetY;
                        targetRotation   = (Main.rand.NextFloat() - .5f) * MathHelper.ToRadians(15);
                        targetOffsetX    = Main.rand.Next(60) - 30;
                        targetOffsetY    = Main.rand.Next(40) - 20;
                        if (world.VolcanoTremorTime == ShakeLength)
                        {
                            targetRotation = 0;
                            targetOffsetX  = 0;
                            targetOffsetY  = 0;
                        }
                    }
                    float transX = Main.screenWidth / 2;
                    float transY = Main.screenHeight / 2;

                    float lerp     = (float)(ShakeCount) / ShakeLength;
                    float rotation = MathHelper.Lerp(previousRotation, targetRotation, lerp);
                    float offsetX  = MathHelper.Lerp(previousOffsetX, targetOffsetX, lerp);
                    float offsetY  = MathHelper.Lerp(previousOffsetY, targetOffsetY, lerp);

                    world.VolcanoTremorTime--;
                    ShakeCount++;


                    return(Transform
                           * Matrix.CreateTranslation(-transX, -transY, 0f)
                           * Matrix.CreateRotationZ(rotation)
                           * Matrix.CreateTranslation(transX, transY, 0f)
                           * Matrix.CreateTranslation(offsetX, offsetY, 0f));
                    //Matrix.CreateFromAxisAngle(new Vector3(Main.screenWidth / 2, Main.screenHeight / 2, 0f), .2f);
                    //Matrix.CreateRotationZ(MathHelper.ToRadians(30));
                }
            }
            return(Transform);
        }
예제 #2
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte();

            switch (msgType)
            {
            // This message sent by the server to initialize the Volcano Tremor on clients
            case ExampleModMessageType.SetTremorTime:
                int          tremorTime = reader.ReadInt32();
                ExampleWorld world      = GetModWorld <ExampleWorld>();
                world.VolcanoTremorTime = tremorTime;
                break;

            // This message sent by the server to initialize the Volcano Rubble.
            case ExampleModMessageType.VolcanicRubbleMultiplayerFix:
                int numberProjectiles = reader.ReadInt32();
                for (int i = 0; i < numberProjectiles; i++)
                {
                    int  identity = reader.ReadInt32();
                    bool found    = false;
                    for (int j = 0; j < 1000; j++)
                    {
                        if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active)
                        {
                            Main.projectile[j].hostile = true;
                            //Main.projectile[j].name = "Volcanic Rubble";
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ErrorLogger.Log("Error: Projectile not found");
                    }
                }
                break;

            case ExampleModMessageType.PuritySpirit:
                PuritySpirit spirit = Main.npc[reader.ReadInt32()].modNPC as PuritySpirit;
                if (spirit != null && spirit.npc.active)
                {
                    spirit.HandlePacket(reader);
                }
                break;

            case ExampleModMessageType.HeroLives:
                Player player = Main.player[reader.ReadInt32()];
                int    lives  = reader.ReadInt32();
                player.GetModPlayer <ExamplePlayer>(this).heroLives = lives;
                if (lives > 0)
                {
                    NetworkText text;
                    if (lives == 1)
                    {
                        text = NetworkText.FromKey("Mods.ExampleMod.LifeLeft", player.name);
                    }
                    else
                    {
                        text = NetworkText.FromKey("Mods.ExampleMod.LivesLeft", player.name, lives);
                    }
                    NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25));
                }
                break;

            default:
                ErrorLogger.Log("ExampleMod: Unknown Message type: " + msgType);
                break;
            }
        }
예제 #3
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte();

            switch (msgType)
            {
            // This message sent by the server to initialize the Volcano Tremor on clients
            case ExampleModMessageType.SetTremorTime:
                int          tremorTime = reader.ReadInt32();
                ExampleWorld world      = GetInstance <ExampleWorld>();
                world.VolcanoTremorTime = tremorTime;
                break;

            // This message sent by the server to initialize the Volcano Rubble.
            case ExampleModMessageType.VolcanicRubbleMultiplayerFix:
                int numberProjectiles = reader.ReadInt32();
                for (int i = 0; i < numberProjectiles; i++)
                {
                    int  identity = reader.ReadInt32();
                    bool found    = false;
                    for (int j = 0; j < 1000; j++)
                    {
                        if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active)
                        {
                            Main.projectile[j].hostile = true;
                            //Main.projectile[j].name = "Volcanic Rubble";
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        Logger.Error("Error: Projectile not found");
                    }
                }
                break;

            case ExampleModMessageType.PuritySpirit:
                if (Main.npc[reader.ReadInt32()].modNPC is PuritySpirit spirit && spirit.npc.active)
                {
                    spirit.HandlePacket(reader);
                }
                break;

            case ExampleModMessageType.HeroLives:
                Player player = Main.player[reader.ReadInt32()];
                int    lives  = reader.ReadInt32();
                player.GetModPlayer <ExamplePlayer>().heroLives = lives;
                if (lives > 0)
                {
                    NetworkText text;
                    if (lives == 1)
                    {
                        text = NetworkText.FromKey("Mods.ExampleMod.LifeLeft", player.name);
                    }
                    else
                    {
                        text = NetworkText.FromKey("Mods.ExampleMod.LivesLeft", player.name, lives);
                    }
                    NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25));
                }
                break;

            // This message syncs ExamplePlayer.exampleLifeFruits
            case ExampleModMessageType.ExamplePlayerSyncPlayer:
                byte          playernumber      = reader.ReadByte();
                ExamplePlayer examplePlayer     = Main.player[playernumber].GetModPlayer <ExamplePlayer>();
                int           exampleLifeFruits = reader.ReadInt32();
                examplePlayer.exampleLifeFruits = exampleLifeFruits;
                examplePlayer.nonStopParty      = reader.ReadBoolean();
                // SyncPlayer will be called automatically, so there is no need to forward this data to other clients.
                break;

            case ExampleModMessageType.NonStopPartyChanged:
                playernumber  = reader.ReadByte();
                examplePlayer = Main.player[playernumber].GetModPlayer <ExamplePlayer>();
                examplePlayer.nonStopParty = reader.ReadBoolean();
                // Unlike SyncPlayer, here we have to relay/forward these changes to all other connected clients
                if (Main.netMode == NetmodeID.Server)
                {
                    var packet = GetPacket();
                    packet.Write((byte)ExampleModMessageType.NonStopPartyChanged);
                    packet.Write(playernumber);
                    packet.Write(examplePlayer.nonStopParty);
                    packet.Send(-1, playernumber);
                }
                break;

            case ExampleModMessageType.ExampleTeleportToStatue:
                if (Main.npc[reader.ReadByte()].modNPC is NPCs.ExamplePerson person && person.npc.active)
                {
                    person.StatueTeleport();
                }
                break;

            default:
                Logger.WarnFormat("ExampleMod: Unknown Message type: {0}", msgType);
                break;
            }
        }
예제 #4
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            ExampleModMessageType msgType = (ExampleModMessageType)reader.ReadByte();

            switch (msgType)
            {
            // This message sent by the server to initialize the Volcano Tremor on clients
            case ExampleModMessageType.SetTremorTime:
                int          tremorTime = reader.ReadInt32();
                ExampleWorld world      = (ExampleWorld)GetModWorld("ExampleWorld");
                world.VolcanoTremorTime = tremorTime;
                break;

            // This message sent by the server to initialize the Volcano Rubble.
            case ExampleModMessageType.VolcanicRubbleMultiplayerFix:
                int numberProjectiles = reader.ReadInt32();
                for (int i = 0; i < numberProjectiles; i++)
                {
                    int  identity = reader.ReadInt32();
                    bool found    = false;
                    for (int j = 0; j < 1000; j++)
                    {
                        if (Main.projectile[j].owner == 255 && Main.projectile[j].identity == identity && Main.projectile[j].active)
                        {
                            Main.projectile[j].hostile = true;
                            Main.projectile[j].name    = "Volcanic Rubble";
                            found = true;
                            break;
                        }
                    }
                    if (!found)
                    {
                        ErrorLogger.Log("Error: Projectile not found");
                    }
                }
                break;

            case ExampleModMessageType.SpawnNPC:
                NPC.NewNPC(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
                break;

            case ExampleModMessageType.PuritySpirit:
                PuritySpirit spirit = Main.npc[reader.ReadInt32()].modNPC as PuritySpirit;
                if (spirit != null && spirit.npc.active)
                {
                    spirit.HandlePacket(reader);
                }
                break;

            case ExampleModMessageType.HeroLives:
                Player player = Main.player[reader.ReadInt32()];
                int    lives  = reader.ReadInt32();
                player.GetModPlayer <ExamplePlayer>(this).heroLives = lives;
                if (lives > 0)
                {
                    string text = player.name + " has " + lives;
                    if (lives == 1)
                    {
                        text += " life left!";
                    }
                    else
                    {
                        text += " lives left!";
                    }
                    NetMessage.SendData(25, -1, -1, text, 255, 255, 25, 25);
                }
                break;

            default:
                ErrorLogger.Log("ExampleMod: Unknown Message type: " + msgType);
                break;
            }
        }