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!"); } } }
public override void HandlePacket(BinaryReader reader, int whoAmI) { MessageType msgType = (MessageType)reader.ReadByte(); Player player; PlayerAssist modPlayer; switch (msgType) { case MessageType.SendRecordsToServer: player = Main.player[whoAmI]; Console.WriteLine("Receiving boss records from the joined player + " + player.name + "!"); for (int i = 0; i < instance.setup.SortedBosses.Count; i++) { ServerCollectedRecords[whoAmI][i].kills = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].deaths = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].fightTime = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].fightTime2 = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].brink2 = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].brink = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].totalDodges = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].totalDodges2 = reader.ReadInt32(); ServerCollectedRecords[whoAmI][i].dodgeTime = reader.ReadInt32(); Console.WriteLine("Establishing " + player.name + "'s records for " + instance.setup.SortedBosses[i].name + " to the server"); } break; case MessageType.RecordUpdate: Main.NewText("Record update packet is being handled"); 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 RecordID brokenRecords = (RecordID)reader.ReadInt32(); int npcPos = reader.ReadInt32(); BossStats specificRecord = modPlayer.AllBossRecords[npcPos].stat; //RecordID.Kills will just be increased by 1 automatically specificRecord.kills++; if (brokenRecords.HasFlag(RecordID.ShortestFightTime)) { specificRecord.fightTime = reader.ReadInt32(); } if (brokenRecords.HasFlag(RecordID.LongestFightTime)) { specificRecord.fightTime2 = reader.ReadInt32(); } specificRecord.fightTimeL = reader.ReadInt32(); if (brokenRecords.HasFlag(RecordID.BestBrink)) { specificRecord.brink2 = reader.ReadInt32(); specificRecord.brinkPercent2 = reader.ReadInt32(); } if (brokenRecords.HasFlag(RecordID.WorstBrink)) { specificRecord.brink = reader.ReadInt32(); specificRecord.brinkPercent = reader.ReadInt32(); } specificRecord.brinkL = reader.ReadInt32(); specificRecord.brinkPercentL = reader.ReadInt32(); if (brokenRecords.HasFlag(RecordID.LeastHits)) { specificRecord.totalDodges = reader.ReadInt32(); } if (brokenRecords.HasFlag(RecordID.MostHits)) { specificRecord.totalDodges2 = reader.ReadInt32(); } specificRecord.totalDodgesL = reader.ReadInt32(); if (brokenRecords.HasFlag(RecordID.DodgeTime)) { specificRecord.dodgeTime = reader.ReadInt32(); } specificRecord.dodgeTimeL = reader.ReadInt32(); //Main.NewText(ServerCollectedRecords[Main.myPlayer][0].kills + " / " + ServerCollectedRecords[Main.myPlayer][0].deaths); //Main.NewText(ServerCollectedRecords[Main.myPlayer][0].fightTime.ToString()); //Main.NewText(ServerCollectedRecords[Main.myPlayer][0].brink + "(" + ServerCollectedRecords[Main.myPlayer][0].brinkPercent + ")"); //Main.NewText(ServerCollectedRecords[Main.myPlayer][0].totalDodges + "(" + ServerCollectedRecords[Main.myPlayer][0].dodgeTime + ")"); // ORDER MATTERS FOR reader break; case MessageType.DeathCount: Console.WriteLine("Death count packet is being handled"); List <BossRecord> deathRecord = Main.LocalPlayer.GetModPlayer <PlayerAssist>().AllBossRecords; int num = reader.ReadInt32(); for (int i = 0; i < num; i++) { int npcPos2 = reader.ReadInt32(); Console.WriteLine("Recording a death from " + instance.setup.SortedBosses[npcPos2].name); deathRecord[npcPos2].stat.deaths++; } break; } }
private BossRecord(TagCompound tag) { modName = tag.Get <string>(nameof(modName)); bossName = tag.Get <string>(nameof(bossName)); stat = tag.Get <BossStats>(nameof(stat)); }