Skip to content

Commit

Permalink
New Feature: Include plugged implants in assets (Issue #124)
Browse files Browse the repository at this point in the history
Authored-by: Costin Anghel <Costin [email protected]>
Minor code changes by GoldenGnu
  • Loading branch information
coanghel authored Oct 7, 2024
1 parent 4b786ec commit 7d50cf0
Show file tree
Hide file tree
Showing 21 changed files with 246 additions and 4 deletions.
1 change: 1 addition & 0 deletions credits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Contributors:
Lazaren
Boran Lordsworth
Ed Thelleres
Tsuro Tsero

Retired Testers:
Varo Jan
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@
<exclude>${tests.to.skip}</exclude>
</excludes>
<environmentVariables>
<JANICE_API_KEY>${janice}</JANICE_API_KEY>
</environmentVariables>
<JANICE_API_KEY>${janice}</JANICE_API_KEY>
</environmentVariables>
<trimStackTrace>false</trimStackTrace>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.troja.eve.esi.api.AssetsApi;
import net.troja.eve.esi.api.BookmarksApi;
import net.troja.eve.esi.api.CharacterApi;
import net.troja.eve.esi.api.ClonesApi;
import net.troja.eve.esi.api.ContractsApi;
import net.troja.eve.esi.api.CorporationApi;
import net.troja.eve.esi.api.IndustryApi;
Expand All @@ -55,6 +56,7 @@ public class EsiOwner extends AbstractOwner implements OwnerType {
private final MarketApi marketApi = new MarketApi(apiClient);
private final IndustryApi industryApi = new IndustryApi(apiClient);
private final CharacterApi characterApi = new CharacterApi(apiClient);
private final ClonesApi clonesApi = new ClonesApi(apiClient);
private final AssetsApi assetsApi = new AssetsApi(apiClient);
private final WalletApi walletApi = new WalletApi(apiClient);
private final UniverseApi universeApi = new UniverseApi(apiClient);
Expand Down Expand Up @@ -185,6 +187,24 @@ private boolean isWallet() {
return EsiScopes.CHARACTER_WALLET.isInScope(scopes);
}
}

@Override
public boolean isClones() {
if (isCorporation()) {
return false; //Character Endpoint
} else {
return EsiScopes.CHARACTER_CLONE.isInScope(scopes);
}
}

@Override
public boolean isImplants() {
if (isCorporation()) {
return false; //Character Endpoint
} else {
return EsiScopes.CHARACTER_IMPLANT.isInScope(scopes);
}
}

@Override
public boolean isAccountBalance() {
Expand Down Expand Up @@ -397,6 +417,10 @@ public WalletApi getWalletApiAuth() {
public UniverseApi getUniverseApiAuth() {
return universeApi;
}

public ClonesApi getClonesApiAuth() {
return clonesApi;
}

public ContractsApi getContractsApiAuth() {
return contractsApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ public boolean isMarketStructures() {
public boolean isShip() {
return false; //Not supported by the XML API
}

@Override
public boolean isClones() {
return false; //Not supported by the XML API
}

@Override
public boolean isImplants() {
return false; //Not supported by the XML API
}

@Override
public boolean isOpenWindows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ public boolean isMarketStructures() {
public boolean isShip() {
return isLocations() && isCharacter();
}

@Override
public boolean isClones() {
return false; //Not supported by the EveKit, Yet
}

@Override
public boolean isImplants() {
return false; //Not supported by the EveKit, Yet
}

@Override
public boolean isOpenWindows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public interface OwnerType extends Comparable<OwnerType> {
//Account Mask
public boolean isCharacter();
public boolean isAssetList();
public boolean isClones();
public boolean isImplants();
public boolean isAccountBalance();
public boolean isIndustryJobs();
public boolean isMarketOrders();
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/data/api/raw/RawAsset.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class RawAsset {
private static final ItemFlag MARKET_ORDER_SELL_FLAG = new ItemFlag(0, General.get().marketOrderSellFlag(), General.get().marketOrderSellFlag());
private static final ItemFlag CONTRACT_INCLUDED_FLAG = new ItemFlag(0, General.get().contractIncluded(), General.get().contractIncluded());
private static final ItemFlag CONTRACT_EXCLUDED_FLAG = new ItemFlag(0, General.get().contractExcluded(), General.get().contractExcluded());
private static final ItemFlag PLUGGED_IMPLANT_FLAG = new ItemFlag(0, General.get().pluggedImplant(), General.get().pluggedImplant());

private Boolean isSingleton = null;
private Long itemId = null;
Expand Down Expand Up @@ -223,6 +224,21 @@ public RawAsset(CorporationAssetsResponse asset) {
typeId = asset.getTypeId();
}

/**
* ESI Implant
*
* @param implantType
* @param implantLocation
*/
public RawAsset(Integer implantType, Long implantLocation) {
isSingleton = true; //Unpacked
itemId = Long.valueOf(implantType + "" + implantLocation);
itemFlag = PLUGGED_IMPLANT_FLAG;
locationId = implantLocation;
quantity = 1; //Plugged in AKA always 1
typeId = implantType;
}

/**
* ESI Ship
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public AboutDialog(final Program program) {
+ "&nbsp;Lazaren<br>"
+ "&nbsp;Boran Lordsworth<br>"
+ "&nbsp;Ed Thelleres<br>"
+ "&nbsp;Tsuro Tsero<br>"
+ "<br>"
+ "<b>Retired Testers</b><br>"
+ "&nbsp;Varo Jan<br>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isCorporation());
}
},
CLONES(YesNo.class, GlazedLists.comparableComparator()) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatClones();
}
@Override
public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isClones());
}
},
IMPLANTS(YesNo.class, GlazedLists.comparableComparator()) {
@Override
public String getColumnName() {
return DialoguesAccount.get().tableFormatImplants();
}
@Override
public Object getColumnValue(final OwnerType from) {
return new YesNo(from.isImplants());
}
},
ASSET_LIST(YesNo.class, GlazedLists.comparableComparator()) {
@Override
public String getColumnName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import net.nikr.eve.jeveasset.io.esi.EsiAssetsGetter;
import net.nikr.eve.jeveasset.io.esi.EsiBlueprintsGetter;
import net.nikr.eve.jeveasset.io.esi.EsiBookmarksGetter;
import net.nikr.eve.jeveasset.io.esi.EsiClonesGetter;
import net.nikr.eve.jeveasset.io.esi.EsiContractItemsGetter;
import net.nikr.eve.jeveasset.io.esi.EsiContractsGetter;
import net.nikr.eve.jeveasset.io.esi.EsiDivisionsGetter;
Expand Down Expand Up @@ -845,6 +846,7 @@ public void update() {
updates.add(new EsiLocationsGetter(this, esiOwner));
updates.add(new EsiShipGetter(this, esiOwner, assetNextUpdate.getOrDefault(esiOwner, Settings.getNow())));
updates.add(new EsiPlanetaryInteractionGetter(this, esiOwner, assetNextUpdate.getOrDefault(esiOwner, Settings.getNow())));
updates.add(new EsiClonesGetter(this, esiOwner, assetNextUpdate.getOrDefault(esiOwner, Settings.getNow())));
}
}
updates.add(new EsiFactionWarfareGetter(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public DialoguesAccount(final Locale locale) {
public abstract String workaroundLabel();
public abstract String workaroundCheckbox();
public abstract String scopeAssets();
public abstract String scopeClones();
public abstract String scopeImplants();
public abstract String scopeWallet();
public abstract String scopeBlueprints();
public abstract String scopeBookmarks();
Expand Down Expand Up @@ -145,6 +147,8 @@ public DialoguesAccount(final Locale locale) {
public abstract String migrate();

public abstract String tableFormatName();
public abstract String tableFormatClones();
public abstract String tableFormatImplants();
public abstract String tableFormatCorporation();
public abstract String tableFormatAssetList();
public abstract String tableFormatAccountBalance();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/nikr/eve/jeveasset/i18n/General.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public General(final Locale locale) {
public abstract String uncaughtErrorMessage();
public abstract String error();
public abstract String contractIncluded();
public abstract String pluggedImplant();
public abstract String contractExcluded();
public abstract String industryJobFlag();
public abstract String marketOrderSellFlag();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.troja.eve.esi.api.AssetsApi;
import net.troja.eve.esi.api.BookmarksApi;
import net.troja.eve.esi.api.CharacterApi;
import net.troja.eve.esi.api.ClonesApi;
import net.troja.eve.esi.api.ContractsApi;
import net.troja.eve.esi.api.CorporationApi;
import net.troja.eve.esi.api.FactionWarfareApi;
Expand Down Expand Up @@ -277,6 +278,10 @@ protected WalletApi getWalletApiAuth() {
protected UniverseApi getUniverseApiAuth() {
return owner.getUniverseApiAuth();
}

public ClonesApi getClonesApiAuth() {
return owner.getClonesApiAuth();
}

public ContractsApi getContractsApiAuth() {
return owner.getContractsApiAuth();
Expand Down
129 changes: 129 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/io/esi/EsiClonesGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2009-2023 Contributors (see credits.txt)
*
* This file is part of jEveAssets.
*
* jEveAssets is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* jEveAssets is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with jEveAssets; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
package net.nikr.eve.jeveasset.io.esi;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
import net.nikr.eve.jeveasset.data.api.accounts.EsiOwner;
import net.nikr.eve.jeveasset.data.api.my.MyAsset;
import net.nikr.eve.jeveasset.gui.dialogs.update.UpdateTask;
import static net.nikr.eve.jeveasset.io.esi.AbstractEsiGetter.DATASOURCE;
import static net.nikr.eve.jeveasset.io.esi.AbstractEsiGetter.DEFAULT_RETRIES;
import net.nikr.eve.jeveasset.io.shared.RawConverter;
import net.troja.eve.esi.ApiException;
import net.troja.eve.esi.ApiResponse;
import net.troja.eve.esi.model.CharacterClonesResponse;
import net.troja.eve.esi.model.CharacterLocationResponse;
import net.troja.eve.esi.model.CharacterRolesResponse.RolesEnum;
import net.troja.eve.esi.model.Clone;


public class EsiClonesGetter extends AbstractEsiGetter {

public EsiClonesGetter(UpdateTask updateTask, EsiOwner owner, Date assetNextUpdate) {
super(updateTask, owner, false, assetNextUpdate, TaskType.CLONES);
}

@Override
protected void update() throws ApiException {
if (owner.isCorporation()) {
return; //Character Endpoint
}
//Get Jump Clones
CharacterClonesResponse jumpClonesResponse = update(DEFAULT_RETRIES, new EsiHandler<CharacterClonesResponse>() {
@Override
public ApiResponse<CharacterClonesResponse> get() throws ApiException {
return getClonesApiAuth().getCharactersCharacterIdClonesWithHttpInfo((int)owner.getOwnerID(), DATASOURCE, null, null);
}
});
//Get Active Clone
List<Integer> activeClone = update(DEFAULT_RETRIES, new EsiHandler<List<Integer>>() {
@Override
public ApiResponse<List<Integer>> get() throws ApiException {
return getClonesApiAuth().getCharactersCharacterIdImplantsWithHttpInfo((int)owner.getOwnerID(), DATASOURCE, null, null);
}
});
//Get Location
CharacterLocationResponse characterLocation = update(DEFAULT_RETRIES, new EsiHandler<CharacterLocationResponse>() {
@Override
public ApiResponse<CharacterLocationResponse> get() throws ApiException {
return getLocationApiAuth().getCharactersCharacterIdLocationWithHttpInfo((int)owner.getOwnerID(), DATASOURCE, null, null);
}
});
Long activeCloneLocation = RawConverter.toLocationID(characterLocation);

//Create assets
List<MyAsset> implants = new ArrayList<>();
List<Clone> jumpClones = jumpClonesResponse.getJumpClones();

for (Clone clone : jumpClones){
List<Integer> cloneImplants = clone.getImplants();
Long cloneLocation = clone.getLocationId();
for (Integer implant : cloneImplants){
MyAsset implantAsset = EsiConverter.toAssetsImplant(implant, cloneLocation, owner);
implants.add(implantAsset);
}
}

for (Integer implant : activeClone){
MyAsset activeCloneImplant = EsiConverter.toAssetsImplant(implant, activeCloneLocation, owner);
implants.add(activeCloneImplant);
}


//Clear out implants
List<MyAsset> assets;
synchronized (owner) {
assets = new ArrayList<>(owner.getAssets());
}
List<MyAsset> existingImplants = assets.stream().filter(asset -> "Plugged in Implant".equals(asset.getFlag())).collect(Collectors.toList());
if (!existingImplants.isEmpty()) {
owner.removeAssets(existingImplants);
}

//Reload Implants
for (MyAsset implant : implants){
owner.addAsset(implant);
}
}

@Override
protected void setNextUpdate(Date date) {
//Use the assets update times
}

@Override
protected boolean haveAccess() {
if (owner.isCorporation()) {
return true; //Overwrite the default, so, we don't get errors
} else {
return owner.isClones() && owner.isImplants();
}
}

@Override
protected RolesEnum[] getRequiredRoles() {
return null;
}

}
5 changes: 5 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/io/esi/EsiConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import net.nikr.eve.jeveasset.io.shared.DataConverter;
import net.troja.eve.esi.model.CharacterAssetsResponse;
import net.troja.eve.esi.model.CharacterBlueprintsResponse;
import net.troja.eve.esi.model.CharacterClonesResponse;
import net.troja.eve.esi.model.CharacterContractsItemsResponse;
import net.troja.eve.esi.model.CharacterContractsResponse;
import net.troja.eve.esi.model.CharacterIndustryJobsResponse;
Expand Down Expand Up @@ -131,6 +132,10 @@ public static List<MyAsset> toAssetsCorporation(List<CorporationAssetsResponse>
public static MyAsset toAssetsShip(CharacterShipResponse shipType, CharacterLocationResponse shipLocation, OwnerType owner) {
return toMyAsset(new RawAsset(shipType, shipLocation), owner, new ArrayList<>());
}

public static MyAsset toAssetsImplant(Integer implantType, Long implantLocation, OwnerType owner) {
return toMyAsset(new RawAsset(implantType, implantLocation), owner, new ArrayList<>());
}

public static MyAsset toAssetsPlanetaryInteraction(CharacterPlanetsResponse planet, PlanetPin pin, OwnerType owner) {
MyAsset parent = toMyAsset(new RawAsset(planet, pin), owner, new ArrayList<>());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/net/nikr/eve/jeveasset/io/esi/EsiScopes.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
public enum EsiScopes {

CHARACTER_ASSETS(SsoScopes.ESI_ASSETS_READ_ASSETS_V1, DialoguesAccount.get().scopeAssets(), ScopeType.CHARACTER),
CHARACTER_CLONE(SsoScopes.ESI_CLONES_READ_CLONES_V1, DialoguesAccount.get().scopeClones(), ScopeType.CHARACTER),
CHARACTER_IMPLANT(SsoScopes.ESI_CLONES_READ_IMPLANTS_V1, DialoguesAccount.get().scopeImplants(), ScopeType.CHARACTER),
CHARACTER_WALLET(SsoScopes.ESI_WALLET_READ_CHARACTER_WALLET_V1, DialoguesAccount.get().scopeWallet(), ScopeType.CHARACTER),
CHARACTER_INDUSTRY_JOBS(SsoScopes.ESI_INDUSTRY_READ_CHARACTER_JOBS_V1, DialoguesAccount.get().scopeIndustryJobs(), ScopeType.CHARACTER),
CHARACTER_MARKET_ORDERS(SsoScopes.ESI_MARKETS_READ_CHARACTER_ORDERS_V1, DialoguesAccount.get().scopeMarketOrders(), ScopeType.CHARACTER),
Expand Down
Loading

0 comments on commit 7d50cf0

Please sign in to comment.