找回密码
 初始化身份识别芯片
查看: 1769|回复: 2

Java求助,绝对值函数插哪里?

[复制链接]

势力巨擘

发表于 2022-8-29 16:05:09 | 显示全部楼层 |阅读模式
  1. package data.hullmods;

  2. import java.util.HashMap;
  3. import java.util.Map;

  4. import com.fs.starfarer.api.combat.BaseHullMod;
  5. import com.fs.starfarer.api.combat.MutableShipStatsAPI;
  6. import com.fs.starfarer.api.combat.ShipAPI.HullSize;
  7. import com.fs.starfarer.api.combat.ShipAPI;

  8. public class BeamSuperCap extends BaseHullMod {

  9.         private static Map mag1 = new HashMap();
  10.         static {
  11.                 mag1.put(HullSize.FRIGATE, -1000f);
  12.                 mag1.put(HullSize.DESTROYER, -2000f);
  13.                 mag1.put(HullSize.CRUISER, -3000f);
  14.                 mag1.put(HullSize.CAPITAL_SHIP, -5000f);
  15.         }
  16.         private static Map mag2 = new HashMap();
  17.         static {
  18.                 mag2.put(HullSize.FRIGATE, 0.75f);
  19.                 mag2.put(HullSize.DESTROYER, 0.65f);
  20.                 mag2.put(HullSize.CRUISER, 0.55f);
  21.                 mag2.put(HullSize.CAPITAL_SHIP, 0.45f);
  22.         }
  23.         private static Map mag3 = new HashMap();
  24.         static {
  25.                 mag3.put(HullSize.FRIGATE, 20f);
  26.                 mag3.put(HullSize.DESTROYER, 40f);
  27.                 mag3.put(HullSize.CRUISER, 50f);
  28.                 mag3.put(HullSize.CAPITAL_SHIP, 60f);
  29.         }
  30.         private static Map mag4 = new HashMap();
  31.         static {
  32.                 mag4.put(HullSize.FRIGATE, 20f);
  33.                 mag4.put(HullSize.DESTROYER, 30f);
  34.                 mag4.put(HullSize.CRUISER, 35f);
  35.                 mag4.put(HullSize.CAPITAL_SHIP, 40f);
  36.         }
  37.        
  38.         public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) {
  39.                 stats.getFluxCapacity().modifyFlat(id, (Float) mag1.get(hullSize));
  40.                 stats.getEnergyRoFMult().modifyMult(id, (Float) mag2.get(hullSize));
  41.                 stats.getEnergyAmmoRegenMult().modifyMult(id, (Float) mag2.get(hullSize));
  42.                 stats.getBeamWeaponDamageMult().modifyPercent(id, (Float) mag3.get(hullSize));
  43.                 stats.getBeamWeaponRangeBonus().modifyPercent(id, (Float) mag4.get(hullSize));
  44.         }
  45.        
  46.         public String getDescriptionParam(int index, HullSize hullSize) {
  47.                 if (index == 0) return "" + ((Float) mag1.get(HullSize.FRIGATE)).intValue();
  48.                 if (index == 1) return "" + ((Float) mag1.get(HullSize.DESTROYER)).intValue();
  49.                 if (index == 2) return "" + ((Float) mag1.get(HullSize.CRUISER)).intValue();
  50.                 if (index == 3) return "" + ((Float) mag1.get(HullSize.CAPITAL_SHIP)).intValue();
  51.                 if (index == 4) return "" + ((Float) mag2.get(HullSize.FRIGATE)).intValue();
  52.                 if (index == 5) return "" + ((Float) mag2.get(HullSize.DESTROYER)).intValue();
  53.                 if (index == 6) return "" + ((Float) mag2.get(HullSize.CRUISER)).intValue();
  54.                 if (index == 7) return "" + ((Float) mag2.get(HullSize.CAPITAL_SHIP)).intValue();
  55.                 if (index == 8) return "" + ((Float) mag3.get(HullSize.FRIGATE)).intValue();
  56.                 if (index == 9) return "" + ((Float) mag3.get(HullSize.DESTROYER)).intValue();
  57.                 if (index == 10) return "" + ((Float) mag3.get(HullSize.CRUISER)).intValue();
  58.                 if (index == 11) return "" + ((Float) mag3.get(HullSize.CAPITAL_SHIP)).intValue();
  59.                 if (index == 12) return "" + ((Float) mag4.get(HullSize.FRIGATE)).intValue();
  60.                 if (index == 13) return "" + ((Float) mag4.get(HullSize.DESTROYER)).intValue();
  61.                 if (index == 14) return "" + ((Float) mag4.get(HullSize.CRUISER)).intValue();
  62.                 if (index == 15) return "" + ((Float) mag4.get(HullSize.CAPITAL_SHIP)).intValue();
  63.                 if (index == 16) return "" + ((Float) mag1.get(hullSize)).intValue();
  64.                 if (index == 17) return "" + ((Float) mag2.get(hullSize)).intValue();
  65.                 if (index == 18) return "" + ((Float) mag3.get(hullSize)).intValue();
  66.                 if (index == 19) return "" + ((Float) mag4.get(hullSize)).intValue();
  67.                 return null;
  68.         }


  69. }
复制代码
在描述里我想要把index4-15 17-19 全部用百分比的绝对值表示,不知道绝对值函数和百分号插哪里。

超级版主

STS 竞技场总主持

高级机师译码专家搬运能手战术专家通讯记者学院教员远星汉化组成员

发表于 2022-8-29 22:13:53 | 显示全部楼层
写一点普适性的东西。

巡洋大副

萌萌

发表于 2022-11-2 18:36:24 | 显示全部楼层
                if (index == 4) return "" + (Math.abs((Float) mag2.get(HullSize.FRIGATE))).intValue() + "%";

本版积分规则

Archiver|手机版|小黑屋|远行星号中文论坛

GMT+8, 2024-12-22 12:23

Powered by Discuz! X3.5

© 2001-2077 Tencent Cloud | Durian Software Studio

快速回复 返回顶部 返回列表