class User extends Base_C_Object {


    constructor(gObject) {

        base.constructor(gObject);
    }

    //获得当前区域
    //@param b boolean
    //@return integer
    function GetArea(b) {
        return Sq_CUser_GetAreaIndex(this.C_Object, b);
    }

    //获得当前区域位置
    //@return integer, integer
    function GetAreaPos() {
        return {
            X = Sq_CUser_GetPosX(this.C_Object),
            Y = Sq_CUser_GetPosY(this.C_Object)
        };
    }

    //获得朝向
    //@return integer, integer
    function GetDirections() {
        return Sq_CUser_Direction(this.C_Object);
    }

    //获得可见values
    //@return integer, integer
    function GetVisibleValues() {
        return Sq_CUser_GetVisibleValues(this.C_Object);
    }

    //获得当前城镇位置
    //@return integer, integer, integer, integer @城镇, 区域, X, Y
    function GetLocation() {
        return {
            Pos = this.GetAreaPos(),
            Town = Sq_CUser_GetTownIndex(this.C_Object),
            Area = Sq_CUser_GetAreaIndex(this.C_Object)
        };
    }

    //账号状态
    //@return integer @after login >= 3
    function GetState() {
        return Sq_CUser_GetState(this.C_Object);
    }

    //角色数量
    //@return integer
    function GetCharacCount() {
        return Sq_CUser_GetCharacCount(this.C_Object);
    }

    //账号ID
    //@return integer
    function GetUID() {
        return Sq_CUser_GetAccId(this.C_Object);
    }

    //唯一ID
    //@return integer
    function GetUniqueId() {
        return Sq_CUser_GetUniqueId(this.C_Object);
    }

    //角色ID
    //@return integer
    function GetCID() {
        return Sq_CUser_GetCharacNo(this.C_Object);
    }

    //角色职业
    //@return integer
    function GetCharacJob() {
        return Sq_CUser_GetCharacJob(this.C_Object);
    }

    //角色名称
    //@return string
    function GetCharacName() {
        return Sq_CUser_GetCharacName(this.C_Object);
    }

    //角色等级
    //@return integer
    function GetCharacLevel() {
        return Sq_CUser_GetCharacLevel(this.C_Object);
    }

    //设置角色等级
    //@param new_level integer
    //@return boolean
    function SetCharacLevel(new_level) {
        Sq_CUser_ChangeGmQuestFlag(this.C_Object, 1);
        Sq_CallFunc(S_Ptr("0x0858EFDE"), "int", ["pointer", "pointer", "int"], S_Ptr("0x0"), this.C_Object, new_level);
        Sq_CUser_ChangeGmQuestFlag(this.C_Object, 0);
    }

    //角色转职职业
    //@return integer
    function GetCharacGrowType() {
        return Sq_CUser_GetCharacGrowType(this.C_Object);
    }

    //角色觉醒职业
    //@return integer
    function GetCharacSecondGrowType() {
        return Sq_CUser_GetCharacSecondGrowType(this.C_Object);
    }

    //更改转职职业 转职职业 是否觉醒
    function ChangeGrowType(GrowType, IsAwa) {
        Sq_CUser_ChangeGrowType(this.C_Object, GrowType, IsAwa);
    }

    //已用疲劳值
    //@return integer
    function GetFatigue() {
        return Sq_CUser_GetFatigue(this.C_Object);
    }

    //最大疲劳值
    //@return integer
    function GetMaxFatigue() {
        return Sq_CUser_GetMaxFatigue(this.C_Object);
    }

    //获取背包
    //@return integer
    function GetInven() {
        local P = Sq_Inven_GetInven(this.C_Object);
        if (P) {
            return Inven(P, this);
        }
        return null;
    }

    //踢人
    //@param src integer @渠道
    //@param p2 integer
    //@param p3 integer
    //@return integer @错误码?
    function Kick(...) {
        local src;
        local p2;
        local p3;
        for (local i = 0; i< vargv.len(); i++) {
            if (i == 0) src = vargv[i];
            if (i == 1) p2 = vargv[i];
            if (i == 2) p3 = vargv[i];
        }

        return Sq_CUser_DisConnSig(this.C_Object, src ? src : 0, p2 ? p2 : 0, p3 ? p3 : 0)
    }

    //踢人
    //@param err @错误号
    //@return integer
    function DisConn(err) {
        return this.Kick(10, 1, err ? err : 1)
    }

    //当前小队/副本
    //@return CParty
    function GetParty() {
        local Ret = Sq_CUser_GetParty(this.C_Object);
        if (Ret) {
            return Party(Ret);
        }
        return null;
    }


    //是否在领主塔
    //@return boolean
    function CheckInBossTower() {
        return (Sq_CUser_CheckInBossTower(this.C_Object) == 1);
    }

    //是否在龙之路
    //@return boolean
    function CheckInBlueMarble() {
        return (Sq_CUser_CheckInBlueMarble(this.C_Object) == 1);
    }

    //是否开启GM权限
    //@return boolean
    function IsGmMode() {
        return (Sq_CUser_IsGmMode(this.C_Object) != 0);
    }

    //获取账号上次退出游戏的时间
    function GetCurCharacLastPlayTick() {
        return Sq_CUser_GetCurCharacLastPlayTick(this.C_Object);
    }

    //获取账号本次登录游戏的时间
    function GetCurCharacLoginTick() {
        return Sq_CallFunc(S_Ptr("0x822F692"), "int", ["pointer"], this.C_Object);
    }

    //获得公网地址
    //@return integer
    function GetIpAddress() {
        return Sq_CallFunc(S_Ptr("0x84EC90A"), "int", ["pointer"], this.C_Object);
    }

    //发包
    function Send(SPacket) {
        Sq_Packet_Send(this.C_Object, SPacket.C_Object);
    }

    //发送弹窗公告包(可自定义文字需要客户端修复233dll搭配)
    function SendNotiBox(Msg, Type) {
        local Pack = Packet();
        Pack.Put_Header(0, 233);
        Pack.Put_Byte(1);
        Pack.Put_Byte(5);
        Pack.Put_Int(Msg.len());
        Pack.Put_BinaryEx(Str_Ptr(Msg), Msg.len());
        Pack.Finalize(true);
        Sq_CallFunc(S_Ptr("0x867B8FE"), "int", ["pointer", "int", "pointer"], this.C_Object, Type, Pack.C_Object);
        Pack.Delete();
    }

    //发送自定义包
    function SendJso(Jso) {
        local Str = Json.Encode(Jso);
        if (PacketDebugModel) print("发送包给客户端: " + Str);
        local Pack = Packet();
        Pack.Put_Header(1, 130);
        Pack.Put_Byte(1);
        Pack.Put_Int(Str.len());
        Pack.Put_Binary(Str);
        Pack.Finalize(true);
        Send(Pack);
        Pack.Delete();
    }

    //发送字节包
    function SendBlob(Np) {
        if(!Np || Np.Size == -1)return;
        local Pack = Packet();
        Pack.Put_Header(1, 131);
        Pack.Put_Byte(1);
        Pack.Put_Int(Np.Size);
        Pack.Put_BinaryEx(Np.C_Object,Np.Size);
        Pack.Finalize(true);
        Send(Pack);
        Pack.Delete();
    }

    //发送自定义DPS包
    function Send_DPS_Pack(Id, Jso) {
        Jso.op <- 2147483646;
        Jso.dps_id <- Id;
        SendJso(Jso);
    }


    //发送消息包
    function SendNotiPacket(Type1, Type2, Type3) {
        Sq_CUser_SendNotiPacket(this.C_Object, Type1, Type2, Type3);
    }


    //获取技能树
    function GetSkillW() {
        return Sq_CUser_GetSkillW(this.C_Object);
    }

    //重置技能树 转职编号 是否觉醒
    function InitSkillW(GrowType, IsAwa) {
        Sq_CUser_InitSkillW(Sq_CUser_GetSkillW(this.C_Object), GrowType, IsAwa);
    }

    //发送公告消息
    function SendNotiPacketMessage(String, Type) {
        local Pack = Packet();
        Pack.Put_Header(0, 12);
        Pack.Put_Byte(Type);
        Pack.Put_Short(0);
        Pack.Put_Byte(0);
        Pack.Put_Int(String.len());
        Pack.Put_Binary(String);
        Pack.Finalize(true);
        this.Send(Pack);
        Pack.Delete();
    }

    //发送公告消息  字符串数组
    function SendNotiForColorPacketMessage(StringArr, Type) {

        local ColorArr = [];
        local SendStrBlob = blob(1);
        SendStrBlob.writen(0xc2, 'c');
        SendStrBlob.writen(0x80, 'c');
        foreach(sobj in StringArr) {
            local StrPoint = Str_Ptr(sobj[0]);
            local StrPointB = Sq_Point2Blob(StrPoint, sobj[0].len());
            if (sobj[1]) {
                SendStrBlob.writen(0xc2, 'c');
                SendStrBlob.writen(0x80, 'c');
                SendStrBlob.writeblob(StrPointB);
                SendStrBlob.writen(0xc2, 'c');
                SendStrBlob.writen(0x80, 'c');

                local ColorBlob = blob(104);
                for (local i = 0; i< 3; i++) {
                    ColorBlob.writen(sobj[2][i], 'c');
                }
                for (local i = 0; i< 101; i++) {
                    ColorBlob.writen(0xff, 'c');
                }
                local ColorPoint = Sq_New_Point(104);
                Sq_WriteBlobToAddress(ColorPoint, ColorBlob);
                ColorArr.append(ColorPoint);

            } else {
                SendStrBlob.writeblob(StrPointB);
            }
        }

        local SendStrLen = SendStrBlob.len();
        local SendStrPoint = Sq_New_Point(SendStrLen);
        Sq_WriteBlobToAddress(SendStrPoint, SendStrBlob);

        local Pack = Packet();
        Pack.Put_Header(0, 370);
        Pack.Put_Byte(Type);
        Pack.Put_Short(0);
        Pack.Put_Byte(3);
        Pack.Put_Int(SendStrLen);
        Pack.Put_BinaryEx(SendStrPoint, SendStrLen);
        Pack.Put_Byte(ColorArr.len());
        foreach(color in ColorArr) {
            Pack.Put_BinaryEx(color, 3);
        }
        Pack.Finalize(true);
        Send(Pack);
        Pack.Delete();
        SendItemSpace(0);

        Sq_Delete_Point(SendStrPoint);
        for (local i = 0; i< ColorArr.len(); i++) {
            Sq_Delete_Point(ColorArr[i]);
        }
    }

    //发送公告消息  字符串数组 带ID
    function SendNotiForColorAIdPacketMessage(StringArr, Type) {
        local ColorArr = [];
        local SendStrBlob = blob(1);
        SendStrBlob.writen(0xc2, 'c');
        SendStrBlob.writen(0x80, 'c');
        foreach(sobj in StringArr) {
            local StrPoint = Str_Ptr(sobj[0]);
            local StrPointB = Sq_Point2Blob(StrPoint, sobj[0].len());
            if (sobj[1]) {
                SendStrBlob.writen(0xc2, 'c');
                SendStrBlob.writen(0x80, 'c');
                SendStrBlob.writeblob(StrPointB);
                SendStrBlob.writen(0xc2, 'c');
                SendStrBlob.writen(0x80, 'c');

                local ColorBlob = blob(104);
                for (local i = 0; i< 3; i++) {
                    ColorBlob.writen(sobj[2][i], 'c');
                }
                if (sobj[3]) {
                    ColorBlob.seek(4);
                    ColorBlob.writen(sobj[3], 'i');
                } else {
                    for (local i = 0; i< 101; i++) {
                        ColorBlob.writen(0xff, 'c');
                    }
                }
                local ColorPoint = Sq_New_Point(104);
                Sq_WriteBlobToAddress(ColorPoint, ColorBlob);
                ColorArr.append(ColorPoint);

            } else {
                SendStrBlob.writeblob(StrPointB);
            }
        }

        local SendStrLen = SendStrBlob.len();
        local SendStrPoint = Sq_New_Point(SendStrLen);
        Sq_WriteBlobToAddress(SendStrPoint, SendStrBlob);

        local Pack = Packet();
        Pack.Put_Header(0, 370);
        Pack.Put_Byte(Type);
        Pack.Put_Short(0);
        Pack.Put_Byte(3);
        Pack.Put_Int(SendStrLen);
        Pack.Put_BinaryEx(SendStrPoint, SendStrLen);
        Pack.Put_Byte(ColorArr.len());
        foreach(color in ColorArr) {
            Pack.Put_BinaryEx(color, 104);
        }
        Pack.Finalize(true);
        Send(Pack);
        Pack.Delete();
        SendItemSpace(0);
        Sq_Delete_Point(SendStrPoint);
        for (local i = 0; i< ColorArr.len(); i++) {
            Sq_Delete_Point(ColorArr[i]);
        }
    }


    //调试信息包
    function Debug(Any) {
        local Time = date();
        local TStr = format("[%d年%d月%d日%d时%d分%d秒]\n", Time.year, Time.month, Time.day, Time.hour, Time.min, Time.sec);
        SendNotiPacketMessage(TStr + Any.tostring(), 8);
    }

    //发送道具
    function GiveItem(ItemId, ItemCount) {
        //如果开了调试
        if ("DebugModelFlag" in getroottable()) {
            local Flag = PvfItem.GetPvfItemById(ItemId);
            if (!Flag) {
                print("未找到Pvf道具: " + ItemId);
                return null;
            }
        }
        local Info = Sq_CUser_GiveUserItem(this.C_Object, ItemId, ItemCount);
        if (Info) { //发送成功就刷新背包
            Sq_CUser_SendUpdateItemList(this.C_Object, 1, Info[0], Info[1]);
            return Info;
        } else return null;
    }
    //发送道具 如果背包满则发送邮件
    function GiveItemEx(GiveTab) {
        local mitems = {};
        foreach(i, v in GiveTab) {
            local Ret = GiveItem(v.id, v.count);
            if (!Ret) mitems[v.id] <- v.count;
        }
        if (mitems.len() > 0) {
            SendMail(mitems, {
                Title = "系统",
                Text = "由于你的包裹已满, 请留出足够的空间来接收道具."
            })
        }
    }

    //更新背包栏
    function SendItemSpace(ItemSpace) {
        Sq_CallFunc(S_Ptr("0x865DB6C"), "int", ["pointer", "int"], this.C_Object, ItemSpace);
    }

    //更新道具信息
    function SendUpdateItemList(Type, ItemSpace, Slot) {
        Sq_CUser_SendUpdateItemList(this.C_Object, Type, ItemSpace, Slot);
    }

    //发送系统邮件
    function SendMail(ItemList, ...) {
        local SGold = 0;
        local STitle = "GM邮件";
        local SText = "这是Gm给您发送的邮件";
        if (vargv.len() > 0) {
            local T = vargv[0];
            if ("Gold" in T) SGold = T.Gold;
            if ("Title" in T) STitle = T.Title;
            if ("Text" in T) SText = T.Text;
        }
        Sq_CUser_SendMail(GetCID(), ItemList, SGold, STitle, SText);
    }

    //无条件完成指定任务并领取奖励
    function ClearQuest_Gm(QuestId) {
        Sq_CUser_ChangeGmQuestFlag(this.C_Object, 1);
        Sq_CUser_QuestAction(this.C_Object, 33, QuestId, 0, 0);
        Sq_CUser_QuestAction(this.C_Object, 35, QuestId, 0, 0);
        Sq_CUser_QuestAction(this.C_Object, 36, QuestId, -1, 1);
        Sq_CUser_RefreshLastQuestTime(this.C_Object);
        Sq_CUser_ChangeGmQuestFlag(this.C_Object, 0);
    }

    //充值点券
    function RechargeCera(Amount) {
        Sq_CUser_RechargeCoupons(this.C_Object, Amount);
    }
    //获取点券
    function GetCera() {
        return Sq_CallFunc(S_Ptr("0x080FDF7A"), "int", ["pointer"], this.C_Object);
    }
    //充值代币券
    function RechargeCeraPoint(Amount) {
        Sq_CUser_RechargeCouponsPoint(this.C_Object, Amount);
    }
    //获取代币券
    function GetCeraPoint() {
        return Sq_CallFunc(S_Ptr("0x08692af6"), "int", ["pointer"], this.C_Object);
    }
    //充值金币
    function RechargeMoney(Amount) {
        Sq_CallFunc(S_Ptr("0x84FF29C"), "int", ["pointer", "int", "int", "int", "int"], Sq_CallFunc(S_Ptr("0x80DA28E"), "pointer", ["pointer"], this.C_Object), Amount, 0, 0, 0);
    }
    //充值胜点
    function RechargeWinPoint(Amount) {
        return Sq_CallFunc(S_Ptr("0x0864fd2c"), "int", ["pointer", "int", "int"], this.C_Object, Amount, 6);
    }
    //获取胜点
    function GetWinPoint() {
        return Sq_CallFunc(S_Ptr("0x0817a17c"), "int", ["pointer"], this.C_Object);
    }
    //获取复活币
    function GetCoin() {
        local Count = Sq_CallFunc(S_Ptr("0x086966b4"), "int", ["pointer"], this.C_Object) + Sq_CallFunc(S_Ptr("0x086966e0"), "int", ["pointer"], this.C_Object) + Sq_CallFunc(S_Ptr("0x0869670c"), "int", ["pointer"], this.C_Object);
        return Count;
    }

    //离开队伍
    function LeaveParty() {
        local PartyObj = GetParty();
        if (PartyObj) {
            PartyObj.LeaveUser(this);
        }
    }

    //放弃副本
    function GiveupDgn() {
        local PartyObj = GetParty();
        if (PartyObj) {
            PartyObj.LeaveUserOnDgn(this);
        }
    }

    //设置玩家坐标
    function SetPosition(Xpos, Ypos, Direction) {
        Sq_CallFunc(S_Ptr("0x082F0E2A"), "pointer", ["pointer", "int", "int", "short"], this.C_Object, Xpos, Ypos, Direction);
    }

    //获取玩家任务信息
    function GetQuest() {
        return Sq_CallFunc(S_Ptr("0x814AA5E"), "pointer", ["pointer"], this.C_Object);
    }

    //获取玩家账号金库
    function GetAccountCargo() {
        local Ret = Sq_CallFunc(S_Ptr("0x0822fc22"), "pointer", ["pointer"], this.C_Object);
        if (Ret) return AccountCargo(Ret, this);
        else return null;
    }

    //获取角色身上的显示时装
    function GetAva() {
        //获取背包对象
        local InvenObj = this.GetInven();
        if (!InvenObj) return;
        local re = [];
        local job = this.GetCharacJob();

        //遍历身上的每一件装备
        for (local u = 0; u <= 10; u++) {
            local EquObj = InvenObj.GetSlot(Inven.INVENTORY_TYPE_BODY, u);
            if (EquObj && !EquObj.IsEmpty) {
                //先拿克隆id  如果这个值有 那说明带的克隆这个是被克隆的装备 直接用这个  但是如果这个人什么都没带 只带了克隆 会显示克隆的id  所以还得判断这个id是不是克隆时装
                local clearId = Sq_CallFunc(S_Ptr("0x850d374"), "int", ["pointer", "int"], InvenObj.C_Object, u)


                local EquObjId = EquObj.GetIndex();
                //如果这个是克隆
                if (clearId > 0) {
                    re.push(clearId);
                } else { //不是克隆 直接把id放上去
                    re.push(EquObjId);
                }
            } else { //如果这个部位没东西 直接放默认时装上去
                re.push(defaultJobItemIdMap[job].index[u]);
            }
        }
        return re;
    }

}

class defaultJobItemId {

    /**
     * 头发
     */
    hat = 0;

    /**
     * 帽子
     */
    hair = 0;

    /**
     *脸
     */
    face = 0;
    /**
     * 披风
     */
    breast = 0;
    /**
     * 上衣
     */
    coat = 0;

    /**
     * 下装
     */
    pants = 0;

    /**
     * 腰部
     */
    waist = 0;

    /**
     * 鞋子
     */
    shoes = 0;

    /**
     * 皮肤
     */
    skin = 0;

    index = null;

    constructor(hat, hair, face, breast, coat, pants, waist, shoes, skin) {
        index = [];
        this.hat = hat;
        this.hair = hair;
        this.face = face;
        this.breast = breast;
        this.coat = coat;
        this.pants = pants;
        this.waist = waist;
        this.shoes = shoes;
        this.skin = skin;

        index.push(hat);
        index.push(hair);
        index.push(face);
        index.push(breast);
        index.push(coat);
        index.push(pants);
        index.push(waist);
        index.push(shoes);
        index.push(skin);
        index.push(0);
        index.push(0);
    }
}
//默认时装
if (!(getroottable().rawin("defaultJobItemIdMap"))) {
    getroottable().defaultJobItemIdMap <- {};
    defaultJobItemIdMap.rawset(0, defaultJobItemId(39278, 39400, 0, 0, 40600, 41000, 0, 41800, 42200));
    defaultJobItemIdMap.rawset(1, defaultJobItemId(0, 43400, 0, 0, 44600, 45000, 0, 45800, 46200));
    defaultJobItemIdMap.rawset(2, defaultJobItemId(0, 47400, 0, 48426, 48600, 49000, 0, 49800, 50200));
    defaultJobItemIdMap.rawset(3, defaultJobItemId(51265, 51400, 0, 0, 52600, 53000, 0, 53800, 54200));
    defaultJobItemIdMap.rawset(4, defaultJobItemId(0, 55400, 55820, 0, 56600, 57000, 0, 57800, 58200));

    defaultJobItemIdMap.rawset(5, defaultJobItemId(1600000, 1610000, 0, 0, 1640000, 1650000, 0, 1670000, 1680000));
    defaultJobItemIdMap.rawset(6, defaultJobItemId(1720000, 1730000, 0, 1750000, 1760000, 1770000, 0, 1790000, 1800000));
    defaultJobItemIdMap.rawset(7, defaultJobItemId(0, 29201, 0, 0, 29202, 29203, 0, 29204, 29205));
    defaultJobItemIdMap.rawset(8, defaultJobItemId(0, 2090000, 0, 0, 2120000, 2130000, 0, 2140000, 2150000));
    defaultJobItemIdMap.rawset(9, defaultJobItemId(39278, 39400, 0, 0, 40600, 41000, 0, 41800, 42200));
    defaultJobItemIdMap.rawset(10, defaultJobItemId(51265, 51400, 0, 0, 52600, 53000, 0, 53800, 54200));
}

//获取公会名称
function User::GetGuildName() {
    return Sq_CallFunc(S_Ptr("0x869742a"), "string", ["pointer"], this.C_Object);
}



//获取副职业对象指针
function User::GetCurCharacExpertJob() {
    return Sq_CallFunc(S_Ptr("0x822f8d4"), "pointer", ["pointer"], this.C_Object);
}

//获得角色副职业
function User::GetCurCharacExpertJobType() {
    return Sq_CallFunc(S_Ptr("0x822f894"), "int", ["pointer"], this.C_Object);
}

//调用分解机
function User::DisPatcher_DisJointItem_disjoint(Slot, ...) {
    local UseIdx = 239;
    local UsePtr = this.C_Object;
    if (vargv.len() > 1) {
        UseIdx = vargv[0];
        UsePtr = vargv[1];
    }
    return Sq_CallFunc(S_Ptr("0x81f92ca"), "int", ["pointer", "int", "int", "int", "pointer", "int"], this.C_Object, Slot, 0, UseIdx, UsePtr, 0xFFFF);
}

//发送Item邮件 Pubilc
function User::SendItemMail(UID, CID, ItemList, title, content) {
    local SUser = World.GetUserByUid(UID);
    local sql = "select letter_id from taiwan_cain_2nd.postal order by letter_id DESC";
    local column_type_list = ["int"];

    local SqlObj = MysqlPool.GetInstance().GetConnect();
    local result = SqlObj.Select(sql, column_type_list);
    local sl = 1;
    if (result.len() > 0) {
        sl = result[0][0] + 1;
    }

    local time = date();
    local timeStr = time["year"] + "-" + (time["month"] + 1) + "-" + time["day"] + " " + time["hour"] + ":" + time["min"] + ":" + time["sec"];

    foreach(value in ItemList) {
        local sql1 = "insert into taiwan_cain_2nd.postal (occ_time,send_charac_name,receive_charac_no,amplify_option,amplify_value,seperate_upgrade,seal_flag,item_id,add_info,upgrade,gold,letter_id,avata_flag,creature_flag) values ('" + timeStr + "','" + title + "'," + CID + ",0,0,0,0," + value.item + "," + value.num + ",0,0," + sl + ",'0','0')";
        SqlObj.Select(sql1, []);
    }

    local sql2 = "insert into taiwan_cain_2nd.letter (letter_id,charac_no,send_charac_name,letter_text,reg_date,stat) values ('" + sl + "'," + CID + ",'" + title + "','" + content + "','" + timeStr + "','1')";
    SqlObj.Select(sql2, []);

    MysqlPool.GetInstance().PutConnect(SqlObj);

    if (SUser) {
        local Pack = Packet();
        Pack.Put_Header(0, 9);
        local MailBox = Sq_CallFunc(S_Ptr("0x0823020C"), "int", ["pointer"], SUser.C_Object);
        Sq_CallFunc(S_Ptr("0x0823455A"), "int", ["int"], MailBox);
        local Not_Count = Sq_CallFunc(S_Ptr("0x084ED330"), "int", ["int"], MailBox);
        Pack.Put_Short(Not_Count);
        Pack.Finalize(true);
        SUser.Send(Pack);
        Pack.Delete();
    }
}

//道具是否被锁
function User::CheckItemLock(Type, Slot) {
    return Sq_CallFunc(S_Ptr("0x8646942"), "int", ["pointer", "int", "int"], this.C_Object, Type, Slot);
}


//查询本日金币交易额度
function User::GetTradeGoldDaily() {
    return Sq_CallFunc(S_Ptr("0x8696600"), "int", ["pointer"], this.C_Object);
}

//设置本日金币交易额度
function User::SetTradeGoldDaily(Value) {
    return Sq_CallFunc(S_Ptr("0x84EC002"), "int", ["pointer", "int"], this.C_Object, Value);
}

//在副本中给玩家掉落一个物品
function User::DropItem(ItemId, Xpos, Ypos) {
    local PartyObj = GetParty();
    if (!PartyObj) return;
    //更改掉落物的坐标
    NativePointer("0x085A7599").writeShort(Xpos);
    NativePointer("0x085A759F").writeShort(Ypos);
    //申请一块内存用于存放包地址
    local PackBuffer = Memory.alloc(8);
    PackBuffer.writeInt(947330670);
    local StrBuffer = "" + PackBuffer.C_Object;
    local AddressStr = StrBuffer.slice(StrBuffer.find("0x") + 2, -1);
    local HexCode = Haker.AsmGenerateMcd(
        "mov ebx," + AddressStr,
        "mov [ebx], eax",
        "mov ebx , 0",
        "mov eax, 0x85A775B",
        "jmp eax");

    Haker.InsertCode("0x85A773C", HexCode);

    //调用逻辑 包才会生成
    Sq_CallFunc(S_Ptr("0x85A73A6"), "int", ["pointer", "pointer", "int"], PartyObj.C_Object, this.C_Object, ItemId);

    local Pack = Packet(PackBuffer.readPointer());
    Send(Pack);
    //销毁包
    Sq_CallFunc(S_Ptr("0x858DE80"), "void", ["pointer"], Pack.C_Object);
    //还原逻辑
    Sq_WriteByteArr(S_Ptr("0x85A773C"), [0x89, 0x44, 0x24, 0x04, 0x8B, 0x45, 0x08]);
    NativePointer("0x085A7599").writeShort(300);
    NativePointer("0x085A759F").writeShort(240);
}

//角色类 发送邮件函数  (标题, 正文, 金币, 道具列表[[3037,100],[3038,100]])
function User::ReqDBSendMultiMail(title, text, gold, item_list) {
    Timer.SetTimeOut(function(SUser, title, text, gold, item_list) {
        local Cid = SUser.GetCID();
        // 获取分割后的道具列表
        local subLists;
        local maxSlots = 10;
        local length = item_list.len();
        if (length <= maxSlots) {
            subLists = [item_list];
        } else {
            subLists = [];
            for (local i = 0; i< length; i += maxSlots) {
                local end = i + maxSlots;
                if (end > length) {
                    end = length;
                }
                subLists.append(item_list.slice(i, end));
            }
        }
        if (subLists) {
            // 为每个子列表发送邮件
            for (local i = 0; i< subLists.len(); ++i) {
                local subList = subLists[i];

                // 添加道具附件
                local vector = Memory.alloc(100);

                Sq_CallFunc(S_Ptr("0x81349D6"), "pointer", ["pointer"], vector.C_Object);
                Sq_CallFunc(S_Ptr("0x817A342"), "pointer", ["pointer"], vector.C_Object);
                //将所有要发送的道具写入Vector
                for (local j = 0; j< subList.len(); ++j) {
                    //道具ID 分配4字节内存
                    local item_id = Memory.alloc(4);
                    //道具数量 分配4字节内存
                    local item_cnt = Memory.alloc(4);
                    //写入道具ID和数量
                    item_id.writeInt(subList[j][0]);
                    item_cnt.writeInt(subList[j][1]);

                    local pair = Memory.alloc(100);

                    Sq_CallFunc(S_Ptr("0x81B8D41"), "pointer", ["pointer", "pointer", "pointer"], pair.C_Object, item_id.C_Object, item_cnt.C_Object);
                    Sq_CallFunc(S_Ptr("0x80DD606"), "pointer", ["pointer", "pointer"], vector.C_Object, pair.C_Object);
                }

                // 邮件支持10个道具附件格子
                local addition_slots = Memory.alloc(1000);

                for (local j = 0; j< 10; ++j) {
                    Sq_CallFunc(S_Ptr("0x80CB854"), "pointer", ["pointer"], addition_slots.add(j * 61).C_Object);
                }

                Sq_CallFunc(S_Ptr("0x8556A14"), "int", ["pointer", "pointer", "int"], vector.C_Object, addition_slots.C_Object, 10);

                local title_ptr = Memory.allocUtf8String(title); // 邮件标题
                local text_ptr = Memory.allocUtf8String(text); // 邮件正文

                local text_len = text.len(); // 邮件正文长度

                // 发邮件给角色
                Sq_CallFunc(S_Ptr("0x8556B68"), "int", ["pointer", "pointer", "int", "int", "int", "pointer", "int", "int", "int", "int"], title_ptr.C_Object, addition_slots.C_Object, subList.len(), gold, Cid, text_ptr.C_Object, text_len, 0, 99, 1);
            }
        }
    }, 1, this, title, text, gold, item_list);
}