Jump to content
  • 0

Online Time reward


Question

Posted

I want to give 1 GCM per hour to online players.

I am editing the java code I found for this, but it does not give an hourly reward.

 

package services;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ScheduledFuture;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import l2f.gameserver.Config;
import l2f.gameserver.ThreadPoolManager;
import l2f.gameserver.database.mysql;
import l2f.gameserver.model.GameObjectsStorage;
import l2f.gameserver.model.Player;
import l2f.gameserver.scripts.ScriptFile;
/**
 *
 * @author Special
 */
public class AutoReward implements ScriptFile, Runnable
{
    private static final Logger _log = LoggerFactory.getLogger(Player.class);
    
    private static final int REWARD_DELAY = 3600000; // 1h.
    private static final int REQUIRED_ONLINE = Config.DAILY_REWARD_REQUIRED_ONLINE * 3600000; // 1h.
    private static final int NOT_REWARD_AFK_DELAY = Config.DAILY_REWARD_AFK_TIME * 60000; // 10 mins.(Config 10)
    private static final DateFormat TIME_FORMAT = new SimpleDateFormat("HH");
    private boolean CLEANED = false;

    private ScheduledFuture<?> _task = null;

    @Override
    public void run()
    {
        if(CLEANED && time() >= Config.DAILY_REWARD_END_HOUR || time() < Config.DAILY_REWARD_START_HOUR)
            CLEANED = false;
        
        if(time() >= Config.DAILY_REWARD_START_HOUR && time() <= Config.DAILY_REWARD_END_HOUR)
        {
            for(Player player : GameObjectsStorage.getAllPlayersForIterate()) {
                    if(player.isOnline() && player.getUptime() >= REQUIRED_ONLINE
                        && (System.currentTimeMillis() - player.getLastNotAfkTime()) > NOT_REWARD_AFK_DELAY) {
                        if(!isRewardedDB(player)) {
                            player.sendMessage("You have been rewarded for online time!");
                            setRewardDB(player);
                        }
                    }
            }
        }
        
        if(CLEANED == false && time() <= Config.DAILY_REWARD_START_HOUR) {
            CLEANED = true;
            wipeRewardDB();
        }
    }
    
    public static int time()
    {
        return Integer.parseInt(TIME_FORMAT.format(new Date(System.currentTimeMillis())));
    }
    
    public static boolean isRewardedDB(Player player) {
        String value = Config.DAILY_REWARD_PROTECTION.equals("HWID") ? player.getHWID() : player.getIP();
    
        if(player.getVar("daily_reward") != null)
            return true;
        
        if(mysql.get("SELECT value FROM character_variables WHERE name='daily_reward' AND value='"+value+"'") != null)
            return true;
        
        return false;
    }
    
    public static void setRewardDB(Player player) {
        String value = Config.DAILY_REWARD_PROTECTION.equals("HWID") ? player.getHWID() : player.getIP();
        
        mysql.set("INSERT INTO character_variables (obj_id, type, name, value, expire_time) VALUES (?,?,?,?,?)", player.getObjectId(), "user-var", "daily_reward", value, -1);
    }
    
    public static void wipeRewardDB() {

        mysql.set("DELETE FROM `character_variables` WHERE `type`='user-var' and `name`='daily_reward'");
    }

    @Override
    public void onLoad()
    {
        _log.info("Loaded Service: AutoReward");
        if(_task == null)
            _task = ThreadPoolManager.getInstance().scheduleAtFixedDelay(this, REWARD_DELAY, REWARD_DELAY);
    }

    @Override
    public void onReload()
    {
        if(_task != null)
        {
            _task.cancel(true);
            _task = null;
        }
        _task = ThreadPoolManager.getInstance().scheduleAtFixedDelay(this, REWARD_DELAY, REWARD_DELAY);
    }

    @Override
    public void onShutdown()
    {
        //
    }
}

1 answer to this question

Recommended Posts

  • 0
Posted

I don't even think this is compilable to honest.

 

Do you want the reward to be every hour on the 24 hour clock, or every hour from the moment the server starts? I mean should it be exactly at 12:00, 13:00, 14:00 or if server starts at 12:21 rewards at 13:21, 14:21, 15:21?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • this will explain better than words  
    • I would like to emphasize that I am selling the tool used to generate geodata for the client you are developing, not the geodata itself; therefore, I consider the price reasonable. As for your view that the price is high and shows a lack of respect for the customer—that is your own opinion. Thank you. I have also purchased his products, and—just as you said—he is skilled and provides very enthusiastic support. If you feel he is deserving, then you should continue buying from him.
    • Ημουν μικρος οταν τον επαιξα, οριακα δεν ηξερα τι ειναι το Lineage, θυμαμαι πηγαιναμε στα νετ με τους φιλους και προσπαθουσαμε να κανουμε log-in αλλα πολλες φορες δεν μπορουσαμε γιατι ο server ηταν heavy σε load και πολλες φορες προλαβαιναμε να παιξουμε μονο κανα τεταρτακι η εικοσαλεπτο απ την μια ωρα που βαζαμε για να ανοιξουμε pc, ωστοσο εχω πολλες αναμνησεις να βλεπω τους μεγαλυτερους τοτε να παιζουν και εγω να καθομαι διπλα και να χαζευω gameplay, Λιγα πραγματα που ξερω (δεν ξερω αν ισχυουν) ειναι οτι τον σερβερ τον ειχε ανοιξει η αλυσιδα TheWeb, επισης οτι ηταν δυο οι σερβερ, ενας rpg low rate και ενας pvp με higher rates, περα απο αυτο δεν μπορεσα να βρω καμια αλλη χρησιμη πληροφορια, ουτε στα forum του theweb.gr ουτε στo l2.thegame.gr (waybackmachine) οποτε ερχομαι εδω που ειμαι σιγουρος οτι θα υπαρχουν σιγουρα καποιοι που επαιξαν εκει και δεν ηταν οσο πιτσιρικας οσο ημουν εγω που δεν καταλαβαινε τι γινοταν.   Γενικοτερα οποιος ξερει οτιδηποτε για τον thegame ας το πει, ακομη κι ας ειναι μια μικρη ιστορια που ακουσε πριν πολλα χρονια, ακομη κι αν ειναι μια μικρη πληροφορια για κατι που θυμαται μεσα στο παιχνιδι, οπως πως λεγανε τους admins, κανα σκηνικο ιντερνετ καφε και μπουνιδια, οοοοοτι μα οτιδηποτε κι αν ειναι αυτο αρκει να εχει να κανει με τον TheGame   (εννοειται εαν εχετε φωτογραφιες η βιντεο να τα linkαρετε)   μερικες δικες μου αποριες ειναι: απο τι chronicle αρχισε και μεχρι που εφτασε? ποια χρονια ηταν το peak του και σε ποιο chronicle? επισης μεχρι πιο chronicle εξελιχθηκε? γιατι εκλεισε αφου τοτε ηταν στο peak το να πηγαινει ο κοσμος στα ιντερνετ καφε και να παιζει λ2, τι features ειχε σαν σερβερ? επι ποσο ηταν? custom πραγματα κτλπ? η ηταν ενας bone stock server?    να'στε καλα!
    • Yeah... the price for the project at this stage is the kind of disrespect to the customer I was talking about.     As for deMEV, he’s overpriced too, but he’s one of the very few people in the L2 market who is available almost 24/7.
    • Thank you all for your interest in my post. I confirm that I did indeed use L2MapConv to develop my tool, adding my own customizations. If you are already a customer of deMEV, please continue to support him; I believe his products are excellent—I have purchased from him myself, and he is truly talented. Below is the Giran 22_22 geodata file generated using my tool; feel free to take a look. Thanks again to everyone for your comments. https://drive.google.com/file/d/1owpXCGEAhAO6TjjBJTYuVFqeUDu9RNoI/view?usp=drive_link
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..