private void btnNewSquad_Click(object sender, EventArgs e) { _squad = new Squad(); this.grpBoxSquadDetails.Enabled = true; this.squad_SquadMemberDataGridView.Visible = true; this.squad_SquadMemberDataGridView.DataSource = _squad.Members; this.txtBoxHomePage.Text = ""; this.textBox1.Text = ""; }
private void cmbBoxSquadPicker_SelectedIndexChanged(object sender, EventArgs e) { if (cmbBoxSquadPicker.SelectedItem != null) { try { _squad = Registry.Instance.GetSquad(cmbBoxSquadPicker.SelectedItem.ToString()); } catch (SquadDoesNotExistInRegistryException ex) { MessageBox.Show(ex.Message, "Unexpect Squad load error!"); return; } this.grpBoxSquadDetails.Enabled = true; this.squad_SquadMemberDataGridView.Visible = true; this.squad_SquadMemberDataGridView.DataSource = _squad.Members; this.txtBoxHomePage.Text = _squad.HomePage; this.textBox1.Text = _squad.SquadName; } }
public static Squad LoadSquad(string squadFileName) { Squad squad = new Squad(); StreamReader reader = null; try { reader = new StreamReader(string.Format(_squadFilePrototype, SafeFileName(squadFileName))); XmlSerializer xSerializer = new XmlSerializer(typeof(Squad)); squad = (Squad)xSerializer.Deserialize(reader); reader.Close(); } catch (Exception) { MessageBox.Show("Failed to Find Squad Definition File!"); } finally { if(reader != null) reader.Close(); } return squad; }
/// <summary> /// /// </summary> /// <param name="pilots"></param> /// <param name="squadName"></param> /// <param name="tourNumber"></param> /// <returns></returns> public AcesHighPilotScore BuildSquadScoreObject(Squad squad, int tourNumber) { AcesHighPilotScore squadScore = new AcesHighPilotScore(); Utility.ConstructAcesHighPilotScoreInnerObjects(ref squadScore); // count the pilots for this tour. int numPilots = squad.CountMembersForTour(tourNumber); foreach (Squad.SquadMember squadMember in squad.Members) { if (!Registry.Instance.PilotStatsContains(squadMember.PilotName)) continue; Registry.PilotStatsRegistry pilotReg = Registry.Instance.GetPilotStats(squadMember.PilotName); // If Pilot wasnt in this sqaud for this tour, dont count their data if (!squad.WasPilotInSquadForThisTour(tourNumber, squadMember)) continue; foreach (AttackScoresDO attackScore in pilotReg.AttackScoresList) { if (attackScore.TourNumber != tourNumber) continue; squadScore.GameId = squad.SquadName; squadScore.TourDetails = attackScore.TourIdentfier; squadScore.TourType = attackScore.TourType; squadScore.TourId = attackScore.TourNumber.ToString(); squadScore.VsEnemy.Attack.HitPercentage.Score += attackScore.VsEnemyHitPercentageScore / numPilots; squadScore.VsEnemy.Attack.KillPerHour.Score += attackScore.VsEnemyKillsPerHourScore / numPilots; squadScore.VsEnemy.Attack.KillPerSortie.Score += attackScore.VsEnemyKillsToSortieScore / numPilots; squadScore.VsEnemy.Attack.KillToDeathPlus1.Score += attackScore.VsEnemyKillsToDeathScore / numPilots; squadScore.VsObjects.Attack.DamagePerDeathPlus1.Score += attackScore.VsObjectsDamagePerDeathScore / numPilots; squadScore.VsObjects.Attack.DamagePerSortie.Score += attackScore.VsObjectsDamagePerSortieScore / numPilots; squadScore.VsObjects.Attack.FieldCaptures.Score += attackScore.VsObjectsFieldCapturesScore / numPilots; squadScore.VsObjects.Attack.HitPercentage.Score += attackScore.VsObjectsHitPercentageScore / numPilots; } foreach (BomberScoresDO bomberScores in pilotReg.BomberScoresList) { if (bomberScores.TourNumber != tourNumber) continue; squadScore.VsObjects.Bomber.DamagePerDeathPlus1.Score += bomberScores.VsObjectsDamagePerDeathScore / numPilots; squadScore.VsObjects.Bomber.DamagePerSortie.Score += bomberScores.VsObjectsDamagePerSortieScore / numPilots; squadScore.VsObjects.Bomber.FieldCaptures.Score += bomberScores.VsObjectsFieldCapturesScore / numPilots; squadScore.VsObjects.Bomber.HitPercentage.Score += bomberScores.VsObjectsHitPercentageScore / numPilots; } foreach (FighterScoresDO fighterScores in pilotReg.FighterScoresList) { if (fighterScores.TourNumber != tourNumber) continue; squadScore.VsEnemy.Fighter.HitPercentage.Score += fighterScores.VsEnemyHitPercentageScore / numPilots; squadScore.VsEnemy.Fighter.KillPerHour.Score += fighterScores.VsEnemyKillsPerHourScore / numPilots; squadScore.VsEnemy.Fighter.KillPerSortie.Score += fighterScores.VsEnemyKillsToSortieScore / numPilots; squadScore.VsEnemy.Fighter.KillToDeathPlus1.Score += fighterScores.VsEnemyKillsToDeathScore / numPilots; } foreach (VehicleBoatScoresDO vehicleBoatScores in pilotReg.VehicleBoatScoresList) { if (vehicleBoatScores.TourNumber != tourNumber) continue; squadScore.VsEnemy.VehicleBoat.HitPercentage.Score += vehicleBoatScores.VsEnemyHitPercentageScore / numPilots; squadScore.VsEnemy.VehicleBoat.KillPerHour.Score += vehicleBoatScores.VsEnemyKillsPerHourScore / numPilots; squadScore.VsEnemy.VehicleBoat.KillPerSortie.Score += vehicleBoatScores.VsEnemyKillsToSortieScore / numPilots; squadScore.VsEnemy.VehicleBoat.KillToDeathPlus1.Score += vehicleBoatScores.VsEnemyKillsToDeathScore / numPilots; squadScore.VsObjects.VehicleBoat.DamagePerDeathPlus1.Score += vehicleBoatScores.VsObjectsDamagePerDeathScore / numPilots; squadScore.VsObjects.VehicleBoat.DamagePerSortie.Score += vehicleBoatScores.VsObjectsDamagePerSortieScore / numPilots; squadScore.VsObjects.VehicleBoat.FieldCaptures.Score += vehicleBoatScores.VsObjectsFieldCapturesScore / numPilots; squadScore.VsObjects.VehicleBoat.HitPercentage.Score += vehicleBoatScores.VsObjectsHitPercentageScore / numPilots; } foreach (AttackStatsDO stats in pilotReg.AttackStatsList) { if (stats.TourNumber != tourNumber.ToString()) continue; squadScore.Overall.Attack.Assists += stats.OverAllAssists; squadScore.Overall.Attack.Bailed += stats.OverAllBailed; squadScore.Overall.Attack.Captured += stats.OverAllCaptured; squadScore.Overall.Attack.Death += stats.OverAllDeath; squadScore.Overall.Attack.Disco += stats.OverAllDisco; squadScore.Overall.Attack.Ditched += stats.OverAllDitched; squadScore.Overall.Attack.Kills += stats.OverAllKills; squadScore.Overall.Attack.Landed += stats.OverAllLanded; squadScore.Overall.Attack.Sorties += stats.OverAllSorties; squadScore.Overall.Attack.Time += stats.OverAllTimeInSeconds; } foreach (BomberStatsDO stats in pilotReg.BomberStatsList) { if (stats.TourNumber != tourNumber.ToString()) continue; squadScore.Overall.Bomber.Assists += stats.OverAllAssists; squadScore.Overall.Bomber.Bailed += stats.OverAllBailed; squadScore.Overall.Bomber.Captured += stats.OverAllCaptured; squadScore.Overall.Bomber.Death += stats.OverAllDeath; squadScore.Overall.Bomber.Disco += stats.OverAllDisco; squadScore.Overall.Bomber.Ditched += stats.OverAllDitched; squadScore.Overall.Bomber.Kills += stats.OverAllKills; squadScore.Overall.Bomber.Landed += stats.OverAllLanded; squadScore.Overall.Bomber.Sorties += stats.OverAllSorties; squadScore.Overall.Bomber.Time += stats.OverAllTimeInSeconds; } foreach (FighterStatsDO stats in pilotReg.FighterStatsList) { if (stats.TourNumber != tourNumber.ToString()) continue; squadScore.Overall.Fighter.Assists += stats.OverAllAssists; squadScore.Overall.Fighter.Bailed += stats.OverAllBailed; squadScore.Overall.Fighter.Captured += stats.OverAllCaptured; squadScore.Overall.Fighter.Death += stats.OverAllDeath; squadScore.Overall.Fighter.Disco += stats.OverAllDisco; squadScore.Overall.Fighter.Ditched += stats.OverAllDitched; squadScore.Overall.Fighter.Kills += stats.OverAllKills; squadScore.Overall.Fighter.Landed += stats.OverAllLanded; squadScore.Overall.Fighter.Sorties += stats.OverAllSorties; squadScore.Overall.Fighter.Time += stats.OverAllTimeInSeconds; } foreach (VehicleBoatStatsDO stats in pilotReg.VehicleBoatStatsList) { if (stats.TourNumber != tourNumber.ToString()) continue; squadScore.Overall.VehicleBoat.Assists += stats.OverAllAssists; squadScore.Overall.VehicleBoat.Bailed += stats.OverAllBailed; squadScore.Overall.VehicleBoat.Captured += stats.OverAllCaptured; squadScore.Overall.VehicleBoat.Death += stats.OverAllDeath; squadScore.Overall.VehicleBoat.Disco += stats.OverAllDisco; squadScore.Overall.VehicleBoat.Ditched += stats.OverAllDitched; squadScore.Overall.VehicleBoat.Kills += stats.OverAllKills; squadScore.Overall.VehicleBoat.Landed += stats.OverAllLanded; squadScore.Overall.VehicleBoat.Sorties += stats.OverAllSorties; squadScore.Overall.VehicleBoat.Time += stats.OverAllTimeInSeconds; } } squadScore.VsEnemy.Attack.HitPercentage.Score = decimal.Round(squadScore.VsEnemy.Attack.HitPercentage.Score, 2); squadScore.VsEnemy.Attack.KillPerHour.Score = decimal.Round(squadScore.VsEnemy.Attack.KillPerHour.Score, 2); squadScore.VsEnemy.Attack.KillPerSortie.Score = decimal.Round(squadScore.VsEnemy.Attack.KillPerSortie.Score, 2); squadScore.VsEnemy.Attack.KillToDeathPlus1.Score = decimal.Round(squadScore.VsEnemy.Attack.KillToDeathPlus1.Score, 2); squadScore.VsObjects.Attack.DamagePerDeathPlus1.Score = decimal.Round(squadScore.VsObjects.Attack.DamagePerDeathPlus1.Score, 2); squadScore.VsObjects.Attack.DamagePerSortie.Score = decimal.Round(squadScore.VsObjects.Attack.DamagePerSortie.Score, 2); squadScore.VsObjects.Attack.FieldCaptures.Score = decimal.Round(squadScore.VsObjects.Attack.FieldCaptures.Score, 2); squadScore.VsObjects.Attack.HitPercentage.Score = decimal.Round(squadScore.VsObjects.Attack.HitPercentage.Score, 2); squadScore.VsObjects.Bomber.DamagePerDeathPlus1.Score = decimal.Round(squadScore.VsObjects.Bomber.DamagePerDeathPlus1.Score, 2); squadScore.VsObjects.Bomber.DamagePerSortie.Score = decimal.Round(squadScore.VsObjects.Bomber.DamagePerSortie.Score, 2); squadScore.VsObjects.Bomber.FieldCaptures.Score = decimal.Round(squadScore.VsObjects.Bomber.FieldCaptures.Score, 2); squadScore.VsObjects.Bomber.HitPercentage.Score = decimal.Round(squadScore.VsObjects.Bomber.HitPercentage.Score, 2); squadScore.VsEnemy.Fighter.HitPercentage.Score = decimal.Round(squadScore.VsEnemy.Fighter.HitPercentage.Score, 2); squadScore.VsEnemy.Fighter.KillPerHour.Score = decimal.Round(squadScore.VsEnemy.Fighter.KillPerHour.Score, 2); squadScore.VsEnemy.Fighter.KillPerSortie.Score = decimal.Round(squadScore.VsEnemy.Fighter.KillPerSortie.Score, 2); squadScore.VsEnemy.Fighter.KillToDeathPlus1.Score = decimal.Round(squadScore.VsEnemy.Fighter.KillToDeathPlus1.Score, 2); squadScore.VsEnemy.VehicleBoat.HitPercentage.Score = decimal.Round(squadScore.VsEnemy.VehicleBoat.HitPercentage.Score, 2); squadScore.VsEnemy.VehicleBoat.KillPerHour.Score = decimal.Round(squadScore.VsEnemy.VehicleBoat.KillPerHour.Score, 2); squadScore.VsEnemy.VehicleBoat.KillPerSortie.Score = decimal.Round(squadScore.VsEnemy.VehicleBoat.KillPerSortie.Score, 2); squadScore.VsEnemy.VehicleBoat.KillToDeathPlus1.Score = decimal.Round(squadScore.VsEnemy.VehicleBoat.KillToDeathPlus1.Score, 2); squadScore.VsObjects.VehicleBoat.DamagePerDeathPlus1.Score = decimal.Round(squadScore.VsObjects.VehicleBoat.DamagePerDeathPlus1.Score, 2); squadScore.VsObjects.VehicleBoat.DamagePerSortie.Score = decimal.Round(squadScore.VsObjects.VehicleBoat.DamagePerSortie.Score, 2); squadScore.VsObjects.VehicleBoat.FieldCaptures.Score = decimal.Round(squadScore.VsObjects.VehicleBoat.FieldCaptures.Score, 2); squadScore.VsObjects.VehicleBoat.HitPercentage.Score = decimal.Round(squadScore.VsObjects.VehicleBoat.HitPercentage.Score, 2); if (squadScore.TourDetails == null) squadScore.TourDetails = string.Format("{0} - [NO DATA]", tourNumber); if (squadScore.TourId == null) squadScore.TourId = tourNumber.ToString(); if (squadScore.TourType == null) squadScore.TourType = "[UNKNOWN]"; return squadScore; }
/// <summary> /// /// </summary> /// <param name="pilots"></param> /// <param name="squadName"></param> /// <param name="tourNumber"></param> /// <param name="modelList"></param> /// <returns></returns> public AcesHighPilotStats BuildSquadStatsObject(Squad squad, int tourNumber, ref bool reloadPilotsRequired) { string tourIdentifier = ""; string tourType = ""; Dictionary<string, ObjectScore> tourStats = new Dictionary<string, ObjectScore>(); // FOR EACH PILOT IN SQUAD foreach (Squad.SquadMember squadMember in squad.Members) { if (!Registry.Instance.PilotStatsContains(squadMember.PilotName)) continue; // get pilot's registry. Registry.PilotStatsRegistry pilotReg = Registry.Instance.GetPilotStats(squadMember.PilotName); // If Pilot wasnt in this sqaud for this tour, dont count their data if (!squad.WasPilotInSquadForThisTour(tourNumber, squadMember)) continue; // FOR EACH MODEL foreach (ObjectVsObjectDO objVsObj in pilotReg.ObjVsObjCompleteList) { // only for the tour we're interested in if (objVsObj.TourNumber == tourNumber) { if (tourIdentifier == "") tourIdentifier = objVsObj.TourIdentfier; if(tourType == "") tourType = objVsObj.TourType; if (!tourStats.ContainsKey(objVsObj.Model)) { // doesnt exist yet? create new one and add. ObjectScore thisObjvObj = new ObjectScore(); thisObjvObj.Model = objVsObj.Model; thisObjvObj.KilledBy = objVsObj.KilledBy; thisObjvObj.KillsIn = objVsObj.KillsIn; thisObjvObj.KillsOf = objVsObj.KillsOf; thisObjvObj.DiedIn = objVsObj.DiedIn; if (objVsObj.DiedIn == null) reloadPilotsRequired = true; tourStats.Add(thisObjvObj.Model, thisObjvObj); } else { // get existing objects reference and add to it. ObjectScore thisObjvObj = tourStats[objVsObj.Model]; thisObjvObj.KilledBy += objVsObj.KilledBy; thisObjvObj.KillsIn += objVsObj.KillsIn; thisObjvObj.KillsOf += objVsObj.KillsOf; thisObjvObj.DiedIn += objVsObj.DiedIn; if (objVsObj.DiedIn == null) reloadPilotsRequired = true; } } } } AcesHighPilotStats squadStatsObj = new AcesHighPilotStats(); Utility.ConstructAcesHighPilotStatsInnerObjects(ref squadStatsObj, tourStats.Count); squadStatsObj.GameId = squad.SquadName; squadStatsObj.TourId = tourNumber.ToString(); squadStatsObj.TourType = tourType; squadStatsObj.TourDetails = tourIdentifier; // copy the list content to bounded sized array. int i = 0; foreach(ObjectScore obj in tourStats.Values) { squadStatsObj.VsObjects.ObjectScore[i++] = obj; } return squadStatsObj; }
private void BuildAndDisplaySquadForm(string squadName, Squad squad) { Registry.Instance.RemovePilot(squadName); int startTour = squad.GetMinTour(squad); int endTour = squad.GetMaxTour(squad); bool inException = false; bool reloadPilotsRequired = false; try { Registry.Instance.GetSquad(squadName).CheckSquadInSync(startTour, endTour); SquadScoreStatsBuilder squadBuilder = new SquadScoreStatsBuilder(); for (int tour = startTour; tour <= endTour; tour++) { AcesHighPilotScore score = squadBuilder.BuildSquadScoreObject(squad, tour); if (score.TourDetails.Contains("[NO DATA]")) continue; AcesHighPilotStats stats = squadBuilder.BuildSquadStatsObject(squad, tour, ref reloadPilotsRequired); Registry.PilotStatsRegistry squadStatsReg = new Registry.PilotStatsRegistry(); Registry.Instance.AddPilotStatsToRegistry(squadName, squadStatsReg); Registry.Instance.ConstructScoresForPilot(score, squadName); Registry.Instance.ConstructStatsForPilot(stats, squadName); } } catch (SquadOutOfSyncException ex) { MessageBox.Show(ex.Text, "Squad out of sync error"); inException = true; } catch (SquadDoesNotExistInRegistryException squadEx) { MessageBox.Show(squadEx.Text, "Squad loading error"); inException = true; } if (!FindAndDisplayStatsWindow(squadName) && !inException) { PilotStatsForm form = new PilotStatsForm(squadName, true); form.MdiParent = this; form.CompositeObjVsObjDataIncomplete = reloadPilotsRequired; form.Show(); } }
/// <summary> /// Determine if the pilot was in the sqaud for the nominated tour /// </summary> /// <param name="tourNumber">the tour in question</param> /// <param name="squadMember">the sqaud member details.</param> /// <returns>true if pilot was in squad for that tour, false otherwise.</returns> public bool WasPilotInSquadForThisTour(int tourNumber, Squad.SquadMember squadMember) { return (tourNumber >= squadMember.StartTour && tourNumber <= squadMember.EndTour); }
public int GetMinTour(Squad squad) { int startTour = 999; foreach (SquadMember squadMember in this.Members) { // capture the min if (squadMember.StartTour < startTour) startTour = squadMember.StartTour; } return startTour; }
public int GetMaxTour(Squad squad) { int endTourByData = 0; int endTourBySqaudDefinition = 0; foreach (SquadMember squadMember in this.Members) { if (Registry.Instance.PilotStatsContains(squadMember.PilotName)) { Registry.PilotStatsRegistry pilotStats = Registry.Instance.GetPilotStats(squadMember.PilotName); foreach (StatsDomainObject obj in pilotStats.FighterStatsList) { int thisTourNumber = System.Convert.ToInt32(obj.TourNumber); if (thisTourNumber > endTourByData) endTourByData = thisTourNumber; } } } foreach (SquadMember squadMember in this.Members) { // capture the min if (squadMember.EndTour > endTourBySqaudDefinition) endTourBySqaudDefinition = squadMember.EndTour; } // if pilot has data which continues past their membership in a sqaud definition // ensure we return their sqaud defined end tour. if (endTourBySqaudDefinition < endTourByData) return endTourBySqaudDefinition; else return endTourByData; }
private WoodenSpoonAward GetWoodenSpoonAward(Squad squad, int tourNumber) { WoodenSpoonAward award = new WoodenSpoonAward(); award.KillsPerAssist = Int32.MaxValue; foreach (Squad.SquadMember member in squad.Members) { WoodenSpoonAward candidateAward = new WoodenSpoonAward(); Registry.PilotStatsRegistry pilotStats = Registry.Instance.GetPilotStats(member.PilotName); FighterStatsDO stats = GetPilotStats(pilotStats, tourNumber); if (stats == null) continue; candidateAward.WinnerName = member.PilotName; candidateAward.KillsPerAssist = stats.OverAllAssists == 0 ? (decimal)stats.OverAllKills : (decimal)stats.OverAllKills / stats.OverAllAssists; if (candidateAward.KillsPerAssist < award.KillsPerAssist) award = candidateAward; } return award; }
private WarhawkAward GetWarhawkAward(Squad squad, int tourNumber) { WarhawkAward award = new WarhawkAward(); award.Kills = Int32.MinValue; foreach (Squad.SquadMember member in squad.Members) { WarhawkAward candidateAward = new WarhawkAward(); Registry.PilotStatsRegistry pilotStats = Registry.Instance.GetPilotStats(member.PilotName); if (pilotStats == null) continue; int kills = 0; foreach (ObjectVsObjectDO objVObj in pilotStats.ObjVsObjCompleteList) { if (objVObj.Model.Contains("P-40")) { kills = objVObj.KillsIn; } } candidateAward.WinnerName = member.PilotName; candidateAward.Kills = kills; if (candidateAward.Kills < award.Kills) award = candidateAward; } return award; }
private MostKillsAward GetMostKillsAward(Squad squad, int tourNumber) { MostKillsAward award = new MostKillsAward(); award.Kills = Int32.MinValue; foreach (Squad.SquadMember member in squad.Members) { MostKillsAward candidateAward = new MostKillsAward(); Registry.PilotStatsRegistry pilotStats = Registry.Instance.GetPilotStats(member.PilotName); FighterStatsDO stats = GetPilotStats(pilotStats, tourNumber); if (stats == null) continue; candidateAward.WinnerName = member.PilotName; candidateAward.Kills = stats.OverAllKills; if (candidateAward.Kills > award.Kills) award = candidateAward; } return award; }