//加入成员 public void AddLegionMembers(uint legion_id, LegionMember members) { if (!mDicInfo.ContainsKey(legion_id)) return; uint id = Data.UpdateLegionMembers(legion_id, members); if (id == 0) return; members.id = id; mDicInfo[legion_id].list_member.Add(members); }
//军团添加成员 public void AddMember(uint legion_id,PlayerObject play) { //已经有军团了 if(play.GetLegionSystem().IsHaveLegion())return; Legion legion = GetLegion(legion_id); if (legion == null) return; LegionMember member = new LegionMember(); member.members_name = play.GetName(); member.money = 0; member.rank = GameBase.Config.Define.LEGION_PLACE_PUTONGTUANYUAN; legion.GetBaseInfo().list_member.Add(member); play.GetLegionSystem().SetLegion(legion,true); UpdateLegionInfo(legion_id, play.GetBaseAttr().player_id); }
//创建军团 public void CreateLegion(LegionInfo info,int player_id) { int legion_id = Data.CreateLegion(info); CreateLegion_Ret ret = new CreateLegion_Ret(); if (legion_id != -1) ret.ret = 1; ret.play_id = player_id; ret.legion_id = legion_id; info.id = (uint)legion_id; mDicInfo[info.id] = info; LegionMember member = new LegionMember(); member.money = info.money; member.members_name = info.leader_name; member.rank = GameBase.Config.Define.LEGION_PLACE_JUNTUANZHANG; member.money = info.money; //初始化的贡献度 AddLegionMembers(info.id,member); ret.money = info.money; ret.boss_id = member.id; SessionManager.Instance().SendMapServer(0, ret.GetBuffer()); }
//创建军团返回 public void CreateLegion_Ret(CreateLegion_Ret info) { LegionInfo le = null; for(int i = 0;i < mListTemp.Count;i++) { if (mListTemp[i].leader_id == info.play_id) { le = mListTemp[i]; le.id = (uint)info.legion_id; mListTemp.Remove(le); break; } } if(info == null || info.ret ==0 || le == null)return; PlayerObject play = UserEngine.Instance().FindPlayerObjectToPlayerId(info.play_id); if (play == null) return; //加入军团长 LegionMember member = new LegionMember(); member.boChange = true; member.members_name = play.GetName(); member.money = info.money; member.id = info.boss_id; member.rank = GameBase.Config.Define.LEGION_PLACE_JUNTUANZHANG; le.list_member.Add(member); Legion l = new Legion(); l.SetBaseInfo(le); mDicLegion[le.id] = l; play.GetLegionSystem().SetLegion(l,true); }
public void Create(PackIn inpack) { id = inpack.ReadUInt32(); name = inpack.ReadString(); title = inpack.ReadByte(); leader_id = inpack.ReadInt32(); leader_name = inpack.ReadString(); money = inpack.ReadLong(); notice = inpack.ReadString(); int count = inpack.ReadInt32(); for (int i = 0; i < count; i++) { LegionMember member = new LegionMember(); member.Create(inpack); list_member.Add(member); } }
//更新军团成员信息 public static uint UpdateLegionMembers(uint legion_id, LegionMember member) { member.members_name = Coding.GB2312ToLatin1(member.members_name); //插入 MySqlCommand command; String sql = ""; if (member.id == 0) { sql = string.Format(MysqlString.CREATE_LEGION_MEMBERS, legion_id, member.members_name, member.money, member.rank); } else { sql = string.Format(MysqlString.UPDATE_LEGION_MEMBERS, member.money, member.rank, legion_id, member.members_name); } command = new MySqlCommand(sql, MysqlConn.GetConn()); MysqlConn.Conn_Open(); command.ExecuteNonQuery(); MysqlConn.Conn_Close(); command.Dispose(); if (member.id != 0) { return member.id; } //取主键-- 不能用于多线程或者多个程序操作该数据库。。切记 uint ret = 0; String _key = "select max(id) from cq_legion_members"; command = new MySqlCommand(_key, MysqlConn.GetConn()); MysqlConn.Conn_Open(); MySqlDataReader reader = command.ExecuteReader(); reader.Read(); if (reader.HasRows) { ret = Convert.ToUInt32(reader[0].ToString()); } MysqlConn.Conn_Close(); command.Dispose(); return ret; }
//从数据库载入军团配置 public void DB_Load() { LegionInfo info = null; String sql = string.Format("select * from cq_legion"); MySqlCommand command = new MySqlCommand(sql, MysqlConn.GetConn()); MysqlConn.Conn_Open(); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (!reader.HasRows) break; info = new LegionInfo(); info.id = reader.GetUInt32("id"); info.name = reader.GetString("name"); info.name = Coding.Latin1ToGB2312(info.name); info.title = reader.GetByte("member_title"); info.leader_id = reader.GetInt32("leader_id"); info.leader_name = reader.GetString("leader_name"); info.leader_name = Coding.Latin1ToGB2312(info.leader_name); info.money = reader.GetInt64("money"); info.notice = reader.GetString("notice"); info.notice = Coding.Latin1ToGB2312(info.notice); mDicInfo[info.id] = info; } MysqlConn.Conn_Close(); command.Dispose(); //载入行会成员信息 foreach (LegionInfo obj in mDicInfo.Values) { sql = string.Format("select * from cq_legion_members where legion_id={0}",obj.id); command = new MySqlCommand(sql, MysqlConn.GetConn()); MysqlConn.Conn_Open(); reader = command.ExecuteReader(); while (reader.Read()) { if (!reader.HasRows) break; LegionMember member = new LegionMember(); member.rank = reader.GetInt16("rank"); member.members_name = reader.GetString("members_name"); member.members_name = Coding.Latin1ToGB2312(member.members_name); member.money = reader.GetInt64("money"); obj.list_member.Add(member); } MysqlConn.Conn_Close(); command.Dispose(); } }