Example #1
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            EntrogicModMessageType msgType = (EntrogicModMessageType)reader.ReadByte();

            switch (msgType)
            {
            case EntrogicModMessageType.ReceiveMagicStormRequest:     // 由服务器通告全体客户端
            {
                EntrogicWorld.magicStorm = reader.ReadBoolean();
                break;
            }

            case EntrogicModMessageType.ReceiveMagicStormMPC: // 客户端发出接受请求,服务器发送参数
                if (Main.dedServ)                             // 在服务器下
                {
                    ModPacket packet = GetPacket();
                    packet.Write((byte)EntrogicModMessageType.ReceiveMagicStormMPC);
                    packet.Write(EntrogicWorld.magicStorm);
                    // 发回给发送者
                    packet.Send(whoAmI, -1);
                    break;
                }
                else     // 客户端下接收
                {
                    EntrogicWorld.magicStorm = reader.ReadBoolean();
                    if (EntrogicWorld.magicStorm == true /*规范!*/)    // 肯定是要开始了才提示啊,不然提示什么东西哦
                    {
                        Main.NewText("魔力开始涌动...", 150, 150, 250);    // 补一个提示
                    }
                    break;
                }

            case EntrogicModMessageType.FindUWTeleporter:
            {
                if (Main.dedServ)         // 在服务器下
                {
                    int i         = reader.ReadInt32();
                    int j         = reader.ReadInt32();
                    int playernum = reader.ReadInt32();
                    UnderworldPortal.HandleTransportion(i, j, playernum, true);
                    break;
                }
                else         // 在客户端下,其实就是给玩家回复提示信息
                {
                    string warn = reader.ReadString();
                    Main.NewText(warn);
                }
                break;
            }

            case EntrogicModMessageType.NPCSpawnOnPlayerAction:
            {
                int plr  = (int)reader.ReadByte();
                int type = (int)reader.ReadInt16();
                if (!NPC.AnyNPCs(type))
                {
                    NPC.SpawnOnPlayer(plr, type);
                }
                break;
            }

            case EntrogicModMessageType.NPCSpawn:
            {
                if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    break;
                }
                int   plr           = (int)reader.ReadByte();
                int   type          = (int)reader.ReadInt16();
                bool  showSpawnText = reader.ReadBoolean();
                float posx          = reader.ReadSingle();
                float posy          = reader.ReadSingle();
                Main.PlaySound(SoundID.Roar, Main.player[plr].Center, 0);
                int npc = NPC.NewNPC((int)posx, (int)posy, type, 1);
                if (npc == 200)
                {
                    break;
                }
                Main.npc[npc].target    = plr;
                Main.npc[npc].timeLeft *= 20;
                if (npc < 200)
                {
                    NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, npc);
                }
                if (showSpawnText == true)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", Main.npc[npc].GetTypeNetName()), new Color(175, 75, 255));
                }
                break;
            }

            case EntrogicModMessageType.SyncExplode:
            {
                if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    Explode(reader.ReadPackedVector2(), reader.ReadPackedVector2(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadBoolean());
                }
                else
                {
                    MessageHelper.SendExplode(reader.ReadPackedVector2(), reader.ReadPackedVector2(), reader.ReadInt32(), -1, whoAmI, reader.ReadInt32(), reader.ReadInt32(), reader.ReadBoolean());
                }
                break;
            }

            case EntrogicModMessageType.SyncCardGamingInfos:
            {
                int            playernumber   = reader.ReadByte();
                EntrogicPlayer entrogicPlayer = Main.player[playernumber].GetModPlayer <EntrogicPlayer>();
                // 如何传输List?首先传输一个List.Count,然后遍历传输List数值,接收者根据List.Count逐个接收,最后List.Add发给第三方
                //entrogicPlayer.IsBookActive = 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)EntrogicModMessageType.SyncBookBubbleInfo);
                //    packet.Write((byte)playernumber);
                //    packet.Write(entrogicPlayer.IsBookActive);
                //    packet.Send(-1, playernumber);
                //}
                break;
            }

            case EntrogicModMessageType.SyncBookBubbleInfo:
            {
                int            playernumber   = reader.ReadByte();
                EntrogicPlayer entrogicPlayer = Main.player[playernumber].GetModPlayer <EntrogicPlayer>();
                entrogicPlayer.PageNum      = reader.ReadByte();
                entrogicPlayer.IsBookActive = reader.ReadBoolean();
                // Unlike SyncPlayer, here we have to relay/forward these changes to all other connected clients
                if (Main.netMode == NetmodeID.Server)
                {
                    MessageHelper.SendBookInfo(playernumber, entrogicPlayer.PageNum, entrogicPlayer.IsBookActive, -1, playernumber);
                }
                break;
            }

            case EntrogicModMessageType.SendCompletedCardMerchantMissionRequest:
            {
                byte playernumber = reader.ReadByte();
                CardMerchantQuest cardMerchantQuest = Main.player[playernumber].GetModPlayer <CardMerchantQuest>();
                cardMerchantQuest.Complete = reader.ReadString();
                // Unlike SyncPlayer, here we have to relay/forward these changes to all other connected clients
                if (Main.netMode == NetmodeID.Server)
                {
                    MessageHelper.SendCardMission(playernumber, cardMerchantQuest.Complete, -1, playernumber);
                }
                break;
            }

            case EntrogicModMessageType.BuildBuilding:
            {
                string  name   = reader.ReadString();
                Vector2 pos    = reader.ReadPackedVector2();
                bool    useAir = reader.ReadBoolean();
                Buildings.Build(name, pos, useAir);
                break;
            }

            default:
                Logger.WarnFormat("Entrogic: Unknown Message type: {0}", msgType);
                break;
            }
        }
        public override void PreUpdate()
        {
            for (int n = 0; n < Main.maxNPCs; n++)
            {
                if (Main.npc[n].active && !bossList.Contains(Main.npc[n]) && !bossListPos.Contains(n) && (Main.npc[n].boss || Main.npc[n].type == 13))
                {
                    // Make sure these "bosses" are not counted
                    if (Main.npc[n].type != NPCID.MoonLordHand && Main.npc[n].type != NPCID.MoonLordCore && Main.npc[n].type != NPCID.MartianSaucerCore)
                    {
                        bossList.Add(Main.npc[n]);
                        bossListPos.Add(n);
                    }
                    // NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(Main.npc[n].FullName + " Added!"), Colors.RarityRed);
                }
            }

            for (int b = bossList.Count - 1; b >= 0; b--)
            {
                if (!Main.npc[bossListPos[b]].active)  // If boss is no longer active, check for despawn conditions and remove NPC from the list
                {
                    if ((Main.npc[bossListPos[b]].type != NPCID.MoonLordHead && Main.npc[bossListPos[b]].life >= 0) ||
                        (Main.npc[bossListPos[b]].type == NPCID.MoonLordHead && Main.npc[bossListPos[b]].life < 0))
                    {
                        if (Main.player.Any(playerCheck => playerCheck.active && !playerCheck.dead)) // If any player is active and alive
                        {
                            if (Main.dayTime && (bossList[b].type == 4 || bossList[b].type == 125 || bossList[b].type == 126 || bossList[b].type == 134))
                            {
                                // Bosses that despawn upon day time: EoC, Retinazar, Spazmatism, The Destroyer
                                key = "Mods.BossAssist.GenericBossSunCondition";
                            }
                            else if (bossList[b].type == NPCID.WallofFlesh)
                            {
                                key = "Mods.BossAssist.WallOfFleshWins";
                            }
                            else
                            {
                                key = "Mods.BossAssist.GenericBossLeft";
                            }
                        }
                        else
                        {
                            if (bossList[b].type == NPCID.KingSlime)
                            {
                                key = "Mods.BossAssist.KingSlimeWins";
                            }
                            else if (bossList[b].type == NPCID.EyeofCthulhu)
                            {
                                key = "Mods.BossAssist.EyeOfCthulhuWins";
                            }
                            else if (bossList[b].type == NPCID.EaterofWorldsHead)
                            {
                                key = "Mods.BossAssist.EaterOfWorldsWins";
                            }
                            else if (bossList[b].type == NPCID.BrainofCthulhu)
                            {
                                key = "Mods.BossAssist.BrainOfCthulhuWins";
                            }
                            else if (bossList[b].type == NPCID.QueenBee)
                            {
                                key = "Mods.BossAssist.QueenBeeWins";
                            }
                            else if (bossList[b].type == NPCID.SkeletronHead)
                            {
                                key = "Mods.BossAssist.SkeletronWins";
                            }
                            else if (bossList[b].type == NPCID.WallofFlesh)
                            {
                                key = "Mods.BossAssist.WallOfFleshWins";
                            }
                            else if (bossList[b].type == NPCID.Retinazer)
                            {
                                key = "Mods.BossAssist.RetinazerWins";
                            }
                            else if (bossList[b].type == NPCID.Spazmatism)
                            {
                                key = "Mods.BossAssist.SpazmatismWins";
                            }
                            else if (bossList[b].type == NPCID.TheDestroyer)
                            {
                                key = "Mods.BossAssist.TheDestroyerWins";
                            }
                            else if (bossList[b].type == NPCID.SkeletronPrime)
                            {
                                key = "Mods.BossAssist.SkeletronPrimeWins";
                            }
                            else if (bossList[b].type == NPCID.Plantera)
                            {
                                key = "Mods.BossAssist.PlanteraWins";
                            }
                            else if (bossList[b].type == NPCID.Golem)
                            {
                                key = "Mods.BossAssist.GolemWins";
                            }
                            else if (bossList[b].type == NPCID.DukeFishron)
                            {
                                key = "Mods.BossAssist.DukeFishronWins";
                            }
                            else if (bossList[b].type == NPCID.CultistBoss)
                            {
                                key = "Mods.BossAssist.LunaticCultistWins";
                            }
                            else if (bossList[b].type == NPCID.MoonLordHead)
                            {
                                key = "Mods.BossAssist.MoonLordWins";
                            }
                            else
                            {
                                for (int i = 0; i < ModBossTypes.Count; i++)
                                {
                                    if (bossList[b].type == ModBossTypes[i])
                                    {
                                        // Main.NewText("Modded Boss Detected!");
                                        key             = ModBossMessages[i];
                                        ModBossDetected = true;
                                        break;
                                    }
                                    else
                                    {
                                        // Main.NewText("Checked all instances inside ModBossTypes, but none were found");
                                        key = "Mods.BossAssist.GenericBossWins";
                                    }
                                }
                            }
                        }
                        if (Main.netMode == 0)
                        {
                            if (ModBossDetected)
                            {
                                ModBossDetected = false;
                                Main.NewText(string.Format(bossList[b].GetFullNetName().ToString() + key), Colors.RarityPurple);
                            }
                            else
                            {
                                Main.NewText(string.Format(Language.GetTextValue(key), bossList[b].GetFullNetName().ToString()), Colors.RarityPurple);
                            }
                        }
                        else
                        {
                            if (ModBossDetected)
                            {
                                ModBossDetected = false;
                                NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(bossList[b].GetFullNetName() + key), Colors.RarityPurple);
                            }
                            else
                            {
                                NetMessage.BroadcastChatMessage(NetworkText.FromKey(key, bossList[b].FullName), Colors.RarityPurple);
                            }
                        }
                    }
                    bossList.RemoveAt(b);
                    bossListPos.RemoveAt(b);
                    // NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(bossList[b].FullName + " Removed!"), Colors.RarityRed);
                }
            }
        }
Example #3
0
        public override void NPCLoot(NPC npc)
        {
            if ((npc.type == NPCID.DD2DarkMageT1 || npc.type == NPCID.DD2DarkMageT3) && !WorldAssist.downedDarkMage)
            {
                WorldAssist.downedDarkMage = true;
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.WorldData);
                }
            }
            if ((npc.type == NPCID.DD2OgreT2 || npc.type == NPCID.DD2OgreT3) && !WorldAssist.downedOgre)
            {
                WorldAssist.downedOgre = true;
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.WorldData);
                }
            }
            if (npc.type == NPCID.PirateShip && !WorldAssist.downedFlyingDutchman)
            {
                WorldAssist.downedFlyingDutchman = true;
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.WorldData);
                }
            }
            if (npc.type == NPCID.MartianSaucerCore && !WorldAssist.downedMartianSaucer)
            {
                WorldAssist.downedMartianSaucer = true;
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.WorldData);
                }
            }
            if (!Main.dedServ && Main.gameMenu)
            {
                return;
            }
            string partName = npc.GetFullNetName().ToString();

            if (BossChecklist.ClientConfig.PillarMessages)
            {
                if (npc.type == NPCID.LunarTowerSolar || npc.type == NPCID.LunarTowerVortex || npc.type == NPCID.LunarTowerNebula || npc.type == NPCID.LunarTowerStardust)
                {
                    if (Main.netMode == 0)
                    {
                        Main.NewText(Language.GetTextValue("Mods.BossChecklist.BossDefeated.Tower", npc.GetFullNetName().ToString()), Colors.RarityPurple);
                    }
                    else
                    {
                        NetMessage.BroadcastChatMessage(NetworkText.FromKey("Mods.BossChecklist.BossDefeated.Tower", npc.GetFullNetName().ToString()), Colors.RarityPurple);
                    }
                }
            }
            if (NPCisLimb(npc) && BossChecklist.ClientConfig.LimbMessages)
            {
                if (npc.type == NPCID.SkeletronHand)
                {
                    partName = "Skeletron Hand";
                }
                if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    Main.NewText(Language.GetTextValue("Mods.BossChecklist.BossDefeated.Limb", partName), Colors.RarityGreen);
                }
                else
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromKey("Mods.BossChecklist.BossDefeated.Limb", partName), Colors.RarityGreen);
                }
            }

            // Setting a record for fastest boss kill, and counting boss kills
            // Twins check makes sure the other is not around before counting towards the record
            int index = ListedBossNum(npc);

            if (index != -1)
            {
                if (!BossChecklist.DebugConfig.NewRecordsDisabled && !BossChecklist.DebugConfig.RecordTrackingDisabled && TruelyDead(npc))
                {
                    if (Main.netMode == NetmodeID.SinglePlayer)
                    {
                        CheckRecords(npc, index);
                    }
                    else if (Main.netMode == NetmodeID.Server)
                    {
                        CheckRecordsMultiplayer(npc, index);
                    }
                }
                if (BossChecklist.DebugConfig.ShowTDC)
                {
                    Main.NewText(npc.FullName + ": " + TruelyDead(npc));
                }
            }
        }
Example #4
0
        public override void PostUpdate()
        {
            Player player = Main.player[Main.myPlayer];

            int playerCoinAmount = 0;

            foreach (Item i in player.inventory)
            {
                switch (i.type)
                {
                case ItemID.CopperCoin:
                    playerCoinAmount += 1 * i.stack;
                    break;

                case ItemID.SilverCoin:
                    playerCoinAmount += 100 * i.stack;
                    break;

                case ItemID.GoldCoin:
                    playerCoinAmount += 10000 * i.stack;
                    break;

                case ItemID.PlatinumCoin:
                    playerCoinAmount += 1000000 * i.stack;
                    break;
                }
            }

            bool anyPlayerHasCelestialBeacon = false;

            for (int i = 0; i < 255; i++)
            {
                if (Main.player[i].active)
                {
                    if (Main.player[i].HasItem(mod.ItemType("Celestial_Beacon")))
                    {
                        anyPlayerHasCelestialBeacon = true;
                    }
                }
            }

            if (NPC.MoonLordCountdown > 1 && anyPlayerHasCelestialBeacon)
            {
                NPC.MoonLordCountdown = 1;
            }

            if (Main.time % 600 == 0 && !NPC.downedMoonlord)
            {
                for (int i = 0; i < Main.npc.Length; i++)
                {
                    if (Main.npc[i].type == NPCID.MoonLordCore && !anyPlayerHasCelestialBeacon)
                    {
                        Main.player[(int)Player.FindClosest(Main.npc[i].position, Main.npc[i].width, Main.npc[i].height)].QuickSpawnItem(mod.ItemType("Celestial_Beacon"));
                        break;
                    }
                }
            }

            if (advanceMoonPhase)
            {
                advanceMoonPhase = false;
                Main.moonPhase++;
                if (Main.moonPhase >= 8)
                {
                    Main.moonPhase = 0;
                }
                if (Main.netMode == NetmodeID.Server)
                {
                    var netMessage = mod.GetPacket();
                    netMessage.Write((byte)ReducedGrindingMessageType.advanceMoonPhase);
                    netMessage.Write(ReducedGrindingWorld.advanceMoonPhase);
                    netMessage.Send();

                    NetMessage.SendData(7);
                }
            }

            if (skipToNight)
            {
                if (Main.sundialCooldown > 0)
                {
                    ReducedGrindingWorld.skippedToDayOrNight = true;
                }
                Main.time   = 54000;
                skipToDay   = false;
                skipToNight = false;
                //Force Traveling Merchant despawn in order to prevent exploiting.
                int travelingMerchantTarget = -1;
                for (int i = 0; i < 200; i++)
                {
                    if (Main.npc[i].active && Main.npc[i].type == NPCID.TravellingMerchant)
                    {
                        travelingMerchantTarget = i;
                        break;
                    }
                }
                if (travelingMerchantTarget > -1)
                {
                    string fullName = Main.npc[travelingMerchantTarget].FullName;
                    if (Main.netMode == NetmodeID.SinglePlayer)                    //0)
                    {
                        Main.NewText(Lang.misc[35].Format(fullName), 50, 125);
                    }
                    else if (Main.netMode == NetmodeID.Server)                    //2)
                    {
                        NetMessage.BroadcastChatMessage(NetworkText.FromKey(Lang.misc[35].Key, Main.npc[travelingMerchantTarget].GetFullNetName()), new Color(50, 125, 255));
                    }
                    Main.npc[travelingMerchantTarget].active  = false;
                    Main.npc[travelingMerchantTarget].netSkip = -1;
                    Main.npc[travelingMerchantTarget].life    = 0;
                    NetMessage.SendData(23, -1, -1, null, travelingMerchantTarget);
                }
                if (Main.netMode == NetmodeID.Server)                 //Server
                {
                    var netMessage = mod.GetPacket();
                    netMessage.Write((byte)ReducedGrindingMessageType.skipToNight);
                    netMessage.Write(ReducedGrindingWorld.skipToNight);

                    netMessage.Write((byte)ReducedGrindingMessageType.skipToDay);
                    netMessage.Write(ReducedGrindingWorld.skipToDay);
                    netMessage.Send();

                    NetMessage.SendData(7);
                }
            }

            if (skipToDay)
            {
                if (Main.sundialCooldown > 0)
                {
                    ReducedGrindingWorld.skippedToDayOrNight = true;
                }
                Main.time   = 32400;
                skipToDay   = false;
                skipToNight = false;
                if (Main.netMode == NetmodeID.Server)
                {
                    var netMessage = mod.GetPacket();
                    netMessage.Write((byte)ReducedGrindingMessageType.skipToNight);
                    netMessage.Write(ReducedGrindingWorld.skipToNight);

                    netMessage.Write((byte)ReducedGrindingMessageType.skipToDay);
                    netMessage.Write(ReducedGrindingWorld.skipToDay);
                    netMessage.Send();

                    NetMessage.SendData(7);
                }
            }

            if (Main.dayTime && skippedToDayOrNight)
            {
                Main.sundialCooldown++;
                skippedToDayOrNight = false;
            }

            //There are 21 stationary vanilla NPCs (excluding Guide and Santa) as of 5/26/2017; 15 Pre-Hardmode and 6 Hardmode.
            float TownNPCs                    = 0f;
            float TownNPCsMax                 = 15f;
            float TownHardmodeNPCs            = 0f;
            float TownHardmodeNPCsMax         = 6f;
            bool  travelingMerchantExists     = false;
            bool  stationaryMerchantExists    = false;
            bool  tryToSpawnTravelingMerchant = true;

            Mod luiafk = ModLoader.GetMod("Luiafk");

            if (GetInstance <IOtherCustomNPCsConfig>().BoneMerchant&& !(luiafk != null && GetInstance <IOtherCustomNPCsConfig>().BoneMerchantDisabledWhenLuiafkIsInstalled))
            {
                TownNPCsMax++;
            }
            if (GetInstance <IOtherCustomNPCsConfig>().ChestSalesman)
            {
                TownNPCsMax++;
            }
            if (GetInstance <ETravelingAndStationaryMerchantConfig>().StationaryMerchant)
            {
                TownNPCsMax++;
            }
            if (GetInstance <IOtherCustomNPCsConfig>().LootMerchant)
            {
                TownNPCsMax++;
            }
            if (GetInstance <IOtherCustomNPCsConfig>().ChristmasElf)
            {
                TownHardmodeNPCsMax++;
            }

            for (int i = 0; i < Terraria.Main.npc.Length; i++)             //Do once for each NPC in the world
            {
                if (Terraria.Main.npc[i].townNPC == true)
                {
                    if (Terraria.Main.npc[i].type == NPCID.TravellingMerchant)
                    {
                        travelingMerchantExists     = true;
                        tryToSpawnTravelingMerchant = false;
                    }
                    if (Terraria.Main.npc[i].type == mod.NPCType("StationaryMerchant"))
                    {
                        stationaryMerchantExists = true;
                    }
                    if (
                        Terraria.Main.npc[i].type == NPCID.Merchant ||
                        Terraria.Main.npc[i].type == NPCID.Nurse ||
                        Terraria.Main.npc[i].type == NPCID.Demolitionist ||
                        Terraria.Main.npc[i].type == NPCID.DyeTrader ||
                        Terraria.Main.npc[i].type == NPCID.Dryad ||
                        Terraria.Main.npc[i].type == NPCID.DD2Bartender ||
                        Terraria.Main.npc[i].type == NPCID.ArmsDealer ||
                        Terraria.Main.npc[i].type == NPCID.Stylist ||
                        Terraria.Main.npc[i].type == NPCID.Painter ||
                        Terraria.Main.npc[i].type == NPCID.Angler ||
                        Terraria.Main.npc[i].type == NPCID.GoblinTinkerer ||
                        Terraria.Main.npc[i].type == NPCID.WitchDoctor ||
                        Terraria.Main.npc[i].type == NPCID.Clothier ||
                        Terraria.Main.npc[i].type == NPCID.Mechanic ||
                        Terraria.Main.npc[i].type == NPCID.PartyGirl ||
                        (Terraria.Main.npc[i].type == mod.NPCType("BoneMerchant") && GetInstance <IOtherCustomNPCsConfig>().BoneMerchant) ||
                        (Terraria.Main.npc[i].type == mod.NPCType("ChestSalesman") && GetInstance <IOtherCustomNPCsConfig>().ChestSalesman) ||
                        (Terraria.Main.npc[i].type == mod.NPCType("StationaryMerchant") && GetInstance <ETravelingAndStationaryMerchantConfig>().StationaryMerchant) ||
                        (Terraria.Main.npc[i].type == mod.NPCType("LootMerchant") && GetInstance <IOtherCustomNPCsConfig>().LootMerchant)
                        )
                    {
                        TownNPCs++;
                    }
                    else if (
                        Terraria.Main.npc[i].type == NPCID.Wizard ||
                        Terraria.Main.npc[i].type == NPCID.TaxCollector ||
                        Terraria.Main.npc[i].type == NPCID.Truffle ||
                        Terraria.Main.npc[i].type == NPCID.Pirate ||
                        Terraria.Main.npc[i].type == NPCID.Steampunker ||
                        Terraria.Main.npc[i].type == NPCID.Cyborg ||
                        (Terraria.Main.npc[i].type == mod.NPCType("Christmas Elf") && GetInstance <IOtherCustomNPCsConfig>().ChristmasElf)
                        )
                    {
                        TownHardmodeNPCs++;
                    }
                }
            }

            float TownNPCPercent = (TownNPCs / TownNPCsMax + TownHardmodeNPCs / TownHardmodeNPCsMax) / 2;

            if (!Main.fastForwardTime && Main.dayTime && Main.time < 27000.0)
            {
                int alltownNPCs = 0;
                for (int j = 0; j < 200; j++)
                {
                    if (Main.npc[j].active && Main.npc[j].townNPC && Main.npc[j].type != 37 && Main.npc[j].type != 453)
                    {
                        alltownNPCs++;
                    }
                }
                if (alltownNPCs >= 2)
                {
                    if (tryToSpawnTravelingMerchant)
                    {
                        tryToSpawnTravelingMerchant = false;
                        if (!Main.fastForwardTime && Main.dayTime && Main.time < 27000.0)
                        {
                            int chanceRoll = (int)(27000.0 / (double)Main.dayRate);
                            chanceRoll *= 4;
                            for (int i = 0; i < 3; i++)
                            {
                                if (Main.rand.Next(chanceRoll) == 0)
                                {
                                    tryToSpawnTravelingMerchant = true;
                                    break;
                                }
                            }
                        }
                    }
                    if (tryToSpawnTravelingMerchant && Main.rand.NextFloat() < GetInstance <ETravelingAndStationaryMerchantConfig>().BaseMorningTMerchantSpawnChance *Math.Pow(TownNPCPercent, 2))
                    {
                        WorldGen.SpawnTravelNPC();
                    }
                }
            }
        }
Example #5
0
        private void Swarm(NPC npc, int boss, int minion, int bossbag, string reward)
        {
            int count = 0;

            if (swarmActive)
            {
                count = NPC.CountNPCS(boss) - 1; //since this one is about to be dead
            }
            else //pandora
            {
                for (int i = 0; i < 200; i++)
                {
                    if (Main.npc[i].active && Array.IndexOf(bosses, Main.npc[i].type) > -1)
                    {
                        count++;
                    }
                }
            }

            int missing = Fargowiltas.swarmSpawned - count;

            Fargowiltas.swarmKills++;

            //drop swarm reward every 100 kills
            if (Fargowiltas.swarmKills % 100 == 0 && reward != "")
            {
                Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, mod.ItemType(reward));
            }

            if (Main.netMode == 2)
            {
                NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Killed: " + Fargowiltas.swarmKills), new Color(206, 12, 15));
                NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Total: " + Fargowiltas.swarmTotal), new Color(206, 12, 15));
            }
            else
            {
                Main.NewText("Killed: " + Fargowiltas.swarmKills, 206, 12, 15);
                Main.NewText("Total: " + Fargowiltas.swarmTotal, 206, 12, 15);
            }

            if (minion != -1 && NPC.CountNPCS(minion) >= Fargowiltas.swarmSpawned)
            {
                for (int i = 0; i < 200; i++)
                {
                    if (Main.npc[i].active && Main.npc[i].type == minion)
                    {
                        Main.npc[i].StrikeNPCNoInteraction(Main.npc[i].lifeMax, 0f, -Main.npc[i].direction, true);
                    }
                }
            }

            //if theres still more to spawn
            if (Fargowiltas.swarmKills <= Fargowiltas.swarmTotal - Fargowiltas.swarmSpawned)
            {
                int spawned = 0;

                for (int i = 0; i < 200; i++)
                {
                    //count npcs
                    int num = 0;
                    for (int j = 0; j < 200; j++)
                    {
                        if (Main.npc[j].active)
                        {
                            num++;
                        }
                    }
                    //kill a minion and spawn boss if too many npcs
                    if (num >= 200)
                    {
                        if (swarmActive && minion > 0 && i < 199)
                        {
                            if (Main.npc[i].type == minion)
                            {
                                Main.npc[i].StrikeNPCNoInteraction(Main.npc[i].lifeMax, 0f, -Main.npc[i].direction, true);
                            }
                        }
                        else //pandora
                        {
                            if (Array.IndexOf(bosses, Main.npc[i].type) == -1 && !Main.npc[i].boss)
                            {
                                Main.npc[i].StrikeNPCNoInteraction(Main.npc[i].lifeMax, 0f, -Main.npc[i].direction, true);
                            }
                        }
                    }

                    SpawnBoss(npc, boss);
                    spawned++;

                    if (spawned <= missing)
                    {
                        continue;
                    }

                    break;
                }
            }
            //swarm over
            else if (Fargowiltas.swarmKills >= Fargowiltas.swarmTotal)
            {
                if (Main.netMode == 2)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("The swarm has been defeated!"), new Color(206, 12, 15));
                }
                else
                {
                    Main.NewText("The swarm has been defeated!", 206, 12, 15);
                }

                for (int i = 0; i < 200; i++)
                {
                    NPC kill = Main.npc[i];
                    if (kill.active && !kill.friendly && kill.type != NPCID.LunarTowerNebula && kill.type != NPCID.LunarTowerSolar && kill.type != NPCID.LunarTowerStardust && kill.type != NPCID.LunarTowerVortex)
                    {
                        Main.npc[i].GetGlobalNPC <FargoGlobalNPC>().noLoot = true;
                        Main.npc[i].StrikeNPCNoInteraction(Main.npc[i].lifeMax, 0f, -Main.npc[i].direction, true);
                    }
                }

                if (bossbag >= 0)
                {
                    npc.DropItemInstanced(npc.Center, npc.Size, bossbag, Fargowiltas.swarmTotal);
                }

                Fargowiltas.swarmActive = false;
            }
            //make sure theres enough left to beat it
            else
            {
                //spawn more if needed
                if (count >= Fargowiltas.swarmSpawned || Fargowiltas.swarmTotal <= 20)
                {
                    return;
                }

                int extraSpawn = 0;

                for (int i = 0; i < 200; i++)
                {
                    //count npcs
                    int num = 0;
                    for (int j = 0; j < 200; j++)
                    {
                        if (Main.npc[j].active)
                        {
                            num++;
                        }
                    }
                    //kill a minion and spawn boss if too many npcs
                    if (num >= 200)
                    {
                        if (swarmActive && minion > 0 && i < 199)
                        {
                            if (Main.npc[i].type == minion)
                            {
                                Main.npc[i].StrikeNPCNoInteraction(Main.npc[i].lifeMax, 0f, -Main.npc[i].direction, true);
                            }
                        }
                        else //pandora
                        {
                            if (Array.IndexOf(bosses, Main.npc[i].type) == -1 && !Main.npc[i].boss)
                            {
                                Main.npc[i].StrikeNPCNoInteraction(Main.npc[i].lifeMax, 0f, -Main.npc[i].direction, true);
                            }
                        }
                    }

                    SpawnBoss(npc, boss);
                    extraSpawn++;

                    if (extraSpawn < 5)
                    {
                        continue;
                    }

                    break;
                }
            }
        }
Example #6
0
        public override void PreUpdate()
        {
            Color textColor = Color.Yellow;

            //  ITEM TEXT and SKY FORT DEBUG GEN
            if (!start && !Main.dedServ && KeyPress(Keys.F1) && KeyHold(Keys.Up))
            {
                if (Main.netMode == 0)
                {
                    Main.NewText("To enter commands, input [Tab + (Hold) Left Control] (instead of Enter), [F2 + LeftControl] for item spawning using chat search via item name, [F3 + LeftControl] for NPC debug and balancing", Color.LightBlue);
                    Main.NewText("Commands: /list 'npcs' 'items1' 'items2' 'items3', /npc [name], /npc 'strike', /item [name], /spawn, /day, /night, /rain 'off' 'on', hold [Left Control + Left Alt] and click to go to mouse", textColor);
                }
                if (Main.netMode == 2)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Input /info and use [Tab] to list commands"), textColor);
                }
                start = true;
            }
            if (KeyHold(Keys.LeftAlt))
            {
                if (KeyPress(Keys.LeftControl))
                {
                    //SkyHall hall = new SkyHall();
                    //hall.SkyFortGen();

                    /*
                     * Vector2 position;
                     * do
                     * {
                     *  position = new Vector2(WorldGen.genRand.Next(200, Main.maxTilesX - 200), 50);
                     * } while (position.X < Main.spawnTileX + 150 && position.X > Main.spawnTileX - 150);
                     * var s = new Structures(position, ArchaeaWorld.skyBrick, ArchaeaWorld.skyBrickWall);
                     * s.InitializeFort();
                     */
                    if (Main.netMode == 0)
                    {
                        for (int i = 0; i < Main.rightWorld / 16; i++)
                        {
                            for (int j = 0; j < Main.bottomWorld / 16; j++)
                            {
                                Main.mapInit    = true;
                                Main.loadMap    = true;
                                Main.refreshMap = true;
                                Main.updateMap  = true;
                                Main.Map.Update(i, j, 255);
                                Main.Map.ConsumeUpdate(i, j);
                            }
                        }
                    }
                }
            }
            if (KeyHold(Keys.LeftControl) && KeyHold(Keys.LeftAlt) && LeftClick())
            {
                if (Main.netMode == 2)
                {
                    NetHandler.Send(Packet.TeleportPlayer, -1, -1, player.whoAmI, Main.MouseWorld.X, Main.MouseWorld.Y);
                }
                else
                {
                    player.Teleport(Main.MouseWorld);
                }
            }
            string chat           = (string)Main.chatText.Clone();
            bool   enteredCommand = KeyPress(Keys.Tab);

            if (chat.StartsWith("/info") && KeyHold(Keys.LeftControl))
            {
                if (enteredCommand)
                {
                    if (Main.netMode != 2)
                    {
                        Main.NewText("Commands: /list 'npcs' 'items1' 'items2' 'items3', /npc [name], /npc 'strike', /item [name], /spawn, /day, /night, /rain 'off' 'on', hold Left Control and click to go to mouse", textColor);
                        Main.NewText("Press [F2] and type an item name in chat, then hover over item icon", textColor);
                        Main.NewText("[F3] for NPC debug and balancing", textColor);
                    }
                }
            }
            if (chat.StartsWith("/") && KeyHold(Keys.LeftControl))
            {
                if (chat.StartsWith("/list"))
                {
                    string[] npcs = new string[]
                    {
                        "Fanatic",
                        "Hatchling_head",
                        "Mimic",
                        "Sky_1",
                        "Sky_2",
                        "Sky_3",
                        "Slime_Itchy",
                        "Slime_Mercurial",
                        "Magnoliac_head",
                        "Sky_boss",
                        "Sky_boss_legacy"
                    };
                    string[] items1 = new string[]
                    {
                        "cinnabar_bow",
                        "cinnabar_dagger",
                        "cinnabar_hamaxe",
                        "cinnabar_pickaxe",
                        "magno_Book",
                        "magno_summonstaff",
                        "magno_treasurebag",
                        "magno_trophy",
                        "magno_yoyo"
                    };
                    string[] items2 = new string[]
                    {
                        "c_Staff",
                        "c_Sword",
                        "n_Staff",
                        "r_Catcher",
                        "r_Flail",
                        "r_Javelin",
                        "r_Tomohawk",
                        "ShockLegs",
                        "ShockMask",
                        "ShockPlate"
                    };
                    string[] items3 = new string[]
                    {
                        "Broadsword",
                        "Calling",
                        "Deflector",
                        "Sabre",
                        "Staff"
                    };
                    if (chat.Contains("npcs"))
                    {
                        if (enteredCommand)
                        {
                            foreach (string s in npcs)
                            {
                                Main.NewText(s + " " + mod.NPCType(s), textColor);
                            }
                        }
                    }
                    if (chat.Contains("items1"))
                    {
                        if (enteredCommand)
                        {
                            foreach (string s in items1)
                            {
                                Main.NewText(s, textColor);
                            }
                        }
                    }
                    if (chat.Contains("items2"))
                    {
                        if (enteredCommand)
                        {
                            foreach (string s in items2)
                            {
                                Main.NewText(s, textColor);
                            }
                        }
                    }
                    if (chat.Contains("items3"))
                    {
                        if (enteredCommand)
                        {
                            foreach (string s in items3)
                            {
                                Main.NewText(s, textColor);
                            }
                        }
                    }
                }
                if (chat.StartsWith("/npc"))
                {
                    string text = Main.chatText.Substring(Main.chatText.IndexOf(' ') + 1);
                    if (!chat.Contains("strike"))
                    {
                        if (enteredCommand)
                        {
                            NPC n = mod.GetNPC(text).npc;
                            if (Main.netMode != 0)
                            {
                                NetHandler.Send(Packet.SpawnNPC, 256, -1, n.type, Main.MouseWorld.X, Main.MouseWorld.Y, player.whoAmI, n.boss);
                            }
                            else
                            {
                                if (n.boss)
                                {
                                    NPC.SpawnOnPlayer(player.whoAmI, n.type);
                                }
                                else
                                {
                                    NPC.NewNPC((int)Main.MouseWorld.X, (int)Main.MouseWorld.Y, n.type);
                                }
                            }
                        }
                    }
                    else
                    {
                        if (enteredCommand)
                        {
                            foreach (NPC npc in Main.npc)
                            {
                                if (npc.active && !npc.friendly && npc.life > 0)
                                {
                                    npc.StrikeNPC(npc.lifeMax, 0f, 1, true);
                                    if (Main.netMode != 0)
                                    {
                                        NetMessage.SendData(MessageID.StrikeNPC, -1, -1, null, npc.whoAmI);
                                    }
                                }
                            }
                        }
                    }
                }
                if (chat.StartsWith("/item"))
                {
                    string text = Main.chatText;
                    if (enteredCommand)
                    {
                        string itemType   = text.Substring("/item ".Length);
                        string stackCount = "";
                        if (itemType.Count(t => t == ' ') != 0)
                        {
                            stackCount = itemType.Substring(text.LastIndexOf(' ') + 1);
                        }
                        bool modded = false;
                        int  type;
                        int  stack = 0;
                        int.TryParse(stackCount, out stack);
                        if (modded = !int.TryParse(itemType, out type))
                        {
                            type = mod.ItemType(itemType);
                        }
                        if (modded)
                        {
                            int t = Item.NewItem(Main.MouseWorld, type, mod.GetItem(itemType).item.maxStack);
                            if (Main.netMode != 0)
                            {
                                NetMessage.SendData(MessageID.SyncItem, -1, -1, null, t);
                            }
                        }
                        else
                        {
                            int.TryParse(stackCount, out stack);
                            int t2 = Item.NewItem(Main.MouseWorld, type, stack == 0 ? 1 : stack);
                            if (Main.netMode != 0)
                            {
                                NetMessage.SendData(MessageID.SyncItem, -1, -1, null, t2);
                            }
                        }
                    }
                }
                if (chat.StartsWith("/spawn"))
                {
                    if (enteredCommand)
                    {
                        if (Main.netMode != 0)
                        {
                            NetHandler.Send(Packet.TeleportPlayer, 256, -1, Main.LocalPlayer.whoAmI, Main.spawnTileX * 16, Main.spawnTileY * 16);
                        }
                        else
                        {
                            player.Teleport(new Vector2(Main.spawnTileX * 16, Main.spawnTileY * 16));
                        }
                    }
                }
                if (chat.StartsWith("/day"))
                {
                    if (enteredCommand)
                    {
                        float time = 10f * 60f * 60f / 2f;
                        if (Main.netMode == 0)
                        {
                            Main.dayTime = true;
                            Main.time    = time;
                        }
                        else
                        {
                            NetHandler.Send(Packet.WorldTime, 256, -1, 0, time, 0f, 0, true);
                        }
                    }
                }
                if (chat.StartsWith("/night"))
                {
                    if (enteredCommand)
                    {
                        float time = 8f * 60f * 60f / 2f;
                        if (Main.netMode == 0)
                        {
                            Main.dayTime = false;
                            Main.time    = time;
                        }
                        else
                        {
                            NetHandler.Send(Packet.WorldTime, 256, -1, 0, time, 0f, 0, false);
                        }
                    }
                }
                if (chat.StartsWith("/rain"))
                {
                    if (chat.Contains("off"))
                    {
                        if (enteredCommand)
                        {
                            Main.raining = false;
                        }
                    }
                    if (chat.Contains("on"))
                    {
                        if (enteredCommand)
                        {
                            Main.raining = true;
                        }
                    }
                }
            }
            if (enteredCommand)
            {
                Main.chatText          = string.Empty;
                Main.drawingPlayerChat = false;
                Main.chatRelease       = false;
            }
            if (KeyPress(Keys.F2) && KeyHold(Keys.LeftControl))
            {
                if (Main.netMode == 1)
                {
                    NetHandler.Send(Packet.Debug, 256, -1, player.whoAmI);
                }
                else
                {
                    debugMenu = !debugMenu;
                }
            }
            if (KeyPress(Keys.F3) && KeyHold(Keys.LeftControl))
            {
                if (Main.netMode == 1)
                {
                    NetHandler.Send(Packet.Debug, 256, -1, player.whoAmI, 1f);
                }
                else
                {
                    spawnMenu = !spawnMenu;
                }
            }
        }
Example #7
0
        public override bool UseItem(Player player)
        {
            Fargowiltas.SwarmActive = true;
            Fargowiltas.SwarmTotal  = 10 * player.inventory[player.selectedItem].stack;
            Fargowiltas.SwarmKills  = 0;

            if (Fargowiltas.SwarmTotal < 100)
            {
                Fargowiltas.SwarmSpawned = 10;
            }
            else
            {
                //energizer swarms
                Fargowiltas.SwarmSpawned = maxSpawn;
            }

            //DG special case
            if (npcType == NPCID.SkeletronHead && Main.dayTime)
            {
                npcType = NPCID.DungeonGuardian;
            }
            //twins special case
            else if (npcType == NPCID.Retinazer)
            {
                Fargowiltas.SwarmTotal *= 2;
            }

            //wof mega special case
            if (npcType == NPCID.WallofFlesh)
            {
                FargoGlobalNPC.SpawnWalls(player);
                counter++;

                if (counter < 10)
                {
                    return(true);
                }
            }
            else
            {
                //spawn the bosses
                for (int i = 0; i < Fargowiltas.SwarmSpawned; i++)
                {
                    int boss = NPC.NewNPC((int)player.position.X + Main.rand.Next(-1000, 1000), (int)player.position.Y + Main.rand.Next(-1000, -400), npcType);
                    Main.npc[boss].GetGlobalNPC <FargoGlobalNPC>().SwarmActive = true;

                    //spawn the other twin as well
                    if (npcType == NPCID.Retinazer)
                    {
                        int twin = NPC.NewNPC((int)player.position.X + Main.rand.Next(-1000, 1000), (int)player.position.Y + Main.rand.Next(-1000, -400), NPCID.Spazmatism);
                        Main.npc[twin].GetGlobalNPC <FargoGlobalNPC>().SwarmActive = true;
                    }
                    else if (npcType == NPCID.TheDestroyer)
                    {
                        //Main.npc[boss].GetGlobalNPC<FargoGlobalNPC>().DestroyerSwarm = true;
                    }
                }
            }

            // Kill whole stack
            player.inventory[player.selectedItem].stack = 0;

            if (Main.netMode == NetmodeID.Server)
            {
                NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(spawnMessage), new Color(175, 75, 255));
                NetMessage.SendData(MessageID.WorldData);
            }
            else if (Main.netMode == NetmodeID.SinglePlayer)
            {
                Main.NewText(spawnMessage, 175, 75, 255);
            }

            Main.PlaySound(15, (int)player.position.X, (int)player.position.Y, 0);
            return(true);
        }
 public override void GameMessageReceivedHandler(object sender, TerrariaChatEventArgs e)
 {
     NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(e.Message + " - TestChatClient"), Color.Cyan, -1);
 }
Example #9
0
 public override void PostUpdate()
 {
     if (!Main.dayTime)
     {
         if (_oldIsDay && Main.netMode != NetmodeID.MultiplayerClient)
         {
             if (Main.netMode != NetmodeID.MultiplayerClient && Main.rand.NextBool(15) && NPC.downedBoss1)
             {
                 ActiveMagicStorm();
             }
         }
         if (Main.netMode != NetmodeID.Server)
         {
             CustomSky customSky = SkyManager.Instance["Entrogic:MagicStormScreen"];
             if (magicStorm)
             {
                 if (!customSky.IsActive())
                 {
                     SkyManager.Instance.Activate("Entrogic:MagicStormScreen", default(Vector2), new object[]
                     {
                         true
                     });
                 }
             }
             else if (customSky.IsActive())
             {
                 SkyManager.Instance.Deactivate("Entrogic:MagicStormScreen", new object[]
                 {
                     default(Vector2),
                     true
                 });
             }
         }
         int mimicrySpawnRate = 962;
         if (Main.netMode != NetmodeID.MultiplayerClient && magicStorm)
         {
             mimicrySpawnRate = 565;
         }
         if (Main.hardMode)
         {
             mimicrySpawnRate -= 182;
         }
         if (Main.rand.NextBool(mimicrySpawnRate) && Main.netMode != NetmodeID.MultiplayerClient)
         {
             foreach (Player player in Main.player)
             {
                 if (player.ZoneOverworldHeight && player.active && !player.dead)
                 {
                     Point rand       = new Point(Main.rand.Next(-80, 81), Main.rand.Next(-60, 61));
                     Point tilePlrPos = player.position.ToTileCoordinates();
                     if (!SummonMimicryAvailable(new Point(rand.X + (int)tilePlrPos.X, rand.Y + (int)tilePlrPos.Y)))
                     {
                         continue;
                     }
                     int mimicry = Projectile.NewProjectile(player.position + rand.ToWorldCoordinates(), Vector2.Zero, ProjectileType <Projectiles.Miscellaneous.Arcana>(), 0, 0f, player.whoAmI);
                     NetMessage.SendData(MessageID.SyncProjectile, -1, -1, null, mimicry);
                 }
             }
         }
     }
     else
     {
         if (_oldIsNight && Main.netMode != NetmodeID.MultiplayerClient)
         {
             if (magicStorm)
             {
                 magicStorm = false;
                 if (Main.dedServ)
                 {
                     NetworkText text = NetworkText.FromKey("魔力平静了下来");
                     NetMessage.BroadcastChatMessage(text, new Color(150, 150, 250));
                     var packet = mod.GetPacket();
                     packet.Write((byte)EntrogicModMessageType.ReceiveMagicStormRequest);
                     packet.Write(magicStorm);
                     packet.Send(); // 不填即为发给服务器
                 }
                 else
                 {
                     string text = "魔力平静了下来";
                     Main.NewText(text, 150, 150, 250);
                 }
             }
         }
     }
     _oldIsDay   = Main.dayTime;
     _oldIsNight = !Main.dayTime;
 }
Example #10
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            switch (reader.ReadByte())
            {
            case 0:     //server side spawning creepers
                if (Main.netMode == 2)
                {
                    byte p          = reader.ReadByte();
                    int  multiplier = reader.ReadByte();
                    int  n          = NPC.NewNPC((int)Main.player[p].Center.X, (int)Main.player[p].Center.Y, NPCType("CreeperGutted"), 0,
                                                 p, 0f, multiplier, 0f);
                    if (n != 200)
                    {
                        Main.npc[n].velocity = Vector2.UnitX.RotatedByRandom(2 * Math.PI) * 8;
                        NetMessage.SendData(23, -1, -1, null, n);
                    }
                }
                break;

            case 1:     //server side synchronize pillar data request
                if (Main.netMode == 2)
                {
                    byte pillar = reader.ReadByte();
                    if (!Main.npc[pillar].GetGlobalNPC <FargoSoulsGlobalNPC>().masoBool[1])
                    {
                        Main.npc[pillar].GetGlobalNPC <FargoSoulsGlobalNPC>().masoBool[1] = true;
                        Main.npc[pillar].GetGlobalNPC <FargoSoulsGlobalNPC>().SetDefaults(Main.npc[pillar]);
                        Main.npc[pillar].life = Main.npc[pillar].lifeMax;
                    }
                }
                break;

            case 2:     //net updating maso
                FargoSoulsGlobalNPC fargoNPC = Main.npc[reader.ReadByte()].GetGlobalNPC <FargoSoulsGlobalNPC>();
                fargoNPC.masoBool[0] = reader.ReadBoolean();
                fargoNPC.masoBool[1] = reader.ReadBoolean();
                fargoNPC.masoBool[2] = reader.ReadBoolean();
                fargoNPC.masoBool[3] = reader.ReadBoolean();
                break;

            case 3:     //rainbow slime/paladin, MP clients syncing to server
                if (Main.netMode == 1)
                {
                    byte npc = reader.ReadByte();
                    Main.npc[npc].lifeMax = reader.ReadInt32();
                    float newScale = reader.ReadSingle();
                    Main.npc[npc].position = Main.npc[npc].Center;
                    Main.npc[npc].width    = (int)(Main.npc[npc].width / Main.npc[npc].scale * newScale);
                    Main.npc[npc].height   = (int)(Main.npc[npc].height / Main.npc[npc].scale * newScale);
                    Main.npc[npc].scale    = newScale;
                    Main.npc[npc].Center   = Main.npc[npc].position;
                }
                break;

            case 4:     //moon lord vulnerability synchronization
                if (Main.netMode == 1)
                {
                    int ML = reader.ReadByte();
                    Main.npc[ML].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter = reader.ReadInt32();
                    FargoSoulsGlobalNPC.masoStateML = reader.ReadByte();
                }
                break;

            case 5:     //retinazer laser MP sync
                if (Main.netMode == 1)
                {
                    int reti = reader.ReadByte();
                    Main.npc[reti].GetGlobalNPC <FargoSoulsGlobalNPC>().masoBool[2] = reader.ReadBoolean();
                    Main.npc[reti].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter     = reader.ReadInt32();
                }
                break;

            case 6:     //shark MP sync
                if (Main.netMode == 1)
                {
                    int shark = reader.ReadByte();
                    Main.npc[shark].GetGlobalNPC <FargoSoulsGlobalNPC>().SharkCount = reader.ReadByte();
                }
                break;

            case 7:     //client to server activate dark caster family
                if (Main.netMode == 2)
                {
                    int caster = reader.ReadByte();
                    if (Main.npc[caster].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter2 == 0)
                    {
                        Main.npc[caster].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter2 = reader.ReadInt32();
                    }
                }
                break;

            case 8:     //server to clients reset counter
                if (Main.netMode == 1)
                {
                    int caster = reader.ReadByte();
                    Main.npc[caster].GetGlobalNPC <FargoSoulsGlobalNPC>().Counter2 = 0;
                }
                break;

            case 9:     //client to server, request heart spawn
                if (Main.netMode == 2)
                {
                    int n = reader.ReadByte();
                    Item.NewItem(Main.npc[n].Hitbox, ItemID.Heart);
                }
                break;

            case 10:     //client to server, sync cultist data
                if (Main.netMode == 2)
                {
                    int cult = reader.ReadByte();
                    FargoSoulsGlobalNPC cultNPC = Main.npc[cult].GetGlobalNPC <FargoSoulsGlobalNPC>();
                    cultNPC.Counter           += reader.ReadInt32();
                    cultNPC.Counter2          += reader.ReadInt32();
                    cultNPC.Timer             += reader.ReadInt32();
                    Main.npc[cult].localAI[3] += reader.ReadSingle();
                }
                break;

            case 11:     //refresh creeper
                if (Main.netMode != 0)
                {
                    byte player  = reader.ReadByte();
                    NPC  creeper = Main.npc[reader.ReadByte()];
                    if (creeper.active && creeper.type == NPCType("CreeperGutted") && creeper.ai[0] == player)
                    {
                        int damage = creeper.lifeMax - creeper.life;
                        creeper.life = creeper.lifeMax;
                        if (damage > 0)
                        {
                            CombatText.NewText(creeper.Hitbox, CombatText.HealLife, damage);
                        }
                        if (Main.netMode == 2)
                        {
                            creeper.netUpdate = true;
                        }
                    }
                }
                break;

            case 77:     //server side spawning fishron EX
                if (Main.netMode == 2)
                {
                    byte target = reader.ReadByte();
                    int  x      = reader.ReadInt32();
                    int  y      = reader.ReadInt32();
                    FargoSoulsGlobalNPC.spawnFishronEX = true;
                    NPC.NewNPC(x, y, NPCID.DukeFishron, 0, 0f, 0f, 0f, 0f, target);
                    FargoSoulsGlobalNPC.spawnFishronEX = false;
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Duke Fishron EX has awoken!"), new Color(50, 100, 255));
                }
                break;

            case 78:     //confirming fish EX max life
                int f = reader.ReadInt32();
                Main.npc[f].lifeMax = reader.ReadInt32();
                break;

            default:
                break;
            }

            //BaseMod Stuff
            MsgType msg = (MsgType)reader.ReadByte();

            if (msg == MsgType.ProjectileHostility) //projectile hostility and ownership
            {
                int  owner    = reader.ReadInt32();
                int  projID   = reader.ReadInt32();
                bool friendly = reader.ReadBoolean();
                bool hostile  = reader.ReadBoolean();
                if (Main.projectile[projID] != null)
                {
                    Main.projectile[projID].owner    = owner;
                    Main.projectile[projID].friendly = friendly;
                    Main.projectile[projID].hostile  = hostile;
                }
                if (Main.netMode == 2)
                {
                    MNet.SendBaseNetMessage(0, owner, projID, friendly, hostile);
                }
            }
            else
            if (msg == MsgType.SyncAI) //sync AI array
            {
                int     classID     = reader.ReadByte();
                int     id          = reader.ReadInt16();
                int     aitype      = reader.ReadByte();
                int     arrayLength = reader.ReadByte();
                float[] newAI       = new float[arrayLength];
                for (int m = 0; m < arrayLength; m++)
                {
                    newAI[m] = reader.ReadSingle();
                }
                if (classID == 0 && Main.npc[id] != null && Main.npc[id].active && Main.npc[id].modNPC != null && Main.npc[id].modNPC is ParentNPC)
                {
                    ((ParentNPC)Main.npc[id].modNPC).SetAI(newAI, aitype);
                }
                else
                if (classID == 1 && Main.projectile[id] != null && Main.projectile[id].active && Main.projectile[id].modProjectile != null && Main.projectile[id].modProjectile is ParentProjectile)
                {
                    ((ParentProjectile)Main.projectile[id].modProjectile).SetAI(newAI, aitype);
                }
                if (Main.netMode == 2)
                {
                    BaseNet.SyncAI(classID, id, newAI, aitype);
                }
            }
        }
Example #11
0
        public override bool UseItem(Player player)
        {
            Main.moonPhase++;
            if (Main.moonPhase >= 8)
            {
                Main.moonPhase = 0;
            }
            if (Main.netMode == NetmodeID.SinglePlayer)
            {
                if (Main.moonPhase == 0)
                {
                    Main.NewText("Moon Phase is now Full.", 50, 255, 130);
                }
                else if (Main.moonPhase == 1)
                {
                    Main.NewText("Moon Phase is now Last Gibbous.", 50, 255, 130);
                }
                else if (Main.moonPhase == 2)
                {
                    Main.NewText("Moon Phase is now Last Quarter.", 50, 255, 130);
                }
                else if (Main.moonPhase == 3)
                {
                    Main.NewText("Moon Phase is now Last Crescent.", 50, 255, 130);
                }
                else if (Main.moonPhase == 4)
                {
                    Main.NewText("Moon Phase is now New.", 50, 255, 130);
                }
                else if (Main.moonPhase == 5)
                {
                    Main.NewText("Moon Phase is now First Crescent.", 50, 255, 130);
                }
                else if (Main.moonPhase == 6)
                {
                    Main.NewText("Moon Phase is now First Quarter.", 50, 255, 130);
                }
                else if (Main.moonPhase == 7)
                {
                    Main.NewText("Moon Phase is now First Gibbous.", 50, 255, 130);
                }
            }
            else if (Main.netMode == NetmodeID.Server)
            {
                if (Main.moonPhase == 0)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now Full"), new Color(50, 255, 130));
                }
                if (Main.moonPhase == 1)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now Last Gibbous"), new Color(50, 255, 130));
                }
                if (Main.moonPhase == 2)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now Last Quarter"), new Color(50, 255, 130));
                }
                if (Main.moonPhase == 3)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now Last Crescent"), new Color(50, 255, 130));
                }
                if (Main.moonPhase == 4)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now New"), new Color(50, 255, 130));
                }
                if (Main.moonPhase == 5)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now First Crescent"), new Color(50, 255, 130));
                }
                if (Main.moonPhase == 6)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now First Quarter"), new Color(50, 255, 130));
                }
                if (Main.moonPhase == 7)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Moon phase is now First Gibbous"), new Color(50, 255, 130));
                }
                NetMessage.SendData(MessageID.WorldData);
            }

            if (Main.rand.Next(14) == 0 && !Main.dayTime && !Main.bloodMoon)
            {
                Main.bloodMoon = true;
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("The Blood moon has risen..."), new Color(50, 255, 130));
                    NetMessage.SendData(MessageID.WorldData);
                }
                else if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    Main.NewText("The Blood Moon has risen...", 50, 255, 130);
                }
            }
            return(true);
        }
Example #12
0
		public static void SendTextToAllPlayers(string msg, Color? color = null)
		{
			Color c = color.GetValueOrDefault(Color.White);
			//NetMessage.SendData(25, -1, -1, msg, 255, c.R, c.G, c.B, 0);
			NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(msg), c, -1);
		}
Example #13
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            switch (reader.ReadByte())
            {
            case 0:     //server side spawning creepers
                if (Main.netMode == 2)
                {
                    byte p          = reader.ReadByte();
                    int  multiplier = reader.ReadByte();
                    int  n          = NPC.NewNPC((int)Main.player[p].Center.X, (int)Main.player[p].Center.Y, NPCType("CreeperGutted"), 0,
                                                 p, 0f, multiplier, 0f);
                    if (n != 200)
                    {
                        Main.npc[n].velocity = Vector2.UnitX.RotatedByRandom(2 * Math.PI) * 8;
                        NetMessage.SendData(23, -1, -1, null, n);
                    }
                }
                break;

            case 1:     //server side synchronize pillar data request
                if (Main.netMode == 2)
                {
                    byte pillar = reader.ReadByte();
                    if (!Main.npc[pillar].GetGlobalNPC <FargoGlobalNPC>().masoBool[1])
                    {
                        Main.npc[pillar].GetGlobalNPC <FargoGlobalNPC>().masoBool[1] = true;
                        Main.npc[pillar].GetGlobalNPC <FargoGlobalNPC>().SetDefaults(Main.npc[pillar]);
                        Main.npc[pillar].life = Main.npc[pillar].lifeMax;
                    }
                }
                break;

            case 2:     //net updating maso
                FargoGlobalNPC fargoNPC = Main.npc[reader.ReadByte()].GetGlobalNPC <FargoGlobalNPC>();
                fargoNPC.masoBool[0] = reader.ReadBoolean();
                fargoNPC.masoBool[1] = reader.ReadBoolean();
                fargoNPC.masoBool[2] = reader.ReadBoolean();
                fargoNPC.masoBool[3] = reader.ReadBoolean();
                break;

            case 3:     //rainbow slime/paladin, MP clients syncing to server
                if (Main.netMode == 1)
                {
                    byte npc = reader.ReadByte();
                    Main.npc[npc].lifeMax = reader.ReadInt32();
                    float newScale = reader.ReadSingle();
                    Main.npc[npc].position = Main.npc[npc].Center;
                    Main.npc[npc].width    = (int)(Main.npc[npc].width / Main.npc[npc].scale * newScale);
                    Main.npc[npc].height   = (int)(Main.npc[npc].height / Main.npc[npc].scale * newScale);
                    Main.npc[npc].scale    = newScale;
                    Main.npc[npc].Center   = Main.npc[npc].position;
                }
                break;

            case 4:     //moon lord vulnerability synchronization
                if (Main.netMode == 1)
                {
                    int ML = reader.ReadByte();
                    Main.npc[ML].GetGlobalNPC <FargoGlobalNPC>().Counter = reader.ReadInt32();
                    FargoGlobalNPC.masoStateML = reader.ReadByte();
                }
                break;

            case 5:     //retinazer laser MP sync
                if (Main.netMode == 1)
                {
                    int reti = reader.ReadByte();
                    Main.npc[reti].GetGlobalNPC <FargoGlobalNPC>().masoBool[2] = reader.ReadBoolean();
                    Main.npc[reti].GetGlobalNPC <FargoGlobalNPC>().Counter     = reader.ReadInt32();
                }
                break;

            case 6:     //shark MP sync
                if (Main.netMode == 1)
                {
                    int shark = reader.ReadByte();
                    Main.npc[shark].GetGlobalNPC <FargoGlobalNPC>().SharkCount = reader.ReadByte();
                }
                break;

            case 7:     //client to server activate dark caster family
                if (Main.netMode == 2)
                {
                    int caster = reader.ReadByte();
                    if (Main.npc[caster].GetGlobalNPC <FargoGlobalNPC>().Counter2 == 0)
                    {
                        Main.npc[caster].GetGlobalNPC <FargoGlobalNPC>().Counter2 = reader.ReadInt32();
                    }
                }
                break;

            case 8:     //server to clients reset counter
                if (Main.netMode == 1)
                {
                    int caster = reader.ReadByte();
                    Main.npc[caster].GetGlobalNPC <FargoGlobalNPC>().Counter2 = 0;
                }
                break;

            case 9:     //client to server, request heart spawn
                if (Main.netMode == 2)
                {
                    int n = reader.ReadByte();
                    Item.NewItem(Main.npc[n].Hitbox, ItemID.Heart);
                }
                break;

            case 10:     //client to server, sync cultist data
                if (Main.netMode == 2)
                {
                    int            cult    = reader.ReadByte();
                    FargoGlobalNPC cultNPC = Main.npc[cult].GetGlobalNPC <FargoGlobalNPC>();
                    cultNPC.Counter           += reader.ReadInt32();
                    cultNPC.Counter2          += reader.ReadInt32();
                    cultNPC.Timer             += reader.ReadInt32();
                    Main.npc[cult].localAI[3] += reader.ReadSingle();
                }
                break;

            case 11:     //refresh creeper
                if (Main.netMode != 0)
                {
                    byte player  = reader.ReadByte();
                    NPC  creeper = Main.npc[reader.ReadByte()];
                    if (creeper.active && creeper.type == NPCType("CreeperGutted") && creeper.ai[0] == player)
                    {
                        int damage = creeper.lifeMax - creeper.life;
                        creeper.life = creeper.lifeMax;
                        if (damage > 0)
                        {
                            CombatText.NewText(creeper.Hitbox, CombatText.HealLife, damage);
                        }
                        if (Main.netMode == 2)
                        {
                            creeper.netUpdate = true;
                        }
                    }
                }
                break;

            case 77:     //server side spawning fishron EX
                if (Main.netMode == 2)
                {
                    byte target = reader.ReadByte();
                    int  x      = reader.ReadInt32();
                    int  y      = reader.ReadInt32();
                    FargoGlobalNPC.spawnFishronEX = true;
                    NPC.NewNPC(x, y, NPCID.DukeFishron, 0, 0f, 0f, 0f, 0f, target);
                    FargoGlobalNPC.spawnFishronEX = false;
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("Duke Fishron EX has awoken!"), new Color(50, 100, 255));
                }
                break;

            case 78:     //confirming fish EX max life
                int f = reader.ReadInt32();
                Main.npc[f].lifeMax = reader.ReadInt32();
                break;

            default:
                break;
            }
        }
        public void Handle(BinaryReader reader, int playerNumber)
        {
            if (Main.netMode == 2)
            {
                var encrypted = reader.ReadString();
                // 解密RSA加密的信息
                var info         = CryptedUserInfo.GetDecrypted(encrypted);
                var serverPlayer = Main.player[playerNumber].GetServerPlayer();
                serverPlayer.qqAuth.CharacterName = Main.player[playerNumber].name;
                serverPlayer.qqAuth.MachineCode   = info.MachineCode;
                if (serverPlayer.IsLogin)
                {
                    MessageSender.SendLoginSuccess(serverPlayer.PrototypePlayer.whoAmI, "你已经登录,请不要重复登录");
                    return;
                }
                if (serverPlayer.HasPassword)
                {
                    bool isLoginSuccess = false;
                    QQAuth.States.LoginState loginState = serverPlayer.qqAuth.Login(info);
                    switch (loginState)
                    {
                    case QQAuth.States.LoginState.Debug:
                        CommandBoardcast.ConsoleMessage("Debug模式已启用,跳过登录验证.");
                        isLoginSuccess = true;
                        break;

                    case QQAuth.States.LoginState.Unbound:
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:未绑定QQ.");
                        MessageSender.SendLoginFailed(playerNumber, "请先绑定QQ!");
                        isLoginSuccess = false;
                        break;

                    case QQAuth.States.LoginState.Banned:
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:玩家已被封禁.");
                        MessageSender.SendLoginFailed(playerNumber, $"您已被封禁!原因:{serverPlayer.qqAuth.GetBanReason(serverPlayer)}");
                        isLoginSuccess = false;
                        break;

                    case QQAuth.States.LoginState.NotFound:
                        serverPlayer.HasPassword = false;
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} ,QQ {serverPlayer.qqAuth.QQ} 数据库记录丢失.");
                        MessageSender.SendLoginFailed(playerNumber, "数据库记录丢失!请重新输入QQ注册。");
                        isLoginSuccess = false;
                        break;

                    case QQAuth.States.LoginState.LoginSuccess:
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} ,QQ {serverPlayer.qqAuth.QQ} 认证成功.");
                        isLoginSuccess = true;
                        break;

                    case QQAuth.States.LoginState.ChangePasswordRequired:
                        serverPlayer.HasPassword = false;
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} ,QQ {serverPlayer.qqAuth.QQ} 申请改密.");
                        MessageSender.SendLoginFailed(playerNumber, "申请改密已受理!请输入QQ和新密码完成改密。");
                        isLoginSuccess = false;
                        break;

                    case QQAuth.States.LoginState.GetMCFailed:
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:机器码获取失败.");
                        MessageSender.SendLoginFailed(playerNumber, "机器码获取失败!请联系管理员。");
                        isLoginSuccess = false;
                        break;

                    case QQAuth.States.LoginState.MCCheckFailed:
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:机器码校验失败.");
                        MessageSender.SendLoginFailed(playerNumber, "机器码校验失败!当前机器可能不是此角色注册的机器。");
                        isLoginSuccess = false;
                        break;

                    case QQAuth.States.LoginState.Error:
                        CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 登录错误,信息:" + serverPlayer.qqAuth.ErrorLog);
                        MessageSender.SendLoginFailed(playerNumber, "数据库操作出错!");
                        isLoginSuccess = false;
                        break;

                    default:
                        isLoginSuccess = false;
                        break;
                    }
                    if (isLoginSuccess)
                    {
                        if (serverPlayer.CheckPassword(info))
                        {
                            if (!ServerSideCharacter2.DEBUGMODE)
                            {
                                OnPlayerLogin?.Invoke(serverPlayer);
                            }
                            RecordVisit(playerNumber, serverPlayer);
                            SuccessLogin(serverPlayer);
                            MessageSender.SendLoginSuccess(serverPlayer.PrototypePlayer.whoAmI, "认证成功");
                            // 告诉客户端解除封印
                            MessageSender.SendLoginIn(serverPlayer.PrototypePlayer.whoAmI);
                            NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(serverPlayer.Name + " 登入了游戏"), new Color(255, 255, 240, 20), -1);
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证成功.");
                        }
                        else
                        {
                            // 如果忘记密码就要找管理员重置密码
                            MessageSender.SendLoginFailed(playerNumber, "密码错误!");
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 认证失败:密码错误.");
                        }
                    }
                }
                else
                {
                    var result = CheckName(Main.player[playerNumber].name);
                    if (result == 0)
                    {
                        bool isRegisterLegal = false;
                        QQAuth.States.RegisterState registerState = serverPlayer.qqAuth.Register(info);
                        switch (registerState)
                        {
                        case QQAuth.States.RegisterState.Debug:
                            CommandBoardcast.ConsoleMessage("Debug模式已启用,跳过注册验证.");
                            isRegisterLegal = true;
                            break;

                        case QQAuth.States.RegisterState.NullQQ:
                            MessageSender.SendLoginFailed(playerNumber, "注册时QQ不能为空!");
                            isRegisterLegal = false;
                            break;

                        case QQAuth.States.RegisterState.RegisterSuccess:
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求合法(常规注册).");
                            isRegisterLegal = true;
                            if (!ServerSideCharacter2.DEBUGMODE)
                            {
                                OnPlayerRegistered?.Invoke(serverPlayer, new EventArgs());
                            }
                            break;

                        case QQAuth.States.RegisterState.RegisterRep:
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求合法(角色可能丢失).");
                            isRegisterLegal = true;
                            break;

                        case QQAuth.States.RegisterState.QQBound:
                            MessageSender.SendLoginFailed(playerNumber, "QQ或角色已被绑定!");
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求被拒(QQ或角色已被绑定).");
                            isRegisterLegal = false;
                            break;

                        case QQAuth.States.RegisterState.GetMCFailed:
                            MessageSender.SendLoginFailed(playerNumber, "机器码获取失败!请联系管理员。");
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求被拒(获取机器码失败).");
                            isRegisterLegal = false;
                            break;

                        case QQAuth.States.RegisterState.MCBound:
                            MessageSender.SendLoginFailed(playerNumber, "该机器已被其他角色绑定!");
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册请求被拒(机器已被绑定).");
                            isRegisterLegal = false;
                            break;

                        case QQAuth.States.RegisterState.Error:
                            MessageSender.SendLoginFailed(playerNumber, "数据库操作出错!");
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册出现错误,信息:" + serverPlayer.qqAuth.ErrorLog);
                            isRegisterLegal = false;
                            break;

                        default:
                            isRegisterLegal = false;
                            break;
                        }
                        if (isRegisterLegal)
                        {
                            serverPlayer.SetPassword(info);
                            // SuccessLogin(serverPlayer);
                            MessageSender.SendLoginSuccess(serverPlayer.PrototypePlayer.whoAmI, "注册成功,输入密码即可登录");
                            // 告诉客户端解除封印
                            // MessageSender.SendLoginIn(serverPlayer.PrototypePlayer.whoAmI);
                            CommandBoardcast.ConsoleMessage($"玩家 {serverPlayer.Name} 注册成功.");
                        }
                    }
                    else
                    {
                        if (result == 1 || result == -1)
                        {
                            serverPlayer.SendMessageBox("无法注册玩家:用户名" +
                                                        (result == 1 ? "过长" : "过短") + "\n" + "用户名应为2-10个字符", 120, Color.Red);
                        }
                        else
                        {
                            serverPlayer.SendMessageBox("无法注册玩家:用户名不能含有下列特殊字符:$%^&*!@#:?|<>", 120, Color.Red);
                        }
                    }
                }
            }
        }
Example #15
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;
            }
        }
        public override void AI()
        {
            npc.GetGlobalNPC <FortressNPCGeneral>().fortressNPC = true;
            Lighting.AddLight(npc.Center, new Vector3(1.2f, 1.2f, 1.2f));
            if (npc.life > npc.lifeMax)
            {
                npc.life = npc.lifeMax;
            }
            if (Main.expertMode)
            {
                damage = 7;
            }
            else
            {
                damage = 9;
            }

            if (start)
            {
                if (QwertyWorld.hasSummonedFortressBoss)
                {
                    startFight = true;
                }
                start = false;
                for (int i = 0; i < previousHealth.Length; i++)
                {
                    previousHealth[i] = npc.lifeMax;
                }
            }
            dpsCheckCounter++;
            if (dpsCheckCounter % 60 == 0)
            {
                for (int i = previousHealth.Length - 1; i > 0; i--)
                {
                    previousHealth[i] = previousHealth[i - 1];
                }
                previousHealth[0] = npc.life;

                dps = (((float)previousHealth[previousHealth.Length - 1] - (float)previousHealth[0]) / (float)previousHealth.Length);

                //Main.NewText("dps: " + dps);
            }
            if (Main.dungeonX < Main.maxTilesX * .5f)
            {
                Center = (int)((double)Main.maxTilesX * 0.8) * 16;
            }
            else
            {
                Center = (int)((double)Main.maxTilesX * 0.2) * 16;
            }
            player = Main.player[npc.target];
            npc.TargetClosest(true);
            if (!player.active || player.dead)
            {
                quitCount++;
                if (quitCount >= 30)
                {
                    npc.position.Y += 100000f;
                    playerDied      = true;
                }
            }
            else
            {
                quitCount = 0;
            }
            directionOfPlayer = (player.Center - npc.Center).ToRotation();
            if (Main.maxTilesX > 8000)
            {
                lowerLimit            = 280 * 16;
                maxDistanceFromCenter = 750 * 16;
            }
            else if (Main.maxTilesX > 6000)
            {
                lowerLimit            = 230 * 16;
                maxDistanceFromCenter = 550 * 16;
            }
            else
            {
                lowerLimit            = 130 * 16;
                maxDistanceFromCenter = 320 * 16;
            }
            if (npc.Center.Y < upperLimit)
            {
                YDirection = 1;
            }
            if (npc.Center.Y > lowerLimit)
            {
                YDirection = -1;
            }
            float Xdistance = Math.Abs(player.Center.X - npc.Center.X);

            if (Xdistance > 1400)
            {
                speedX = 0;
                impatient++;
                if (impatient == 240 && !playerDied)
                {
                    string key          = "Mods.QwertysRandomContent.DivineMock";
                    Color  messageColor = Color.Orange;
                    if (Main.netMode == 2) // Server
                    {
                        NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor);
                    }
                    else if (Main.netMode == 0) // Single Player
                    {
                        Main.NewText(Language.GetTextValue(key), messageColor);
                    }
                }
                if (impatient > 240 && npc.life < npc.lifeMax)
                {
                    npc.life++;
                }
            }
            else if (Xdistance > 400)
            {
                speedX    = 2;
                impatient = 0;
            }
            else
            {
                speedX    = (400f - Xdistance) / 80f + 2;
                impatient = 0;
            }
            if (startFight)
            {
                if (runOnce)
                {
                    runOnce = false;
                }
                attackTimer++;
                if (attackTimer > attackDelay)
                {
                    Main.PlaySound(SoundID.Item43, npc.Center);
                    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    if (pickAttack)
                    {
                        if (Main.netMode != 1)
                        {
                            npc.ai[0]     = Main.rand.Next(6);
                            npc.netUpdate = true;
                        }
                        pickAttack = false;
                    }
                    if (npc.ai[0] == 4 && (NPC.AnyNPCs(mod.NPCType("HealingBarrier")) || (int)(dps / 12f) < 2))
                    {
                        npc.ai[0]     = 0;
                        npc.netUpdate = true;
                    }
                    if (npc.ai[0] == 5)
                    {
                        int numberOfProjectiles = 5;
                        if (Main.expertMode)
                        {
                            numberOfProjectiles += 4;
                        }
                        float spread = 2 * (float)Math.PI;


                        for (int p = 0; p < numberOfProjectiles; p++)
                        {
                            float shiftedAim = (directionOfPlayer - (spread / 2)) + (spread * ((float)p / (float)numberOfProjectiles));
                            float speed      = 1;
                            Projectile.NewProjectile(npc.Center + QwertyMethods.PolarVector(speed, shiftedAim), QwertyMethods.PolarVector(speed, shiftedAim), mod.ProjectileType("CaeliteSaw"), damage, 0, player.whoAmI, npc.whoAmI);
                        }
                        attackTimer = 0;
                    }
                    else if (npc.ai[0] == 4)
                    {
                        int numberOfProjectiles = (int)(dps / 12f);

                        for (int i = 0; i < numberOfProjectiles; i++)
                        {
                            NPC.NewNPC((int)npc.Center.X, (int)npc.Center.Y, mod.NPCType("HealingBarrier"), 0, (float)i / (float)numberOfProjectiles * 2 * (float)Math.PI, npc.whoAmI * -npc.direction);
                        }
                        attackTimer = 0;
                    }
                    else if (npc.ai[0] == 3)
                    {
                        int   numberOfProjectiles = 7;
                        float spread = (float)Math.PI / 2;


                        for (int p = 0; p < numberOfProjectiles; p++)
                        {
                            float shiftedAim = (directionOfPlayer - (spread / 2)) + Main.rand.NextFloat(spread);
                            float speed      = Main.rand.Next(7, 10);
                            Projectile.NewProjectile(npc.Center, QwertyMethods.PolarVector(speed, shiftedAim), mod.ProjectileType("Deflect"), (int)(damage * 1.2f), 0, player.whoAmI, npc.whoAmI);
                        }
                        attackTimer = 0;
                    }
                    else
                    {
                        int   numberOfProjectiles = 3;
                        float spread = (float)Math.PI / 8;


                        for (int p = 0; p < numberOfProjectiles; p++)
                        {
                            float shiftedAim = (directionOfPlayer - (spread / 2)) + (spread * ((float)p / (float)numberOfProjectiles));
                            float speed      = 5;
                            Projectile.NewProjectile(npc.Center, QwertyMethods.PolarVector(speed, shiftedAim), mod.ProjectileType("BarrierSpread"), damage, 0, player.whoAmI, npc.whoAmI);
                        }
                        attackTimer = 0;
                    }
                }
                else
                {
                    pickAttack = true;
                }
                if (npc.Center.X < player.Center.X && npc.Center.X < Center - maxDistanceFromCenter && Main.netMode != 1)
                {
                    npc.Center    = new Vector2(player.Center.X + Xdistance, npc.Center.Y);
                    npc.netUpdate = true;
                }
                if (npc.Center.X > player.Center.X && npc.Center.X > Center + maxDistanceFromCenter && Main.netMode != 1)
                {
                    npc.Center    = new Vector2(player.Center.X - Xdistance, npc.Center.Y);
                    npc.netUpdate = true;
                }
                npc.spriteDirection = npc.direction;
                XDirection          = -npc.direction;
                npc.velocity        = new Vector2(speedX * XDirection, speedY * YDirection);
                //Main.NewText(Xdistance);
                //Main.NewText(player.GetModPlayer<FortressBiome>(mod).TheFortress);
            }
            else
            {
                //Main.NewText(player.GetModPlayer<FortressBiome>(mod).TheFortress);
                QwertyWorld.hasSummonedFortressBoss = true;
                if (Main.netMode != 2)
                {
                    aggressionTimer++;
                    if (aggressionTimer > 20 * 60)
                    {
                        string key          = "Mods.QwertysRandomContent.DivineStart";
                        Color  messageColor = Color.Orange;
                        if (Main.netMode == 2) // Server
                        {
                            NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor);
                        }
                        else if (Main.netMode == 0) // Single Player
                        {
                            Main.NewText(Language.GetTextValue(key), messageColor);
                        }
                        startFight    = true;
                        npc.netUpdate = true;
                    }
                    else if (!player.GetModPlayer <FortressBiome>(mod).TheFortress&& aggressionTimer > 10)
                    {
                        string key          = "Mods.QwertysRandomContent.DivineLeave";
                        Color  messageColor = Color.Orange;
                        if (Main.netMode == 2) // Server
                        {
                            NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor);
                        }
                        else if (Main.netMode == 0) // Single Player
                        {
                            Main.NewText(Language.GetTextValue(key), messageColor);
                        }
                        npc.active = false;
                    }
                }
            }
        }
Example #17
0
        public override void Spawn(int playerIndex)
        {
            Player player = Main.player[playerIndex];

            Vector2 pos = player.position;

            if (pos.Y / 16f < (float)(Main.maxTilesY - 205))
            {
                Main.NewText(HEROsMod.HeroText("UnderworldToSpawnWoF"));
                return;
            }
            if (Main.netMode == 1)
            {
                return;
            }
            Player.FindClosest(pos, 16, 16);
            int num = 1;

            if (pos.X / 16f > (float)(Main.maxTilesX / 2))
            {
                num = -1;
            }
            bool flag = false;
            int  num2 = (int)pos.X;

            while (!flag)
            {
                flag = true;
                for (int i = 0; i < 255; i++)
                {
                    if (Main.player[i].active && Main.player[i].position.X > (float)(num2 - 1200) && Main.player[i].position.X < (float)(num2 + 1200))
                    {
                        num2 -= num * 16;
                        flag  = false;
                    }
                }
                if (num2 / 16 < 20 || num2 / 16 > Main.maxTilesX - 20)
                {
                    flag = true;
                }
            }
            int num3 = (int)pos.Y;
            int num4 = num2 / 16;
            int num5 = num3 / 16;
            int num6 = 0;

            try
            {
                while (WorldGen.SolidTile(num4, num5 - num6) || Main.tile[num4, num5 - num6].liquid >= 100)
                {
                    if (!WorldGen.SolidTile(num4, num5 + num6) && Main.tile[num4, num5 + num6].liquid < 100)
                    {
                        num5 += num6;
                        goto IL_162;
                    }
                    num6++;
                }
                num5 -= num6;
            }
            catch
            {
            }
IL_162:
            num3 = num5 * 16;
            int num7 = NPC.NewNPC(num2, num3, 113, 0);

            if (Main.netMode == 0)
            {
                Main.NewText(Language.GetTextValue("Announcement.HasAwoken", Main.npc[num7].TypeName), 175, 75, 255, false);
                return;
            }
            if (Main.netMode == 2)
            {
                NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[]
                {
                    Main.npc[num7].GetTypeNetName()
                }), new Color(175, 75, 255), -1);
            }
        }
Example #18
0
        public static bool GenereateViralMeteorite(int i, int j)     //from WorldGen.cs, line 2303
        {
            int worldBoundaries = 50;

            if (i < worldBoundaries || i > Main.maxTilesX - worldBoundaries)
            {
                return(false);
            }
            if (j < worldBoundaries || j > Main.maxTilesY - worldBoundaries)
            {
                return(false);
            }
            int       meteoriteArea = 35;   //The amount of space the VM will take up
            Rectangle meteoriteRect = new Rectangle((i - meteoriteArea) * 16, (j - meteoriteArea) * 16, meteoriteArea * 2 * 16, meteoriteArea * 2 * 16);

            for (int p = 0; p < Main.maxPlayers; p++)
            {
                Player player = Main.player[p];
                if (player.active)
                {
                    Rectangle playerArea = new Rectangle((int)(player.position.X + (float)(player.width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(player.position.Y + (float)(player.height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2);
                    if (meteoriteRect.Intersects(playerArea))
                    {
                        return(false);
                    }
                }
            }
            for (int n = 0; n < Main.maxNPCs; n++)
            {
                NPC npc = Main.npc[n];
                if (npc.active)
                {
                    Rectangle npcArea = new Rectangle((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height);         //How much space that NPC is taking up and where
                    if (meteoriteRect.Intersects(npcArea))
                    {
                        return(false);
                    }
                }
            }
            for (int xCoord = i - meteoriteArea; xCoord < i + meteoriteArea; xCoord++)
            {
                for (int yCoord = j - meteoriteArea; yCoord < j + meteoriteArea; yCoord++)
                {
                    if (Main.tile[xCoord, yCoord].active() && TileID.Sets.BasicChest[(int)Main.tile[xCoord, yCoord].type])
                    {
                        return(false);
                    }
                }
            }
            meteoriteArea = WorldGen.genRand.Next(17, 23);
            for (int xCoord = i - meteoriteArea; xCoord < i + meteoriteArea; xCoord++)
            {
                for (int yCoord = j - meteoriteArea; yCoord < j + meteoriteArea; yCoord++)
                {
                    if (yCoord > j + Main.rand.Next(-2, 3) - 5)     //Deciding random Y placement
                    {
                        float tilePlacementX = (float)Math.Abs(i - xCoord);
                        float tilePlacementY = (float)Math.Abs(j - yCoord);
                        float num6           = (float)Math.Sqrt((double)(tilePlacementX * tilePlacementX + tilePlacementY * tilePlacementY));
                        if ((double)num6 < (double)meteoriteArea * 0.9 + (double)Main.rand.Next(-4, 5))
                        {
                            if (!Main.tileSolid[(int)Main.tile[xCoord, yCoord].type])
                            {
                                Main.tile[xCoord, yCoord].active(false);
                            }
                            Main.tile[xCoord, yCoord].type = (ushort)JoJoStands.Instance.TileType("ViralMeteoriteTile");
                        }
                    }
                }
            }
            meteoriteArea = WorldGen.genRand.Next(8, 14);
            for (int xCoord = i - meteoriteArea; xCoord < i + meteoriteArea; xCoord++)
            {
                for (int yCoord = j - meteoriteArea; yCoord < j + meteoriteArea; yCoord++)
                {
                    if (yCoord > j + Main.rand.Next(-2, 3) - 4)
                    {
                        float num9  = (float)Math.Abs(i - xCoord);
                        float num10 = (float)Math.Abs(j - yCoord);
                        float num11 = (float)Math.Sqrt((double)(num9 * num9 + num10 * num10));
                        if ((double)num11 < (double)meteoriteArea * 0.8 + (double)Main.rand.Next(-3, 4))
                        {
                            Main.tile[xCoord, yCoord].active(false);
                        }
                    }
                }
            }
            meteoriteArea = WorldGen.genRand.Next(25, 35);
            for (int xCoord = i - meteoriteArea; xCoord < i + meteoriteArea; xCoord++)
            {
                for (int yCoord = j - meteoriteArea; yCoord < j + meteoriteArea; yCoord++)
                {
                    float tilePlacementX = (float)Math.Abs(i - xCoord);
                    float tilePlacementY = (float)Math.Abs(j - yCoord);
                    float num16          = (float)Math.Sqrt((double)(tilePlacementX * tilePlacementX + tilePlacementY * tilePlacementY));
                    if ((double)num16 < (double)meteoriteArea * 0.7)
                    {
                        if (Main.tile[xCoord, yCoord].type == TileID.Trees || Main.tile[xCoord, yCoord].type == TileID.CorruptThorns || Main.tile[xCoord, yCoord].type == TileID.CrimtaneThorns)
                        {
                            WorldGen.KillTile(xCoord, yCoord, false, false, false);
                        }
                        Main.tile[xCoord, yCoord].liquid = 0;
                    }
                    if (Main.tile[xCoord, yCoord].type == JoJoStands.Instance.TileType("ViralMeteoriteTile"))
                    {
                        if (!WorldGen.SolidTile(xCoord - 1, yCoord) && !WorldGen.SolidTile(xCoord + 1, yCoord) && !WorldGen.SolidTile(xCoord, yCoord - 1) && !WorldGen.SolidTile(xCoord, yCoord + 1))
                        {
                            Main.tile[xCoord, yCoord].active(false);
                        }
                        else if ((Main.tile[xCoord, yCoord].halfBrick() || Main.tile[xCoord - 1, yCoord].topSlope()) && !WorldGen.SolidTile(xCoord, yCoord + 1))
                        {
                            Main.tile[xCoord, yCoord].active(false);
                        }
                    }
                    WorldGen.SquareTileFrame(xCoord, yCoord, true);
                    WorldGen.SquareWallFrame(xCoord, yCoord, true);
                }
            }
            meteoriteArea = WorldGen.genRand.Next(23, 32);
            for (int xCoord = i - meteoriteArea; xCoord < i + meteoriteArea; xCoord++)
            {
                for (int yCoord = j - meteoriteArea; yCoord < j + meteoriteArea; yCoord++)
                {
                    if (yCoord > j + WorldGen.genRand.Next(-3, 4) - 3 && Main.tile[xCoord, yCoord].active() && Main.rand.Next(10) == 0)
                    {
                        float tilePlacementX = (float)Math.Abs(i - xCoord);
                        float tilePlacementY = (float)Math.Abs(j - yCoord);
                        float num21          = (float)Math.Sqrt((double)(tilePlacementX * tilePlacementX + tilePlacementY * tilePlacementY));
                        if ((double)num21 < (double)meteoriteArea * 0.8)
                        {
                            if (Main.tile[xCoord, yCoord].type == TileID.Trees || Main.tile[xCoord, yCoord].type == TileID.CorruptThorns || Main.tile[xCoord, yCoord].type == TileID.CrimtaneThorns)
                            {
                                WorldGen.KillTile(xCoord, yCoord, false, false, false);
                            }
                            Main.tile[xCoord, yCoord].type = (ushort)JoJoStands.Instance.TileType("ViralMeteoriteTile");
                            WorldGen.SquareTileFrame(xCoord, yCoord, true);
                        }
                    }
                }
            }
            meteoriteArea = WorldGen.genRand.Next(30, 38);
            for (int xCoord = i - meteoriteArea; xCoord < i + meteoriteArea; xCoord++)
            {
                for (int yCoord = j - meteoriteArea; yCoord < j + meteoriteArea; yCoord++)
                {
                    if (yCoord > j + WorldGen.genRand.Next(-2, 3) && Main.tile[xCoord, yCoord].active() && Main.rand.Next(20) == 0)
                    {
                        float tilePlacementX = (float)Math.Abs(i - xCoord);
                        float tilePlacementY = (float)Math.Abs(j - yCoord);
                        float num26          = (float)Math.Sqrt((double)(tilePlacementX * tilePlacementX + tilePlacementY * tilePlacementY));
                        if ((double)num26 < (double)meteoriteArea * 0.85)
                        {
                            if (Main.tile[xCoord, yCoord].type == TileID.Trees || Main.tile[xCoord, yCoord].type == TileID.CorruptThorns || Main.tile[xCoord, yCoord].type == TileID.CrimtaneThorns)
                            {
                                WorldGen.KillTile(xCoord, yCoord, false, false, false);
                            }
                            Main.tile[xCoord, yCoord].type = (ushort)JoJoStands.Instance.TileType("ViralMeteoriteTile");
                            WorldGen.SquareTileFrame(xCoord, yCoord, true);
                        }
                    }
                }
            }
            if (Main.netMode == NetmodeID.SinglePlayer)
            {
                Main.NewText("A dangerous virus now inhabits " + Main.worldName + "...", 50, 255, 130, false);
            }
            else if (Main.netMode == NetmodeID.Server)
            {
                NetMessage.BroadcastChatMessage(NetworkText.FromKey("A dangerous virus now inhabits " + Main.worldName + "...", new object[0]), new Color(50, 255, 130), -1);
            }
            if (Main.netMode != NetmodeID.MultiplayerClient)
            {
                NetMessage.SendTileSquare(-1, i, j, 40, TileChangeType.None);
            }
            return(true);
        }
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            MessageType type = (MessageType)reader.ReadByte();

            if (type == MessageType.PuritySpirit)
            {
                PuritySpirit.PuritySpirit spirit = Main.npc[reader.ReadInt32()].modNPC as PuritySpirit.PuritySpirit;
                if (spirit != null && spirit.npc.active)
                {
                    spirit.HandlePacket(reader);
                }
            }
            else if (type == MessageType.HeroLives)
            {
                Player player = Main.player[reader.ReadInt32()];
                int    lives  = reader.ReadInt32();
                player.GetModPlayer <BluemagicPlayer>(this).heroLives = lives;
                if (lives > 0)
                {
                    NetworkText text;
                    if (lives == 1)
                    {
                        text = NetworkText.FromKey("Mods.Bluemagic.LifeLeft", player.name);
                    }
                    else
                    {
                        text = NetworkText.FromKey("Mods.Bluemagic.LivesLeft", player.name, lives);
                    }
                    NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25));
                }
            }
            else if (type == MessageType.ChaosSpirit)
            {
                NPC npc = Main.npc[reader.ReadInt32()];
                if (npc.active)
                {
                    ChaosSpirit.ChaosSpirit spirit = npc.modNPC as ChaosSpirit.ChaosSpirit;
                    if (spirit != null)
                    {
                        spirit.HandlePacket(reader);
                    }
                    ChaosSpirit2 spirit2 = npc.modNPC as ChaosSpirit2;
                    if (spirit2 != null)
                    {
                        spirit2.HandlePacket(reader);
                    }
                    ChaosSpirit3 spirit3 = npc.modNPC as ChaosSpirit3;
                    if (spirit3 != null)
                    {
                        spirit3.HandlePacket(reader);
                    }
                }
            }
            else if (type == MessageType.PushChaosArm)
            {
                NPC     npc  = Main.npc[reader.ReadInt32()];
                Vector2 push = new Vector2(reader.ReadSingle(), reader.ReadSingle());
                if (npc.active)
                {
                    ChaosSpiritArm arm = npc.modNPC as ChaosSpiritArm;
                    if (arm != null)
                    {
                        arm.offset += push;
                        if (Main.netMode == 2)
                        {
                            ModPacket packet = GetPacket();
                            packet.Write((byte)MessageType.PushChaosArm);
                            packet.Write(push.X);
                            packet.Write(push.Y);
                            packet.Send(-1, whoAmI);
                        }
                    }
                }
            }
            else if (type == MessageType.TerraSpirit)
            {
                NPC npc = Main.npc[reader.ReadInt32()];
                if (npc.active)
                {
                    TerraSpirit.TerraSpirit spirit = npc.modNPC as TerraSpirit.TerraSpirit;
                    if (spirit != null)
                    {
                        spirit.HandlePacket(reader);
                    }
                }
            }
            else if (type == MessageType.TerraLives)
            {
                Player player = Main.player[reader.ReadInt32()];
                int    lives  = reader.ReadInt32();
                player.GetModPlayer <BluemagicPlayer>().terraLives = lives;
                if (lives > 0)
                {
                    NetworkText text;
                    if (lives == 1)
                    {
                        text = NetworkText.FromKey("Mods.Bluemagic.LifeLeft", player.name);
                    }
                    else
                    {
                        text = NetworkText.FromKey("Mods.Bluemagic.LivesLeft", player.name, lives);
                    }
                    NetMessage.BroadcastChatMessage(text, new Color(255, 25, 25));
                }
            }
            else if (type == MessageType.GoldBlob)
            {
                NPC   npc   = Main.npc[reader.ReadByte()];
                float value = reader.ReadByte();
                if (npc.active && npc.type == NPCType("GoldBlob"))
                {
                    npc.localAI[0] = value;
                }
            }
            else if (type == MessageType.ExtraLives)
            {
                BluemagicPlayer player = Main.player[Main.myPlayer].GetModPlayer <BluemagicPlayer>();
                if (player.terraLives > 0)
                {
                    player.terraLives += 3;
                }
            }
            else if (type == MessageType.BulletNegative)
            {
                NPC npc = Main.npc[reader.ReadByte()];
                if (npc.active && npc.type == NPCType("TerraSpirit2") && npc.modNPC is TerraSpirit2)
                {
                    var bullets = ((TerraSpirit2)npc.modNPC).bullets;
                    int count   = reader.ReadByte();
                    for (int k = 0; k < count; k++)
                    {
                        bullets.Add(new BulletNegative(reader.ReadVector2(), reader.ReadVector2()));
                    }
                }
            }
            else if (type == MessageType.CustomStats)
            {
                byte            byte1     = reader.ReadByte();
                byte            byte2     = reader.ReadByte();
                Player          player    = Main.player[byte1];
                BluemagicPlayer modPlayer = player.GetModPlayer <BluemagicPlayer>();
                CustomStats     stats     = byte2 == 0 ? modPlayer.chaosStats : modPlayer.cataclysmStats;
                stats.NetReceive(reader);
                if (Main.netMode == 2)
                {
                    ModPacket packet = GetPacket(512);
                    packet.Write(byte1);
                    packet.Write(byte2);
                    stats.NetSend(packet);
                    packet.Send(-1, whoAmI);
                }
            }
        }
Example #20
0
        public void BeCompanionCube()
        {
            Player player = Main.player[projectile.owner];
            Color  color;

            color = Lighting.GetColor((int)projectile.Center.X / 16, (int)projectile.Center.Y / 16);
            Vector3 vector3_1 = color.ToVector3();

            color = Lighting.GetColor((int)player.Center.X / 16, (int)player.Center.Y / 16);
            Vector3 vector3_2 = color.ToVector3();

            if (vector3_1.Length() < 0.15f && vector3_2.Length() < 0.15)
            {
                notlocalai1 += 1;
            }
            else if (notlocalai1 > 0)
            {
                notlocalai1 -= 1;
            }

            notlocalai1 = MathHelper.Clamp(notlocalai1, -3600f, 600);

            if (notlocalai1 > Main.rand.Next(300, 600) && !player.immune)
            {
                notlocalai1 = Main.rand.Next(30) * -10 - 300;

                switch (Main.rand.Next(3))
                {
                case 0:     //stab
                    if (projectile.owner == Main.myPlayer)
                    {
                        Main.PlaySound(SoundID.Item1, projectile.Center);
                        player.Hurt(Terraria.DataStructures.PlayerDeathReason.ByOther(6), 777, 0, false, false, false, -1);
                        player.immune     = false;
                        player.immuneTime = 0;
                    }
                    break;

                case 1:     //spawn mutant
                    if (Main.netMode != NetmodeID.MultiplayerClient)
                    {
                        int n = NPC.NewNPC((int)projectile.Center.X, (int)projectile.Center.Y, ModContent.NPCType <NPCs.MutantBoss.MutantBoss>());
                        if (Main.netMode == NetmodeID.Server)
                        {
                            NetMessage.BroadcastChatMessage(Terraria.Localization.NetworkText.FromLiteral("Mutant has awoken!"), new Color(175, 75, 255));
                            if (n != Main.maxNPCs)
                            {
                                NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, n);
                            }
                        }
                        else
                        {
                            Main.NewText("Mutant has awoken!", 175, 75, 255);
                        }
                    }
                    break;

                default:
                    if (projectile.owner == Main.myPlayer)
                    {
                        CombatText.NewText(projectile.Hitbox, Color.LimeGreen, "You think you're safe?");
                    }
                    break;
                }
            }
        }
Example #21
0
 public static void SpawnBoss(Player player, int bossType, bool spawnMessage = true, Vector2 npcCenter = default, string overrideDisplayName = "", bool namePlural = false)
 {
     if (npcCenter == default)
     {
         npcCenter = player.Center;
     }
     if (Main.netMode != 1)
     {
         if (NPC.AnyNPCs(bossType))
         {
             return;
         }
         int npcID = NPC.NewNPC((int)npcCenter.X, (int)npcCenter.Y, bossType, 0);
         Main.npc[npcID].ai[3]      = -1;
         Main.npc[npcID].Center     = npcCenter;
         Main.npc[npcID].netUpdate2 = true;
         if (spawnMessage)
         {
             string npcName = !string.IsNullOrEmpty(Main.npc[npcID].GivenName) ? Main.npc[npcID].GivenName : overrideDisplayName;
             if ((npcName == null || npcName.Equals("")) && Main.npc[npcID].modNPC != null)
             {
                 npcName = Main.npc[npcID].modNPC.DisplayName.GetDefault();
             }
             if (namePlural)
             {
                 if (Main.netMode == NetmodeID.SinglePlayer)
                 {
                     if (Main.netMode != 1)
                     {
                         BaseUtility.Chat(npcName + Language.GetTextValue("Mods.AAMod.Common.BosshasAwoken"), 175, 75, 255, false);
                     }
                 }
                 else
                 if (Main.netMode == NetmodeID.Server)
                 {
                     NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(npcName + Language.GetTextValue("Mods.AAMod.Common.BosshasAwoken")), new Color(175, 75, 255), -1);
                 }
             }
             else
             {
                 if (Main.netMode == NetmodeID.SinglePlayer)
                 {
                     if (Main.netMode != 1)
                     {
                         BaseUtility.Chat(Language.GetTextValue("Announcement.HasAwoken", npcName), 175, 75, 255, false);
                     }
                 }
                 else
                 if (Main.netMode == NetmodeID.Server)
                 {
                     NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[]
                     {
                         NetworkText.FromLiteral(npcName)
                     }), new Color(175, 75, 255), -1);
                 }
             }
         }
     }
     else
     {
         //I have no idea how to convert this to the standard system so im gonna post this method too lol
         AANet.SendNetMessage(AANet.SummonNPCFromClient, (byte)player.whoAmI, (short)bossType, spawnMessage, (int)npcCenter.X, (int)npcCenter.Y, overrideDisplayName, namePlural);
     }
 }
Example #22
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            CheatSheetMessageType msgType = (CheatSheetMessageType)reader.ReadByte();
            string key;

            switch (msgType)
            {
            case CheatSheetMessageType.SpawnNPC:
                int npcType = reader.ReadInt32();
                int netID   = reader.ReadInt32();
                NPCSlot.HandleNPC(npcType, netID, true, whoAmI);
                key = "Mods.CheatSheet.MobBrowser.SpawnNPCNotification";
                NetMessage.BroadcastChatMessage(NetworkText.FromKey(key, netID, Netplay.Clients[whoAmI].Name), Color.Azure);
                //message = "Spawned " + netID + " by " + Netplay.Clients[whoAmI].Name;
                //NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
                break;

            case CheatSheetMessageType.QuickClear:
                int clearType = reader.ReadInt32();
                switch (clearType)
                {
                case 0:
                    key = "Mods.CheatSheet.QuickClear.ItemClearNotification";
                    //message = "Items were cleared by ";
                    break;

                case 1:
                    key = "Mods.CheatSheet.QuickClear.ProjectileClearNotification";
                    //message = "Projectiles were cleared by ";
                    break;

                default:
                    key = "";
                    break;
                }
                //message += Netplay.Clients[whoAmI].Name;
                QuickClearHotbar.HandleQuickClear(clearType, true, whoAmI);
                NetMessage.BroadcastChatMessage(NetworkText.FromKey(key, Netplay.Clients[whoAmI].Name), Color.Azure);
                //NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
                break;

            case CheatSheetMessageType.VacuumItems:
                Hotbar.HandleVacuum(true, whoAmI);
                key = "Mods.CheatSheet.Vacuum.VacuumNotification";
                NetMessage.BroadcastChatMessage(NetworkText.FromKey(key, Netplay.Clients[whoAmI].Name), Color.Azure);
                //message = "Items on the ground were vacuumed by " + Netplay.Clients[whoAmI].Name;
                //NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
                break;

            case CheatSheetMessageType.ButcherNPCs:
                NPCButchererHotbar.HandleButcher(reader.ReadInt32(), true);
                key = "Mods.CheatSheet.Butcherer.ButcherNotification";
                NetMessage.BroadcastChatMessage(NetworkText.FromKey(key, Netplay.Clients[whoAmI].Name), Color.Azure);
                //message = "NPCs were butchered by " + Netplay.Clients[whoAmI].Name;
                //NetMessage.SendData(25, -1, -1, message, 255, Color.Azure.R, Color.Azure.G, Color.Azure.B, 0);
                break;

            case CheatSheetMessageType.TeleportPlayer:
                QuickTeleportHotbar.HandleTeleport(reader.ReadInt32(), true, whoAmI);
                break;

            case CheatSheetMessageType.SetSpawnRate:
                SpawnRateMultiplier.HandleSetSpawnRate(reader, whoAmI);
                break;

            case CheatSheetMessageType.SpawnRateSet:
                SpawnRateMultiplier.HandleSpawnRateSet(reader, whoAmI);
                break;

            case CheatSheetMessageType.RequestFilterNPC:
                int  netID2  = reader.ReadInt32();
                bool desired = reader.ReadBoolean();
                NPCBrowser.FilterNPC(netID2, desired);
                ConfigurationLoader.SaveSetting();

                var packet = GetPacket();
                packet.Write((byte)CheatSheetMessageType.InformFilterNPC);
                packet.Write(netID2);
                packet.Write(desired);
                packet.Send();
                break;

            case CheatSheetMessageType.InformFilterNPC:
                int  netID3   = reader.ReadInt32();
                bool desired2 = reader.ReadBoolean();
                NPCBrowser.FilterNPC(netID3, desired2);
                NPCBrowser.needsUpdate = true;
                break;

            //case CheatSheetMessageType.RequestToggleNPCSpawn:
            //	NPCSlot.HandleFilterRequest(reader.ReadInt32(), reader.ReadInt32(), true);
            //	break;
            default:
                ErrorLogger.Log("CheatSheet: Unknown Message type: " + msgType);
                break;
            }
        }
        public override void PreUpdate()
        {
            //QwertyMethods.ServerClientCheck(DinoKillCount);

            if (DinoEvent)
            {
            }
            if (NPC.downedMoonlord)
            {
                MaxDinoKillCount = 300;
                if (DinoKillCount >= MaxDinoKillCount)
                {
                    DinoEvent             = false;
                    downedDinoMilitia     = true;
                    downedDinoMilitiaHard = true;
                    if (Main.netMode == NetmodeID.Server)
                    {
                        NetMessage.SendData(MessageID.WorldData); // Immediately inform clients of new world state.
                    }
                    string key          = "Mods.QwertysRandomContent.DinoDefeat";
                    Color  messageColor = Color.Orange;
                    if (Main.netMode == 2) // Server
                    {
                        NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor);
                    }
                    else if (Main.netMode == 0) // Single Player
                    {
                        Main.NewText(Language.GetTextValue(key), messageColor);
                    }
                    DinoKillCount = 0;
                }
            }
            else
            {
                MaxDinoKillCount = 150;
                if (DinoKillCount >= MaxDinoKillCount)
                {
                    DinoEvent         = false;
                    downedDinoMilitia = true;
                    if (Main.netMode == NetmodeID.Server)
                    {
                        NetMessage.SendData(MessageID.WorldData); // Immediately inform clients of new world state.
                    }
                    string key          = "Mods.QwertysRandomContent.DinoDefeat";
                    Color  messageColor = Color.Orange;
                    if (Main.netMode == 2) // Server
                    {
                        NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor);
                    }
                    else if (Main.netMode == 0) // Single Player
                    {
                        Main.NewText(Language.GetTextValue(key), messageColor);
                    }
                    DinoKillCount = 0;
                }
            }

            if (!hasGeneratedRhuthinium && NPC.downedBoss3)
            {
                for (int i = 0; i < (int)((double)(Main.maxTilesX * Main.maxTilesY) * 6E-06); i++)
                {
                    WorldGen.OreRunner(
                        WorldGen.genRand.Next(0, Main.maxTilesX),                         // X Coord of the tile
                        WorldGen.genRand.Next((int)Main.rockLayer, Main.maxTilesY - 200), // Y Coord of the tile
                        (double)WorldGen.genRand.Next(40, 40),                            // Strength (High = more)
                        WorldGen.genRand.Next(2, 6),                                      // Steps
                        (ushort)mod.TileType("RhuthiniumOre")                             // The tile type that will be spawned
                        );                                                                // Overrides existing tiles
                }
                string key          = "Mods.QwertysRandomContent.RhuthiniumGenerates";
                Color  messageColor = Color.Cyan;
                if (Main.netMode == 2) // Server
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor);
                }
                else if (Main.netMode == 0) // Single Player
                {
                    Main.NewText(Language.GetTextValue(key), messageColor);
                }
                hasGeneratedRhuthinium = true;
            }
        }
Example #24
0
        public void ProcessMessage(string text, byte clientId)
        {
            int num = Main.rand.Next(1, 101);

            NetMessage.BroadcastChatMessage(NetworkText.FromFormattable("*{0} {1} {2}", (object)Main.player[(int)clientId].name, (object)Lang.mp[9].ToNetworkText(), (object)num), RollCommand.RESPONSE_COLOR, -1);
        }
Example #25
0
        private bool AluminumMeteor(On.Terraria.WorldGen.orig_meteor orig, int i, int j)
        {
            Main.LocalPlayer.GetModPlayer <StarlightPlayer>().Shake += 80;
            Main.PlaySound(SoundID.DD2_ExplosiveTrapExplode);

            if (Main.rand.Next(3) > (StarlightWorld.HasFlag(WorldFlags.AluminumMeteors) ? 0 : 1))
            {
                Point16 target = new Point16();

                while (!CheckAroundMeteor(target))
                {
                    int x = Main.rand.Next(Main.maxTilesX);

                    for (int y = 0; y < Main.maxTilesY; y++)
                    {
                        if (Framing.GetTileSafely(x, y).active())
                        {
                            target = new Point16(x, y - 20);
                            break;
                        }
                    }
                }

                for (int x = -10; x < 10; x++)
                {
                    for (int y = -30; y < 30; y++)
                    {
                        if (Math.Abs(x) < (10 - Math.Abs(y) / 3) + StarlightWorld.genNoise.GetPerlin(x * 4, y * 4) * 8)
                        {
                            WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType <Tiles.Moonstone.MoonstoneOre>(), true, true);
                        }
                    }
                }

                for (int x = -15; x < 15; x++)
                {
                    for (int y = 0; y < 40; y++)
                    {
                        if (Math.Abs(x) < (10 - Math.Abs(y) / 3) + StarlightWorld.genNoise.GetPerlin(x * 4, y * 4) * 8)
                        {
                            WorldGen.PlaceTile(target.X + x, target.Y + y, ModContent.TileType <Tiles.Moonstone.MoonstoneOre>(), true, true);
                        }
                    }
                }

                if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    Main.NewText("A shard of the moon has landed!", new Color(107, 233, 231));
                }

                else if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral("A shard of the moon has landed!"), new Color(107, 233, 231));
                }

                return(true);
            }

            else
            {
                return(orig(i, j));
            }
        }
Example #26
0
 public override bool Shoot(Player player, ref Vector2 position, ref float speedX, ref float speedY, ref int type, ref int damage, ref float knockBack)
 {
     if (Main.raining == true)
     {
         if (Main.netMode == 2) // Server
         {
             NetMessage.BroadcastChatMessage(NetworkText.FromKey(rainoff), messageColor);
         }
         else if (Main.netMode == 0) // Single Player
         {
             Main.NewText(Language.GetTextValue(rainoff), messageColor);
         }
         Main.raining    = false;
         Main.rainTime   = 0;
         Main.maxRaining = 0.0f;
         return(true);
     }
     else if (Main.raining == false && Main.slimeRain == false)
     {
         if (Main.netMode == 2) // Server
         {
             NetMessage.BroadcastChatMessage(NetworkText.FromKey(rainon), messageColor);
         }
         else if (Main.netMode == 0) // Single Player
         {
             Main.NewText(Language.GetTextValue(rainon), messageColor);
         }
         int maxValue1 = 86400;
         int maxValue2 = maxValue1 / 24;
         Main.rainTime = Main.rand.Next(maxValue2 * 8, maxValue1);
         if (Main.rand.Next(3) == 0)
         {
             Main.rainTime += Main.rand.Next(0, maxValue2);
         }
         if (Main.rand.Next(4) == 0)
         {
             Main.rainTime += Main.rand.Next(0, maxValue2 * 2);
         }
         if (Main.rand.Next(5) == 0)
         {
             Main.rainTime += Main.rand.Next(0, maxValue2 * 2);
         }
         if (Main.rand.Next(6) == 0)
         {
             Main.rainTime += Main.rand.Next(0, maxValue2 * 3);
         }
         if (Main.rand.Next(7) == 0)
         {
             Main.rainTime += Main.rand.Next(0, maxValue2 * 4);
         }
         if (Main.rand.Next(8) == 0)
         {
             Main.rainTime += Main.rand.Next(0, maxValue2 * 5);
         }
         float num = 1f;
         if (Main.rand.Next(2) == 0)
         {
             num += 0.05f;
         }
         if (Main.rand.Next(3) == 0)
         {
             num += 0.1f;
         }
         if (Main.rand.Next(4) == 0)
         {
             num += 0.15f;
         }
         if (Main.rand.Next(5) == 0)
         {
             num += 0.2f;
         }
         Main.rainTime = (int)((double)Main.rainTime * (double)num);
         RainStuff();
         Main.raining = true;
         return(true);
     }
     return(false);
 }
Example #27
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;
            }
        }
        public static void SpawnOnPlayerButNoTextAndReturnValue(int plr, int Type, out int npc)
        {
            npc = -1;
            if (Main.netMode == 1)
            {
                return;
            }
            if (Type == 262 && NPC.AnyNPCs(262))
            {
                return;
            }
            if (Type == 245)
            {
                if (NPC.AnyNPCs(245))
                {
                    return;
                }
                try
                {
                    int num  = (int)Main.player[plr].Center.X / 16;
                    int num2 = (int)Main.player[plr].Center.Y / 16;
                    int num3 = 0;
                    int num4 = 0;
                    for (int i = num - 20; i < num + 20; i++)
                    {
                        for (int j = num2 - 20; j < num2 + 20; j++)
                        {
                            if (Main.tile[i, j].active() && Main.tile[i, j].type == 237 && Main.tile[i, j].frameX == 18 && Main.tile[i, j].frameY == 0)
                            {
                                num3 = i;
                                num4 = j;
                            }
                        }
                    }
                    if (num3 > 0 && num4 > 0)
                    {
                        int num5 = num4 - 15;
                        int num6 = num4 - 15;
                        for (int k = num4; k > num4 - 100; k--)
                        {
                            if (WorldGen.SolidTile(num3, k))
                            {
                                num5 = k;
                                break;
                            }
                        }
                        for (int l = num4; l < num4 + 100; l++)
                        {
                            if (WorldGen.SolidTile(num3, l))
                            {
                                num6 = l;
                                break;
                            }
                        }
                        num4 = (num5 + num5 + num6) / 3;
                        int num7 = NPC.NewNPC(num3 * 16 + 8, num4 * 16, 245, 100, 0f, 0f, 0f, 0f, 255);
                        npc = num7;
                        Main.npc[num7].target = plr;
                        string typeName = Main.npc[num7].TypeName;
                    }
                }
                catch
                {
                }
                return;
            }
            else if (Type == 370)
            {
                Player player = Main.player[plr];
                if (!player.active || player.dead)
                {
                    return;
                }
                int m = 0;
                while (m < 1000)
                {
                    Projectile projectile = Main.projectile[m];
                    if (projectile.active && projectile.bobber && projectile.owner == plr)
                    {
                        int    num8      = NPC.NewNPC((int)projectile.Center.X, (int)projectile.Center.Y + 100, 370, 0, 0f, 0f, 0f, 0f, 255);
                        string typeName2 = Main.npc[num8].TypeName;
                        if (Main.netMode == 0)
                        {
                            Main.NewText(Language.GetTextValue("Announcement.HasAwoken", typeName2), 175, 75, 255, false);
                            return;
                        }
                        if (Main.netMode == 2)
                        {
                            NetMessage.BroadcastChatMessage(NetworkText.FromKey("Announcement.HasAwoken", new object[]
                            {
                                Main.npc[num8].GetTypeNetName()
                            }), new Color(175, 75, 255), -1);
                            return;
                        }
                        break;
                    }
                    else
                    {
                        m++;
                    }
                }
                return;
            }
            else
            {
                if (Type != 398)
                {
                    bool flag  = false;
                    int  num9  = 0;
                    int  num10 = 0;
                    int  num11 = (int)(Main.player[plr].position.X / 16f) - Assist.spawnRangeX * 2;
                    int  num12 = (int)(Main.player[plr].position.X / 16f) + Assist.spawnRangeX * 2;
                    int  num13 = (int)(Main.player[plr].position.Y / 16f) - Assist.spawnRangeY * 2;
                    int  num14 = (int)(Main.player[plr].position.Y / 16f) + Assist.spawnRangeY * 2;
                    int  num15 = (int)(Main.player[plr].position.X / 16f) - NPC.safeRangeX;
                    int  num16 = (int)(Main.player[plr].position.X / 16f) + NPC.safeRangeX;
                    int  num17 = (int)(Main.player[plr].position.Y / 16f) - NPC.safeRangeY;
                    int  num18 = (int)(Main.player[plr].position.Y / 16f) + NPC.safeRangeY;
                    if (num11 < 0)
                    {
                        num11 = 0;
                    }
                    if (num12 > Main.maxTilesX)
                    {
                        num12 = Main.maxTilesX;
                    }
                    if (num13 < 0)
                    {
                        num13 = 0;
                    }
                    if (num14 > Main.maxTilesY)
                    {
                        num14 = Main.maxTilesY;
                    }
                    for (int n = 0; n < 1000; n++)
                    {
                        int num19 = 0;
                        while (num19 < 100)
                        {
                            int num20 = Main.rand.Next(num11, num12);
                            int num21 = Main.rand.Next(num13, num14);
                            if (Main.tile[num20, num21].nactive() && Main.tileSolid[(int)Main.tile[num20, num21].type])
                            {
                                goto IL_730;
                            }
                            if ((!Main.wallHouse[(int)Main.tile[num20, num21].wall] || n >= 999) && (Type != 50 || n >= 500 || Main.tile[num21, num21].wall <= 0))
                            {
                                int num22 = num21;
                                while (num22 < Main.maxTilesY)
                                {
                                    if (Main.tile[num20, num22].nactive() && Main.tileSolid[(int)Main.tile[num20, num22].type])
                                    {
                                        if (num20 < num15 || num20 > num16 || num22 < num17 || num22 > num18 || n == 999)
                                        {
                                            ushort num23 = Main.tile[num20, num22].type;
                                            num9  = num20;
                                            num10 = num22;
                                            flag  = true;
                                            break;
                                        }
                                        break;
                                    }
                                    else
                                    {
                                        num22++;
                                    }
                                }
                                if (flag && Type == 50 && n < 900)
                                {
                                    int num24 = 20;
                                    if (!Collision.CanHitLine(new Vector2((float)num9, (float)(num10 - 1)) * 16f, 16, 16, new Vector2((float)num9, (float)(num10 - 1 - num24)) * 16f, 16, 16) || !Collision.CanHitLine(new Vector2((float)num9, (float)(num10 - 1 - num24)) * 16f, 16, 16, Main.player[plr].Center, 0, 0))
                                    {
                                        num9  = 0;
                                        num10 = 0;
                                        flag  = false;
                                    }
                                }
                                if (!flag || n >= 999)
                                {
                                    goto IL_730;
                                }
                                int num25 = num9 - Assist.spawnSpaceX / 2;
                                int num26 = num9 + Assist.spawnSpaceX / 2;
                                int num27 = num10 - Assist.spawnSpaceY;
                                int num28 = num10;
                                if (num25 < 0)
                                {
                                    flag = false;
                                }
                                if (num26 > Main.maxTilesX)
                                {
                                    flag = false;
                                }
                                if (num27 < 0)
                                {
                                    flag = false;
                                }
                                if (num28 > Main.maxTilesY)
                                {
                                    flag = false;
                                }
                                if (flag)
                                {
                                    for (int num29 = num25; num29 < num26; num29++)
                                    {
                                        for (int num30 = num27; num30 < num28; num30++)
                                        {
                                            if (Main.tile[num29, num30].nactive() && Main.tileSolid[(int)Main.tile[num29, num30].type])
                                            {
                                                flag = false;
                                                break;
                                            }
                                        }
                                    }
                                    goto IL_730;
                                }
                                goto IL_730;
                            }
IL_728:
                            num19++;
                            continue;
IL_730:
                            if (!flag && !flag)
                            {
                                goto IL_728;
                            }
                            break;
                        }
                        if (flag && n < 999)
                        {
                            Rectangle rectangle = new Rectangle(num9 * 16, num10 * 16, 16, 16);
                            for (int num31 = 0; num31 < 255; num31++)
                            {
                                if (Main.player[num31].active)
                                {
                                    Rectangle rectangle2 = new Rectangle((int)(Main.player[num31].position.X + (float)(Main.player[num31].width / 2) - (float)(NPC.sWidth / 2) - (float)NPC.safeRangeX), (int)(Main.player[num31].position.Y + (float)(Main.player[num31].height / 2) - (float)(NPC.sHeight / 2) - (float)NPC.safeRangeY), NPC.sWidth + NPC.safeRangeX * 2, NPC.sHeight + NPC.safeRangeY * 2);
                                    if (rectangle.Intersects(rectangle2))
                                    {
                                        flag = false;
                                    }
                                }
                            }
                        }
                        if (flag)
                        {
                            break;
                        }
                    }
                    if (flag)
                    {
                        int num32 = NPC.NewNPC(num9 * 16 + 8, num10 * 16, Type, 1, 0f, 0f, 0f, 0f, 255);
                        npc = num32;
                        if (num32 == 200)
                        {
                            return;
                        }
                        Main.npc[num32].target    = plr;
                        Main.npc[num32].timeLeft *= 20;
                        string typeName3 = Main.npc[num32].TypeName;
                        if (Main.netMode == 2 && num32 < 200)
                        {
                            NetMessage.SendData(23, -1, -1, null, num32, 0f, 0f, 0f, 0, 0, 0);
                        }
                        if (Type == 125)
                        {
                            if (Main.netMode == 0)
                            {
                                Main.NewText(Lang.misc[48].Value, 175, 75, 255, false);
                                return;
                            }
                            if (Main.netMode == 2)
                            {
                                NetMessage.BroadcastChatMessage(Lang.misc[48].ToNetworkText(), new Color(175, 75, 255), -1);
                                return;
                            }
                        }
                        else if (Type != 82 && Type != 126 && Type != 50 && Type != 398 && Type != 551)
                        {
                        }
                    }
                    return;
                }
                Player player2 = Main.player[plr];
                npc = NPC.NewNPC((int)player2.Center.X, (int)player2.Center.Y - 150, Type, 0, 0f, 0f, 0f, 0f, 255);
                return;
            }
        }
Example #29
0
 public override void PostUpdate()
 {
     if (Main.dayTime && VolcanoCountdown == 0)
     {
         if (VolcanoCooldown > 0)
         {
             VolcanoCooldown--;
         }
         if (VolcanoCooldown <= 0 && Main.rand.Next(VolcanoChance) == 0)
         {
             string key          = "Mods.ExampleMod.VolcanoWarning";
             Color  messageColor = Color.Orange;
             if (Main.netMode == 2)                     // Server
             {
                 NetMessage.BroadcastChatMessage(NetworkText.FromKey(key), messageColor);
             }
             else if (Main.netMode == 0)                     // Single Player
             {
                 Main.NewText(Language.GetTextValue(key), messageColor);
             }
             VolcanoCountdown = DefaultVolcanoCountdown;
             VolcanoCooldown  = DefaultVolcanoCooldown;
         }
     }
     if (VolcanoCountdown > 0)
     {
         VolcanoCountdown--;
         if (VolcanoCountdown == 0)
         {
             VolcanoTremorTime = DefaultVolcanoTremorTime;
             // Since PostUpdate only happens in single and server, we need to inform the clients to shake if this is a server
             if (Main.netMode == 2)
             {
                 var netMessage = mod.GetPacket();
                 netMessage.Write((byte)ExampleModMessageType.SetTremorTime);
                 netMessage.Write(VolcanoTremorTime);
                 netMessage.Send();
             }
             for (int playerIndex = 0; playerIndex < 255; playerIndex++)
             {
                 if (Main.player[playerIndex].active)
                 {
                     Player  player       = Main.player[playerIndex];
                     int     speed        = 12;
                     float   spawnX       = Main.rand.Next(1000) - 500 + player.Center.X;
                     float   spawnY       = -1000 + player.Center.Y;
                     Vector2 baseSpawn    = new Vector2(spawnX, spawnY);
                     Vector2 baseVelocity = player.Center - baseSpawn;
                     baseVelocity.Normalize();
                     baseVelocity = baseVelocity * speed;
                     List <int> identities = new List <int>();
                     for (int i = 0; i < VolcanoProjectiles; i++)
                     {
                         Vector2 spawn = baseSpawn;
                         spawn.X = spawn.X + i * 30 - (VolcanoProjectiles * 15);
                         Vector2 velocity = baseVelocity;
                         velocity   = baseVelocity.RotatedBy(MathHelper.ToRadians(-VolcanoAngleSpread / 2 + (VolcanoAngleSpread * i / (float)VolcanoProjectiles)));
                         velocity.X = velocity.X + 3 * Main.rand.NextFloat() - 1.5f;
                         int projectile = Projectile.NewProjectile(spawn.X, spawn.Y, velocity.X, velocity.Y, Main.rand.Next(ProjectileID.MolotovFire, ProjectileID.MolotovFire3 + 1), 10, 10f, Main.myPlayer, 0f, 0f);
                         Main.projectile[projectile].hostile = true;
                         Main.projectile[projectile].Name    = "Volcanic Rubble";
                         identities.Add(Main.projectile[projectile].identity);
                     }
                     if (Main.netMode == 2)
                     {
                         var netMessage = mod.GetPacket();
                         netMessage.Write((byte)ExampleModMessageType.VolcanicRubbleMultiplayerFix);
                         netMessage.Write(identities.Count);
                         for (int i = 0; i < identities.Count; i++)
                         {
                             netMessage.Write(identities[i]);
                         }
                         netMessage.Send();
                     }
                 }
             }
         }
     }
 }
        void SendStats(NPC npc)
        {
            try
            {
                //System.Console.WriteLine("SendStats");

                StringBuilder sb = new StringBuilder();
                sb.Append("Damage stats for " + Lang.GetNPCNameValue(npc.type) + ": ");
                for (int i = 0; i < 256; i++)
                {
                    int playerDamage = damageDone[i];
                    if (playerDamage > 0)
                    {
                        if (i == 255)
                        {
                            sb.Append($"Traps/TownNPC: {playerDamage}, ");
                        }
                        else
                        {
                            sb.Append($"{Main.player[i].name}: {playerDamage}, ");
                        }
                    }
                }
                sb.Length -= 2;                 // removes last ,
                Color messageColor = Color.Orange;

                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(sb.ToString()), messageColor);

                    var netMessage = mod.GetPacket();
                    netMessage.Write((byte)DPSExtremeMessageType.InformClientsCurrentBossTotals);
                    netMessage.Write(true);
                    netMessage.Write((byte)npc.whoAmI);
                    DPSExtremeGlobalNPC bossGlobalNPC = npc.GetGlobalNPC <DPSExtremeGlobalNPC>();
                    byte count = 0;
                    for (int i = 0; i < 256; i++)
                    {
                        if (bossGlobalNPC.damageDone[i] > 0)
                        {
                            count++;
                        }
                    }
                    netMessage.Write(count);
                    for (int i = 0; i < 256; i++)
                    {
                        if (bossGlobalNPC.damageDone[i] > 0)
                        {
                            netMessage.Write((byte)i);
                            netMessage.Write(bossGlobalNPC.damageDone[i]);
                        }
                    }
                    netMessage.Send();

                    Dictionary <byte, int> stats = new Dictionary <byte, int>();
                    for (int i = 0; i < 256; i++)
                    {
                        if (bossGlobalNPC.damageDone[i] > -1)
                        {
                            stats[(byte)i] = bossGlobalNPC.damageDone[i];
                        }
                    }
                    DPSExtreme.instance.InvokeOnSimpleBossStats(stats);
                }
                else if (Main.netMode == NetmodeID.SinglePlayer)
                {
                    Main.NewText(sb.ToString(), messageColor);
                }
                else if (Main.netMode == NetmodeID.MultiplayerClient)
                {
                    // MP clients should just wait for message.
                }
            }
            catch (Exception e)
            {
                //ErrorLogger.Log("SendStats" + e.Message);
            }
        }