求助怎么实现hardpoint武器射程增加
在api里找到了WeaponSlotAPI,可以判断是否hardpoint,但直接用报错了15520 ERROR com.fs.starfarer.combat.CombatMain- java.lang.RuntimeException: Error loading
java.lang.RuntimeException: Error loading
at com.fs.starfarer.loading.scripts.ScriptStore$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: File 'data/hullmods/HardPointRange.java', Line 43, Column 25: Non-abstract class "data.hullmods.HardPointRange$ALLWeaponRangeMod" must implement method "public abstract float com.fs.starfarer.api.combat.listeners.WeaponRangeModifier.getWeaponRangePercentMod(com.fs.starfarer.api.combat.ShipAPI, com.fs.starfarer.api.combat.WeaponAPI)"
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:226)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:178)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: File 'data/hullmods/HardPointRange.java', Line 43, Column 25: Non-abstract class "data.hullmods.HardPointRange$ALLWeaponRangeMod" must implement method "public abstract float com.fs.starfarer.api.combat.listeners.WeaponRangeModifier.getWeaponRangePercentMod(com.fs.starfarer.api.combat.ShipAPI, com.fs.starfarer.api.combat.WeaponAPI)"
at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:10174)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:419)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:658)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:662)
at org.codehaus.janino.UnitCompiler.access$600(UnitCompiler.java:185)
at org.codehaus.janino.UnitCompiler$2.visitMemberClassDeclaration(UnitCompiler.java:350)
at org.codehaus.janino.Java$MemberClassDeclaration.accept(Java.java:1035)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:354)
at org.codehaus.janino.UnitCompiler.compileDeclaredMemberTypes(UnitCompiler.java:769)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:532)
at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:393)
at org.codehaus.janino.UnitCompiler.access$400(UnitCompiler.java:185)
at org.codehaus.janino.UnitCompiler$2.visitPackageMemberClassDeclaration(UnitCompiler.java:347)
at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:1139)
at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:354)
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:322)
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:224)
... 5 more
源码:
public class HardPointRange extends BaseHullMod {
public static float RANGE_MISSILE = 0f;
public static float range_Hardpoint_pct = 100f;
public void applyEffectsAfterShipCreation(ShipAPI ship, MutableShipStatsAPI stats, String id) {
ship.addListener(new ALLWeaponRangeMod());
}
private static class ALLWeaponRangeMod implements WeaponRangeModifier {
public float getWeaponRangeFlatMod(ShipAPI ship, WeaponAPI weapon) {
return 0f;
}
@Override
public float getWeaponRangeMultMod(ShipAPI ship, WeaponAPI weapon) {
return 1f;
}
@Override
public float getWeaponRangePercentMod(ShipAPI ship, WeaponAPI weapon , WeaponSlotAPI weapslot) { //
if (weapslot.isHardpoint() ) { //!(weapon.getType() == WeaponType.MISSILE) &&
return (range_Hardpoint_pct);
} else {
return 0f;
}
return 0f;
}
}
public boolean isApplicableToShip(ShipAPI ship) {
return true;
}
} 欸,报错的意思是,你的 ALLWeaponRangeMod类需要实现一个叫 getWeaponRangePercentMod 的方法,这个方法接受的参数是第一个参数 是 ShipAPI , 第二个参数 是 WeaponAPI 。
但是你的代码中 getWeaponRangePercentMod方法的参数是三个...
我看了一下接口,getWeaponRangePercentMod是 不需要 第三个参数 WeaponSlotAPI 的 钟离云初 发表于 2022-3-3 12:32
欸,报错的意思是,你的 ALLWeaponRangeMod类需要实现一个叫 getWeaponRangePercentMod 的方法,这个方法 ...
增加了一个监听器
package com.fs.starfarer.api.combat.listeners;
import com.fs.starfarer.api.combat.ShipAPI;
import com.fs.starfarer.api.combat.WeaponAPI;
import com.fs.starfarer.api.loading.WeaponSlotAPI;
/**
* Only applies when added to ships, NOT the combat engine, for performance reasons.
*
* @author Alex Mosolov
*
* Copyright 2019 Fractal Softworks, LLC
*/
public interface x_WeaponRangeModifier {
float getWeaponRangePercentMod(ShipAPI ship, WeaponAPI weapon, WeaponSlotAPI slot);
float getWeaponRangeMultMod(ShipAPI ship, WeaponAPI weapon, WeaponSlotAPI slot);
float getWeaponRangeFlatMod(ShipAPI ship, WeaponAPI weapon, WeaponSlotAPI slot);
}
现在的报错是这个
147919 ERROR com.fs.starfarer.combat.CombatMain- java.lang.RuntimeException: Error loading
java.lang.RuntimeException: Error loading
at com.fs.starfarer.loading.scripts.ScriptStore$3.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: 1 error(s) while compiling unit "data/hullmods/HardPointRange.java"
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:226)
at org.codehaus.janino.JavaSourceClassLoader.findClass(JavaSourceClassLoader.java:178)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Caused by: org.codehaus.commons.compiler.CompileException: 1 error(s) while compiling unit "data/hullmods/HardPointRange.java"
at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:326)
at org.codehaus.janino.JavaSourceClassLoader.generateBytecodes(JavaSourceClassLoader.java:224)
... 5 more
新加的监听器没有起效? 齐格隆冬强 发表于 2022-3-4 08:36
增加了一个监听器
package com.fs.starfarer.api.combat.listeners;
我建议你弄一个ide写代码,你现在这个问题是你的HardPointRange.java的代码写错了,无法编译。和你之前那个问题一样,你把远行星号的接口引进去后ide会告诉你基本的编译问题
页:
[1]