Jump to content

Recommended Posts

Posted (edited)

Hello members,

 

Since my mobile service provider has an app and allows me play a game in order to win certain prizes like (extra mbs, msgs, talk time ) when i put a code 

i decided to create something similar to l2.

 

Explaination:

  1. Every player can get a coupon.
  2. Coupons have categories : Silver,Gold,Platinum
  3. Each category has its own reward list (configurable)
  4. Coupons can be deleted , redeemed  and show their rewards by writting /coupons
  5. You will win a random reward based on coupon's category and grade type
  6. Create your own condition and add a new coupon to this player.
  7. Grade Type added (No grade,D,C,B,A,S) based on the current level of the player, the grade will not change once the coupon activated
  8. Players have daily limit.
  9. Coupons Task Manager running and every day the time you will set all limits will be lifted.

If you guys find any mistakes please let me know i would really appreciate it, cause i want to learn alternative and easier ways  ;)

The code is working properly.

 

Coded on aCis 370 rev.

 

Video

 

Code

 

Htmls

 

Database

 

 

DROP TABLE IF EXISTS `coupons`;
CREATE TABLE `coupons` (
  `owner_objid` int(10) DEFAULT NULL,
  `coupon_id` int(11) NOT NULL DEFAULT '0',
  `coupon_category` varchar(45) DEFAULT NULL,
  `grade` tinyint(3) NOT NULL DEFAULT '0',
  PRIMARY KEY (`coupon_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 
ALTER TABLE `characters` ADD COLUMN `couponsused` tinyint(3) NOT NULL DEFAULT 0 AFTER `death_penalty_level`;
 

 

 

 

Player configs:

 

 

# Maximum coupons per day (0 = disalbe)
# This limit will be lifted at the time you will set in ResetCouponsLimitAt config
CouponsLimit = 5
 
# Time for the daily lift (default 00:00)
ResetCouponsLimitAt = 00:00

 

 

 

Special thanks to Tryskell.

 

P.s I do not have voiced command handlers so i used usercommandhandelrs.

if you want too, you have to add 1 line in commandname-e.dat

115	114	a,coupons\0
Edited by melron
  • Upvote 5
Posted (edited)

Not bad idea, sort of lucky wheel :P

 

To make it more complete create an item which could be droppable from a Rb, let's say, and this item will generate the coupon code, else some exchange option, x item for the coupon code. :)

Edited by SweeTs
Posted (edited)

- Rewards should be handled by a static map <String, List<CouponReward>> (basically a map with 3 entries), where string is the type of coupon. Your coupon will only stores coupon type (gold, silver,...) and not rewards.

- CouponManager coupons List can't be an ArrayList, you will get ConcurrentException. Either use ConcurrentHashMap, or CopyOnWriteArrayList (which is really horrible on .set()).

- final String DELETE_COUPON = "DELETE FROM coupons where coupon_id = ?"; and all other queries must be private static final and set out of the method (or at least passed directly the parameter in prepareStatement).

- getCouponId : use Rnd from commons package, and not Random. The method probably can be cleanup by a lot (using StringUtil.LETTERS_AND_DIGITS) and a scramble method.

 

The whole reward acquisition should be reworked. The basic concept is, your coupon is linked to a RewardType (SILVER, etc), your reward map .get( retrieve all possible rewards. Then you only need to Rnd.get(rewards) to retrieve the associated reward.

 

Atm you pass all possible rewards on each coupon, which is totally uneeded and generate a lot of pointless data. The whole bypass "redeem" needs to be reviewed too.

 

PS : if you want to enforce the coupon type, you can create RewardType enum, and store rewards under an EnumMap rather than a HashMap <String, List<CouponReward>>.

PS2 : at least you thought about coupon id already existing, good job :).

Edited by Tryskell
Posted

Well as i can see there are serious problems , should a mod move it to the proper section until it get fixed? It is not worth for someone to get it if its not completed.

 

 

Nick,Tryskell i love you guys. I will try to fix it as soon as possible :)

 

Thank you pirama,Sweets!

Posted (edited)

Well as i can see there are serious problems , should a mod move it to the proper section until it get fixed? It is not worth for someone to get it if its not completed.

 

 

Nick,Tryskell i love you guys. I will try to fix it as soon as possible :)

 

Thank you pirama,Sweets!

 

Simply share it under a v1, v2 model with a little changeset for each version.

 

The only real serious problem impacting the stability of your custom is the ConcurrentException if numerous players got/remove coupons in same time. Use ConcurrentHashMap.newKeySet() to handle it properly. Other changes are readability, performance and optimization.

Edited by Tryskell
Posted

Some comments.

  • Why are you returning null instead of empty list when a list is empty? It is easier and safer to handle empty lists than null statements that throw NPEs

 

Nice try overall. Thanks for the share.

 

I don't agree with this, empty lists, empty string etc have terrible performance, I always go with null checks, NPE means bad code that should be fixed not handled, imho NPE should be an Error and not an exception

Posted (edited)

Your opinion versus the whole internet.

 

Can't get it, so you're saying that few unnecessary calls that give you a dummy empty list are cleaner than nullptr ? Its obvious that this emptylist should be used on other cases but here? Explain me why this is worst and I will go to fck off right away

 

final ArrayList<Coupon> coupons = getCoupons(player);

if (coupons == null)

{

     //msg and exit

}

{

else

{

   for (Coupon c : coupons)

        c.something();

}

 

if getCoupons returns empty list instead of null, the flow of the rest code is dumb and nonsense. null checks are as fast as 1 == 1

Edited by xxdem
Posted

Why you even share it for free? I mean, you probably spent time on this, maybe even much time.

By the video i see its a unique idea, never seen something on other servers.

 

You probably should fix all the code the guys mentioned above and try to sell it.

because community is in need of new things i guess. It's a good idea to make new shares like old times.

Posted (edited)

Why you even share it for free? I mean, you probably spent time on this, maybe even much time.

By the video i see its a unique idea, never seen something on other servers.

 

You probably should fix all the code the guys mentioned above and try to sell it.

Designatix answered you but it's not only this thing.

Imagine this topic in marketplace section with these bugs inside ;)

Also there are many shares that deserves your question and not mine for sure :P.

I'm gonna update it to be completed and reshare it

Thank you for your good words my friend!

Edited by melron

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.




×
×
  • Create New...