Package asis

Source Code of asis.IncreasedSpawns

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package asis;

import asis.ASISSaveFile.GUISettings;
import asis.ini.INI;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import skyproc.*;
import skyproc.gui.SPProgressBarPlug;

/**
*
* @author pc tech
*/
public class IncreasedSpawns {
   
    public void addSpawns() {
        internalAddSpawns();
    }
   
    public void addSpawns(ASIS a) {
        if (a.getModExclusions() != null) {
            modExclusions.addAll(a.getModExclusions());
        }
        internalAddSpawns();
    }
   
    private void internalAddSpawns() {
        SPProgressBarPlug.setStatus("Increased Spawns: Starting Patch");
        SPProgressBarPlug.incrementBar();
        Mod merger = new Mod("TmpMerger", false);
        merger.addAsOverrides(SPGlobal.getDB());
        //Processes the ini files and checks them for the patch settings.
        processINI();
        //getPatchSettings();
        getBlockList();
        addIncreasedSpawns(merger);
    }
   
    private void addIncreasedSpawns(Mod merger) {
        //FormID dupNPCForm = null;
        String scriptName = "increasedSpawns";
        int num;
        float numMult;
        boolean include;
        String edid;
       
        FLST listOfValidCells = null;
        FLST listOfValidNPCs = null;
        FormID uniqueFaction = null;
       
        try {
            listOfValidNPCs = new FLST(SPGlobal.getGlobalPatch(), "listOfValidNPCs");
            listOfValidCells = new FLST(SPGlobal.getGlobalPatch(), "listOfValidCells");
            uniqueFaction = new FormID("000800", SPGlobal.getDB().getMod(new ModListing("ASIS-Dependency", false)).getInfo());
        } catch (NullPointerException exception) {
            JOptionPane.showMessageDialog(null, "The patcher will not work correctly if ASIS-Dependency.esp is not\ninstalled before running the patcher.  Please install the plugin\n(and check that it has not been ghosted by Wrye Bash) and try\nagain.  If you have done so and continue to see this message,\nplease contact the author.  The patcher will now exit.");
            System.exit(0);
        }
       
        SPProgressBarPlug.setStatus("Increased Spawns: Adding Spawns/Duplicating NPCs");
        SPProgressBarPlug.incrementBar();
       
        for (int i = 0; i < cellExclusions.size(); i++) {
            listOfValidCells.addFormEntry((FormID) cellExclusions.get(i));
        }
        ArrayList<FormID> globals = new ArrayList<>();
        FormID intspawns;
        for (int i = 0; i < 10; i++) {
            globals.add((new GLOB(SPGlobal.getGlobalPatch(), "ASISSpawnWeight" + i,
                    GLOB.GLOBType.Float, spawnweight[i], true)).getForm());
        }
        intspawns = (new GLOB(SPGlobal.getGlobalPatch(), "ASISIntSpawns", GLOB.GLOBType.Float,
                ASIS.save.getDouble(GUISettings.ISREDUCEDINTERIORSPAWNS).floatValue(), true)).getForm();
       
        for (NPC_ n : merger.getNPCs()) {
           
            include = getValidNPC(n);
           
            if (include) {
                try {
                    //Returns the formID of the dup for addition to the NPC below.
                    //dupNPCForm = duplicateNPCForSpawns(n);
                    //duplicateNPCForTemplate(n);

                    edid = n.getEDID();
                   
                    listOfValidNPCs.addFormEntry(n.getForm());

                    //Determines any unique NPC maximum spawn settings.
                    num = getNumMaxSpawns(n);
                    numMult = getNumReducedSpawns(n) * getNumIncreasedSpawns(n);

                    //Actual script addition is done here.
                    ScriptRef script = new ScriptRef(scriptName);
                    //script.setProperty("creatureToSpawn", dupNPCForm);
                    script.setProperty("listOfValidNPCs", listOfValidNPCs.getForm());
                    script.setProperty("listOfValidCells", listOfValidCells.getForm());
                    script.setProperty("uniqueSpawnFaction", uniqueFaction);
                    //script.setProperty("creatureToSpawn", n.getForm());
                    script.setProperty("reducedInteriorSpawns", reducedInteriorSpawns);
                    if (n.getEDID().toUpperCase().contains("AMBUSH")) {
                        script.setProperty("isAmbushSpawn", true);
                    } else {
                        script.setProperty("isAmbushSpawn", false);
                    }
                    script.setProperty("numMaxSpawns", num);
                    for (int i = 0; i < globals.size(); i++) {
                        script.setProperty("spawn" + i + "weightG", (globals.get(i)));
                    }
                    script.setProperty("interiorSpawnsG", intspawns);
                    script.setProperty("maxNumG", (new GLOB(SPGlobal.getGlobalPatch(), "ASISMaxNum" + edid,
                        GLOB.GLOBType.Float, num, true)).getForm());
                    script.setProperty("multiplierG", (new GLOB(SPGlobal.getGlobalPatch(), "ASISNumMult" + edid,
                        GLOB.GLOBType.Float, numMult, true)).getForm());
                    n.scripts.addScript(script);
                    SPGlobal.getGlobalPatch().addRecord(n);
                   
                } catch (Exception e) {
                    SPGlobal.logException(e);
                }
            }
        }
        //Add the NPC to the patch.
        SPGlobal.getGlobalPatch().addRecord(listOfValidNPCs);
    }
   
    private void processINI() {
       
        SPProgressBarPlug.setStatus("Increased Spawns: Processing INI");
        SPProgressBarPlug.incrementBar();
        INI ini = null;

        //Sets up the file reader for the ini file.
        try {
            ini = new INI("IncreasedSpawns.ini");
        } catch (IOException ex) {
            Logger.getLogger(NPCPotions.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        Collection<INI.IniSectionHead> sections = getSectionList();
       
        ini.addSection(sections);
       
        try {
            ini.readData();
        } catch (IOException ex) {
            Logger.getLogger(NPCPotions.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        initializeLists(ini);
    }
   
    private boolean getValidNPC(NPC_ n) {
        boolean include = false;
        boolean exclude = false;
        String list;
        String edid = n.getEDID().toUpperCase();
       
        if (!npcBlockList.contains(n.getForm())) {
            if (inclusions.isEmpty()) {
                include = true;
            }
            if (!include) {
                for (int i = 0; i < inclusions.size(); i++) {
                    list = ((String) inclusions.get(i)).toUpperCase();
                    if (edid.contains(list)) {
                        include = true;
                        break;
                    }
                }
            }
            if (include && !exclusions.isEmpty() && !modExclusions.isEmpty()) {
                exclude = false;
            }
            if (!exclude) {
                for (int i = 0; i < exclusions.size(); i++) {
                    list = ((String) exclusions.get(i)).toUpperCase();
                    if (edid.contains(list)) {
                        exclude = true;
                        break;
                    }
                }
            }
            if (include && !exclude) {
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    }
   
    private int getNumMaxSpawns(NPC_ n) {
        String list;
        if (!npcMaxSettings.isEmpty()) {
            for (Map.Entry<String, String> entry : npcMaxSettings.entrySet()) {
                list = entry.getKey();
                if (n.getEDID().toUpperCase().contains(list)) {
                    return Integer.parseInt(npcMaxSettings.get(list));
                }
            }
        }
        return 9;
    }
   
    private float getNumReducedSpawns(NPC_ n) {
        String list;
        if (!npcReducedSettings.isEmpty()) {
            for (Map.Entry<String, String> entry : npcReducedSettings.entrySet()) {
                list = entry.getKey();
                if (n.getEDID().toUpperCase().contains(list)) {
                    return Float.parseFloat(npcReducedSettings.get(list));
                }
            }
        }
        return -1;
    }
   
    private float getNumIncreasedSpawns(NPC_ n) {
        String list;
        if (!npcIncreasedSettings.isEmpty()) {
            for (Map.Entry<String, String> entry : npcIncreasedSettings.entrySet()) {
                list = entry.getKey();
                if (n.getEDID().toUpperCase().contains(list)) {
                    return Float.parseFloat(npcIncreasedSettings.get(list));
                }
            }
        }
        return -1;
    }
   
    private void getBlockList() {
        //Clean-up NPC's from excluded mods.  This is done as blocking the import
        // could cause previous NPC's to override an excluded mods NPC's.
        String list;
        Mod tempMod;
        for (int i = 0; i < modExclusions.size(); i++) {
            list = (String) modExclusions.get(i);
            try {
                tempMod = SPGlobal.getDB().getMod(new ModListing(list));
                for (NPC_ n : tempMod.getNPCs()) {
                    npcBlockList.add(n.getForm());
                }
            } catch (Exception e) {
                //Do nothing, probably doesn't have the mod in the exclusions.
            }
        }
    }
   
    private Collection<INI.IniSectionHead> getSectionList() {
        Collection<INI.IniSectionHead> sectionList = new ArrayList<>();
       
        for (IniSection currentSection : IniSection.values()) {
            sectionList.add(new INI.IniSectionHead(currentSection.getName(), currentSection.getFormat()));
        }
       
        return sectionList;
    }
   
    private void initializeLists(INI ini) {
        inclusions = (ArrayList) ini.getCollection(new INI.IniSectionHead(IniSection.NPCINCLUSIONS.getName(),
                IniSection.NPCINCLUSIONS.getFormat()));
        exclusions = (ArrayList) ini.getCollection(new INI.IniSectionHead(IniSection.NPCEXCLUSIONS.getName(),
                IniSection.NPCEXCLUSIONS.getFormat()));
        modExclusions.addAll((ArrayList) ini.getCollection(new INI.IniSectionHead(IniSection.MODEXCLUSIONS.getName(),
                IniSection.MODEXCLUSIONS.getFormat())));
       
        patchSettingsMap = ini.getMap(new INI.IniSectionHead(IniSection.PATCHSETTINGS.getName(),
                IniSection.PATCHSETTINGS.getFormat()));
       
        cellExclusions = (ArrayList) ini.getCollectionForms(new INI.IniSectionHead(IniSection.CELLEXCLUSIONS.getName(),
                IniSection.CELLEXCLUSIONS.getFormat()));
       
        npcMaxSettings = ini.getMap(new INI.IniSectionHead(IniSection.NPCMAXSPAWNSETTINGS.getName(),
                IniSection.NPCMAXSPAWNSETTINGS.getFormat()));
       
        npcReducedSettings = ini.getMap(new INI.IniSectionHead(IniSection.NPCREDUCEDSPAWNSETTINGS.getName(),
                IniSection.NPCREDUCEDSPAWNSETTINGS.getFormat()));
       
        npcIncreasedSettings = ini.getMap(new INI.IniSectionHead(IniSection.NPCREDUCEDSPAWNSETTINGS.getName(),
                IniSection.NPCREDUCEDSPAWNSETTINGS.getFormat()));
       
        spawnweight[0] = ASIS.save.getDouble(GUISettings.ISSPAWN0WEIGHT).floatValue();
        spawnweight[1] = ASIS.save.getDouble(GUISettings.ISSPAWN1WEIGHT).floatValue();
        spawnweight[2] = ASIS.save.getDouble(GUISettings.ISSPAWN2WEIGHT).floatValue();
        spawnweight[3] = ASIS.save.getDouble(GUISettings.ISSPAWN3WEIGHT).floatValue();
        spawnweight[4] = ASIS.save.getDouble(GUISettings.ISSPAWN4WEIGHT).floatValue();
        spawnweight[5] = ASIS.save.getDouble(GUISettings.ISSPAWN5WEIGHT).floatValue();
        spawnweight[6] = ASIS.save.getDouble(GUISettings.ISSPAWN6WEIGHT).floatValue();
        spawnweight[7] = ASIS.save.getDouble(GUISettings.ISSPAWN7WEIGHT).floatValue();
        spawnweight[8] = ASIS.save.getDouble(GUISettings.ISSPAWN8WEIGHT).floatValue();
        spawnweight[9] = ASIS.save.getDouble(GUISettings.ISSPAWN9WEIGHT).floatValue();
       
    }
   
    private enum IniSection {
       
        PATCHSETTINGS(INI.IniDataFormat.KEY_VALUE, "PATCHSETTINGS"),
        NPCINCLUSIONS(INI.IniDataFormat.VALUE, "NPCINCLUSIONS"),
        NPCEXCLUSIONS(INI.IniDataFormat.VALUE, "NPCEXCLUSIONS"),
        NPCMAXSPAWNSETTINGS(INI.IniDataFormat.KEY_VALUE, "NPCMAXSPAWNSETTINGS"),
        NPCREDUCEDSPAWNSETTINGS(INI.IniDataFormat.KEY_VALUE, "NPCREDUCEDSPAWNSETTINGS"),
        CELLEXCLUSIONS(INI.IniDataFormat.VALUE, "CELLEXCLUSIONS"),
        MODEXCLUSIONS(INI.IniDataFormat.VALUE, "MODEXCLUSIONS");
        private INI.IniDataFormat format;
        private String name;
       
        IniSection(INI.IniDataFormat format, String name) {
            this.format = format;
            this.name = name;
        }
       
        String getName() {
            return name;
        }
       
        INI.IniDataFormat getFormat() {
            return format;
        }
    }
    String npcType = null;
    String npcSpawnCount = null;
    String settingType = null;
    String settingValue = null;
    Map<String, String> npcMaxSettings = new HashMap<>();
    Map<String, String> npcReducedSettings = new HashMap<>();
    Map<String, String> npcIncreasedSettings = new HashMap<>();
    Map<String, String> patchSettingsMap = new HashMap<>();
    Map<FormID, FormID> formsOrigDup = new HashMap<>();
    ArrayList inclusions = new ArrayList<>(0);
    ArrayList exclusions = new ArrayList<>(0);
    ArrayList modExclusions = new ArrayList<>(0);
    ArrayList cellExclusions = new ArrayList<>(0);
    ArrayList<FormID> npcBlockList = new ArrayList<>();
    float[] spawnweight = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
    boolean reducedInteriorSpawns = false;
    public int numProgressSections = 5;
}
TOP

Related Classes of asis.IncreasedSpawns

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.