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

feat: cyclopedia general stats and badges #4540

Merged
merged 3 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data/lib/core/constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ SCREENSHOT_TYPE_SKILLUP = 12

SCREENSHOT_TYPE_FIRST = SCREENSHOT_TYPE_ACHIEVEMENT
SCREENSHOT_TYPE_LAST = SCREENSHOT_TYPE_SKILLUP

CYCLOPEDIA_SKILL_MAGIC = 1
CYCLOPEDIA_SKILL_SHIELDING = 6
CYCLOPEDIA_SKILL_DISTANCE = 7
CYCLOPEDIA_SKILL_SWORD = 8
CYCLOPEDIA_SKILL_CLUB = 9
CYCLOPEDIA_SKILL_AXE = 10
CYCLOPEDIA_SKILL_FIST = 11
CYCLOPEDIA_SKILL_FISHING = 13

CYCLOPEDIA_SKILL_AMOUNT = 8
95 changes: 91 additions & 4 deletions data/scripts/network/cyclopedia_character.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,77 @@ local function sendCombatStats(self, msg)
return true
end

local clientSkillsId = {
[0] = CYCLOPEDIA_SKILL_FIST,
[1] = CYCLOPEDIA_SKILL_CLUB,
[2] = CYCLOPEDIA_SKILL_SWORD,
[3] = CYCLOPEDIA_SKILL_AXE,
[4] = CYCLOPEDIA_SKILL_DISTANCE,
[5] = CYCLOPEDIA_SKILL_SHIELDING,
[6] = CYCLOPEDIA_SKILL_FISHING
}

local function sendGeneralStats(self, msg)
msg:addU64(self:getExperience())
msg:addU16(self:getLevel())
msg:addByte(self:getLevelPercent())

msg:addU16(self:getClientExpDisplay())
msg:addU32(0) -- tournament exp (deprecated)
msg:addU16(self:getClientLowLevelBonusDisplay())
msg:addU16(0) -- store exp bonus
msg:addU16(self:getClientStaminaBonusDisplay())
msg:addU16(0) -- exp boost remaining time
msg:addByte(0) -- enable exp boost store button

msg:addU16(self:getHealth())
msg:addU16(self:getMaxHealth())
msg:addU16(self:getMana())
msg:addU16(self:getMaxMana())
msg:addByte(self:getSoul())
msg:addU16(self:getStamina())

local foodTime = 0
local condition = self:getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT)
if condition then
foodTime = condition:getTicks() / 1000
end

msg:addU16(foodTime)
msg:addU16(self:getOfflineTrainingTime() / 60 / 1000)
msg:addU16(self:getSpeed() / 2)
msg:addU16(self:getBaseSpeed() / 2)

local infiniteCapacity = self:hasFlag(PlayerFlag_HasInfiniteCapacity) and 1000000
msg:addU32(infiniteCapacity or self:getCapacity()) -- base + bonus capacity
msg:addU32(infiniteCapacity or self:getCapacity())
msg:addU32(infiniteCapacity or self:getFreeCapacity())

msg:addByte(CYCLOPEDIA_SKILL_AMOUNT)

msg:addByte(CYCLOPEDIA_SKILL_MAGIC)
msg:addU16(self:getMagicLevel())
msg:addU16(self:getBaseMagicLevel())
msg:addU16(self:getBaseMagicLevel()) -- base + loyalty bonus
msg:addU16(self:getMagicLevelPercent() * 100)

for i = SKILL_FIST, SKILL_FISHING, 1 do
msg:addByte(clientSkillsId[i])
msg:addU16(self:getEffectiveSkillLevel(i))
msg:addU16(self:getSkillLevel(i))

-- base + loyalty bonus
msg:addU16(self:getSkillLevel(i))
msg:addU16(self:getSkillPercent(i) * 100)
end

msg:addByte(0) -- magic boost (element and value)

msg:sendToPlayer(self)
msg:delete()
return true
end

local function sendAchievements(self, msg)
local achievementIds = self:getAchievements()
msg:addU16(self:getAchievementPoints())
Expand All @@ -100,36 +171,52 @@ local function sendAchievements(self, msg)
return true
end

local function sendBadges(self, msg)
msg:addByte(0x01) -- show account info
msg:addByte(0x01) -- account online
msg:addByte(self:isPremium() and 1 or 0)
msg:addString("") -- loyalty title

msg:addByte(0) -- badges count
-- structure:
-- u32 badge id
-- string badge name

msg:sendToPlayer(self)
msg:delete()
return true
end

local BASIC_INFO = 0x00
local GENERAL_STATS = 0x01
local COMBAT_STATS = 0x02
local ACHIEVEMENTS = 0x05
local BADGES = 0x0A

--[[
local GENERAL_STATS = 0x01
local RECENT_DEATHS = 0x03
local RECENT_PVP_KILLS = 0x04
local ITEM_SUMMARY = 0x06
local APPEARANCES = 0x07
local STORE = 0x08
local INSPECTION = 0x09
local BADGES = 0x0A
local TITLES = 0x0B
]]--

local handlers = {
[BASIC_INFO] = sendBasicInfo,
[GENERAL_STATS] = sendGeneralStats,
[COMBAT_STATS] = sendCombatStats,
[ACHIEVEMENTS] = sendAchievements,
[BADGES] = sendBadges,

--[[
[GENERAL_STATS] = sendGeneralStats,
[RECENT_DEATHS] = sendRecentDeaths,
[RECENT_PVP_KILLS] = sendRecentPvpKills,
[ITEM_SUMMARY] = sendItemSummary,
[APPEARANCES] = sendAppearances,
[STORE] = sendStore,
[INSPECTION] = sendInspection,
[BADGES] = sendBadges,
[TITLES] = sendTitles
]]--
}
Expand Down
26 changes: 26 additions & 0 deletions src/luascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2587,8 +2587,10 @@ void LuaScriptInterface::registerFunctions()
registerMethod("Player", "addExperience", LuaScriptInterface::luaPlayerAddExperience);
registerMethod("Player", "removeExperience", LuaScriptInterface::luaPlayerRemoveExperience);
registerMethod("Player", "getLevel", LuaScriptInterface::luaPlayerGetLevel);
registerMethod("Player", "getLevelPercent", LuaScriptInterface::luaPlayerGetLevelPercent);

registerMethod("Player", "getMagicLevel", LuaScriptInterface::luaPlayerGetMagicLevel);
registerMethod("Player", "getMagicLevelPercent", LuaScriptInterface::luaPlayerGetMagicLevelPercent);
registerMethod("Player", "getBaseMagicLevel", LuaScriptInterface::luaPlayerGetBaseMagicLevel);
registerMethod("Player", "getMana", LuaScriptInterface::luaPlayerGetMana);
registerMethod("Player", "addMana", LuaScriptInterface::luaPlayerAddMana);
Expand Down Expand Up @@ -8955,6 +8957,18 @@ int LuaScriptInterface::luaPlayerGetLevel(lua_State* L)
return 1;
}

int LuaScriptInterface::luaPlayerGetLevelPercent(lua_State* L)
{
// player:getLevelPercent()
Player* player = getUserdata<Player>(L, 1);
if (player) {
lua_pushnumber(L, player->getLevelPercent());
} else {
lua_pushnil(L);
}
return 1;
}

int LuaScriptInterface::luaPlayerGetMagicLevel(lua_State* L)
{
// player:getMagicLevel()
Expand All @@ -8967,6 +8981,18 @@ int LuaScriptInterface::luaPlayerGetMagicLevel(lua_State* L)
return 1;
}

int LuaScriptInterface::luaPlayerGetMagicLevelPercent(lua_State* L)
{
// player:getMagicLevelPercent()
Player* player = getUserdata<Player>(L, 1);
if (player) {
lua_pushnumber(L, player->getMagicLevelPercent());
} else {
lua_pushnil(L);
}
return 1;
}

int LuaScriptInterface::luaPlayerGetBaseMagicLevel(lua_State* L)
{
// player:getBaseMagicLevel()
Expand Down
2 changes: 2 additions & 0 deletions src/luascript.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,10 @@ class LuaScriptInterface
static int luaPlayerAddExperience(lua_State* L);
static int luaPlayerRemoveExperience(lua_State* L);
static int luaPlayerGetLevel(lua_State* L);
static int luaPlayerGetLevelPercent(lua_State* L);

static int luaPlayerGetMagicLevel(lua_State* L);
static int luaPlayerGetMagicLevelPercent(lua_State* L);
static int luaPlayerGetBaseMagicLevel(lua_State* L);
static int luaPlayerGetMana(lua_State* L);
static int luaPlayerAddMana(lua_State* L);
Expand Down
Loading