Search in sources :

Example 6 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class VALMatchAPI method getMatch.

public VALMatch getMatch(ValorantShard platform, String gameId) {
    DataCallBuilder builder = new DataCallBuilder().withURLParameter(Constants.MATCH_ID_PLACEHOLDER, gameId).withHeader(Constants.X_RIOT_TOKEN_HEADER_KEY, DataCall.getCredentials().getVALAPIKey()).withEndpoint(URLEndpoint.V1_VAL_MATCH_BY_ID).withPlatform(platform);
    Map<String, Object> data = new TreeMap<>();
    data.put("platform", platform);
    data.put("gameid", gameId);
    Optional<?> chl = DataCall.getCacheProvider().get(URLEndpoint.V1_VAL_MATCH_BY_ID, data);
    if (chl.isPresent()) {
        return (VALMatch) chl.get();
    }
    try {
        VALMatch match = (VALMatch) builder.build();
        data.put("value", match);
        DataCall.getCacheProvider().store(URLEndpoint.V1_VAL_MATCH_BY_ID, data);
        return match;
    } catch (ClassCastException e) {
        return null;
    }
}
Also used : VALMatch(no.stelar7.api.r4j.pojo.val.match.VALMatch)

Example 7 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class FrameToImageTest method generateMinimap.

private void generateMinimap(LOLMatch match) {
    // Load map data
    try {
        BufferedImage image = ImageIO.read(new URL(api.getImageAPI().getMap("map" + match.getMap().getId(), null)));
        Rectangle mapBounds = match.getMap().getBounds();
        // load icon data
        int championSquareOffset = (int) (120d / 4d);
        int championSquarePadding = (int) (120d / 12d);
        Map<Integer, Item> items = api.getDDragonAPI().getItems();
        Map<Integer, StaticChampion> champs = api.getDDragonAPI().getChampions();
        Map<Integer, BufferedImage> championImages = new HashMap<>();
        Map<Integer, BufferedImage> itemImages = new HashMap<>();
        match.getParticipants().forEach(p -> {
            try {
                BufferedImage before = ImageIO.read(new URL(api.getImageAPI().getSquare(champs.get(p.getChampionId()), null)));
                double scaleFactor = 1d / 4d;
                BufferedImage after = scaleImage(before, scaleFactor);
                championImages.put(p.getParticipantId(), after);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        items.values().parallelStream().forEach(i -> {
            try {
                BufferedImage before = ImageIO.read(new URL(api.getImageAPI().getItem(i, null)));
                double scaleFactor = 1d / 2d;
                BufferedImage after = scaleImage(before, scaleFactor);
                itemImages.put(i.getId(), after);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
        if (turretIcon == null) {
            try {
                turretIcon = new EnumMap<>(TeamType.class);
                BufferedImage temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/turret_100.png"));
                turretIcon.put(TeamType.BLUE, scaleImage(temp, .4));
                temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/turret_200.png"));
                turretIcon.put(TeamType.RED, scaleImage(temp, .4));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (inhibIcon == null) {
            try {
                inhibIcon = new EnumMap<>(TeamType.class);
                BufferedImage temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/inhibitor_building_100.png"));
                inhibIcon.put(TeamType.BLUE, scaleImage(temp, .25));
                temp = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/images/normal/event_icons/inhibitor_building_200.png"));
                inhibIcon.put(TeamType.RED, scaleImage(temp, .25));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (swordIcon == null) {
            try {
                swordIcon = ImageIO.read(new URL("http://matchhistory.na.leagueoflegends.com/assets/1.0.32/css/resources/images/scoreboardicon_score.png"));
                swordIcon = scaleImage(swordIcon, 1.5);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Map<Integer, List<Pair<Item, Integer>>> inventory = new HashMap<>();
        Map<Integer, Triplet<Integer>> kda = new HashMap<>();
        IntStream.rangeClosed(1, 10).forEach(i -> kda.put(i, new Triplet<>(0, 0, 0)));
        match.getTimeline().getFrames().forEach(frame -> {
            try {
                // Generate file output data
                String path = match.getPlatform().getValue() + File.separator + match.getGameId();
                File outputFile = new File(path, frame.getTimestamp() + ".png");
                outputFile.getParentFile().mkdirs();
                // Make sure map is large enough for all the data
                int imgW = image.getWidth() + (championSquareOffset + championSquarePadding) * 4;
                int imgH = (image.getHeight() + (championSquareOffset + championSquarePadding) * 11);
                BufferedImage newMap = new BufferedImage(imgW, imgH, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = (Graphics2D) newMap.getGraphics();
                // set background
                g.setColor(Color.black);
                g.fillRect(0, 0, newMap.getWidth(), newMap.getHeight());
                // set separator line
                g.setColor(Color.white);
                g.fillRect(0, image.getHeight() + (int) (championSquareOffset / 1.5f) + championSquarePadding / 2, newMap.getWidth(), championSquareOffset / 4);
                g.fillRect(image.getWidth() + (int) (championSquareOffset / 1.5f), 0, championSquareOffset / 4, newMap.getHeight());
                // set minimap
                g.drawImage(image, 0, 0, null);
                int[] killCount = { 0 };
                frame.getEvents().forEach(me -> {
                    Predicate<Pair<Item, Integer>> itemIdFilter = p -> p.getKey().getId() == me.getItemId();
                    Predicate<Pair<Item, Integer>> itemAfterFilter = p -> p.getKey().getId() == me.getAfterId();
                    Predicate<Pair<Item, Integer>> itemBeforeFilter = p -> p.getKey().getId() == me.getBeforeId();
                    if (!inhibDestroyTime.isEmpty()) {
                        Map<Pair<Integer, Integer>, Long> clone = new HashMap<>(inhibDestroyTime);
                        clone.forEach((k, v) -> {
                            if (v + (60000 * 5) <= me.getTimestamp()) {
                                inhib.add(k);
                                inhibDestroyTime.remove(k);
                            }
                        });
                    }
                    switch(me.getType()) {
                        case ITEM_PURCHASED:
                            {
                                handlePurchaseEvent(items, inventory, me, itemIdFilter);
                                break;
                            }
                        case ITEM_DESTROYED:
                        case ITEM_SOLD:
                            {
                                handleSoldEvent(inventory, me, itemIdFilter);
                                break;
                            }
                        case ITEM_UNDO:
                            {
                                handleUndoEvent(items, inventory, me, itemBeforeFilter, itemAfterFilter);
                                break;
                            }
                        case CHAMPION_KILL:
                            {
                                handleKillEvent(image, mapBounds, championSquareOffset, championSquarePadding, championImages, g, killCount, me, kda);
                                break;
                            }
                        // ignored events
                        case SKILL_LEVEL_UP:
                        case WARD_KILL:
                        case WARD_PLACED:
                        case ELITE_MONSTER_KILL:
                            {
                                break;
                            }
                        case BUILDING_KILL:
                            {
                                handleBuildingEvent(me);
                                break;
                            }
                        default:
                            {
                                System.out.println(me);
                                break;
                            }
                    }
                });
                for (Pair<Integer, Integer> turret : turrets) {
                    BufferedImage turretImage = turretIcon.get(turretTeam.get(turret));
                    int xPos = scale(turret.getKey(), mapBounds.getX(), mapBounds.getW(), 0, image.getWidth());
                    int yPos = image.getHeight() - scale(turret.getValue(), mapBounds.getY(), mapBounds.getH(), 0, image.getHeight());
                    int xOffset = (int) (-turretImage.getWidth() / 1.25f);
                    int yOffset = -(turretImage.getHeight() / 2);
                    xPos += xOffset;
                    yPos += yOffset;
                    g.drawImage(turretImage, xPos, yPos, null);
                }
                for (Pair<Integer, Integer> p : inhib) {
                    BufferedImage inhibImage = inhibIcon.get(inhibTeam.get(p));
                    int xPos = scale(p.getKey(), mapBounds.getX(), mapBounds.getW(), 0, image.getWidth());
                    int yPos = image.getHeight() - scale(p.getValue(), mapBounds.getY(), mapBounds.getH(), 0, image.getHeight());
                    int xOffset = (int) (-inhibImage.getWidth() / 1.1f);
                    int yOffset = -(inhibImage.getHeight() / 3);
                    xPos += xOffset;
                    yPos += yOffset;
                    g.drawImage(inhibImage, xPos, yPos, null);
                }
                frame.getParticipantFrames().values().forEach(mpf -> {
                    drawPosition(image, mapBounds, g, mpf, championImages);
                    drawInventory(image, championSquareOffset, championSquarePadding, itemImages, inventory, g, mpf, championImages);
                    drawKDA(kda, image, g, championSquareOffset, championSquarePadding);
                });
                for (int i = 0; i < killList.size(); i++) {
                    Pair<Integer, Integer> k = killList.get(i);
                    int xPos = k.getKey();
                    int yPos = k.getValue();
                    g.setColor(Color.red);
                    g.fillOval(xPos - 8, yPos - 8, 16, 16);
                    g.setColor(Color.black);
                    g.drawString(String.valueOf(i + 1), xPos - 3, yPos + 5);
                    g.drawOval(xPos - 8, yPos - 8, 16, 16);
                }
                killList.clear();
                ImageIO.write(newMap, "png", outputFile);
            } catch (IOException e) {
                e.printStackTrace();
            }
        });
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IntStream(java.util.stream.IntStream) FileSystemCacheProvider(no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider) java.awt.image(java.awt.image) java.util(java.util) URL(java.net.URL) R4J(no.stelar7.api.r4j.impl.R4J) MatchListBuilder(no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder) DataCall(no.stelar7.api.r4j.basic.calling.DataCall) SummonerBuilder(no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder) no.stelar7.api.r4j.pojo.lol.match.v5(no.stelar7.api.r4j.pojo.lol.match.v5) ImageIO(javax.imageio.ImageIO) Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) Predicate(java.util.function.Predicate) AffineTransform(java.awt.geom.AffineTransform) Rectangle(no.stelar7.api.r4j.basic.utils.Rectangle) StaticChampion(no.stelar7.api.r4j.pojo.lol.staticdata.champion.StaticChampion) java.awt(java.awt) List(java.util.List) LeagueShard(no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard) java.io(java.io) SecretFile(no.stelar7.api.r4j.tests.SecretFile) org.junit.jupiter.api(org.junit.jupiter.api) Item(no.stelar7.api.r4j.pojo.lol.staticdata.item.Item) no.stelar7.api.r4j.basic.constants.types.lol(no.stelar7.api.r4j.basic.constants.types.lol) no.stelar7.api.r4j.basic.utils(no.stelar7.api.r4j.basic.utils) Rectangle(no.stelar7.api.r4j.basic.utils.Rectangle) URL(java.net.URL) Item(no.stelar7.api.r4j.pojo.lol.staticdata.item.Item) List(java.util.List) StaticChampion(no.stelar7.api.r4j.pojo.lol.staticdata.champion.StaticChampion) SecretFile(no.stelar7.api.r4j.tests.SecretFile)

Example 8 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class UseageTest method testUseage.

@Test
public void testUseage() {
    R4J api = new R4J(SecretFile.CREDS);
    DataCall.setCacheProvider(new FileSystemCacheProvider());
    Map<Integer, StaticRune> runeData = api.getDDragonAPI().getRunes();
    Map<Integer, StaticMastery> masteriesData = api.getDDragonAPI().getMasteries();
    Map<Integer, StaticChampion> championData = api.getDDragonAPI().getChampions();
    Map<Integer, StaticPerk> perkData = api.getDDragonAPI().getPerks();
    Summoner summoner = Summoner.byName(LeagueShard.EUW1, "stelar7");
    List<String> some = summoner.getLeagueGames().get();
    LOLMatch match = LOLMatch.get(summoner.getPlatform(), some.get(0));
    MatchParticipant self = match.getParticipants().stream().filter(p -> p.getPuuid().equals(summoner.getPUUID())).findFirst().get();
    StaticChampion champion = championData.get(self.getChampionId());
    ChampionMastery mastery = summoner.getChampionMastery(champion.getId());
    boolean didWin = self.didWin();
    System.out.format("Player '%s' played their latest game as '%s'%n", summoner.getName(), champion.getName());
    System.out.format("They have a masteryscore of %s on that champion%n", mastery.getChampionPoints());
    System.out.format("They played in %s, their role was: %s%n", self.getChampionSelectLane(), self.getRole());
    System.out.format("They %s that game%n", didWin ? "won" : "lost");
    System.out.format("%nThey used the following perks:%n");
    List<PerkSelection> perks = self.getPerks().getPerkStyles().stream().flatMap(s -> s.getSelections().stream()).collect(Collectors.toList());
    for (PerkSelection perk : perks) {
        StaticPerk perkInfo = perkData.get(perk.getPerk());
        String name = perkInfo.getName();
        System.out.format("Name: '%-20s' variables: %-5s, %-5s, %-5s%n", name, perk.getVar1(), perk.getVar2(), perk.getVar3());
    }
}
Also used : StaticPerk(no.stelar7.api.r4j.pojo.lol.staticdata.perk.StaticPerk) Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) FileSystemCacheProvider(no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider) StaticMastery(no.stelar7.api.r4j.pojo.lol.staticdata.mastery.StaticMastery) java.util(java.util) Summoner(no.stelar7.api.r4j.pojo.lol.summoner.Summoner) R4J(no.stelar7.api.r4j.impl.R4J) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) DataCall(no.stelar7.api.r4j.basic.calling.DataCall) StaticChampion(no.stelar7.api.r4j.pojo.lol.staticdata.champion.StaticChampion) Collectors(java.util.stream.Collectors) StaticPerk(no.stelar7.api.r4j.pojo.lol.staticdata.perk.StaticPerk) Test(org.junit.jupiter.api.Test) StaticRune(no.stelar7.api.r4j.pojo.lol.staticdata.rune.StaticRune) no.stelar7.api.r4j.pojo.lol.match.v5(no.stelar7.api.r4j.pojo.lol.match.v5) LeagueShard(no.stelar7.api.r4j.basic.constants.api.regions.LeagueShard) SecretFile(no.stelar7.api.r4j.tests.SecretFile) StaticChampion(no.stelar7.api.r4j.pojo.lol.staticdata.champion.StaticChampion) R4J(no.stelar7.api.r4j.impl.R4J) FileSystemCacheProvider(no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider) StaticRune(no.stelar7.api.r4j.pojo.lol.staticdata.rune.StaticRune) ChampionMastery(no.stelar7.api.r4j.pojo.lol.championmastery.ChampionMastery) StaticMastery(no.stelar7.api.r4j.pojo.lol.staticdata.mastery.StaticMastery) Test(org.junit.jupiter.api.Test)

Example 9 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class TestVALMatch method testGetSingleById.

@Test
public void testGetSingleById() {
    R4J api = new R4J(SecretFile.CREDS);
    VALMatchAPI matchAPI = api.getVALAPI().getMatchAPI();
    VALMatch match = matchAPI.getMatch(ValorantShard.AP, "c4eb3e3d-d175-4b73-b7d4-279374d1b19b");
    System.out.println();
}
Also used : VALMatchAPI(no.stelar7.api.r4j.impl.val.VALMatchAPI) R4J(no.stelar7.api.r4j.impl.R4J)

Example 10 with Match

use of no.stelar7.api.l4j8.pojo.match.Match in project L4J8 by stelar7.

the class TestVALMatch method generateRecentGamesData.

@Test
@Disabled
public void generateRecentGamesData() throws IOException {
    LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    loggerContext.getLogger("no.stelar7.api.r4j.basic.calling.DataCallBuilder").setLevel(Level.INFO);
    loggerContext.getLogger("no.stelar7.api.r4j.basic.ratelimiting.BurstRateLimiter").setLevel(Level.INFO);
    while (true) {
        DataCall.getCacheProvider().clear(URLEndpoint.V1_VAL_MATCH_BY_ID, new HashMap<>());
        Map<String, JsonElement> matches = new HashMap<>();
        Map<String, JsonElement> players = new HashMap<>();
        R4J api = new R4J(SecretFile.CREDS);
        VALMatchAPI matchAPI = api.getVALAPI().getMatchAPI();
        RecentMatchList recentMatches = matchAPI.getRecentMatches(ValorantShard.EU, GameQueueType.COMPETITIVE);
        List<String> matchIds = recentMatches.getMatchIds().stream().limit(100).collect(Collectors.toList());
        int max = matchIds.size();
        int current = 0;
        for (String matchId : matchIds) {
            System.out.println("Working on match " + (++current) + "/" + max);
            VALMatch match = matchAPI.getMatch(ValorantShard.EU, matchId);
            JsonElement matchJson = Utils.getGson().toJsonTree(match);
            matches.put(matchId, matchJson);
            for (Player player : match.getPlayers()) {
                RiotAccount account = api.getAccountAPI().getAccountByPUUID(RegionShard.EUROPE, player.getPUUID());
                JsonElement accountJson = Utils.getGson().toJsonTree(account);
                players.put(account.getPUUID(), accountJson);
            }
        }
        JsonArray matchJson = new JsonArray();
        for (JsonElement value : matches.values()) {
            matchJson.add(value);
        }
        JsonArray playerJson = new JsonArray();
        for (JsonElement value : players.values()) {
            playerJson.add(value);
        }
        JsonObject obj = new JsonObject();
        obj.add("players", playerJson);
        obj.add("matches", matchJson);
        Path outputPath = Paths.get("C:\\cdragon\\valorant\\" + recentMatches.getGeneratedAt() + ".json");
        Files.createDirectories(outputPath.getParent());
        Files.write(outputPath, Utils.getGson().toJson(obj).getBytes(StandardCharsets.UTF_8));
    }
}
Also used : VALMatchAPI(no.stelar7.api.r4j.impl.val.VALMatchAPI) R4J(no.stelar7.api.r4j.impl.R4J) URLEndpoint(no.stelar7.api.r4j.basic.constants.api.URLEndpoint) RiotAccount(no.stelar7.api.r4j.pojo.shared.RiotAccount)

Aggregations

Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)8 R4J (no.stelar7.api.r4j.impl.R4J)7 SummonerBuilder (no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder)6 Summoner (no.stelar7.api.l4j8.pojo.summoner.Summoner)6 MatchListBuilder (no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder)5 java.util (java.util)4 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)4 FileSystemCacheProvider (no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)4 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)4 VALMatchAPI (no.stelar7.api.r4j.impl.val.VALMatchAPI)4 java.awt (java.awt)3 AffineTransform (java.awt.geom.AffineTransform)3 java.awt.image (java.awt.image)3 java.io (java.io)3 URL (java.net.URL)3 List (java.util.List)3 Predicate (java.util.function.Predicate)3 IntStream (java.util.stream.IntStream)3 ImageIO (javax.imageio.ImageIO)3 L4J8 (no.stelar7.api.l4j8.impl.L4J8)3