Search in sources :

Example 1 with ISoliniaAlignment

use of com.solinia.solinia.Interfaces.ISoliniaAlignment in project solinia3-core by mixxit.

the class JsonAlignmentRepository method reload.

@Override
public void reload() {
    List<ISoliniaAlignment> file = new ArrayList<ISoliniaAlignment>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaAlignment>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    alignments.clear();
    for (ISoliniaAlignment i : file) {
        alignments.put(i.getId(), i);
    }
    System.out.println("Reloaded " + alignments.size() + " Alignments");
}
Also used : ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) ISoliniaAlignment(com.solinia.solinia.Interfaces.ISoliniaAlignment) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ISoliniaAlignment

use of com.solinia.solinia.Interfaces.ISoliniaAlignment in project solinia3-core by mixxit.

the class ConfigurationManager method addAlignment.

@Override
public void addAlignment(String alignmentname) throws Exception {
    for (ISoliniaAlignment alignment : getAlignments()) {
        if (alignment.getName().equals(alignmentname.toUpperCase()))
            throw new Exception("Alignment already exists");
    }
    SoliniaAlignment alignment = new SoliniaAlignment();
    alignment.setId(getNextAlignmentId());
    alignment.setName(alignmentname);
    alignmentsRepository.add(alignment);
}
Also used : SoliniaAlignment(com.solinia.solinia.Models.SoliniaAlignment) ISoliniaAlignment(com.solinia.solinia.Interfaces.ISoliniaAlignment) ISoliniaAlignment(com.solinia.solinia.Interfaces.ISoliniaAlignment) InvalidCraftSettingException(com.solinia.solinia.Exceptions.InvalidCraftSettingException) InvalidNPCEventSettingException(com.solinia.solinia.Exceptions.InvalidNPCEventSettingException) InvalidNpcSettingException(com.solinia.solinia.Exceptions.InvalidNpcSettingException) InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) InvalidItemSettingException(com.solinia.solinia.Exceptions.InvalidItemSettingException) InvalidAASettingException(com.solinia.solinia.Exceptions.InvalidAASettingException) InvalidFactionSettingException(com.solinia.solinia.Exceptions.InvalidFactionSettingException) InvalidLootTableSettingException(com.solinia.solinia.Exceptions.InvalidLootTableSettingException) InvalidRaceSettingException(com.solinia.solinia.Exceptions.InvalidRaceSettingException) IOException(java.io.IOException) InvalidSpawnGroupSettingException(com.solinia.solinia.Exceptions.InvalidSpawnGroupSettingException) InvalidClassSettingException(com.solinia.solinia.Exceptions.InvalidClassSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) InvalidLootDropSettingException(com.solinia.solinia.Exceptions.InvalidLootDropSettingException) InvalidZoneSettingException(com.solinia.solinia.Exceptions.InvalidZoneSettingException)

Example 3 with ISoliniaAlignment

use of com.solinia.solinia.Interfaces.ISoliniaAlignment in project solinia3-core by mixxit.

the class ConfigurationManager method updateKingsAndEmperors.

@Override
public void updateKingsAndEmperors() {
    List<UUID> goodkingCache = new ArrayList<UUID>();
    List<UUID> neutralkingCache = new ArrayList<UUID>();
    List<UUID> evilkingCache = new ArrayList<UUID>();
    for (ISoliniaRace race : getRaces()) {
        HashMap<UUID, Integer> kingCount = new HashMap<UUID, Integer>();
        try {
            for (ISoliniaPlayer player : StateManager.getInstance().getPlayerManager().getCharacters()) {
                if (player.getRaceId() != race.getId())
                    continue;
                if (!player.isMain())
                    continue;
                if (player.getFealty() == null)
                    continue;
                ISoliniaPlayer fealtyPlayer = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getFealty());
                if (fealtyPlayer.getRaceId() != player.getRaceId())
                    continue;
                if (!fealtyPlayer.isMain())
                    continue;
                if (fealtyPlayer.isAlignmentEmperor())
                    continue;
                if (!kingCount.containsKey(player.getFealty())) {
                    kingCount.put(player.getFealty(), 1);
                } else {
                    kingCount.put(player.getFealty(), kingCount.get(player.getFealty()) + 1);
                }
            }
            Entry<UUID, Integer> maxEntry = null;
            for (Entry<UUID, Integer> entry : kingCount.entrySet()) {
                if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                    maxEntry = entry;
                }
            }
            if (maxEntry != null) {
                if (race.getKing() == null || !race.getKing().equals(maxEntry.getKey()))
                    StateManager.getInstance().getConfigurationManager().getRace(race.getId()).setKing(maxEntry.getKey());
                switch(race.getAlignment()) {
                    case "GOOD":
                        goodkingCache.add(maxEntry.getKey());
                        break;
                    case "NEUTRAL":
                        neutralkingCache.add(maxEntry.getKey());
                        break;
                    case "EVIL":
                        evilkingCache.add(maxEntry.getKey());
                        break;
                    default:
                        break;
                }
            }
        } catch (CoreStateInitException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    try {
        // Good
        HashMap<UUID, Integer> goodkingCount = new HashMap<UUID, Integer>();
        if (StateManager.getInstance().getConfigurationManager().getAlignment("GOOD") != null)
            for (UUID king : goodkingCache) {
                ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
                if (player == null)
                    continue;
                if (!player.isMain())
                    continue;
                if (player.getRace() == null)
                    continue;
                if (!player.isRacialKing())
                    continue;
                if (player.getVoteEmperor() == null)
                    continue;
                if (player.getVoteEmperor().equals(player.getUUID()))
                    continue;
                ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
                if (fealty == null)
                    continue;
                if (fealty.getRace() == null)
                    continue;
                if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
                    continue;
                if (fealty.isRacialKing())
                    continue;
                if (!goodkingCount.containsKey(player.getVoteEmperor())) {
                    goodkingCount.put(player.getVoteEmperor(), 1);
                } else {
                    goodkingCount.put(player.getVoteEmperor(), goodkingCount.get(player.getVoteEmperor()) + 1);
                }
            }
        Entry<UUID, Integer> maxEntry = null;
        for (Entry<UUID, Integer> entry : goodkingCount.entrySet()) {
            if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                maxEntry = entry;
            }
        }
        if (maxEntry != null) {
            ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("GOOD");
            if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
                StateManager.getInstance().getConfigurationManager().getAlignment("GOOD").setEmperor(maxEntry.getKey());
        }
        // Neutral
        HashMap<UUID, Integer> neutralkingCount = new HashMap<UUID, Integer>();
        if (StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL") != null)
            for (UUID king : neutralkingCache) {
                ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
                if (player == null)
                    continue;
                if (player.getRace() == null)
                    continue;
                if (!player.isRacialKing())
                    continue;
                if (player.getVoteEmperor() == null)
                    continue;
                if (player.getVoteEmperor().equals(player.getUUID()))
                    continue;
                ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
                if (fealty == null)
                    continue;
                if (fealty.getRace() == null)
                    continue;
                if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
                    continue;
                if (fealty.isRacialKing())
                    continue;
                if (!neutralkingCount.containsKey(player.getVoteEmperor())) {
                    neutralkingCount.put(player.getVoteEmperor(), 1);
                } else {
                    neutralkingCount.put(player.getVoteEmperor(), neutralkingCount.get(player.getVoteEmperor()) + 1);
                }
            }
        maxEntry = null;
        for (Entry<UUID, Integer> entry : neutralkingCount.entrySet()) {
            if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                maxEntry = entry;
            }
        }
        if (maxEntry != null) {
            ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL");
            if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
                StateManager.getInstance().getConfigurationManager().getAlignment("NEUTRAL").setEmperor(maxEntry.getKey());
        }
        // Evil
        HashMap<UUID, Integer> evilkingCount = new HashMap<UUID, Integer>();
        if (StateManager.getInstance().getConfigurationManager().getAlignment("EVIL") != null)
            for (UUID king : evilkingCache) {
                ISoliniaPlayer player = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(king);
                if (player == null)
                    continue;
                if (player.getRace() == null)
                    continue;
                if (!player.isRacialKing())
                    continue;
                if (player.getVoteEmperor() == null)
                    continue;
                if (player.getVoteEmperor().equals(player.getUUID()))
                    continue;
                ISoliniaPlayer fealty = StateManager.getInstance().getPlayerManager().getMainCharacterDataOnly(player.getVoteEmperor());
                if (fealty == null)
                    continue;
                if (fealty.getRace() == null)
                    continue;
                if (!fealty.getRace().getAlignment().equals(player.getRace().getAlignment()))
                    continue;
                if (fealty.isRacialKing())
                    continue;
                if (!evilkingCount.containsKey(player.getVoteEmperor())) {
                    evilkingCount.put(player.getVoteEmperor(), 1);
                } else {
                    evilkingCount.put(player.getVoteEmperor(), evilkingCount.get(player.getVoteEmperor()) + 1);
                }
            }
        maxEntry = null;
        for (Entry<UUID, Integer> entry : evilkingCount.entrySet()) {
            if (maxEntry == null || entry.getValue() > maxEntry.getValue()) {
                maxEntry = entry;
            }
        }
        if (maxEntry != null) {
            ISoliniaAlignment alignment = StateManager.getInstance().getConfigurationManager().getAlignment("EVIL");
            if (alignment.getEmperor() == null || !alignment.getEmperor().equals(maxEntry.getKey()))
                StateManager.getInstance().getConfigurationManager().getAlignment("EVIL").setEmperor(maxEntry.getKey());
        }
    } catch (CoreStateInitException e) {
    // try next loop
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ArrayList(java.util.ArrayList) ISoliniaAlignment(com.solinia.solinia.Interfaces.ISoliniaAlignment) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) UUID(java.util.UUID) ISoliniaRace(com.solinia.solinia.Interfaces.ISoliniaRace)

Aggregations

ISoliniaAlignment (com.solinia.solinia.Interfaces.ISoliniaAlignment)3 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)2 ArrayList (java.util.ArrayList)2 Gson (com.google.gson.Gson)1 InvalidAASettingException (com.solinia.solinia.Exceptions.InvalidAASettingException)1 InvalidClassSettingException (com.solinia.solinia.Exceptions.InvalidClassSettingException)1 InvalidCraftSettingException (com.solinia.solinia.Exceptions.InvalidCraftSettingException)1 InvalidFactionSettingException (com.solinia.solinia.Exceptions.InvalidFactionSettingException)1 InvalidItemSettingException (com.solinia.solinia.Exceptions.InvalidItemSettingException)1 InvalidLootDropSettingException (com.solinia.solinia.Exceptions.InvalidLootDropSettingException)1 InvalidLootTableSettingException (com.solinia.solinia.Exceptions.InvalidLootTableSettingException)1 InvalidNPCEventSettingException (com.solinia.solinia.Exceptions.InvalidNPCEventSettingException)1 InvalidNpcSettingException (com.solinia.solinia.Exceptions.InvalidNpcSettingException)1 InvalidRaceSettingException (com.solinia.solinia.Exceptions.InvalidRaceSettingException)1 InvalidSpawnGroupSettingException (com.solinia.solinia.Exceptions.InvalidSpawnGroupSettingException)1 InvalidSpellSettingException (com.solinia.solinia.Exceptions.InvalidSpellSettingException)1 InvalidZoneSettingException (com.solinia.solinia.Exceptions.InvalidZoneSettingException)1 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)1 ISoliniaRace (com.solinia.solinia.Interfaces.ISoliniaRace)1 SoliniaAlignment (com.solinia.solinia.Models.SoliniaAlignment)1