Jump to content
  • 0

[Help] Daily/Weekly quest


gripao

Question

Hello!!

I'm trying to make a quest to kill X mobs and give you a reward. I already have it ready, or so I think.

 

Now I would like to add the function of making it daily or weekly. I've tried to control this in the same java file of the quest, but I haven't been able to...

 

I was thinking of putting a marker on the quest so that it is "daily" or "weekly" and ¿generating another java program? that is in charge of restarting all the quests with the daily marker at 9 in the morning every day and on Wednesdays at 9 every Wednesday.

 

Since I'm new to java programming (I had already programmed in bash) and developing l2j I don't know where I should create that program. Could it be in the java folder with a name like "org.l2jmobius.xxx.xxx"?

 

I don't know how to approach it because I don't understand the logic of the files and that how runs every day to reset quest with marker.

 

Could anyone help me understand this and explain how I should do it? I'm not asking for ready-made code, I can do that myself, but how to deal with it 😛

 

I also don't know if this method is better or in the java file itself (but I haven't managed to do it this way).

 

See you guys and thanks for all. 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0
16 hours ago, gripao said:

Hello!!

I'm trying to make a quest to kill X mobs and give you a reward. I already have it ready, or so I think.

 

Now I would like to add the function of making it daily or weekly. I've tried to control this in the same java file of the quest, but I haven't been able to...

 

I was thinking of putting a marker on the quest so that it is "daily" or "weekly" and ¿generating another java program? that is in charge of restarting all the quests with the daily marker at 9 in the morning every day and on Wednesdays at 9 every Wednesday.

 

Since I'm new to java programming (I had already programmed in bash) and developing l2j I don't know where I should create that program. Could it be in the java folder with a name like "org.l2jmobius.xxx.xxx"?

 

I don't know how to approach it because I don't understand the logic of the files and that how runs every day to reset quest with marker.

 

Could anyone help me understand this and explain how I should do it? I'm not asking for ready-made code, I can do that myself, but how to deal with it 😛

 

I also don't know if this method is better or in the java file itself (but I haven't managed to do it this way).

 

See you guys and thanks for all. 


If you are this new to java, I would strongly recommend using IntelliJ Community Edition (free) instead of Eclipse since it indexes your entire source and makes it extremely easy to navigate forward and backward dependencies and method calls.

Now, on the topic.

Unless your Mobius sources are ancient, they should already have native support. It is called `DailyTaskManager`.
It would be impossible to give you a mould without such a DailyTaskManager. I would suggest you parse/adapt it from a newer source version if you don't have it.

The logic is rather simple once you get to understand it.
1. You need a handler to count the mobs and give rewards, etc.
2. You need to keep mission status for each individual player in the database.
3. You need to INSERT the data when a player takes the mission, UPDATE it whenever you like, be it on every single mob or not (I would only update the DB on player disconnect/log out, or on mission completion), and SELECT/extract it when the player logs in (EnterWorld.java).
4. You need a way to get the Mission Reset Type (Daily/Weekly), and you should call a reset method similar to the one at the bottom of my post from within the DailyTaskManager every day at 9am or whenever you like.

Keep in mind that the above is not an exhaustive list, but some generalised approach aimed at helping you see the bigger picture.
 

public synchronized void reset()
    {
        DailyMissionResetType reset = _holder.getResetType(); 
        switch (reset)
        {
            case NEVER ->
            {
                return;
            }
            case MONTHLY ->
            {
                if (Calendar.getInstance().get(Calendar.DAY_OF_MONTH) != 1)
                {
                    return;
                }
            }
            case WEEKLY ->
            {
                if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY)
                {
                    return;
                }
            }
            case WEEKEND ->
            {
                if (Calendar.getInstance().get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY)
                {
                    return;
                }
            }
            case DAILY ->
            {
            }
            default ->
            {
                LOGGER.warning("Unhandled daily mission reset type: " + reset);
                return;
            }
        }

        try (
                Connection con = DatabaseFactory.getConnection();
                PreparedStatement ps = con.prepareStatement("DELETE FROM character_daily_rewards WHERE missionId = ? AND status = ?"))
        {
            ps.setInt(1, _holder.getId());
            ps.setInt(2, DailyMissionStatus.COMPLETED.getClientId());
            ps.execute();
        }
        catch (SQLException e)
        {
            LOGGER.log(Level.WARNING, "Error while clearing data for: " + getClass().getSimpleName(), e);
        }
        finally
        {
            _entries.clear();
            // resets the entries in the Manager.
            DailyMissionsManager.getInstance().clearEntries();
        }
    }


*Disclaimer: The provided code snippet is just an adaptation of Mobius' implementation on newer chronicles.
 

Edited by Salty Mike
Link to comment
Share on other sites

  • 0
18 hours ago, gripao said:

Hello!!

I'm trying to make a quest to kill X mobs and give you a reward. I already have it ready, or so I think.

 

Now I would like to add the function of making it daily or weekly. I've tried to control this in the same java file of the quest, but I haven't been able to...

 

I was thinking of putting a marker on the quest so that it is "daily" or "weekly" and ¿generating another java program? that is in charge of restarting all the quests with the daily marker at 9 in the morning every day and on Wednesdays at 9 every Wednesday.

 

Since I'm new to java programming (I had already programmed in bash) and developing l2j I don't know where I should create that program. Could it be in the java folder with a name like "org.l2jmobius.xxx.xxx"?

 

I don't know how to approach it because I don't understand the logic of the files and that how runs every day to reset quest with marker.

 

Could anyone help me understand this and explain how I should do it? I'm not asking for ready-made code, I can do that myself, but how to deal with it 😛

 

I also don't know if this method is better or in the java file itself (but I haven't managed to do it this way).

 

See you guys and thanks for all. 

make an item that expires either a week or a day when u press the accept , if u try to redo it and u have the item it wont let you, can be in quest items and not destroyable... 

Link to comment
Share on other sites

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
Answer this question...

×   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...