• 个人简介

    #include <iostream>
    #include <string>
    #include <cstdlib>
    #include <ctime>
    #include <cmath>
    #include <sstream>
    #include <algorithm>
    #include <vector>
    #include <windows.h>  // Windows 系统休眠函数头文件
    using namespace std;
    
    // 工具函数:整数转字符串
    string intToString(int num) {
        stringstream ss;
        ss << num;
        return ss.str();
    }
    
    // 枚举类型定义
    enum SpiritRoot { WASTE, LOW, MIDDLE, HIGH, HEAVENLY };
    enum SpecialBody { DOUBLE_PUPIL, GREAT_WASTE, MORTAL_BODY }; // 删除了NONE,只保留三种体质
    enum Realm { QI_TRAINING, FOUNDATION, GOLDEN_CORE, YUAN_YING, SPIRIT_TRANSFORMATION, REALM_COUNT };
    enum Profession { SWORD_CULTIVATOR, ALCHEMIST };
    enum Material { BLOOD_LING_GRASS, DRAGON_BLOOD_CRYSTAL, LIFE_FLOWER, IRON_ORE, MATERIAL_COUNT };
    
    // 工具函数声明
    string getRealmName(Realm realm);
    string getSpiritRootName(SpiritRoot root);
    string getSpecialBodyName(SpecialBody body);
    string getProfessionName(Profession prof);
    string getMaterialName(Material mat);
    
    class Player {
    private:
        // 基础属性
        SpiritRoot spiritRoot;
        SpecialBody specialBody;
        Realm realm = QI_TRAINING;
        Profession profession;
        int spirit, maxSpirit;
        int qi, maxQi;
        int health, maxHealth;
        int attack, baseAttack;
        int defense, baseDefense;
        double critRate, baseCritRate;
        double critDamage, baseCritDamage;
        
        // 历练相关属性
        int divineWeaponShards = 0;
        bool hasDevouringSkill = false;
        int weaponPower = 0;
        
        // 状态buff
        int bipolarSealTurns = 0;
        double atkBuff = 0, defBuff = 0, allAttrBuff = 0;
    
        // 剑修专属属性
        int swordIntent = 0;
        int swordLevel = 0;
        vector<int> swordIntentReq;
        int swordQuenchCount = 0;
        double swordQuenchSuccessRate = 0.8;
        int swordRealm = 1;
    
        // 丹修专属属性
        int alchemyProficiency = 0;
        int bloodPill = 0, bloodBurnPill = 2, healingPill = 10;
        int bloodPillUsed = 0;
        int materials[MATERIAL_COUNT] = {0};
        int alchemyRealm = 1;
        bool hasHunyuanScripture = false;  // 是否获得《混元丹道真经》
        double hunyuanBonus = 1.0;         // 混元丹道真经带来的熟练度加成倍数
    
        // 初始化剑术所需剑意
        void initSwordIntentReq() {
            swordIntentReq.resize(100);
            swordIntentReq[0] = 100;
            for (int i = 1; i < 100; i++) {
                swordIntentReq[i] = (int)(swordIntentReq[i - 1] * 1.5);
            }
        }
    
        // 随机生成灵根
        SpiritRoot generateSpiritRoot() {
            int randVal = rand() % 100;
            if (randVal < 20) return WASTE;
            else if (randVal < 50) return LOW;
            else if (randVal < 75) return MIDDLE;
            else if (randVal < 90) return HIGH;
            else return HEAVENLY;
        }
    
        // 随机生成体质(删除无特殊体质,调整概率为:凡体50%,重瞳25%,大荒体25%)
        SpecialBody generateSpecialBody() {
            int randVal = rand() % 100;
            if (randVal < 50) return MORTAL_BODY;    // 凡体:50%
            else if (randVal < 75) return DOUBLE_PUPIL;// 重瞳:25%
            else return GREAT_WASTE;                  // 大荒体:25%
        }
    
        // 应用buff效果
        void applyBuffs() {
            attack = baseAttack + weaponPower;
            defense = baseDefense;
            critRate = baseCritRate;
            critDamage = baseCritDamage;
    
            // 应用混元丹道真经的全属性加成
            if (profession == ALCHEMIST && hasHunyuanScripture) {
                double bonus = alchemyRealm * 0.01;
                attack = (int)(attack * (1 + bonus));
                defense = (int)(defense * (1 + bonus));
                critRate *= (1 + bonus);
                critDamage *= (1 + bonus);
            }
    
            if (bipolarSealTurns > 0) {
                attack = (int)(attack * (1 + allAttrBuff));
                defense = (int)(defense * (1 + defBuff));
                critRate *= (1 + allAttrBuff);
                critDamage *= (1 + allAttrBuff);
                cout << "\n双极守印生效中(剩余" << bipolarSealTurns << "回合):全属性提升" 
                     << allAttrBuff * 100 << "%,防御额外提升" << (defBuff - allAttrBuff) * 100 << "%" << endl;
                bipolarSealTurns--;
            }
        }
    
        // 更新武器威力
        void updateWeaponPower() {
            weaponPower = divineWeaponShards / 10;
        }
    
        // 设置初始属性
        void setBaseAttributes() {
            // 基础属性初始化
            maxHealth = 1000;
            health = maxHealth;
            baseAttack = 100;
            baseDefense = 20;
            baseCritRate = 0.1;
            baseCritDamage = 1.5;
            maxSpirit = 500;
            spirit = maxSpirit;
            maxQi = 1000;
            qi = 0;
    
            // 灵根和体质生成
            spiritRoot = generateSpiritRoot();
            specialBody = generateSpecialBody();
            applyRootAndBodyBonus(); // 应用加成
    
            // 职业初始化
            if (profession == SWORD_CULTIVATOR) {
                initSwordIntentReq();
            }
    
            // 显示初始信息
            cout << "觉醒灵根:" << getSpiritRootName(spiritRoot) << endl;
            cout << "觉醒体质:" << getSpecialBodyName(specialBody) << endl;
            if (specialBody == DOUBLE_PUPIL) {
                cout << "【重瞳】效果:突破成功率+25%(上限90%),雷劫伤害-30%,攻击+40%,暴击率+30%,暴击伤害+20%,5%概率秒杀,解锁「眸光轰击」" << endl;
            } else if (specialBody == GREAT_WASTE) {
                cout << "【大荒体】效果:突破必成(需2倍灵气),生命+30%,防御+20%,解锁「双极守印」" << endl;
            } else if (specialBody == MORTAL_BODY) {
                cout << "【凡体】效果:无特殊加成,大道至简,全凭苦修" << endl;
            }
        }
    
        // 灵根和体质加成
        void applyRootAndBodyBonus() {
            // 灵根加成
            switch (spiritRoot) {
                case HIGH: baseAttack += 20; baseDefense += 10; break;
                case HEAVENLY: baseAttack += 50; baseDefense += 30; maxSpirit += 200; maxQi += 300; break;
                case MIDDLE: baseAttack += 10; baseDefense += 5; break;
                default: break;
            }
    
            // 体质加成
            if (specialBody == DOUBLE_PUPIL) {
                baseAttack = (int)(baseAttack * 1.4);
                baseCritRate += 0.3;
                baseCritDamage += 0.2;
            } else if (specialBody == GREAT_WASTE) {
                maxHealth = (int)(maxHealth * 1.3);
                baseDefense = (int)(baseDefense * 1.2);
            }
            // 凡体无加成,不做处理
        }
    
        // 通用攻击逻辑
        bool attackTarget(int& targetHealth, int targetAttack, bool isBloodBurnActive, string targetName) {
            applyBuffs();
            int damage = attack;
            bool isCrit = (rand() % 100) < (critRate * 100);
    
            // 重瞳秒杀
            if (specialBody == DOUBLE_PUPIL && rand() % 100 < 5) {
                cout << "你的重瞳一闪,重瞳之力发动!直接秒杀" << targetName << "!" << endl;
                targetHealth = 0;
                return true;
            }
    
            // 暴击和燃血丹效果
            if (isCrit) { damage = (int)(damage * critDamage); cout << "暴击!"; }
            if (isBloodBurnActive) { damage = (int)(damage * 1.5); cout << "燃血丹效果激活,伤害+50%!"; }
    
            // 伤害计算
            targetHealth -= damage;
            cout << "对" << targetName << "造成" << damage << "点伤害!剩余生命:" << max(0, targetHealth) << endl;
            if (targetHealth <= 0) return true;
    
            // 目标反击
            int targetDamage = max(1, targetAttack - defense / 2);
            health -= targetDamage;
            cout << targetName << "对你造成" << targetDamage << "点伤害!你的剩余生命:" << max(0, health) << endl;
            return health > 0;
        }
    
        // 剑气攻击
        bool swordQiAttack(int& targetHealth, int targetAttack, string targetName) {
            const int SPIRIT_COST = 100;
            if (spirit < SPIRIT_COST) {
                cout << "灵力不足!需要" << SPIRIT_COST << "点,当前:" << spirit << endl;
                return false;
            }
            spirit -= SPIRIT_COST;
            cout << "消耗" << SPIRIT_COST << "灵力发动剑气攻击!剩余灵力:" << spirit << endl;
    
            int damage = (int)(attack * 1.5);
            bool isCrit = (rand() % 100) < (critRate * 100);
            if (isCrit) { damage = (int)(damage * critDamage); cout << "剑气暴击!"; }
    
            targetHealth -= damage;
            cout << "剑气对" << targetName << "造成" << damage << "点伤害!剩余生命:" << max(0, targetHealth) << endl;
            if (targetHealth <= 0) return true;
    
            // 目标反击
            int targetDamage = max(1, targetAttack - defense / 2);
            health -= targetDamage;
            cout << targetName << "对你造成" << targetDamage << "点伤害!你的剩余生命:" << max(0, health) << endl;
            return health > 0;
        }
    
        // 重瞳技能:眸光轰击
        bool pupilBlast(int& targetHealth, int targetAttack, string targetName) {
            const double COST_RATE = 0.1;
            int cost = (int)(maxSpirit * COST_RATE);
            if (spirit < cost) {
                cout << "灵力不足!需要" << cost << "点(最大灵力10%),当前:" << spirit << endl;
                return false;
            }
            spirit -= cost;
            cout << "消耗" << cost << "灵力发动「眸光轰击」!" << endl;
    
            int damage = attack * 3; // 无视防御
            targetHealth -= damage;
            cout << "眸光对" << targetName << "造成" << damage << "点伤害!剩余生命:" << max(0, targetHealth) << endl;
            if (targetHealth <= 0) return true;
    
            // 目标反击
            int targetDamage = max(1, targetAttack - defense / 2);
            health -= targetDamage;
            cout << targetName << "对你造成" << targetDamage << "点伤害!你的剩余生命:" << max(0, health) << endl;
            return health > 0;
        }
    
        // 大荒体技能:双极守印
        bool bipolarSeal() {
            const double COST_RATE = 0.2;
            int cost = (int)(maxSpirit * COST_RATE);
            if (spirit < cost) {
                cout << "灵力不足!需要" << cost << "点(最大灵力20%),当前:" << spirit << endl;
                return false;
            }
            spirit -= cost;
            bipolarSealTurns = 3; // 持续3回合
            allAttrBuff = 0.2;
            defBuff = 0.4;
            cout << "发动「双极守印」!3回合内全属性+20%,防御额外+40%!" << endl;
            return true;
        }
    
        // 逃跑逻辑
        bool attemptEscape(int targetLevel, string targetName) {
            applyBuffs();
            int playerRealm = (int)realm;
            int targetRealm = min(playerRealm + 1, 4);
            int escapeRate = (targetRealm < playerRealm) ? 80 : (targetRealm == playerRealm ? 50 : 10);
    
            cout << "尝试逃离" << targetName << ",成功率:" << escapeRate << "%" << endl;
            if (rand() % 100 < escapeRate) {
                cout << "成功逃脱!" << endl;
                return true;
            } else {
                cout << "逃跑失败,被反击!" << endl;
                int targetDamage = max(1, (targetLevel * 100) - defense / 2);
                health -= targetDamage;
                cout << targetName << "对你造成" << targetDamage << "点伤害!剩余生命:" << max(0, health) << endl;
                return health > 0;
            }
        }
    
        // 邪修战斗
        bool fightEvilCultivator() {
            int evilLevel = (int)realm + 1;
            int evilHealth = 600 * evilLevel;
            int evilAttack = 120 * evilLevel;
            cout << "\n遭遇" << getRealmName((Realm)(min((int)realm + 1, 4))) << "期邪修!生命:" << evilHealth << ",攻击:" << evilAttack << endl;
    
            bool isBloodBurnActive = false;
            int battleBurnCount = 0;
            while (true) {
                applyBuffs();
                if (!handleBattleChoice(evilHealth, evilAttack, isBloodBurnActive, battleBurnCount, "邪修")) {
                    return false;
                }
                if (evilHealth <= 0) break;
            }
    
            // 战斗奖励
            int shardsGained = 2 + rand() % 3;
            divineWeaponShards += shardsGained;
            updateWeaponPower();
            cout << "击杀邪修!获得" << shardsGained << "个神兵碎片(总计:" << divineWeaponShards << ")" << endl;
    
            int spiritReward = 60 + rand() % 40;
            int qiReward = 120 + rand() % 60;
            spirit = min(spirit + spiritReward, maxSpirit);
            qi = min(qi + qiReward, maxQi * (specialBody == GREAT_WASTE ? 2 : 1));
            cout << "获得" << spiritReward << "灵力(" << spirit << "/" << maxSpirit << ")," << qiReward << "灵气(" << qi << "/" 
                 << (specialBody == GREAT_WASTE ? maxQi * 2 : maxQi) << ")" << endl;
            return true;
        }
    
        // 统一处理战斗选项
        bool handleBattleChoice(int& targetHealth, int targetAttack, bool& isBloodBurnActive, int& battleBurnCount, string targetName) {
            if (profession == SWORD_CULTIVATOR) {
                cout << "\n剑修选项:1.普通攻击 2.剑气攻击 3.逃跑";
                if (specialBody == DOUBLE_PUPIL) cout << " 4.眸光轰击";
                else if (specialBody == GREAT_WASTE) cout << " 4.双极守印";
                cout << "(灵力:" << spirit << ")" << endl;
                int choice; cin >> choice;
    
                switch (choice) {
                    case 1: return attackTarget(targetHealth, targetAttack, isBloodBurnActive, targetName);
                    case 2: return swordQiAttack(targetHealth, targetAttack, targetName);
                    case 3: return attemptEscape((int)realm + 1, targetName);
                    case 4: 
                        if (specialBody == DOUBLE_PUPIL) return pupilBlast(targetHealth, targetAttack, targetName);
                        else if (specialBody == GREAT_WASTE) return bipolarSeal();
                    default: 
                        cout << "无效选择,默认普通攻击!" << endl;
                        return attackTarget(targetHealth, targetAttack, isBloodBurnActive, targetName);
                }
            } else {
                cout << "\n丹修选项:1.攻击 2.燃血丹(" << bloodBurnPill << ") 3.回春丹(" << healingPill << ") 4.逃跑";
                if (specialBody == DOUBLE_PUPIL) cout << " 5.眸光轰击";
                else if (specialBody == GREAT_WASTE) cout << " 5.双极守印";
                cout << "(灵力:" << spirit << ")" << endl;
                int choice; cin >> choice;
    
                switch (choice) {
                    case 1: return attackTarget(targetHealth, targetAttack, isBloodBurnActive, targetName);
                    case 2: isBloodBurnActive = useBloodBurnPill(battleBurnCount); return true;
                    case 3: {
                        int num; cout << "使用回春丹数量:"; cin >> num;
                        for (int i = 0; i < num; i++) useHealingPill();
                        return true;
                    }
                    case 4: return attemptEscape((int)realm + 1, targetName);
                    case 5: 
                        if (specialBody == DOUBLE_PUPIL) return pupilBlast(targetHealth, targetAttack, targetName);
                        else if (specialBody == GREAT_WASTE) return bipolarSeal();
                    default: 
                        cout << "无效选择,默认普通攻击!" << endl;
                        return attackTarget(targetHealth, targetAttack, isBloodBurnActive, targetName);
                }
            }
        }
    
        // 仙人梦中传道剧情
        void immortalDreamTeaching() {
            cout << "\n*** 异象发生!你在修炼中进入深层冥想,梦中见到一位仙风道骨的老者 ***" << endl;
            
            if (!hasHunyuanScripture) {
                // 第一次触发,获得《混元丹道真经》
                hasHunyuanScripture = true;
                hunyuanBonus = 1.5;  // 熟练度获得提升50%
                cout << "老者传授你《混元丹道真经》!" << endl;
                cout << "【混元丹道真经】效果:" << endl;
                cout << "- 炼丹获得的熟练度提升50%" << endl;
                cout << "- 丹药效果提升20%" << endl;
                cout << "- 获得当前丹道境界层数×1%的全属性加成" << endl;
            } else {
                // 后续触发,提升丹道境界
                cout << "老者对你的丹道见解表示赞赏,亲自指点你的丹道瓶颈!" << endl;
                int oldRealm = alchemyRealm;
                
                // 直接提升丹道境界,有小概率连升两级
                alchemyRealm += (rand() % 100 < 20) ? 2 : 1;
                cout << "丹道境界从" << oldRealm << "品提升至" << alchemyRealm << "品!" << endl;
            }
            
            // 梦境奖励
            int qiBonus = 200 + rand() % 100;
            qi = min(qi + qiBonus, maxQi * (specialBody == GREAT_WASTE ? 2 : 1));
            cout << "从梦境中醒来,感悟良多,获得" << qiBonus << "点灵气!" << endl;
        }
    
    public:
        Player(Profession prof) : profession(prof) {
            setBaseAttributes();
        }
    
        ~Player() = default;
    
        // 基础 getter
        Profession getProfession() const { return profession; }
        bool isDead() const { return health <= 0; }
    
        // 丹修:使用燃血丹
        bool useBloodBurnPill(int& battleBurnCount) {
            if (profession == SWORD_CULTIVATOR || bloodBurnPill <= 0 || battleBurnCount >= 3) {
                cout << (profession == SWORD_CULTIVATOR ? "剑修无法使用燃血丹!" : 
                       (bloodBurnPill <= 0 ? "无燃血丹!" : "燃血丹使用达上限!")) << endl;
                return false;
            }
            bloodBurnPill--;
            battleBurnCount++;
            health = max(1, (int)(health * 0.7));
            
            // 应用混元丹道真经的丹药效果加成
            double damageMultiplier = hasHunyuanScripture ? 1.7 : 1.5;
            cout << "使用燃血丹,燃烧30%生命提升攻击!" << (hasHunyuanScripture ? "(混元丹道加成,伤害+70%)" : "(伤害+50%)") << endl;
            return true;
        }
    
        // 丹修:使用回春丹
        void useHealingPill() {
            if (profession == SWORD_CULTIVATOR) {
                cout << "剑修无法使用回春丹!" << endl;
                return;
            }
            if (healingPill <= 0) {
                cout << "无回春丹!" << endl;
                return;
            }
            healingPill--;
            
            // 应用混元丹道真经的丹药效果加成
            int baseHeal = 100 * alchemyRealm;
            int actualHeal = hasHunyuanScripture ? (int)(baseHeal * 1.2) : baseHeal;
            health = min(health + actualHeal, maxHealth);
            cout << "使用回春丹,恢复" << actualHeal << "生命!当前:" << health 
                 << (hasHunyuanScripture ? "(混元丹道加成,效果提升20%)" : "") << endl;
        }
    
        // 剑修:练剑
        void practiceSword() {
            if (profession != SWORD_CULTIVATOR) return;
    
            int baseGain = 20;
            double realmBonus = 1 + (int)realm * 0.2;
            int gain = (int)(baseGain * realmBonus) + rand() % (int)(baseGain * realmBonus);
            swordIntent += gain;
            cout << "练剑获得" << gain << "剑意!当前:" << swordIntent << endl;
    
            while (swordLevel < 100 && swordIntent >= swordIntentReq[swordLevel]) {
                swordIntent -= swordIntentReq[swordLevel];
                swordLevel++;
                if (swordLevel <= 15) {
                    baseAttack += 1;
                    attack = baseAttack + weaponPower;
                    cout << "剑术" << swordLevel << "层!攻击+1(当前:" << attack << ")" << endl;
                } else {
                    baseAttack += 100;
                    baseCritRate = min(baseCritRate + 0.05, 1.0);
                    baseCritDamage = min(baseCritDamage + 0.01, 2.0);
                    attack = baseAttack + weaponPower;
                    critRate = baseCritRate;
                    critDamage = baseCritDamage;
                    cout << "剑术" << swordLevel << "层!攻击+100,暴击率+" << 5 << "%,暴击伤害+" << 1 << "%" << endl;
                }
                // 剑道境界突破
                if (swordLevel >= swordRealm * 2) {
                    if (rand() % 100 < 70) {
                        swordRealm++;
                        baseAttack = (int)(baseAttack * 1.02);
                        baseDefense = (int)(baseDefense * 1.02);
                        baseCritRate = min(baseCritRate + 0.02, 1.0);
                        baseCritDamage = min(baseCritDamage + 0.02, 2.0);
                        attack = baseAttack + weaponPower;
                        defense = baseDefense;
                        cout << "剑道" << swordRealm << "重!全属性+2%!" << endl;
                    } else {
                        swordLevel--;
                        cout << "剑道突破失败,剑术降1级!" << endl;
                    }
                }
            }
        }
    
        // 剑修:淬炼长剑
        void quenchSword() {
            if (profession != SWORD_CULTIVATOR || materials[IRON_ORE] == 0) {
                cout << (profession != SWORD_CULTIVATOR ? "非剑修无法淬炼!" : "无玄铁!") << endl;
                return;
            }
            cout << "淬炼长剑(成功率:" << swordQuenchSuccessRate * 100 << "%)" << endl;
            if (rand() % 100 < swordQuenchSuccessRate * 100) {
                baseAttack = (int)(baseAttack * 1.01);
                attack = baseAttack + weaponPower;
                cout << "淬炼成功!攻击提升至" << attack << endl;
            } else {
                cout << "淬炼失败!" << endl;
            }
            swordQuenchSuccessRate = max(0.2, swordQuenchSuccessRate - 0.05);
            materials[IRON_ORE]--;
        }
    
        // 丹修:炼丹
        void refinePill(int pillType) {
            if (profession != ALCHEMIST) return;
    
            struct PillInfo { string name; int req[MATERIAL_COUNT]; double baseRate; };
            PillInfo pills[] = {
                {"气血丹", {0, 2, 0, 0}, 0.3},   // 龙血晶x2
                {"燃血丹", {1, 0, 0, 0}, 0.2},   // 血灵草x1
                {"回春丹", {0, 0, 3, 0}, 0.7}    // 生命之花x3
            };
            if (pillType < 1 || pillType > 3) {
                cout << "无效丹药类型!" << endl;
                return;
            }
            PillInfo& pill = pills[pillType - 1];
    
            // 检查材料
            for (int i = 0; i < MATERIAL_COUNT; i++) {
                if (materials[i] < pill.req[i]) {
                    cout << "材料不足:" << getMaterialName((Material)i) << "(需" << pill.req[i] << ",当前" << materials[i] << ")" << endl;
                    return;
                }
            }
            // 消耗材料
            for (int i = 0; i < MATERIAL_COUNT; i++) materials[i] -= pill.req[i];
    
            // 炼丹成功率
            double finalRate = min(pill.baseRate + alchemyProficiency / 1000.0, 0.9);
            cout << "炼制" << pill.name << "(成功率:" << finalRate * 100 << "%)..." << endl;
    
            if (rand() % 100 < finalRate * 100) {
                cout << "炼丹成功!获得1枚" << pill.name << "!" << endl;
                if (pillType == 1) bloodPill++;
                else if (pillType == 2) bloodBurnPill++;
                else healingPill++;
                if (pillType == 1 || pillType == 3) {
                    // 应用混元丹道真经的丹药效果加成
                    int baseHeal = 100 * alchemyRealm;
                    int actualHeal = hasHunyuanScripture ? (int)(baseHeal * 1.2) : baseHeal;
                    health = min(health + actualHeal, maxHealth);
                    cout << "获得" << actualHeal << "点生命恢复!" << (hasHunyuanScripture ? "(混元丹道加成)" : "") << endl;
                }
            } else {
                cout << "炼丹失败,材料已消耗!" << endl;
            }
    
            // 熟练度和丹道境界(应用混元丹道真经的熟练度加成)
            int proficiencyGain = hasHunyuanScripture ? 8 : 5;  // 基础5点,加成后8点
            alchemyProficiency = min(alchemyProficiency + proficiencyGain, 300);
            cout << "熟练度:" << alchemyProficiency << "(加成" << alchemyProficiency / 10 << "%" 
                 << (hasHunyuanScripture ? ",混元丹道加成" : "") << ")" << endl;
            if (alchemyProficiency >= alchemyRealm * 100) {
                if (rand() % 100 < 50) {
                    alchemyRealm++;
                    cout << "丹道" << alchemyRealm << "品!" << endl;
                } else {
                    alchemyProficiency = max(alchemyProficiency - (int)(alchemyProficiency * 0.1), 0);
                    cout << "丹道突破失败,熟练度-10%!" << endl;
                }
            }
        }
    
        // 丹修:查看丹方
        void viewDanFang() {
            if (profession != ALCHEMIST) return;
            cout << "气血丹:龙血晶x2\n燃血丹:血灵草x1\n回春丹:生命之花x3" << endl;
        }
    
        // 修炼
        void cultivate() {
            int baseSpiritGain = 30, baseQiGain = 50;
            if (hasDevouringSkill) {
                baseQiGain = (int)(baseQiGain * 1.5);
                cout << "吞天魔功:灵气吸收+50%!" << endl;
            }
    
            int spiritGain = baseSpiritGain + rand() % (baseSpiritGain / 2);
            int qiGain = baseQiGain + rand() % (baseQiGain / 2);
            int healthRecover = 50 + (int)realm * 20;
            health = min(health + healthRecover, maxHealth);
    
            spirit = min(spirit + spiritGain, maxSpirit);
            qi = min(qi + qiGain, maxQi * (specialBody == GREAT_WASTE ? 2 : 1));
    
            cout << "修炼恢复" << healthRecover << "生命(" << health << "/" << maxHealth << ")" << endl;
            cout << "获得" << spiritGain << "灵力(" << spirit << "/" << maxSpirit << ")," << qiGain << "灵气(" << qi << "/" 
                 << (specialBody == GREAT_WASTE ? maxQi * 2 : maxQi) << ")" << endl;
    
            // 丹修有15%概率触发仙人梦中传道剧情
            if (profession == ALCHEMIST && rand() % 100 < 15) {
                immortalDreamTeaching();
            }
        }
    
        // 战斗(妖兽)
        bool fightMonster() {
            int monsterLevel = (int)realm + 1;
            int monsterHealth = 500 * monsterLevel;
            int monsterAttack = 100 * monsterLevel;
            cout << "\n遭遇" << getRealmName((Realm)(min((int)realm + 1, 4))) << "期妖兽!生命:" << monsterHealth << ",攻击:" << monsterAttack << endl;
    
            bool isBloodBurnActive = false;
            int battleBurnCount = 0;
            while (true) {
                applyBuffs();
                if (!handleBattleChoice(monsterHealth, monsterAttack, isBloodBurnActive, battleBurnCount, "妖兽")) {
                    return false;
                }
                if (monsterHealth <= 0) break;
            }
    
            // 战斗奖励
            cout << "击杀妖兽!" << endl;
            int dropCount = 1 + rand() % 2;
            for (int i = 0; i < dropCount; i++) {
                if (profession == ALCHEMIST) {
                    Material mat = (Material)(rand() % (MATERIAL_COUNT - 1));
                    int num = 1 + rand() % 3;
                    materials[mat] += num;
                    cout << "获得" << num << "个" << getMaterialName(mat) << endl;
                } else {
                    int iron = 1 + rand() % 3;
                    materials[IRON_ORE] += iron;
                    cout << "获得" << iron << "个玄铁" << endl;
                }
            }
    
            int spiritReward = 50 + rand() % 30;
            int qiReward = 100 + rand() % 50;
            spirit = min(spirit + spiritReward, maxSpirit);
            qi = min(qi + qiReward, maxQi * (specialBody == GREAT_WASTE ? 2 : 1));
            cout << "获得" << spiritReward << "灵力(" << spirit << "/" << maxSpirit << ")," << qiReward << "灵气(" << qi << "/" 
                 << (specialBody == GREAT_WASTE ? maxQi * 2 : maxQi) << ")" << endl;
            return true;
        }
    
        // 历练功能
        void venture() {
            cout << "\n外出历练..." << endl;
            int randEvent = rand() % 100;
    
            if (randEvent < 25) { // 神秘老者
                int qiGain = (int)(maxQi * 0.02);
                qi = min(qi + qiGain, maxQi * (specialBody == GREAT_WASTE ? 2 : 1));
                cout << "遇神秘老者传授技巧!获得" << qiGain << "灵气(" << qi << "/" 
                     << (specialBody == GREAT_WASTE ? maxQi * 2 : maxQi) << ")" << endl;
            } else if (randEvent < 50) { // 邪修
                fightEvilCultivator();
            } else if (randEvent < 75) { // 上古秘境
                if (realm >= GOLDEN_CORE) {
                    cout << "发现上古秘境!" << endl;
                    int event = rand() % 100;
                    if (event < 60) {
                        int shards = 3 + rand() % 3;
                        divineWeaponShards += shards;
                        updateWeaponPower();
                        cout << "获得" << shards << "神兵碎片(总计:" << divineWeaponShards << ")" << endl;
                    } else if (event < 70 && !hasDevouringSkill) {
                        hasDevouringSkill = true;
                        cout << "获得《吞天魔功》!灵气吸收大幅提升!" << endl;
                    } else {
                        int loss = maxHealth / 3 + rand() % (maxHealth / 3);
                        health = max(1, health - loss);
                        spirit = 0;
                        cout << "触发禁制!受" << loss << "伤害(剩余:" << health << "),灵力耗尽!" << endl;
                    }
                } else {
                    cout << "感知到秘境,但修为不足(需金丹及以上)!" << endl;
                    // 改为发现材料
                    int matCount = 1 + rand() % 2;
                    for (int i = 0; i < matCount; i++) {
                        if (profession == SWORD_CULTIVATOR) {
                            int iron = 2 + rand() % 3;
                            materials[IRON_ORE] += iron;
                            cout << "发现" << iron << "个玄铁" << endl;
                        } else {
                            Material mat = (Material)(rand() % (MATERIAL_COUNT - 1));
                            int num = 2 + rand() % 3;
                            materials[mat] += num;
                            cout << "发现" << num << "个" << getMaterialName(mat) << endl;
                        }
                    }
                }
            } else { // 稀有材料
                cout << "发现稀有材料!" << endl;
                int matCount = 1 + rand() % 2;
                for (int i = 0; i < matCount; i++) {
                    if (profession == SWORD_CULTIVATOR) {
                        int iron = 2 + rand() % 3;
                        materials[IRON_ORE] += iron;
                        cout << "获得" << iron << "个玄铁(当前:" << materials[IRON_ORE] << ")" << endl;
                    } else {
                        Material mat = (Material)(rand() % (MATERIAL_COUNT - 1));
                        int num = 2 + rand() % 3;
                        materials[mat] += num;
                        cout << "获得" << num << "个" << getMaterialName(mat) << "(当前:" << materials[mat] << ")" << endl;
                    }
                }
            }
        }
    
        // 尝试突破境界
        bool attemptBreakthrough() {
            int requiredQi = (specialBody == GREAT_WASTE) ? maxQi * 2 : maxQi;
            if (qi < requiredQi) {
                cout << "灵气不足!当前:" << qi << "/" << requiredQi << endl;
                return false;
            }
            if (realm >= SPIRIT_TRANSFORMATION) {
                cout << "已达最高境界!" << endl;
                return false;
            }
    
            cout << "\n突破" << getRealmName((Realm)(realm + 1)) << "期!九天雷劫降临!" << endl;
            int baseSuccessRate = max(30, 80 - (int)realm * 10);
            int successRate = (specialBody == DOUBLE_PUPIL) ? min(90, baseSuccessRate + 25) : baseSuccessRate;
            cout << "突破成功率:" << successRate << "%" << endl;
    
            int remainingQi = qi;
            bool success = true;
    
            if (specialBody != GREAT_WASTE) { // 非大荒体需渡雷劫
                for (int i = 1; i <= 9; i++) {
                    cout << "\n第" << i << "道雷劫降临!";
                    Sleep(1000);  // 休眠1秒
                    
                    int lightningDamage = 30 + rand() % 120 + (int)realm * 30;
                    if (specialBody == DOUBLE_PUPIL) {
                        int reduced = (int)(lightningDamage * 0.7);
                        cout << "重瞳减免30%伤害(" << lightningDamage << "→" << reduced << ")" << endl;
                        lightningDamage = reduced;
                    } else {
                        cout << "伤害:" << lightningDamage << endl;
                    }
    
                    if (remainingQi >= lightningDamage) {
                        remainingQi -= lightningDamage;
                        cout << "消耗" << lightningDamage << "灵气抵御!剩余:" << remainingQi << endl;
                    } else {
                        cout << "第" << i << "道雷劫未抵御!灵气耗尽!" << endl;
                        success = false;
                        for (int j = i + 1; j <= 9; j++) cout << "第" << j << "道雷劫直接击中!" << endl;
                        break;
                    }
    
                    // 每道雷劫失败概率
                    int failChance = (specialBody == DOUBLE_PUPIL) ? (int)((100.0 - successRate) / 12) : (int)((100.0 - successRate) / 9);
                    if (rand() % 100 < failChance) {
                        cout << "第" << i << "道雷劫后灵气溃散,突破失败!" << endl;
                        success = false;
                        break;
                    }
                }
            }
    
            // 突破结果
            if (success && (specialBody == GREAT_WASTE || rand() % 100 < successRate)) {
                realm = (Realm)(realm + 1);
                maxQi = (int)(maxQi * 1.5);
                maxSpirit = (int)(maxSpirit * 1.2);
                qi = 0;
                spirit = maxSpirit;
                maxHealth = (int)(maxHealth * 1.2);
                health = maxHealth;
                baseAttack = (int)(baseAttack * 1.2);
                baseDefense = (int)(baseDefense * 1.2);
                attack = baseAttack + weaponPower;
                defense = baseDefense;
    
                cout << "\n突破成功!当前境界:" << getRealmName(realm) << endl;
                cout << "属性提升:灵气上限" << maxQi << "(突破需" << (specialBody == GREAT_WASTE ? maxQi * 2 : maxQi) 
                     << "),灵力上限" << maxSpirit << endl;
                return true;
            } else {
                // 失败惩罚:无境界倒退,失去50%最大生命和全部灵气
                qi = 0;
                spirit = max(1, spirit / 2);
                health = max(1, maxHealth / 2);
                cout << "\n突破失败!灵气耗尽,生命剩余" << health << endl;
                if (health <= 0) cout << "突破失败,不幸陨落!" << endl;
                return false;
            }
        }
    
        // 查看状态
        void viewStatus() {
            applyBuffs();
            cout << "\n=== 状态 ===" << endl;
            cout << "职业:" << getProfessionName(profession) << "  境界:" << getRealmName(realm) << endl;
            cout << "灵根:" << getSpiritRootName(spiritRoot) << "  体质:" << getSpecialBodyName(specialBody) << endl;
            cout << "生命:" << health << "/" << maxHealth << "  灵力:" << spirit << "/" << maxSpirit << endl;
            cout << "灵气:" << qi << "/" << (specialBody == GREAT_WASTE ? maxQi * 2 : maxQi) << endl;
            cout << "攻击:" << attack << "(基础:" << baseAttack << " + 武器:" << weaponPower << ")  防御:" << defense << endl;
            cout << "暴击率:" << critRate * 100 << "%  暴击伤害:" << critDamage * 100 << "%" << endl;
            cout << "神兵碎片:" << divineWeaponShards << "  功法:" << (hasDevouringSkill ? "有吞天魔功" : "无") << endl;
            if (profession == ALCHEMIST && hasHunyuanScripture) {
                cout << "丹道功法:《混元丹道真经》(全属性+" << alchemyRealm * 1 << "%)" << endl;
            }
            if (bipolarSealTurns > 0) cout << "状态:双极守印(剩余" << bipolarSealTurns << "回合)" << endl;
    
            if (profession == SWORD_CULTIVATOR) {
                cout << "剑道" << swordRealm << "重  剑术" << swordLevel << "层  剑意:" << swordIntent << "/" 
                     << (swordLevel < 100 ? intToString(swordIntentReq[swordLevel]) : "MAX") << endl;
                cout << "玄铁:" << materials[IRON_ORE] << endl;
            } else {
                cout << "丹道" << alchemyRealm << "品  熟练度:" << alchemyProficiency << (hasHunyuanScripture ? "(混元加成)" : "") << endl;
                cout << "气血丹:" << bloodPill << "  燃血丹:" << bloodBurnPill << "  回春丹:" << healingPill << endl;
                cout << "材料:血灵草" << materials[BLOOD_LING_GRASS] << "  龙血晶" << materials[DRAGON_BLOOD_CRYSTAL] 
                     << "  生命之花" << materials[LIFE_FLOWER] << endl;
            }
            cout << "==========\n" << endl;
        }
    
        // 检查是否可突破
        bool canBreakthrough() {
            int requiredQi = (specialBody == GREAT_WASTE) ? maxQi * 2 : maxQi;
            return qi >= requiredQi && realm < SPIRIT_TRANSFORMATION;
        }
    };
    
    // 工具函数实现
    string getRealmName(Realm realm) {
        const string names[] = {"练气", "筑基", "金丹", "元婴", "化神"};
        return names[realm];
    }
    
    string getSpiritRootName(SpiritRoot root) {
        const string names[] = {"废灵根", "下品灵根", "中品灵根", "上品灵根", "天灵根"};
        return names[root];
    }
    
    string getSpecialBodyName(SpecialBody body) {
        const string names[] = {"重瞳", "大荒体", "凡体"}; // 更新体质名称列表
        return names[body];
    }
    
    string getProfessionName(Profession prof) {
        return prof == SWORD_CULTIVATOR ? "剑修" : "丹修";
    }
    
    string getMaterialName(Material mat) {
        const string names[] = {"血灵草", "龙血晶", "生命之花", "玄铁"};
        return names[mat];
    }
    
    int main() {
        srand(time(0));
        cout << "欢迎来到修仙世界!" << endl;
        cout << "觉醒灵根和体质中..." << endl;
        cout << "选择职业:1.剑修 2.丹修" << endl;
        int choice; cin >> choice;
    
        Player* player = new Player(choice == 1 ? SWORD_CULTIVATOR : ALCHEMIST);
        cout << "你选择成为" << getProfessionName(player->getProfession()) << "!" << endl;
    
        while (true) {
            if (player->isDead()) {
                cout << "\n生命气息消散,修仙之路终结...游戏结束!" << endl;
                delete player;
                return 0;
            }
    
            cout << "\n行动选择:" << endl;
            cout << "1.修炼  2.战斗  3.查看状态  4.历练" << endl;
            if (player->getProfession() == SWORD_CULTIVATOR) {
                cout << "5.练剑  6.淬炼长剑" << endl;
            } else {
                cout << "5.炼丹  6.查看丹方" << endl;
            }
            if (player->canBreakthrough()) {
                cout << "7.尝试突破境界" << endl;
            }
            cout << "0.退出游戏" << endl;
            cin >> choice;
    
            if (player->canBreakthrough() && choice == 7) {
                player->attemptBreakthrough();
                continue;
            }
    
            switch (choice) {
                case 1: player->cultivate(); break;
                case 2: player->fightMonster(); break;
                case 3: player->viewStatus(); break;
                case 4: player->venture(); break;
                case 5: 
                    if (player->getProfession() == SWORD_CULTIVATOR) player->practiceSword();
                    else {
                        cout << "选择丹药:1.气血丹 2.燃血丹 3.回春丹" << endl;
                        int pill; cin >> pill;
                        player->refinePill(pill);
                    }
                    break;
                case 6: 
                    if (player->getProfession() == SWORD_CULTIVATOR) player->quenchSword();
                    else player->viewDanFang();
                    break;
                case 0: 
                    cout << "感谢游玩!" << endl;
                    delete player;
                    return 0;
                default: cout << "无效选择!" << endl;
            }
        }
    }
    
    
  • 最近活动

  • Stat

  • Rating