Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在线泡经验 #20

Open
najoast opened this issue May 30, 2023 · 2 comments
Open

在线泡经验 #20

najoast opened this issue May 30, 2023 · 2 comments
Labels
脚本 设计 游戏设计相关

Comments

@najoast
Copy link
Owner

najoast commented May 30, 2023

功能概述

玩家在线期间,会定时获得经验。
获得经验的数量和等级无关,从始至终获得经验的速度都一样。

设计目的

  • 减轻升级负担,让玩家可以更轻松的升级。
  • 鼓励玩家在线。

数值

  • 期望值:玩家什么都不做的情况下,挂机满100小时,可以升到满级
  • 根据这篇文档,335版本玩家升到满级,大概需要16625400 点经验,根据我们的期望值,得出每秒给玩家的经验值 = 16625400 / (100*3600) = 46 点
  • 每5秒给一次经验,每次给经验 = 46 * 5 = 230

代码

https://github.com/najoast/eluna_scripts/blob/master/src/online_give_xp.lua

@najoast najoast added 脚本 设计 游戏设计相关 labels May 30, 2023
@sjg01
Copy link

sjg01 commented Jul 29, 2023

lua链接失效了。

@najoast
Copy link
Owner Author

najoast commented Aug 3, 2023

--[[
* 设计:https://github.com/najoast/qzms_forum/issues/1
* 作者:全栈君
* B站: 全栈游戏开发 https://space.bilibili.com/389407601
* 时间:2023-5-30 17:02:52
]]

local playerId2EventId = {}

local function RemoveEvent(player)
	local eventId = playerId2EventId[player:GetGUIDLow()]
	if eventId then
		-- print("移除事件ID", eventId)
		player:RemoveEventById(eventId)
		playerId2EventId[player:GetGUIDLow()] = nil
	end
end

local function OnTimer(event, delay, repeats, player)
	if player:GetLevel() >= 80 then
		RemoveEvent(player)
		return
	end
	player:GiveXP(230)
	-- print(string.format("玩家 %s 获得了 230 点经验", player:GetName()))
end

--- @param player Player
local function OnPlayerLogin(event, player)
	-- print(string.format("玩家 %s 上线了,等级 %d, GUIDLow %d", player:GetName(), player:GetLevel(), player:GetGUIDLow()))
	if player:GetLevel() >= 80 then
		return
	end
	local eventId = player:RegisterEvent(OnTimer, 5000, 0)
	-- print("注册事件ID", eventId)
	playerId2EventId[player:GetGUIDLow()] = eventId
end

local function OnPlayerLogout(event, player)
	-- print(string.format("玩家 %s 下线了,等级 %d, GUIDLow %d", player:GetName(), player:GetLevel(), player:GetGUIDLow()))
	RemoveEvent(player)
end

-- LOGIN
RegisterPlayerEvent(3, OnPlayerLogin)
RegisterPlayerEvent(4, OnPlayerLogout)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
脚本 设计 游戏设计相关
Projects
None yet
Development

No branches or pull requests

2 participants