星舰传奇代码解析,懂得帮忙看一下理解是否正确?
我在星舰传奇的SL_ShowMarketDefenses下找到了相关增加舰船插件的方法,SL_ShowMarketDefenses继承MarketCMD:public boolean execute(String ruleId, InteractionDialogAPI dialog, List<Misc.Token> params, Map<String, MemoryAPI> memoryMap) {
PersonAPI commander = null;
List<CampaignFleetAPI> pulledIn = new ArrayList();
if(!ModPlugin.REMOVE_ALL_DATA_AND_FEATURES) {
commander = guessCommander(pulledIn);
}
if(Global.getSettings().getModManager().isModEnabled("nexerelin")) {
try {
if(!(new Nex_MarketCMD(dialog.getInteractionTarget()).execute(ruleId, dialog, params, memoryMap))) return false;
} catch (Exception e) {
ModPlugin.reportCrash(e, false);
if(!super.execute(ruleId, dialog, params, memoryMap)) return false;
}
} else {
if(!super.execute(ruleId, dialog, params, memoryMap)) return false;
}
if (ModPlugin.REMOVE_ALL_DATA_AND_FEATURES) return true;
try {
FactionConfig.clearEnemyFleetRep();
if (commander == null || commander.isDefault()) return false;
FactionConfig.get(commander.getFaction()).showFleetReputation(dialog, commander);
ArrayList<FleetMemberAPI> allEnemyShips = new ArrayList<>();
for(CampaignFleetAPI fleet : pulledIn) allEnemyShips.addAll(fleet.getFleetData().getMembersListCopy());
for(FleetMemberAPI ship : allEnemyShips) {
ship.getVariant().addPermaMod(Reputation.ENEMY_HULLMOD_ID);
ship.updateStats();
}
return true;
} catch (Exception e) {
ModPlugin.reportCrash(e);
return false;
}
}
其中:
for(FleetMemberAPI ship : allEnemyShips) {
ship.getVariant().addPermaMod(Reputation.ENEMY_HULLMOD_ID);
ship.updateStats();
}
他获取到了所有的敌人的船,给船增加《声名在外》的插件,这个是针对敌人的插件,我猜他的想法是给敌人增加BUFF,然后看看他怎么获取到敌人的舰队舰船的:
protected PersonAPI guessCommander(List<CampaignFleetAPI> pulledIn) {
try {
//从全局获取玩家舰队
CampaignFleetAPI pf = Global.getSector().getPlayerFleet();
//这个应该是MarketCMD的原有方法获取了势力舰队的API
CampaignFleetAPI actualOther = getInteractionTargetForFIDPI();
//工厂类创建了一次战斗?
BattleAPI b = Global.getFactory().createBattle(pf, actualOther);
//我猜是通过距离获取附近的舰队
for (CampaignFleetAPI fleet : pf.getContainingLocation().getFleets()) {
//如果已经在战斗跳过
if (b == fleet.getBattle()) continue;
if (fleet.getBattle() != null) continue;
//待机还是在巡逻?反正不是在战斗
if (fleet.isStationMode()) continue;
//获得一个距离
float dist = Misc.getDistance(actualOther.getLocation(), fleet.getLocation());
//距离减去双方半径不知道干啥用
dist -= actualOther.getRadius();
dist -= fleet.getRadius();
//如果船已经挂完了就跳过循环
if (fleet.getFleetData().getNumMembers() <= 0) continue;
//声呐射程
float baseSensorRange = pf.getBaseSensorRangeToDetect(fleet.getSensorProfile());
//可以看到玩家舰队
boolean visible = fleet.isVisibleToPlayerFleet();
SectorEntityToken.VisibilityLevel level = fleet.getVisibilityLevelToPlayerFleet();
float joinRange = Misc.getBattleJoinRange();
if (fleet.getFaction().isPlayerFaction() && !fleet.isStationMode()) {
joinRange += Global.getSettings().getFloat("battleJoinRangePlayerFactionBonus");
}
//距离小于可以加入战斗的距离,且不是玩家舰队,且距离小于声呐范围或者(可以触碰并且等级XXXXX看不懂),且舰队有AI,AI想加入战斗
if (dist < joinRange
&& !fleet.isPlayerFleet()
&& (dist < baseSensorRange || (visible && level != SectorEntityToken.VisibilityLevel.SENSOR_CONTACT))
&& ((fleet.getAI() != null && fleet.getAI().wantsToJoin(b, true)) || fleet.isStationMode())) {
//获取舰队
pulledIn.add(fleet);
}
}
//结束战斗
b.leave(actualOther, false);
//完成战斗相关,每太看懂
b.finish(BattleAPI.BattleSide.NO_JOIN, false);
//获取舰队加入List
pulledIn.add(actualOther);
} catch (Exception e) {
return null;
}
return Util.getHighestLevelEnemyCommanderInBattle(pulledIn);
}
可以看到他用了一个巨神奇的方式实现需求,毕竟只有需要加入战斗的船才需要加入插件用这个方式就可以保证对战双方都有这个MOD的插件,MarketCMD这个东西应该是市场相关的我猜,我还以为是刷新船到市场的时候给他增加船插,这个操作实在是很秀
星舰传奇有非常多的状态修改可以参考,真的太棒了:
if(isFighter) {
switch (trait.getTypeId()) {
case "fighter_damage":
stats.getBallisticWeaponDamageMult().modifyPercent(id, e);
stats.getEnergyWeaponDamageMult().modifyPercent(id, e);
stats.getMissileWeaponDamageMult().modifyPercent(id, e);
break;
case "fighter_speed":
stats.getAcceleration().modifyPercent(id, e);
stats.getMaxSpeed().modifyPercent(id, e);
stats.getTurnAcceleration().modifyPercent(id, e);
break;
case "fighter_durability":
stats.getHullDamageTakenMult().modifyPercent(id, -e);
stats.getShieldDamageTakenMult().modifyPercent(id, -e);
stats.getArmorDamageTakenMult().modifyPercent(id, -e);
break;
}
} else {
switch (trait.getTypeId()) {
case "ammo_regen":
stats.getBallisticAmmoRegenMult().modifyPercent(id, e);
stats.getEnergyAmmoRegenMult().modifyPercent(id, e);
stats.getMissileAmmoRegenMult().modifyPercent(id, e);
break;
case "ammo_capacity":
stats.getBallisticAmmoBonus().modifyPercent(id, e);
stats.getEnergyAmmoBonus().modifyPercent(id, e);
stats.getMissileAmmoBonus().modifyPercent(id, e);
break;
case "system_cooldown":
stats.getSystemCooldownBonus().modifyPercent(id, e);
break;
case "system_regen_rate":
stats.getSystemRegenBonus().modifyPercent(id, e);
break;
case "ballistics_rof":
stats.getBallisticRoFMult().modifyPercent(id, e);
break;
case "energy_cost":
stats.getEnergyWeaponFluxCostMod().modifyPercent(id, e);
break;
case "pd_range":
stats.getNonBeamPDWeaponRangeBonus().modifyPercent(id, e);
stats.getBeamPDWeaponRangeBonus().modifyPercent(id, e);
break;
case "pd_damage":
stats.getDamageToMissiles().modifyPercent(id, e);
stats.getDamageToFighters().modifyPercent(id, e);
break;
case "dmod_integrity":
int dmods = 0;
for(String modId : ship.getVariant().getPermaMods()) {
if(Global.getSettings().getHullModSpec(modId).hasTag("dmod")) dmods++;
}
stats.getHullBonus().modifyPercent(id, e * dmods);
break;
case "missile_guidance":
stats.getMissileGuidance().modifyPercent(id, e);
stats.getMissileAccelerationBonus().modifyPercent(id, e);
stats.getMissileMaxSpeedBonus().modifyPercent(id, e);
stats.getMissileTurnAccelerationBonus().modifyPercent(id, e);
stats.getMissileMaxTurnRateBonus().modifyPercent(id, e);
break;
case "missile_reload":
stats.getMissileRoFMult().modifyPercent(id, e);
break;
case "cursed":
CombatPlugin.CURSED.put(ship.getId(), e);
break;
case "phase_mad":
CombatPlugin.PHASEMAD.put(ship.getId(), e);
break;
case "dmod_effect":
stats.getDynamic().getStat(Stats.DMOD_EFFECT_MULT).modifyPercent(id, e);
break;
case "survey":
stats.getDynamic().getMod(Stats.getSurveyCostReductionId(Commodities.SUPPLIES)).modifyFlat(id, -e);
break;
case "blockade_runner":
stats.getZeroFluxSpeedBoost().modifyPercent(id, e);
break;
case "drive_stabilizer":
stats.getSensorProfile().modifyFlat(id, e);
break;
case "command_support":
stats.getDynamic().getMod(Stats.COMMAND_POINT_RATE_FLAT).modifyFlat(id, e * 0.01f);
break;
case "nav_support":
stats.getDynamic().getMod(Stats.COORDINATED_MANEUVERS_FLAT).modifyFlat(id, e);
break;
case "ecm_support":
stats.getDynamic().getMod(Stats.ELECTRONIC_WARFARE_FLAT).modifyFlat(id, e);
break;
case "cr_cap":
stats.getMaxCombatReadiness().modifyFlat(id, e * 0.01f, trait.getName(true));
break;
case "cr_recovery":
stats.getBaseCRRecoveryRatePercentPerDay().modifyPercent(id, e);
break;
case "damage":
stats.getBallisticWeaponDamageMult().modifyPercent(id, e);
stats.getEnergyWeaponDamageMult().modifyPercent(id, e);
stats.getMissileWeaponDamageMult().modifyPercent(id, e);
break;
case "malfunction":
stats.getCriticalMalfunctionChance().modifyPercent(id, e);
stats.getEngineMalfunctionChance().modifyPercent(id, e);
stats.getShieldMalfunctionChance().modifyPercent(id, e);
stats.getWeaponMalfunctionChance().modifyPercent(id, e);
break;
case "mount_durability":
stats.getWeaponHealthBonus().modifyPercent(id, e);
break;
case "engine_durability":
stats.getEngineHealthBonus().modifyPercent(id, e);
break;
case "crew_casualties":
stats.getCrewLossMult().modifyPercent(id, e);
stats.getDynamic().getStat(Stats.FIGHTER_CREW_LOSS_MULT).modifyPercent(id, e);
break;
case "recovery_chance":
stats.getDynamic().getMod(Stats.INDIVIDUAL_SHIP_RECOVERY_MOD).modifyPercent(id, e);
stats.getBreakProb().modifyPercent(id, -e);
break;
case "maneuverability":
stats.getAcceleration().modifyPercent(id, e);
stats.getDeceleration().modifyPercent(id, e);
stats.getTurnAcceleration().modifyPercent(id, e);
stats.getMaxTurnRate().modifyPercent(id, e);
break;
case "hull_integrity":
stats.getHullBonus().modifyPercent(id, e);
break;
case "shield_strength":
stats.getShieldDamageTakenMult().modifyPercent(id, e);
break;
case "armor_strength":
stats.getArmorBonus().modifyPercent(id, e);
break;
case "engine_power":
stats.getMaxSpeed().modifyPercent(id, e);
break;
case "emp_resistance":
stats.getEmpDamageTakenMult().modifyPercent(id, -e);
break;
case "shield_stability":
stats.getShieldUpkeepMult().modifyPercent(id, e);
break;
case "peak_cr_time":
stats.getPeakCRDuration().modifyPercent(id, e);
break;
case "overload_time":
stats.getOverloadTimeMod().modifyPercent(id, e);
break;
case "flux_capacity":
stats.getFluxCapacity().modifyPercent(id, e);
break;
case "flux_dissipation":
stats.getFluxDissipation().modifyPercent(id, e);
break;
case "sensor_strength":
stats.getSensorStrength().modifyPercent(id, e);
break;
case "sensor_profile":
stats.getSensorProfile().modifyPercent(id, e);
break;
case "refit_time":
stats.getFighterRefitTimeMult().modifyPercent(id, e);
break;
case "salvage":
stats.getDynamic().getMod(Stats.SALVAGE_VALUE_MULT_MOD).modifyPercent(id, e);
break;
case "cargo_capacity":
stats.getCargoMod().modifyFlat(id, e);
break;
case "fuel_efficiency":
stats.getFuelUseMod().modifyPercent(id, e);
break;
case "fuel_capacity":
stats.getFuelMod().modifyFlat(id, e);
break;
case "supply_upkeep":
stats.getSuppliesPerMonth().modifyPercent(id, e);
break;
case "phase_cost":
stats.getPhaseCloakActivationCostBonus().modifyPercent(id, e);
stats.getPhaseCloakUpkeepCostBonus().modifyPercent(id, e);
break;
case "phase_cooldown":
stats.getPhaseCloakCooldownBonus().modifyPercent(id, e);
break;
case "range":
stats.getBallisticWeaponRangeBonus().modifyPercent(id, e);
stats.getEnergyWeaponRangeBonus().modifyPercent(id, e);
stats.getMissileWeaponRangeBonus().modifyPercent(id, e);
break;
case "repair":
stats.getCombatEngineRepairTimeMult().modifyPercent(id, -e);
stats.getCombatWeaponRepairTimeMult().modifyPercent(id, -e);
stats.getRepairRatePercentPerDay().modifyPercent(id, e);
break;
case "weapon_stability":
stats.getRecoilPerShotMult().modifyPercent(id, e);
break;
case "turret_rotation":
stats.getWeaponTurnRateBonus().modifyPercent(id, e);
break;
case "vent_rate":
stats.getVentRateMult().modifyPercent(id, e);
break;
case "shield_raise_rate":
stats.getShieldUnfoldRateMult().modifyPercent(id, e);
break;
}
}
PermaMod从代码上看好像就是那种不可修改的内置插槽:
public static void updateRepHullMod(FleetMemberAPI ship) {
if(!RepRecord.isShipNotable(ship)) return;
Trait.Tier tier = RepRecord.get(ship).getTier();
ShipVariantAPI v;
if(tier == Trait.Tier.UNKNOWN) {
Reputation.removeShipOfNote(ship);
Util.removeRepHullmodFromVariant(ship.getVariant());
return;
}
if(ship.getVariant().isStockVariant()) {
v = ship.getVariant().clone();
v.setSource(VariantSource.REFIT);
ship.setVariant(v, false, false);
} else v = ship.getVariant();
Util.removeRepHullmodFromVariant(v);
v.addPermaMod(tier.getHullModID());
List<String> slots = v.getModuleSlots();
for(int i = 0; i < slots.size(); ++i) {
ShipVariantAPI module = v.getModuleVariant(slots.get(i));
if(module == null) continue;
if(module.isStockVariant()) {
module = module.clone();
module.setSource(VariantSource.REFIT);
v.setModuleVariant(slots.get(i), module);
}
module.addPermaMod(tier.getHullModID());
}
Reputation.addShipOfNote(ship);
ship.updateStats();
}
分析的好啊分析的好啊{:5_118:} SGRS 发表于 2022-11-23 15:33
分析的好啊分析的好啊
mod讨论区讨论代码的好少... zyx547864023 发表于 2022-11-23 15:35
mod讨论区讨论代码的好少...
你应该找群加入。大佬更活跃,交流更实时。{:tieba_15:} 变成圆 发表于 2022-11-23 16:06
你应该找群加入。大佬更活跃,交流更实时。
搜不到群,有群号吗? zyx547864023 发表于 2022-11-23 16:06
搜不到群,有群号吗?
我没有。可以问问最近活跃的大神。 zyx547864023 发表于 2022-11-23 16:06
搜不到群,有群号吗?
首页最下面就有hh,才发现。刚好有新人问加群的贴有人回复了。 变成圆 发表于 2022-11-23 23:15
首页最下面就有hh,才发现。刚好有新人问加群的贴有人回复了。
是的我已经进去了 zyx547864023 发表于 2022-11-23 23:16
是的我已经进去了
{:tieba_21:}
页:
[1]