Search in sources :

Example 1 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item in project L4J8 by stelar7.

the class FrameToImageTest method generateMinimap.

private void generateMinimap(Match match) {
    // Load map data
    try {
        BufferedImage image = ImageIO.read(new URL(api.getImageAPI().getMap("map" + match.getMap().getId(), null, null)));
        Rectangle mapBounds = match.getMap().getBounds();
        // load icon data
        int championSquareOffset = (int) (120d / 4d);
        int championSquarePadding = (int) (120d / 12d);
        Map<Integer, Item> items = api.getStaticAPI().getItems(Platform.EUW1, null, null, null).getData();
        Map<Integer, StaticChampion> champs = api.getStaticAPI().getChampions(Platform.EUW1, null, null, null);
        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, 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, 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.getMatchId();
                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.getItemAfter();
                    Predicate<Pair<Item, Integer>> itemBeforeFilter = p -> p.getKey().getId() == me.getItemBefore();
                    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.getEventType()) {
                        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;
                            }
                    }
                });
                turrets.forEach(p -> {
                    BufferedImage turretImage = turretIcon.get(turretTeam.get(p));
                    int xPos = scale(p.getKey(), (int) mapBounds.getX(), (int) mapBounds.getWidth(), 0, image.getWidth());
                    int yPos = image.getHeight() - scale(p.getValue(), (int) mapBounds.getY(), (int) mapBounds.getHeight(), 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);
                });
                inhib.forEach(p -> {
                    BufferedImage inhibImage = inhibIcon.get(inhibTeam.get(p));
                    int xPos = scale(p.getKey(), (int) mapBounds.getX(), (int) mapBounds.getWidth(), 0, image.getWidth());
                    int yPos = image.getHeight() - scale(p.getValue(), (int) mapBounds.getY(), (int) mapBounds.getHeight(), 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) Platform(no.stelar7.api.l4j8.basic.constants.api.Platform) no.stelar7.api.l4j8.basic.utils(no.stelar7.api.l4j8.basic.utils) java.awt.image(java.awt.image) java.util(java.util) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item) no.stelar7.api.l4j8.basic.constants.types(no.stelar7.api.l4j8.basic.constants.types) URL(java.net.URL) Predicate(java.util.function.Predicate) no.stelar7.api.l4j8.pojo.match(no.stelar7.api.l4j8.pojo.match) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) AffineTransform(java.awt.geom.AffineTransform) L4J8(no.stelar7.api.l4j8.impl.L4J8) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider) java.awt(java.awt) List(java.util.List) Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) java.io(java.io) MatchListBuilder(no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder) SecretFile(no.stelar7.api.l4j8.tests.SecretFile) ImageIO(javax.imageio.ImageIO) org.junit(org.junit) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) DataCall(no.stelar7.api.l4j8.basic.calling.DataCall) URL(java.net.URL) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item) List(java.util.List) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) SecretFile(no.stelar7.api.l4j8.tests.SecretFile)

Example 2 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item in project L4J8 by stelar7.

the class FrameToImageTest method handleUndoEvent.

private void handleUndoEvent(Map<Integer, Item> items, Map<Integer, List<Pair<Item, Integer>>> inventory, MatchEvent me, Predicate<Pair<Item, Integer>> itemBeforeFilter, Predicate<Pair<Item, Integer>> afterItemFilter) {
    List<Pair<Item, Integer>> inv = inventory.getOrDefault(me.getParticipantId(), new ArrayList<>());
    Optional<Pair<Item, Integer>> optional = inv.stream().filter(itemBeforeFilter).findFirst();
    if (optional.isPresent()) {
        Pair<Item, Integer> op = optional.get();
        Pair<Item, Integer> np = new Pair<>(op.getKey(), op.getValue() - 1);
        inv.remove(op);
        if (np.getValue() > 0) {
            inv.add(np);
        }
        Item parent = items.get(op.getKey().getId());
        if (parent.getFrom() != null) {
            for (String s : items.get(op.getKey().getId()).getFrom()) {
                int iid = Integer.parseInt(s);
                Optional<Pair<Item, Integer>> innerO = inv.stream().filter(p -> p.getKey().getId() == iid).findFirst();
                if (innerO.isPresent()) {
                    Pair<Item, Integer> iop = innerO.get();
                    Pair<Item, Integer> inp = new Pair<>(iop.getKey(), iop.getValue() + 1);
                    inv.remove(iop);
                    inv.add(inp);
                } else {
                    Pair<Item, Integer> inp = new Pair<>(items.get(iid), 1);
                    inv.add(inp);
                }
            }
        }
    } else {
        Optional<Pair<Item, Integer>> iopiotnal = inv.stream().filter(afterItemFilter).findFirst();
        if (iopiotnal.isPresent()) {
            Pair<Item, Integer> op = iopiotnal.get();
            Pair<Item, Integer> np = new Pair<>(op.getKey(), op.getValue() + 1);
            inv.remove(op);
            inv.add(np);
        } else {
            Pair<Item, Integer> np = new Pair<>(items.get(me.getItemAfter()), 1);
            inv.add(np);
        }
    }
    inventory.put(me.getParticipantId(), inv);
}
Also used : IntStream(java.util.stream.IntStream) Platform(no.stelar7.api.l4j8.basic.constants.api.Platform) no.stelar7.api.l4j8.basic.utils(no.stelar7.api.l4j8.basic.utils) java.awt.image(java.awt.image) java.util(java.util) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item) no.stelar7.api.l4j8.basic.constants.types(no.stelar7.api.l4j8.basic.constants.types) URL(java.net.URL) Predicate(java.util.function.Predicate) no.stelar7.api.l4j8.pojo.match(no.stelar7.api.l4j8.pojo.match) SummonerBuilder(no.stelar7.api.l4j8.impl.builders.summoner.SummonerBuilder) AffineTransform(java.awt.geom.AffineTransform) L4J8(no.stelar7.api.l4j8.impl.L4J8) FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider) java.awt(java.awt) List(java.util.List) Summoner(no.stelar7.api.l4j8.pojo.summoner.Summoner) java.io(java.io) MatchListBuilder(no.stelar7.api.l4j8.impl.builders.match.MatchListBuilder) SecretFile(no.stelar7.api.l4j8.tests.SecretFile) ImageIO(javax.imageio.ImageIO) org.junit(org.junit) StaticChampion(no.stelar7.api.l4j8.pojo.staticdata.champion.StaticChampion) DataCall(no.stelar7.api.l4j8.basic.calling.DataCall) Item(no.stelar7.api.l4j8.pojo.staticdata.item.Item)

Example 3 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item in project L4J8 by stelar7.

the class StaticTest method testItemSingle.

@Test
public void testItemSingle() {
    DataCall.setCacheProvider(new FileSystemCacheProvider());
    DataCall.setLogLevel(LogLevel.DEBUG);
    EnumSet<ItemDataFlags> dataFlags = EnumSet.of(ItemDataFlags.ALL, ItemDataFlags.IMAGE);
    Item list = api.getItem(Platform.EUW1, 3147, dataFlags, null, null);
    Assert.assertTrue("ok?", list.getId() == 3147);
}
Also used : FileSystemCacheProvider(no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)

Example 4 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item 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 5 with Item

use of no.stelar7.api.r4j.pojo.lol.staticdata.item.Item in project L4J8 by stelar7.

the class FrameToImageTest method handleUndoEvent.

private void handleUndoEvent(Map<Integer, Item> items, Map<Integer, List<Pair<Item, Integer>>> inventory, TimelineFrameEvent me, Predicate<Pair<Item, Integer>> itemBeforeFilter, Predicate<Pair<Item, Integer>> afterItemFilter) {
    List<Pair<Item, Integer>> inv = inventory.getOrDefault(me.getParticipantId(), new ArrayList<>());
    Optional<Pair<Item, Integer>> optional = inv.stream().filter(itemBeforeFilter).findFirst();
    if (optional.isPresent()) {
        Pair<Item, Integer> op = optional.get();
        Pair<Item, Integer> np = new Pair<>(op.getKey(), op.getValue() - 1);
        inv.remove(op);
        if (np.getValue() > 0) {
            inv.add(np);
        }
        Item parent = items.get(op.getKey().getId());
        if (parent.getFrom() != null) {
            for (String s : items.get(op.getKey().getId()).getFrom()) {
                int iid = Integer.parseInt(s);
                Optional<Pair<Item, Integer>> innerO = inv.stream().filter(p -> p.getKey().getId() == iid).findFirst();
                if (innerO.isPresent()) {
                    Pair<Item, Integer> iop = innerO.get();
                    Pair<Item, Integer> inp = new Pair<>(iop.getKey(), iop.getValue() + 1);
                    inv.remove(iop);
                    inv.add(inp);
                } else {
                    Pair<Item, Integer> inp = new Pair<>(items.get(iid), 1);
                    inv.add(inp);
                }
            }
        }
    } else {
        Optional<Pair<Item, Integer>> iopiotnal = inv.stream().filter(afterItemFilter).findFirst();
        if (iopiotnal.isPresent()) {
            Pair<Item, Integer> op = iopiotnal.get();
            Pair<Item, Integer> np = new Pair<>(op.getKey(), op.getValue() + 1);
            inv.remove(op);
            inv.add(np);
        } else {
            Pair<Item, Integer> np = new Pair<>(items.get(me.getAfterId()), 1);
            inv.add(np);
        }
    }
    inventory.put(me.getParticipantId(), inv);
}
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) Item(no.stelar7.api.r4j.pojo.lol.staticdata.item.Item)

Aggregations

java.awt (java.awt)4 AffineTransform (java.awt.geom.AffineTransform)4 java.awt.image (java.awt.image)4 java.io (java.io)4 URL (java.net.URL)4 java.util (java.util)4 List (java.util.List)4 Predicate (java.util.function.Predicate)4 IntStream (java.util.stream.IntStream)4 ImageIO (javax.imageio.ImageIO)4 FileSystemCacheProvider (no.stelar7.api.r4j.basic.cache.impl.FileSystemCacheProvider)4 Item (no.stelar7.api.r4j.pojo.lol.staticdata.item.Item)4 FileSystemCacheProvider (no.stelar7.api.l4j8.basic.cache.impl.FileSystemCacheProvider)3 MatchListBuilder (no.stelar7.api.r4j.impl.lol.builders.matchv5.match.MatchListBuilder)3 SummonerBuilder (no.stelar7.api.r4j.impl.lol.builders.summoner.SummonerBuilder)3 Summoner (no.stelar7.api.r4j.pojo.lol.summoner.Summoner)3 DataCall (no.stelar7.api.l4j8.basic.calling.DataCall)2 Platform (no.stelar7.api.l4j8.basic.constants.api.Platform)2 no.stelar7.api.l4j8.basic.constants.types (no.stelar7.api.l4j8.basic.constants.types)2 no.stelar7.api.l4j8.basic.utils (no.stelar7.api.l4j8.basic.utils)2