Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
95 views
in Technique[技术] by (71.8m points)

java - How to create LootBox System like videogames

I want to practice java creating a LootBox Open System. I just tried this.

-Creating an Interface called Tier. -Creating UltimateTier,PremiumTier,StandardTier classes that implements Tier Interface. -Creating classes like Gold that extends UltimateTier,Titanium extends UltimateTier, Silver extends PremiumTier, etc.

Then I use org.reflections to find classes that inherits from another to create chances to get rare items like gold with this code

Tier[] tierItem = new Tier[3];
    for (int i = 0; i < 3; i++) {
         int itemQuality = (int)(1 + Math.random()* 10);

        int itemQuality = 1;
        if (itemQuality == 1) {
            tierItem[i] = new UltimateItemTier().getItem();
        }
        if (itemQuality >= 2 && itemQuality <= 4) {
            tierItem[i] = new PremiumItemTier();

        }
        if (itemQuality >= 5) {
            tierItem[i] = new StandardItemTier();
        }
    }

    return tierItem;

It returns me a list of 3 TIERITEMS, but I need to choose randomly 1 of those items for according to each tier on the list.

for example, if there is 10 PremiumItems and when I open the StandarBox, the list return "PremiumTier", "PremiumTier" , "StandardTier", the code must select any random item that inherits or match that Tier.

So list must return ( for example ) "Silver(PremiumTier), PremiumMetal(PremiumTier), Wood(StandardTier)

question from:https://stackoverflow.com/questions/66054133/how-to-create-lootbox-system-like-videogames

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...