示例#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)
            {
                // 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);
        }
示例#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)
            {
                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);
        }
示例#3
0
        public override void OnEnterWorld(Player player)
        {
            BossLogUI.PageNum = -3;
            durationLastFight = hitsTakenLastFight = healthLossLastFight = -1;
            RecordTimers      = new List <int>();
            BrinkChecker      = new List <int>();
            MaxHealth         = new List <int>();
            DeathTracker      = new List <bool>();
            DodgeTimer        = new List <int>();
            AttackCounter     = new List <int>();

            foreach (BossInfo boss in BossChecklist.bossTracker.SortedBosses)
            {
                RecordTimers.Add(0);
                BrinkChecker.Add(0);
                MaxHealth.Add(0);
                DeathTracker.Add(false);
                DodgeTimer.Add(0);
                AttackCounter.Add(0);
            }

            int bossCount = BossChecklist.bossTracker.SortedBosses.Count;

            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                // Essentially to get "BossAssist.ServerCollectedRecords[player.whoAmI] = AllBossRecords;"
                ModPacket packet = mod.GetPacket();
                packet.Write((byte)PacketMessageType.SendRecordsToServer);
                for (int i = 0; i < bossCount; i++)
                {
                    BossStats stat = 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
            }
        }
示例#4
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)
            }
        }
示例#5
0
        public void CheckRecords(NPC npc, int recordIndex)
        {
            Player       player    = Main.LocalPlayer;
            PlayerAssist modPlayer = player.GetModPlayer <PlayerAssist>();

            if (!npc.playerInteraction[Main.myPlayer])
            {
                return;                                                    // Player must have contributed to the boss fight
            }
            bool      newRecordSet = false;
            BossStats bossStats    = modPlayer.AllBossRecords[recordIndex].stat;

            int durationAttempt     = modPlayer.RecordTimers[recordIndex];
            int currentBestDuration = bossStats.durationBest;

            int hitsTakenAttempt     = modPlayer.AttackCounter[recordIndex];
            int currentBestHitsTaken = bossStats.hitsTakenBest;

            int dodgeTimeAttempt     = modPlayer.DodgeTimer[recordIndex];
            int currentBestDodgeTime = bossStats.dodgeTimeBest;

            int brinkAttempt       = modPlayer.BrinkChecker[recordIndex];
            int maxLifeAttempt     = modPlayer.MaxHealth[recordIndex];
            int currentBestBrink   = bossStats.healthLossBest;
            int currentBestMaxLife = bossStats.healthAtStart;

            // Setup player's last fight attempt numbers
            modPlayer.durationLastFight   = durationAttempt;
            modPlayer.hitsTakenLastFight  = hitsTakenAttempt;
            modPlayer.healthLossLastFight = brinkAttempt;

            bossStats.kills++;             // Kills always go up, since comparing only occurs if boss was defeated

            // If the player has beaten their best record, we change BEST to PREV and make the current attempt the new BEST
            // Otherwise, just overwrite PREV with the current attempt
            if (durationAttempt < currentBestDuration || currentBestDuration <= 0)
            {
                bossStats.durationPrev = currentBestDuration;
                bossStats.durationBest = durationAttempt;
                newRecordSet           = true;
            }
            else
            {
                bossStats.durationPrev = durationAttempt;
            }

            // Empty check should be less than 0 because 0 is achievable (No Hit)
            if (hitsTakenAttempt < currentBestHitsTaken || currentBestHitsTaken < 0)
            {
                bossStats.hitsTakenPrev = currentBestHitsTaken;
                bossStats.hitsTakenBest = hitsTakenAttempt;
                newRecordSet            = true;
            }
            else
            {
                bossStats.hitsTakenPrev = hitsTakenAttempt;
            }

            // This is an extra record based on Hits Taken. Only overwrite if time is higher than previous.
            if (dodgeTimeAttempt > currentBestDodgeTime || currentBestDodgeTime <= 0)
            {
                bossStats.dodgeTimeBest = dodgeTimeAttempt;
            }

            if (brinkAttempt < currentBestBrink || currentBestBrink <= 0)
            {
                bossStats.healthLossPrev    = currentBestBrink;
                bossStats.healthLossBest    = brinkAttempt;
                bossStats.healthAtStartPrev = currentBestMaxLife;
                bossStats.healthAtStart     = maxLifeAttempt;
                newRecordSet = true;
            }
            else
            {
                bossStats.healthLossPrev    = brinkAttempt;
                bossStats.healthAtStartPrev = maxLifeAttempt;
            }

            // If a new record was made, notify the player
            if (newRecordSet)
            {
                modPlayer.hasNewRecord[recordIndex] = true;
                // Compare records to World Records. Logically, you can only beat the world records if you have beaten your own record
                // TODO: Move World Record texts to Multiplayer exclusively. Check should still happen.
                string message = CheckWorldRecords(recordIndex) ? "World Record!" : "New Record!";
                CombatText.NewText(player.getRect(), Color.LightYellow, message, true);
            }
        }
示例#6
0
 private BossRecord(TagCompound tag)
 {
     bossName = tag.Get <string>(nameof(bossName));
     stat     = tag.Get <BossStats>(nameof(stat));
 }
示例#7
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;
            }
        }