Jump to content

Recommended Posts

Posted (edited)
### Eclipse Workspace Patch 1.0
#P L2J_DataPack
Index: dist/game/data/scripts/custom/QuizEvent/QuizEvent.java
===================================================================
--- dist/game/data/scripts/custom/QuizEvent/QuizEvent.java    (revision 0)
+++ dist/game/data/scripts/custom/QuizEvent/QuizEvent.java    (working copy)

package custom.QuizEvent;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import com.l2jserver.Config;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.util.Broadcast;
import com.l2jserver.util.Rnd;

/**
 * 
 * @author Bellatrix
 *
 */
public class QuizEvent
{
    public static boolean                             _quizRunning;
    private static String                             _question;
    private static String                             _answer1;
    private static String                             _answer2;
    private static String                             _answer3;
    private static int                                 _rightanswer;
    private static Map<L2PcInstance,Integer>     _players;
    private static int                                 status;
    private static int                                 announced;
    private static ThreadPoolManager                 tpm;
    private static AutoEventTask                    task;
    private static String[][]                         _questions;
    private static int i = 0;
    private static final int STATUS_NOT_IN_PROGRESS = 0;
    private static final int STATUS_ASK = 1;
    private static final int STATUS_ANSWER = 2;
    private static final int STATUS_END = 3;
    
    //----------------------------------------------------------------------------
    //------------------------------ CONFIG --------------------------------------
    //----------------------------------------------------------------------------
    
    //Number of questions per event
    private static int _questionNumber = 3;
    
    //The Item ID of the reward
    private static int _rewardID = 57;
    
    //The ammount of the reward
    private static int _rewardCount = 1000;
    
    //Wait for the first event after the server start (in seconds)
    private static int _initWait = 3600;
    
    //Time for answer the question (in seconds)
    private static int _answerTime = 60;
    
    //Time between two event (in seconds)
    private static int _betweenTime = 18000;
    
    
    
    public QuizEvent()
    {
        tpm = ThreadPoolManager.getInstance();
        status = STATUS_NOT_IN_PROGRESS;
        task = new AutoEventTask();
        announced = 0;
        _quizRunning = false;
        _question = "";
        _answer1 = "";
        _answer2 = "";
        _answer3 = "";
        _rightanswer = 0;
        _players = new HashMap<>(100);
        _questions = new String[20][];
        includeQuestions();
        tpm.scheduleGeneral(task, _initWait*1000);
        
    }
            
    
    
    private void includeQuestions()
    {
        
        
        File questionFile = new File(Config.DATAPACK_ROOT, "data/scripts/custom/QuizEvent/QuizEvent.xml");
        Document doc = null;
        try
        {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setIgnoringComments(true);
            dbf.setValidating(false);
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(questionFile);
            
            for (Node root = doc.getFirstChild(); root != null; root = root.getNextSibling())
            {
                if ("list".equalsIgnoreCase(root.getNodeName()))
                {
                    
                    for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling())
                    {
                
                        if ("question".equalsIgnoreCase(child.getNodeName()))
                        {
                            int id, correct;
                            String ask, answer1, answer2, answer3;
                            NamedNodeMap attrs = child.getAttributes();
                            
                            id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
                            correct = Integer.parseInt(attrs.getNamedItem("correct").getNodeValue());
                            ask = attrs.getNamedItem("ask").getNodeValue();
                            answer1 = attrs.getNamedItem("answer1").getNodeValue();
                            answer2 = attrs.getNamedItem("answer2").getNodeValue();
                            answer3 = attrs.getNamedItem("answer3").getNodeValue();
                            
                            _questions[id] = new String[]{ ask, answer1, answer2, answer3, ""+correct }; 
                            i++;
                        
                            
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            
        }
    }
    
    
    
    
    
    
    private class AutoEventTask implements Runnable
    {
        @Override
        public void run()
        {
            switch (status)
            {
            case STATUS_NOT_IN_PROGRESS:
                announceStart();
                break;
            case STATUS_ASK:    
                    if (announced < _questionNumber)
                    {
                    announceQuestion();
                    }
                    else
                    {
                    status = STATUS_END;
                    tpm.scheduleGeneral(task, 3000);
                    }
                break;
            case STATUS_ANSWER:
                announceCorrect();
                break;
            case STATUS_END:
                endEvent();
                break;
            default:
                break;
                
            }
        }
    }
    
    
    
    //Get a random question from the quiz_event table    
    private static void selectQuestion()
    {
        int id = Rnd.get(i)+1;
        _question = _questions[id][0];        
        _answer1 = _questions[id][1];
        _answer2 = _questions[id][2];
        _answer3 = _questions[id][3];
        _rightanswer = Integer.parseInt(""+_questions[id][4]);
    }
    
    
    
    //Announce the question
    private static void announceQuestion()
    {

        selectQuestion();
        Broadcast.toAllOnlinePlayers("-----------------");
        Broadcast.toAllOnlinePlayers("Question: "+_question);
        Broadcast.toAllOnlinePlayers("-----------------");
        Broadcast.toAllOnlinePlayers("1: "+_answer1);
        Broadcast.toAllOnlinePlayers("2: "+_answer2);
        Broadcast.toAllOnlinePlayers("3: "+_answer3);
        Broadcast.toAllOnlinePlayers("-----------------");
        
        status = STATUS_ANSWER;
        tpm.scheduleGeneral(task, _answerTime*1000);
    }
    
    
    
    //Announce the correct answer
    private static void announceCorrect()
    {
        Broadcast.toAllOnlinePlayers("-----------------");
        Broadcast.toAllOnlinePlayers("The correct answer was: "+_rightanswer);
        Broadcast.toAllOnlinePlayers("-----------------");
        announced++;
        giveReward();
        status = STATUS_ASK;
        tpm.scheduleGeneral(task, 5000);
    }
    
    
    private static void announceStart()
    {
        _quizRunning = true;
        _players.clear();
        Broadcast.toAllOnlinePlayers("Quiz Event begins! "+_questionNumber+" questions. "+_answerTime+" secs for answer each. ");
        Broadcast.toAllOnlinePlayers("Type . and the number of the correct answer to the chat. (Like: .1)");
        Broadcast.toAllOnlinePlayers("Get Ready!");
                
        status = STATUS_ASK;
        tpm.scheduleGeneral(task, 5000);
    }
    
    //Add a player and its answer
    public static void setAnswer(L2PcInstance player, int answer)
    {
        if( _players.containsKey(player) )
            player.sendMessage("You already choosen an aswer!: "+_players.get(player));
        else
        _players.put(player, answer);
    }
    
    
    private static void endEvent()
    {
        _quizRunning = false;
        Broadcast.toAllOnlinePlayers("The Quiz Event is over!");
        announced = 0;
        status = STATUS_NOT_IN_PROGRESS;
        tpm.scheduleGeneral(task, _betweenTime*1000);
    }
    
    
    
    private static void giveReward()
    {        
        for( L2PcInstance p: _players.keySet())
        {
            if(_players.get(p) == _rightanswer)
                {
                p.sendMessage("Your answer was correct!");
                p.addItem("Quiz", _rewardID, _rewardCount, p, true);
                }
                else
                {
                p.sendMessage("Your answer was not correct!");
                }

            
        }
        _players.clear();
    }
}
\ No newline at end of file
Index: dist/game/data/scripts/Custom/QuizEvent/QuizEvent.xml
===================================================================
--- dist/game/data/scripts/custom/QuizEvent/QuizEvent.xml    (revision 8768)
+++ dist/game/data/scripts/custom/QuizEvent/QuizEvent.xml    (working copy)
<?xml version="1.0" encoding="UTF-8"?>
<list>
    <question id = "1" ask = "Quel type Bijoux Drop Baium" answer1 = "Necklace" answer2 = "Ring" answer3 = "Earring" correct = "2" />
    <question id = "2" ask = "Comment s'appel l'admin" answer1 = "Bellatrix" answer2 = "Roberta" answer3 = "Jo" correct = "1" />
    <question id = "3" ask = "Quel Recompense donne le tvt" answer1 = "Codex" answer2 = "Coin" answer3 = "EventCoin" correct = "3" />
</list>
Index: dist/game/data/scripts/handlers/voicedcommandhandlers/Quiz.java
===================================================================
--- dist/game/data/scripts/handlers/voicedcommandhandlers/Quiz.java    (revision 0)
+++ dist/game/data/scripts/handlers/voicedcommandhandlers/Quiz.java    (working copy)
package handlers.voicedcommandhandlers;

import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;

import custom.QuizEvent.QuizEvent;

/**
 * @author Bellatrix
 */
public class Quiz implements IVoicedCommandHandler {
    private static final String[] _voicedCommands = {
        "quiz",
        "1",
        "2",
        "3"
    };
    
    /**
     * @see Bellatrix
     */
    @Override
    public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params) {
        
        if (command.equalsIgnoreCase("1") && QuizEvent._quizRunning) {
            QuizEvent.setAnswer(activeChar, 1);
        }
        
        if (command.equalsIgnoreCase("2") && QuizEvent._quizRunning) {
            QuizEvent.setAnswer(activeChar, 2);
        }
        
        if (command.equalsIgnoreCase("3") && QuizEvent._quizRunning) {
            QuizEvent.setAnswer(activeChar, 3);
        }
        return true;
    }
    
    /**
     * @see Bellatrix
     */
    @Override
    public String[] getVoicedCommandList() {
        new QuizEvent();
        return _voicedCommands;
    }
}
Index: dist/game/data/scripts/handlers/MasterHandlers.java
===================================================================
--- dist/game/data/scripts/handlers/MasterHandlerjava    (revision 0)
+++ dist/game/data/scripts/handlers/Masterhandlers.java    (working copy)
import handlers.voicedcommandhandlers.Quiz;


    private static final Class<?>[] VOICED_COMMAND_HANDLERS =
    {
        StatsVCmd.class,
        // TODO: Add configuration options for this voiced commands:
        // CastleVCmd.class,
        // SetVCmd.class,
        (Config.L2JMOD_ALLOW_WEDDING ? Wedding.class : null),
        (Config.BANKING_SYSTEM_ENABLED ? Banking.class : null),
        (Config.L2JMOD_CHAT_ADMIN ? ChatAdmin.class : null),
        (Config.L2JMOD_MULTILANG_ENABLE && Config.L2JMOD_MULTILANG_VOICED_ALLOW ? Lang.class : null),
        (Config.L2JMOD_ENABLE_ONLINE_STATUS ? OnlineStatus.class : null),
        (Config.L2JMOD_DEBUG_VOICE_COMMAND ? Debug.class : null),
        (Config.L2JMOD_ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null),
        Quiz.class,

 

Edited by extasie80
  • Like 1
  • Upvote 1
  • 1 year later...

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

    • Hi, could someone please share a C1 L2 Off cheat code for local play?
    • I’ve worked with a web designer Tacoma before, and it really reminded me how much smoother projects run when design and development stay in sync. Your setup looks solid, and pairing clean UI work with steady backend support can save a ton of back‑and‑forth later. If you ever decide to push harder on conversions or need outside perspective on structure, that mix helped me spot gaps early on.
    • If you’re juggling mixed payment methods and tricky setups, I’ve found that easing the pressure on the subscription side can make the whole flow smoother. I started using Subscription Revenue Growth for handling my own recurring payments, upgrades, and all that messy churn stuff, and it took a big weight off. Pairing something stable for subs with your gateway setup can keep cashflow from going off the rails.
    • L2Avalon launches February 20 High Five project (Salvation client) focused on classic world progression — not instance spam and not “twink” metas. What is L2Avalon? L2Avalon is built around real Lineage 2 gameplay: farming spots, open world conflict, raids, epics, economy and competition. No Kamael Reduced instanced content **Discord:** https://discord.gg/NbM2cXmAem 🌐 **Website:** https://l2avalon.net Balance & Economy Every class is tuned to be viable in PvE and PvP Off-meta classes get buffed instead of adding power-creep garbage Adena-based economy Farming matters: boosted Drop/Spoil for each stage of progression Rates & Settings Dynamic XP: 50x (Lv 1–40) → 1x (Lv 78+) Staged progression with new content unlocking weekly Adena / Drop / Spoil: 3x / 5x / 5x NPC Buffer: 2 hours (Premium: 3 hours) Box limit: 2+1 windows per PC MP potion: 1000 MP, 10s cooldown Free2Play System (earn Donate Coins by playing) You don’t have to donate to progress. Donate Coins drop in-game, so everything is achievable through playtime and activity. Where Donate Coins drop: Mobs Lv 76+, Raid Bosses Lv 70+, Epic Bosses Auto-farm (controlled) Limit: only 1 window can use auto-farm at the same time Daily time: 1 hour/day without Premium Extra tickets: purchasable with PC Bang points (earned by being online) Disabled zones: CC / IT / FOG / VARKA / KETRA Equipment Changes Reworked set bonuses Reworked SA system Enchanted set bonuses Enchanted shirt bonuses Fake Epic jewelry (weakened alternative) Skills (High Five mechanics) New skills added Old skills updated New enchant branches + updated existing ones Subclass skills Clan skills Daily Activities (solo-friendly) Events / Missions / Instances Stages Soon — stage schedule and weekly unlocks will be published February 20 — we start. **Discord:** https://discord.gg/NbM2cXmAem 🌐 **Website:** https://l2avalon.net
  • 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..

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock