Skip to content

Commit c1aaac4

Browse files
authored
Better Viral Weapon (#194)
1 parent df3456d commit c1aaac4

18 files changed

Lines changed: 33 additions & 12 deletions

app/src/main/java/de/twonirwana/infinity/PrintUtils.java

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,16 @@ public static String getWeaponPsWithExtra(TrooperProfile trooperProfile, Weapon
192192
}
193193

194194
public static String getWeaponSavingRollWithExtra(TrooperProfile trooperProfile, Weapon weapon) {
195+
return getWeaponSavingRollWithExtra(trooperProfile, weapon, true);
196+
}
197+
198+
199+
public static String getWeaponSavingRollWithExtra(TrooperProfile trooperProfile, Weapon weapon, boolean applyViral) {
195200
if (weapon == null) {
196201
return "";
197202
}
198203
if (trooperProfile == null) {
199-
getSavingRoll(weapon, weapon.getProbabilityOfSurvival(), null);
204+
getSavingRoll(weapon, weapon.getProbabilityOfSurvival(), null, applyViral);
200205
}
201206
String modifiedPs = getWeaponPsWithExtra(trooperProfile, weapon);
202207
if (weapon.getProbabilityOfSurvival() == null || weapon.getProbabilityOfSurvival().equals("*")) {
@@ -205,10 +210,10 @@ public static String getWeaponSavingRollWithExtra(TrooperProfile trooperProfile,
205210
if (weapon.getSaving().equals("-") || weapon.getSaving().isEmpty()) {
206211
return weapon.getProbabilityOfSurvival();
207212
}
208-
return getSavingRoll(weapon, null, trooperProfile); //PARA weapons
213+
return getSavingRoll(weapon, null, trooperProfile, applyViral); //PARA weapons
209214
}
210215

211-
return getSavingRoll(weapon, modifiedPs, trooperProfile);
216+
return getSavingRoll(weapon, modifiedPs, trooperProfile, applyViral);
212217
}
213218

214219
public static String getCcRangeText(MartialArtLevel martialArtLevel) {
@@ -218,7 +223,7 @@ public static String getCcRangeText(MartialArtLevel martialArtLevel) {
218223
return "CC [MA Att./Opp: %s/%s]".formatted(martialArtLevel.getAttackerModi(), martialArtLevel.getOpponentModi());
219224
}
220225

221-
public static String getSavingRoll(Weapon weapon, String ps, TrooperProfile trooperProfile) {
226+
public static String getSavingRoll(Weapon weapon, String ps, TrooperProfile trooperProfile, boolean applyViral) {
222227
final String psOp;
223228
if (ps == null || "-".equals(ps)) {
224229
psOp = "";
@@ -244,7 +249,8 @@ public static String getSavingRoll(Weapon weapon, String ps, TrooperProfile troo
244249
if (weapon.getProperties().contains("Continous Damage") || weaponExtra.contains("Continous Damage")) {
245250
extraList.add("C");
246251
}
247-
if ((weapon.getAmmunition() != null && weapon.getAmmunition().getName().contains("Shock")) || weaponExtra.contains("Shock") || weapon.getProperties().contains(VIRAL_TRAIT)) {
252+
if ((weapon.getAmmunition() != null && weapon.getAmmunition().getName().contains("Shock")) || weaponExtra.contains("Shock") ||
253+
(weapon.getProperties().contains(VIRAL_TRAIT) && applyViral)) {
248254
extraList.add("S");
249255
}
250256
if ((weapon.getAmmunition() != null && weapon.getAmmunition().getName().contains("E/M"))) {
@@ -262,7 +268,7 @@ public static String getSavingRoll(Weapon weapon, String ps, TrooperProfile troo
262268
String extraString = extraList.isEmpty() ? "" : " " + Joiner.on(" ").join(extraList);
263269

264270
final String savingNumber;
265-
if (weapon.getProperties().contains(VIRAL_TRAIT)) {
271+
if (weapon.getProperties().contains(VIRAL_TRAIT) && applyViral) {
266272
savingNumber = "2";
267273
} else {
268274
savingNumber = weapon.getSavingNum();
@@ -277,13 +283,28 @@ public static String getRangeModifier(Weapon.RangeModifier rangeModifier, boolea
277283
rangeModifier.modifier());
278284
}
279285

280-
public static String getWeaponPropertiesString(Weapon weapon, boolean showSavingRollInsteadOfAmmo) {
281-
return weapon.getProperties().stream()
286+
public static String getAmmo(Weapon weapon) {
287+
if (weapon == null || weapon.getAmmunition() == null) {
288+
return "";
289+
}
290+
if (weapon.getProperties().stream().anyMatch(VIRAL_TRAIT::equals)) {
291+
return "%s+Bio".formatted(weapon.getAmmunition().getName());
292+
}
293+
return weapon.getAmmunition().getName();
294+
}
295+
296+
public static String getWeaponPropertiesString(TrooperProfile trooperProfile, Weapon weapon, boolean showSavingRollInsteadOfAmmo) {
297+
List<String> traits = weapon.getProperties().stream()
282298
.map(PrintUtils::stripTeardropSuffix)
283299
.filter(s -> !REMOVE_WEAPON_TRAITS.contains(s))
284300
.filter(s -> !CC_PROPERTY.equals(s)) //shown in range
285301
.filter(s -> !VIRAL_TRAIT.equals(s) || !showSavingRollInsteadOfAmmo)
286-
.collect(Collectors.joining(", "));
302+
.collect(Collectors.toList());
303+
304+
if (showSavingRollInsteadOfAmmo && weapon.getProperties().stream().anyMatch(VIRAL_TRAIT::equals)) {
305+
traits.add("%s vs STR".formatted(getWeaponSavingRollWithExtra(trooperProfile, weapon, false)));
306+
}
307+
return Joiner.on(", ").join(traits);
287308
}
288309

289310
public static String stripTeardropSuffix(String input) {

app/src/main/resources/templates/fragments/WeaponTable.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@
6060
th:text="${printUtils.getWeaponSavingRollWithExtra(unitProfile, weapon)}"></td>
6161

6262
<td th:if="${!showSavingRollInsteadOfAmmo}"
63-
th:text="${weapon.ammunition != null ? weapon.ammunition.name : ''}"></td>
63+
th:text="${printUtils.getAmmo(weapon)}"></td>
6464

6565
<td class="weapon-table-traits"
66-
th:text="${printUtils.getWeaponPropertiesString(weapon, showSavingRollInsteadOfAmmo)}"></td>
66+
th:text="${printUtils.getWeaponPropertiesString(unitProfile, weapon, showSavingRollInsteadOfAmmo)}"></td>
6767
</tr>
6868

6969
</tbody>

data/core/src/main/java/de/twonirwana/infinity/db/DataLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ private static Optional<BufferedInputStream> getStreamForURL(String urlString) {
383383
urlConnection.setRequestProperty("Referer", "https://infinityuniverse.com/");
384384
return Optional.of(new BufferedInputStream(urlConnection.getInputStream()));
385385
} catch (Exception e) {
386-
log.error("Error downloading: {}", urlString, e);
386+
log.error("Error downloading {}: {}", urlString, e.getMessage());
387387
return Optional.empty();
388388
}
389389
}
3.71 KB
Loading
1.36 KB
Loading
741 Bytes
Loading
3.87 KB
Loading
-436 Bytes
Loading
2.29 KB
Loading
971 Bytes
Loading

0 commit comments

Comments
 (0)