Beispiel #1
0
        public override void clientClone(ModPlayer clientClone)
        {
            PlayerAssist clone = clientClone as PlayerAssist;

            clone.BossTrophies   = BossTrophies;
            clone.AllBossRecords = AllBossRecords;
        }
 public void ResetArrays(int shortcut, PlayerAssist player)
 {
     if (ActiveBossesList.Count != shortcut)
     {
         while (ActiveBossesList.Count > shortcut)
         {
             ActiveBossesList.RemoveAt(ActiveBossesList.Count - 1);
         }
         while (ActiveBossesList.Count < shortcut)
         {
             ActiveBossesList.Add(false);
         }
     }
     if (player.DeathTracker.Count != shortcut)
     {
         while (player.DeathTracker.Count > shortcut)
         {
             player.DeathTracker.RemoveAt(player.DeathTracker.Count - 1);
         }
         while (player.DeathTracker.Count < shortcut)
         {
             player.DeathTracker.Add(false);
         }
     }
     if (player.RecordTimers.Count != shortcut)
     {
         while (player.RecordTimers.Count > shortcut)
         {
             player.RecordTimers.RemoveAt(player.RecordTimers.Count - 1);
         }
         while (player.RecordTimers.Count < shortcut)
         {
             player.RecordTimers.Add(0);
         }
     }
     if (player.BrinkChecker.Count != shortcut)
     {
         while (player.BrinkChecker.Count > shortcut)
         {
             player.BrinkChecker.RemoveAt(player.BrinkChecker.Count - 1);
         }
         while (player.BrinkChecker.Count < shortcut)
         {
             player.BrinkChecker.Add(0);
         }
     }
     if (player.MaxHealth.Count != shortcut)
     {
         while (player.MaxHealth.Count > shortcut)
         {
             player.MaxHealth.RemoveAt(player.MaxHealth.Count - 1);
         }
         while (player.MaxHealth.Count < shortcut)
         {
             player.MaxHealth.Add(0);
         }
     }
     if (player.AttackCounter.Count != shortcut)
     {
         while (player.AttackCounter.Count > shortcut)
         {
             player.AttackCounter.RemoveAt(player.AttackCounter.Count - 1);
         }
         while (player.AttackCounter.Count < shortcut)
         {
             player.AttackCounter.Add(0);
         }
     }
     if (player.DodgeTimer.Count != shortcut)
     {
         while (player.DodgeTimer.Count > shortcut)
         {
             player.DodgeTimer.RemoveAt(player.DodgeTimer.Count - 1);
         }
         while (player.DodgeTimer.Count < shortcut)
         {
             player.DodgeTimer.Add(0);
         }
     }
     while (ActiveSpecialBosses.Count != 3)
     {
         ActiveSpecialBosses.Add(false);
     }
 }
        public override void PreUpdate()
        {
            List <BossInfo> BL        = BossAssist.instance.setup.SortedBosses;
            PlayerAssist    modPlayer = Main.LocalPlayer.GetModPlayer <PlayerAssist>();

            ResetArrays(BL.Count, modPlayer);

            // Bosses listed below are special cases
            ActiveBossesList[BL.FindIndex(x => x.id == NPCID.EaterofWorldsHead)] = Main.npc.Any(npc => (npc.type == 13 || npc.type == 14 || npc.type == 15) && npc.active);
            ActiveBossesList[BL.FindIndex(x => x.id == NPCID.Retinazer)]         = Main.npc.Any(npc => (npc.type == NPCID.Spazmatism || npc.type == NPCID.Retinazer) && npc.active);
            ActiveBossesList[BL.FindIndex(x => x.id == NPCID.MoonLordHead)]      = Main.npc.Any(npc => (npc.type == NPCID.MoonLordCore || npc.type == NPCID.MoonLordHand || npc.type == NPCID.MoonLordHead) && npc.active);

            for (int n = 0; n < Main.maxNPCs; n++)
            {
                NPC b = Main.npc[n];

                if (NPCAssist.GetListNum(b) != -1)
                {
                    if (NPCAssist.GetListNum(b) == BL.FindIndex(x => x.id == NPCID.EaterofWorldsHead) ||
                        NPCAssist.GetListNum(b) == BL.FindIndex(x => x.id == NPCID.Retinazer) ||
                        NPCAssist.GetListNum(b) == BL.FindIndex(x => x.id == NPCID.MoonLordHead))
                    {
                        if (ActiveBossesList[NPCAssist.GetListNum(b)])
                        {
                            if (Main.LocalPlayer.dead)
                            {
                                modPlayer.DeathTracker[NPCAssist.GetListNum(b)] = true;
                            }
                            ActiveSpecialBosses[GetSpecialNum(NPCAssist.GetListNum(b))] = true;
                        }
                        else if (ActiveSpecialBosses[GetSpecialNum(NPCAssist.GetListNum(b))])
                        {
                            if ((b.type != NPCID.MoonLordHead && b.life >= 0 && CheckRealLife(b.realLife)) || (b.type == NPCID.MoonLordHead && b.life <= 0))
                            {
                                if (!BossAssist.ClientConfig.ODespawnBool)
                                {
                                    if (Main.netMode == NetmodeID.SinglePlayer)
                                    {
                                        Main.NewText(GetDespawnMessage(b), Colors.RarityPurple);
                                    }
                                    else
                                    {
                                        NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(GetDespawnMessage(b)), Colors.RarityPurple);
                                    }
                                }
                            }
                            ActiveSpecialBosses[GetSpecialNum(NPCAssist.GetListNum(b))] = false;
                        }
                    }
                    else
                    {
                        if (b.active)
                        {
                            ActiveBossesList[NPCAssist.GetListNum(b)] = true;
                            if (Main.LocalPlayer.dead)
                            {
                                modPlayer.DeathTracker[NPCAssist.GetListNum(b)] = true;
                            }
                        }
                        else if (!b.active && Main.npc.All(npc => (npc.type == b.type && !npc.active) || npc.type != b.type)) // <INACTIVE NPC>
                        {
                            if (ActiveBossesList[NPCAssist.GetListNum(b)])
                            {
                                if ((b.type != NPCID.MoonLordHead && b.life >= 0) || (b.type == NPCID.MoonLordHead && b.life < 0))
                                {
                                    if (!BossAssist.ClientConfig.ODespawnBool)
                                    {
                                        if (Main.netMode == NetmodeID.SinglePlayer)
                                        {
                                            Main.NewText(GetDespawnMessage(b), Colors.RarityPurple);
                                        }
                                        else
                                        {
                                            NetMessage.BroadcastChatMessage(NetworkText.FromLiteral(GetDespawnMessage(b)), Colors.RarityPurple);
                                        }
                                    }
                                }
                            }
                            ActiveBossesList[NPCAssist.GetListNum(b)] = false;
                        }
                    }
                }
            }

            /// Record Timers
            for (int active = 0; active < ActiveBossesList.Count; active++)
            {
                if (!Main.LocalPlayer.dead)
                {
                    if (ActiveBossesList[active])
                    {
                        modPlayer.RecordTimers[active]++;
                        modPlayer.DodgeTimer[active]++;
                        modPlayer.MaxHealth[active] = Main.LocalPlayer.statLifeMax2;
                        if (modPlayer.BrinkChecker[active] == 0 || (Main.LocalPlayer.statLife < modPlayer.BrinkChecker[active] && Main.LocalPlayer.statLife > 0))
                        {
                            modPlayer.BrinkChecker[active] = Main.LocalPlayer.statLife;
                        }
                    }
                    else
                    {
                        modPlayer.MaxHealth[active]    = Main.LocalPlayer.statLifeMax2;
                        modPlayer.RecordTimers[active] = 0;
                        modPlayer.BrinkChecker[active] = 0;
                        modPlayer.DodgeTimer[active]   = 0;
                    }
                }
                else
                {
                    modPlayer.MaxHealth[active]    = Main.LocalPlayer.statLifeMax2;
                    modPlayer.RecordTimers[active] = 0;
                    modPlayer.BrinkChecker[active] = 0;
                    modPlayer.DodgeTimer[active]   = 0;
                }
            }
        }
        public void CheckRecords(NPC npc, Player player, PlayerAssist modplayer)
        {
            int recordIndex   = SpecialBossCheck(npc);
            int recordAttempt = modplayer.RecordTimers[recordIndex]; // Trying to set a new record
            int currentRecord = modplayer.AllBossRecords[recordIndex].stat.fightTime;
            int worstRecord   = modplayer.AllBossRecords[recordIndex].stat.fightTime2;

            modplayer.AllBossRecords[recordIndex].stat.fightTimeL = recordAttempt;

            int brinkAttempt = modplayer.BrinkChecker[recordIndex];             // Trying to set a new record
            int MaxLife      = modplayer.MaxHealth[recordIndex];
            int currentBrink = modplayer.AllBossRecords[recordIndex].stat.brink2;
            int worstBrink   = modplayer.AllBossRecords[recordIndex].stat.brink;

            modplayer.AllBossRecords[recordIndex].stat.brinkL = brinkAttempt;
            double lastHealth = (double)brinkAttempt / (double)MaxLife;

            modplayer.AllBossRecords[recordIndex].stat.brinkPercentL = (int)(lastHealth * 100);

            int dodgeTimeAttempt = modplayer.DodgeTimer[recordIndex];
            int currentDodgeTime = modplayer.AllBossRecords[recordIndex].stat.dodgeTime;
            int dodgeAttempt     = modplayer.AttackCounter[recordIndex];
            int currentDodges    = modplayer.AllBossRecords[recordIndex].stat.totalDodges;
            int worstDodges      = modplayer.AllBossRecords[recordIndex].stat.totalDodges2;

            modplayer.AllBossRecords[recordIndex].stat.dodgeTimeL   = dodgeTimeAttempt;
            modplayer.AllBossRecords[recordIndex].stat.totalDodgesL = dodgeAttempt;

            // Increase kill count
            modplayer.AllBossRecords[recordIndex].stat.kills++;

            if (recordAttempt < currentRecord && currentRecord != 0 && worstRecord <= 0)
            {
                // First make the current record the worst record if no worst record has been made and a new record was made
                modplayer.AllBossRecords[recordIndex].stat.fightTime2 = currentRecord;
            }
            if (recordAttempt < currentRecord || currentRecord <= 0)
            {
                //The player has beaten their best record, so we have to overwrite the old record with the new one
                modplayer.AllBossRecords[recordIndex].stat.fightTime = recordAttempt;
            }
            else if (recordAttempt > worstRecord || worstRecord <= 0)
            {
                //The player has beaten their worst record, so we have to overwrite the old record with the new one
                modplayer.AllBossRecords[recordIndex].stat.fightTime2 = recordAttempt;
            }

            if (brinkAttempt > currentBrink && currentBrink != 0 && worstBrink <= 0)
            {
                modplayer.AllBossRecords[recordIndex].stat.brink = currentBrink;
            }
            if (brinkAttempt > currentBrink || currentBrink <= 0)
            {
                modplayer.AllBossRecords[recordIndex].stat.brink2 = brinkAttempt;
                double newHealth = (double)brinkAttempt / (double)MaxLife;                 // Casts may be redundant, but this setup doesn't work without them.
                modplayer.AllBossRecords[recordIndex].stat.brinkPercent2 = (int)(newHealth * 100);
            }
            else if (brinkAttempt < worstBrink || worstBrink <= 0)
            {
                modplayer.AllBossRecords[recordIndex].stat.brink = brinkAttempt;
                double newHealth = (double)brinkAttempt / (double)MaxLife;                 // Casts may be redundant, but this setup doesn't work without them.
                modplayer.AllBossRecords[recordIndex].stat.brinkPercent = (int)(newHealth * 100);
            }

            if (dodgeTimeAttempt > currentDodgeTime || currentDodgeTime < 0)
            {
                // There is no "worse record" for this one so just overwrite any better records made
                modplayer.AllBossRecords[recordIndex].stat.dodgeTime = dodgeTimeAttempt;
            }

            if (dodgeAttempt < currentDodges || currentDodges < 0)
            {
                modplayer.AllBossRecords[recordIndex].stat.totalDodges = dodgeAttempt;
                if (worstDodges == 0)
                {
                    modplayer.AllBossRecords[recordIndex].stat.totalDodges2 = currentDodges;
                }
            }
            else if (dodgeAttempt > worstDodges || worstDodges < 0)
            {
                modplayer.AllBossRecords[recordIndex].stat.totalDodges2 = dodgeAttempt;
            }

            modplayer.DodgeTimer[recordIndex]    = 0;
            modplayer.AttackCounter[recordIndex] = 0;

            // If a new record was made, notify the player
            if ((recordAttempt < currentRecord || currentRecord <= 0) || (brinkAttempt > currentBrink || currentBrink <= 0) || (dodgeAttempt < currentDodges || dodgeAttempt <= 0))
            {
                CombatText.NewText(player.getRect(), Color.LightYellow, "New Record!", true);
            }
        }
        public void CheckRecordsMultiplayer(NPC npc)
        {
            int recordIndex = SpecialBossCheck(npc);

            for (int i = 0; i < 255; i++)
            {
                Player       player    = Main.player[i];
                PlayerAssist modPlayer = player.GetModPlayer <PlayerAssist>();

                if (!player.active || !npc.playerInteraction[i])
                {
                    continue;                                              // Players must be active AND have interacted with the boss
                }
                if (Main.netMode == NetmodeID.Server)
                {
                    Console.WriteLine("<<<<<<<<<<<<<<<<<<< Starting the Server NPCLoot stuff");
                    List <BossStats> list      = BossAssist.ServerCollectedRecords[i];
                    BossStats        oldRecord = list[recordIndex];

                    // Establish the new records for comparing

                    BossStats newRecord = new BossStats()
                    {
                        fightTimeL   = modPlayer.RecordTimers[recordIndex],
                        totalDodgesL = modPlayer.AttackCounter[recordIndex],
                        dodgeTimeL   = modPlayer.DodgeTimer[recordIndex],
                        brinkL       = modPlayer.BrinkChecker[recordIndex],

                        brinkPercentL = (int)(((double)modPlayer.BrinkChecker[recordIndex] / modPlayer.MaxHealth[recordIndex]) * 100),
                    };

                    Console.WriteLine("<<<<<<<<<<<<<<<<<<< Declared new and old records");

                    // Compare the records

                    RecordID specificRecord = RecordID.None;

                    if (newRecord.fightTimeL < oldRecord.fightTime)
                    {
                        specificRecord |= RecordID.ShortestFightTime;
                        BossAssist.ServerCollectedRecords[i][recordIndex].fightTime = newRecord.fightTime;
                    }
                    if (newRecord.fightTimeL > oldRecord.fightTime2)
                    {
                        specificRecord |= RecordID.LongestFightTime;
                        BossAssist.ServerCollectedRecords[i][recordIndex].fightTime2 = newRecord.fightTime2;
                    }
                    BossAssist.ServerCollectedRecords[i][recordIndex].fightTimeL = newRecord.fightTimeL;

                    if (newRecord.brink2 > oldRecord.brink2)
                    {
                        specificRecord |= RecordID.BestBrink;
                        BossAssist.ServerCollectedRecords[i][recordIndex].brink2        = newRecord.brink;
                        BossAssist.ServerCollectedRecords[i][recordIndex].brinkPercent2 = newRecord.brinkPercent2;
                    }
                    if (newRecord.brink < oldRecord.brink)
                    {
                        specificRecord |= RecordID.WorstBrink;
                        BossAssist.ServerCollectedRecords[i][recordIndex].brink        = newRecord.brink;
                        BossAssist.ServerCollectedRecords[i][recordIndex].brinkPercent = newRecord.brinkPercent;
                    }
                    BossAssist.ServerCollectedRecords[i][recordIndex].brinkL        = newRecord.brinkL;
                    BossAssist.ServerCollectedRecords[i][recordIndex].brinkPercentL = newRecord.brinkPercentL;

                    if (newRecord.totalDodges < oldRecord.totalDodges)
                    {
                        specificRecord |= RecordID.LeastHits;
                        BossAssist.ServerCollectedRecords[i][recordIndex].totalDodges = newRecord.totalDodges;
                    }
                    if (newRecord.totalDodges2 > oldRecord.totalDodges2)
                    {
                        specificRecord |= RecordID.MostHits;
                        BossAssist.ServerCollectedRecords[i][recordIndex].totalDodges2 = newRecord.totalDodges2;
                    }
                    BossAssist.ServerCollectedRecords[i][recordIndex].totalDodgesL = newRecord.totalDodgesL;

                    if (newRecord.dodgeTime > oldRecord.dodgeTime)
                    {
                        specificRecord |= RecordID.DodgeTime;
                        BossAssist.ServerCollectedRecords[i][recordIndex].dodgeTime = newRecord.dodgeTime;
                    }
                    BossAssist.ServerCollectedRecords[i][recordIndex].dodgeTimeL = newRecord.dodgeTimeL;

                    Console.WriteLine("<<<<<<<<<<<<<<<<<<< Updated recrods apporiately");
                    // Make the packet

                    ModPacket packet = mod.GetPacket();
                    packet.Write((byte)MessageType.RecordUpdate);

                    packet.Write((int)specificRecord);
                    packet.Write((int)recordIndex);
                    // Kills update by 1 automatically
                    // Deaths have to be sent elsewhere (NPCLoot wont run if the player dies)

                    if (specificRecord.HasFlag(RecordID.ShortestFightTime))
                    {
                        packet.Write(newRecord.fightTime);
                    }
                    if (specificRecord.HasFlag(RecordID.LongestFightTime))
                    {
                        packet.Write(newRecord.fightTime2);
                    }
                    packet.Write(newRecord.fightTimeL);

                    if (specificRecord.HasFlag(RecordID.BestBrink))
                    {
                        packet.Write(newRecord.brink2);
                        packet.Write(newRecord.brinkPercent2);
                    }
                    if (specificRecord.HasFlag(RecordID.WorstBrink))
                    {
                        packet.Write(newRecord.brink);
                        packet.Write(newRecord.brinkPercent);
                    }
                    packet.Write(newRecord.brinkL);
                    packet.Write(newRecord.brinkPercentL);

                    if (specificRecord.HasFlag(RecordID.LeastHits))
                    {
                        packet.Write(newRecord.totalDodges);
                    }
                    if (specificRecord.HasFlag(RecordID.MostHits))
                    {
                        packet.Write(newRecord.totalDodges2);
                    }
                    packet.Write(newRecord.totalDodgesL);
                    if (specificRecord.HasFlag(RecordID.DodgeTime))
                    {
                        packet.Write(newRecord.dodgeTime);
                    }
                    packet.Write(newRecord.dodgeTimeL);
                    Console.WriteLine("<<<<<<<<<<<<<<<<<<< Making Packet");

                    // ORDER MATTERS
                    packet.Send(toClient: i);
                    Console.WriteLine("<<<<<<<<<<<<<<<<<<< PACKET SENT!");
                }
            }
        }