Наследование: Terraria.ModLoader.ModPlayer
Пример #1
0
        public override void SendClientChanges(ModPlayer clientPlayer)
        {
            // Here we would sync something like an RPG stat whenever the player changes it.
            ExamplePlayer clone = clientPlayer as ExamplePlayer;

            if (clone.nonStopParty != nonStopParty)
            {
                // Send a Mod Packet with the changes.
                var packet = mod.GetPacket();
                packet.Write((byte)ExampleModMessageType.NonStopPartyChanged);
                packet.Write((byte)player.whoAmI);
                packet.Write(nonStopParty);
                packet.Send();
            }
        }
Пример #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      = 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;
            }
        }
Пример #3
0
        public override void CopyCustomBiomesTo(Player other)
        {
            ExamplePlayer modOther = other.GetModPlayer <ExamplePlayer>();

            modOther.ZoneExample = ZoneExample;
        }
Пример #4
0
        public override bool CustomBiomesMatch(Player other)
        {
            ExamplePlayer modOther = other.GetModPlayer <ExamplePlayer>(mod);

            return(ZoneExample == modOther.ZoneExample);
        }
Пример #5
0
        public override void ResetNearbyTileEffects()
        {
            ExamplePlayer modPlayer = (ExamplePlayer)Main.player[Main.myPlayer].GetModPlayer(mod, "ExamplePlayer");

            modPlayer.voidMonolith = false;
        }