Search in sources :

Example 1 with Agent

use of fr.guiguilechat.jcelechat.model.sde.npcs.Agent in project JCELechat by guiguilechat.

the class NPCsTranslater method main.

/**
 * @param args
 *          should be [database destination root], typically
 *          src/generated/resources/
 */
@SuppressWarnings("unchecked")
public static void main(String[] args) {
    int parrallelism = Runtime.getRuntime().availableProcessors() * 100;
    System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "" + parrallelism);
    long timeStart = System.currentTimeMillis();
    File folderOut = new File(args.length == 0 ? "src/generated/resources/" : args[0]);
    FileTools.delDir(folderOut);
    folderOut.mkdirs();
    LinkedHashMap<String, Agent> agents = new LinkedHashMap<>();
    LinkedHashMap<String, Corporation> corporations = new LinkedHashMap<>();
    LinkedHashMap<Integer, LPOffer> lpoffers = new LinkedHashMap<>();
    translate(Eagents.load(), agents, corporations, lpoffers);
    // sort
    Stream.of(agents, corporations).forEach(m -> {
        ArrayList<Entry<String, ?>> list = new ArrayList<>(m.entrySet());
        Collections.sort(list, (e1, e2) -> e1.getKey().compareTo(e2.getKey()));
        m.clear();
        for (Entry<String, ?> e : list) {
            ((Map<String, Object>) m).put(e.getKey(), e.getValue());
        }
    });
    ArrayList<Entry<Integer, LPOffer>> list = new ArrayList<>(lpoffers.entrySet());
    Collections.sort(list, (e1, e2) -> e1.getKey().compareTo(e2.getKey()));
    lpoffers.clear();
    for (Entry<Integer, LPOffer> e : list) {
        lpoffers.put(e.getKey(), e.getValue());
    }
    // save
    Agent.export(agents, folderOut);
    Corporation.export(corporations, folderOut);
    LPOffer.export(lpoffers, folderOut);
    logger.info("exported npcs in " + (System.currentTimeMillis() - timeStart) / 1000 + "s");
}
Also used : Agent(fr.guiguilechat.jcelechat.model.sde.npcs.Agent) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Corporation(fr.guiguilechat.jcelechat.model.sde.npcs.Corporation) Entry(java.util.Map.Entry) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LPOffer(fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer)

Example 2 with Agent

use of fr.guiguilechat.jcelechat.model.sde.npcs.Agent in project JCELechat by guiguilechat.

the class NPCsTranslater method translate.

private static void translate(LinkedHashMap<Integer, Eagents> eagents, LinkedHashMap<String, Agent> agents, LinkedHashMap<String, Corporation> corporations, LinkedHashMap<Integer, LPOffer> offers) {
    ESIAccess esi = ESIAccess.INSTANCE;
    CacheStatic cache = ESIStatic.INSTANCE.cache();
    // prefetch
    MapHolder<Integer, R_get_corporations_corporation_id> corporationsHolder = ((ListHolder<Integer>) cache.corporations.npccorps().follow(l -> {
        l.parallelStream().forEach(cache.corporations::get);
    })).toMap(i -> i, i -> cache.corporations.get(i).get());
    MapHolder<Integer, R_get_universe_factions> factionsHolder = cache.universe.factions().toMap(f -> f.faction_id);
    eagents.values().parallelStream().map(ag -> ag.locationID).distinct().forEach(lid -> Location.resolve(null, lid).system());
    // 
    LinkedHashMap<Integer, EnpcCorporations> ecorps = EnpcCorporations.load();
    Map<Integer, String> idx2name = EinvNames.loadById();
    Map<Integer, R_get_corporations_corporation_id> npcCorps = corporationsHolder.get();
    Map<Integer, R_get_universe_factions> factionById = factionsHolder.get();
    Map<Integer, Location> agentsLocation = eagents.entrySet().parallelStream().collect(Collectors.toMap(eag -> eag.getKey(), eag -> Location.resolve(null, eag.getValue().locationID)));
    logger.info("NPC prefetch received");
    for (Entry<Integer, Eagents> eagt : eagents.entrySet()) {
        Agent agent = new Agent();
        Eagents agt = eagt.getValue();
        agent.id = eagt.getKey();
        agent.corporation = ecorps.get(agt.corporationID).enName();
        agent.name = idx2name.get(agent.id);
        agent.isLocator = agt.isLocator;
        agent.level = agt.level;
        agent.type = AGENT_TYPE.of(agt.agentTypeID);
        if (agent.type == null) {
            logger.warn("no type for agent " + agent.name + " typeID=" + agt.agentTypeID);
        }
        agent.division = AGENT_DIVISION.of(agt.divisionID);
        if (agent.division == null) {
            logger.warn("no division for agent " + agent.name + " divisionID=" + agt.divisionID);
        }
        Location loc = agentsLocation.get(agent.id);
        if (loc != null) {
            agent.system = loc.system().name;
            R_get_universe_stations_station_id station = loc.station();
            if (station != null) {
                agent.station = station.name;
                agent.stationId = agt.locationID;
            }
            agents.put(agent.name, agent);
        } else {
            logger.warn("invalid location for agent " + agent.name + " locid=" + agt.locationID);
        }
    }
    logger.info("translated agents data");
    for (Entry<Integer, EnpcCorporations> e : ecorps.entrySet()) {
        Corporation add = new Corporation();
        add.id = e.getKey();
        EnpcCorporations snpc = e.getValue();
        add.name = snpc.enName();
        R_get_universe_factions faction = factionById.get(snpc.factionID);
        if (faction == null) {
            logger.debug("can't find faction from id " + snpc.factionID + " for corporation " + add.name);
        } else {
            add.faction = faction.name;
        }
        R_get_corporations_corporation_id esicorp = npcCorps.get(add.id);
        if (esicorp != null && esicorp.faction_id != 0) {
            add.warfare = factionById.get(esicorp.faction_id).name;
        }
        add.concordRate = EnpcCorporations.concordRates().getOrDefault(add.id, 0.0);
        if (add.id == EnpcCorporations.CONCORD_ID) {
            add.concordRate = 1.0;
        }
        corporations.put(add.name, add);
    }
    Map<Integer, LPOffer> covertedOffers = corporations.values().stream().parallel().flatMap(c -> {
        Requested<R_get_loyalty_stores_corporation_id_offers[]> req = esi.connection.get_loyalty_stores_offers(c.id, null);
        return req.isOk() ? Stream.of(req.getOK()) : Stream.empty();
    }).map(offer -> makeOffer(offer)).filter(o -> o != null).collect(Collectors.toMap(off -> off.id, off -> off, (o1, o2) -> o1));
    offers.putAll(covertedOffers);
    corporations.values().stream().parallel().forEach(c -> loadCorpOffers(c, esi.connection, offers));
}
Also used : R_get_universe_stations_station_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id) ItemRef(fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer.ItemRef) FileTools(fr.guiguilechat.jcelechat.model.FileTools) Corporation(fr.guiguilechat.jcelechat.model.sde.npcs.Corporation) LoggerFactory(org.slf4j.LoggerFactory) AGENT_DIVISION(fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_DIVISION) EinvNames(fr.guiguilechat.jcelechat.model.sde.load.bsd.EinvNames) ESIStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic) Agent(fr.guiguilechat.jcelechat.model.sde.npcs.Agent) LPOffer(fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer) MapHolder(fr.lelouet.tools.holders.interfaces.collections.MapHolder) ESIAccess(fr.guiguilechat.jcelechat.jcesi.disconnected.modeled.ESIAccess) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Eblueprints(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eblueprints) R_get_universe_factions(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions) Map(java.util.Map) ListHolder(fr.lelouet.tools.holders.interfaces.collections.ListHolder) Location(fr.guiguilechat.jcelechat.jcesi.tools.locations.Location) Material(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eblueprints.Material) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) Collectors(java.util.stream.Collectors) File(java.io.File) R_get_loyalty_stores_corporation_id_offers(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_loyalty_stores_corporation_id_offers) AGENT_TYPE(fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_TYPE) Eagents(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eagents) Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) Stream(java.util.stream.Stream) R_get_corporations_corporation_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id) Entry(java.util.Map.Entry) EnpcCorporations(fr.guiguilechat.jcelechat.model.sde.load.fsd.EnpcCorporations) Comparator(java.util.Comparator) Collections(java.util.Collections) EtypeIDs(fr.guiguilechat.jcelechat.model.sde.load.fsd.EtypeIDs) Requested(fr.guiguilechat.jcelechat.jcesi.interfaces.Requested) R_get_corporations_corporation_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id) R_get_loyalty_stores_corporation_id_offers(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_loyalty_stores_corporation_id_offers) R_get_universe_stations_station_id(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id) ListHolder(fr.lelouet.tools.holders.interfaces.collections.ListHolder) R_get_universe_factions(fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions) CacheStatic(fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic) EnpcCorporations(fr.guiguilechat.jcelechat.model.sde.load.fsd.EnpcCorporations) LPOffer(fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer) Agent(fr.guiguilechat.jcelechat.model.sde.npcs.Agent) Corporation(fr.guiguilechat.jcelechat.model.sde.npcs.Corporation) ESIAccess(fr.guiguilechat.jcelechat.jcesi.disconnected.modeled.ESIAccess) Eagents(fr.guiguilechat.jcelechat.model.sde.load.fsd.Eagents) Location(fr.guiguilechat.jcelechat.jcesi.tools.locations.Location)

Example 3 with Agent

use of fr.guiguilechat.jcelechat.model.sde.npcs.Agent in project JCELechat by guiguilechat.

the class MultipleAgentStations method main.

public static void main(String[] args) {
    HashMap<String, StationAgentsSummary> summsHS = new HashMap<>();
    HashMap<String, StationAgentsSummary> summsLS = new HashMap<>();
    HashMap<String, StationAgentsSummary> summsNS = new HashMap<>();
    for (Agent a : Agent.load().values()) {
        if (a.level >= 3 && a.level < 5 && a.type == AGENT_TYPE.Basic && validDivisions.contains(a.division)) {
            SolarSystem solsyst = SolarSystem.load().get(a.system);
            Map<String, StationAgentsSummary> dataholder = null;
            if (solsyst.isHS()) {
                dataholder = summsHS;
            }
            if (solsyst.isLS()) {
                dataholder = summsLS;
            }
            if (solsyst.isNS()) {
                dataholder = summsNS;
            }
            StationAgentsSummary sum = dataholder.get(a.station);
            if (sum == null) {
                sum = new StationAgentsSummary();
                sum.solsyst = SolarSystem.load().get(a.system);
                dataholder.put(a.station, sum);
            }
            switch(a.division) {
                case Distribution:
                    if (a.level == 3) {
                        sum.L3D++;
                    } else {
                        sum.L4D++;
                    }
                    break;
                case Mining:
                    if (a.level == 3) {
                        sum.L3M++;
                    } else {
                        sum.L4M++;
                    }
                    break;
                case Security:
                    if (a.level == 3) {
                        sum.L3S++;
                    } else {
                        sum.L4S++;
                    }
                    break;
                default:
                    throw new UnsupportedOperationException("case not handled " + a.division);
            }
        }
    }
    if (csv) {
        System.out.println("region" + csvSeparator + "constellation" + csvSeparator + "solar system" + csvSeparator + "security status" + csvSeparator + "true sec" + csvSeparator + "station" + csvSeparator + "division" + csvSeparator + "level" + csvSeparator + "number");
    }
    for (HashMap<String, StationAgentsSummary> mmap : Arrays.asList(summsHS, summsLS, summsNS)) {
        String secstatus = mmap == summsHS ? "HS" : mmap == summsLS ? "LS" : "NS";
        if (!csv) {
            System.out.println(secstatus + ":");
        }
        for (AGENT_DIVISION division : validDivisions) {
            for (int level : new int[] { 3, 4 }) {
                if (!csv) {
                    System.out.println("  " + division + " level " + level);
                }
                mmap.entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).forEach(e -> {
                    StationAgentsSummary val = e.getValue();
                    int nb = val.missions(division, level);
                    if (nb > 1) {
                        if (!csv) {
                            System.out.println("      " + e.getKey() + " : " + nb);
                        } else {
                            System.out.println(val.solsyst.region + csvSeparator + val.solsyst.constellation + csvSeparator + val.solsyst.name + csvSeparator + secstatus + csvSeparator + val.solsyst.truesec + csvSeparator + e.getKey() + csvSeparator + division + csvSeparator + level + csvSeparator + nb);
                        }
                    }
                });
            }
        }
    }
}
Also used : HashSet(java.util.HashSet) Arrays(java.util.Arrays) Map(java.util.Map) Set(java.util.Set) AGENT_DIVISION(fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_DIVISION) HashMap(java.util.HashMap) Agent(fr.guiguilechat.jcelechat.model.sde.npcs.Agent) SolarSystem(fr.guiguilechat.jcelechat.model.sde.locations.SolarSystem) AGENT_TYPE(fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_TYPE) Agent(fr.guiguilechat.jcelechat.model.sde.npcs.Agent) HashMap(java.util.HashMap) SolarSystem(fr.guiguilechat.jcelechat.model.sde.locations.SolarSystem) AGENT_DIVISION(fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_DIVISION)

Aggregations

Agent (fr.guiguilechat.jcelechat.model.sde.npcs.Agent)3 Map (java.util.Map)3 AGENT_DIVISION (fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_DIVISION)2 AGENT_TYPE (fr.guiguilechat.jcelechat.model.sde.npcs.Agent.AGENT_TYPE)2 Corporation (fr.guiguilechat.jcelechat.model.sde.npcs.Corporation)2 LPOffer (fr.guiguilechat.jcelechat.model.sde.npcs.LPOffer)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 Entry (java.util.Map.Entry)2 CacheStatic (fr.guiguilechat.jcelechat.jcesi.disconnected.CacheStatic)1 ESIStatic (fr.guiguilechat.jcelechat.jcesi.disconnected.ESIStatic)1 ESIAccess (fr.guiguilechat.jcelechat.jcesi.disconnected.modeled.ESIAccess)1 Requested (fr.guiguilechat.jcelechat.jcesi.interfaces.Requested)1 Location (fr.guiguilechat.jcelechat.jcesi.tools.locations.Location)1 FileTools (fr.guiguilechat.jcelechat.model.FileTools)1 R_get_corporations_corporation_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_corporations_corporation_id)1 R_get_loyalty_stores_corporation_id_offers (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_loyalty_stores_corporation_id_offers)1 R_get_universe_factions (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_factions)1 R_get_universe_stations_station_id (fr.guiguilechat.jcelechat.model.jcesi.compiler.compiled.responses.R_get_universe_stations_station_id)1