Skip to content

Commit

Permalink
ship parameter processing rework (#493)
Browse files Browse the repository at this point in the history
  • Loading branch information
myangelkamikaze authored Aug 15, 2024
1 parent ce6bdbd commit 190be7d
Show file tree
Hide file tree
Showing 11 changed files with 5,731 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static class Extensions
ship.HPMaxModernized = deckBuilderShip.Hp - ship.HPMax;

IEnumerable<IEquipmentDataMaster> equip = ship.AllSlotInstance
.Where(e => e is not null)
.Select(e => e!.MasterEquipment);
.OfType<IEquipmentData>()
.Select(e => e.MasterEquipment);

ship.FirepowerFit = deckBuilderShip.Firepower - ship.FirepowerBase - equip.Sum(e => e.Firepower);
ship.TorpedoFit = deckBuilderShip.Torpedo - ship.TorpedoBase - equip.Sum(e => e.Torpedo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class GameDataExtensions
{
if (shipData is null) return null;

ShipDataMock ship = new(KcDatabase.MasterShips[(int)shipData.Id])
ShipDataMock ship = new(KcDatabase.MasterShips[(int)shipData.Id], shipData.Kyouka)
{
MasterID = shipData.DropId ?? 0,
Level = shipData.Level,
Expand All @@ -59,14 +59,7 @@ public static class GameDataExtensions
Ammo = shipData.Ammo,
Range = shipData.Range,
Speed = shipData.Speed,
LuckModernized = shipData.Kyouka.Skip(4).FirstOrDefault(),
HPMaxModernized = shipData.Kyouka.Skip(5).FirstOrDefault(),
ASWModernized = shipData.Kyouka.Skip(6).FirstOrDefault(),
SpecialEffectItemFirepower = shipData.SpecialEffectItems?.Sum(i => i.Firepower) ?? 0,
SpecialEffectItemTorpedo = shipData.SpecialEffectItems?.Sum(i => i.Torpedo) ?? 0,
SpecialEffectItemArmor = shipData.SpecialEffectItems?.Sum(i => i.Armor) ?? 0,
SpecialEffectItemEvasion = shipData.SpecialEffectItems?.Sum(i => i.Evasion) ?? 0,
SpecialEffectItems = shipData.SpecialEffectItems ?? new(),
SpecialEffectItems = shipData.SpecialEffectItems ?? [],
};

if (shipData.Aircraft is not null)
Expand Down Expand Up @@ -200,6 +193,10 @@ private static IBaseAirCorpsSquadron MakeAirBaseSquadron(SortieAirBaseSquadron?
Ammo = ship.Ammo,
Range = ship.Range,
Speed = ship.Speed,
FirepowerBase = ship.FirepowerBase,
TorpedoBase = ship.TorpedoBase,
AABase = ship.AABase,
ArmorBase = ship.ArmorBase,
LuckModernized = ship.LuckModernized,
HPMaxModernized = ship.HPMaxModernized,
ASWModernized = ship.ASWModernized,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ public PhaseFriendlySupportInfo(ApiFriendlyInfo apiFriendlyInfo)
})
.Cast<IEquipmentData?>()
.ToList(),
FirepowerBase = apiFriendlyInfo.ApiParam[i][0],
TorpedoBase = apiFriendlyInfo.ApiParam[i][1],
AABase = apiFriendlyInfo.ApiParam[i][2],
ArmorBase = apiFriendlyInfo.ApiParam[i][3],
};

ship.FirepowerModernized += apiFriendlyInfo.ApiParam[i][0] - ship.FirepowerBase;
ship.TorpedoModernized += apiFriendlyInfo.ApiParam[i][1] - ship.TorpedoBase;
ship.AAModernized += apiFriendlyInfo.ApiParam[i][2] - ship.AABase;
ship.ArmorModernized += apiFriendlyInfo.ApiParam[i][3] - ship.ArmorBase;

Ships.Add(ship);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,7 @@ public PhaseInitial(IKCDatabase kcDatabase, BattleFleets fleets, IBattleApiRespo
FriendInitialHPs = battle.ApiFNowhps;
FriendMaxHPs = battle.ApiFMaxhps;

foreach ((IShipData? ship, int i) in fleets.Fleet.MembersInstance.Select((s, i) => (s, i)))
{
if (ship is not ShipDataMock s) continue;

s.HPCurrent = FriendInitialHPs[i];
}
SetShipParameters(fleets.Fleet.MembersInstance, FriendInitialHPs, battle.ApiFParam);

Escape(fleets.Fleet, battle.ApiEscapeIdx);

Expand Down Expand Up @@ -251,7 +246,7 @@ public PhaseInitial(IKCDatabase kcDatabase, BattleFleets fleets, IPlayerCombined
: this(kcDatabase, fleets, (IBattleApiResponse)battle)
{
ApiCombatRationCombined = battle.ApiCombatRationCombined;
SetEscortFleetHp(fleets, battle);
SetEscortFleetParameters(fleets, battle);
Escape(fleets.EscortFleet, battle.ApiEscapeIdxCombined);
}

Expand All @@ -267,7 +262,7 @@ public PhaseInitial(IKCDatabase kcDatabase, BattleFleets fleets, ICombinedBattle
: this(kcDatabase, fleets, (IBattleApiResponse)battle)
{
ApiCombatRationCombined = battle.ApiCombatRationCombined;
SetEscortFleetHp(fleets, battle);
SetEscortFleetParameters(fleets, battle);
Escape(fleets.EscortFleet, battle.ApiEscapeIdxCombined);

IsEnemyCombinedFleet = true;
Expand All @@ -278,7 +273,7 @@ public PhaseInitial(IKCDatabase kcDatabase, BattleFleets fleets, ICombinedBattle
public PhaseInitial(IKCDatabase kcDatabase, BattleFleets fleets, ICombinedNightBattleApiResponse battle)
: this(kcDatabase, fleets, (IBattleApiResponse)battle)
{
SetEscortFleetHp(fleets, battle);
SetEscortFleetParameters(fleets, battle);
EnemyMembersEscortInstance = MakeEnemyEscortFleet(battle);
SetEnemyRange(EnemyMembersEscortInstance);
}
Expand Down Expand Up @@ -324,30 +319,33 @@ public PhaseInitial(IKCDatabase kcDatabase, BattleFleets fleets, ApiDestructionB
.ToList();
}

private static void SetEscortFleetHp(BattleFleets fleets, IPlayerCombinedFleetBattle battle)
private static void SetEscortFleetParameters(BattleFleets fleets, IPlayerCombinedFleetBattle battle)
{
if (fleets.EscortFleet is null) return;

SetEscortFleetHp(fleets, battle.ApiFNowhpsCombined);
SetShipParameters(fleets.EscortFleet.MembersInstance, battle.ApiFNowhpsCombined, battle.ApiFParamCombined);
}

private static void SetEscortFleetHp(BattleFleets fleets, ICombinedNightBattleApiResponse battle)
private static void SetEscortFleetParameters(BattleFleets fleets, ICombinedNightBattleApiResponse battle)
{
if (fleets.EscortFleet is null) return;
if (battle.ApiFNowhpsCombined is null) return;
if (battle.ApiFParamCombined is null) return;

SetEscortFleetHp(fleets, battle.ApiFNowhpsCombined);
SetShipParameters(fleets.EscortFleet.MembersInstance, battle.ApiFNowhpsCombined, battle.ApiFParamCombined);
}

private static void SetEscortFleetHp(BattleFleets fleets, List<int> hpNowList)
private static void SetShipParameters(IEnumerable<IShipData?> ships, List<int> hpNowList, List<List<int>> param)
{
if (fleets.EscortFleet is null) return;

foreach ((IShipData? ship, int i) in fleets.EscortFleet.MembersInstance.Select((s, i) => (s, i)))
foreach ((IShipData? ship, int i) in ships.Select((s, i) => (s, i)))
{
if (ship is not ShipDataMock s) continue;

s.HPCurrent = hpNowList[i];
s.FirepowerBase = param[i][0];
s.TorpedoBase = param[i][1];
s.AABase = param[i][2];
s.ArmorBase = param[i][3];
}
}

Expand Down
36 changes: 0 additions & 36 deletions ElectronicObserverCoreTests/BattleRank/BattleRankTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,32 +258,26 @@ public void SortieDetailTest6()
new ShipDataMock(Database.MasterShips[ShipId.NisshinA])
{
HPCurrent = 55,
HPMaxModernized = 55,
},
new ShipDataMock(Database.MasterShips[ShipId.MakigumoKaiNi])
{
HPCurrent = 38,
HPMaxModernized = 38,
},
new ShipDataMock(Database.MasterShips[ShipId.KasumiKaiNi])
{
HPCurrent = 37,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.UmikazeKaiNi])
{
HPCurrent = 37,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.KawakazeKaiNi])
{
HPCurrent = 37,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.YuraKaiNi])
{
HPCurrent = 10,
HPMaxModernized = 51,
},
]),
EscapedShipList = new([5]), // Yura escaped
Expand All @@ -295,32 +289,26 @@ public void SortieDetailTest6()
new ShipDataMock(Database.MasterShips[ShipId.NisshinA])
{
HPCurrent = 55,
HPMaxModernized = 55,
},
new ShipDataMock(Database.MasterShips[ShipId.MakigumoKaiNi])
{
HPCurrent = 38,
HPMaxModernized = 38,
},
new ShipDataMock(Database.MasterShips[ShipId.KasumiKaiNi])
{
HPCurrent = 16,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.UmikazeKaiNi])
{
HPCurrent = 37,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.KawakazeKaiNi])
{
HPCurrent = 9,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.YuraKaiNi])
{
HPCurrent = 10,
HPMaxModernized = 51,
},
]),
EscapedShipList = new([5]), // Yura escaped
Expand All @@ -333,32 +321,26 @@ public void SortieDetailTest6()
new ShipDataMock(Database.MasterShips[ShipId.YuubariKaiNiToku])
{
HPCurrent = 10,
HPMaxModernized = 47,
},
new ShipDataMock(Database.MasterShips[ShipId.AbukumaKaiNi])
{
HPCurrent = 51,
HPMaxModernized = 51,
},
new ShipDataMock(Database.MasterShips[ShipId.HatsushimoKaiNi])
{
HPCurrent = 17,
HPMaxModernized = 39,
},
new ShipDataMock(Database.MasterShips[ShipId.AmatsukazeKaiNi])
{
HPCurrent = 40,
HPMaxModernized = 40,
},
new ShipDataMock(Database.MasterShips[ShipId.KawakazeKaiNi])
{
HPCurrent = 37,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.YuraKaiNi])
{
HPCurrent = 43,
HPMaxModernized = 43,
},
]),
EscapedShipList = new([3]), // Amatsukaze escaped
Expand All @@ -370,32 +352,26 @@ public void SortieDetailTest6()
new ShipDataMock(Database.MasterShips[ShipId.YuubariKaiNiToku])
{
HPCurrent = 10,
HPMaxModernized = 47,
},
new ShipDataMock(Database.MasterShips[ShipId.AbukumaKaiNi])
{
HPCurrent = 7,
HPMaxModernized = 51,
},
new ShipDataMock(Database.MasterShips[ShipId.HatsushimoKaiNi])
{
HPCurrent = 8,
HPMaxModernized = 39,
},
new ShipDataMock(Database.MasterShips[ShipId.AmatsukazeKaiNi])
{
HPCurrent = 40,
HPMaxModernized = 40,
},
new ShipDataMock(Database.MasterShips[ShipId.KawakazeKaiNi])
{
HPCurrent = 34,
HPMaxModernized = 37,
},
new ShipDataMock(Database.MasterShips[ShipId.YuraKaiNi])
{
HPCurrent = 43,
HPMaxModernized = 43,
},
]),
EscapedShipList = new([3]), // Amatsukaze escaped
Expand All @@ -408,32 +384,26 @@ public void SortieDetailTest6()
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ri-Class Flagship
{
HPCurrent = 76,
HPMaxModernized = 76,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ri-Class Flagship
{
HPCurrent = 76,
HPMaxModernized = 76,
},
new ShipDataMock(Database.MasterShips[(ShipId)1591]) // Tsu-Class
{
HPCurrent = 48,
HPMaxModernized = 48,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ni-Class Late Model
{
HPCurrent = 40,
HPMaxModernized = 40,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ni-Class Late Model
{
HPCurrent = 40,
HPMaxModernized = 40,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ni-Class Late Model
{
HPCurrent = 40,
HPMaxModernized = 40,
},
]),
},
Expand All @@ -444,32 +414,26 @@ public void SortieDetailTest6()
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ri-Class Flagship
{
HPCurrent = 44,
HPMaxModernized = 76,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ri-Class Flagship
{
HPCurrent = 32,
HPMaxModernized = 76,
},
new ShipDataMock(Database.MasterShips[(ShipId)1591]) // Tsu-Class
{
HPCurrent = 35,
HPMaxModernized = 48,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ni-Class Late Model
{
HPCurrent = 0,
HPMaxModernized = 40,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ni-Class Late Model
{
HPCurrent = 0,
HPMaxModernized = 40,
},
new ShipDataMock(Database.MasterShips[(ShipId)1527]) // Ni-Class Late Model
{
HPCurrent = 0,
HPMaxModernized = 40,
},
]),
},
Expand Down
Loading

0 comments on commit 190be7d

Please sign in to comment.