Exemplo n.º 1
0
        public bool CheckWorldRecords(int recordIndex)           // Returns whether or not to stop the New Record! text from appearing to show World Record! instead
        {
            Player       player       = Main.LocalPlayer;
            PlayerAssist modPlayer    = player.GetModPlayer <PlayerAssist>();
            BossStats    playerRecord = modPlayer.AllBossRecords[recordIndex].stat;
            WorldStats   worldRecord  = WorldAssist.worldRecords[recordIndex].stat;
            bool         newRecord    = false;

            if (playerRecord.durationBest < worldRecord.durationWorld || worldRecord.durationWorld <= 0)
            {
                worldRecord.durationWorld  = playerRecord.durationBest;
                worldRecord.durationHolder = player.name;
                newRecord = true;
            }
            if (playerRecord.hitsTakenBest < worldRecord.hitsTakenWorld || worldRecord.hitsTakenWorld < 0)
            {
                worldRecord.hitsTakenWorld  = playerRecord.hitsTakenBest;
                worldRecord.dodgeTimeWorld  = playerRecord.dodgeTimeBest;
                worldRecord.hitsTakenHolder = player.name;
                newRecord = true;
            }
            if (playerRecord.healthLossBest < worldRecord.healthLossWorld || worldRecord.healthLossWorld <= 0)
            {
                worldRecord.healthLossWorld    = playerRecord.healthLossBest;
                worldRecord.healthAtStartWorld = playerRecord.healthAtStart;
                worldRecord.healthLossHolder   = player.name;
                newRecord = true;
            }
            return(newRecord);
        }
Exemplo n.º 2
0
        public bool CheckWorldRecords(int recordIndex)           // Returns whether or not to stop the New Record! text from appearing to show World Record! instead
        {
            Player       player       = Main.LocalPlayer;
            PlayerAssist modPlayer    = player.GetModPlayer <PlayerAssist>();
            BossStats    playerRecord = modPlayer.AllBossRecords[recordIndex].stat;
            WorldStats   worldRecord  = WorldAssist.worldRecords[recordIndex].stat;
            bool         newRecord    = false;

            if (playerRecord.durationBest < worldRecord.durationWorld || worldRecord.durationWorld <= 0)
            {
                // only say World Record if you the player is on a server OR if the player wasn't holding the previoes record
                newRecord = (worldRecord.durationHolder != player.name && worldRecord.durationHolder != "") || Main.netMode == NetmodeID.MultiplayerClient;
                worldRecord.durationWorld  = playerRecord.durationBest;
                worldRecord.durationHolder = player.name;
            }
            if (playerRecord.hitsTakenBest < worldRecord.hitsTakenWorld || worldRecord.hitsTakenWorld < 0)
            {
                newRecord = (worldRecord.hitsTakenHolder != player.name && worldRecord.hitsTakenHolder != "") || Main.netMode == NetmodeID.MultiplayerClient;
                worldRecord.hitsTakenWorld  = playerRecord.hitsTakenBest;
                worldRecord.dodgeTimeWorld  = playerRecord.dodgeTimeBest;
                worldRecord.hitsTakenHolder = player.name;
            }
            if (playerRecord.healthLossBest < worldRecord.healthLossWorld || worldRecord.healthLossWorld <= 0)
            {
                newRecord = (worldRecord.healthLossHolder != player.name && worldRecord.healthLossHolder != "") || Main.netMode == NetmodeID.MultiplayerClient;
                worldRecord.healthLossWorld    = playerRecord.healthLossBest;
                worldRecord.healthAtStartWorld = playerRecord.healthAtStart;
                worldRecord.healthLossHolder   = player.name;
            }
            return(newRecord);
        }
Exemplo n.º 3
0
        public void CheckRecordsMultiplayer(NPC npc, int recordIndex)
        {
            string[] newRecordHolders = new string[] { "", "", "" };
            int[]    newWorldRecords  = new int[] {
                WorldAssist.worldRecords[recordIndex].stat.durationWorld,
                WorldAssist.worldRecords[recordIndex].stat.hitsTakenWorld,
                WorldAssist.worldRecords[recordIndex].stat.dodgeTimeWorld,
                WorldAssist.worldRecords[recordIndex].stat.healthLossWorld,
                WorldAssist.worldRecords[recordIndex].stat.healthAtStartWorld,
            };
            for (int i = 0; i < 255; i++)
            {
                Player player = Main.player[i];

                // Players must be active AND have interacted with the boss AND cannot have recordingstats disabled
                if (!player.active || !npc.playerInteraction[i])
                {
                    continue;
                }
                PlayerAssist     modPlayer = player.GetModPlayer <PlayerAssist>();
                List <BossStats> list      = BossChecklist.ServerCollectedRecords[i];
                BossStats        oldRecord = list[recordIndex];

                // Establish the new records for comparing
                BossStats newRecord = new BossStats()
                {
                    durationPrev      = modPlayer.RecordTimers[recordIndex],
                    hitsTakenPrev     = modPlayer.AttackCounter[recordIndex],
                    dodgeTimePrev     = modPlayer.DodgeTimer[recordIndex],
                    healthLossPrev    = modPlayer.BrinkChecker[recordIndex],
                    healthAtStartPrev = modPlayer.MaxHealth[recordIndex]
                };

                // Setup player's last fight attempt numbers
                modPlayer.durationLastFight   = newRecord.durationPrev;
                modPlayer.hitsTakenLastFight  = newRecord.hitsTakenPrev;
                modPlayer.healthLossLastFight = newRecord.healthLossPrev;

                RecordID specificRecord = RecordID.None;
                // For each record type we check if its beats the current record or if it is not set already
                // If it is beaten, we add a flag to specificRecord to allow newRecord's numbers to override the current record
                if (newRecord.durationPrev < oldRecord.durationBest || oldRecord.durationBest <= 0)
                {
                    Console.WriteLine($"{player.name} set a new record for DURATION: {newRecord.durationPrev} (Previous Record: {oldRecord.durationBest})");
                    specificRecord        |= RecordID.ShortestFightTime;
                    oldRecord.durationPrev = oldRecord.durationBest;
                    oldRecord.durationBest = newRecord.durationPrev;
                }
                else
                {
                    oldRecord.durationPrev = newRecord.durationPrev;
                }

                if (newRecord.hitsTakenPrev < oldRecord.hitsTakenBest || oldRecord.hitsTakenBest < 0)
                {
                    Console.WriteLine($"{player.name} set a new record for HITS TAKEN: {newRecord.hitsTakenPrev} (Previous Record: {oldRecord.hitsTakenBest})");
                    specificRecord         |= RecordID.LeastHits;
                    oldRecord.hitsTakenPrev = oldRecord.hitsTakenBest;
                    oldRecord.hitsTakenBest = newRecord.hitsTakenPrev;
                }
                else
                {
                    oldRecord.hitsTakenPrev = newRecord.hitsTakenPrev;
                }

                if (newRecord.dodgeTimePrev > oldRecord.dodgeTimeBest || oldRecord.dodgeTimeBest <= 0)
                {
                    Console.WriteLine($"{player.name} set a new record for BEST DODGE TIME: {newRecord.dodgeTimePrev} (Previous Record: {oldRecord.dodgeTimeBest})");
                    specificRecord         |= RecordID.DodgeTime;
                    oldRecord.dodgeTimeBest = newRecord.dodgeTimePrev;
                }

                if (newRecord.healthLossPrev > oldRecord.healthLossBest || oldRecord.healthLossBest <= 0)
                {
                    Console.WriteLine($"{player.name} set a new record for BEST HEALTH: {newRecord.healthLossPrev} (Previous Record: {oldRecord.healthLossBest})");
                    specificRecord          |= RecordID.BestBrink;
                    oldRecord.healthLossPrev = oldRecord.healthLossBest;
                    oldRecord.healthLossBest = newRecord.healthLossPrev;
                }
                else
                {
                    oldRecord.healthLossPrev = newRecord.healthLossPrev;
                }

                // Make and send the packet
                ModPacket packet = mod.GetPacket();
                packet.Write((byte)PacketMessageType.RecordUpdate);
                packet.Write((int)recordIndex);            // Which boss record are we changing?
                newRecord.NetSend(packet, specificRecord); // Writes all the variables needed
                packet.Send(toClient: i);                  // We send to the player. Only they need to see their own records
            }
            if (newRecordHolders.Any(x => x != ""))
            {
                WorldStats worldStats     = WorldAssist.worldRecords[recordIndex].stat;
                RecordID   specificRecord = RecordID.None;
                if (newRecordHolders[0] != "")
                {
                    specificRecord           |= RecordID.ShortestFightTime;
                    worldStats.durationHolder = newRecordHolders[0];
                    worldStats.durationWorld  = newWorldRecords[0];
                }
                if (newRecordHolders[1] != "")
                {
                    specificRecord            |= RecordID.LeastHits;
                    worldStats.hitsTakenHolder = newRecordHolders[1];
                    worldStats.hitsTakenWorld  = newWorldRecords[1];
                    worldStats.dodgeTimeWorld  = newWorldRecords[2];
                }
                if (newRecordHolders[2] != "")
                {
                    specificRecord |= RecordID.BestBrink;
                    worldStats.healthLossHolder   = newRecordHolders[2];
                    worldStats.healthLossWorld    = newWorldRecords[3];
                    worldStats.healthAtStartWorld = newWorldRecords[4];
                }

                ModPacket packet = mod.GetPacket();
                packet.Write((byte)PacketMessageType.WorldRecordUpdate);
                packet.Write((int)recordIndex); // Which boss record are we changing?
                worldStats.NetSend(packet, specificRecord);
                packet.Send();                  // To server (world data for everyone)
            }
        }
Exemplo n.º 4
0
 private WorldRecord(TagCompound tag)
 {
     bossName = tag.Get <string>(nameof(bossName));
     stat     = tag.Get <WorldStats>(nameof(stat));
 }
Exemplo n.º 5
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            PacketMessageType msgType = (PacketMessageType)reader.ReadByte();
            Player            player;
            PlayerAssist      modPlayer;

            switch (msgType)
            {
            // Sent from Client to Server
            case PacketMessageType.RequestHideBoss:
                //if (Main.netMode == NetmodeID.MultiplayerClient)
                //{
                //	Main.NewText("Huh? RequestHideBoss on client?");
                //}
                string bossKey = reader.ReadString();
                bool   hide    = reader.ReadBoolean();
                if (hide)
                {
                    WorldAssist.HiddenBosses.Add(bossKey);
                }
                else
                {
                    WorldAssist.HiddenBosses.Remove(bossKey);
                }
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.WorldData);
                }
                //else
                //	ErrorLogger.Log("BossChecklist: Why is RequestHideBoss on Client/SP?");
                break;

            case PacketMessageType.RequestClearHidden:
                //if (Main.netMode == NetmodeID.MultiplayerClient)
                //{
                //	Main.NewText("Huh? RequestClearHidden on client?");
                //}
                WorldAssist.HiddenBosses.Clear();
                if (Main.netMode == NetmodeID.Server)
                {
                    NetMessage.SendData(MessageID.WorldData);
                }
                //else
                //	ErrorLogger.Log("BossChecklist: Why is RequestHideBoss on Client/SP?");
                break;

            case PacketMessageType.SendRecordsToServer:
                player = Main.player[whoAmI];
                Console.WriteLine($"Receiving boss records from the joined player {player.name}!");
                for (int i = 0; i < bossTracker.SortedBosses.Count; i++)
                {
                    BossStats bossStats = ServerCollectedRecords[whoAmI][i];
                    bossStats.kills          = reader.ReadInt32();
                    bossStats.deaths         = reader.ReadInt32();
                    bossStats.durationBest   = reader.ReadInt32();
                    bossStats.durationPrev   = reader.ReadInt32();
                    bossStats.healthLossBest = reader.ReadInt32();
                    bossStats.healthLossPrev = reader.ReadInt32();
                    bossStats.hitsTakenBest  = reader.ReadInt32();
                    bossStats.hitsTakenPrev  = reader.ReadInt32();
                    bossStats.dodgeTimeBest  = reader.ReadInt32();

                    //Console.WriteLine($"Establishing {player.name}'s records for {bossTracker.SortedBosses[i].name} to the server");
                }
                break;

            case PacketMessageType.RecordUpdate:
                player    = Main.LocalPlayer;
                modPlayer = player.GetModPlayer <PlayerAssist>();
                //Server just sent us information about what boss just got killed and its records shall be updated
                //Since we did packet.Send(toClient: i);, you can use LocalPlayer here
                int npcPos = reader.ReadInt32();

                BossStats specificRecord = modPlayer.AllBossRecords[npcPos].stat;          // Get the Player's records
                specificRecord.NetRecieve(reader, player, npcPos);                         // The records will be updated through the reader (player and npcPos needed for new record)

                //Update the serverrecords too so they can be used later
                // TODO? send it as a single entry?
                ModPacket packet = GetPacket();
                packet.Write((byte)PacketMessageType.SendRecordsToServer);
                for (int i = 0; i < bossTracker.SortedBosses.Count; i++)
                {
                    BossStats stat = modPlayer.AllBossRecords[i].stat;
                    packet.Write(stat.kills);
                    packet.Write(stat.deaths);
                    packet.Write(stat.durationBest);
                    packet.Write(stat.durationPrev);
                    packet.Write(stat.hitsTakenBest);
                    packet.Write(stat.hitsTakenPrev);
                    packet.Write(stat.dodgeTimeBest);
                    packet.Write(stat.healthLossBest);
                    packet.Write(stat.healthLossPrev);
                }
                packet.Send();                         // To server (ORDER MATTERS FOR reader)
                break;

            case (PacketMessageType.WorldRecordUpdate):
                npcPos = reader.ReadInt32();
                WorldStats worldRecords = WorldAssist.worldRecords[npcPos].stat; // Get the Player's records
                worldRecords.NetRecieve(reader);                                 // The records will be updated through the reader (player and npcPos needed for new record)
                break;

            default:
                Logger.Error("Unknown Message type: " + msgType);
                break;
            }
        }