/*
文件名:GameManagerClass.nut
路径:BaseClass/GameManagerClass/GameManagerClass.nut
创建日期:2024-04-09	20:30
文件用途:游戏管理器类
*/
class GameManager extends Base_C_Object {

    constructor() {
        local CObject = Sq_GameManager_GameManager();
        base.constructor(CObject);
    }

    function GetParty() {
        local C_Party = Sq_GameManager_GetParty(C_Object);
        return Party(C_Party);
    }

    //设置游戏最大等级
    function SetGameMaxLevel(MaxLevel) {
        NativePointer("0x8360C38").add(3).writeU8(MaxLevel);
        NativePointer("0x8360C76").add(3).writeU8(MaxLevel);
        NativePointer("0x8360CC1").add(3).writeU8(MaxLevel);
        NativePointer("0x84EF802").add(3).writeU8(MaxLevel);
        NativePointer("0x858F002").add(3).writeU8(MaxLevel);
        NativePointer("0x865A5C0").add(1).writeU8(MaxLevel);
        NativePointer("0x865B091").add(4).writeU8(MaxLevel);
        NativePointer("0x865B757").add(4).writeU8(MaxLevel);
        NativePointer("0x8662F53").add(2).writeU8(MaxLevel);
        NativePointer("0x86630F0").add(3).writeU8(MaxLevel);
        NativePointer("0x86638F4").add(2).writeU8(MaxLevel);
        NativePointer("0x8665D24").add(4).writeU8(MaxLevel);
        NativePointer("0x8666E9A").add(2).writeU8(MaxLevel);
        NativePointer("0x866A4A6").add(2).writeU8(MaxLevel);
        NativePointer("0x866A657").add(2).writeU8(MaxLevel);
        NativePointer("0x866A926").add(3).writeU8(MaxLevel);
        NativePointer("0x866A93F").add(2).writeU8(MaxLevel);
        NativePointer("0x867AEC0").add(2).writeU8(MaxLevel);
        NativePointer("0x8689D48").add(3).writeU8(MaxLevel);
        NativePointer("0x868fecb").add(3).writeU8(MaxLevel);
        NativePointer("0x868fed4").add(6).writeU8(MaxLevel);
    }

    //设置装备解锁需要时间
    function SetItemLockTime(time) {
        NativePointer("0x8402D29").writeInt(time);
        NativePointer("0x854242F").writeInt(time);
        NativePointer("0x854274D").writeInt(time);
        NativePointer("0x854296F").writeInt(time);
        NativePointer("0x8542AD9").writeInt(time);
        NativePointer("0x8542BDE").writeInt(time);
    }

    //开启创建鼠标妹
    function OpenCreateJob_CreatorMage() {
        Sq_WriteByteArr(S_Ptr("0x81C029F"), [0xf]);
    }

    //开启获得魔法封印时自动解除魔法封印
    function OpenRandomAutomaticUnblocking() {
        Cb_User_Insert_Item_Leave_Func.Rindro <- function(args) {
            local SUser = User(NativePointer(args[0]).readPointer());
            local InvenObj = SUser.GetInven();
            local idx = args.pop();
            if (idx > 0) {
                local inven_item = InvenObj.GetSlot(1, idx);
                local item_id = inven_item.GetIndex();
                local pvfitem = PvfItem.GetPvfItemById(item_id);
                //如果是魔法封印装备
                if (!pvfitem.IsRandomOption()) {
                    return;
                }
                local random_option = NativePointer(inven_item.C_Object).add(37);
                if (random_option.readU32() || random_option.add(4).readU32() || random_option.add(8).readShort()) {
                    return;
                }
                NativePointer(inven_item.C_Object).add(37).add(0).writeU8(1);
            }
            SUser.SendItemSpace(0);
            return null;
        }
    }

    //开启自动热重载
    function OpenHotFix(Path = "/dp_s/MyProject") {
        print("DP-S开启自动重载脚本功能,重载目录为: " + Path + " .");
        print("请注意如果你不处于DP-S开发环境，请关闭此功能，以免对性能造成影响");
        Sq_AutoReload(Path);
    }

    //开启时装镶嵌
    function FixAvatarUseJewel() {
        //时装镶嵌修复
        _AvatarUseJewel_Object <- AvatarUseJewel();
    }

    //修复下线卡城镇
    function FixSaveTown() {
        Cb_Set_Charac_Info_Detail_Enter_Func._FixSaveTown_ <- function(arg) {
            local curArea = NativePointer(arg[3]).add(34).readS8();
            if (curArea == 12 || curArea == 13) {
                NativePointer(arg[3]).add(34).writeS8(11);
            }
        }
    }

    //修复绝望金币异常
    function FixDespairGold() {
        getroottable()._FixDespairGold_Data_ <- {};
        Cb_UseAncientDungeonItems_Enter_Func._FixDespairGold_ <- function(arg) {
            local DgnObj = Dungeon(arg[1]);
            local DgnIndex = DgnObj.GetId();
            if ((DgnIndex >= 11008) && (DgnIndex <= 11107)) {
                getroottable()._FixDespairGold_Data_[arg[1]] <- NativePointer(arg[1]).add(2044).readS8();
                NativePointer(arg[1]).add(2044).writeS8(0);
            }
        }
        Cb_UseAncientDungeonItems_Leave_Func._FixDespairGold_ <- function(arg) {
            local DgnObj = Dungeon(arg[1]);
            local DgnIndex = DgnObj.GetId();
            if ((DgnIndex >= 11008) && (DgnIndex <= 11107)) {
                //绝望之塔 不再扣除金币
                NativePointer(arg[1]).add(2044).writeS8(getroottable()._FixDespairGold_Data_[arg[1]]);
                getroottable()._FixDespairGold_Data_.rawdelete(arg[1]);
            }
        }
    }

    //修复绝望之塔通关后可以用门票继续进入
    function FixDespairDungeon() {
        Cb_User_GetLastClearTime_Leave_Func._FixDespairDungeon_ <- function(arg) {
            return 0;
        }
    }

    //修改交易金币上限
    function FixGlodTradeDaily(Count) {
        local Arr = [0xB8];
        local BlobObj = blob(0);
        BlobObj.writen(Count, 'i');
        for (local i = 0; i< 4; i++) {
            Arr.append(BlobObj[i]);
        }
        Arr.append(0x90);
        Sq_WriteByteArr(S_Ptr("0x86464CE"), Arr);
    }

}
//热重载
function _Reload_List_Write_(Path) {
    dofile(Path);
    print("位于 [" + Path + "] 的脚本已重载")
}