diff --git a/data/lib/core/constants.lua b/data/lib/core/constants.lua index 66196b959c..65aada9491 100644 --- a/data/lib/core/constants.lua +++ b/data/lib/core/constants.lua @@ -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 diff --git a/data/scripts/network/cyclopedia_character.lua b/data/scripts/network/cyclopedia_character.lua index ec27ef6663..09b2dd0800 100644 --- a/data/scripts/network/cyclopedia_character.lua +++ b/data/scripts/network/cyclopedia_character.lua @@ -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()) @@ -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 ]]-- } diff --git a/src/luascript.cpp b/src/luascript.cpp index 6a65a46b4a..bfdd7e606a 100644 --- a/src/luascript.cpp +++ b/src/luascript.cpp @@ -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); @@ -8955,6 +8957,18 @@ int LuaScriptInterface::luaPlayerGetLevel(lua_State* L) return 1; } +int LuaScriptInterface::luaPlayerGetLevelPercent(lua_State* L) +{ + // player:getLevelPercent() + Player* player = getUserdata(L, 1); + if (player) { + lua_pushnumber(L, player->getLevelPercent()); + } else { + lua_pushnil(L); + } + return 1; +} + int LuaScriptInterface::luaPlayerGetMagicLevel(lua_State* L) { // player:getMagicLevel() @@ -8967,6 +8981,18 @@ int LuaScriptInterface::luaPlayerGetMagicLevel(lua_State* L) return 1; } +int LuaScriptInterface::luaPlayerGetMagicLevelPercent(lua_State* L) +{ + // player:getMagicLevelPercent() + Player* player = getUserdata(L, 1); + if (player) { + lua_pushnumber(L, player->getMagicLevelPercent()); + } else { + lua_pushnil(L); + } + return 1; +} + int LuaScriptInterface::luaPlayerGetBaseMagicLevel(lua_State* L) { // player:getBaseMagicLevel() diff --git a/src/luascript.h b/src/luascript.h index d26b599a3f..b11fd37286 100644 --- a/src/luascript.h +++ b/src/luascript.h @@ -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);