use of fr.guiguilechat.jcelechat.jcesi.tools.locations.Location in project JCELechat by guiguilechat.
the class Universe method location.
public Location location(long locationid) {
Location ret = cachedLocationSystems.get(locationid);
if (ret == null) {
synchronized (cachedLocationSystems) {
ret = cachedLocationSystems.get(locationid);
if (ret == null) {
ret = Location.resolve(parent, locationid);
cachedLocationSystems.put(locationid, ret);
}
}
}
return ret;
}
use of fr.guiguilechat.jcelechat.jcesi.tools.locations.Location in project JCELechat by guiguilechat.
the class Markets method getLocalMarket.
/**
* get a pricing for a specific location id. If the locationd id is a region,
* will get the market for that region. If a system, will get the market for
* that system. If a structure or station, will get the market for that one.
*
* @param locationId
* @return
*/
public IPricing getLocalMarket(long locationId) {
// if a region : get the regional market.
if (locationId >= 10000000l && locationId < 12000000l) {
return getMarket((int) locationId);
}
IPricing lm = localMarket.get(locationId);
if (lm == null) {
synchronized (localMarket) {
lm = localMarket.get(locationId);
if (lm == null) {
Location loc = Location.resolve(null, locationId);
RegionalMarket rm = getMarket(loc.region().region_id);
lm = rm.filter((int) locationId, 0, false);
localMarket.put(locationId, lm);
}
}
}
return lm;
}
use of fr.guiguilechat.jcelechat.jcesi.tools.locations.Location in project JCELechat by guiguilechat.
the class Assets method grow.
protected ItemForest grow(List<R_get_corporations_corporation_id_assets> assets) {
ItemForest ret = new ItemForest();
for (R_get_corporations_corporation_id_assets item : assets) {
ret.itemsByID.put(item.item_id, new ItemNode(item));
}
// fetch the names
name(ret.itemsByID);
// place the items in the roots.
for (ItemNode itemNode : ret.itemsByID.values()) {
ItemNode parent = ret.itemsByID.get(itemNode.location_id);
if (parent == null) {
Location location = Location.resolve(con, itemNode.location_id);
ret.roots.computeIfAbsent(location, loc -> new HashMap<>()).computeIfAbsent(itemNode.location_flag, f -> new ArrayList<>()).add(itemNode);
} else {
parent.contained.computeIfAbsent(itemNode.location_flag, f -> new ArrayList<>()).add(itemNode);
}
}
return ret;
}
use of fr.guiguilechat.jcelechat.jcesi.tools.locations.Location in project JCELechat by guiguilechat.
the class Assets method grow.
protected ItemForest grow(List<R_get_characters_character_id_assets> assets) {
ItemForest ret = new ItemForest();
for (R_get_characters_character_id_assets item : assets) {
ret.itemsByID.put(item.item_id, new ItemNode(item));
}
// fetch the names
name(ret.itemsByID);
// place the items in the roots.
for (ItemNode itemNode : ret.itemsByID.values()) {
ItemNode parent = ret.itemsByID.get(itemNode.location_id);
if (parent == null) {
Location location = Location.resolve(con, itemNode.location_id);
ret.roots.computeIfAbsent(location, loc -> new HashMap<>()).computeIfAbsent(itemNode.location_flag, f -> new ArrayList<>()).add(itemNode);
} else {
parent.contained.computeIfAbsent(itemNode.location_flag, f -> new ArrayList<>()).add(itemNode);
}
}
return ret;
}
use of fr.guiguilechat.jcelechat.jcesi.tools.locations.Location 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));
}
Aggregations