组队和公会系统的功能实现

本文详细介绍了游戏开发中的组队和公会系统功能实现,包括组队数据结构、创建队伍、申请加入、邀请加入、公会基本结构及公会管理等关键环节,提供了一整套游戏社交功能的实现方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


放一起讲是觉得这两个功能比较类似,区别是公会数据保存在数据库里

组队数据结构

服务器队伍类,组队数据仅在内存中使用,如果做成支付宝种树,叠猫猫那类持久组队,可以新建张数据表

function TeamMgr:Init()
	self.teamlist = {
   }
	self.singlePersion = {
   }
end

玩家队伍数据

local Team = oo.class()
local _TEAM_MEM_NUM = 5 --一个队伍最多有5个成员,包括仙君和玩家--

function Team:ctor(teamid,player,targetid)
	self.teamid = teamid
	self.leader = player
	self.targetid = targetid
	self.cfgid = math.floor(targetid / 1000)
	self.index =  targetid % 1000
	self.isAuto = 1--是否进行自动匹配	 
	if self.targetid == 0 then
		self.isAuto = 0--是否进行自动匹配
	end
	self.memlist = {
   player}
	self.xianjunlist = {
   }
	self.levelRange = {
   0,1000}
	--self.xianjunStar = 0
end

组队功能

组队事件

注册onJoinTeam入队和onLeaveTeam离队方法

function TeamPerson:ctor(player,targetid)
	self.player = player
	self.targetid = targetid
	self.cfgid = math.floor(targetid / 1000)
end

function TeamPerson:init()	
	self.config = server.configCenter.TeamTargetConfig[self.cfgid]
	if not self.config then 
		return false
	end	
	self.m_joinTeamE = self.player:SubEvent(server.enEvent.PlayerEvnt.EVENTID_ENTITY_JION_TEAM,self.onJoinTeam,self)
	self.m_leaveTeamE = self.player:SubEvent(server.enEvent.PlayerEvnt.EVENTID_ENTITY_LEAVE_TEAM,self.onLeaveTeam,self)
	return true
end
--示例
function TeamPerson:onLeaveTeam(args)
	if args.entityID ~= self.player.entityID then
		return
	end
	--删除定时器
	if self.del_timer  then 
		lua_app.del_timer(self.del_timer)
		self.del_timer =  nil
	end 
end

创建队伍

function TeamMgr:createTeam(player,targetid)
	if player.prop.teamid ~= 0 then --已经有队伍不能再次创建
		return false
	end
	local teamid =  _Cur_TeamID + 1
	local team =  Team.new(teamid,player,targetid)
	if team and team:init(true) then
		_Cur_TeamID = teamid
		self.teamlist[teamid] = team
	else
		return false
	end
	--触发入队事件
	local args = {
   }
	args.entityID = player.entityID  --创建队伍
	args.teamid = teamid
	args.EventID = server.enEvent.PlayerEvnt.EVENTID_ENTITY_JION_TEAM
	player:FireEvent(args.EventID,args)
	local function  _matchTeam()
		if self.matchTime then
			lua_app.del_timer(self.matchTime)
		end
		if next(self.singlePersion) then
			self:doMatch() 
		end
		self.matchTime =  lua_app.add_timer(5000, _matchTeam)
	end
	if not self.matchTime then
		self.matchTime =  lua_app.add_timer(5000, _matchTeam)
	end
	--存在目标的的可以进行发送超链接
	if targetid and targetid > 0 then
		local info = team:getTargetInfo()		
		local players = {
   }
		for _, actor in pairs(server.playerCenter:GetOnlinePlayers()) do
			if actor.prop.level >= team.levelRange[1] and 
			actor.prop.level <= team.levelRange[2] then
				table.insert(players,actor)
			end
		end
	server.chatCenter:SendLink2SomePalyers(1320,player,players,info.activeName,info.rangeName,
		{
   server.ChatLinkType.team,teamid,player.entityID,"申请组队"})
	end 
	return true
end

申请加入队伍

与客户端通信协议

--[[
#请求加入队伍
cs_team_jointeam 17002 {
   
	request {
    
	teamid	0 : integer
	}
}

]]
function server.cs_team_jointeam(socketid, msg)
    local player = server.playerCenter:GetPlayerBySocket(socketid)
    server.teamMgr:joinTeam(msg.teamid,player.entityID)
end

服务器验证队伍信息

function TeamMgr:joinTeam(teamid,entityID)
	local player  = server.gameEntityCenter:GetEntityByID(entityID)
	if not player then
		return false
	end
	local team = self.teamlist[teamid]
	if not team then
		--链接已经失效
		server.chatCenter:sendTipMsg(1321,player.dbid)
		return false
	end
	if player.prop.teamid ~= 0 then
		server.sendErr(player, "你已经有队伍了")
		
欢迎使用睿博!魔兽世界公会系统(RB!DKP),本系统为网络游戏魔兽世界玩家公会用网站平台,您可以使用本系统快速建立属于您自己的公会网站。系统主体部分为DKP系统,DKP系统拥有完善的功能,支持市面上主流的记分/查分插件,方便、快捷、准确的DKP记录及处理使您在公会管理中事半功倍,辅助性公会公告/制度/语音等自由方便的在线编辑设计,使您不需要懂得网站设计也能完善自己的公会网站,免费稳定的系统升级,保证了系统的持久稳定发展,系统完美支持魔兽世界国服/台服,祝您使用愉快。 睿博!魔兽世界发展历史:   2005年,魔兽世界国服公测,我们发布了SP.WoWSystem ,为全球首套ASP平台的DKP系统(当时全球范围内只有PHP平台的EQDKP系统),也是国内第一套自主DKP系统;   2008年,魔兽世界国服发布燃烧的远征,我们发布了LS!DKP ,更进一步完善系统以配合新的游戏格局需求;   2009年,魔兽世界全球发布巫妖王之怒,我们发布了RB!DKP系统(定名,订立系统所属睿博软件),并制定了本系统的发展规划,定制了系统的发展方向,确保了系统的更新及技术支持,完全重写所有代码,建立了更加完善的DKP系统模式,完美支持更多的插件,并完美支持国服/台服;   我们会再接再厉,使系统更加完善、功能更贴近公会网站的发展需求,并持续对相关插件进行同步更新,再次感谢您对睿博!魔兽世界公会系统(RB!DKP)的支持。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值