@@ -31,9 +31,12 @@ public final class BattleVehicleEligibilityService {
3131 private BattleVehicleEligibilityService () {}
3232
3333 public static boolean isEligible (War war , String factionId , PlayerVehicleRecord record ) {
34- if (war == null || factionId == null || factionId .isBlank () || record == null ) {
34+ if (war == null || factionId == null || factionId .isBlank ()) {
3535 return true ;
3636 }
37+ if (record == null ) {
38+ return false ;
39+ }
3740 return isEligible (war , factionId , record .getVehicleTypeId (), record );
3841 }
3942
@@ -42,17 +45,44 @@ public static boolean isEligible(
4245 if (war == null || factionId == null || factionId .isBlank ()) {
4346 return true ;
4447 }
45- if (!VehicleCategoryRules .isBerthableType (vehicleTypeId )) {
46- return true ;
48+ return decide (war , factionId , vehicleTypeId , berthRecord ) == BattleVehicleEligibilityResult .ALLOWED ;
49+ }
50+
51+ static BattleVehicleEligibilityResult decide (
52+ War war , String factionId , String vehicleTypeId , PlayerVehicleRecord record ) {
53+ if (record != null && record .getMode () == OwnershipMode .POOL ) {
54+ return poolOnPlayerSide (war , factionId , record .getFactionId ())
55+ ? BattleVehicleEligibilityResult .ALLOWED
56+ : BattleVehicleEligibilityResult .DENIED_POOL_SIDE ;
4757 }
48- if (berthRecord == null || berthRecord .getMode () != OwnershipMode .INSTALLATION ) {
58+ if (record != null && record .getMode () == OwnershipMode .INSTALLATION ) {
59+ if (!VehicleCategoryRules .isBerthableType (vehicleTypeId )) {
60+ return BattleVehicleEligibilityResult .ALLOWED ;
61+ }
62+ String installationId = record .getInstallationId ();
63+ if (installationId == null || installationId .isBlank ()) {
64+ return BattleVehicleEligibilityResult .DENIED_NOT_BERTHED ;
65+ }
66+ if (!BattleInstallationInPlayService .isInPlay (war , factionId , installationId )) {
67+ return BattleVehicleEligibilityResult .DENIED_NOT_COMMITTED ;
68+ }
69+ return BattleVehicleEligibilityResult .ALLOWED ;
70+ }
71+ return BattleVehicleEligibilityResult .DENIED_NOT_FACTION_VEHICLE ;
72+ }
73+
74+ private static boolean poolOnPlayerSide (War war , String playerFactionId , String vehicleFactionId ) {
75+ if (vehicleFactionId == null || vehicleFactionId .isBlank ()) {
4976 return false ;
5077 }
51- String installationId = berthRecord .getInstallationId ();
52- if (installationId == null || installationId .isBlank ()) {
78+ Faction playerFaction = FactionManager .getByString (playerFactionId );
79+ Faction vehicleFaction = FactionManager .getByString (vehicleFactionId );
80+ if (playerFaction == null || vehicleFaction == null ) {
5381 return false ;
5482 }
55- return BattleInstallationInPlayService .isInPlay (war , factionId , installationId );
83+ var playerSide = war .getSide (playerFaction );
84+ var vehicleSide = war .getSide (vehicleFaction );
85+ return playerSide != null && playerSide .equals (vehicleSide );
5686 }
5787
5888 public static BattleVehicleEligibilityResult check (
@@ -85,24 +115,8 @@ public static BattleVehicleEligibilityResult check(
85115 return BattleVehicleEligibilityResult .NOT_CAMPAIGN_BATTLE ;
86116 }
87117
88- String vehicleTypeId = vehicle .getId ();
89- if (!VehicleCategoryRules .isBerthableType (vehicleTypeId )) {
90- return BattleVehicleEligibilityResult .ALLOWED ;
91- }
92-
93118 Optional <PlayerVehicleRecord > recordOpt = registry .getByVehicleUuid (vehicle .getUUID ());
94- PlayerVehicleRecord record = recordOpt .orElse (null );
95- if (record == null || record .getMode () != OwnershipMode .INSTALLATION ) {
96- return BattleVehicleEligibilityResult .DENIED_NOT_BERTHED ;
97- }
98- String installationId = record .getInstallationId ();
99- if (installationId == null || installationId .isBlank ()) {
100- return BattleVehicleEligibilityResult .DENIED_NOT_BERTHED ;
101- }
102- if (!BattleInstallationInPlayService .isInPlay (war , faction .getId (), installationId )) {
103- return BattleVehicleEligibilityResult .DENIED_NOT_COMMITTED ;
104- }
105- return BattleVehicleEligibilityResult .ALLOWED ;
119+ return decide (war , faction .getId (), vehicle .getId (), recordOpt .orElse (null ));
106120 }
107121
108122 public static Player resolveNotifyPlayer (ActiveVehicle vehicle , PlayerVehicleRegistry registry ) {
@@ -131,12 +145,16 @@ public enum BattleVehicleEligibilityResult {
131145 NOT_CAMPAIGN_BATTLE ,
132146 DENIED_PRE_BATTLE_WARBAND ,
133147 DENIED_NOT_BERTHED ,
134- DENIED_NOT_COMMITTED ;
148+ DENIED_NOT_COMMITTED ,
149+ DENIED_NOT_FACTION_VEHICLE ,
150+ DENIED_POOL_SIDE ;
135151
136152 public boolean isDenied () {
137153 return this == DENIED_PRE_BATTLE_WARBAND
138154 || this == DENIED_NOT_BERTHED
139- || this == DENIED_NOT_COMMITTED ;
155+ || this == DENIED_NOT_COMMITTED
156+ || this == DENIED_NOT_FACTION_VEHICLE
157+ || this == DENIED_POOL_SIDE ;
140158 }
141159 }
142160
@@ -154,6 +172,10 @@ public static String forResult(BattleVehicleEligibilityResult result) {
154172 "§cThis vehicle must be berthed at a committed installation for this battle." ;
155173 case DENIED_NOT_COMMITTED ->
156174 "§cThis vehicle is berthed at an installation not committed for this battle." ;
175+ case DENIED_NOT_FACTION_VEHICLE ->
176+ "§cOnly faction pool and installation vehicles can be used in a campaign battle." ;
177+ case DENIED_POOL_SIDE ->
178+ "§cThis pool vehicle belongs to a faction that is not on your side." ;
157179 case ALLOWED , NOT_CAMPAIGN_BATTLE -> null ;
158180 };
159181 }
0 commit comments