⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp_and_level.lua

📁 top web admin panel (tales of pirates)
💻 LUA
📖 第 1 页 / 共 3 页
字号:

--此处放置经验值和级别有关的计算

InTeamGetExp_RAID = 1

--创建工会的物品检测
function AskGuildItem(role,Guild_type)
	local gold = GetChaAttr(role,ATTR_GD)
	local fame = GetChaAttr(role,ATTR_FAME) 
	local attr_guild = HasGuild ( role ) 
	if attr_guild ~= 0 then 
		HelpInfo(role,0,"已有所属工会")
		--SystemNotice(role,0,"已有所属工会")
		return 0 
	end 
	local Lv = Lv ( role )
	if Lv < 40 then
		SystemNotice ( role , "等级不足40级,无法创建" )
		return 0
	end

	if Guild_type == 1 then						--判定海盗工会
		if Guild2_ItemMax > 0 then
			for i = 1 , Guild2_ItemMax , 1 do
				local K = Check_BagItem(role,Guild2_item[i],Guild2_count[i])
				if K == 0 then
					HelpInfo(role,0,"道具不足无法创建")
					--SystemNotice(role,0,"道具不足无法创建")
					return 0
				end
			end
		end

		if gold < Guild2_Gold then
			HelpInfo(role,0,"金钱不足无法创建")
			--SystemNotice(role,0,"金钱不足无法创建")
			return 0
		end
		if fame < Guild2_fame then
			HelpInfo(role,0,"声望不足无法创建")
			--SystemNotice(role,0,"声望不足无法创建")
			return 0
		end
	elseif Guild_type == 0 then					--判定海军工会
		if Guild1_ItemMax > 0 then
			for i = 1 , Guild1_ItemMax , 1 do
				local K = Check_BagItem(role,Guild1_item[i],Guild1_count[i])
				if K == 0 then
					HelpInfo(role,0,"道具不足无法创建")
					--SystemNotice(role,0,"道具不足无法创建")
					return 0
				end
			end
		end
		if gold < Guild1_Gold then
			HelpInfo(role,0,"金钱不足无法创建")
			--SystemNotice(role,0,"金钱不足无法创建")
			return 0
		end
		if fame < Guild1_fame then
			HelpInfo(role,0,"声望不足无法创建")
			--SystemNotice(role,0,"声望不足无法创建")
			return 0
		end
	else
		--LG("checkguild","工会类型错误  Guild_type = ",Guild_type)
	end
	return 1
end 

function Check_BagItem(role,a,b)		--检查背包数量是否足够
	local a = CheckBagItem ( role , a ) 
	if a>= b then 
		return 1 
	else 
		return 0 
	end 
end 
		


--删除创建工会所需物品
function DeductGuildItem(role,Guild_type)
	local gold = GetChaAttr(role,ATTR_GD)
	local fame = GetChaAttr(role,ATTR_FAME) 
	local attr_guild = HasGuild ( role )  
--	if attr_guild ~= 0 then 
--		HelpInfo(role,0,"已有所属工会") 
		--SystemNotice(role,0,"已有所属工会") 
--		return 0 
--	end 

	if Guild_type == 1 then						--判定海盗工会
--		if Guild2_ItemMax > 0 then
--			for i = 1 ,Guild2_ItemMax,1 do
--				local K = DelBagItem(role,Guild2_item[i],Guild2_count[i])
--			end
--		end
		DelBagItem(role,1780,1)	
		gold = gold - Guild2_Gold
		fame = fame - Guild2_fame
		SetAttrChangeFlag ( role )

		SetChaAttr(role,ATTR_GD,gold)
		SetChaAttr(role,ATTR_FAME,fame)

		SyncChar( role, 4 )
	
	elseif Guild_type == 0	then					--判定海军工会
--		if Guild1_ItemMax > 0 then
--			for i = 1 ,Guild1_ItemMax,1 do
--				local K = DelBagItem(role,Guild1_item[i],Guild1_count[i])
--			end
--		end
		DelBagItem(role,1780,1)	
		gold = gold - Guild1_Gold
		fame = fame - Guild1_fame
		SetAttrChangeFlag ( role )

		SetChaAttr(role,ATTR_GD,gold)
		SetChaAttr(role,ATTR_FAME,fame)

		SyncChar( role, 4 )
	else
		--LG("checkguild","工会类型错误  Guild_type = ",Guild_type)
	end

end
	

function AskJoinGuild ( role , guild_type ) 					-- 申请加入工会判定   工会类型 0-海军,1-海盗
	local attr_guild = HasGuild ( role )  
	if attr_guild ~= 0 then 
		HelpInfo(role,0,"已有所属工会") 
		--SystemNotice(role,0,"已有所属工会") 
		return 0 
	end 
--	local fame = GetChaAttr ( role , ATTR_FAME ) 
--	if guild_type == 0 then 
--		if fame < JOINGUILD_NAVY_FAME then 
--			HelpInfo(role,0,"海军名声不足") 
--			--SystemNotice(role,0,"海军名声不足") 
--			return 0 
--		end 
--	elseif guild_type == 1 then 
--		if fame > JOINGUILD_PIRATE_FAME then 
--			HelpInfo(role,0,"海盗名声不足") 
--			--SystemNotice(role,0,"海盗名声不足") 
--			return 0 
--		end 
--	end 
	return 1 
end 

			



--经验分配(包含组队经验分配)
--当有角色死亡时被调用
function GetExp_New(dead , atk  ) 
	if ValidCha(atk) == 0  then 
		LG ( "exp_atker=NIL" , "function GetExp_New : atker = nil " ) 
		return 
	end 
	--SystemNotice ( atk , "进入GetExp_New")

	--LuaPrint("Enter function GetExp() --[[经验值获得公式1、正常杀怪 2、人物被怪物杀死 3、人物正常pk死亡 4、无经验奖惩]]--") 
	local a = Check_Combat_Mod(dead , atk ) 
	if a==1 then 
	--LG("exp" , " enter  pkm mod" ) 
	GetExp_PKM( dead , atk ) --[[player kill monster]]--
	elseif a==2 then 
	--LG("exp" , " enter  mkp mod" ) 
	GetExp_MKP(dead , atk) --[[monster kill player]]--
	elseif a==3 then 
	--LG("exp" , " enter  pkp mod" ) 
	GetExp_PKP(dead , atk) --[[player kill player]]--
	elseif a==4 then 
	--LG("exp" , " enter  mkm mod" ) 
	GetExp_Noexp(dead , atk) --[[monster kill monster]]--
	else 
	--LuaPrint("无法判定经验获得模式".."\n") return 
	end 
end 









function Check_Combat_Mod(dead , atk) --[[判定经验奖惩方式]]-- 
	--LuaPrint("Enter function Check_Combat_Mod () --[[判定经验奖惩方式]]-- ") 
	local rolemod_atker = IsPlayer(atk) 
	--LG("exp" , " atker role = " ,  rolemod_atker ) 
	local rolemod_defer = IsPlayer(dead)  --检查角色种类:0、怪物, 1、玩家
	--LG("exp" , " defer role = " ,  rolemod_defer ) 
	if (rolemod_atker==0) and (rolemod_defer==0) then 
		return 4 
	elseif rolemod_atker==0 and rolemod_defer==1 then 
		return 2 
	elseif rolemod_atker==1 and rolemod_defer==0 then 
		return 1 
	elseif rolemod_atker==1 and rolemod_defer==1 then 
		return 3 
	else 
		--LuaPrint("错误的角色类型值".."\n") 
		return 
	end 
	--LuaPrint("Out function Check_Combat_Mod () --[[判定经验奖惩方式]]-- ") 
end 




function GetExp_PKM( dead , atk  ) --[[player kill monster 经验值获得公式 所得exp=exp(d)/math.floor(|lv(a)-lv(b)|*0.1+1)]]--
--	LG ( "exp" , " enter getexp " ) 
	--SystemNotice ( atk , "进入GetExp_PKM")
--	local EXP_RAID_STATE = 1
--	local StateLv = GetChaStateLv ( atk , STATE_SBJYGZ )
	
--	if StateLv >= 0 and StateLv <= 10 then
--			EXP_RAID_STATE = StateLv + 1
--	end

	local dead_lv = GetChaAttrI( dead , ATTR_LV ) --获得死者的等级   
	local dead_exp = GetChaAttrI( dead , ATTR_CEXP ) * EXP_RAID
	LG("exp" , "deadlv = " , dead_lv ) 
	LG("exp" , "dead_exp = " , dead_exp ) 
	local k = {} 
	local kdmg = {} 
	local k_exp = {} 

	k[0] , kdmg[0] = GetChaHarmByNo ( dead , 0 ) 
--	if ValidCha ( k[0] ) == 0 then 
--		SystemNotice ( atk , "伤害列表首位为空" ) 
--	end 
	--SystemNotice ( atk , "攻击伤害排位0号") 
	--SystemNotice ( atk , "攻击伤害为"..kdmg[0]) 

	k[1] , kdmg[1] = GetChaHarmByNo ( dead , 1 ) 
--	if ValidCha ( k[1] ) == 0 then 
--		SystemNotice ( atk , "伤害列表2位为空" ) 
--	end 
	--SystemNotice ( atk , "攻击伤害排位1号") 
	--SystemNotice ( atk , "攻击伤害为"..kdmg[1]) 

	k[2] , kdmg[2] = GetChaHarmByNo ( dead , 2 ) 
--	if ValidCha ( k[2] ) == 0 then 
--		SystemNotice ( atk , "伤害列表3位为空" ) 
--	end 
	--SystemNotice ( atk , "攻击伤害排位2号") 
	--SystemNotice ( atk , "攻击伤害为"..kdmg[2]) 

	k[3] , kdmg[3] = GetChaHarmByNo ( dead , 3 ) 
--	if ValidCha ( k[3] ) == 0 then 
--		SystemNotice ( atk , "伤害列表4位为空" ) 
--	end 
	--SystemNotice ( atk , "攻击伤害排位3号") 
	--SystemNotice ( atk , "攻击伤害为"..kdmg[3]) 

	k[4] , kdmg[4] = GetChaHarmByNo ( dead , 4 ) 
--	if ValidCha ( k[4] ) == 0 then 
--		SystemNotice ( atk , "伤害列表5位为空" ) 
--	end 
	--SystemNotice ( atk , "攻击伤害排位4号") 
	--SystemNotice ( atk , "攻击伤害为"..kdmg[4]) 
	local first_atker = GetFirstAtker ( dead ) 
	
	local Gen_dmg = 0 

	for i = 0 , 4 , 1 do 
		if k[i] ~= 0 then 
			Gen_dmg = Gen_dmg + kdmg[i] 
			--SystemNotice ( atk , "攻击伤害指针不为0的排位"..i) 
			--SystemNotice ( atk , "攻击伤害为"..kdmg[i]) 
		end 
	end 
	--SystemNotice ( atk , "总攻击伤害为"..Gen_dmg) 
	for i = 0 , 4 , 1 do 
		k_exp[i] = 0 

		if ValidCha( k[i] )== 1 then 
			if kdmg[i] > 0 then 
				if k[i] == first_atker then 
					k_exp[i] = dead_exp * ( 0.7 * kdmg[i] / Gen_dmg + 0.3 )		--第一位攻击者优先获得30%的怪物总经验
				else
					k_exp[i] =  dead_exp * 0.7 * kdmg[i] / Gen_dmg 
				end
				--SystemNotice ( atk , "攻击伤害排位"..i) 
				--SystemNotice ( atk , "分配到exp"..k_exp[i]) 
				ShareTeamExp ( dead , k[i] , k_exp[i] ,atk ) 
			end 
		end 
	end 
	local item_host = 0 
	local exp_max = k_exp[0] 
	--SystemNotice ( atk , "道具初始归属排位"..0) 
	for i = 1 , 4 , 1 do 
		--SystemNotice ( atk , "道具归属判定"..i) 
		--SystemNotice ( atk , "经验份额"..k_exp[i])

		if k_exp [i] > exp_max  then 
			exp_max = k_exp[i] 
			item_host = i 
			--SystemNotice ( atk , "道具更改归属排位"..i) 
		end 
	end 
	if ChaIsBoat (k[item_host] ) == 1 then 

		local ship_lv = GetChaAttr ( k[item_host] , ATTR_LV ) 
		local shipowner_lv  = GetChaAttr ( TurnToCha ( k[item_host] ) , ATTR_LV )  
		local ship_exp = GetChaAttr ( k[item_host] , ATTR_CEXP ) 
		local ship_expadd = math.floor ( math.min ( 7 , ( dead_lv / 10 + 2 ) ) ) 
		local lv_limit = math.min ( ship_lv , shipowner_lv ) - 10 
		if dead_lv >= lv_limit then 
			ship_exp = ship_exp + ship_expadd 
			SetCharaAttr (  ship_exp , k[item_host] ,ATTR_CEXP ) 
--			SystemNotice ( k[item_host] , "增加船只熟练"..ship_expadd ) 

		end 
	end 
	SetItemHost ( dead , k[item_host] ) 

end 


function ValidCha(ter)
  if ter==nil or ter==0 then 
	return 0 
  end
  return 1
end

function ShareTeamExp ( dead , team_atker , dead_exp , The_Killer) 
	local cha_name1100 = GetChaDefaultName (team_atker )	
	local star111=GetChaAttr (  team_atker , ATTR_CEXP )----------当前等级经验
	LG("star_exp" , "玩家"..cha_name1100.."当前经验为"..star111.."进入ShareTeamExp" ) 
	local atker_role = ChaIsBoat ( team_atker ) 
	local monster_location = IsChaInLand ( dead ) 
	if atker_role == 1 and monster_location == 1 then 
		dead_exp = math.floor ( dead_exp / 5 + 1 ) 
	end 

	--SystemNotice ( team_atker , "进入ShareTeamExp")

	local dead_lv = GetChaAttrI( dead , ATTR_LV )			--获得死者的等级   
	--local team_atker = TurnToCha ( team_atker )				--转成人指针
	local t = {} 
	t[0] = team_atker  
	if ValidCha (team_atker) == 0 then 
		LG ( "luascript_err" , "function ShareTeamExp : 队伍经验来源者为空" ) 
		return 
	end 
	t[1] = GetTeamCha(team_atker, 0 )  
	t[2] = GetTeamCha(team_atker, 1 )   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -