From e2655d95dec8300d80866be616a5daa3450e2cbd Mon Sep 17 00:00:00 2001 From: kervala Date: Tue, 24 May 2016 11:24:36 +0200 Subject: [PATCH] Fixed: Inconsistent EOL --- .../data/gamedev/syui_v3/syui/player.lua | 1760 ++++++++--------- .../client/data/gamedev/syui_v3/syui/syui.lua | 864 ++++---- 2 files changed, 1312 insertions(+), 1312 deletions(-) diff --git a/code/ryzom/client/data/gamedev/syui_v3/syui/player.lua b/code/ryzom/client/data/gamedev/syui_v3/syui/player.lua index c1a0106e1..0dd4db07b 100644 --- a/code/ryzom/client/data/gamedev/syui_v3/syui/player.lua +++ b/code/ryzom/client/data/gamedev/syui_v3/syui/player.lua @@ -10,109 +10,109 @@ end ------------------------------------------------------------------------------------------------------------ -- create the game namespace without reseting if already created in an other file. -if (game==nil) then - game= {}; -end - -if (game.PVP == nil) then - game.PVP = {}; - game.PVP.tagStartTimer = 0; - game.PVP.flagStartTimer = 0; - game.PVP.tagTimerStarted = false; - game.PVP.flagTimerStarted = false; -end - -if (game.BonusMalus == nil) then - game.BonusMalus = {}; - game.BonusMalus.DeathPenaltyBefore = -1; - game.BonusMalus.DeathPenaltyAfter = -1; - game.BonusMalus.XPCatSlotBefore = -1; - game.BonusMalus.XPCatSlotAfter = -1; - game.BonusMalus.RingXPCatSlotBefore = -1; - game.BonusMalus.RingXPCatSlotAfter = -1; - game.BonusMalus.OutpostSlotBefore = -1; - game.BonusMalus.OutpostSlotAfter = -1; - game.BonusMalus.BonusAHList= {}; - game.BonusMalus.MalusAHList= {}; -end - - ------------------------------------------------------------------------------------------------------------- --- Update player bars in function of what we wants to display (we can hide each one of the 3 bars : sap,stamina and focus) -function game:updatePlayerBars() - - local dispSap = getDbProp('UI:SAVE:PLAYER:DISP_SAP'); - local dispSta = getDbProp('UI:SAVE:PLAYER:DISP_STA'); - local dispFoc = getDbProp('UI:SAVE:PLAYER:DISP_FOC'); - - local ui = getUI('ui:interface:player:content'); - - -- active ui in function of what is displayed - - ui.b_sap.active = (dispSap == 1); - ui.jsap.active = (dispSap == 1); - - ui.b_sta.active = (dispSta == 1); - ui.jsta.active = (dispSta == 1); - - ui.b_foc.active = (dispFoc == 1); - ui.jfoc.active = (dispFoc == 1); - - -- choose good y-position - - local totalBarDisp = dispSap + dispSta + dispFoc; - if (totalBarDisp == 3) then - - ui.b_sap.y = -18; - ui.b_sta.y = -36; - ui.b_foc.y = -54; - ui.current_action.y = -65; - - elseif (totalBarDisp == 2) then - - if (dispSap == 0) then - ui.b_sta.y = -18; - ui.b_foc.y = -36; - end - - if (dispSta == 0) then - ui.b_sap.y = -18; - ui.b_foc.y = -36; - end - - if (dispFoc == 0) then - ui.b_sap.y = -18; - ui.b_sta.y = -36; - end - - ui.current_action.y = -50; - - elseif (totalBarDisp == 1) then - - ui.b_sta.y = -18; - ui.b_foc.y = -18; - ui.b_sta.y = -18; - - ui.current_action.y = -35; - - else - ui.current_action.y = -18; - end - - -end - - ------------------------------------------------------------------------------------------------------------- --- convert a boolean to a number 0 or 1 -function booleanToNumber(thebool) - if(thebool) then - return 1; - else - return 0; - end -end - +if (game==nil) then + game= {}; +end + +if (game.PVP == nil) then + game.PVP = {}; + game.PVP.tagStartTimer = 0; + game.PVP.flagStartTimer = 0; + game.PVP.tagTimerStarted = false; + game.PVP.flagTimerStarted = false; +end + +if (game.BonusMalus == nil) then + game.BonusMalus = {}; + game.BonusMalus.DeathPenaltyBefore = -1; + game.BonusMalus.DeathPenaltyAfter = -1; + game.BonusMalus.XPCatSlotBefore = -1; + game.BonusMalus.XPCatSlotAfter = -1; + game.BonusMalus.RingXPCatSlotBefore = -1; + game.BonusMalus.RingXPCatSlotAfter = -1; + game.BonusMalus.OutpostSlotBefore = -1; + game.BonusMalus.OutpostSlotAfter = -1; + game.BonusMalus.BonusAHList= {}; + game.BonusMalus.MalusAHList= {}; +end + + +------------------------------------------------------------------------------------------------------------ +-- Update player bars in function of what we wants to display (we can hide each one of the 3 bars : sap,stamina and focus) +function game:updatePlayerBars() + + local dispSap = getDbProp('UI:SAVE:PLAYER:DISP_SAP'); + local dispSta = getDbProp('UI:SAVE:PLAYER:DISP_STA'); + local dispFoc = getDbProp('UI:SAVE:PLAYER:DISP_FOC'); + + local ui = getUI('ui:interface:player:content'); + + -- active ui in function of what is displayed + + ui.b_sap.active = (dispSap == 1); + ui.jsap.active = (dispSap == 1); + + ui.b_sta.active = (dispSta == 1); + ui.jsta.active = (dispSta == 1); + + ui.b_foc.active = (dispFoc == 1); + ui.jfoc.active = (dispFoc == 1); + + -- choose good y-position + + local totalBarDisp = dispSap + dispSta + dispFoc; + if (totalBarDisp == 3) then + + ui.b_sap.y = -18; + ui.b_sta.y = -36; + ui.b_foc.y = -54; + ui.current_action.y = -65; + + elseif (totalBarDisp == 2) then + + if (dispSap == 0) then + ui.b_sta.y = -18; + ui.b_foc.y = -36; + end + + if (dispSta == 0) then + ui.b_sap.y = -18; + ui.b_foc.y = -36; + end + + if (dispFoc == 0) then + ui.b_sap.y = -18; + ui.b_sta.y = -36; + end + + ui.current_action.y = -50; + + elseif (totalBarDisp == 1) then + + ui.b_sta.y = -18; + ui.b_foc.y = -18; + ui.b_sta.y = -18; + + ui.current_action.y = -35; + + else + ui.current_action.y = -18; + end + + +end + + +------------------------------------------------------------------------------------------------------------ +-- convert a boolean to a number 0 or 1 +function booleanToNumber(thebool) + if(thebool) then + return 1; + else + return 0; + end +end + ------------------------------------------------------------------------------------------------------------ -- Update player pvp tag function game:pvpTagUpdateDisplay() @@ -122,110 +122,110 @@ function game:pvpTagUpdateDisplay() local uiPlayer= getUI('ui:interface:player:header_opened'); -- get the current state - local pvpServerFlag= pvpServerFlagTimer > currentServerTick; - local pvpLocalTag= (getDbProp('UI:TEMP:PVP_FACTION:TAG_PVP') == 1); - local pvpServerTag= (getDbProp('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:TAG_PVP') == 1); - local pvpServerActivateTimerOn= pvpServerTagTimer > currentServerTick; - - -- deduce the display state according to the current state - local GREEN= 0; - local ORANGE= 1; - local RED= 2; - local buttonMode= GREEN; - local buttonPushed= false; - local buttonTimer= false; - -- if the flag is activated, then must display PVP flag button and timer - if (pvpServerFlag) then - -- ** RED MODE - buttonMode= RED; - buttonPushed= false; - buttonTimer= true; - -- else must display correct mode according to the TAG state - else - -- There are 8 possibilities according to the combination of the 3 flags - -- Here: TL= pvpLocalTag, TS= pvpServerTag, AS= pvpServerActivateTimerOn) - -- TL TS AS - -- ** GREEN MODE ** - -- 0 0 0 -> Standard disabled PVP - -- 1 0 0 -> The user pressed the button but still no response from server - -- 1 1 1 -> The user pressed the button and got response from server. => GREEN icon with timer - -- 0 1 1 -> The user canceled the activation (server not acked yet the cancel). => default display - -- ** ORANGE MODE ** - -- 1 1 0 -> Standard enabled PVP - -- 0 1 0 -> The user pressed the button but still no response from server - -- 0 0 1 -> The user pressed the button and got response from server. => ORANGE icon with timer - -- 1 0 1 -> The user canceled the activation (server not acked yet the cancel). => default display - - -- From this table, we can deduce the following rules - - -- buttonMode is GREEN when TS==AS - if( pvpServerTag == pvpServerActivateTimerOn ) then - buttonMode= GREEN; - else - buttonMode= ORANGE; - end - - -- the button is pushed if (there is a timer and TL==TS), or (no timer and TL!=TS) - if( pvpServerActivateTimerOn == (pvpLocalTag == pvpServerTag) ) then - buttonPushed= true; - else - buttonPushed= false; - end - - -- display a timer only if the timer is activated and server and local tag are equals - if( pvpServerActivateTimerOn and pvpLocalTag == pvpServerTag ) then - buttonTimer= true; - else - buttonTimer= false; - end - - end - - -- setup the local display - setDbProp("UI:TEMP:PVP_FACTION:DSP_MODE", buttonMode); - setDbProp("UI:TEMP:PVP_FACTION:DSP_PUSHED", booleanToNumber(buttonPushed)); - setDbProp("UI:TEMP:PVP_FACTION:DSP_TIMER", booleanToNumber(buttonTimer)); - - -- setup the timer bar - if(buttonTimer) then - local uiBar = uiPlayer.pvp_timer; - local uiBarBg = uiPlayer.pvp_timer_bg; - -- Flag Bar? - if(buttonMode==RED) then - -- display a reverse timer - uiBar.w = uiBarBg.w * (pvpServerFlagTimer - currentServerTick) / (pvpServerFlagTimer - game.PVP.flagStartTimer); - else - -- display a forward timer - uiBar.w = uiBarBg.w * (currentServerTick - game.PVP.tagStartTimer) / (pvpServerTagTimer - game.PVP.tagStartTimer); - end - end - - -- force update of the tooltip for any button (by disabling then reenabling) - disableContextHelpForControl(uiPlayer.pvp_tag_button_0); - disableContextHelpForControl(uiPlayer.pvp_tag_button_1); - disableContextHelpForControl(uiPlayer.pvp_tag_button_2); -end - ------------------------------------------------------------------------------------------------------------- --- Update player pvp tag -function game:pvpTag() - local buttonStat = getDbProp('UI:TEMP:PVP_FACTION:TAG_PVP'); - if (buttonStat == 0) then - setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP',1); - else - setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP',0); - end - sendMsgToServerPvpTag(buttonStat == 0); - - -- update display - self:pvpTagUpdateDisplay(); -end - ------------------------------------------------------------------------------------------------------------- --- Update button due to server validation -function game:updatePvpTag() - -- force copy to temp of Server tag - local pvpServerTag= (getDbProp('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:TAG_PVP') == 1); + local pvpServerFlag= pvpServerFlagTimer > currentServerTick; + local pvpLocalTag= (getDbProp('UI:TEMP:PVP_FACTION:TAG_PVP') == 1); + local pvpServerTag= (getDbProp('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:TAG_PVP') == 1); + local pvpServerActivateTimerOn= pvpServerTagTimer > currentServerTick; + + -- deduce the display state according to the current state + local GREEN= 0; + local ORANGE= 1; + local RED= 2; + local buttonMode= GREEN; + local buttonPushed= false; + local buttonTimer= false; + -- if the flag is activated, then must display PVP flag button and timer + if (pvpServerFlag) then + -- ** RED MODE + buttonMode= RED; + buttonPushed= false; + buttonTimer= true; + -- else must display correct mode according to the TAG state + else + -- There are 8 possibilities according to the combination of the 3 flags + -- Here: TL= pvpLocalTag, TS= pvpServerTag, AS= pvpServerActivateTimerOn) + -- TL TS AS + -- ** GREEN MODE ** + -- 0 0 0 -> Standard disabled PVP + -- 1 0 0 -> The user pressed the button but still no response from server + -- 1 1 1 -> The user pressed the button and got response from server. => GREEN icon with timer + -- 0 1 1 -> The user canceled the activation (server not acked yet the cancel). => default display + -- ** ORANGE MODE ** + -- 1 1 0 -> Standard enabled PVP + -- 0 1 0 -> The user pressed the button but still no response from server + -- 0 0 1 -> The user pressed the button and got response from server. => ORANGE icon with timer + -- 1 0 1 -> The user canceled the activation (server not acked yet the cancel). => default display + + -- From this table, we can deduce the following rules + + -- buttonMode is GREEN when TS==AS + if( pvpServerTag == pvpServerActivateTimerOn ) then + buttonMode= GREEN; + else + buttonMode= ORANGE; + end + + -- the button is pushed if (there is a timer and TL==TS), or (no timer and TL!=TS) + if( pvpServerActivateTimerOn == (pvpLocalTag == pvpServerTag) ) then + buttonPushed= true; + else + buttonPushed= false; + end + + -- display a timer only if the timer is activated and server and local tag are equals + if( pvpServerActivateTimerOn and pvpLocalTag == pvpServerTag ) then + buttonTimer= true; + else + buttonTimer= false; + end + + end + + -- setup the local display + setDbProp("UI:TEMP:PVP_FACTION:DSP_MODE", buttonMode); + setDbProp("UI:TEMP:PVP_FACTION:DSP_PUSHED", booleanToNumber(buttonPushed)); + setDbProp("UI:TEMP:PVP_FACTION:DSP_TIMER", booleanToNumber(buttonTimer)); + + -- setup the timer bar + if(buttonTimer) then + local uiBar = uiPlayer.pvp_timer; + local uiBarBg = uiPlayer.pvp_timer_bg; + -- Flag Bar? + if(buttonMode==RED) then + -- display a reverse timer + uiBar.w = uiBarBg.w * (pvpServerFlagTimer - currentServerTick) / (pvpServerFlagTimer - game.PVP.flagStartTimer); + else + -- display a forward timer + uiBar.w = uiBarBg.w * (currentServerTick - game.PVP.tagStartTimer) / (pvpServerTagTimer - game.PVP.tagStartTimer); + end + end + + -- force update of the tooltip for any button (by disabling then reenabling) + disableContextHelpForControl(uiPlayer.pvp_tag_button_0); + disableContextHelpForControl(uiPlayer.pvp_tag_button_1); + disableContextHelpForControl(uiPlayer.pvp_tag_button_2); +end + +------------------------------------------------------------------------------------------------------------ +-- Update player pvp tag +function game:pvpTag() + local buttonStat = getDbProp('UI:TEMP:PVP_FACTION:TAG_PVP'); + if (buttonStat == 0) then + setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP',1); + else + setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP',0); + end + sendMsgToServerPvpTag(buttonStat == 0); + + -- update display + self:pvpTagUpdateDisplay(); +end + +------------------------------------------------------------------------------------------------------------ +-- Update button due to server validation +function game:updatePvpTag() + -- force copy to temp of Server tag + local pvpServerTag= (getDbProp('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:TAG_PVP') == 1); setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP', booleanToNumber(pvpServerTag)); -- launch timer DB if necessary @@ -235,27 +235,27 @@ function game:updatePvpTag() if(pvpServerTagTimer > currentServerTick) or (pvpServerFlagTimer > currentServerTick) then local ui = getUI('ui:interface:player'); - addOnDbChange(ui,'@UI:VARIABLES:CURRENT_SERVER_TICK', 'game:updatePvpTimer()'); - - if(pvpServerTagTimer > currentServerTick and game.PVP.tagTimerStarted == false) then - game.PVP.tagStartTimer = currentServerTick; - game.PVP.tagTimerStarted = true; - end - if(pvpServerFlagTimer > currentServerTick and game.PVP.flagTimerStarted == false) then - game.PVP.flagStartTimer = currentServerTick; - game.PVP.flagTimerStarted = true; - end - end - - -- update display (after start timer reseted) - self:pvpTagUpdateDisplay(); -end - ------------------------------------------------------------------------------------------------------------- --- -function game:updatePvpTimer() - - -- update display + addOnDbChange(ui,'@UI:VARIABLES:CURRENT_SERVER_TICK', 'game:updatePvpTimer()'); + + if(pvpServerTagTimer > currentServerTick and game.PVP.tagTimerStarted == false) then + game.PVP.tagStartTimer = currentServerTick; + game.PVP.tagTimerStarted = true; + end + if(pvpServerFlagTimer > currentServerTick and game.PVP.flagTimerStarted == false) then + game.PVP.flagStartTimer = currentServerTick; + game.PVP.flagTimerStarted = true; + end + end + + -- update display (after start timer reseted) + self:pvpTagUpdateDisplay(); +end + +------------------------------------------------------------------------------------------------------------ +-- +function game:updatePvpTimer() + + -- update display self:pvpTagUpdateDisplay(); -- try to stop @@ -265,44 +265,44 @@ function game:updatePvpTimer() -- Manage Tag Timer display if(pvpServerTagTimer <= currentServerTick) then - game.PVP.tagTimerStarted = false; - end - - -- Manage Flag Timer display - if(pvpServerFlagTimer <= currentServerTick) then - game.PVP.flagTimerStarted = false; - end - - -- if both off, stop the db update - if(game.PVP.tagTimerStarted == false) and (game.PVP.flagTimerStarted == false) then - removeOnDbChange(getUI('ui:interface:player'),'@UI:VARIABLES:CURRENT_SERVER_TICK'); - end -end - ------------------------------------------------------------------------------------------------------------- --- -function game:formatTime(temps) - - local hours = math.floor(temps/(10*60*60)); - local minutes = math.floor((temps - (hours*10*60*60)) / (10*60)); - local seconds = math.floor((temps - (hours*10*60*60) - (minutes*10*60)) / 10); - - local fmt = i18n.get('uittPvPTime'); - fmt = findReplaceAll(fmt, '%h', tostring(hours)); - fmt = findReplaceAll(fmt, '%m', tostring(minutes)); - fmt = findReplaceAll(fmt, '%s', tostring(seconds)); - return fmt; -end - ------------------------------------------------------------------------------------------------------------- --- -function game:playerTTPvp() - - -- The tooltip to display depends on the current display state - local buttonMode= getDbProp("UI:TEMP:PVP_FACTION:DSP_MODE"); - local buttonPushed= (getDbProp("UI:TEMP:PVP_FACTION:DSP_PUSHED")==1); - local buttonTimer= (getDbProp("UI:TEMP:PVP_FACTION:DSP_TIMER")==1); - local text; + game.PVP.tagTimerStarted = false; + end + + -- Manage Flag Timer display + if(pvpServerFlagTimer <= currentServerTick) then + game.PVP.flagTimerStarted = false; + end + + -- if both off, stop the db update + if(game.PVP.tagTimerStarted == false) and (game.PVP.flagTimerStarted == false) then + removeOnDbChange(getUI('ui:interface:player'),'@UI:VARIABLES:CURRENT_SERVER_TICK'); + end +end + +------------------------------------------------------------------------------------------------------------ +-- +function game:formatTime(temps) + + local hours = math.floor(temps/(10*60*60)); + local minutes = math.floor((temps - (hours*10*60*60)) / (10*60)); + local seconds = math.floor((temps - (hours*10*60*60) - (minutes*10*60)) / 10); + + local fmt = i18n.get('uittPvPTime'); + fmt = findReplaceAll(fmt, '%h', tostring(hours)); + fmt = findReplaceAll(fmt, '%m', tostring(minutes)); + fmt = findReplaceAll(fmt, '%s', tostring(seconds)); + return fmt; +end + +------------------------------------------------------------------------------------------------------------ +-- +function game:playerTTPvp() + + -- The tooltip to display depends on the current display state + local buttonMode= getDbProp("UI:TEMP:PVP_FACTION:DSP_MODE"); + local buttonPushed= (getDbProp("UI:TEMP:PVP_FACTION:DSP_PUSHED")==1); + local buttonTimer= (getDbProp("UI:TEMP:PVP_FACTION:DSP_TIMER")==1); + local text; -- Flag mode? if(buttonMode==2) then @@ -311,19 +311,19 @@ function game:playerTTPvp() local tempsString = game:formatTime( pvpServerFlagTimer - currentServerTick ); text = i18n.get('uittPvPModeFlag'); text = findReplaceAll(text, '%temps', tempsString); - -- Tag mode - else - -- base text - if(buttonMode==0 and not(buttonPushed)) then - text = i18n.get('uittPvPModeTagOff'); - elseif(buttonMode==0 and buttonPushed) then - text = i18n.get('uittPvPModeTagOffChange'); - elseif(buttonMode==1 and not(buttonPushed)) then - text = i18n.get('uittPvPModeTagOn'); - elseif(buttonMode==1 and buttonPushed) then - text = i18n.get('uittPvPModeTagOnChange'); - else - text = ucstring(); + -- Tag mode + else + -- base text + if(buttonMode==0 and not(buttonPushed)) then + text = i18n.get('uittPvPModeTagOff'); + elseif(buttonMode==0 and buttonPushed) then + text = i18n.get('uittPvPModeTagOffChange'); + elseif(buttonMode==1 and not(buttonPushed)) then + text = i18n.get('uittPvPModeTagOn'); + elseif(buttonMode==1 and buttonPushed) then + text = i18n.get('uittPvPModeTagOnChange'); + else + text = ucstring(); end -- timer if(buttonTimer) then @@ -332,80 +332,80 @@ function game:playerTTPvp() local tempsString = game:formatTime( pvpServerTagTimer - currentServerTick ); local timeFmt= i18n.get('uittPvPTagTimer'); timeFmt= findReplaceAll(timeFmt, '%temps', tempsString); - text= concatUCString(text, timeFmt); - end - end - - -- set the text - setContextHelpText(text); -end - - - --- *************************************************************************** --- *************************************************************************** --- BONUS MALUS --- *************************************************************************** --- *************************************************************************** - - ------------------------------------------------------------------------------------------------------------- -function game:bonusMalusActiveText(ui, slot, state) - local uiTextGroup= ui["text" .. tostring(slot) ]; - if(uiTextGroup) then - uiTextGroup.active= state; - end -end - ------------------------------------------------------------------------------------------------------------- -function game:bonusMalusSetText(ui, slot, fmt) - local uiTextGroup= ui["text" .. tostring(slot) ]; - if(uiTextGroup) then - uiTextGroup.shade0.uc_hardtext_format= fmt; - uiTextGroup.shade1.uc_hardtext_format= fmt; - uiTextGroup.shade2.uc_hardtext_format= fmt; - uiTextGroup.shade3.uc_hardtext_format= fmt; - uiTextGroup.text.uc_hardtext_format= fmt; - uiTextGroup.text2.uc_hardtext_format= fmt; - end -end - ------------------------------------------------------------------------------------------------------------- --- From given DB vals, compute the 'Xp Bonus' text info -function game:updateXpCatQuantity(textSlot, ui) - -- get the ui text to fill - if(ui==nil) then - ui= getUICaller(); - end - - -- format the text - local fmt= "x@{FF6F}" .. tostring( getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Count") ); - - self:bonusMalusSetText(ui, textSlot, fmt); -end - - ------------------------------------------------------------------------------------------------------------- --- From given DB vals, compute the 'Ring Xp Bonus' text info -function game:updateRingXpCatQuantity(textSlot, ui) - -- get the ui text to fill - if(ui==nil) then - ui= getUICaller(); - end - - -- format the text - local fmt= "x@{FF6F}" .. tostring( getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count") ); - - self:bonusMalusSetText(ui, textSlot, fmt); -end - - ------------------------------------------------------------------------------------------------------------- -function game:outpostUpdatePVPTimer(textSlot, ui) - -- get the ui text to fill - if(ui==nil) then - ui= getUICaller(); - end + text= concatUCString(text, timeFmt); + end + end + + -- set the text + setContextHelpText(text); +end + + + +-- *************************************************************************** +-- *************************************************************************** +-- BONUS MALUS +-- *************************************************************************** +-- *************************************************************************** + + +------------------------------------------------------------------------------------------------------------ +function game:bonusMalusActiveText(ui, slot, state) + local uiTextGroup= ui["text" .. tostring(slot) ]; + if(uiTextGroup) then + uiTextGroup.active= state; + end +end + +------------------------------------------------------------------------------------------------------------ +function game:bonusMalusSetText(ui, slot, fmt) + local uiTextGroup= ui["text" .. tostring(slot) ]; + if(uiTextGroup) then + uiTextGroup.shade0.uc_hardtext_format= fmt; + uiTextGroup.shade1.uc_hardtext_format= fmt; + uiTextGroup.shade2.uc_hardtext_format= fmt; + uiTextGroup.shade3.uc_hardtext_format= fmt; + uiTextGroup.text.uc_hardtext_format= fmt; + uiTextGroup.text2.uc_hardtext_format= fmt; + end +end + +------------------------------------------------------------------------------------------------------------ +-- From given DB vals, compute the 'Xp Bonus' text info +function game:updateXpCatQuantity(textSlot, ui) + -- get the ui text to fill + if(ui==nil) then + ui= getUICaller(); + end + + -- format the text + local fmt= "x@{FF6F}" .. tostring( getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Count") ); + + self:bonusMalusSetText(ui, textSlot, fmt); +end + + +------------------------------------------------------------------------------------------------------------ +-- From given DB vals, compute the 'Ring Xp Bonus' text info +function game:updateRingXpCatQuantity(textSlot, ui) + -- get the ui text to fill + if(ui==nil) then + ui= getUICaller(); + end + + -- format the text + local fmt= "x@{FF6F}" .. tostring( getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count") ); + + self:bonusMalusSetText(ui, textSlot, fmt); +end + + +------------------------------------------------------------------------------------------------------------ +function game:outpostUpdatePVPTimer(textSlot, ui) + -- get the ui text to fill + if(ui==nil) then + ui= getUICaller(); + end -- Get the timer of interest (priority to player leaving the zone) local endTimer= 0; @@ -413,12 +413,12 @@ function game:outpostUpdatePVPTimer(textSlot, ui) if( endOfPvpTimer>0 ) then endTimer= endOfPvpTimer; else - local endOfRound= getDbProp('SERVER:CHARACTER_INFO:PVP_OUTPOST:ROUND_END_DATE'); - if( endOfRound>0 ) then - endTimer= endOfRound; - end - end - + local endOfRound= getDbProp('SERVER:CHARACTER_INFO:PVP_OUTPOST:ROUND_END_DATE'); + if( endOfRound>0 ) then + endTimer= endOfRound; + end + end + -- Use a text with a timer? if( endTimer>0 ) then -- compute the time that lefts in sec (suppose a smooth server tick is 1 ms) @@ -426,203 +426,203 @@ function game:outpostUpdatePVPTimer(textSlot, ui) local timeSec= (endTimer- curTick)/10; -- replace in str local text= "@{FF6F}" .. runFct('secondsToTimeStringShort', timeSec); - self:bonusMalusSetText(ui, textSlot, text); - -- else Default display - else - self:bonusMalusSetText(ui, textSlot, "@{FF6F}on"); - end - -end - - ------------------------------------------------------------------------------------------------------------- -function game:deathPenaltyUpdateXPMalus() -end - - ------------------------------------------------------------------------------------------------------------- --- called when someone click on a bonus malus icon. redirect to correct action handler if any -function game:onLeftClickBonus() - local ui= getUICaller(); - local id= getIndexInDB(ui); - local ah= self.BonusMalus.BonusAHList[id]; - if(ui and ah) then - runAH(ui, ah, ""); - end -end - -function game:onLeftClickMalus() - local ui= getUICaller(); - local id= getIndexInDB(ui); - local ah= self.BonusMalus.MalusAHList[id]; - if(ui and ah) then - runAH(ui, ah, ""); - end -end - ------------------------------------------------------------------------------------------------------------- --- update if needed the ActionHandler and text update from DB -function game:updateBonusMalusTextSetup() - local numLocalBonusMalus= getDefine("num_local_bonus_malus"); - local uiBonus= getUI('ui:interface:bonus_malus:header_opened:bonus'); - local uiMalus= getUI('ui:interface:bonus_malus:header_opened:malus'); - local dbXpCat= "@SERVER:CHARACTER_INFO:XP_CATALYSER:Count"; - local dbRingXpCat= "@SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count"; - local dbOutpost= "@SERVER:CHARACTER_INFO:PVP_OUTPOST, @UI:VARIABLES:CURRENT_SERVER_TICK"; - local dbDeathPenalty= "@SERVER:USER:DEATH_XP_MALUS"; - - - -- reset cache - self.BonusMalus.DeathPenaltyBefore= self.BonusMalus.DeathPenaltyAfter; - self.BonusMalus.XPCatSlotBefore= self.BonusMalus.XPCatSlotAfter; - self.BonusMalus.RingXPCatSlotBefore= self.BonusMalus.RingXPCatSlotAfter; - self.BonusMalus.OutpostSlotBefore= self.BonusMalus.OutpostSlotAfter; - - - -- *** remove and hide any preceding - for i= 0,numLocalBonusMalus-1 do - -- reset AH - self.BonusMalus.BonusAHList[i]= nil; - self.BonusMalus.MalusAHList[i]= nil; - -- hide text view - self:bonusMalusActiveText(uiBonus, i, false); - -- reset special tooltip - setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', i), game.TBonusMalusSpecialTT.None); - end - removeOnDbChange(uiBonus, dbXpCat); - removeOnDbChange(uiBonus, dbRingXpCat); - removeOnDbChange(uiBonus, dbOutpost); - - - -- *** set new XPCat setup - local slot= self.BonusMalus.XPCatSlotAfter; - if(slot~=-1) then - -- set AH to use for this slot - self.BonusMalus.BonusAHList[slot]= "xp_catalyser_stop_use"; - -- add DB change, and call now! else not updated - addOnDbChange(uiBonus, dbXpCat, formatUI("game:updateXpCatQuantity(#1, nil)", slot) ); - self:updateXpCatQuantity(slot, uiBonus); - -- show text - self:bonusMalusActiveText(uiBonus, slot, true); - -- set special tooltip (id==1 for xpcat) - setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', slot), game.TBonusMalusSpecialTT.XpCatalyser); - end - - -- *** set new RingXPCat setup - local slot= self.BonusMalus.RingXPCatSlotAfter; - if(slot~=-1) then - -- set AH to use for this slot - self.BonusMalus.BonusAHList[slot]= "ring_xp_catalyser_stop_use"; - -- add DB change, and call now! else not updated - addOnDbChange(uiBonus, dbRingXpCat, formatUI("game:updateRingXpCatQuantity(#1, nil)", slot) ); - self:updateRingXpCatQuantity(slot, uiBonus); - -- show text - self:bonusMalusActiveText(uiBonus, slot, true); - -- set special tooltip (id==1 for ringxpcat) - setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', slot), game.TBonusMalusSpecialTT.XpCatalyser); - end - - - -- *** set new Outpost setup - local slot= self.BonusMalus.OutpostSlotAfter; - if(slot~=-1) then - -- no AH - -- add DB change, and call now! else not updated - addOnDbChange(uiBonus, dbOutpost, formatUI("game:outpostUpdatePVPTimer(#1, nil)", slot) ); - self:outpostUpdatePVPTimer(slot, uiBonus); - -- show text - self:bonusMalusActiveText(uiBonus, slot, true); - -- don't set the tooltip here, because redone after return - end - - - -- *** set new DeathPenalty setup - local slot= self.BonusMalus.DeathPenaltyAfter; - if(slot~=-1) then - -- no AH - -- add DB change, and call now! else not updated - addOnDbChange(uiMalus, dbDeathPenalty, formatUI("game:deathPenaltyUpdateXPMalus(#1, nil)", slot) ); - self:deathPenaltyUpdateXPMalus(slot, uiMalus); - -- show text - self:bonusMalusActiveText(uiMalus, slot, true); - -- set special tooltip (id==1 for death penalty) - setDbProp( formatUI('UI:VARIABLES:MALUS:#1:SPECIAL_TOOLTIP', slot), game.TBonusMalusSpecialTT.DeathPenalty); - end - -end - ------------------------------------------------------------------------------------------------------------- --- Update Bonus malus local DB according to server DB -function game:updatePlayerBonusMalus() - local numServerBonusMalus= tonumber(getDefine("num_server_bonus_malus")); - local numLocalBonusMalus= tonumber(getDefine("num_local_bonus_malus")); - local dbServerBonusBase= getDefine("bonus") .. ":" ; - local dbServerMalusBase= getDefine("malus") .. ":" ; - local dbLocalBonusBase= "UI:VARIABLES:BONUS:"; - local dbLocalMalusBase= "UI:VARIABLES:MALUS:"; - - local i; - local mustUpdateTextSetup= false; - - - -- *********************** - -- *** Insert Bonus - -- *********************** - local destIndex= 0; - local mustShowBonus= false; - - -- *** Insert XPCatalyzer first - local xpcatCount= getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Count"); - if(xpcatCount~=0) then - local xpcatLevel= getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Level"); - -- Get the most appropriate icon - local iconLevel= 50; - for i= 50,250,50 do - if(i<=xpcatLevel) then - iconLevel= i; - end - end - -- Set the DB for this brick - mustShowBonus= true; - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", getSheetId('big_xpcat_' .. tostring(iconLevel) .. '.sbrick' ) ); - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", 0 ); - self.BonusMalus.XPCatSlotAfter = destIndex; - destIndex= destIndex+1; - else - self.BonusMalus.XPCatSlotAfter = -1; - end - if(self.BonusMalus.XPCatSlotAfter ~= self.BonusMalus.XPCatSlotBefore) then - mustUpdateTextSetup= true; - end - - -- *** Then insert RingXPCatalyzer - local ringxpcatCount= getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count"); - if(ringxpcatCount~=0) then - local ringxpcatLevel= getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Level"); - -- Get the most appropriate icon - local iconLevel= 50; - for i= 50,250,50 do - if(i<=ringxpcatLevel) then - iconLevel= i; - end - end - -- Set the DB for this brick - mustShowBonus= true; - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", getSheetId('big_ring_xpcat_' .. tostring(iconLevel) .. '.sbrick' ) ); - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", 0 ); - self.BonusMalus.RingXPCatSlotAfter = destIndex; - destIndex= destIndex+1; - else - self.BonusMalus.RingXPCatSlotAfter = -1; - end - if(self.BonusMalus.RingXPCatSlotAfter ~= self.BonusMalus.RingXPCatSlotBefore) then - mustUpdateTextSetup= true; - end - - - -- *** Insert PVPOutpost - local pvpOutpostPresent= getDbProp("SERVER:CHARACTER_INFO:PVP_OUTPOST:FLAG_PVP"); - local pvpOutpostEndOfPVPFlag= 0; + self:bonusMalusSetText(ui, textSlot, text); + -- else Default display + else + self:bonusMalusSetText(ui, textSlot, "@{FF6F}on"); + end + +end + + +------------------------------------------------------------------------------------------------------------ +function game:deathPenaltyUpdateXPMalus() +end + + +------------------------------------------------------------------------------------------------------------ +-- called when someone click on a bonus malus icon. redirect to correct action handler if any +function game:onLeftClickBonus() + local ui= getUICaller(); + local id= getIndexInDB(ui); + local ah= self.BonusMalus.BonusAHList[id]; + if(ui and ah) then + runAH(ui, ah, ""); + end +end + +function game:onLeftClickMalus() + local ui= getUICaller(); + local id= getIndexInDB(ui); + local ah= self.BonusMalus.MalusAHList[id]; + if(ui and ah) then + runAH(ui, ah, ""); + end +end + +------------------------------------------------------------------------------------------------------------ +-- update if needed the ActionHandler and text update from DB +function game:updateBonusMalusTextSetup() + local numLocalBonusMalus= getDefine("num_local_bonus_malus"); + local uiBonus= getUI('ui:interface:bonus_malus:header_opened:bonus'); + local uiMalus= getUI('ui:interface:bonus_malus:header_opened:malus'); + local dbXpCat= "@SERVER:CHARACTER_INFO:XP_CATALYSER:Count"; + local dbRingXpCat= "@SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count"; + local dbOutpost= "@SERVER:CHARACTER_INFO:PVP_OUTPOST, @UI:VARIABLES:CURRENT_SERVER_TICK"; + local dbDeathPenalty= "@SERVER:USER:DEATH_XP_MALUS"; + + + -- reset cache + self.BonusMalus.DeathPenaltyBefore= self.BonusMalus.DeathPenaltyAfter; + self.BonusMalus.XPCatSlotBefore= self.BonusMalus.XPCatSlotAfter; + self.BonusMalus.RingXPCatSlotBefore= self.BonusMalus.RingXPCatSlotAfter; + self.BonusMalus.OutpostSlotBefore= self.BonusMalus.OutpostSlotAfter; + + + -- *** remove and hide any preceding + for i= 0,numLocalBonusMalus-1 do + -- reset AH + self.BonusMalus.BonusAHList[i]= nil; + self.BonusMalus.MalusAHList[i]= nil; + -- hide text view + self:bonusMalusActiveText(uiBonus, i, false); + -- reset special tooltip + setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', i), game.TBonusMalusSpecialTT.None); + end + removeOnDbChange(uiBonus, dbXpCat); + removeOnDbChange(uiBonus, dbRingXpCat); + removeOnDbChange(uiBonus, dbOutpost); + + + -- *** set new XPCat setup + local slot= self.BonusMalus.XPCatSlotAfter; + if(slot~=-1) then + -- set AH to use for this slot + self.BonusMalus.BonusAHList[slot]= "xp_catalyser_stop_use"; + -- add DB change, and call now! else not updated + addOnDbChange(uiBonus, dbXpCat, formatUI("game:updateXpCatQuantity(#1, nil)", slot) ); + self:updateXpCatQuantity(slot, uiBonus); + -- show text + self:bonusMalusActiveText(uiBonus, slot, true); + -- set special tooltip (id==1 for xpcat) + setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', slot), game.TBonusMalusSpecialTT.XpCatalyser); + end + + -- *** set new RingXPCat setup + local slot= self.BonusMalus.RingXPCatSlotAfter; + if(slot~=-1) then + -- set AH to use for this slot + self.BonusMalus.BonusAHList[slot]= "ring_xp_catalyser_stop_use"; + -- add DB change, and call now! else not updated + addOnDbChange(uiBonus, dbRingXpCat, formatUI("game:updateRingXpCatQuantity(#1, nil)", slot) ); + self:updateRingXpCatQuantity(slot, uiBonus); + -- show text + self:bonusMalusActiveText(uiBonus, slot, true); + -- set special tooltip (id==1 for ringxpcat) + setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', slot), game.TBonusMalusSpecialTT.XpCatalyser); + end + + + -- *** set new Outpost setup + local slot= self.BonusMalus.OutpostSlotAfter; + if(slot~=-1) then + -- no AH + -- add DB change, and call now! else not updated + addOnDbChange(uiBonus, dbOutpost, formatUI("game:outpostUpdatePVPTimer(#1, nil)", slot) ); + self:outpostUpdatePVPTimer(slot, uiBonus); + -- show text + self:bonusMalusActiveText(uiBonus, slot, true); + -- don't set the tooltip here, because redone after return + end + + + -- *** set new DeathPenalty setup + local slot= self.BonusMalus.DeathPenaltyAfter; + if(slot~=-1) then + -- no AH + -- add DB change, and call now! else not updated + addOnDbChange(uiMalus, dbDeathPenalty, formatUI("game:deathPenaltyUpdateXPMalus(#1, nil)", slot) ); + self:deathPenaltyUpdateXPMalus(slot, uiMalus); + -- show text + self:bonusMalusActiveText(uiMalus, slot, true); + -- set special tooltip (id==1 for death penalty) + setDbProp( formatUI('UI:VARIABLES:MALUS:#1:SPECIAL_TOOLTIP', slot), game.TBonusMalusSpecialTT.DeathPenalty); + end + +end + +------------------------------------------------------------------------------------------------------------ +-- Update Bonus malus local DB according to server DB +function game:updatePlayerBonusMalus() + local numServerBonusMalus= tonumber(getDefine("num_server_bonus_malus")); + local numLocalBonusMalus= tonumber(getDefine("num_local_bonus_malus")); + local dbServerBonusBase= getDefine("bonus") .. ":" ; + local dbServerMalusBase= getDefine("malus") .. ":" ; + local dbLocalBonusBase= "UI:VARIABLES:BONUS:"; + local dbLocalMalusBase= "UI:VARIABLES:MALUS:"; + + local i; + local mustUpdateTextSetup= false; + + + -- *********************** + -- *** Insert Bonus + -- *********************** + local destIndex= 0; + local mustShowBonus= false; + + -- *** Insert XPCatalyzer first + local xpcatCount= getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Count"); + if(xpcatCount~=0) then + local xpcatLevel= getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Level"); + -- Get the most appropriate icon + local iconLevel= 50; + for i= 50,250,50 do + if(i<=xpcatLevel) then + iconLevel= i; + end + end + -- Set the DB for this brick + mustShowBonus= true; + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", getSheetId('big_xpcat_' .. tostring(iconLevel) .. '.sbrick' ) ); + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", 0 ); + self.BonusMalus.XPCatSlotAfter = destIndex; + destIndex= destIndex+1; + else + self.BonusMalus.XPCatSlotAfter = -1; + end + if(self.BonusMalus.XPCatSlotAfter ~= self.BonusMalus.XPCatSlotBefore) then + mustUpdateTextSetup= true; + end + + -- *** Then insert RingXPCatalyzer + local ringxpcatCount= getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count"); + if(ringxpcatCount~=0) then + local ringxpcatLevel= getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Level"); + -- Get the most appropriate icon + local iconLevel= 50; + for i= 50,250,50 do + if(i<=ringxpcatLevel) then + iconLevel= i; + end + end + -- Set the DB for this brick + mustShowBonus= true; + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", getSheetId('big_ring_xpcat_' .. tostring(iconLevel) .. '.sbrick' ) ); + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", 0 ); + self.BonusMalus.RingXPCatSlotAfter = destIndex; + destIndex= destIndex+1; + else + self.BonusMalus.RingXPCatSlotAfter = -1; + end + if(self.BonusMalus.RingXPCatSlotAfter ~= self.BonusMalus.RingXPCatSlotBefore) then + mustUpdateTextSetup= true; + end + + + -- *** Insert PVPOutpost + local pvpOutpostPresent= getDbProp("SERVER:CHARACTER_INFO:PVP_OUTPOST:FLAG_PVP"); + local pvpOutpostEndOfPVPFlag= 0; local pvpOutpostEndOfRound= 0; if(pvpOutpostPresent~=0) then local pvpOutpostLevel= 0; @@ -631,327 +631,327 @@ function game:updatePlayerBonusMalus() -- set a level only if we have some round, and if the out timer is not set if(pvpOutpostEndOfRound~=0 and pvpOutpostEndOfPVPFlag==0) then pvpOutpostLevel= 1 + getDbProp('SERVER:CHARACTER_INFO:PVP_OUTPOST:ROUND_LVL_CUR'); - end - - -- Set the DB for this brick - mustShowBonus= true; - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", getSheetId('big_outpost_pvp_' .. tostring(pvpOutpostLevel) .. '.sbrick' ) ); - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", 0 ); - self.BonusMalus.OutpostSlotAfter = destIndex; - destIndex= destIndex+1; - else - self.BonusMalus.OutpostSlotAfter = -1; - end - if(self.BonusMalus.OutpostSlotAfter ~= self.BonusMalus.OutpostSlotBefore) then - mustUpdateTextSetup= true; - end - - - -- *** Insert standard Bonus - for i=0,numServerBonusMalus-1 do - -- get - local sheet= getDbProp(dbServerBonusBase .. tostring(i) .. ":SHEET" ); - local disabled= getDbProp(dbServerBonusBase .. tostring(i) .. ":DISABLED" ); - if(sheet~=0) then - mustShowBonus= true; - end - -- copy (to index shifted if needed) - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", sheet ); - setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", disabled ); - destIndex= destIndex+1; - end - if(mustShowBonus) then - setDbProp("UI:VARIABLES:SHOW_BONUS", 1); - else - setDbProp("UI:VARIABLES:SHOW_BONUS", 0); - end - - - -- *** erase any remaining bonus - while destIndex 0 then result = concatUCString(tostring(seconds), i18n.get("uittSecondsShort")) end - if minutes > 0 then result = concatUCString(tostring(minutes), i18n.get("uittMinutesShort"), result) end - if hours > 0 then result = concatUCString(tostring(hours), i18n.get("uittHoursShort"), result) end - return result -end - ------------------------------------------------------------------------------------------------------------- --- display the time left for a power / auras in its tooltip -function game:setPhraseTooltipPowerRegenTime(ttWin, regenTimeInTicks) - local text = ttWin:find("regen_time") - if regenTimeInTicks == 0 then - text.active = false - else - text.active = true - text.uc_hardtext_single_line_format = concatUCString(i18n.get("uittRegenTime"), game:timeInSecondsToReadableTime(math.floor((regenTimeInTicks + 9) * 0.1))) - text:invalidateCoords() - ttWin:invalidateCoords() - end -end - - -local EmptyUCString = ucstring() - ------------------------------------------------------------------------------------------------------------- --- called by C++ code when the tooltip of a phrase is about to be displayed -function game:updatePhraseTooltip(phrase) - LastTooltipPhrase = phrase - local ttWin = getUI("ui:interface:action_context_help") - local text = phrase:getName() - - if not text or text == EmptyUCString then - text = ucstring("") - end - - local desc = phrase:getDesc() - if desc and desc ~= EmptyUCString then - local str = tostring(desc) - local charFound = false - for k = 1, string.len(str) do - if string.byte(str, k) ~= 32 then - charFound = true - break - end - end - if charFound then - text = concatUCString(text, "\n@{CCCF}", desc) - end - else - text = concatUCString(text, "@{CCCF}") - end - -- IMPORTANT : the following getters on 'phrase' take in account the 'total action malus' for the timebeing - self:setPhraseTooltipCarac(ttWin, "hp_cost", phrase:getHpCost()) - self:setPhraseTooltipCarac(ttWin, "sta_cost", phrase:getStaCost()) - self:setPhraseTooltipCarac(ttWin, "sap_cost", phrase:getSapCost()) - self:setPhraseTooltipCarac(ttWin, "focus_cost", phrase:getFocusCost()) - self:setPhraseTooltipCarac(ttWin, "cast_time", phrase:getCastTime(), concatUCString(string.format("%.1f", phrase:getCastTime()), i18n.get("uittSeconds"))) - local castRange = phrase:getCastRange() - if not phrase:isMagicPhrase() then - castRange = 0 - end - self:setPhraseTooltipCarac(ttWin, "cast_range", castRange, concatUCString(tostring(castRange), i18n.get("uittMeters"))) - -- if the phrase is a power / aura, then we may want to display its regen time in the tooltip - if phrase:isPowerPhrase() then - setOnDraw(ttWin, "game:updatePowerPhraseTooltip()") - else - setOnDraw(ttWin, "") - end - -- - local successRateText = ttWin:find("success_rate") - local successRate = phrase:getSuccessRate() - if successRate == 0 then - successRateText.active = false - else - successRateText.active = true - successRateText.uc_hardtext_single_line_format = concatUCString(i18n.get("uittSuccessRate"), tostring(successRate), " %") - end - - local disableTimeText = ttWin:find("disable_time") - if phrase:isPowerPhrase() then - local disableTime = phrase:getPowerDisableTime() - if disableTime == 0 then - disableTimeText.active = false - else - disableTimeText.active = true - disableTimeText.uc_hardtext_single_line_format = concatUCString(i18n.get("uittDisableTime"), game:timeInSecondsToReadableTime(disableTime / 10)) - end - else - disableTimeText.active = false - end - game:updatePowerPhraseTooltip() - updateTooltipCoords() - return text -end - ------------------------------------------------------------------------------------------------------------- --- called at each frame when a power/aura tooltip is displayed,in order to update the regen countdown -function game:updatePowerPhraseTooltip() - local ttWin = getUI("ui:interface:action_context_help") - local leftRegenTime = 0 - if LastTooltipPhrase:isPowerPhrase() then - leftRegenTime = LastTooltipPhrase:getTotalRegenTime() - LastTooltipPhrase:getRegenTime() - end - if leftRegenTime < 0 then - leftRegenTime = 0 - end - self:setPhraseTooltipPowerRegenTime(ttWin, leftRegenTime) - updateTooltipCoords() -end - - --- *************************************************************************** --- *************************************************************************** --- CURRENT BUFF ITEM --- *************************************************************************** --- *************************************************************************** - ------------------------------------------------------------------------------------------------------------- --- called by C++ code when the tooltip of a buff item is about to be displayed -function game:updateBuffItemTooltip(buffItem) - local ttWin = getUI("ui:interface:buff_item_context_help") - local text = buffItem:getName() - - self:setPhraseTooltipCarac(ttWin, "hp_buff", buffItem:getHpBuff()) - self:setPhraseTooltipCarac(ttWin, "sta_buff", buffItem:getStaBuff()) - self:setPhraseTooltipCarac(ttWin, "sap_buff", buffItem:getSapBuff()) - self:setPhraseTooltipCarac(ttWin, "focus_buff", buffItem:getFocusBuff()) - - updateTooltipCoords() - return text -end - --- *************************************************************************** --- *************************************************************************** --- CURRENT CRYSTALLIZED SPELL --- *************************************************************************** --- *************************************************************************** - ------------------------------------------------------------------------------------------------------------- --- called by C++ code when the tooltip of a cristallized spell is about to be displayed -function game:updateCrystallizedSpellTooltip(crystallizedSpell) - local ttWin = getUI("ui:interface:crystallized_spell_context_help") - local text = crystallizedSpell:getName() - - crystallizedSpell:buildCrystallizedSpellListBrick() - - updateTooltipCoords() - return text -end + end + + -- Set the DB for this brick + mustShowBonus= true; + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", getSheetId('big_outpost_pvp_' .. tostring(pvpOutpostLevel) .. '.sbrick' ) ); + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", 0 ); + self.BonusMalus.OutpostSlotAfter = destIndex; + destIndex= destIndex+1; + else + self.BonusMalus.OutpostSlotAfter = -1; + end + if(self.BonusMalus.OutpostSlotAfter ~= self.BonusMalus.OutpostSlotBefore) then + mustUpdateTextSetup= true; + end + + + -- *** Insert standard Bonus + for i=0,numServerBonusMalus-1 do + -- get + local sheet= getDbProp(dbServerBonusBase .. tostring(i) .. ":SHEET" ); + local disabled= getDbProp(dbServerBonusBase .. tostring(i) .. ":DISABLED" ); + if(sheet~=0) then + mustShowBonus= true; + end + -- copy (to index shifted if needed) + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":SHEET", sheet ); + setDbProp(dbLocalBonusBase .. tostring(destIndex) .. ":DISABLED", disabled ); + destIndex= destIndex+1; + end + if(mustShowBonus) then + setDbProp("UI:VARIABLES:SHOW_BONUS", 1); + else + setDbProp("UI:VARIABLES:SHOW_BONUS", 0); + end + + + -- *** erase any remaining bonus + while destIndex 0 then result = concatUCString(tostring(seconds), i18n.get("uittSecondsShort")) end + if minutes > 0 then result = concatUCString(tostring(minutes), i18n.get("uittMinutesShort"), result) end + if hours > 0 then result = concatUCString(tostring(hours), i18n.get("uittHoursShort"), result) end + return result +end + +------------------------------------------------------------------------------------------------------------ +-- display the time left for a power / auras in its tooltip +function game:setPhraseTooltipPowerRegenTime(ttWin, regenTimeInTicks) + local text = ttWin:find("regen_time") + if regenTimeInTicks == 0 then + text.active = false + else + text.active = true + text.uc_hardtext_single_line_format = concatUCString(i18n.get("uittRegenTime"), game:timeInSecondsToReadableTime(math.floor((regenTimeInTicks + 9) * 0.1))) + text:invalidateCoords() + ttWin:invalidateCoords() + end +end + + +local EmptyUCString = ucstring() + +------------------------------------------------------------------------------------------------------------ +-- called by C++ code when the tooltip of a phrase is about to be displayed +function game:updatePhraseTooltip(phrase) + LastTooltipPhrase = phrase + local ttWin = getUI("ui:interface:action_context_help") + local text = phrase:getName() + + if not text or text == EmptyUCString then + text = ucstring("") + end + + local desc = phrase:getDesc() + if desc and desc ~= EmptyUCString then + local str = tostring(desc) + local charFound = false + for k = 1, string.len(str) do + if string.byte(str, k) ~= 32 then + charFound = true + break + end + end + if charFound then + text = concatUCString(text, "\n@{CCCF}", desc) + end + else + text = concatUCString(text, "@{CCCF}") + end + -- IMPORTANT : the following getters on 'phrase' take in account the 'total action malus' for the timebeing + self:setPhraseTooltipCarac(ttWin, "hp_cost", phrase:getHpCost()) + self:setPhraseTooltipCarac(ttWin, "sta_cost", phrase:getStaCost()) + self:setPhraseTooltipCarac(ttWin, "sap_cost", phrase:getSapCost()) + self:setPhraseTooltipCarac(ttWin, "focus_cost", phrase:getFocusCost()) + self:setPhraseTooltipCarac(ttWin, "cast_time", phrase:getCastTime(), concatUCString(string.format("%.1f", phrase:getCastTime()), i18n.get("uittSeconds"))) + local castRange = phrase:getCastRange() + if not phrase:isMagicPhrase() then + castRange = 0 + end + self:setPhraseTooltipCarac(ttWin, "cast_range", castRange, concatUCString(tostring(castRange), i18n.get("uittMeters"))) + -- if the phrase is a power / aura, then we may want to display its regen time in the tooltip + if phrase:isPowerPhrase() then + setOnDraw(ttWin, "game:updatePowerPhraseTooltip()") + else + setOnDraw(ttWin, "") + end + -- + local successRateText = ttWin:find("success_rate") + local successRate = phrase:getSuccessRate() + if successRate == 0 then + successRateText.active = false + else + successRateText.active = true + successRateText.uc_hardtext_single_line_format = concatUCString(i18n.get("uittSuccessRate"), tostring(successRate), " %") + end + + local disableTimeText = ttWin:find("disable_time") + if phrase:isPowerPhrase() then + local disableTime = phrase:getPowerDisableTime() + if disableTime == 0 then + disableTimeText.active = false + else + disableTimeText.active = true + disableTimeText.uc_hardtext_single_line_format = concatUCString(i18n.get("uittDisableTime"), game:timeInSecondsToReadableTime(disableTime / 10)) + end + else + disableTimeText.active = false + end + game:updatePowerPhraseTooltip() + updateTooltipCoords() + return text +end + +------------------------------------------------------------------------------------------------------------ +-- called at each frame when a power/aura tooltip is displayed,in order to update the regen countdown +function game:updatePowerPhraseTooltip() + local ttWin = getUI("ui:interface:action_context_help") + local leftRegenTime = 0 + if LastTooltipPhrase:isPowerPhrase() then + leftRegenTime = LastTooltipPhrase:getTotalRegenTime() - LastTooltipPhrase:getRegenTime() + end + if leftRegenTime < 0 then + leftRegenTime = 0 + end + self:setPhraseTooltipPowerRegenTime(ttWin, leftRegenTime) + updateTooltipCoords() +end + + +-- *************************************************************************** +-- *************************************************************************** +-- CURRENT BUFF ITEM +-- *************************************************************************** +-- *************************************************************************** + +------------------------------------------------------------------------------------------------------------ +-- called by C++ code when the tooltip of a buff item is about to be displayed +function game:updateBuffItemTooltip(buffItem) + local ttWin = getUI("ui:interface:buff_item_context_help") + local text = buffItem:getName() + + self:setPhraseTooltipCarac(ttWin, "hp_buff", buffItem:getHpBuff()) + self:setPhraseTooltipCarac(ttWin, "sta_buff", buffItem:getStaBuff()) + self:setPhraseTooltipCarac(ttWin, "sap_buff", buffItem:getSapBuff()) + self:setPhraseTooltipCarac(ttWin, "focus_buff", buffItem:getFocusBuff()) + + updateTooltipCoords() + return text +end + +-- *************************************************************************** +-- *************************************************************************** +-- CURRENT CRYSTALLIZED SPELL +-- *************************************************************************** +-- *************************************************************************** + +------------------------------------------------------------------------------------------------------------ +-- called by C++ code when the tooltip of a cristallized spell is about to be displayed +function game:updateCrystallizedSpellTooltip(crystallizedSpell) + local ttWin = getUI("ui:interface:crystallized_spell_context_help") + local text = crystallizedSpell:getName() + + crystallizedSpell:buildCrystallizedSpellListBrick() + + updateTooltipCoords() + return text +end diff --git a/code/ryzom/client/data/gamedev/syui_v3/syui/syui.lua b/code/ryzom/client/data/gamedev/syui_v3/syui/syui.lua index e8a6a84cc..bfa8f8b3b 100644 --- a/code/ryzom/client/data/gamedev/syui_v3/syui/syui.lua +++ b/code/ryzom/client/data/gamedev/syui_v3/syui/syui.lua @@ -1,433 +1,433 @@ --- written by Syphox -local M = {} - -function M.exist() - return true -end - -local bit32 = {} -local logic_and = { -[0] = { [0] = 0, 0, 0, 0}, -[1] = { [0] = 0, 1, 0, 1}, -[2] = { [0] = 0, 0, 2, 2}, -[3] = { [0] = 0, 1, 2, 3}, -} - -local function checkint32( name, argidx, x, level ) - local n = tonumber( x ) - if not n then - error( string.format( - "bad argument #%d to '%s' (number expected, got %s)", - argidx, name, type( x ) - ), level + 1 ) - end - return math.floor( n ) % 0x100000000 -end - -local function comb( name, args, nargs, s, t ) - for i = 1, nargs do - args[i] = checkint32( name, i, args[i], 3 ) - end - local pow = 1 - local ret = 0 - for b = 0, 31, 2 do - local c = s - for i = 1, nargs do - c = t[c][args[i] % 4] - args[i] = math.floor( args[i] / 4 ) - end - ret = ret + c * pow - pow = pow * 4 - end - return ret -end -function bit32.btest( ... ) - return comb( 'btest', { ... }, select( '#', ... ), 3, logic_and ) ~= 0 -end - - -local function targetIsInSameTeam() - if(getDbProp('UI:VARIABLES:IS_TEAM_PRESENT')~=0)then - for i=0,7 do - local groupEntityUID = getDbProp('SERVER:GROUP:' .. tostring(i) ..':UID') - if(groupEntityUID == getDbProp('UI:VARIABLES:TARGET:UID'))then - return true - end - end - return false - end -end - -local function targetIsInSameGuild() - if(getDbProp('SERVER:GUILD:NAME')~=0)then - local nbMember = getNbGuildMembers(); - for i=0,(nbMember-1) do - if(getGuildMemberName(i) == getTargetName())then - return true - end - end - return false - end -end - -local function targetIsInSameLeague() - local targetLeague = getDbProp('SERVER:Entities:E' .. getTargetSlot() .. ':P25') - local playerLeague = getDbProp('SERVER:Entities:E0:P25') - if(targetLeague == playerLeague and playerLeague ~= 0)then - return true - end - return false -end - --- no way found yet -local function targetIsInSameOpFight() - -end - --- 1=duel, 2=unk, 3=arena, 4=unk, 5=gvg (pr), 6=unk, 7=tagged(mara), 8=unk, 9=tp safezone, 10=safe zone related -function M.checkPvPMode() - local targetProp = getDbProp('SERVER:Entities:E' .. getTargetSlot() .. ':P23') - local playerProp = getDbProp('SERVER:Entities:E0:P23') - local pvp_mode = {1,3,5,7} - for i=1,8 do - if(bit32.btest(targetProp, 2^(i-1)) and bit32.btest(playerProp, 2^(i-1)))then - return true - end - end - return false -end - -function M.PvPLogo() - local targetProp = getDbProp('SERVER:Entities:E' .. getTargetSlot() .. ':P23') - for i=1,8 do - if(bit32.btest(targetProp, 2^(i-1)))then - return true - end - end - return false -end - -function M.isEnemy() - if(isTargetPlayer() and M.checkPvPMode())then - if(targetIsInSameGuild())then - return false - end - if(targetIsInSameTeam())then - return false - end - if(targetIsInSameLeague())then - return false - end - return true - end - return false -end - -local function TJauge(val) - local jvalue = getDbProp("UI:VARIABLES:BARS:TARGET:" .. val) / 1.27 - if(jvalue < 0)then - jvalue = 0 - end - setDbProp("UI:VARIABLES:BARS:TARGET:" .. val .. "_PERCENT", math.floor(jvalue)) -end - -function M.UpdateJauge() - local bars = {"HP", "SAP", "STA"} - for k,v in pairs(bars) do - TJauge(v) - end -end - -function M.teamInvite(uiID) - runAH(nil, 'talk', 'mode=0|text=/invite '.. getUI('ui:interface:' .. uiID).title) -end - -function M.updateFLinvB(uiID) - if(uiID==nil)then - return - end - local tUI = getUI('ui:interface:' .. uiID .. ':header_closed:invite_button') - if(getUI('ui:interface:' .. uiID .. ':header_closed:online').texture ~= 'w_online.tga')then - if(tUI.texture == 'invt.tga')then - tUI.texture = '' - end - else - if(tUI.texture == '')then - tUI.texture = 'invt.tga' - tUI.x = -52 - tUI.y = 0 - end - end -end - -function M.invToGuild(ply) - ply = getUI('ui:interface:add_guild'):find('edit_text').hardtext:split(">")[2] - if(ply ~= '')then - runAH(nil, 'talk', 'mode=0|text=/guildinvite ' .. ply) - end - runAH(nil, 'leave_modal', '') -end - -function M.teamInviteFromGuild(uiID) - runAH(nil, 'talk', 'mode=0|text=/invite ' .. getGuildMemberName(tonumber(uiID:split(":m")[2]))) -end - -local tGuild = 'ui:interface:guild:content:tab_guild:list_member:guild_members' -function M.updateGLinvB() - if(getUI('ui:interface:guild').active)then - -- if get #id from member template, it creates too many instances and game will crash. bad coded from ryzom dev - for v = 0, (getNbGuildMembers()-1) do - local uiTexture = getUI(tGuild .. ":" .. tGuild .. ":m" .. v .. ':online') - local tUI = getUI(tGuild .. ":" .. tGuild .. ":m" .. v .. ':invite_button') - if(getUI("ui:interface:player").title ~= getUI(tGuild .. ":" .. tGuild .. ":m" .. v .. ":name").hardtext)then - if(uiTexture.texture ~= 'w_online.tga')then - if(tUI.texture == 'invt.tga')then - tUI.texture = '' - end - else - if(tUI.texture == '')then - tUI.texture = 'invt.tga' - tUI.x = -22 - tUI.y = 0 - end - end - else - -- fix the invite button in guild tab, because it sometimes disappear - -- the button appear for the player with higher grade than member - local invB = getUI('ui:interface:guild:content:tab_guild_i:invite') - if(getGuildMemberGrade(v) ~= 'Member')then - if(invB.active == false)then - invB.active = true - end - else - invB.active = false - end - end - end - end -end - -function M.updateMemberCount() - -- fix the new guild tab - local mcount = getUI('ui:interface:guild:content:tab_guild_i:member_count') - if(getUI('ui:interface:guild').active)then - if(tonumber(mcount.hardtext) ~= getNbGuildMembers())then - mcount.hardtext = getNbGuildMembers() - end - end -end - -function M.updateFPS() - local fpsUI = getUI('ui:interface:compass:frame:fps') - if(fpsUI==nil)then return end; - local fps = getDbProp('UI:VARIABLES:FPS') - fpsUI.hardtext = fps; - local colRGB = '255 81 81 255' - if(fps >= 30)then - colRGB = '155 255 81 255' - elseif(fps >= 20)then - colRGB = '249 255 81 255' - end - fpsUI.color = colRGB -end - -function string:split(Pattern) - local Results = {} - local Start = 1 - local SplitStart, SplitEnd = string.find(self, Pattern, Start) - while(SplitStart)do - table.insert(Results, string.sub(self, Start, SplitStart-1)) - Start = SplitEnd+1 - SplitStart, SplitEnd = string.find(self, Pattern, Start) - end - table.insert(Results, string.sub(self, Start)) - return Results -end - -function M.sysinfo(txt, mtd) - if(mtd==nil)then mtd='SYS' end; - displaySystemInfo(ucstring(tostring(txt)), mtd); -end - -function M.showTargetPercent() - local targetUI = getUI('ui:interface:target') - local playerUI = getUI('ui:interface:player') - local contentUI = targetUI:find("content") - local clawImg = targetUI:find("slot_claw") - local targetTitle = targetUI:find("target_title") - local playerTitle = playerUI:find("player_title") - local wgTargetConside = targetUI:find("conside") - local wgTargetLevel = targetUI:find("target_level") - targetTitle.color = "255 255 255 255" - playerTitle.color = targetTitle.color - - if (isTargetUser() or - (isTargetPlayer() and - not M.isEnemy()))then - wgTargetConside.active = false - contentUI.h = 55 - contentUI.y = -24 - clawImg.active = false - else - if(not isTargetPlayer() and - not M.checkPvPMode() and - getTargetLevel() > 0)then - if(clawImg.texture ~= "claw.tga")then - clawImg.texture = "claw.tga" - clawImg.x = 7 - clawImg.y = -6 - end - end - if(targetUI.title == "")then - wgTargetConside.active = false - clawImg.active = false - end - contentUI.h = 18 - contentUI.y = -26 - end - - if(getTargetLevelForce() > 0 and - not isTargetPlayer())then - if(getTargetLevel() > 0)then - --fix campfire, do not show claw - if(tostring(getTargetSheet())~="object_campfire_28_b.creature")then - wgTargetConside.active = true - clawImg.active = true - end - end - end - - if(getTargetLevel() <= 0 or isTargetNPC())then - wgTargetConside.active = false - wgTargetLevel.active = false - wgTargetLevel.hardtext = "" - clawImg.active = false - wgTargetConside.texture = "blank_n.tga" - end - - if((isTargetUser() or isTargetPlayer()) and M.PvPLogo())then - if(clawImg.texture ~= "pvp.tga")then - clawImg.texture = "pvp.tga" - clawImg.x = 0 - clawImg.y = 5 - end - clawImg.active = true - wgTargetConside.active = false - end -end - -function M.newConsider() - local targetWindow = getUI("ui:interface:target") - local clawImg = targetWindow:find("slot_claw") - local targetTitle = targetWindow:find("target_title") - local wgTargetLevel = targetWindow:find("target_level") - local wgTargetConside = targetWindow:find("conside") - local wgImpossible = targetWindow:find("impossible") - local wgSlotRing = targetWindow:find("slot_ring") - local wgToolTip = targetWindow:find("target_tooltip") - local pvpMode = false - - local maxDiffLevel = 10 - if not pvpMode then - for gm = 0, 7 do - if getDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT") ~= 0 then - maxDiffLevel = maxDiffLevel + 10 - end - end - end - - local impossible = (getTargetLevel() - getPlayerLevel() > maxDiffLevel) - - wgSlotRing.active = false - wgTargetConside.active = false - wgImpossible.active = false - wgTargetConside.texture = "blank_n.tga" - - if impossible then - -- targeted object is too hard too beat, display a skull - wgTargetLevel.active = false - wgTargetConside.active = false - wgImpossible.texture = "skull_imp.tga" - clawImg.active = false - wgImpossible.active = true - wgImpossible.color = "255 255 255 255" - --wgImpossible.color = "255 50 50 255" - wgTargetLevel.hardtext = "" - else - --fix campfire, do not show, claw, lvl and consider - if(tostring(getTargetSheet())=="object_campfire_28_b.creature")then - wgTargetConside.active = false - wgTargetLevel.active = false - wgTargetLevel.hardtext = "" - clawImg.active = false - wgTargetConside.texture = "blank_n.tga" - return - end - -- player can see the level of the targeted creature, but not from NPC's - if(not isTargetNPC())then - wgTargetLevel.active = true - wgTargetConside.active = true - wgImpossible.active = false - wgImpossible.texture = "blank_n.tga" - - wgTargetLevel.hardtext = tostring(getTargetLevel()) - wgTargetLevel.color = "255 255 255 255" - wgImpossible.color = "255 255 255 255" - end - - local image={ 'b1', 'b2', 'b3', 'b4', 'b5', 'g1', 'g2', 'g3', 'g4', 'g5', 'ge1', 'ge2', 'ge3', 'ge4', 'ge5', 'r1', 'r2', 'r3', 'r4', 'r5', 'l1', 'l2', 'l3', 'l4', 'l5', 'l5', 'l5' } - - if(getTargetLevel()<10)then - wgTargetConside.texture = 'consider_gr.tga' - end - - for k,v in pairs(image) do - if(getTargetLevel()>=tonumber(k .. 0))then - wgTargetConside.texture = 'consider_' .. v .. '.tga' - end - end - end - - -- based on the 'level force', set a colored ring around the level - local levelForce = getTargetLevelForce() - - wgImpossible.active = true - if levelForce < 6 then - wgToolTip.tooltip = i18n.get("uittConsiderTargetLevel") - elseif levelForce == 6 then - -- Named creature - wgImpossible.color = "255 255 255 255" - --wgImpossible.color = "191 225 254 255" - wgImpossible.texture = "skull_imp.tga" - wgImpossible.active = true - wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss") - wgTargetLevel.hardtext = "" - elseif levelForce == 7 then - -- Boss - wgImpossible.color = "255 255 255 255" - --wgImpossible.color = "222 191 254 255" - wgImpossible.texture = "skull_imp.tga" - wgImpossible.active = true - wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss") - wgTargetLevel.hardtext = "" - elseif levelForce == 8 then - -- Mini-Boss - wgImpossible.color = "255 255 255 255" - --wgImpossible.color = "254 191 191 255" - wgImpossible.texture = "skull_imp.tga" - wgImpossible.active = true - wgTargetLevel.hardtext = "" - wgTargetConside.active = false - if isTargetNPC() then - wgToolTip.tooltip = i18n.get("uittConsiderBossNpc") - else - wgToolTip.tooltip = i18n.get("uittConsiderBoss") - end - end - - if impossible then - wgToolTip.tooltip = concatUCString(wgToolTip.tooltip, ucstring("\n"), i18n.get("uittConsiderUnknownLevel")) - end -end - +-- written by Syphox +local M = {} + +function M.exist() + return true +end + +local bit32 = {} +local logic_and = { +[0] = { [0] = 0, 0, 0, 0}, +[1] = { [0] = 0, 1, 0, 1}, +[2] = { [0] = 0, 0, 2, 2}, +[3] = { [0] = 0, 1, 2, 3}, +} + +local function checkint32( name, argidx, x, level ) + local n = tonumber( x ) + if not n then + error( string.format( + "bad argument #%d to '%s' (number expected, got %s)", + argidx, name, type( x ) + ), level + 1 ) + end + return math.floor( n ) % 0x100000000 +end + +local function comb( name, args, nargs, s, t ) + for i = 1, nargs do + args[i] = checkint32( name, i, args[i], 3 ) + end + local pow = 1 + local ret = 0 + for b = 0, 31, 2 do + local c = s + for i = 1, nargs do + c = t[c][args[i] % 4] + args[i] = math.floor( args[i] / 4 ) + end + ret = ret + c * pow + pow = pow * 4 + end + return ret +end +function bit32.btest( ... ) + return comb( 'btest', { ... }, select( '#', ... ), 3, logic_and ) ~= 0 +end + + +local function targetIsInSameTeam() + if(getDbProp('UI:VARIABLES:IS_TEAM_PRESENT')~=0)then + for i=0,7 do + local groupEntityUID = getDbProp('SERVER:GROUP:' .. tostring(i) ..':UID') + if(groupEntityUID == getDbProp('UI:VARIABLES:TARGET:UID'))then + return true + end + end + return false + end +end + +local function targetIsInSameGuild() + if(getDbProp('SERVER:GUILD:NAME')~=0)then + local nbMember = getNbGuildMembers(); + for i=0,(nbMember-1) do + if(getGuildMemberName(i) == getTargetName())then + return true + end + end + return false + end +end + +local function targetIsInSameLeague() + local targetLeague = getDbProp('SERVER:Entities:E' .. getTargetSlot() .. ':P25') + local playerLeague = getDbProp('SERVER:Entities:E0:P25') + if(targetLeague == playerLeague and playerLeague ~= 0)then + return true + end + return false +end + +-- no way found yet +local function targetIsInSameOpFight() + +end + +-- 1=duel, 2=unk, 3=arena, 4=unk, 5=gvg (pr), 6=unk, 7=tagged(mara), 8=unk, 9=tp safezone, 10=safe zone related +function M.checkPvPMode() + local targetProp = getDbProp('SERVER:Entities:E' .. getTargetSlot() .. ':P23') + local playerProp = getDbProp('SERVER:Entities:E0:P23') + local pvp_mode = {1,3,5,7} + for i=1,8 do + if(bit32.btest(targetProp, 2^(i-1)) and bit32.btest(playerProp, 2^(i-1)))then + return true + end + end + return false +end + +function M.PvPLogo() + local targetProp = getDbProp('SERVER:Entities:E' .. getTargetSlot() .. ':P23') + for i=1,8 do + if(bit32.btest(targetProp, 2^(i-1)))then + return true + end + end + return false +end + +function M.isEnemy() + if(isTargetPlayer() and M.checkPvPMode())then + if(targetIsInSameGuild())then + return false + end + if(targetIsInSameTeam())then + return false + end + if(targetIsInSameLeague())then + return false + end + return true + end + return false +end + +local function TJauge(val) + local jvalue = getDbProp("UI:VARIABLES:BARS:TARGET:" .. val) / 1.27 + if(jvalue < 0)then + jvalue = 0 + end + setDbProp("UI:VARIABLES:BARS:TARGET:" .. val .. "_PERCENT", math.floor(jvalue)) +end + +function M.UpdateJauge() + local bars = {"HP", "SAP", "STA"} + for k,v in pairs(bars) do + TJauge(v) + end +end + +function M.teamInvite(uiID) + runAH(nil, 'talk', 'mode=0|text=/invite '.. getUI('ui:interface:' .. uiID).title) +end + +function M.updateFLinvB(uiID) + if(uiID==nil)then + return + end + local tUI = getUI('ui:interface:' .. uiID .. ':header_closed:invite_button') + if(getUI('ui:interface:' .. uiID .. ':header_closed:online').texture ~= 'w_online.tga')then + if(tUI.texture == 'invt.tga')then + tUI.texture = '' + end + else + if(tUI.texture == '')then + tUI.texture = 'invt.tga' + tUI.x = -52 + tUI.y = 0 + end + end +end + +function M.invToGuild(ply) + ply = getUI('ui:interface:add_guild'):find('edit_text').hardtext:split(">")[2] + if(ply ~= '')then + runAH(nil, 'talk', 'mode=0|text=/guildinvite ' .. ply) + end + runAH(nil, 'leave_modal', '') +end + +function M.teamInviteFromGuild(uiID) + runAH(nil, 'talk', 'mode=0|text=/invite ' .. getGuildMemberName(tonumber(uiID:split(":m")[2]))) +end + +local tGuild = 'ui:interface:guild:content:tab_guild:list_member:guild_members' +function M.updateGLinvB() + if(getUI('ui:interface:guild').active)then + -- if get #id from member template, it creates too many instances and game will crash. bad coded from ryzom dev + for v = 0, (getNbGuildMembers()-1) do + local uiTexture = getUI(tGuild .. ":" .. tGuild .. ":m" .. v .. ':online') + local tUI = getUI(tGuild .. ":" .. tGuild .. ":m" .. v .. ':invite_button') + if(getUI("ui:interface:player").title ~= getUI(tGuild .. ":" .. tGuild .. ":m" .. v .. ":name").hardtext)then + if(uiTexture.texture ~= 'w_online.tga')then + if(tUI.texture == 'invt.tga')then + tUI.texture = '' + end + else + if(tUI.texture == '')then + tUI.texture = 'invt.tga' + tUI.x = -22 + tUI.y = 0 + end + end + else + -- fix the invite button in guild tab, because it sometimes disappear + -- the button appear for the player with higher grade than member + local invB = getUI('ui:interface:guild:content:tab_guild_i:invite') + if(getGuildMemberGrade(v) ~= 'Member')then + if(invB.active == false)then + invB.active = true + end + else + invB.active = false + end + end + end + end +end + +function M.updateMemberCount() + -- fix the new guild tab + local mcount = getUI('ui:interface:guild:content:tab_guild_i:member_count') + if(getUI('ui:interface:guild').active)then + if(tonumber(mcount.hardtext) ~= getNbGuildMembers())then + mcount.hardtext = getNbGuildMembers() + end + end +end + +function M.updateFPS() + local fpsUI = getUI('ui:interface:compass:frame:fps') + if(fpsUI==nil)then return end; + local fps = getDbProp('UI:VARIABLES:FPS') + fpsUI.hardtext = fps; + local colRGB = '255 81 81 255' + if(fps >= 30)then + colRGB = '155 255 81 255' + elseif(fps >= 20)then + colRGB = '249 255 81 255' + end + fpsUI.color = colRGB +end + +function string:split(Pattern) + local Results = {} + local Start = 1 + local SplitStart, SplitEnd = string.find(self, Pattern, Start) + while(SplitStart)do + table.insert(Results, string.sub(self, Start, SplitStart-1)) + Start = SplitEnd+1 + SplitStart, SplitEnd = string.find(self, Pattern, Start) + end + table.insert(Results, string.sub(self, Start)) + return Results +end + +function M.sysinfo(txt, mtd) + if(mtd==nil)then mtd='SYS' end; + displaySystemInfo(ucstring(tostring(txt)), mtd); +end + +function M.showTargetPercent() + local targetUI = getUI('ui:interface:target') + local playerUI = getUI('ui:interface:player') + local contentUI = targetUI:find("content") + local clawImg = targetUI:find("slot_claw") + local targetTitle = targetUI:find("target_title") + local playerTitle = playerUI:find("player_title") + local wgTargetConside = targetUI:find("conside") + local wgTargetLevel = targetUI:find("target_level") + targetTitle.color = "255 255 255 255" + playerTitle.color = targetTitle.color + + if (isTargetUser() or + (isTargetPlayer() and + not M.isEnemy()))then + wgTargetConside.active = false + contentUI.h = 55 + contentUI.y = -24 + clawImg.active = false + else + if(not isTargetPlayer() and + not M.checkPvPMode() and + getTargetLevel() > 0)then + if(clawImg.texture ~= "claw.tga")then + clawImg.texture = "claw.tga" + clawImg.x = 7 + clawImg.y = -6 + end + end + if(targetUI.title == "")then + wgTargetConside.active = false + clawImg.active = false + end + contentUI.h = 18 + contentUI.y = -26 + end + + if(getTargetLevelForce() > 0 and + not isTargetPlayer())then + if(getTargetLevel() > 0)then + --fix campfire, do not show claw + if(tostring(getTargetSheet())~="object_campfire_28_b.creature")then + wgTargetConside.active = true + clawImg.active = true + end + end + end + + if(getTargetLevel() <= 0 or isTargetNPC())then + wgTargetConside.active = false + wgTargetLevel.active = false + wgTargetLevel.hardtext = "" + clawImg.active = false + wgTargetConside.texture = "blank_n.tga" + end + + if((isTargetUser() or isTargetPlayer()) and M.PvPLogo())then + if(clawImg.texture ~= "pvp.tga")then + clawImg.texture = "pvp.tga" + clawImg.x = 0 + clawImg.y = 5 + end + clawImg.active = true + wgTargetConside.active = false + end +end + +function M.newConsider() + local targetWindow = getUI("ui:interface:target") + local clawImg = targetWindow:find("slot_claw") + local targetTitle = targetWindow:find("target_title") + local wgTargetLevel = targetWindow:find("target_level") + local wgTargetConside = targetWindow:find("conside") + local wgImpossible = targetWindow:find("impossible") + local wgSlotRing = targetWindow:find("slot_ring") + local wgToolTip = targetWindow:find("target_tooltip") + local pvpMode = false + + local maxDiffLevel = 10 + if not pvpMode then + for gm = 0, 7 do + if getDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT") ~= 0 then + maxDiffLevel = maxDiffLevel + 10 + end + end + end + + local impossible = (getTargetLevel() - getPlayerLevel() > maxDiffLevel) + + wgSlotRing.active = false + wgTargetConside.active = false + wgImpossible.active = false + wgTargetConside.texture = "blank_n.tga" + + if impossible then + -- targeted object is too hard too beat, display a skull + wgTargetLevel.active = false + wgTargetConside.active = false + wgImpossible.texture = "skull_imp.tga" + clawImg.active = false + wgImpossible.active = true + wgImpossible.color = "255 255 255 255" + --wgImpossible.color = "255 50 50 255" + wgTargetLevel.hardtext = "" + else + --fix campfire, do not show, claw, lvl and consider + if(tostring(getTargetSheet())=="object_campfire_28_b.creature")then + wgTargetConside.active = false + wgTargetLevel.active = false + wgTargetLevel.hardtext = "" + clawImg.active = false + wgTargetConside.texture = "blank_n.tga" + return + end + -- player can see the level of the targeted creature, but not from NPC's + if(not isTargetNPC())then + wgTargetLevel.active = true + wgTargetConside.active = true + wgImpossible.active = false + wgImpossible.texture = "blank_n.tga" + + wgTargetLevel.hardtext = tostring(getTargetLevel()) + wgTargetLevel.color = "255 255 255 255" + wgImpossible.color = "255 255 255 255" + end + + local image={ 'b1', 'b2', 'b3', 'b4', 'b5', 'g1', 'g2', 'g3', 'g4', 'g5', 'ge1', 'ge2', 'ge3', 'ge4', 'ge5', 'r1', 'r2', 'r3', 'r4', 'r5', 'l1', 'l2', 'l3', 'l4', 'l5', 'l5', 'l5' } + + if(getTargetLevel()<10)then + wgTargetConside.texture = 'consider_gr.tga' + end + + for k,v in pairs(image) do + if(getTargetLevel()>=tonumber(k .. 0))then + wgTargetConside.texture = 'consider_' .. v .. '.tga' + end + end + end + + -- based on the 'level force', set a colored ring around the level + local levelForce = getTargetLevelForce() + + wgImpossible.active = true + if levelForce < 6 then + wgToolTip.tooltip = i18n.get("uittConsiderTargetLevel") + elseif levelForce == 6 then + -- Named creature + wgImpossible.color = "255 255 255 255" + --wgImpossible.color = "191 225 254 255" + wgImpossible.texture = "skull_imp.tga" + wgImpossible.active = true + wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss") + wgTargetLevel.hardtext = "" + elseif levelForce == 7 then + -- Boss + wgImpossible.color = "255 255 255 255" + --wgImpossible.color = "222 191 254 255" + wgImpossible.texture = "skull_imp.tga" + wgImpossible.active = true + wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss") + wgTargetLevel.hardtext = "" + elseif levelForce == 8 then + -- Mini-Boss + wgImpossible.color = "255 255 255 255" + --wgImpossible.color = "254 191 191 255" + wgImpossible.texture = "skull_imp.tga" + wgImpossible.active = true + wgTargetLevel.hardtext = "" + wgTargetConside.active = false + if isTargetNPC() then + wgToolTip.tooltip = i18n.get("uittConsiderBossNpc") + else + wgToolTip.tooltip = i18n.get("uittConsiderBoss") + end + end + + if impossible then + wgToolTip.tooltip = concatUCString(wgToolTip.tooltip, ucstring("\n"), i18n.get("uittConsiderUnknownLevel")) + end +end + return M \ No newline at end of file