001package com.fs.starfarer.api.impl.combat.dweller; 002 003import java.util.LinkedHashMap; 004import java.util.Map; 005 006import com.fs.starfarer.api.Global; 007import com.fs.starfarer.api.combat.BaseHullMod; 008import com.fs.starfarer.api.combat.CombatEngineAPI; 009import com.fs.starfarer.api.combat.MutableShipStatsAPI; 010import com.fs.starfarer.api.combat.ShipAPI; 011import com.fs.starfarer.api.combat.ShipAPI.HullSize; 012 013/** 014 * Required for Shrouded Dweller "ships" - spawns combat entities for custom rendering etc. 015 * 016 * @author Alex 017 * 018 */ 019public class DwellerHullmod extends BaseHullMod { 020 021 public static Map<String, DwellerShipCreator> SHIP_CREATORS = new LinkedHashMap<>(); 022 023 static { 024 //SHIP_CREATORS.put("shrouded_tendril", new TestDwellerShipCreator()); 025 SHIP_CREATORS.put("shrouded_tendril", new ShroudedTendrilShipCreator()); 026 SHIP_CREATORS.put("shrouded_eye", new ShroudedEyeShipCreator()); 027 SHIP_CREATORS.put("shrouded_vortex", new ShroudedVortexShipCreator()); 028 SHIP_CREATORS.put("shrouded_maw", new ShroudedMawShipCreator()); 029 SHIP_CREATORS.put("shrouded_maelstrom", new ShroudedMaelstromShipCreator()); 030 SHIP_CREATORS.put("shrouded_ejecta", new ShroudedEjectaShipCreator()); 031 } 032 033 034 public static String INITED_DWELLER_STUFF = "inited_dweller_stuff"; 035 036 protected DwellerShipCreator getShipCreator(String hullId) { 037 return SHIP_CREATORS.get(hullId); 038 } 039 protected boolean addStrategyAI() { 040 return true; 041 } 042 043 @Override 044 public void applyEffectsBeforeShipCreation(HullSize hullSize, MutableShipStatsAPI stats, String id) { 045 if (stats == null || stats.getVariant() == null) return; 046 String hullId = stats.getVariant().getHullSpec().getBaseHullId(); 047 DwellerShipCreator creator = getShipCreator(hullId); 048 if (creator != null) { 049 creator.initBeforeShipCreation(hullSize, stats, id); 050 } 051 } 052 053 @Override 054 public void applyEffectsAfterShipCreation(ShipAPI ship, String id) { 055 if (ship == null || ship.getHullSpec() == null) return; 056 String hullId = ship.getHullSpec().getBaseHullId(); 057 DwellerShipCreator creator = getShipCreator(hullId); 058 if (creator != null) { 059 creator.initAfterShipCreation(ship, id); 060 } 061 } 062 063 064 065 @Override 066 public void applyEffectsAfterShipAddedToCombatEngine(ShipAPI ship, String id) { 067 if (ship == null || ship.getHullSpec() == null) return; 068 String hullId = ship.getHullSpec().getBaseHullId(); 069 DwellerShipCreator creator = getShipCreator(hullId); 070 if (creator != null) { 071 creator.initAfterShipAddedToCombatEngine(ship, id); 072 } 073 074 if (addStrategyAI()) { 075 CombatEngineAPI engine = Global.getCombatEngine(); 076 if (!engine.hasPluginOfClass(DwellerCombatStrategyForBothSidesPlugin.class)) { 077 engine.addPlugin(new DwellerCombatStrategyForBothSidesPlugin()); 078 } 079 } 080 } 081 082 @Override 083 public void advanceInCombat(ShipAPI ship, float amount) { 084 if (amount <= 0f || ship == null) return; 085 086 if (ship.hasTag(INITED_DWELLER_STUFF)) return; 087 ship.addTag(INITED_DWELLER_STUFF); 088 089 if (ship == null || ship.getHullSpec() == null) return; 090 String hullId = ship.getHullSpec().getBaseHullId(); 091 DwellerShipCreator creator = getShipCreator(hullId); 092 if (creator != null) { 093 creator.initInCombat(ship); 094 } 095 } 096} 097 098 099 100 101 102 103 104 105 106 107 108 109 110