Solved prerequisite checker

Discussion in 'Plugin Development' started by guitargun, Jan 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    guitargun

    with my arena plugin players buy items in sets of tiers (see image).
    however they can not stack up the lower set tiers and can only have 1 of the same item

    [​IMG]

    the top is the starting item the bottem is the end item.
    currently I have this:
    Code:
                if (!containers.contains(piece.getName())) {
                    for (String in : containers) {
                        if (Armor.returnarmor(in) != null) {
                            if (Armor.returnarmor(in).getPrereq() != null) {
                                if (!Armor.returnarmor(in).getPrereq().getName()
                                        .equals(piece.getName())) {
                                    total = piece.getCost();
                                }else{
                                }
                            }else{
                                total = piece.getCost();
                            }
                        }else{
                            total = piece.getCost();
                        }
                    }
                }
    
    where containers is a arraylist containg item names you currently have.
    what I want to have is the total = piece.getCost().

    so the out come has to be:
    if you have the item nothing happens
    if you have all of the items in the highest tier nothing happens
    if you have 1 part of the tree (lets say the chest of gods) and not the other part only the other part has the total under it.
    the prereqs under your item has to be empty even though you are in the 2nd tier only in the 3rd tier they can show up again if all conditions are met.

    any ideas on how to handle this?
     
  2. Offline

    Dmrtje

    @guitargun maybe you can make some sort of a HashMap with the name or UUID of the player and a ArrayList what thet did get and then check the HashMap if the players has what is needed
     
  3. Offline

    mine-care

    @guitargunalternatvely to what @Dmrtje said you can make a custom oject in map to hold purchases and make any checks you want;
     
  4. Offline

    guitargun

    hmm that should also be that I have to add some methods in my enums for that. i'll see what I can do

    @Dmrtje and @mine-care I found a solution for it. was a lot of work and fiddling around but it works now
    result:
    Code:
                if(playerhas != 3){
                            if(!containers.contains(piece.getName())){
                                int forh = 0;
                                int forp = 0;
                                for(String c : playerh){
                                    if(Armor.returnarmor(c) == Armor.HEAVIER_CHEST || Armor.returnarmor(c) == Armor.RESISTENCE_CHEST){
                                        forh++;
                                    }else if(Armor.returnarmor(c) == Armor.CHEST_OF_GODS){
                                        forp++;
                                    }
                                }
                                if((piece == Armor.HEAVY_CHEST || piece == Armor.RESISTENCE_CHEST || piece == Armor.HEAVIER_CHEST) && forh != 2){
                                    total = piece.getCost();
                                }else if((piece == Armor.PURIFYING_CHEST || piece == Armor.CHEST_OF_GODS) && forp != 1){
                                    total = piece.getCost();
                                }else if(piece == Armor.CRUDE_CHEST){
                                    if(forh != 2){
                                        if(!containers.contains(Armor.HEAVY_CHEST.getName())){
                                            total = piece.getCost();
                                        }
                                    }
                                    if(forp != 1){
                                        if(!containers.contains(Armor.PURIFYING_CHEST.getName())){
                                            total = piece.getCost();
                                        }
                                    }
                                }
                    }
                }
    playerhas is a list that contains the last tier if the player has it

    EDIT by Timtower: merged posts
     
    Last edited by a moderator: Feb 1, 2015
Thread Status:
Not open for further replies.

Share This Page