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

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.



  • Posts

    • Fix Visual Boundary for AutoFarm when entering a new zone. Fix Assassin Interface Automatic SoulShot usage. Fix Assassin Interface not displaying Castle/Base. Fix Achievements displaying item rewards for CommunityBoard & NPC. Fix Prevent players from purchasing their own Auctioned items. Added ''.raid'' and ''.achievement'' commands. Added support for multiple currencies on Auction Added Search feature to Auction. Added Offline Stores Added '.exit' & '.quit' command to Dungeon System so players can now exit/quit dungeons Added VIP Account System (Alternative XP, SP & Drop Rates, Unlocks Costumes) Added Loot Box System Changed DungeonsManager now displays reward list on dungeon pages. Changed GlobalShop to include pages for all currencies. HTML/XML edits
    • When I teleport to town, my current location is differ from the map. How do I fix this?    
    • A New Chapter Begins We're Rebuilding – Join Our Staff Team After many years of activity, growth, and challenges, it’s finally time for our community to restructure and move forward. We’re ready to turn a new page and evolve into something greater — but we can’t do it without the help of passionate and committed people. That’s why we’re now opening up staff applications for those who want to actively shape the future of our community. If you have the motivation, time, and patience to contribute to something meaningful, this is your chance to step in and make a real impact. What We're Looking For We’re building a fresh and dedicated team of individuals who are ready to support and grow this project. Open roles include: Moderators – to keep the forum clean, safe, and organized Gaming Moderators – to help manage gaming boards (e.g., Lineage, GTA FiveM) Content Creators – to post updates, guides, and articles Community Managers – to engage users and drive activity Technical Staff – for development, backend, and server work We’re not focusing only on Lineage anymore. Our vision is expanding to new areas — including GTA FiveM and other multiplayer games you might have expertise in. If you have a good idea, a server plan, or something new to suggest — we’re open to it. Now’s the time to bring it forward. Requirements We’re looking for individuals who have: A history of activity on the forum (preferred) Available time to contribute consistently A sense of teamwork and responsibility A genuine interest in gaming and community building If you're interested, just send a private message to me or Celestine. (or just reply here) Tell us a few things about yourself and how you’d like to contribute. Let’s bring this community back to life. Let’s rebuild something great — together.   M M G A 
  • Topics

×
×
  • Create New...