微信扫一扫 分享朋友圈

已有 20 人浏览分享

[服務器教學] 武陵道場

[複製鏈接]

初窺門道

275

威望

910

金錢

333

A幣
主題
44
回帖
34
精華
1
綜合社群主題發文量
0
電玩社群主題發文量
0
娛樂社群主題發文量
0
技術社群主題發文量
44
閱讀權限
20
註冊時間
2021-11-15
  • TA的每日心情
    奮鬥
    2024-1-28 13:17
  • 簽到天數: 1 天

    連續簽到: 1 天

    [LV.1]初來乍到

    chenhui540 發表於  4 小時前 | 顯示全部樓層 | 閱讀模式
    1.jpg
    3.jpg
    2.jpg

    ##########################################

                byte hpdisplaytype = -1;
                if (stats.getTagColor() > 0) {
                    hpdisplaytype = 0;
                } else if (stats.isFriendly()) {
                    hpdisplaytype = 1;
                } else if (mid >= 9305100 && mid <= 9305339) { // 道场怪物血量显示
                    hpdisplaytype = 2;
                } else if (!stats.isBoss() || mid == 9410066 || stats.isPartyBonus()) {
                    hpdisplaytype = 3;
                }
                stats.setHPDisplayType(hpdisplaytype);

                monsterStats.put(Integer.valueOf(mid), stats);
            }
            return stats;
        }

    ##########################################

        /*
        清除道场数据
        */
        public void ResetDojoRanks() {
            Calendar cal = Calendar.getInstance();
            int week = cal.get(Calendar.WEEK_OF_MONTH) % 2;
            int day = cal.get(Calendar.DAY_OF_WEEK);
            int time = (week == 1 && day == 1) ? 0 : (week == 0 && day == 1) ? 1 : week;
            int tab = time == 1 ? 0 : 1;

            try (
                Connection con = DatabaseConnection.getConnection();
                PreparedStatement ps = con.prepareStatement("DELETE FROM dojo_ranks WHERE tab = ?")) {
                ps.setInt(1, tab);
                ps.executeUpdate();
            } catch (SQLException e) {
                System.err.println("定时清理道场数据失败: " + e.getMessage());
            }
        }

        /*
        道场排行查询
        */
        public List<Pair<Integer, Integer>> DojoRanks() {
            List<Pair<Integer, Integer>> scores = new ArrayList<>();
            Calendar cal = Calendar.getInstance();
            int week = cal.get(Calendar.WEEK_OF_MONTH) % 2;
            int day = cal.get(Calendar.DAY_OF_WEEK);
            int time = (week == 1 && day == 1) ? 0 : (week == 0 && day == 1) ? 1 : week;
            int tab = time == 1 ? 0 : 1;

            try (
                Connection con = DatabaseConnection.getConnection();
                PreparedStatement ps = con.prepareStatement("SELECT `characterid`, `time` FROM dojo_ranks WHERE tab = ? ORDER BY `time` ASC LIMIT 50")) {
                ps.setInt(1, tab);
                try (
                    ResultSet rs = ps.executeQuery()) {
                    while (rs.next()) {
                        scores.add(new Pair<>(rs.getInt("characterid"), rs.getInt("time")));
                    }
                }
            } catch (SQLException e) {
                System.err.println("DojoRanks 错误: " + e);
            }
            return scores;
        }

        /*
        道场排行查询
        */
        public void sendDojoRanks() {
            Calendar cal = Calendar.getInstance();
            int week = cal.get(Calendar.WEEK_OF_MONTH) % 2;
            int day = cal.get(Calendar.DAY_OF_WEEK);
            int tab = (week == 1 && day == 1) ? 0 : (week == 0 && day == 1) ? 1 : week;

            try (
                Connection con = DatabaseConnection.getConnection();
                PreparedStatement ps = con.prepareStatement("SELECT `name`, `time` FROM dojo_ranks WHERE tab = ? ORDER BY `time` ASC LIMIT 50")) {
                ps.setInt(1, tab);
                try (
                    ResultSet rs = ps.executeQuery()) {
                        client.getSession().write(MaplePacketCreator.getDojoRanking(rs));
                        //ps.close();
                        //rs.close();
                }
            } catch (SQLException e) {
                System.err.println("sendDojoRanks 错误: " + e);
            }
        }

        /*
        写入道场排行
        */
        public void setDojoRanks(int timeDifference) {
            Calendar cal = Calendar.getInstance();
            int week = cal.get(Calendar.WEEK_OF_MONTH) % 2;
            int day = cal.get(Calendar.DAY_OF_WEEK);
            int tab = (week == 1 && day == 1) ? 0 : (week == 0 && day == 1) ? 1 : week;

            final String sqlSelect = "SELECT 1 FROM dojo_ranks WHERE characterid = ? AND tab = ? LIMIT 1";
            final String sqlUpdate = "UPDATE dojo_ranks SET name = ?, time = LEAST(time, ?) WHERE characterid = ? AND tab = ?";
            final String sqlInsert = "INSERT INTO dojo_ranks (characterid, name, tab, time) VALUES (?, ?, ?, ?)";

            try (
                Connection con = DatabaseConnection.getConnection()) {

                boolean exists = false;
                try (PreparedStatement ps = con.prepareStatement(sqlSelect)) {
                    ps.setInt(1, getId());
                    ps.setInt(2, tab);
                    try (ResultSet rs = ps.executeQuery()) {
                        exists = rs.next();
                    }
                }
                if (exists) {
                    try (PreparedStatement ps = con.prepareStatement(sqlUpdate)) {
                        ps.setString(1, getName());
                        ps.setInt(2, timeDifference);
                        ps.setInt(3, getId());
                        ps.setInt(4, tab);
                        ps.executeUpdate();
                    }
                } else {
                    try (PreparedStatement ps = con.prepareStatement(sqlInsert)) {
                        ps.setInt(1, getId());
                        ps.setString(2, getName());
                        ps.setInt(3, tab);
                        ps.setInt(4, timeDifference);
                        ps.executeUpdate();
                    }
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    ##########################################

        /*
        道场排行
        */
        public static byte[] getDojoRanking(ResultSet rs) throws SQLException {
            final MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

            mplew.writeShort(SendPacketOpcode.DOJANG_RANK.getValue());

            if (!rs.last()) {
                mplew.writeInt(1);
                mplew.writeShort(1);
                mplew.writeMapleAsciiString("");
                mplew.writeLong(0);
                return mplew.getPacket();
            }

            mplew.writeInt(rs.getRow()); // size
            rs.beforeFirst();
            int rank = 1;
            while (rs.next()) {
                mplew.writeShort(rank);
                mplew.writeMapleAsciiString(rs.getString("name"));
                mplew.writeLong(rs.getInt("time"));
                rank++;
            }
            return mplew.getPacket();
        }


    ##########################################

        /*
        道场BUFF选项视窗
        */
        public static byte[] getSlideMenu(int npcid, int type, int lasticon, String sel) {
            //Types: 0 - map selection 1 - neo city map selection 2 - korean map selection 3 - tele rock map selection 4 - dojo buff selection
            MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();

            mplew.writeShort(SendPacketOpcode.NPC_TALK.getValue());
            mplew.write(4); // slide menu
            mplew.writeInt(npcid);

            mplew.write(16);
            mplew.write(0);

            mplew.writeInt(type); // 选单类型
            mplew.writeInt(type == 0 ? lasticon : 0); // last icon on menu
            mplew.writeMapleAsciiString(sel);

            return mplew.getPacket();
        }


    ##########################################

    -- ----------------------------
    -- Table structure for `dojo_ranks`
    -- ----------------------------
    DROP TABLE IF EXISTS `dojo_ranks`;
    CREATE TABLE `dojo_ranks` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `tab` int(2) NOT NULL DEFAULT '0',
      `characterid` int(11) NOT NULL DEFAULT '0',
      `time` int(11) NOT NULL DEFAULT '0',
      `name` varchar(13) NOT NULL DEFAULT '',
      PRIMARY KEY (`id`),
      KEY `id` (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

    -- ----------------------------
    -- Records of dojo_ranks
    -- ----------------------------


    新版道场有普通、困难、排名模式。困难模式按照道场积分达到一定级别,给予不同的任务奖励。排名模式以WEEK_OF_MONTH作为区分,用于读取和记录通关时间,在排名内的玩家,下周上线时,会自动发放对应的奖励任务。

    任务脚本 7707


            //道场排行奖励

            var list = qm.getPlayer().DojoRanks();

            cal = java.util.Calendar.getInstance();
            day = cal.get(java.util.Calendar.DAY_OF_WEEK);
            week = cal.get(java.util.Calendar.WEEK_OF_MONTH) % 2;

            if (list.isEmpty() == false) {

            for (var i = 0; i < list.size(); i++) {

            if (list.get(i).getLeft() == qm.getPlayer().getId() && i < 50) {
                    Packages.server.quest.MapleQuest.getInstance(7213).forceStart(qm.getPlayer(), qm.getNpc(), i < 10 ? (i + 1) : 11);
                    }
                    }

            //上周道场数据清理
            if (day == 5 || day == 6 || day == 7) {
                    qm.getPlayer().ResetDojoRanks();
                    }
                    }


    道场脚本2026.8.1.rar (20.84 KB, 下載次數: 0)
    您需要登錄後才可以回帖 登錄 | 註冊會員

    本版積分規則

    78

    發文

    910

    金錢

    333

    A幣

    ----------榮譽勳章----------

    熱門推薦
    圖文推薦
    • 聯繫我們

    手機版|小黑屋|AICL社群娛樂集團

    GMT+8, 2026-8-1 16:56 , 網路刷新 0.136429 秒 .

    歡迎來到 AICL網路社群

    版權AICL社群所有 2011-2021.

    Total:123 Today:213 Online:322