查看: 259|回復: 0

[閒聊閒語] 靈魂/靈魂石

[複製鏈接]

71

主題

267

帖子

5707

金錢

火焰之影

Rank: 8Rank: 8

威望
247
精華
0
貢獻
0
鑽石
0
閱讀權限
50
積分
6468
在線時間
110 小時
相冊
0
日誌
0
好友
0
發表於 2026-1-30 22:38 | 顯示全部樓層 |閱讀模式
package com.lineage.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* 靈魂/靈魂石配置類別
* 負責加載和管理遊戲中靈魂系統相關的配置設定
*/
public final class ConfigSoul {
    private static final Logger logger = Logger.getLogger(ConfigSoul.class.getName());

    // ========== 系統核心固定參數(硬編碼) ==========
    /** 授權過期時間:2100年1月1日 00:00:00 UTC */
    private static final long AUTH_EXPIRE_TIMESTAMP = 4102416000000L;

    /** 配置檔案路徑(相對路徑) */
    private static final String SOUL_CONFIG_FILE = "./config/soul.properties";

    // ========== 靈魂系統設定(外部配置) ==========
    /** 是否啟用靈魂系統 */
    public static boolean enableSoulSystem = true;

    /** 靈魂石最大堆疊數量 */
    public static int maxSoulStoneStack = 100;

    /** 靈魂石掉落機率(百分比) */
    public static double soulStoneDropRate = 0.1;

    /** 靈魂石製作成功機率(百分比) */
    public static double soulStoneCraftSuccessRate = 0.8;

    /** 靈魂石製作金幣消耗 */
    public static int soulStoneCraftCost = 1000;

    /** 靈魂石製作所需材料數量 */
    public static int soulStoneCraftMaterialCount = 5;

    // ========== 靈魂強化設定(外部配置) ==========
    /** 是否啟用靈魂強化 */
    public static boolean enableSoulEnhancement = true;

    /** 靈魂強化最大等級 */
    public static int maxSoulEnhanceLevel = 10;

    /** 靈魂強化基礎成功機率(百分比) */
    public static double baseSoulEnhanceSuccessRate = 0.7;

    /** 靈魂強化失敗懲罰(是否降低等級) */
    public static boolean soulEnhanceFailurePenalty = true;

    /** 靈魂強化金幣消耗基數 */
    public static int soulEnhanceCostBase = 500;

    // ========== 靈魂技能設定(外部配置) ==========
    /** 是否啟用靈魂技能 */
    public static boolean enableSoulSkills = true;

    /** 靈魂技能激活等級需求 */
    public static int soulSkillActivateLevel = 20;

    /** 靈魂技能MP消耗倍率 */
    public static double soulSkillMpCostMultiplier = 1.2;

    /** 靈魂技能冷卻時間倍率 */
    public static double soulSkillCooldownMultiplier = 0.8;

    /** 靈魂技能效果倍率 */
    public static double soulSkillEffectMultiplier = 1.5;

    // ========== 靈魂特殊效果設定(外部配置) ==========
    /** 是否啟用靈魂特殊效果 */
    public static boolean enableSoulSpecialEffects = true;

    /** 靈魂持續回復效果間隔(秒) */
    public static int soulRegenInterval = 5;

    /** 靈魂持續回復HP數量 */
    public static int soulRegenHpAmount = 10;

    /** 靈魂持續回復MP數量 */
    public static int soulRegenMpAmount = 5;

    /** 靈魂攻擊力加成(百分比) */
    public static double soulAttackBonus = 0.1;

    /** 靈魂防禦力加成(百分比) */
    public static double soulDefenseBonus = 0.05;

    /**
     * 私有建構子,防止實例化
     */
    private ConfigSoul() {
        // 授權時間檢查
        if (new Date().after(new Date(AUTH_EXPIRE_TIMESTAMP))) {
            throw new RuntimeException("授權已過期,靈魂配置無法啟動!");
        }
    }

    /**
     * 加載靈魂配置
     * @throws ConfigErrorException 當配置加載失敗時拋出
     */
    public static void load() throws ConfigErrorException {
        Properties properties = new Properties();
        FileInputStream fis = null;

        try {
            File configFile = new File(SOUL_CONFIG_FILE);
            if (!configFile.exists()) {
                logger.warning("靈魂配置檔案不存在: " + SOUL_CONFIG_FILE + ",使用預設值");
                logDefaultConfiguration();
                return;
            }

            fis = new FileInputStream(configFile);
            properties.load(fis);

            // 載入靈魂系統設定
            enableSoulSystem = Boolean.parseBoolean(
                properties.getProperty("EnableSoulSystem", "true"));
            maxSoulStoneStack = Integer.parseInt(
                properties.getProperty("MaxSoulStoneStack", "100"));
            soulStoneDropRate = Double.parseDouble(
                properties.getProperty("SoulStoneDropRate", "0.1"));
            soulStoneCraftSuccessRate = Double.parseDouble(
                properties.getProperty("SoulStoneCraftSuccessRate", "0.8"));
            soulStoneCraftCost = Integer.parseInt(
                properties.getProperty("SoulStoneCraftCost", "1000"));
            soulStoneCraftMaterialCount = Integer.parseInt(
                properties.getProperty("SoulStoneCraftMaterialCount", "5"));

            // 載入靈魂強化設定
            enableSoulEnhancement = Boolean.parseBoolean(
                properties.getProperty("EnableSoulEnhancement", "true"));
            maxSoulEnhanceLevel = Integer.parseInt(
                properties.getProperty("MaxSoulEnhanceLevel", "10"));
            baseSoulEnhanceSuccessRate = Double.parseDouble(
                properties.getProperty("BaseSoulEnhanceSuccessRate", "0.7"));
            soulEnhanceFailurePenalty = Boolean.parseBoolean(
                properties.getProperty("SoulEnhanceFailurePenalty", "true"));
            soulEnhanceCostBase = Integer.parseInt(
                properties.getProperty("SoulEnhanceCostBase", "500"));

            // 載入靈魂技能設定
            enableSoulSkills = Boolean.parseBoolean(
                properties.getProperty("EnableSoulSkills", "true"));
            soulSkillActivateLevel = Integer.parseInt(
                properties.getProperty("SoulSkillActivateLevel", "20"));
            soulSkillMpCostMultiplier = Double.parseDouble(
                properties.getProperty("SoulSkillMpCostMultiplier", "1.2"));
            soulSkillCooldownMultiplier = Double.parseDouble(
                properties.getProperty("SoulSkillCooldownMultiplier", "0.8"));
            soulSkillEffectMultiplier = Double.parseDouble(
                properties.getProperty("SoulSkillEffectMultiplier", "1.5"));

            // 載入靈魂特殊效果設定
            enableSoulSpecialEffects = Boolean.parseBoolean(
                properties.getProperty("EnableSoulSpecialEffects", "true"));
            soulRegenInterval = Integer.parseInt(
                properties.getProperty("SoulRegenInterval", "5"));
            soulRegenHpAmount = Integer.parseInt(
                properties.getProperty("SoulRegenHpAmount", "10"));
            soulRegenMpAmount = Integer.parseInt(
                properties.getProperty("SoulRegenMpAmount", "5"));
            soulAttackBonus = Double.parseDouble(
                properties.getProperty("SoulAttackBonus", "0.1"));
            soulDefenseBonus = Double.parseDouble(
                properties.getProperty("SoulDefenseBonus", "0.05"));

            logger.info("靈魂配置加載完成");
            logConfiguration();

        } catch (NumberFormatException e) {
            String errorMsg = "靈魂配置檔案中包含無效的數字格式: " + e.getMessage();
            logger.severe(errorMsg);
            throw new ConfigErrorException(errorMsg);
        } catch (IOException e) {
            String errorMsg = "讀取靈魂配置檔案時發生錯誤: " + e.getMessage();
            logger.severe(errorMsg);
            throw new ConfigErrorException(errorMsg);
        } catch (Exception e) {
            String errorMsg = "加載靈魂配置時發生未預期錯誤: " + e.getMessage();
            logger.severe(errorMsg);
            throw new ConfigErrorException(errorMsg);
        } finally {
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    logger.log(Level.WARNING, "關閉靈魂配置檔案輸入流時發生錯誤", e);
                }
            }
            properties.clear();
        }
    }

    /**
     * 記錄預設配置資訊
     */
    private static void logDefaultConfiguration() {
        logger.info("使用預設靈魂配置設定");
        logConfiguration();
    }

    /**
     * 記錄當前配置設定到日誌
     */
    private static void logConfiguration() {
        logger.info("=== 靈魂配置設定 ===");
        logger.info("靈魂系統: " + (enableSoulSystem ? "啟用" : "停用"));
        if (enableSoulSystem) {
            logger.info("靈魂石最大堆疊: " + maxSoulStoneStack);
            logger.info("靈魂石掉落機率: " + (soulStoneDropRate * 100) + "%");
            logger.info("靈魂石製作成本: " + soulStoneCraftCost + "金幣");
        }
        logger.info("靈魂強化: " + (enableSoulEnhancement ? "啟用" : "停用"));
        if (enableSoulEnhancement) {
            logger.info("最大強化等級: " + maxSoulEnhanceLevel);
            logger.info("基礎成功機率: " + (baseSoulEnhanceSuccessRate * 100) + "%");
        }
        logger.info("靈魂技能: " + (enableSoulSkills ? "啟用" : "停用"));
        if (enableSoulSkills) {
            logger.info("技能激活等級: " + soulSkillActivateLevel);
            logger.info("技能效果倍率: " + soulSkillEffectMultiplier + "x");
        }
        logger.info("靈魂特效: " + (enableSoulSpecialEffects ? "啟用" : "停用"));
        logger.info("=================");
    }

    /**
     * 計算靈魂強化成功機率
     * @param level 當前強化等級
     * @return 成功機率(0.0-1.0)
     */
    public static double calculateSoulEnhanceSuccessRate(int level) {
        if (!enableSoulEnhancement || level <= 0 || level >= maxSoulEnhanceLevel) {
            return 0.0;
        }

        // 等級越高,成功機率越低
        double rateReduction = (level - 1) * 0.05; // 每等級降低5%
        return Math.max(0.1, baseSoulEnhanceSuccessRate - rateReduction);
    }

    /**
     * 計算靈魂強化消耗
     * @param level 當前強化等級
     * @return 金幣消耗量
     */
    public static int calculateSoulEnhanceCost(int level) {
        if (!enableSoulEnhancement || level <= 0 || level >= maxSoulEnhanceLevel) {
            return 0;
        }

        // 等級越高,消耗越多
        return soulEnhanceCostBase * level;
    }

    /**
     * 計算靈魂技能MP消耗
     * @param baseCost 基礎MP消耗
     * @return 調整後的MP消耗
     */
    public static int calculateSoulSkillMpCost(int baseCost) {
        if (!enableSoulSkills) {
            return baseCost;
        }

        return (int) Math.max(1, baseCost * soulSkillMpCostMultiplier);
    }

    /**
     * 計算靈魂技能冷卻時間
     * @param baseCooldown 基礎冷卻時間(毫秒)
     * @return 調整後的冷卻時間
     */
    public static int calculateSoulSkillCooldown(int baseCooldown) {
        if (!enableSoulSkills) {
            return baseCooldown;
        }

        return (int) Math.max(100, baseCooldown * soulSkillCooldownMultiplier);
    }

    /**
     * 計算靈魂技能效果
     * @param baseEffect 基礎效果值
     * @return 調整後的效果值
     */
    public static int calculateSoulSkillEffect(int baseEffect) {
        if (!enableSoulSkills) {
            return baseEffect;
        }

        return (int) Math.max(1, baseEffect * soulSkillEffectMultiplier);
    }

    /**
     * 檢查是否可以使用靈魂系統
     * @param playerLevel 玩家等級
     * @return 如果可以使用返回true
     */
    public static boolean canUseSoulSystem(int playerLevel) {
        return enableSoulSystem && playerLevel >= soulSkillActivateLevel;
    }

    /**
     * 獲取配置摘要資訊
     * @return 配置摘要字串
     */
    public static String getConfigurationSummary() {
        return String.format(
            "靈魂配置 - 系統: %s, 強化: %s, 技能: %s, 特效: %s",
            enableSoulSystem ? "啟用" : "停用",
            enableSoulEnhancement ? "啟用" : "停用",
            enableSoulSkills ? "啟用" : "停用",
            enableSoulSpecialEffects ? "啟用" : "停用"
        );
    }
}





上一篇︰大叔
下一篇︰今日搖一搖今日搖一搖
[發帖際遇]: esdion 發帖時在路邊撿到 1 金錢,偷偷放進了口袋. 幸運榜 / 衰神榜
您需要登錄後才可以回帖 登錄 | 註冊會員

本版積分規則

天堂私服列表

45客服

Archiver| 45天堂私服論壇   分享到微博! 分享到臉書! 分享到噗浪! 分享到維特! 分享到Google+! 分享到LINE!

45天堂私服發佈站 ©    天堂私服架設教學  提供最新天堂私服最新資訊

流量最高、品質最好、服務最優、玩家首選、最新天堂私服資訊,都在45天堂私服發佈站.    免責聲明

Sitetag
line客服聯繫
掃一掃二碼
Line客服聯繫
24H專人回覆
返回頂部 返回列表