Thread: Simple Mystery Box With A Simple Rarity System.

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 21
  1. #11  
    Banned
    Join Date
    Aug 2015
    Age
    26
    Posts
    143
    Thanks given
    42
    Thanks received
    43
    Rep Power
    0
    Nice work I guess
    Reply With Quote  
     

  2. #12  
    Registered Member

    Join Date
    Jul 2012
    Posts
    905
    Thanks given
    78
    Thanks received
    136
    Rep Power
    67
    EDIT: Nvm
    Reply With Quote  
     

  3. #13  
    Registered Member -Syndicate's Avatar
    Join Date
    Jan 2015
    Posts
    77
    Thanks given
    46
    Thanks received
    15
    Rep Power
    37
    Oh man.. There's a slew of ways you could have done this better.
    It's better than some of the atrocities I've seen for Mystery Boxes though.

    I plan on re-writing almost everything in the server I'm currently working on, I don't have Mystery Boxes but..
    I wrote this in about 5 minutes, obviously I've only tested it a bit, but something like this would be 1000x better.

    Class; MysteryBox
    Code:
    package server.model.minigames;
    
    import server.util.Misc;
    
    public class MysteryBox {
    
    	public enum MysteryReward {
    		COMMON {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, UNCOMMON {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, RARE {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, LEGENDARY {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		};
    
    		public abstract void getReward();
    		
    		public String getRarity() {
    			return name().charAt(0) + name().substring(1).toLowerCase();
    		}
    	}
    	
    }
    For testing; in the Commands class
    Code:
    			if (playerCommand.equalsIgnoreCase("testbox")) {
    				for (MysteryBox.MysteryReward mystery : MysteryBox.MysteryReward.values()) {
    					int chances = Misc.randomWithRange(0, 48);
    					/*if (chances <= 24) {
    						mystery.COMMON.getReward();
    					} else if (chances >= 24 && chances <= 36) {
    						mystery.UNCOMMON.getReward();
    					} else if (chances >= 36 && chances <= 42) {
    						mystery.RARE.getReward();
    					} else if (chances >= 42) {
    						mystery.LEGENDARY.getReward();
    					}*/
    					if (chances >= 0) {
    						mystery.getReward();
    					}
    				}
    			}
    Really haven't done anything with it though, just wrote the class and made sure the basis of it works.

    EDIT: I have a thing for Enums.
    Reply With Quote  
     

  4. #14  
    Registered Member

    Join Date
    Nov 2014
    Posts
    247
    Thanks given
    38
    Thanks received
    144
    Rep Power
    201
    Quote Originally Posted by -Syndicate View Post
    Oh man.. There's a slew of ways you could have done this better.
    It's better than some of the atrocities I've seen for Mystery Boxes though.

    I plan on re-writing almost everything in the server I'm currently working on, I don't have Mystery Boxes but..
    I wrote this in about 5 minutes, obviously I've only tested it a bit, but something like this would be 1000x better.

    Class; MysteryBox
    Code:
    package server.model.minigames;
    
    import server.util.Misc;
    
    public class MysteryBox {
    
    	public enum MysteryReward {
    		COMMON {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, UNCOMMON {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, RARE {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, LEGENDARY {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		};
    
    		public abstract void getReward();
    		
    		public String getRarity() {
    			return name().charAt(0) + name().substring(1).toLowerCase();
    		}
    	}
    	
    }
    For testing; in the Commands class
    Code:
    			if (playerCommand.equalsIgnoreCase("testbox")) {
    				for (MysteryBox.MysteryReward mystery : MysteryBox.MysteryReward.values()) {
    					int chances = Misc.randomWithRange(0, 48);
    					/*if (chances <= 24) {
    						mystery.COMMON.getReward();
    					} else if (chances >= 24 && chances <= 36) {
    						mystery.UNCOMMON.getReward();
    					} else if (chances >= 36 && chances <= 42) {
    						mystery.RARE.getReward();
    					} else if (chances >= 42) {
    						mystery.LEGENDARY.getReward();
    					}*/
    					if (chances >= 0) {
    						mystery.getReward();
    					}
    				}
    			}
    Really haven't done anything with it though, just wrote the class and made sure the basis of it works.

    EDIT: I have a thing for Enums.
    wtf... If I were to rate code on a scale from 0 to 10, his would be -1 and, yes, yours would be 1000x better.
    Reply With Quote  
     

  5. #15  
    Banned Market Banned Market Banned


    Join Date
    Jan 2011
    Age
    23
    Posts
    3,115
    Thanks given
    1,198
    Thanks received
    1,479
    Rep Power
    0
    Quote Originally Posted by -Syndicate View Post
    Oh man.. There's a slew of ways you could have done this better.
    It's better than some of the atrocities I've seen for Mystery Boxes though.

    I plan on re-writing almost everything in the server I'm currently working on, I don't have Mystery Boxes but..
    I wrote this in about 5 minutes, obviously I've only tested it a bit, but something like this would be 1000x better.

    ... code ...

    Really haven't done anything with it though, just wrote the class and made sure the basis of it works.

    EDIT: I have a thing for Enums.
    The proper way to do what you're trying to do would be to include the chance value and an array of items directly in the enum
    Reply With Quote  
     

  6. Thankful user:


  7. #16  
    Wut can u say when theres nothin to tell

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    21
    Posts
    1,535
    Thanks given
    668
    Thanks received
    402
    Rep Power
    971
    I actually would use Enum for that... another example is that I have some kind of Boxes handler, since I'm not using just Mystery boxes I decided to involve them all into one handler as interface and boxes are abstract objects...

    Could be done with Enum aswell, but was most likely to work either way



    [Only registered and activated users can see links. ]


    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  8. Thankful user:


  9. #17  
    Registered Member -Syndicate's Avatar
    Join Date
    Jan 2015
    Posts
    77
    Thanks given
    46
    Thanks received
    15
    Rep Power
    37
    Quote Originally Posted by lare96 View Post
    The proper way to do what you're trying to do would be to include the chance value and an array of items directly in the enum
    Yes I know, but I wrote it very quickly and didn't have time to work on it.
    I also only have one hand, boxers fracture on my dominant hand. Lolol.
    Reply With Quote  
     

  10. #18  
    Extreme Donator Market Banned Market Banned



    Join Date
    Dec 2010
    Age
    22
    Posts
    6,082
    Thanks given
    1,690
    Thanks received
    1,233
    Rep Power
    1704
    Quote Originally Posted by Max _ View Post
    Was just about to say that about the arrays.

    Overall the code looks pretty LQ.
    You should indent.



    Why are you just copying what Lare has already posted?
    I linked him to it so he wouldn't have it find it. Good day!
    Reply With Quote  
     

  11. #19  
    Registered Member Dr. Syn PHD's Avatar
    Join Date
    Mar 2015
    Posts
    156
    Thanks given
    76
    Thanks received
    15
    Rep Power
    15
    Quote Originally Posted by -Syndicate View Post
    Oh man.. There's a slew of ways you could have done this better.
    It's better than some of the atrocities I've seen for Mystery Boxes though.

    I plan on re-writing almost everything in the server I'm currently working on, I don't have Mystery Boxes but..
    I wrote this in about 5 minutes, obviously I've only tested it a bit, but something like this would be 1000x better.

    Class; MysteryBox
    Code:
    package server.model.minigames;
    
    import server.util.Misc;
    
    public class MysteryBox {
    
    	public enum MysteryReward {
    		COMMON {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, UNCOMMON {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, RARE {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		}, LEGENDARY {
    			public void getReward() {
    				Misc.println("Returned "+getRarity());
    			}
    		};
    
    		public abstract void getReward();
    		
    		public String getRarity() {
    			return name().charAt(0) + name().substring(1).toLowerCase();
    		}
    	}
    	
    }
    Oh dear god. This isn't 1000x better at all.
    Reply With Quote  
     

  12. #20  
    Registered Member -Syndicate's Avatar
    Join Date
    Jan 2015
    Posts
    77
    Thanks given
    46
    Thanks received
    15
    Rep Power
    37
    Quote Originally Posted by Syn- View Post
    Oh dear god. This isn't 1000x better at all.
    LOL, oh really? Please elaborate.
    What I posted there was literally a test to return the name of each constant.

    Utilized properly, it may be slightly redundant, but that's not always a terrible thing.
    The only thing that gets rather repetitive is the array that has assigned in each constants abstract method.

    So, unless you just skimmed that, and assumed its redundancy meant it was worse, I don't see how you came to that conclusion.
    Reply With Quote  
     

Page 2 of 3 FirstFirst 123 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. mystery box with common,uncommon,rare etc.
    By Joris_ in forum Tutorials
    Replies: 14
    Last Post: 09-10-2014, 05:43 PM
  2. Simple Mystery box and Crystal key combining
    By Wulfite in forum Snippets
    Replies: 27
    Last Post: 01-12-2014, 05:47 PM
  3. [PI] Mystery boxes WITH TUT
    By Shaloxis in forum Tutorials
    Replies: 26
    Last Post: 05-19-2013, 03:25 PM
  4. Simple JavaScript Chat Box with OOP Skill
    By JavaScriptBank in forum Website Development
    Replies: 0
    Last Post: 01-07-2011, 04:37 AM
  5. Replies: 4
    Last Post: 06-03-2010, 06:35 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •