Thread: Timed Task System

Page 1 of 2 12 LastLast
Results 1 to 10 of 16
  1. #1 Timed Task System 
    touched like seafood
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    23
    Posts
    4,837
    Thanks given
    1,676
    Thanks received
    1,566
    Discord
    View profile
    Rep Power
    1390
    TimedTaskType.java
    [Only registered and activated users can see links. ]

    TimedTaskReward.java
    [Only registered and activated users can see links. ]

    TimedTaskManager.java
    [Only registered and activated users can see links. ]

    AbstractTimedTask.java
    [Only registered and activated users can see links. ]

    TimedTaskInterfaceManager.java
    [Only registered and activated users can see links. ]

    all these bois get touched like seafood

    Example usage:
    Code:
    package com.rs.game.player.content.timedtasks.week;
    
    import com.rs.game.item.Item;
    import com.rs.game.player.content.timedtasks.AbstractTimedTask;
    
    /**
     * @author Tyluur <[email protected]>
     * @[Only registered and activated users can see links. ] 2018-12-26
     */
    public class RuniteOreWeeklyTimedTask extends AbstractTimedTask {
    
    	private static final long serialVersionUID = 8547553057115818247L;
    
    	@Override
    	protected String title() {
    		return "Mine @[email protected] rune ores";
    	}
    
    	@Override
    	public int targetAmount() {
    		return 1_000;
    	}
    
    	@Override
    	public Item[] rewards() {
    		return new Item[] { new Item(995, 1_000_000) };
    	}
    }
    [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] (official dog of rune-server)
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Reply With Quote  
     

  2. #2  
    Registered Member

    Join Date
    Feb 2010
    Posts
    3,187
    Thanks given
    1,124
    Thanks received
    834
    Discord
    View profile
    Rep Power
    1514
    why are you implementing Serializable
    Reply With Quote  
     

  3. #3  
    touched like seafood
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    23
    Posts
    4,837
    Thanks given
    1,676
    Thanks received
    1,566
    Discord
    View profile
    Rep Power
    1390
    Quote Originally Posted by Fire Cape View Post
    why are you implementing Serializable
    So you can serialize it.
    [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] (official dog of rune-server)
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Reply With Quote  
     

  4. #4  
    WVWVWVWVWVWVWVW

    _jordan's Avatar
    Join Date
    Nov 2012
    Age
    23
    Posts
    2,865
    Thanks given
    62
    Thanks received
    1,530
    Discord
    View profile
    Rep Power
    5000
    Why is there a serializable uid lmaooo

    Spoiler for signature:
    When your vision is crystal clear, they say it's razor-sharp
    A focused mind is said to be like a knife, but the scalpel is wisdom
    All one can do is accept that life is a double-edged sword
    Stay on the edge

    -



    Reply With Quote  
     

  5. #5  
    Registered Member
    JayArrowz's Avatar
    Join Date
    Sep 2008
    Posts
    67
    Thanks given
    60
    Thanks received
    64
    Discord
    View profile
    Rep Power
    392
    Quote Originally Posted by Tyluur View Post
    So you can serialize it.
    Why would anyone want to represent the TimedTask as a sequence of bytes? It doesn't make sense.

    Also the enum here: [Only registered and activated users can see links. ]
    I believe you should represent this DATA not in a enum but as flat file maybe JSON. The fact that you use a enum to represent this data means if someone wanted to add something like YEAR to that enum they'd be modifying current smelly code inside TimeTaskManager and making it smell more due to using a enum.

    Fishy indeed

    .e.g. Tyluur says to his manager i want to add YEARLY TimeTaskType. Tyluur tells his manager its gonna take 2 weeks, his manager asks why? Tyluur says he has to modify a bunch of if statements after he adds a new item to the enum, to support this change.
    Reply With Quote  
     

  6. #6  
    Chemist

    Advocatus's Avatar
    Join Date
    Dec 2009
    Age
    28
    Posts
    2,549
    Thanks given
    192
    Thanks received
    761
    Discord
    View profile
    Rep Power
    1332
    You can submit multiple files in a single gist.
    [Only registered and activated users can see links. ] your giveTasks method is pretty bloated and could be simplified. The method is private so based on ur implementation the only possible input to the method is DAY/WEEK. As a result, the code

    Code:
    	private void giveTasks(TimedTaskType day) {
    		if (day == TimedTaskType.DAY) {
    			int amount = Utils.random(DAY.minimumAmount(), DAY.maximumAmount());
    			long overAt = System.currentTimeMillis() + DAY.getTime();
    			List<AbstractTimedTask> tasks = generateRandomTasks(DAY, amount);
    
    			tasks.forEach(task -> task.setOverAt(overAt));
    
    			timedTasks.removeIf(task -> task.getDurationType() == DAY);
    			timedTasks.addAll(tasks);
    			rewardMap.put(DAY, DAY.pickRandomReward());
    			lastDayRecieveDate = new Date();
    		}
    		if (day == TimedTaskType.WEEK) {
    			long overAt = System.currentTimeMillis() + WEEK.getTime();
    			int amount = Utils.random(WEEK.minimumAmount(), WEEK.maximumAmount());
    			List<AbstractTimedTask> tasks = generateRandomTasks(WEEK, amount);
    
    			tasks.forEach(task -> task.setOverAt(overAt));
    
    			timedTasks.removeIf(task -> task.getDurationType() == WEEK);
    			timedTasks.addAll(tasks);
    			rewardMap.put(WEEK, WEEK.pickRandomReward());
    			lastWeekReceiveDate = new Date();
    		}
    	}
    Can be simplified/shortened by changing WEEK.pickRandomReward()-> day.pickRandomReward(). You can also do that with the other methods as well so that you dont just have an if/else with mostly identical code.

    Also TimedTaskType day is a pretty terrible name for the parameter in this case.
    Quote Originally Posted by blakeman8192 View Post
    Quitting is the only true failure.
    Reply With Quote  
     

  7. Thankful user:


  8. #7  
    Registered Member
    Join Date
    Dec 2013
    Posts
    318
    Thanks given
    109
    Thanks received
    72
    Rep Power
    309
    Quote Originally Posted by JayArrowz View Post
    Why would anyone want to represent the TimedTask as a sequence of bytes? It doesn't make sense.

    Also the enum here: [Only registered and activated users can see links. ]
    I believe you should represent this DATA not in a enum but as flat file maybe JSON. The fact that you use a enum to represent this data means if someone wanted to add something like YEAR to that enum they'd be modifying current smelly code inside TimeTaskManager and making it smell more due to using a enum.

    Fishy indeed

    .e.g. Tyluur says to his manager i want to add YEARLY TimeTaskType. Tyluur tells his manager its gonna take 2 weeks, his manager asks why? Tyluur says he has to modify a bunch of if statements after he adds a new item to the enum, to support this change.
    If your server goes down and you don't want the progress of a task to reset, serialisation of the timed task can work.
    Reply With Quote  
     

  9. Thankful user:


  10. #8  
    Registered Member
    JayArrowz's Avatar
    Join Date
    Sep 2008
    Posts
    67
    Thanks given
    60
    Thanks received
    64
    Discord
    View profile
    Rep Power
    392
    Quote Originally Posted by Kiissmyswagb View Post
    If your server goes down and you don't want the progress of a task to reset, serialisation of the timed task can work.
    I'd cry if anyone used binary serializers to save this... it still doesn't make sense to store it in raw bytes over something more readable like json.
    Reply With Quote  
     

  11. #9  
    Registered Member
    Join Date
    Dec 2013
    Posts
    318
    Thanks given
    109
    Thanks received
    72
    Rep Power
    309
    Quote Originally Posted by JayArrowz View Post
    I'd cry if anyone used binary serializers to save this... it still doesn't make sense to store it in raw bytes over something more readable like json.
    You don't need to worry about readability on something that doesn't require manual configuration.
    Reply With Quote  
     

  12. Thankful users:


  13. #10  
    Registered Member

    Join Date
    Nov 2014
    Posts
    247
    Thanks given
    38
    Thanks received
    144
    Rep Power
    201
    Quote Originally Posted by Kiissmyswagb View Post
    You don't need to worry about readability on something that doesn't require manual configuration.
    garbage take. it is far too easy to store things in a readable format these days for someone to use serialization for something they will store locally. in what world would you want to work with binary blobs over something more readable. it will be a pain to refactor, and you will have binary blobs sitting there that are of no use to query/look at/graph whatever (well unless of course you make special tooling but then...). why in the world would you store things as serialized objects this is 2021 people are literally spoonfeeding you better ways.

    scenario: you need to refactor a timed task or remove a timed task type.

    OT: Not the way I would do this. Not a fan of relying on package names? to determine which classes belong to which task type. You keep digging yourself deeper and deeper into a pigeonhole when this is supposed to be "abstract". What about a task that happens every 4 hours, or whatever? Why do I need to add a bunch of infrastructure changes to support that? Why is the abstract task forcing you to provide a list of items (I get you can override the giveRewards, but still, why am I forced to implement rewards()). Why not have AbstractTask (everything) -> ItemRewardTask (for convenience, base class for those item reward ones). Your enum also has item rewards... like why are item rewards so heavily integrated into this for no reason.

    I would reccomend you take a step back and think "what is the engine here". The answer is: something that will assign/do something to each player based on some "clock time". First make that and then worry about the task stuff secondarily. Right now that is already poorly written and making your life difficult.
    Reply With Quote  
     

Page 1 of 2 12 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. Buying Daily Tasks & New person task system
    By JAVA GURU #1023 in forum Buying
    Replies: 2
    Last Post: 03-19-2012, 12:37 AM
  2. My Task System Interface [VIEWS/COMMENTS?]
    By Rage in forum Show-off
    Replies: 4
    Last Post: 01-22-2012, 07:34 AM
  3. Task System.
    By Sir Tom in forum Snippets
    Replies: 7
    Last Post: 12-25-2011, 11:22 PM
  4. Task System Interface
    By Archspire in forum Snippets
    Replies: 23
    Last Post: 11-10-2011, 12:21 AM
  5. Slayer Task System.
    By Bando in forum Snippets
    Replies: 5
    Last Post: 08-17-2010, 07:36 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •