2023-09-12 17:32:05 +08:00

131 lines
3.0 KiB
Go

package main
type GuildMember struct {
AccountId string
Level int32 // 1: 会长, 20: 副会长, 30: 精英, 40 成员
}
type Guild struct {
AutoId int64 // 公会自增id
GuildId int64 // 公会id
Name string // 公会名称
LeaderId string // 公会leader
Avatar int32 // 头像
Notice string // 公告
JoinCond int32 // 公会加入条件
JoinCondValue int32 // 公会加入条件值
TotalStars int32 // 总星星数量
TotalKills int32 // 单局总击杀数
ChickenDinners int32 // 单局第一名数
MaxMembers int32 // 公会最大成员数 default 30
Members []*GuildMember
PendingReqs map[string]int32 // pendingAccountId -> status 0,1,2,3 pending, accept, reject, leave
}
// GuildLog 公会日志
type GuildLog struct {
GuildId int64
AccountId string
LogType int32
Content string
}
// PendingReq 待审核请求
type PendingReq struct {
AccountId string
Status int32 // 0 pending, 1 ok, 2 reject, 3 disband
}
func (g *Guild) GetGuildId() int64 {
return g.GuildId
}
func (g *Guild) GetMembersCount() int {
return len(g.Members)
}
func (g *Guild) GetMembers() []*GuildMember {
return g.Members
}
// findMemberIndex 根据 AccountId 查找成员在 Members 切片中的索引
func (g *Guild) findMemberIndex(accountId string) int {
for i, member := range g.Members {
if member.AccountId == accountId {
return i
}
}
return -1
}
// GetMember 根据 AccountId 获取成员信息
func (g *Guild) GetMember(accountId string) *GuildMember {
index := g.findMemberIndex(accountId)
if index == -1 {
return nil
}
return g.Members[index]
}
// IsMember 是否是公会成员
func (g *Guild) IsMember(accountId string) bool {
return g.findMemberIndex(accountId) >= 0
}
// IsFull 成员是否已满
func (g *Guild) IsFull() bool {
return int32(len(g.Members)) >= g.MaxMembers
}
// AddMember 添加成员
func (g *Guild) AddMember(member *GuildMember) {
g.Members = append(g.Members, member)
}
// RemoveMember 移除成员
func (g *Guild) RemoveMember(accountId string) {
if accountId == g.LeaderId {
return
}
index := g.findMemberIndex(accountId)
if index == -1 {
return
}
copy(g.Members[index:], g.Members[index+1:])
g.Members[len(g.Members)-1] = nil
g.Members = g.Members[:len(g.Members)-1]
}
func (g *Guild) SetNotice(notice *string) {
g.Notice = *notice
}
func (g *Guild) GetNotice() string {
return g.Notice
}
// AddPendingReq 添加等待审核成员
func (g *Guild) AddPendingReq(p *PendingReq) {
g.PendingReqs[p.AccountId] = p.Status
}
func (g *Guild) GetPendingReqStatus(accountId string) int32 {
if pendingReqStatus, exists := g.PendingReqs[accountId]; exists {
return pendingReqStatus
}
return -1
}
// RemovePendingReq 移除等待审核成员
func (g *Guild) RemovePendingReq(accountId string) {
delete(g.PendingReqs, accountId)
}
func (gm *GuildMember) GetAccountId() string {
return gm.AccountId
}
func (g *Guild) IsInReq(accountId string) bool {
return g.PendingReqs[accountId] == PendingReqIsJoinGuildStatusJoined
}