Finalized the mount system and the recently new skills/stats.

* Added mount options to the thing menu.
* Reworked the mounting/dismounting.
* Fixed up some skill module bugs.
* Added alerts to stats like health, mana, capacity, and regeneration time (need to revise this one as it currently has no maximum).
This commit is contained in:
BeniS 2012-08-21 00:28:19 +12:00
parent f4cc942c85
commit 1d20cc9e4b
8 changed files with 85 additions and 35 deletions

View File

@ -251,12 +251,19 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
end end
if creatureThing then if creatureThing then
local localPlayer = g_game.getLocalPlayer()
menu:addSeparator() menu:addSeparator()
if creatureThing:isLocalPlayer() then if creatureThing:isLocalPlayer() then
menu:addOption(tr('Set Outfit'), function() g_game.requestOutfit() end) menu:addOption(tr('Set Outfit'), function() g_game.requestOutfit() end)
if creatureThing:isPartyMember() --[[and not fighting]] then if not localPlayer:isMounted() then
menu:addOption(tr('Mount'), function() localPlayer:mount() end)
else
menu:addOption(tr('Dismount'), function() localPlayer:dismount() end)
end
if creatureThing:isPartyMember() then
if creatureThing:isPartyLeader() then if creatureThing:isPartyLeader() then
if creatureThing:isPartySharedExperienceActive() then if creatureThing:isPartySharedExperienceActive() then
menu:addOption(tr('Disable Shared Experience'), function() g_game.partyShareExperience(false) end) menu:addOption(tr('Disable Shared Experience'), function() g_game.partyShareExperience(false) end)
@ -268,7 +275,6 @@ function createThingMenu(menuPosition, lookThing, useThing, creatureThing)
end end
else else
local localPlayer = g_game.getLocalPlayer()
if g_game.getAttackingCreature() ~= creatureThing then if g_game.getAttackingCreature() ~= creatureThing then
menu:addOption(tr('Attack'), function() g_game.attack(creatureThing) end) menu:addOption(tr('Attack'), function() g_game.attack(creatureThing) end)
else else

View File

@ -7,13 +7,22 @@ function terminate()
end end
function toggleMount() function toggleMount()
if g_game.getFeature(GamePlayerMounts) then local player = g_game.getLocalPlayer()
g_game.mount(not g_game.isMounted()) if player then
player:toggleMount()
end
end
function mount()
local player = g_game.getLocalPlayer()
if player then
player:mount()
end end
end end
function dismount() function dismount()
if g_game.getFeature(GamePlayerMounts) then local player = g_game.getLocalPlayer()
g_game.mount(false) if player then
player:dismount()
end end
end end

View File

@ -9,6 +9,7 @@ function init()
onManaChange = onManaChange, onManaChange = onManaChange,
onSoulChange = onSoulChange, onSoulChange = onSoulChange,
onFreeCapacityChange = onFreeCapacityChange, onFreeCapacityChange = onFreeCapacityChange,
onTotalCapacityChange = onTotalCapacityChange,
onStaminaChange = onStaminaChange, onStaminaChange = onStaminaChange,
onOfflineTrainingChange = onOfflineTrainingChange, onOfflineTrainingChange = onOfflineTrainingChange,
onRegenerationChange = onRegenerationChange, onRegenerationChange = onRegenerationChange,
@ -20,8 +21,7 @@ function init()
onBaseSkillChange = onBaseSkillChange onBaseSkillChange = onBaseSkillChange
}) })
connect(g_game, { connect(g_game, {
onGameStart = refresh, onGameStart = refresh
onGameEnd = refresh
}) })
skillsWindow = g_ui.loadUI('skills.otui', modules.game_interface.getRightPanel()) skillsWindow = g_ui.loadUI('skills.otui', modules.game_interface.getRightPanel())
@ -40,6 +40,7 @@ function terminate()
onManaChange = onManaChange, onManaChange = onManaChange,
onSoulChange = onSoulChange, onSoulChange = onSoulChange,
onFreeCapacityChange = onFreeCapacityChange, onFreeCapacityChange = onFreeCapacityChange,
onTotalCapacityChange = onTotalCapacityChange,
onStaminaChange = onStaminaChange, onStaminaChange = onStaminaChange,
onOfflineTrainingChange = onOfflineTrainingChange, onOfflineTrainingChange = onOfflineTrainingChange,
onRegenerationChange = onRegenerationChange, onRegenerationChange = onRegenerationChange,
@ -60,6 +61,12 @@ function terminate()
skillsWindow:destroy() skillsWindow:destroy()
end end
function resetSkillColor(id)
local skill = skillsWindow:recursiveGetChildById(id)
local widget = skill:getChildById('value')
widget:setColor('#bbbbbb')
end
function setSkillBase(id, value, baseValue) function setSkillBase(id, value, baseValue)
if baseValue < 1 or value < 1 then if baseValue < 1 or value < 1 then
return return
@ -68,13 +75,13 @@ function setSkillBase(id, value, baseValue)
local widget = skill:getChildById('value') local widget = skill:getChildById('value')
if value > baseValue then if value > baseValue then
widget:setColor('#008b00') widget:setColor('#008b00') -- green
skill:setTooltip(baseValue .. ' + ' .. (value - baseValue)) skill:setTooltip(baseValue .. ' + ' .. (value - baseValue))
elseif value < baseValue then elseif value < baseValue then
widget:setColor('#008b00') widget:setColor('#b22222') -- red
skill:setTooltip(baseValue .. ' - ' .. (value - baseValue)) skill:setTooltip(baseValue .. ' - ' .. (value - baseValue))
else else
widget:setColor('#bbbbbb') widget:setColor('#bbbbbb') -- default
skill:removeTooltip() skill:removeTooltip()
end end
end end
@ -107,6 +114,18 @@ function setSkillPercent(id, percent, tooltip)
end end
end end
function checkAlert(id, value, maxValue, threshold)
if value > maxValue or maxValue < 1 then
return
end
local percent = math.floor((value / maxValue) * 100)
if percent < threshold then
setSkillColor(id, '#b22222') -- red
else
resetSkillColor(id)
end
end
function update() function update()
local offlineTraining = skillsWindow:recursiveGetChildById('offlineTraining') local offlineTraining = skillsWindow:recursiveGetChildById('offlineTraining')
if not g_game.getFeature(GameOfflineTrainingTime) then if not g_game.getFeature(GameOfflineTrainingTime) then
@ -138,8 +157,6 @@ function refresh()
onOfflineTrainingChange(player, player:getOfflineTrainingTime()) onOfflineTrainingChange(player, player:getOfflineTrainingTime())
onRegenerationChange(player, player:getRegenerationTime()) onRegenerationChange(player, player:getRegenerationTime())
onSpeedChange(player, player:getSpeed()) onSpeedChange(player, player:getSpeed())
onBaseSpeedChange(player, player:getBaseSpeed())
onBaseMagicLevelChange(player, player:getBaseMagicLevel())
for i=0,6 do for i=0,6 do
onSkillChange(player, i, player:getSkillLevel(i), player:getSkillLevelPercent(i)) onSkillChange(player, i, player:getSkillLevel(i), player:getSkillLevelPercent(i))
@ -186,10 +203,12 @@ end
function onHealthChange(localPlayer, health, maxHealth) function onHealthChange(localPlayer, health, maxHealth)
setSkillValue('health', tr(health)) setSkillValue('health', tr(health))
checkAlert('health', health, maxHealth, 30)
end end
function onManaChange(localPlayer, mana, maxMana) function onManaChange(localPlayer, mana, maxMana)
setSkillValue('mana', tr(mana)) setSkillValue('mana', tr(mana))
checkAlert('mana', mana, maxMana, 30)
end end
function onSoulChange(localPlayer, soul) function onSoulChange(localPlayer, soul)
@ -198,6 +217,11 @@ end
function onFreeCapacityChange(localPlayer, freeCapacity) function onFreeCapacityChange(localPlayer, freeCapacity)
setSkillValue('capacity', freeCapacity) setSkillValue('capacity', freeCapacity)
checkAlert('capacity', freeCapacity, localPlayer:getTotalCapacity(), 20)
end
function onTotalCapacityChange(localPlayer, totalCapacity)
checkAlert('capacity', localPlayer:getFreeCapacity(), totalCapacity, 20)
end end
function onStaminaChange(localPlayer, stamina) function onStaminaChange(localPlayer, stamina)
@ -228,7 +252,7 @@ function onOfflineTrainingChange(localPlayer, offlineTrainingTime)
end end
function onRegenerationChange(localPlayer, regenerationTime) function onRegenerationChange(localPlayer, regenerationTime)
if not g_game.getFeature(GamePlayerRegenerationTime) then if not g_game.getFeature(GamePlayerRegenerationTime) or regenerationTime < 0 then
return return
end end
local hours = math.floor(regenerationTime / 60) local hours = math.floor(regenerationTime / 60)
@ -238,45 +262,37 @@ function onRegenerationChange(localPlayer, regenerationTime)
end end
setSkillValue('regenerationTime', hours .. ":" .. minutes) setSkillValue('regenerationTime', hours .. ":" .. minutes)
checkAlert('regenerationTime', regenerationTime, 30, 20) -- what is max regeneration?
end end
function onSpeedChange(localPlayer, speed) function onSpeedChange(localPlayer, speed)
setSkillValue('speed', speed) setSkillValue('speed', speed)
setSkillBase('speed', speed, localPlayer:getBaseSpeed()) onBaseSpeedChange(localPlayer, localPlayer:getBaseSpeed())
end end
function onBaseSpeedChange(localPlayer, baseSpeed) function onBaseSpeedChange(localPlayer, baseSpeed)
local speed = localPlayer:getSpeed() setSkillBase('speed', localPlayer:getSpeed(), baseSpeed)
onSpeedChange(localPlayer, baseSpeed)
setSkillBase('speed', speed, baseSpeed)
end end
function onMagicLevelChange(localPlayer, magiclevel, percent) function onMagicLevelChange(localPlayer, magiclevel, percent)
setSkillValue('magiclevel', magiclevel) setSkillValue('magiclevel', magiclevel)
setSkillPercent('magiclevel', percent, tr('You have %s percent to go', 100 - percent)) setSkillPercent('magiclevel', percent, tr('You have %s percent to go', 100 - percent))
setSkillBase('magiclevel', magiclevel, localPlayer:getBaseMagicLevel()) onBaseMagicLevelChange(localPlayer, localPlayer:getBaseMagicLevel())
end end
function onBaseMagicLevelChange(localPlayer, baseMagicLevel) function onBaseMagicLevelChange(localPlayer, baseMagicLevel)
local magiclevel = localPlayer:getMagicLevel() setSkillBase('magiclevel', localPlayer:getMagicLevel(), baseMagicLevel)
onMagicLevelChange(localPlayer, magiclevel, localPlayer:getMagicLevelPercent())
setSkillBase('magiclevel', magiclevel, baseMagicLevel)
end end
function onSkillChange(localPlayer, id, level, percent) function onSkillChange(localPlayer, id, level, percent)
setSkillValue('skillId' .. id, level) setSkillValue('skillId' .. id, level)
setSkillPercent('skillId' .. id, percent, tr('You have %s percent to go', 100 - percent)) setSkillPercent('skillId' .. id, percent, tr('You have %s percent to go', 100 - percent))
setSkillBase('skillId'..id, level, localPlayer:getSkillBaseLevel(id)) onBaseSkillChange(localPlayer, id, localPlayer:getSkillBaseLevel(id))
end end
function onBaseSkillChange(localPlayer, id, baseLevel) function onBaseSkillChange(localPlayer, id, baseLevel)
local level = localPlayer:getSkillLevel(id) setSkillBase('skillId'..id, localPlayer:getSkillLevel(id), baseLevel)
onSkillChange(localPlayer, id, level, localPlayer:getSkillLevelPercent(id))
setSkillBase('skillId'..id, level, baseLevel)
end end

View File

@ -54,3 +54,26 @@ function Player:hasVip(creatureName)
end end
return false return false
end end
function Player:isMounted()
local outfit = self:getOutfit()
return outfit.mount ~= nil and outfit.mount > 0
end
function Player:toggleMount()
if g_game.getFeature(GamePlayerMounts) then
g_game.mount(not self:isMounted())
end
end
function Player:mount()
if g_game.getFeature(GamePlayerMounts) then
g_game.mount(true)
end
end
function Player:dismount()
if g_game.getFeature(GamePlayerMounts) then
g_game.mount(false)
end
end

View File

@ -53,7 +53,6 @@ void Game::resetGameStates()
m_online = false; m_online = false;
m_denyBotCall = false; m_denyBotCall = false;
m_dead = false; m_dead = false;
m_mounted = false;
m_serverBeat = 50; m_serverBeat = 50;
m_seq = 0; m_seq = 0;
m_canReportBugs = false; m_canReportBugs = false;
@ -1079,7 +1078,6 @@ void Game::mount(bool mount)
return; return;
m_protocolGame->sendMountStatus(mount); m_protocolGame->sendMountStatus(mount);
m_mounted = mount;
} }
void Game::requestItemInfo(const ItemPtr& item, int index) void Game::requestItemInfo(const ItemPtr& item, int index)

View File

@ -251,7 +251,6 @@ public:
bool isDead() { return m_dead; } bool isDead() { return m_dead; }
bool isAttacking() { return !!m_attackingCreature; } bool isAttacking() { return !!m_attackingCreature; }
bool isFollowing() { return !!m_followingCreature; } bool isFollowing() { return !!m_followingCreature; }
bool isMounted() { return m_mounted; }
ContainerPtr getContainer(int index) { return m_containers[index]; } ContainerPtr getContainer(int index) { return m_containers[index]; }
std::map<int, ContainerPtr> getContainers() { return m_containers; } std::map<int, ContainerPtr> getContainers() { return m_containers; }
@ -288,7 +287,6 @@ private:
bool m_online; bool m_online;
bool m_denyBotCall; bool m_denyBotCall;
bool m_dead; bool m_dead;
bool m_mounted;
int m_serverBeat; int m_serverBeat;
uint m_seq; uint m_seq;
Otc::FightModes m_fightMode; Otc::FightModes m_fightMode;

View File

@ -199,7 +199,6 @@ void OTClient::registerLuaFunctions()
g_lua.bindSingletonFunction("g_game", "isDead", &Game::isDead, &g_game); g_lua.bindSingletonFunction("g_game", "isDead", &Game::isDead, &g_game);
g_lua.bindSingletonFunction("g_game", "isAttacking", &Game::isAttacking, &g_game); g_lua.bindSingletonFunction("g_game", "isAttacking", &Game::isAttacking, &g_game);
g_lua.bindSingletonFunction("g_game", "isFollowing", &Game::isFollowing, &g_game); g_lua.bindSingletonFunction("g_game", "isFollowing", &Game::isFollowing, &g_game);
g_lua.bindSingletonFunction("g_game", "isMounted", &Game::isMounted, &g_game);
g_lua.bindSingletonFunction("g_game", "getContainer", &Game::getContainer, &g_game); g_lua.bindSingletonFunction("g_game", "getContainer", &Game::getContainer, &g_game);
g_lua.bindSingletonFunction("g_game", "getContainers", &Game::getContainers, &g_game); g_lua.bindSingletonFunction("g_game", "getContainers", &Game::getContainers, &g_game);
g_lua.bindSingletonFunction("g_game", "getVips", &Game::getVips, &g_game); g_lua.bindSingletonFunction("g_game", "getVips", &Game::getVips, &g_game);
@ -380,6 +379,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassMemberFunction<LocalPlayer>("setStates", &LocalPlayer::setStates); g_lua.bindClassMemberFunction<LocalPlayer>("setStates", &LocalPlayer::setStates);
g_lua.bindClassMemberFunction<LocalPlayer>("setSkill", &LocalPlayer::setSkill); g_lua.bindClassMemberFunction<LocalPlayer>("setSkill", &LocalPlayer::setSkill);
g_lua.bindClassMemberFunction<LocalPlayer>("setHealth", &LocalPlayer::setHealth); g_lua.bindClassMemberFunction<LocalPlayer>("setHealth", &LocalPlayer::setHealth);
g_lua.bindClassMemberFunction<LocalPlayer>("setTotalCapacity", &LocalPlayer::setTotalCapacity);
g_lua.bindClassMemberFunction<LocalPlayer>("setFreeCapacity", &LocalPlayer::setFreeCapacity); g_lua.bindClassMemberFunction<LocalPlayer>("setFreeCapacity", &LocalPlayer::setFreeCapacity);
g_lua.bindClassMemberFunction<LocalPlayer>("setExperience", &LocalPlayer::setExperience); g_lua.bindClassMemberFunction<LocalPlayer>("setExperience", &LocalPlayer::setExperience);
g_lua.bindClassMemberFunction<LocalPlayer>("setLevel", &LocalPlayer::setLevel); g_lua.bindClassMemberFunction<LocalPlayer>("setLevel", &LocalPlayer::setLevel);

View File

@ -1465,7 +1465,7 @@ Outfit ProtocolGame::getOutfit(const InputMessagePtr& msg)
} }
if(g_game.getFeature(Otc::GamePlayerMounts)) { if(g_game.getFeature(Otc::GamePlayerMounts)) {
int mount = msg->getU16(); // mount int mount = msg->getU16();
outfit.setMount(mount); outfit.setMount(mount);
} }