| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347 |
- package model
- import (
- "rocommon"
- "rocommon/util"
- "roserver/baseserver/model"
- model2 "roserver/db/model"
- "roserver/serverproto"
- )
- func (this *GuildManager) GetGuildMemberCount(guildMember *serverproto.MemberData) int32 {
- if guildMember == nil {
- return 0
- }
- return int32(len(guildMember.MemberInfo))
- }
- func (this *GuildManager) QuitApplyGuild(uid uint64, guildId uint64) serverproto.ErrorCode {
- guild := this.GetGuild(guildId)
- if guild != nil {
- //删除公会中,此玩家的申请信息
- var bFind bool = false
- for index, data := range guild.ApplyList.ApplyGuild {
- if data == uid {
- guild.ApplyList.ApplyGuild = append(guild.ApplyList.ApplyGuild[:index], guild.ApplyList.ApplyGuild[index+1:]...)
- bFind = true
- break
- }
- }
- if bFind == true {
- this.SaveGuildApply(guild)
- }
- }
- applyData := this.GetRoleApplyInfo(uid)
- if applyData != nil {
- var bFind bool = false
- for index, data := range applyData.ApplyGuild {
- if data == guildId {
- applyData.ApplyGuild = append(applyData.ApplyGuild[:index], applyData.ApplyGuild[index+1:]...)
- bFind = true
- break
- }
- }
- if bFind == true {
- this.SaveRoleApplyData(uid, applyData)
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- //申请加入工会
- func (this *GuildManager) ApplyGuild(uid uint64, guildId uint64, level int32, ev rocommon.ProcEvent) serverproto.ErrorCode {
- guild := this.GetGuild(guildId)
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- if level < guild.GuildBase.RecruitLevel {
- return serverproto.ErrorCode_ERROR_GUILD_ROLE_LEVEL_LOW
- }
- //如果公会默认是不接受申请的
- if guild.GuildBase.RecruitType == Recruit_Refused {
- return serverproto.ErrorCode_ERROR_GUILD_CANT_APPLY
- }
- //公会申请列表满
- if guild.ApplyList != nil {
- if len(guild.ApplyList.ApplyGuild) >= int(model.GlobalGuildApplyListMax) {
- return serverproto.ErrorCode_ERROR_GUILD_APPLY_COUNT_MAX
- } else {
- for _, data := range guild.ApplyList.ApplyGuild {
- if data == uid {
- return serverproto.ErrorCode_ERROR_GUILD_NO_REAPPLY
- }
- }
- }
- }
- //玩家申请列表
- applyData := this.GetRoleApplyInfo(uid)
- if applyData != nil {
- if len(applyData.ApplyGuild) >= int(model.GlobalGuildRoleApplyMax) {
- return serverproto.ErrorCode_ERROR_GUILD_APPLY_COUTN_MAX
- }
- for _, data := range applyData.ApplyGuild {
- if data == guildId {
- return serverproto.ErrorCode_ERROR_GUILD_NO_REAPPLY
- }
- }
- }
- //是否需要申请
- if guild.GuildBase.RecruitType == Recruit_Verify {
- if guild.ApplyList == nil {
- guild.ApplyList = &serverproto.GuildApplayData{}
- }
- guild.ApplyList.ApplyGuild = append(guild.ApplyList.ApplyGuild, uid)
- this.SaveGuildApply(guild)
- } else if guild.GuildBase.RecruitType == Recruit_None_Verify {
- //判定公会是否在公会战中
- _, bRet := GuildBattleMag.IsInGuildBattle(guildId)
- if bRet == true {
- return serverproto.ErrorCode_ERROR_GUILDBATTLE_In_GuildBattle
- }
- //看下这个人是否有公会
- _, ok := this.RoleToGuilds[uid]
- if ok {
- return serverproto.ErrorCode_ERROR_GUILD_IN_GUILD
- }
- //公会是否满员
- memberNum := this.GetMaxGuildMemberNum(guild)
- if this.GetGuildMemberCount(guild.GuildMember) >= memberNum {
- return serverproto.ErrorCode_ERROR_GUILD_MEMBER_COUNT_MAX
- }
- //检查公会是否有这个人
- for _, data := range guild.GuildMember.MemberInfo {
- if data.MemberId == uid {
- return serverproto.ErrorCode_ERROR_GUILD_IN_GUILD
- }
- }
- //添加公会成员
- member := &serverproto.GuildMember{
- MemberId: uid,
- Title: Guild_Title_Member,
- OfflineTime: 0,
- AddGuildTime: util.GetCurrentTime(),
- }
- guild.GuildMember.MemberInfo = append(guild.GuildMember.MemberInfo, member)
- this.SaveGuildMember(guild)
- //直接加入公会,则推送公会信息
- ntfMsg := &serverproto.SCApplyInfoHandleNtf{
- Data: &serverproto.GuildNotifyData{},
- }
- ntfMsg.ApplyResult = Guild_Apply_Accept
- ntfMsg.GuildId = guild.GuildBase.GuildBrief.GuildId
- ntfMsg.Uid = uid
- ntfMsg.Data.Brief = guild.GuildBase.GuildBrief
- ntfMsg.Data.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- ntfMsg.Data.IsApply = false
- //保存
- this.RoleToGuilds[uid] = &serverproto.GuildIdex{
- GuildId: guildId,
- }
- this.SaveRoleToGuild(uid)
- model.ServiceReplay(ev, ntfMsg)
- //删除玩家个人申请记录
- this.RemoveRoleApply(uid)
- //刪除该公会玩家申请信息
- this.RemoveGuildApply(uid, guild)
- //保存玩家公会信息
- this.SaveGuildApply(guild)
- this.SendGuildNotice(guild, uid, Guild_SysChat_Event_PlayerJoin, Guild_Title_Member, 0)
- this.AddGuildLog(guild, 0, 0, Guild_Title_Member, uid, Guild_Event_Type_DirectJoin)
- util.InfoF("[ApplyGuild] player join guild guildId :%v uid:%v ", guild.GuildBase.GuildBrief.GuildId, uid)
- return serverproto.ErrorCode_ERROR_OK
- }
- //存库一下玩家的申请信息
- if applyData == nil {
- var newApply serverproto.RoleApplayData
- newApply.ApplyGuild = append(newApply.ApplyGuild, guildId)
- this.ApplyData[uid] = &newApply
- this.SaveRoleApplyData(uid, &newApply)
- } else {
- applyData.ApplyGuild = append(applyData.ApplyGuild, guildId)
- this.SaveRoleApplyData(uid, applyData)
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- //离开公会(会长离开公会需要有额外处理)
- func (this *GuildManager) QuitGuild(uid uint64, guildId uint64) serverproto.ErrorCode {
- guild := this.GetGuild(guildId)
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- //todo wangzhaocan 退出公会测试放开
- _, bRet := GuildBattleMag.IsInGuildBattle(guildId)
- if bRet == true {
- return serverproto.ErrorCode_ERROR_GUILDBATTLE_In_GuildBattle
- }
- //检查是否是会长
- title := this.GetMemberTitle(uid, guild)
- if title == Guild_Title_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_PRESIDENT_CANT_LEAVE
- }
- for index, member := range guild.GuildMember.MemberInfo {
- if member.MemberId == uid {
- //找到,则删除
- guild.GuildMember.MemberInfo = append(guild.GuildMember.MemberInfo[:index], guild.GuildMember.MemberInfo[index+1:]...)
- break
- }
- }
- for index, member := range guild.GuildMember.VicePreId {
- if member == uid {
- //找到,则删除
- guild.GuildMember.VicePreId = append(guild.GuildMember.VicePreId[:index], guild.GuildMember.VicePreId[index+1:]...)
- break
- }
- }
- this.AddGuildLog(guild, title, uid, 0, 0, Guild_Event_Type_LeaveGuild)
- this.SaveGuildMember(guild)
- this.RemoveRoleToGuild(uid)
- util.InfoF("[QuitGuild] guildId :%v uid:%v old_title:%v", guild.GuildBase.GuildBrief.GuildId, uid, title)
- return serverproto.ErrorCode_ERROR_OK
- }
- //检查今日踢出玩家数量
- func (this *GuildManager) CheckKickNum(guildMember *serverproto.MemberData) bool {
- if guildMember == nil {
- return false
- }
- //重置时间
- if guildMember.KickTime < util.GetCurrentTime() {
- guildMember.KickTime = util.GetLatest5Hour()
- guildMember.KickNum = 0
- }
- if util.GetCurrentTime() <= guildMember.KickTime && guildMember.KickNum < model.GlobalGuildKickMemberCount {
- return true
- }
- return false
- }
- //踢除公会成员
- func (this *GuildManager) KickGuildMember(preUid uint64, uid uint64, guildId uint64, needCheck bool) serverproto.ErrorCode {
- guild, ok := this.Guilds[guildId]
- if !ok {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- //判定公会是否在公会战中
- _, bRet := GuildBattleMag.IsInGuildBattle(guildId)
- if bRet == true {
- return serverproto.ErrorCode_ERROR_GUILDBATTLE_In_GuildBattle
- }
- checkRet := this.CheckKickNum(guild.GuildMember)
- if !checkRet && needCheck {
- return serverproto.ErrorCode_ERROR_GUILD_KICK_MEMBER_MAX_COUNT
- }
- opTitle := this.GetMemberTitle(preUid, guild)
- memberTitle := this.GetMemberTitle(uid, guild)
- if opTitle == -1 {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if memberTitle == -1 {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_FOUND_MEMBER
- }
- //被踢的人是会长,则返回
- if memberTitle == Guild_Title_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_PRESIDENT_KICK
- }
- if opTitle != Guild_Title_Pre && opTitle != Guild_Title_Vice_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_NO_AUTHORITY
- }
- //验证是否是会长副会长操作,验证是否存在这个成员
- if opTitle > memberTitle {
- var bFind bool = false
- for idx, data := range guild.GuildMember.MemberInfo {
- if data.MemberId == uid {
- bFind = true
- //删除当前玩家
- _, ok := this.RoleToGuilds[uid]
- if ok {
- this.RoleToGuilds[uid] = &serverproto.GuildIdex{
- GuildId: guildId,
- }
- }
- guild.GuildMember.MemberInfo = append(guild.GuildMember.MemberInfo[:idx], guild.GuildMember.MemberInfo[idx+1:]...)
- //副会长ID删除
- for index, viceUid := range guild.GuildMember.VicePreId {
- if viceUid == uid {
- guild.GuildMember.VicePreId = append(guild.GuildMember.VicePreId[:index], guild.GuildMember.VicePreId[index+1:]...)
- break
- }
- }
- //踢人次数+1
- guild.GuildMember.KickNum += 1
- this.SaveGuildMember(guild)
- this.RemoveRoleToGuild(uid)
- this.AddGuildLog(guild, opTitle, preUid, memberTitle, uid, Guild_Event_Type_KickGuild)
- ntfMsg := &serverproto.SCKickGuildMemberNtf{
- GuildId: guildId,
- Uid: uid,
- }
- SendSocial(ntfMsg)
- util.InfoF("[ApplyGuild] kick guild member guildId :%v pre_id:%v, uid:%v ", guild.GuildBase.GuildBrief.GuildId, preUid, uid)
- return serverproto.ErrorCode_ERROR_OK
- }
- }
- if bFind == false {
- return serverproto.ErrorCode_ERROR_GUILD_KICK_TARGET_NOT_FOUND
- }
- } else {
- return serverproto.ErrorCode_ERROR_GUILD_NO_AUTHORITY
- }
- return serverproto.ErrorCode_ERROR_FAIL
- }
- func (this *GuildManager) ChangeMemberTitleNtf(guildId uint64, uid uint64, uidList []*serverproto.KeyValueType64) {
- ntfMsg := &serverproto.SCChangeMemberTitleNtf{}
- ntfMsg.GuildId = guildId
- ntfMsg.UidList = uidList
- ntfMsg.Uid = uid
- SendSocial(ntfMsg)
- }
- func (this *GuildManager) ApplyInfoHandleNtf(guild *GuildData, uid uint64, result int32) {
- ntfMsg := &serverproto.SCApplyInfoHandleNtf{
- Data: &serverproto.GuildNotifyData{},
- }
- ntfMsg.ApplyResult = result
- ntfMsg.Uid = uid
- ntfMsg.GuildId = guild.GuildBase.GuildBrief.GuildId
- ntfMsg.Data.Brief = guild.GuildBase.GuildBrief
- ntfMsg.Data.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- SendSocial(ntfMsg)
- }
- func (this *GuildManager) KickGuildMemberNtf(guild *GuildData, uid uint64, result int32) {
- ntfMsg := &serverproto.SCKickGuildMemberNtf{}
- ntfMsg.Uid = uid
- ntfMsg.GuildId = guild.GuildBase.GuildBrief.GuildId
- SendSocial(ntfMsg)
- }
- //去social请求在线状态
- func (this *GuildManager) GetMemberOnlineInfo(guild *GuildData, memberList []uint64) {
- if len(memberList) <= 0 {
- return
- }
- reqMsg := &serverproto.SSGuildMemberOnlineInfoReq{}
- reqMsg.GuildId = guild.GuildBase.GuildBrief.GuildId
- for _, data := range memberList {
- reqMsg.UidList = append(reqMsg.UidList, data)
- }
- SendSocial(reqMsg)
- }
- //social返回,设置公会成员在线状态
- func (this *GuildManager) OnGuildMemberOnlineAck(ackMsg *serverproto.SSGuildMemberOnlineInfoAck) {
- if ackMsg == nil {
- return
- }
- guild := this.GetGuild(ackMsg.GuildId)
- if guild == nil || guild.GuildMember == nil {
- return
- }
- for _, data := range ackMsg.UidList {
- for _, member := range guild.GuildMember.MemberInfo {
- if data.Key == member.MemberId {
- if data.Value == 1 {
- member.OfflineTime = 0
- } else if data.Value == 0 {
- member.OfflineTime = int64(util.GetCurrentTime())
- }
- }
- }
- }
- }
- //修改会员官职
- func (this *GuildManager) ChangeMemberTitle(preUid, uid, guildId uint64, title int32) serverproto.ErrorCode {
- guild, ok := this.Guilds[guildId]
- if !ok {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- if guild.GuildMember == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_FOUND
- }
- var nFind int32 = 0
- for _, data := range guild.GuildMember.MemberInfo {
- if data.MemberId == uid || data.MemberId == preUid {
- nFind++
- }
- if nFind == 2 {
- break
- }
- }
- if nFind != 2 {
- return serverproto.ErrorCode_ERROR_GUILD_KICK_TARGET_NOT_FOUND
- }
- //不是会长,错误
- opTitle := this.GetMemberTitle(preUid, guild)
- if opTitle != Guild_Title_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_NO_AUTHORITY
- }
- memberTitle := this.GetMemberTitle(uid, guild)
- if memberTitle == title {
- return serverproto.ErrorCode_ERROR_GUILD_ARGS_INVALIDATE
- }
- if title == Guild_Title_Member {
- //查看此人是否是副会长,不是副会长则操作无效
- if memberTitle != Guild_Title_Vice_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_ARGS_INVALIDATE
- }
- //从副会长列表中删除
- for idx, viceUid := range guild.GuildMember.VicePreId {
- if viceUid == uid {
- guild.GuildMember.VicePreId = append(guild.GuildMember.VicePreId[:idx], guild.GuildMember.VicePreId[idx+1:]...)
- break
- }
- }
- for _, member := range guild.GuildMember.MemberInfo {
- if member.MemberId == uid {
- member.Title = Guild_Title_Member
- break
- }
- }
- var uidList []*serverproto.KeyValueType64
- uidList = append(uidList, &serverproto.KeyValueType64{
- Key: uid,
- Value: Guild_Title_Member,
- })
- this.ChangeMemberTitleNtf(guildId, uid, uidList)
- this.AddGuildLog(guild, opTitle, preUid, memberTitle, uid, Guild_Event_Type_Member)
- } else if title == Guild_Title_Vice_Pre {
- //此人不是副会长,且,副会长人数小于2。则可以提升
- if len(guild.GuildMember.VicePreId) >= int(model.GlobalGuildVicePreNum) {
- return serverproto.ErrorCode_ERROR_GUILD_VICE_PRESIDENT_MAX
- }
- if memberTitle == Guild_Title_Vice_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_ARGS_INVALIDATE
- }
- guild.GuildMember.VicePreId = append(guild.GuildMember.VicePreId, uid)
- for _, member := range guild.GuildMember.MemberInfo {
- if member.MemberId == uid {
- member.Title = Guild_Title_Vice_Pre
- }
- }
- var uidList []*serverproto.KeyValueType64
- uidList = append(uidList, &serverproto.KeyValueType64{
- Key: uid,
- Value: Guild_Title_Vice_Pre,
- })
- this.ChangeMemberTitleNtf(guildId, uid, uidList)
- this.AddGuildLog(guild, opTitle, preUid, memberTitle, uid, Guild_Event_Type_VicePresident)
- } else if title == Guild_Title_Pre { //转让会长只能给副会长
- if memberTitle != Guild_Title_Vice_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_ARGS_INVALIDATE
- }
- for idx, viceUid := range guild.GuildMember.VicePreId {
- if viceUid == uid {
- guild.GuildMember.VicePreId[idx] = preUid
- break
- }
- }
- guild.GuildMember.PreId = uid
- //修改职位
- var count int32 = 0
- for _, member := range guild.GuildMember.MemberInfo {
- if member.MemberId == preUid {
- if member.Title == Guild_Title_Pre {
- member.Title = Guild_Title_Vice_Pre
- count++
- }
- } else if member.MemberId == uid {
- if member.Title == Guild_Title_Vice_Pre {
- member.Title = Guild_Title_Pre
- count++
- }
- } else {
- if count >= 2 {
- break
- }
- }
- }
- var uidList []*serverproto.KeyValueType64
- uidList = append(uidList, &serverproto.KeyValueType64{
- Key: preUid,
- Value: Guild_Title_Vice_Pre,
- })
- uidList = append(uidList, &serverproto.KeyValueType64{
- Key: uid,
- Value: Guild_Title_Pre,
- })
- this.ChangeMemberTitleNtf(guildId, preUid, uidList)
- this.ChangeMemberTitleNtf(guildId, uid, uidList)
- this.AddGuildLog(guild, opTitle, preUid, memberTitle, uid, Guild_Event_Type_ChangePresident)
- GuildBattleMag.ExchangeGuildPre(preUid, uid, guildId)
- }
- this.SaveGuildMember(guild)
- return serverproto.ErrorCode_ERROR_OK
- }
- //设置公会信息(徽章,)
- func (this *GuildManager) SetGuildInfo(msg *serverproto.CSSetGuildInfoReq) serverproto.ErrorCode {
- guild := this.GetGuild(msg.GuildId)
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- if msg.Uid != guild.GuildMember.PreId {
- return serverproto.ErrorCode_ERROR_GUILD_NO_AUTHORITY
- }
- //设置入会等级,和入会条件
- guild.GuildBase.RecruitLevel = msg.JoinLevel
- if msg.JoinType == Recruit_Refused || msg.JoinType == Recruit_Verify || msg.JoinType == Recruit_None_Verify {
- guild.GuildBase.RecruitType = msg.JoinType
- }
- //设置徽章
- if msg.GuildBadge != 0 {
- //检查是否存在这个徽章
- guild.GuildBase.GuildBrief.GuildBadge = msg.GuildBadge
- guild.GuildBase.RecruitLevel = msg.JoinLevel
- guild.GuildBase.RecruitType = msg.JoinType
- guild.GuildBase.RecruitNotice = msg.RecruitNotice
- }
- this.SaveGuildBase(guild)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *GuildManager) CheckInGuildApplyList(uid uint64, guild *GuildData) serverproto.ErrorCode {
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- if guild.ApplyList == nil {
- return serverproto.ErrorCode_ERROR_GUILD_APPLY_TIME_OUT
- }
- for _, data := range guild.ApplyList.ApplyGuild {
- if data == uid {
- return serverproto.ErrorCode_ERROR_OK
- }
- }
- //需要判定判定是否是公会成员
- return serverproto.ErrorCode_ERROR_GUILD_APPLY_TIME_OUT
- }
- //处理玩家入会申请 todo wangzhaocan
- func (this *GuildManager) ApplyInfoHandle(msg *serverproto.CSApplyInfoHandleReq, ackMsg *serverproto.SCApplyInfoHandleAck) serverproto.ErrorCode {
- if msg == nil || ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- guild := this.GetGuild(msg.GuildId)
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- opTitle := this.GetMemberTitle(msg.Uid, guild)
- if opTitle != Guild_Title_Pre && opTitle != Guild_Title_Vice_Pre {
- return serverproto.ErrorCode_ERROR_GUILD_NO_AUTHORITY
- }
- if msg.HandleType == Guild_Apply_None {
- //处理玩家入会申请
- if msg.Apply.Value == Guild_Apply_Accept {
- //判定公会是否在公会战中
- _, bBattle := GuildBattleMag.IsInGuildBattle(msg.GuildId)
- if bBattle == true {
- return serverproto.ErrorCode_ERROR_GUILDBATTLE_In_GuildBattle
- }
- bRet := this.HandlePlayerApply(msg.Apply.Key, guild)
- retResult := &serverproto.KeyValueType64{
- Key: msg.Apply.Key,
- }
- if bRet != serverproto.ErrorCode_ERROR_OK {
- retResult.Value = Guild_Apply_Refused
- if bRet == serverproto.ErrorCode_ERROR_GUILD_MEMBER_COUNT_MAX {
- retResult.Value = Guild_Apply_Ignore
- }
- retResult.Value2 = int32(bRet)
- ackMsg.UidList = append(ackMsg.UidList, retResult)
- return bRet
- }
- retResult.Value = Guild_Apply_Accept
- retResult.Value2 = int32(serverproto.ErrorCode_ERROR_OK)
- ackMsg.UidList = append(ackMsg.UidList, retResult)
- this.GetMemberOnlineInfo(guild, []uint64{msg.Apply.Key})
- this.ApplyInfoHandleNtf(guild, msg.Apply.Key, Guild_Apply_Accept)
- this.SaveGuildMember(guild)
- //刪除玩家所有申請
- this.RemoveRoleApply(msg.Apply.Key)
- this.SendGuildNotice(guild, msg.Apply.Key, Guild_SysChat_Event_PlayerJoin, Guild_Title_Member, 0)
- this.AddGuildLog(guild, opTitle, msg.Uid, Guild_Title_Member, msg.Apply.Key, Guild_Event_Type_JoinGuild)
- } else {
- //删除玩家申请的这个公会ID
- bRet := this.CheckInGuildApplyList(msg.Apply.Key, guild)
- ackMsg.UidList = append(ackMsg.UidList, &serverproto.KeyValueType64{
- Key: msg.Apply.Key,
- Value: Guild_Apply_Refused,
- Value2: int32(bRet),
- })
- this.RemoveRoleApplyItem(msg.Apply.Key, guild.GuildBase.GuildBrief.GuildId)
- }
- //刪除该公会玩家申请信息
- this.RemoveGuildApply(msg.Apply.Key, guild)
- //保存玩家公会信息
- this.SaveGuildApply(guild)
- } else if msg.HandleType == Guild_Apply_All_Accept {
- //判定公会是否在公会战中
- _, bBattle := GuildBattleMag.IsInGuildBattle(msg.GuildId)
- if bBattle == true {
- return serverproto.ErrorCode_ERROR_GUILDBATTLE_In_GuildBattle
- }
- //同意所有玩家入会
- var hasNewMember bool = false
- var bRet serverproto.ErrorCode
- var uidList []uint64
- for _, applyUid := range msg.UidList {
- bRet = this.HandlePlayerApply(applyUid, guild)
- retResult := &serverproto.KeyValueType64{
- Key: applyUid,
- Value2: int32(bRet),
- }
- if bRet == serverproto.ErrorCode_ERROR_OK {
- retResult.Value = Guild_Apply_Accept
- } else if bRet == serverproto.ErrorCode_ERROR_GUILD_MEMBER_COUNT_MAX {
- retResult.Value = Guild_Apply_Ignore
- } else {
- retResult.Value = Guild_Apply_Refused
- }
- ackMsg.UidList = append(ackMsg.UidList, retResult)
- if bRet == serverproto.ErrorCode_ERROR_OK {
- uidList = append(uidList, applyUid)
- this.RemoveRoleApply(applyUid)
- this.RemoveGuildApply(applyUid, guild)
- this.ApplyInfoHandleNtf(guild, applyUid, Guild_Apply_Accept)
- this.AddGuildLog(guild, opTitle, msg.Uid, Guild_Title_Member, applyUid, Guild_Event_Type_JoinGuild)
- this.SendGuildNotice(guild, applyUid, Guild_SysChat_Event_PlayerJoin, Guild_Title_Member, 0)
- hasNewMember = true
- }
- }
- if hasNewMember == true {
- if len(uidList) > 0 {
- this.GetMemberOnlineInfo(guild, uidList)
- }
- this.SaveGuildMember(guild)
- this.SaveGuildApply(guild)
- }
- } else if msg.HandleType == Guild_Apply_All_Refused {
- //清除所有的申请
- for _, applyUid := range guild.ApplyList.ApplyGuild {
- this.RemoveRoleApplyItem(applyUid, guild.GuildBase.GuildBrief.GuildId)
- this.RemoveGuildApply(applyUid, guild)
- }
- this.SaveGuildApply(guild)
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- //删除公会的申请记录
- func (this *GuildManager) RemoveGuildApply(uid uint64, guild *GuildData) {
- if guild == nil {
- return
- }
- for idx, applyData := range guild.ApplyList.ApplyGuild {
- if applyData == uid {
- guild.ApplyList.ApplyGuild = append(guild.ApplyList.ApplyGuild[:idx], guild.ApplyList.ApplyGuild[idx+1:]...)
- }
- }
- }
- func (this *GuildManager) RemoveRoleApplyItem(uid uint64, guildId uint64) {
- applyData := this.GetRoleApplyInfo(uid)
- if applyData == nil {
- return
- }
- var change bool = false
- for idx, data := range applyData.ApplyGuild {
- if data == guildId {
- applyData.ApplyGuild = append(applyData.ApplyGuild[:idx], applyData.ApplyGuild[idx+1:]...)
- change = true
- }
- }
- if change == true {
- this.SaveRoleApplyData(uid, applyData)
- }
- }
- //删除个人申请公会记录
- func (this *GuildManager) RemoveRoleApply(uid uint64) {
- applyData := this.GetRoleApplyInfo(uid)
- if applyData == nil {
- return
- }
- //删除所有公会的申请列表数据
- for _, guildId := range applyData.ApplyGuild {
- guild := this.GetGuild(guildId)
- if guild != nil {
- this.RemoveGuildApply(uid, guild)
- this.SaveGuildApply(guild)
- }
- }
- //删除数据库中,玩家的申请数据“
- this.RemoveRoleApplyFromRedis(uid)
- //删除applyData申请列表
- delete(this.ApplyData, uid)
- }
- //处理加入
- func (this *GuildManager) HandlePlayerApply(uid uint64, guildData *GuildData) serverproto.ErrorCode {
- if guildData == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- if guildData.ApplyList == nil || len(guildData.ApplyList.ApplyGuild) <= 0 {
- return serverproto.ErrorCode_ERROR_GUILD_APPLYLIST_NOT_FOUND
- }
- count := this.GetMaxGuildMemberNum(guildData)
- if this.GetGuildMemberCount(guildData.GuildMember) >= count {
- return serverproto.ErrorCode_ERROR_GUILD_MEMBER_COUNT_MAX
- }
- //查找这个人是否有加入工会
- _, ok := this.RoleToGuilds[uid]
- if ok {
- return serverproto.ErrorCode_ERROR_GUILD_IN_GUILD
- }
- //检查是否有这个人申请
- var bApply bool = false
- for _, data := range guildData.ApplyList.ApplyGuild {
- if data == uid {
- bApply = true
- break
- }
- }
- if bApply == false {
- return serverproto.ErrorCode_ERROR_GUILD_APPLYLIST_NOT_FOUND
- }
- //将这个人加入到工会列表中
- member := &serverproto.GuildMember{
- MemberId: uid,
- Title: Guild_Title_Member,
- AddGuildTime: util.GetCurrentTime(),
- }
- guildData.GuildMember.MemberInfo = append(guildData.GuildMember.MemberInfo, member)
- this.RoleToGuilds[uid] = &serverproto.GuildIdex{
- GuildId: guildData.GuildBase.GuildBrief.GuildId,
- }
- this.SaveRoleToGuild(uid)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *GuildManager) GetGuildInfo(guildId uint64) (serverproto.ErrorCode, *serverproto.GuildBase, []*serverproto.MemberBrief) {
- guild := this.GetGuild(guildId)
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST, nil, nil
- }
- var memBrief []*serverproto.MemberBrief
- for _, data := range guild.GuildMember.MemberInfo {
- memBrief = append(memBrief, &serverproto.MemberBrief{
- Uid: data.MemberId,
- OfflineTime: data.OfflineTime,
- Title: data.Title,
- })
- }
- return serverproto.ErrorCode_ERROR_OK, guild.GuildBase, memBrief
- }
- //上线检查是否有公会通过申请
- func (this *GuildManager) CheckRoleApply(uid uint64, changeType int32, reLogin bool, ntf bool, ev rocommon.ProcEvent) {
- ackMsg := &serverproto.SSOnlineGuildInfoAck{
- Data: &serverproto.GuildNotifyData{
- Brief: &serverproto.GuildBrief{},
- },
- InGuildBattle: GuildBattleMag.IsInBattleTime(),
- }
- guildIndex, ok := this.RoleToGuilds[uid]
- if ok == false {
- if ntf == true {
- ackMsg.Data = nil
- model.ServiceReplay(ev, ackMsg)
- }
- return
- }
- guild := this.GetGuild(guildIndex.GuildId)
- if guild == nil || guild.GuildBase == nil {
- ackMsg.Data = nil
- if ntf == true {
- model.ServiceReplay(ev, ackMsg)
- }
- return
- } else {
- guildIndex := &serverproto.GuildIdex{
- GuildId: guild.GuildBase.GuildBrief.GuildId,
- }
- this.RoleToGuilds[uid] = guildIndex
- }
- if guild.GuildBase != nil {
- ackMsg.Data.Brief = guild.GuildBase.GuildBrief
- ackMsg.Data.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- }
- //记录下时间
- if guild.GuildMember != nil {
- bFind := false
- for _, data := range guild.GuildMember.MemberInfo {
- if data.MemberId == uid {
- data.OfflineTime = 0
- bFind = true
- break
- }
- }
- if bFind {
- this.SaveGuildMember(guild)
- this.GetBattleBossList(guild, ackMsg)
- this.BossRefreshNotify(guild, ev)
- } else {
- this.RemoveRoleToGuild(uid)
- ackMsg.Data = nil
- }
- }
- // this.GetBattleBossList(guild, ackMsg)
- // this.BossRefreshNotify(guild, ev)
- if reLogin == false && ntf == true {
- model.ServiceReplay(ev, ackMsg)
- }
- this.CheckNeedChangePresident(guild, true)
- }
- //公会成员上下线:changeType:1上线 2:下线
- func (this *GuildManager) MemberStateChange(uid uint64, guildId uint64, changeType int32, reLogin bool, demonFightTime uint64, ntf bool, ev rocommon.ProcEvent) {
- guild := this.GetGuild(guildId)
- if guildId == 0 || guild == nil {
- //没有公会,检查是否有过申请加入公会
- this.CheckRoleApply(uid, changeType, reLogin, ntf, ev)
- return
- }
- ackMsg := &serverproto.SSOnlineGuildInfoAck{
- Data: &serverproto.GuildNotifyData{},
- InGuildBattle: GuildBattleMag.IsInBattleTime(),
- }
- // guild := this.GetGuild(guildId)
- if guild.GuildMember == nil {
- if changeType == 1 && ntf == true {
- model.ServiceReplay(ev, ackMsg)
- }
- return
- }
- var inGuild bool = false
- for _, data := range guild.GuildMember.MemberInfo {
- if data.MemberId == uid {
- inGuild = true
- if changeType == 1 {
- data.OfflineTime = 0
- } else if changeType == 2 {
- data.OfflineTime = int64(util.GetCurrentTime())
- } else {
- if ntf == true {
- model.ServiceReplay(ev, ackMsg)
- }
- return
- }
- break
- }
- }
- //上线情况下:
- if changeType == 1 {
- //当前玩家在公会里
- if inGuild == true {
- apply := len(guild.ApplyList.ApplyGuild)
- ackMsg.Data.IsApply = false
- if apply > 0 {
- ackMsg.Data.IsApply = true
- }
- ackMsg.Data.Brief = guild.GuildBase.GuildBrief
- ackMsg.Data.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- title := this.GetMemberTitle(uid, guild)
- if title == Guild_Title_Pre || title == Guild_Title_Vice_Pre {
- this.SendGuildNotice(guild, uid, Guild_SysChat_Event_Online, title, 0)
- }
- this.BossRefreshNotify(guild, ev)
- this.GetBattleBossList(guild, ackMsg)
- ackMsg.MsgRec = append(ackMsg.MsgRec, guild.GuildMsg...)
- ackMsg.GuildSys = guild.GuildSys
- //上线校验是否有公会魔王挑战奖励
- if demonFightTime != 0 {
- this.OnlineGetDemonReward(uid, demonFightTime, ev)
- }
- } else {
- ackMsg.Data = nil
- }
- if reLogin == false && ntf == true {
- ackMsg.InGuildBattle = GuildBattleMag.IsInBattleTime()
- model.ServiceReplay(ev, ackMsg)
- util.InfoF("[MemberStateChange] online return guild info uid:%v, inGuild:%v, ackMsg:::::%v", uid, inGuild, ackMsg)
- }
- this.CheckNeedChangePresident(guild, true)
- }
- if inGuild == true {
- this.SaveGuildMember(guild)
- }
- }
- func (this *GuildManager) GetGuildMemberData(msg *serverproto.CSGuildMemberInfoReq, ackMsg *serverproto.SCGuildMemberInfoAck) serverproto.ErrorCode {
- if msg == nil || ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- guild := this.GetGuild(msg.GuildId)
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- ackMsg.GuildId = guild.GuildBase.GuildBrief.GuildId
- for _, uids := range msg.UidList {
- for _, member := range guild.GuildMember.MemberInfo {
- if uids == member.MemberId {
- memInfo := &serverproto.MemberInfo{
- Brief: &serverproto.CommonPlayerBriefInfo{},
- }
- memInfo.TotalActive = this.GetMemberActive(member)
- model2.GetSystemDataFromRedis(model2.RolePlayerBriefPrefix, member.MemberId, memInfo.Brief)
- ackMsg.MemberData = append(ackMsg.MemberData, memInfo)
- }
- }
- }
- return serverproto.ErrorCode_ERROR_OK
- }
- //玩家是否申请自己公会
- func (this *GuildManager) CheckGuildApply(uid uint64, guildId uint64) bool {
- apply := this.GetRoleApplyInfo(uid)
- if apply == nil {
- return false
- }
- for _, data := range apply.ApplyGuild {
- if data == guildId {
- return true
- }
- }
- return false
- }
- func (this *GuildManager) SearchGuild(uid uint64, searchString string, ev rocommon.ProcEvent) {
- ackMsg := &serverproto.SCSearchGuildAck{
- SearchString: searchString,
- }
- //按照名字查找,
- guildIndex, ok := this.GuildsIndex[searchString]
- if ok == true {
- guild := this.GetGuild(uint64(guildIndex.GuildId))
- if guild != nil {
- var ntfData serverproto.GuildNotifyData
- ntfData.Brief = guild.GuildBase.GuildBrief
- ntfData.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- ntfData.IsApply = this.CheckGuildApply(uid, guild.GuildBase.GuildBrief.GuildId)
- ackMsg.Data = append(ackMsg.Data, &ntfData)
- }
- }
- //按照ID查找,
- guildId2, _ := model.Str2NumU64(searchString)
- guild := this.GetGuild(guildId2)
- if guild != nil {
- //返回公会信息
- var ntfData serverproto.GuildNotifyData
- ntfData.Brief = guild.GuildBase.GuildBrief
- ntfData.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- ntfData.IsApply = this.CheckGuildApply(uid, guild.GuildBase.GuildBrief.GuildId)
- ackMsg.Data = append(ackMsg.Data, &ntfData)
- }
- model.ServiceReplay(ev, ackMsg)
- }
- func (this *GuildManager) PackRecommendGuild(uid uint64, reqCount int32, ackMsg *serverproto.SCRecommendGuildInfoAck) {
- if ackMsg == nil {
- return
- }
- //先打包申请了的公会
- var count int32 = 0
- RecommendMap := map[uint64]int32{}
- applyInfo := this.GetRoleApplyInfo(uid)
- if applyInfo != nil {
- for _, guildId := range applyInfo.ApplyGuild {
- guild := this.GetGuild(guildId)
- if guild == nil {
- //玩家申请列表中 删除这个ID
- continue
- }
- var data serverproto.GuildNotifyData
- data.Brief = guild.GuildBase.GuildBrief
- data.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- data.IsApply = true
- ackMsg.Data = append(ackMsg.Data, &data)
- count += 1
- RecommendMap[guildId] = 1
- }
- }
- //再打包其他推荐公会
- var startId int32 = 0
- if int32(len(this.RecommendGuild)) <= MaxRecommend {
- startId = 1
- } else if int32(len(this.RecommendGuild)) <= 60 && int32(len(this.RecommendGuild)) > 30 {
- if reqCount >= 2 {
- startId = int32(len(this.RecommendGuild)) - MaxRecommend + 1
- } else {
- startId = 1
- }
- } else {
- if reqCount == 3 {
- if int32(len(this.RecommendGuild)) >= 90 {
- startId = 61
- } else {
- startId = int32(len(this.RecommendGuild)) - MaxRecommend + 1
- }
- } else if reqCount == 2 {
- startId = MaxRecommend + 1
- } else if reqCount == 1 {
- startId = 1
- }
- }
- util.InfoF("uid:=%v PackRecommendGuild startId:=%v, size:%v ", uid, startId, len(this.RecommendGuild))
- //打包公会相关数据
- for idx, recommend := range this.RecommendGuild {
- if count >= MaxRecommend { //打包超过30个
- break
- }
- if int32(idx+1) < int32(startId) { //从startId开始
- continue
- }
- _, ok := RecommendMap[recommend.GuildId]
- if ok {
- continue
- }
- var bFind bool = false
- if applyInfo != nil && applyInfo.ApplyGuild != nil {
- for _, data := range applyInfo.ApplyGuild {
- if data == recommend.GuildId {
- bFind = true
- break
- }
- }
- }
- if bFind == true {
- continue
- }
- guild := this.GetGuild(recommend.GuildId)
- if guild == nil {
- continue
- }
- var data serverproto.GuildNotifyData
- data.Brief = guild.GuildBase.GuildBrief
- data.MemCount = this.GetGuildMemberCount(guild.GuildMember)
- data.IsApply = false
- ackMsg.Data = append(ackMsg.Data, &data)
- count++
- }
- util.InfoF("uid:=%v PackRecommendGuild data size := %v, reqCount:=%v", uid, ackMsg.Data, reqCount)
- }
- func (this *GuildManager) GetGuildApplyList(uid uint64, guildId uint64, ev rocommon.ProcEvent) {
- ackMsg := &serverproto.SCGuildApplyDataAck{
- Error: int32(serverproto.ErrorCode_ERROR_OK),
- }
- guild := this.GetGuild(guildId)
- if guild == nil {
- ackMsg.Error = int32(serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST)
- model.ServiceReplay(ev, ackMsg)
- return
- }
- for _, data := range guild.ApplyList.ApplyGuild {
- ackMsg.UidList = append(ackMsg.UidList, data)
- }
- model.ServiceReplay(ev, ackMsg)
- }
- func (this *GuildManager) RemoveGuildActive(member *serverproto.GuildMember) {
- if member == nil {
- return
- }
- if len(member.ActiveInfo) <= 5 {
- return
- }
- //删除最早的记录
- for i := 0; i < len(member.ActiveInfo); {
- gapDay := util.GetDurationDay1(uint64(member.ActiveInfo[i].Key), util.GetTimeMilliseconds())
- if gapDay > 4 {
- member.ActiveInfo = append(member.ActiveInfo[:i], member.ActiveInfo[i+1:]...)
- } else {
- i++
- }
- }
- }
- func (this *GuildManager) GetSelfGuildData(msg *serverproto.CSGetSelfGuildInfoReq, ackMsg *serverproto.SCGetSelfGuildInfoAck) serverproto.ErrorCode {
- if ackMsg == nil {
- return serverproto.ErrorCode_ERROR_FAIL
- }
- guild := this.GetGuild(msg.GuildId)
- if guild == nil {
- return serverproto.ErrorCode_ERROR_GUILD_NOT_EXIST
- }
- for _, data := range guild.GuildMember.MemberInfo {
- ackMsg.MemBrief = append(ackMsg.MemBrief, &serverproto.MemberBrief{
- Uid: data.MemberId,
- OfflineTime: data.OfflineTime,
- Title: data.Title,
- })
- if data.MemberId == msg.Uid {
- ackMsg.TotalActive = this.GetMemberActive(data)
- }
- }
- ackMsg.Guild_Base = guild.GuildBase
- title := this.GetMemberTitle(msg.Uid, guild)
- if title == Guild_Title_Vice_Pre || title == Guild_Title_Pre {
- if guild.ApplyList == nil || len(guild.ApplyList.ApplyGuild) <= 0 {
- ackMsg.ApplyList = false
- } else {
- ackMsg.ApplyList = true
- }
- }
- GetSelfGuildBattleData(guild.GuildBase.GuildBrief.GuildId, ackMsg)
- return serverproto.ErrorCode_ERROR_OK
- }
- func (this *GuildManager) GetMemberActive(member *serverproto.GuildMember) uint32 {
- if member == nil {
- return 0
- }
- if len(member.ActiveInfo) <= 0 {
- return 0
- }
- var totalActive uint32 = 0
- for _, data := range member.ActiveInfo {
- gapDay := util.GetDurationDay1(uint64(data.Key), util.GetTimeMilliseconds())
- if gapDay > 4 {
- continue
- }
- totalActive += uint32(data.Value)
- }
- return totalActive
- }
- func (this *GuildManager) OnRoleActivityChange(uid uint64, guildId uint64, activity int32) {
- guild := this.GetGuild(guildId)
- if guild == nil {
- return
- }
- var isMember bool = false
- //个人活跃度增加//上限在Game能判定
- for _, member := range guild.GuildMember.MemberInfo {
- if member.MemberId == uid {
- var bFind bool = false
- for index, active := range member.ActiveInfo {
- isSameDay := model.IsSameDay(int64(active.Key))
- if isSameDay == false {
- member.ActiveInfo[index].Value += activity
- bFind = true
- break
- }
- }
- if bFind == false {
- nowTime := int64(util.GetCurrentTime())
- member.ActiveInfo = append(member.ActiveInfo, &serverproto.KeyValueType64{
- Key: uint64(nowTime),
- Value: activity,
- })
- }
- if len(member.ActiveInfo) > 5 {
- this.RemoveGuildActive(member)
- }
- isMember = true
- this.SaveGuildMember(guild)
- break
- }
- }
- //公会活跃度增加
- if isMember == false {
- return
- }
- //检查当日公会活跃度是否满
- cfgData, ok := serverproto.GuildLvCfgLoader[guild.GuildBase.GuildBrief.GuildLevel]
- if !ok {
- return
- }
- //公会经验增加
- this.AddGuildExp(guild, int32(activity))
- //增加公会活跃度
- if guild.GuildBase.GuildBrief.GuildActive < uint32(cfgData.ActiveLimit) {
- // addActivity := uint32(cfgData.ActiveLimit) - guild.GuildBase.DayActive
- addActivity := uint32(cfgData.ActiveLimit) - guild.GuildBase.GuildBrief.GuildActive
- if addActivity >= uint32(activity) {
- addActivity = uint32(activity)
- }
- globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Activi_To_GuildActive)]
- if !ok {
- return
- }
- per1, per2 := model.Str2Res(globalData.SVal)
- addActivity = (addActivity * uint32(per2)) / uint32(per1)
- // guild.GuildBase.DayActive += addActivity
- guild.GuildBase.GuildBrief.GuildActive += addActivity
- }
- //只要有活跃度或者经验变动则记为活跃变动
- guild.GuildBase.ActiveTime = int64(util.GetCurrentTime())
- this.CheckAddRecommendGuild(guild)
- this.SaveGuildBase(guild)
- }
- func (this *GuildManager) AddGuildExp(guild *GuildData, activity int32) {
- if guild == nil {
- return
- }
- globalData, ok := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Max_Level)]
- if !ok {
- return
- }
- if globalData.IVal <= guild.GuildBase.GuildBrief.GuildLevel {
- return
- }
- globalData2, ok2 := serverproto.GlobalCfgLoader[int32(serverproto.GlobalType_Global_Guild_Activi_To_GuildExp)]
- if !ok2 {
- return
- }
- per1, per2 := model.Str2Res(globalData2.SVal)
- addExp := (activity / int32(per1)) * per2
- guild.GuildBase.GuildExp += uint32(addExp)
- //判定是否升级
- level := guild.GuildBase.GuildBrief.GuildLevel
- for ; level < globalData.IVal; level++ {
- cfgData, ok := serverproto.GuildLvCfgLoader[guild.GuildBase.GuildBrief.GuildLevel]
- if !ok {
- return
- }
- if guild.GuildBase.GuildExp < uint32(cfgData.ExpRequire) {
- return
- }
- guild.GuildBase.GuildBrief.GuildLevel++
- guild.GuildBase.GuildExp = guild.GuildBase.GuildExp - uint32(cfgData.ExpRequire)
- }
- //到达最大等级,修正经验
- if guild.GuildBase.GuildBrief.GuildLevel >= globalData.IVal {
- guild.GuildBase.GuildExp = 0
- }
- this.SaveGuildBase(guild)
- }
- func (this *GuildManager) GetGuildLogs(guildId uint64, logTime int64, ev rocommon.ProcEvent) {
- ackMsg := &serverproto.SCGuildLogInfoAck{}
- guild := this.GetGuild(guildId)
- if guild == nil {
- model.ServiceReplay(ev, ackMsg)
- return
- }
- if guild.GuildLogs == nil {
- this.GetGuildLog(guildId, guild)
- if guild.GuildLogs == nil {
- model.ServiceReplay(ev, ackMsg)
- return
- }
- }
- var count int32 = 0
- for _, data := range guild.GuildLogs.GuildLog {
- if logTime != 0 && data.EventTime >= uint64(logTime) {
- continue
- }
- if count >= 10 {
- break
- }
- ackMsg.Log = append(ackMsg.Log, data)
- count++
- }
- if count < 10 {
- ackMsg.IsEnd = true
- }
- model.ServiceReplay(ev, ackMsg)
- }
- func (this *GuildManager) OnGuildChat(ntfMsg *serverproto.SSGuildChatMessageNtf) {
- guild := this.GetGuild(ntfMsg.GuildId)
- if guild == nil {
- return
- }
- if len(guild.GuildMsg) >= 10 {
- guild.GuildMsg = guild.GuildMsg[1:len(guild.GuildMsg)]
- }
- guild.GuildMsg = append(guild.GuildMsg, &serverproto.MessageContentInfo{
- Type: ntfMsg.Type,
- FromId: ntfMsg.FromId,
- Message: ntfMsg.Message,
- //TargetId: ntfMsg.TargetId,
- })
- for _, data := range guild.GuildMember.MemberInfo {
- if data.OfflineTime == 0 {
- ntfMsg.UidList = append(ntfMsg.UidList, data.MemberId)
- }
- }
- SendSocial(ntfMsg)
- }
- //公会公告
- const SystemMessageType_Guild = 7 //公会公告
- func (this *GuildManager) SendGuildNotice(guild *GuildData, uid uint64, eventType, title, bossId int32) {
- if guild == nil {
- return
- }
- //发送给所有game服务器
- ssMsgNtf := &serverproto.SSGuildNoticeMessageNtf{}
- ssMsg := &serverproto.SystemMessage{
- Type: SystemMessageType_Guild,
- ParamId: []int32{eventType, title, bossId},
- SendTime: util.GetTimeMilliseconds(),
- }
- brief := &serverproto.CommonPlayerBriefInfo{}
- err := model2.GetSystemDataFromRedis(model2.RolePlayerBriefPrefix, uid, brief)
- if err == nil {
- ssMsg.NickName = brief.NickName
- }
- ssMsgNtf.SysMsg = append(ssMsgNtf.SysMsg, ssMsg)
- ssMsgNtf.GuildId = guild.GuildBase.GuildBrief.GuildId
- for _, member := range guild.GuildMember.MemberInfo {
- if member.OfflineTime == 0 {
- ssMsgNtf.UidList = append(ssMsgNtf.UidList, member.MemberId)
- }
- }
- SendSocial(ssMsgNtf)
- }
|