com.lineage.server.model.L1ItemDelay.java Source code

Java tutorial

Introduction

Here is the source code for com.lineage.server.model.L1ItemDelay.java

Source

/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.lineage.server.ClientThread;
import com.lineage.server.GeneralThreadPool;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_Paralysis;
import com.lineage.server.templates.L1EtcItem;

/**
 * 
 * 
 * @author jrwz
 */
public class L1ItemDelay {

    /**
     * ?
     */
    static class ItemDelayTimer implements Runnable {

        /**  */
        private final L1Character _cha;

        /** ID */
        private final int _delayId;

        /**  () */
        private final int _delayTime;

        /**
         * ?
         * 
         * @param cha
         *            
         * @param id
         *            ID
         * @param delayTiem
         *             ()
         */
        public ItemDelayTimer(final L1Character cha, final int id, final int delayTime) {
            this._cha = cha;
            this._delayId = id;
            this._delayTime = delayTime;
        }

        /**
         * ?
         * 
         * @return  ()
         */
        public int get_delayTime() {
            return this._delayTime;
        }

        @Override
        public void run() {
            this.stopDelayTimer(this._delayId);
        }

        /**
         * ?
         * 
         * @param delayId
         *            ID
         */
        public void stopDelayTimer(final int delayId) {
            this._cha.removeItemDelay(delayId);
        }
    }

    /**
     * ?
     */
    static class TeleportUnlockTimer implements Runnable {

        /**  */
        private final L1PcInstance _pc;

        /**
         * ?
         * 
         * @param pc
         *            
         */
        public TeleportUnlockTimer(final L1PcInstance pc) {
            this._pc = pc;
        }

        @Override
        public void run() {
            this._pc.sendPackets(new S_Paralysis(S_Paralysis.TYPE_TELEPORT_UNLOCK, true));
        }
    }

    /** ??? */
    private static final Log _log = LogFactory.getLog(L1ItemDelay.class);

    /**
     * 500:?
     */
    public static final int WEAPON = 500; // ?

    /**
     * 501:?
     */
    public static final int ARMOR = 501; // ?

    /**
     * 502:??
     */
    public static final int ITEM = 502; // ??

    /**
     * 503:??
     */
    public static final int POLY = 503; // ??

    /**
     * 
     * 
     * @param client
     *            
     * @param item
     *            
     */
    public static void onItemUse(final ClientThread client, final L1ItemInstance item) {
        try {
            final L1PcInstance pc = client.getActiveChar();
            if (pc != null) {
                onItemUse(pc, item);
            }

        } catch (final Exception e) {
            _log.error(e.getLocalizedMessage(), e);
        }
    }

    /**
     * 
     * 
     * @param pc
     *            
     * @param delayId
     *            ID<br>
     * <br>
     *            500:?<br>
     *            501:?<br>
     *            502:??<br>
     *            503:??<br>
     *            504:?<br>
     * @param delayTime
     *             ()
     */
    public static void onItemUse(final L1PcInstance pc, final int delayId, final int delayTime) {
        try {
            if ((delayId != 0) && (delayTime != 0)) {
                final ItemDelayTimer timer = new ItemDelayTimer(pc, delayId, delayTime);

                pc.addItemDelay(delayId, timer);
                GeneralThreadPool.getInstance().schedule(timer, delayTime);
            }

        } catch (final Exception e) {
            _log.error(e.getLocalizedMessage(), e);
        }
    }

    /**
     * 
     * 
     * @param pc
     *            
     * @param item
     *            
     */
    public static void onItemUse(final L1PcInstance pc, final L1ItemInstance item) {
        try {
            int delayId = 0;
            int delayTime = 0;
            switch (item.getItem().getType2()) {
            case 0: // ?
                delayId = ((L1EtcItem) item.getItem()).get_delayid();
                delayTime = ((L1EtcItem) item.getItem()).get_delaytime();
                break;

            case 1: // 
                return;

            case 2: // 
                switch (item.getItemId()) {
                case 20077: // ?
                case 120077: // ?? ?
                case 20062: // 

                    //  && ???
                    if (item.isEquipped() && !pc.isInvisble()) {
                        pc.beginInvisTimer();
                    }
                    break;

                default: // ?
                    return;
                }
                break;
            }

            if ((delayId != 0) && (delayTime != 0)) {
                final ItemDelayTimer timer = new ItemDelayTimer(pc, delayId, delayTime);

                pc.addItemDelay(delayId, timer);
                GeneralThreadPool.getInstance().schedule(timer, delayTime);
            }

        } catch (final Exception e) {
            _log.error(e.getLocalizedMessage(), e);
        }
    }

    /**
     * ?
     * 
     * @param pc
     *            
     * @param item
     *            
     */
    public static void teleportUnlock(final L1PcInstance pc, final L1ItemInstance item) {
        final int delayTime = ((L1EtcItem) item.getItem()).get_delaytime();
        final TeleportUnlockTimer timer = new TeleportUnlockTimer(pc);
        GeneralThreadPool.getInstance().schedule(timer, delayTime);
    }

    private L1ItemDelay() {
    }

}