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

    • You invent yourself a life - bad for you, one of the inner core dev, fernandopm, which worked hard over aCis quests from 2011 to 2016 is argentinian. I teached him back in time to work and make proper quests. My dev team comes from 10+ countries and I'm myself french. "Racist/nationalist" card ? Not working bro.   Not sure why I should thank you to send me questions, and regarding bug reports, so far, I got none of yours in either discord, gitlab, or forums. I'm sorry if you feel "ignored", but that's more a psychanalyst you need to speak with if you put emotions towards someones' appreciation over a forum. I never ignore a bug report, and if so (like skills reports), it's because I got a bigger plan (skills refactor, in that case). In any case, I delivered cookies for the bug report/fix, even if it dated of months, with proper credits over changesets. "Victim card" ? Not really working, but ok, maybe you're "emotional".   I barely make money out of aCis, for the spent time - simply selling my services, or even coding/administrating a minecraft/L2J server would make far more money. Breaking intentionally things would be stupid. If you don't understand I'm not the only one working on that pack, I can't help you. Also, the scale of edits is sometimes extreme - AI L2OFF ? 1800 files added. How do you want everything works in a single shot ? "Exploiting noobz for money" card ? Still not working, or I'm a terrible businessman.   Meanwhile - you shadow advertise your project, L2JOne (since 2017 btw) - you should maybe start by the beginning saying you're a competitor and aCis is actually a spike in your foot. That also explains why you act like that. RusAcis got the exact same strategy, speaking bad of me, saying they got unique fixes (you speak about I break things, they break and recode things 4 times sometimes, btw), but successfully reselling latest revision with poorly executed stuff. "aCis is good, Tryskell is ok, but I solve all issues in extreme low time so I can piss over him" card ? Mmmmhhhh.   Our conversation ends here if you want, I don't force ppl to speak with me if they don't want - hopefully, people would understand I'm not the arrogant one and the one who doesn't want to talk, or even collaborate. :). I understand you got your own project and got no will to improve aCis.   NOTE : I'm extremely happy for your call of ExShowServerPrimitive with getValidGeoLocation, extremely impressive. Arrogant, no. Sarcastic ? Maybe.   Good night everyone.
    • Hi. @GX-Ext, svn does not work. is there anywhere else where we can get source code? Thank you so much.
    • new synchronized movement with neoengine obstacle correction I reported bugs to you and you completely ignored me because of my nationality. Yes, you were arrogant towards me. I sent you many questions on your forum and you didn't even thank me or say anything about it. I stopped using your updates a long time ago and focused on fixing my own aCis because you intentionally break the code. Just buy versions 401 to 409; you intentionally broke a lot of things for "IDIOTS" to buy from you. Anyway, our conversation ends here. Good luck with renaming and organizing; that probably makes you more money than fixing the basics. With this debug I created valid notes for monsters and NPCs, fixing the maxZ that you broke, and also corrected fly/water movements, making them more efficient. I only spent 2 months and I'm using Geoengine l2.j   NOTE: I'm not selling my GeoEngine, don't waste your time sending messages!
    • I'm on that same situation, but hey after almost 3600 commits it's almost playable! 😛
  • 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