824 lines
28 KiB
Plaintext
824 lines
28 KiB
Plaintext
/*
|
|
文件名:MarrySystem.nut
|
|
路径:Dps_A/ProjectClass/MarrySystem/MarrySystem.nut
|
|
创建日期:2024-10-01 10:02
|
|
文件用途:结婚系统
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
class Marry {
|
|
//当前频道
|
|
Channel = null;
|
|
//配置
|
|
Config = null;
|
|
//包头
|
|
OP = 20078000;
|
|
//请求结婚的列表
|
|
RequestMarryList = {};
|
|
//进入礼堂前的位置信息
|
|
EnterAuditoriumPosList = {};
|
|
|
|
//礼堂id 对应的用户信息 结构为Map<cid,Map<uid , avatar[]>>
|
|
AuditoriumUserInfo = {};
|
|
//角色时装信息
|
|
UserAvaList = {};
|
|
|
|
//礼堂id 对应礼堂的宾客信息
|
|
AuditoriumUserInfoNewPeople = {};
|
|
|
|
//数据库操作集
|
|
Mysql_Operate_Func = {
|
|
//查询结婚状态
|
|
CheckMarryState = function(Cid) {
|
|
local CheckSql = format(MARRY_SQL_LIST.CheckMarryState, Cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(CheckSql, ["int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
//没结婚要返回false
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return 0;
|
|
} else {
|
|
return Ret[0][0];
|
|
}
|
|
}
|
|
//新增结婚信息
|
|
InseartMarryInfo = function(Cid, Name, TargerCid, Job, Level, Experience, Equip, State) {
|
|
local sql = format(MARRY_SQL_LIST.InseartMarryInfo, Cid, Name, TargerCid, Job, Level, Experience, Equip, State, TargerCid, Equip, State);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
SqlObj.Exec_Sql(sql);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
}
|
|
//查询结婚对象CID
|
|
CheckMarryTarget = function(Cid) {
|
|
local CheckSql = format(MARRY_SQL_LIST.CheckMarryTarget, Cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(CheckSql, ["int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
//没结婚要返回false
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return null;
|
|
} else {
|
|
return Ret[0][0];
|
|
}
|
|
}
|
|
//删除结婚信息
|
|
DeleteMarryInfo = function(Cid) {
|
|
local delete_sql = format(MARRY_SQL_LIST.DeleteMarryInfo, Cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
SqlObj.Exec_Sql(delete_sql);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
}
|
|
|
|
|
|
//清空礼堂信息列表
|
|
RomoveRoom = function(Cid) {
|
|
local delete_sql = format(MARRY_SQL_LIST.RomoveRoom);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
SqlObj.Exec_Sql(delete_sql);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
}
|
|
|
|
|
|
//查询结婚对象名字
|
|
CheckMarryTargetName = function(Cid) {
|
|
local CheckSql = format(MARRY_SQL_LIST.CheckMarryTargetName, Cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(CheckSql, ["string"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
//没结婚要返回false
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return null;
|
|
} else {
|
|
return Ret[0][0];
|
|
}
|
|
}
|
|
//修改结婚状态
|
|
ChangeMarryState = function(Cid, State) {
|
|
local Sql = format(MARRY_SQL_LIST.ChangeMarryState, State, Cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
SqlObj.Exec_Sql(Sql);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
}
|
|
//新增礼堂信息
|
|
InsertMarryRoom = function(Cid, Name, Time, Level, Target_CId, Target_Name, State, Index) {
|
|
local Sql = format(MARRY_SQL_LIST.InsertMarryRoom, Cid, Name, Time, Level, Target_CId, Target_Name, State, Index);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
SqlObj.Exec_Sql(Sql);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
}
|
|
|
|
|
|
//查询礼堂信息
|
|
GetAuditoriumList = function() {
|
|
local Sql = format(MARRY_SQL_LIST.GetAuditoriumList);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(Sql, ["int", "string", "int", "int", "int", "string", "int", "int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
|
|
return Ret;
|
|
}
|
|
|
|
|
|
//根据cid查询自己的礼堂编号
|
|
GetAuditoriumIndexById = function(cid) {
|
|
local Sql = format(MARRY_SQL_LIST.GetAuditoriumIndexById, cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(Sql, ["int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return null;
|
|
} else {
|
|
return Ret[0][0];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//根据cid查询婚礼开始时间
|
|
GetAuditoriumTimeById = function(cid) {
|
|
local Sql = format(MARRY_SQL_LIST.GetAuditoriumTimeById, cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(Sql, ["int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return null;
|
|
} else {
|
|
return Ret[0][0];
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//根据cid查询2个人的姓名
|
|
GetAuditoriumName2ById = function(cid) {
|
|
local Sql = format(MARRY_SQL_LIST.GetAuditoriumName2ById, cid, cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(Sql, ["int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return null;
|
|
} else {
|
|
return Ret[0];
|
|
}
|
|
}
|
|
|
|
|
|
//根据cid查询自己的经验值
|
|
GetExpById = function(cid) {
|
|
local Sql = format(MARRY_SQL_LIST.GetExpById, cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(Sql, ["int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return null;
|
|
} else {
|
|
return Ret[0][0];
|
|
}
|
|
}
|
|
|
|
//设置自己的经验值和等级
|
|
SetExpAndLvById = function(Cid, lv, exp) {
|
|
local Sql = format(MARRY_SQL_LIST.SetExpAndLvById, lv, exp, Cid, Cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
SqlObj.Exec_Sql(Sql);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
}
|
|
|
|
|
|
//根据cid查询自己的uid
|
|
GetUidByCid = function(cid) {
|
|
local Sql = format(MARRY_SQL_LIST.GetUidByCid, cid);
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local Ret = SqlObj.Select(Sql, ["int"]);
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
if (Ret.len()< 1 || Ret[0][0] == null) {
|
|
return null;
|
|
} else {
|
|
return Ret[0][0];
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//查看是否结婚包
|
|
function CheckMarryStateCallBack(SUser, Jso) {
|
|
local T = {
|
|
op = OP + 10,
|
|
Flag = Mysql_Operate_Func.CheckMarryState(SUser.GetCID())
|
|
}
|
|
SUser.SendJso(T);
|
|
}
|
|
|
|
//申请订婚包
|
|
function RequestMarry(SUser, Jso) {
|
|
local PSUser = World.GetUserByName(Jso.Name);
|
|
//判断对象角色是否在线
|
|
if (!PSUser) {
|
|
//没找到这个角色要返回一个错误包
|
|
local T = {
|
|
op = OP + 90,
|
|
str = "未找到角色,请检查角色名或查看玩家是否在线"
|
|
}
|
|
SUser.SendNotiBox("未找到角色,请检查角色名或查看玩家是否在线", 1);
|
|
}
|
|
//判断是否是自己
|
|
if (SUser.GetCID() == PSUser.GetCID()) {
|
|
SUser.SendNotiBox("不能和自己结婚!", 1);
|
|
return;
|
|
}
|
|
//查询两人状态必须都为未结婚
|
|
local SUserState = Mysql_Operate_Func.CheckMarryState(SUser.GetCID());
|
|
local PSUserState = Mysql_Operate_Func.CheckMarryState(PSUser.GetCID());
|
|
if (SUserState) {
|
|
SUser.SendNotiBox("抱歉,您已经结婚了!", 1);
|
|
return;
|
|
}
|
|
if (PSUserState) {
|
|
SUser.SendNotiBox("抱歉,对方已经结婚了...", 1);
|
|
return;
|
|
}
|
|
|
|
local T = {
|
|
op = OP + 4,
|
|
applicantCid = SUser.GetCID(),
|
|
applicantUid = SUser.GetUID(),
|
|
applicantName = SUser.GetCharacName(),
|
|
}
|
|
PSUser.SendJso(T);
|
|
|
|
//把请求加入到请求列表
|
|
RequestMarryList.rawset(SUser.GetCID(), PSUser.GetCID());
|
|
}
|
|
|
|
//订婚答复包
|
|
function ResponseMarry(SUser, Jso) {
|
|
local Flag = Jso.Flag;
|
|
local applicantUser = World.GetUserByUidCid(Jso.applicantUid, Jso.applicantCid);
|
|
if (Flag) {
|
|
if (applicantUser) {
|
|
//在请求列表里查看是否有请求
|
|
if (!(RequestMarryList.rawin(Jso.applicantCid)) || RequestMarryList[Jso.applicantCid] != SUser.GetCID()) {
|
|
SUser.SendNotiBox("抱歉,对方未发送请求!", 1);
|
|
return;
|
|
}
|
|
|
|
applicantUser.SendNotiBox("恭喜您!\n对方同意了您的请求。\n请寻找大司祭制定结婚的详细事宜。", 1);
|
|
|
|
Mysql_Operate_Func.InseartMarryInfo(Jso.applicantCid, applicantUser.GetCharacName(), SUser.GetCID(), applicantUser.GetCharacJob(), 0, 0, "no", 1);
|
|
Mysql_Operate_Func.InseartMarryInfo(SUser.GetCID(), SUser.GetCharacName(), Jso.applicantCid, SUser.GetCharacJob(), 0, 0, "no", 1);
|
|
|
|
//刷新客户端的订婚状态
|
|
local T = {
|
|
op = OP + 10,
|
|
Flag = 1
|
|
};
|
|
applicantUser.SendJso(T);
|
|
SUser.SendJso(T);
|
|
}
|
|
} else {
|
|
if (applicantUser) applicantUser.SendNotiBox("很遗憾!\n对方拒绝了您的请求", 1);
|
|
}
|
|
}
|
|
|
|
//退婚包
|
|
function CancelMarry(SUser, Jso) {
|
|
//加判断 必须两人都在订婚状态才能退婚
|
|
|
|
local DeleteArr = [];
|
|
DeleteArr.push(SUser.GetCID());
|
|
local Target_CId = Mysql_Operate_Func.CheckMarryTarget(SUser.GetCID());
|
|
if (Target_CId) {
|
|
DeleteArr.push(Target_CId);
|
|
//如果对象存在则判断两人是否都在订婚状态
|
|
local SUserState = Mysql_Operate_Func.CheckMarryState(SUser.GetCID())
|
|
local TargetState = Mysql_Operate_Func.CheckMarryTarget(Target_CId);
|
|
if (SUserState != 1 || TargetState != 1) return;
|
|
}
|
|
|
|
|
|
foreach(s_cid in DeleteArr) {
|
|
Mysql_Operate_Func.DeleteMarryInfo(s_cid);
|
|
}
|
|
//刷新客户端的订婚状态
|
|
local T = {
|
|
op = OP + 10,
|
|
Flag = 0
|
|
};
|
|
SUser.SendJso(T);
|
|
//如果需要通知被退婚的对象
|
|
if (DeleteArr.len() > 1) {
|
|
local WorldMap = World.GetOnlinePlayer();
|
|
foreach(W_User in WorldMap) {
|
|
if (W_User.GetCID() == DeleteArr[1]) {
|
|
W_User.SendJso(T);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
//打开准备婚礼窗口
|
|
function OpenPreparationWindow(SUser, Jso) {
|
|
local Target_CId = Mysql_Operate_Func.CheckMarryTarget(SUser.GetCID());
|
|
if (!Target_CId) {
|
|
SUser.SendNotiBox("没有婚礼信息!", 1);
|
|
return;
|
|
}
|
|
local Target_Name = Mysql_Operate_Func.CheckMarryTargetName(Target_CId);
|
|
if (!Target_Name) {
|
|
SUser.SendNotiBox("没有婚礼信息!", 1);
|
|
return;
|
|
}
|
|
local T = {
|
|
op = OP + 12,
|
|
MyName = SUser.GetCharacName(),
|
|
TargetName = Target_Name,
|
|
};
|
|
SUser.SendJso(T);
|
|
}
|
|
|
|
//确认婚礼
|
|
function ConfirmMarry(SUser, Jso) {
|
|
local Target_CId = Mysql_Operate_Func.CheckMarryTarget(SUser.GetCID());
|
|
if (!Target_CId) {
|
|
SUser.SendNotiBox("没有婚礼信息!", 1);
|
|
return;
|
|
}
|
|
local Time = Jso.Time;
|
|
local Level = Jso.Level;
|
|
local NeedItem = Config[("结婚等级" + (Level + 1) + "道具ID")];
|
|
|
|
//获取背包对象
|
|
local InvenObj = SUser.GetInven();
|
|
local SlotIdx = InvenObj.GetSlotById(NeedItem);
|
|
if (SlotIdx == -1) {
|
|
SUser.SendNotiBox("没有足够的道具!", 1);
|
|
return;
|
|
} else {
|
|
InvenObj.DeleteItemCount(NeedItem, 1);
|
|
|
|
|
|
|
|
//获得婚礼仪式开始时间
|
|
local Index = time() + (Time + 1) * 10 * 60;
|
|
//注册婚礼礼堂信息
|
|
Mysql_Operate_Func.InsertMarryRoom(SUser.GetCID(), SUser.GetCharacName(), Time, Level, Target_CId, Mysql_Operate_Func.CheckMarryTargetName(Target_CId), Time, Index);
|
|
Mysql_Operate_Func.InsertMarryRoom(Target_CId, Mysql_Operate_Func.CheckMarryTargetName(Target_CId), Time, Level, SUser.GetCID(), SUser.GetCharacName(), Time, Index);
|
|
AuditoriumUserInfo.rawset(SUser.GetCID(), {});
|
|
|
|
|
|
Mysql_Operate_Func.ChangeMarryState(SUser.GetCID(), 2);
|
|
Mysql_Operate_Func.ChangeMarryState(Target_CId, 2);
|
|
|
|
|
|
local T = {
|
|
op = OP + 10,
|
|
Flag = 2
|
|
}
|
|
|
|
|
|
//这里放2个新人的信息
|
|
local avatra = [];
|
|
local infore = {};
|
|
infore.rawset("job", SUser.GetCharacJob());
|
|
infore.rawset("growjob", SUser.GetCharacGrowType());
|
|
infore.rawset("avatar", Config["职业对应的结婚礼服"][SUser.GetCharacJob().tostring()]);
|
|
infore.rawset("name", SUser.GetCharacName());
|
|
infore.rawset("uid", SUser.GetUID());
|
|
|
|
//根据cid去查uid
|
|
local Target_Uid = Mysql_Operate_Func.GetUidByCid(Target_CId);
|
|
|
|
local Muser = World.GetUserByUid(Target_Uid);
|
|
local infore2 = {};
|
|
infore2.rawset("job", Muser.GetCharacJob());
|
|
infore2.rawset("growjob", Muser.GetCharacGrowType());
|
|
infore2.rawset("avatar", Config["职业对应的结婚礼服"][Muser.GetCharacJob().tostring()]);
|
|
infore2.rawset("name", Muser.GetCharacName());
|
|
infore2.rawset("uid", Muser.GetUID());
|
|
avatra.push(infore);
|
|
avatra.push(infore2);
|
|
|
|
AuditoriumUserInfoNewPeople.rawset(SUser.GetCID(), avatra);
|
|
|
|
|
|
|
|
local WorldMap = World.GetOnlinePlayer();
|
|
foreach(W_User in WorldMap) {
|
|
if (W_User.GetCID() == Target_CId) {
|
|
W_User.SendJso(T);
|
|
W_User.SendNotiBox(format("婚礼将在%d分钟后举行!\n点击大司祭可进入礼堂。", (Time + 1) * 10), 1);
|
|
}
|
|
}
|
|
|
|
SUser.SendJso(T);
|
|
SUser.SendNotiBox(format("婚礼将在%d分钟后举行!\n点击大司祭可进入礼堂。", (Time + 1) * 10), 1);
|
|
|
|
Timer.SetTimeOut(OpenAuditorium.bindenv(this), (Time + 1) * 10 * 1000, SUser.GetCID());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//婚礼前的准备 把2个新人先传进去
|
|
function OpenPreparation(index) {
|
|
//拿到两个新人的信息
|
|
local uidsInfo = AuditoriumUserInfoNewPeople[index];
|
|
|
|
local uid1 = uidsInfo[0].rawget("uid");
|
|
local uid2 = uidsInfo[1].rawget("uid");
|
|
|
|
//拿到礼堂所有宾客的信息
|
|
local userlist = AuditoriumUserInfo[index];
|
|
//如果不在里面就传送进来
|
|
if (!(userlist.rawin(uid1))) {
|
|
EnterAuditorium(World.GetUserByUid(uid1), {
|
|
room = -1
|
|
});
|
|
}
|
|
if (!(userlist.rawin(uid2))) {
|
|
EnterAuditorium(World.GetUserByUid(uid2), {
|
|
room = -1
|
|
});
|
|
}
|
|
}
|
|
|
|
//开启婚礼 参数为礼堂编号 也就是其中一个人的cid
|
|
function OpenAuditorium(index) {
|
|
print(time());
|
|
|
|
//婚礼准备
|
|
OpenPreparation(index);
|
|
|
|
//通知所有在这个礼堂里的人 婚礼开始了
|
|
local userlist = AuditoriumUserInfo[index];
|
|
|
|
|
|
//先拿到新人存的信息
|
|
local info = AuditoriumUserInfoNewPeople[index];
|
|
|
|
local uid1 = info[0].rawget("uid");
|
|
local uid2 = info[1].rawget("uid");
|
|
|
|
|
|
//比那里礼堂所有人信息
|
|
foreach(uid, v in userlist) {
|
|
local user = World.GetUserByUid(uid);
|
|
//todo 这里要判断 如果是结婚的人就不加到宾客里
|
|
if (!user) {
|
|
|
|
}
|
|
local infore = {
|
|
job = user.GetCharacJob(),
|
|
growjob = user.GetCharacGrowType(),
|
|
avatar = user.GetAva(),
|
|
name = user.GetCharacName(),
|
|
};
|
|
info.push(infore);
|
|
if (info.len() >= 8) {
|
|
break;
|
|
}
|
|
}
|
|
printT(info);
|
|
|
|
|
|
|
|
foreach(uid, v in userlist) {
|
|
local user = World.GetUserByUid(uid);
|
|
//发包通知 普通宾客的包
|
|
local T = {
|
|
op = OP + 34,
|
|
info = info
|
|
}
|
|
user.SendJso(T);
|
|
}
|
|
|
|
|
|
//删除礼堂信息
|
|
AuditoriumUserInfo.rawdelete(index);
|
|
//删除数据库信息
|
|
//Mysql_Operate_Func.RomoveRoom();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//进入礼堂
|
|
function EnterAuditorium(SUser, Jso) {
|
|
local RoomId = Jso.room;
|
|
|
|
local location = SUser.GetLocation();
|
|
|
|
// //进入自己的礼堂
|
|
if (RoomId == -1) {
|
|
local MyState = Mysql_Operate_Func.CheckMarryState(SUser.GetCID());
|
|
if (MyState != 2) {
|
|
SUser.SendNotiBox("您访问的礼堂不存在!", 1);
|
|
return;
|
|
}
|
|
RoomId = SUser.GetCID();
|
|
//如果根据自己的cid不能拿到礼堂信息 说明这个礼堂的key是对象的
|
|
if (!(AuditoriumUserInfo.rawin(RoomId))) {
|
|
//对象的cid
|
|
RoomId = Mysql_Operate_Func.GetAuditoriumIndexById(SUser.GetCID());
|
|
}
|
|
|
|
location.rawset("所在礼堂编号", RoomId);
|
|
//向缓存写入进入时的坐标
|
|
EnterAuditoriumPosList.rawset(SUser.GetCID(), location);
|
|
|
|
//移动到礼堂
|
|
World.MoveArea(SUser, Config["礼堂城镇编号"], Config["礼堂区域编号"], 55, 349);
|
|
} else {
|
|
location.rawset("所在礼堂编号", RoomId);
|
|
//向缓存写入进入时的坐标
|
|
EnterAuditoriumPosList.rawset(SUser.GetCID(), location);
|
|
//移动到礼堂
|
|
World.MoveArea(SUser, Config["礼堂城镇编号"], Config["礼堂区域编号"], 55, 349);
|
|
}
|
|
|
|
|
|
|
|
|
|
local infore = {};
|
|
infore.rawset("job", SUser.GetCharacJob());
|
|
infore.rawset("growjob", SUser.GetCharacGrowType());
|
|
infore.rawset("avatar", SUser.GetAva());
|
|
infore.rawset("name", SUser.GetCharacName());
|
|
|
|
|
|
|
|
AuditoriumUserInfo[RoomId].rawset(SUser.GetUID(), infore);
|
|
|
|
//遍历这个礼堂里的人 给他们发送可见列表
|
|
local UserCanSee = [];
|
|
foreach(uid, info in AuditoriumUserInfo[RoomId]) {
|
|
UserCanSee.push(uid);
|
|
}
|
|
MarryUserCallBack(UserCanSee, SUser)
|
|
|
|
|
|
local T = {
|
|
op = OP + 22,
|
|
time = Mysql_Operate_Func.GetAuditoriumTimeById(RoomId) - time()
|
|
}
|
|
|
|
|
|
SUser.SendJso(T);
|
|
}
|
|
|
|
|
|
//服务端区域移动添加玩家HOOK 让大家不可见
|
|
function Marry_insert_user_hook(C_Area, C_User) {
|
|
//如果有城镇配置
|
|
if (Config) {
|
|
local SUser = User(C_User);
|
|
if (SUser.GetLocation().Town == Config["礼堂城镇编号"]) {
|
|
if (SUser.GetLocation().Area == Config["礼堂区域编号"]) Sq_WriteAddress(C_Area, 0x68, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
//离开礼堂
|
|
function LeaveAuditorium(SUser, Jso) {
|
|
if (EnterAuditoriumPosList.rawin(SUser.GetCID())) {
|
|
local Info = EnterAuditoriumPosList[SUser.GetCID()];
|
|
//离开礼堂回到进入时的位置
|
|
World.MoveArea(SUser, Info.Town, Info.Area, Info.Pos.X, Info.Pos.Y);
|
|
|
|
//给这个礼堂的人发送退出可见列表的包
|
|
foreach(uid in AuditoriumUserInfo[Info["所在礼堂编号"]]) {
|
|
UserCanSee.push(uid);
|
|
}
|
|
MarryUserDeleteCallBack(UserCanSee, SUser)
|
|
|
|
|
|
AuditoriumUserInfo[Info["所在礼堂编号"]].rawdelete(SUser.GetUID());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//获得礼堂列表
|
|
function GetAuditoriumList(SUser, Jso) {
|
|
local re = Mysql_Operate_Func.GetAuditoriumList();
|
|
local SendArr = [];
|
|
//判断用的
|
|
local SelectMap = {};
|
|
|
|
foreach(v in re) {
|
|
local TimeBuf = v.pop();
|
|
local id = v[0];
|
|
//不存在时PUSH
|
|
if (!(SelectMap.rawin(v[4]))) {
|
|
v.push(AuditoriumUserInfo.rawget(id).len());
|
|
v.push(Channel);
|
|
v.push(TimeBuf);
|
|
SendArr.push(v);
|
|
SelectMap.rawset(id, 1);
|
|
}
|
|
}
|
|
local T = {
|
|
op = OP + 20,
|
|
info = SendArr
|
|
}
|
|
SUser.SendJso(T);
|
|
}
|
|
|
|
function GetConfig(SUser, Jso) {
|
|
local T = {
|
|
op = OP + 778,
|
|
town = Config["礼堂城镇编号"],
|
|
area = Config["礼堂区域编号"],
|
|
}
|
|
SUser.SendJso(T);
|
|
}
|
|
|
|
|
|
//加入到可见列表
|
|
function MarryUserCallBack(CUserList, MUser) {
|
|
|
|
|
|
local RealList = [];
|
|
foreach(uid in CUserList) {
|
|
local SUser = World.GetUserByUid(uid);
|
|
if (SUser && SUser.GetState() >= 3) RealList.append(SUser);
|
|
}
|
|
|
|
foreach(_Index, Value in RealList) {
|
|
local SUser = Value;
|
|
local Pack = Packet();
|
|
Pack.Put_Header(0, 24);
|
|
Pack.Put_Byte(SUser.GetLocation().Town); //城镇
|
|
Pack.Put_Byte(SUser.GetArea(1)); //区域
|
|
Pack.Put_Short((RealList.len() - 1)); //几个玩家 要减去自己
|
|
foreach(__Index, MapObj in RealList) {
|
|
if (SUser.GetUID() == MapObj.GetUID()) continue;
|
|
Pack.Put_Short(MapObj.GetUniqueId());
|
|
Pack.Put_Short(MapObj.GetAreaPos().X);
|
|
Pack.Put_Short(MapObj.GetAreaPos().Y);
|
|
Pack.Put_Byte(MapObj.GetDirections()); //朝向
|
|
Pack.Put_Byte(MapObj.GetVisibleValues()); //是否可见
|
|
}
|
|
Pack.Put_Byte(1); //是否可见
|
|
Pack.Finalize(true);
|
|
SUser.Send(Pack);
|
|
Pack.Delete();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//退出可见列表
|
|
function MarryUserDeleteCallBack(RealList, MUser) {
|
|
|
|
foreach(_Index, Value in RealList) {
|
|
local SUser = Value;
|
|
if (!SUser || !(SUser.GetState() >= 3) || !MUser || !(MUser.GetState() >= 3)) continue;
|
|
if (SUser.GetUID() == MUser.GetUID()) continue;
|
|
local Pack = Packet();
|
|
Pack.Put_Header(0, 23);
|
|
Pack.Put_Short(MUser.GetUniqueId()); //唯一id
|
|
Pack.Put_Byte(MUser.GetLocation().Town); //城镇
|
|
|
|
|
|
Pack.Put_Byte(99); //区域
|
|
Pack.Put_Short(MUser.GetAreaPos().X);
|
|
|
|
Pack.Put_Short(MUser.GetAreaPos().Y);
|
|
Pack.Put_Byte(MUser.GetDirections()); //朝向
|
|
Pack.Put_Byte(MUser.GetVisibleValues()); //是否可见
|
|
Pack.Finalize(true);
|
|
|
|
SUser.Send(Pack);
|
|
Pack.Delete();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
Config = dofile("/root/娱心插件配置/结婚系统配置.dat");
|
|
|
|
local ConfigPath = Sq_Game_GetConfig();
|
|
Channel = ConfigPath.slice(-6).slice(0, 2);
|
|
|
|
//注册来自客户端的收包
|
|
// ClientSocketPackFuncMap.rawset(OP + 9, CheckMarryStateCallBack.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 3, RequestMarry.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 5, ResponseMarry.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 7, CancelMarry.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 11, OpenPreparationWindow.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 13, ConfirmMarry.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 15, EnterAuditorium.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 17, LeaveAuditorium.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 19, GetAuditoriumList.bindenv(this));
|
|
// ClientSocketPackFuncMap.rawset(OP + 777, GetConfig.bindenv(this));
|
|
//注册结婚回调函数
|
|
Cb_Insert_User_Func.Marry <- Marry_insert_user_hook.bindenv(this); //区域添加角色
|
|
|
|
// //玩家重新上线的时候自动给他退出礼堂
|
|
Cb_reach_game_world_Func.Auditorium <- function(SUser) {
|
|
|
|
if (EnterAuditoriumPosList && EnterAuditoriumPosList.rawin(SUser.GetUID())) {
|
|
local Info = EnterAuditoriumPosList[SUser.GetCID()];
|
|
//给这个礼堂的人发送退出可见列表的包
|
|
foreach(cid in AuditoriumUserInfo[Info["所在礼堂编号"]]) {
|
|
UserCanSee.push(cid);
|
|
}
|
|
MarryUserDeleteCallBack(UserCanSee, SUser)
|
|
|
|
AuditoriumUserInfo[Info["所在礼堂编号"]].rawdelete(SUser.GetUID());
|
|
}
|
|
}.bindenv(this);
|
|
|
|
|
|
|
|
//从池子拿连接
|
|
local SqlObj = MysqlPool.GetInstance().GetConnect();
|
|
local query = "SELECT COUNT(*) AS table_exists FROM information_schema.tables WHERE table_schema = 'zyk' AND table_name = 'marry';"
|
|
local Res = SqlObj.Select(query, ["int"]);
|
|
//需要建库
|
|
if (Res.len() > 0 && Res[0][0] == 0) {
|
|
local CreateSql = "CREATE TABLE IF NOT EXISTS zyk.marry (cid INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), target_cid INT(11), job INT(11), level INT(11), experience INT(11), equip VARCHAR(255), state INT(11));"
|
|
local CreateSql2 = "CREATE TABLE IF NOT EXISTS zyk.marry_room (cid INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), time INT(11), level INT(11), target_cid INT(11), target_name VARCHAR(255), state INT(11), index INT(11));"
|
|
SqlObj.Exec_Sql(CreateSql);
|
|
SqlObj.Exec_Sql(CreateSql2);
|
|
}
|
|
//把连接还池子
|
|
MysqlPool.GetInstance().PutConnect(SqlObj);
|
|
|
|
|
|
Cb_Use_Item_Sp_Func[Config["结婚等级1道具ID"]] <- function(SUser, ItemId) {
|
|
ExpUp(SUser, Config["道具1给的心意点"]);
|
|
}.bindenv(this);
|
|
Cb_Use_Item_Sp_Func[Config["结婚等级2道具ID"]] <- function(SUser, ItemId) {
|
|
ExpUp(SUser, Config["道具2给的心意点"]);
|
|
}.bindenv(this);
|
|
Cb_Use_Item_Sp_Func[Config["结婚等级3道具ID"]] <- function(SUser, ItemId) {
|
|
ExpUp(SUser, Config["道具3给的心意点"]);
|
|
}.bindenv(this);
|
|
|
|
}
|
|
|
|
function ExpUp(SUser, expUp) {
|
|
exp = Mysql_Operate_Func.GetExpById(SUser.GetCID())
|
|
if (!exp) {
|
|
return;
|
|
}
|
|
exp = exp + expUp;
|
|
for (local i = 6; i >= 0; i--) {
|
|
//如果当前的经验值大于所遍历到的等级 就设定等级为这个 然后不继续向更低等级遍历
|
|
if (Config["戒指等级"][i.tostring()]["所需经验"]< exp) {
|
|
Mysql_Operate_Func.SetExpAndLvById(SUser.GetCID(), i, exp)
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
//初始化结婚
|
|
// ProjectInitFuncMap.P_Marry <- Marry(); |