1 -- In this file we define functions that serves for player windows
3 function getDbPropU(dbEntry
)
4 value
= getDbProp(dbEntry
)
6 value
= 4294967296+value
11 if string.find(_VERSION
, "Lua 5.0") then
12 function math
.fmod(a
, b
)
17 ------------------------------------------------------------------------------------------------------------
18 -- create the game namespace without reseting if already created in an other file.
23 if (game
.PVP
== nil) then
25 game
.PVP
.tagStartTimer
= 0;
26 game
.PVP
.flagStartTimer
= 0;
27 game
.PVP
.tagTimerStarted
= false;
28 game
.PVP
.flagTimerStarted
= false;
31 if (game
.BonusMalus
== nil) then
33 game
.BonusMalus
.DeathPenaltyBefore
= -1;
34 game
.BonusMalus
.DeathPenaltyAfter
= -1;
35 game
.BonusMalus
.XPCatSlotBefore
= -1;
36 game
.BonusMalus
.XPCatSlotAfter
= -1;
37 game
.BonusMalus
.RingXPCatSlotBefore
= -1;
38 game
.BonusMalus
.RingXPCatSlotAfter
= -1;
39 game
.BonusMalus
.OutpostSlotBefore
= -1;
40 game
.BonusMalus
.OutpostSlotAfter
= -1;
41 game
.BonusMalus
.BonusAHList
= {};
42 game
.BonusMalus
.MalusAHList
= {};
46 ------------------------------------------------------------------------------------------------------------
47 -- Update player bars in function of what we wants to display (we can hide each one of the 3 bars : sap,stamina and focus)
48 function game
:updatePlayerBars()
50 local dispSap
= getDbProp('UI:SAVE:PLAYER:DISP_SAP');
51 local dispSta
= getDbProp('UI:SAVE:PLAYER:DISP_STA');
52 local dispFoc
= getDbProp('UI:SAVE:PLAYER:DISP_FOC');
54 local ui
= getUI('ui:interface:player:content');
56 -- active ui in function of what is displayed
58 ui
.b_sap
.active
= (dispSap
== 1);
59 ui
.jsap
.active
= (dispSap
== 1);
61 ui
.b_sta
.active
= (dispSta
== 1);
62 ui
.jsta
.active
= (dispSta
== 1);
64 ui
.b_foc
.active
= (dispFoc
== 1);
65 ui
.jfoc
.active
= (dispFoc
== 1);
67 -- choose good y-position
69 local totalBarDisp
= dispSap
+ dispSta
+ dispFoc
;
70 if (totalBarDisp
== 3) then
75 ui
.current_action
.y
= -65;
77 elseif (totalBarDisp
== 2) then
79 if (dispSap
== 0) then
84 if (dispSta
== 0) then
89 if (dispFoc
== 0) then
94 ui
.current_action
.y
= -50;
96 elseif (totalBarDisp
== 1) then
102 ui
.current_action
.y
= -35;
105 ui
.current_action
.y
= -18;
112 ------------------------------------------------------------------------------------------------------------
113 -- convert a boolean to a number 0 or 1
114 function booleanToNumber(thebool
)
122 ------------------------------------------------------------------------------------------------------------
123 -- Update player pvp tag
124 function game
:pvpTagUpdateDisplay()
125 local currentServerTick
= getDbPropU('UI:VARIABLES:CURRENT_SERVER_TICK');
126 local pvpServerTagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:ACTIVATION_TIME');
127 local pvpServerFlagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:FLAG_PVP_TIME_LEFT');
128 local uiPlayer
= getUI('ui:interface:player:header_opened');
130 -- get the current state
131 local pvpServerFlag
= pvpServerFlagTimer
> currentServerTick
;
132 local pvpLocalTag
= (getDbProp('UI:TEMP:PVP_FACTION:TAG_PVP') == 1);
133 local pvpServerTag
= (getDbProp('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:TAG_PVP') == 1);
134 local pvpServerActivateTimerOn
= pvpServerTagTimer
> currentServerTick
;
136 -- deduce the display state according to the current state
140 local buttonMode
= GREEN
;
141 local buttonPushed
= false;
142 local buttonTimer
= false;
143 -- if the flag is activated, then must display PVP flag button and timer
144 if (pvpServerFlag
) then
149 -- else must display correct mode according to the TAG state
151 -- There are 8 possibilities according to the combination of the 3 flags
152 -- Here: TL= pvpLocalTag, TS= pvpServerTag, AS= pvpServerActivateTimerOn)
155 -- 0 0 0 -> Standard disabled PVP
156 -- 1 0 0 -> The user pressed the button but still no response from server
157 -- 1 1 1 -> The user pressed the button and got response from server. => GREEN icon with timer
158 -- 0 1 1 -> The user canceled the activation (server not acked yet the cancel). => default display
160 -- 1 1 0 -> Standard enabled PVP
161 -- 0 1 0 -> The user pressed the button but still no response from server
162 -- 0 0 1 -> The user pressed the button and got response from server. => ORANGE icon with timer
163 -- 1 0 1 -> The user canceled the activation (server not acked yet the cancel). => default display
165 -- From this table, we can deduce the following rules
167 -- buttonMode is GREEN when TS==AS
168 if( pvpServerTag
== pvpServerActivateTimerOn
) then
174 -- the button is pushed if (there is a timer and TL==TS), or (no timer and TL!=TS)
175 if( pvpServerActivateTimerOn
== (pvpLocalTag
== pvpServerTag
) ) then
181 -- display a timer only if the timer is activated and server and local tag are equals
182 if( pvpServerActivateTimerOn
and pvpLocalTag
== pvpServerTag
) then
190 -- setup the local display
191 setDbProp("UI:TEMP:PVP_FACTION:DSP_MODE", buttonMode
);
192 setDbProp("UI:TEMP:PVP_FACTION:DSP_PUSHED", booleanToNumber(buttonPushed
));
193 setDbProp("UI:TEMP:PVP_FACTION:DSP_TIMER", booleanToNumber(buttonTimer
));
195 -- setup the timer bar
197 local uiBar
= uiPlayer
.pvp_timer
;
198 local uiBarBg
= uiPlayer
.pvp_timer_bg
;
200 if(buttonMode
==RED
) then
201 -- display a reverse timer
202 uiBar
.w
= uiBarBg
.w
* (pvpServerFlagTimer
- currentServerTick
) / (pvpServerFlagTimer
- game
.PVP
.flagStartTimer
);
204 -- display a forward timer
205 uiBar
.w
= uiBarBg
.w
* (currentServerTick
- game
.PVP
.tagStartTimer
) / (pvpServerTagTimer
- game
.PVP
.tagStartTimer
);
209 -- force update of the tooltip for any button (by disabling then reenabling)
210 disableContextHelpForControl(uiPlayer
.pvp_tag_button_0
);
211 disableContextHelpForControl(uiPlayer
.pvp_tag_button_1
);
212 disableContextHelpForControl(uiPlayer
.pvp_tag_button_2
);
215 ------------------------------------------------------------------------------------------------------------
216 -- Update player pvp tag
217 function game
:pvpTag()
218 local buttonStat
= getDbProp('UI:TEMP:PVP_FACTION:TAG_PVP');
219 if (buttonStat
== 0) then
220 setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP',1);
222 setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP',0);
224 sendMsgToServerPvpTag(buttonStat
== 0);
227 self
:pvpTagUpdateDisplay();
230 ------------------------------------------------------------------------------------------------------------
231 -- Update button due to server validation
232 function game
:updatePvpTag()
233 -- force copy to temp of Server tag
234 local pvpServerTag
= (getDbProp('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:TAG_PVP') == 1);
235 setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP', booleanToNumber(pvpServerTag
));
237 -- launch timer DB if necessary
238 local currentServerTick
= getDbPropU('UI:VARIABLES:CURRENT_SERVER_TICK');
239 local pvpServerTagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:ACTIVATION_TIME');
240 local pvpServerFlagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:FLAG_PVP_TIME_LEFT');
242 if(pvpServerTagTimer
> currentServerTick
) or (pvpServerFlagTimer
> currentServerTick
) then
243 local ui
= getUI('ui:interface:player');
244 addOnDbChange(ui
,'@UI:VARIABLES:CURRENT_SERVER_TICK', 'game:updatePvpTimer()');
246 if(pvpServerTagTimer
> currentServerTick
and game
.PVP
.tagTimerStarted
== false) then
247 game
.PVP
.tagStartTimer
= currentServerTick
;
248 game
.PVP
.tagTimerStarted
= true;
250 if(pvpServerFlagTimer
> currentServerTick
and game
.PVP
.flagTimerStarted
== false) then
251 game
.PVP
.flagStartTimer
= currentServerTick
;
252 game
.PVP
.flagTimerStarted
= true;
256 -- update display (after start timer reseted)
257 self
:pvpTagUpdateDisplay();
260 ------------------------------------------------------------------------------------------------------------
262 function game
:updatePvpTimer()
265 self
:pvpTagUpdateDisplay();
268 local currentServerTick
= getDbPropU('UI:VARIABLES:CURRENT_SERVER_TICK');
269 local pvpServerTagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:ACTIVATION_TIME');
270 local pvpServerFlagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:FLAG_PVP_TIME_LEFT');
272 -- Manage Tag Timer display
273 if(pvpServerTagTimer
<= currentServerTick
) then
274 game
.PVP
.tagTimerStarted
= false;
277 -- Manage Flag Timer display
278 if(pvpServerFlagTimer
<= currentServerTick
) then
279 game
.PVP
.flagTimerStarted
= false;
282 -- if both off, stop the db update
283 if(game
.PVP
.tagTimerStarted
== false) and (game
.PVP
.flagTimerStarted
== false) then
284 removeOnDbChange(getUI('ui:interface:player'),'@UI:VARIABLES:CURRENT_SERVER_TICK');
288 ------------------------------------------------------------------------------------------------------------
290 function game
:formatTime(temps
)
292 local hours
= math
.floor(temps
/(10*60*60));
293 local minutes
= math
.floor((temps
- (hours
*10*60*60)) / (10*60));
294 local seconds
= math
.floor((temps
- (hours
*10*60*60) - (minutes
*10*60)) / 10);
296 local fmt
= i18n
.get('uittPvPTime');
297 fmt
= findReplaceAll(fmt
, '%h', tostring(hours
));
298 fmt
= findReplaceAll(fmt
, '%m', tostring(minutes
));
299 fmt
= findReplaceAll(fmt
, '%s', tostring(seconds
));
303 ------------------------------------------------------------------------------------------------------------
305 function game
:playerTTPvp()
307 -- The tooltip to display depends on the current display state
308 local buttonMode
= getDbProp("UI:TEMP:PVP_FACTION:DSP_MODE");
309 local buttonPushed
= (getDbProp("UI:TEMP:PVP_FACTION:DSP_PUSHED")==1);
310 local buttonTimer
= (getDbProp("UI:TEMP:PVP_FACTION:DSP_TIMER")==1);
314 if(buttonMode
==2) then
315 local pvpServerFlagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:FLAG_PVP_TIME_LEFT');
316 local currentServerTick
= getDbPropU('UI:VARIABLES:CURRENT_SERVER_TICK');
317 local tempsString
= game
:formatTime( pvpServerFlagTimer
- currentServerTick
);
318 text
= i18n
.get('uittPvPModeFlag');
319 text
= findReplaceAll(text
, '%temps', tempsString
);
323 if(buttonMode
==0 and not(buttonPushed
)) then
324 text
= i18n
.get('uittPvPModeTagOff');
325 elseif(buttonMode
==0 and buttonPushed
) then
326 text
= i18n
.get('uittPvPModeTagOffChange');
327 elseif(buttonMode
==1 and not(buttonPushed
)) then
328 text
= i18n
.get('uittPvPModeTagOn');
329 elseif(buttonMode
==1 and buttonPushed
) then
330 text
= i18n
.get('uittPvPModeTagOnChange');
336 local pvpServerTagTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_FACTION_TAG:ACTIVATION_TIME');
337 local currentServerTick
= getDbPropU('UI:VARIABLES:CURRENT_SERVER_TICK');
338 local tempsString
= game
:formatTime( pvpServerTagTimer
- currentServerTick
);
339 local timeFmt
= i18n
.get('uittPvPTagTimer');
340 timeFmt
= findReplaceAll(timeFmt
, '%temps', tempsString
);
341 text
= concatUCString(text
, timeFmt
);
346 setContextHelpText(text
);
351 -- ***************************************************************************
352 -- ***************************************************************************
354 -- ***************************************************************************
355 -- ***************************************************************************
358 ------------------------------------------------------------------------------------------------------------
359 function game
:bonusMalusActiveText(ui
, slot
, state
)
360 local uiTextGroup
= ui
["text" .. tostring(slot
) ];
362 uiTextGroup
.active
= state
;
366 ------------------------------------------------------------------------------------------------------------
367 function game
:bonusMalusSetText(ui
, slot
, fmt
)
368 local uiTextGroup
= ui
["text" .. tostring(slot
) ];
370 uiTextGroup
.shade0
.uc_hardtext_format
= fmt
;
371 uiTextGroup
.shade1
.uc_hardtext_format
= fmt
;
372 uiTextGroup
.shade2
.uc_hardtext_format
= fmt
;
373 uiTextGroup
.shade3
.uc_hardtext_format
= fmt
;
374 uiTextGroup
.text
.uc_hardtext_format
= fmt
;
375 uiTextGroup
.text2
.uc_hardtext_format
= fmt
;
379 ------------------------------------------------------------------------------------------------------------
380 -- From given DB vals, compute the 'Xp Bonus' text info
381 function game
:updateXpCatQuantity(textSlot
, ui
)
382 -- get the ui text to fill
388 local fmt
= "x@{FF6F}" .. tostring( getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Count") );
390 self
:bonusMalusSetText(ui
, textSlot
, fmt
);
394 ------------------------------------------------------------------------------------------------------------
395 -- From given DB vals, compute the 'Ring Xp Bonus' text info
396 function game
:updateRingXpCatQuantity(textSlot
, ui
)
397 -- get the ui text to fill
403 local fmt
= "x@{FF6F}" .. tostring( getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count") );
405 self
:bonusMalusSetText(ui
, textSlot
, fmt
);
409 ------------------------------------------------------------------------------------------------------------
410 function game
:outpostUpdatePVPTimer(textSlot
, ui
)
411 -- get the ui text to fill
416 -- Get the timer of interest (priority to player leaving the zone)
418 local endOfPvpTimer
= getDbPropU('SERVER:CHARACTER_INFO:PVP_OUTPOST:FLAG_PVP_TIME_END');
419 if( endOfPvpTimer
>0 ) then
420 endTimer
= endOfPvpTimer
;
422 local endOfRound
= getDbProp('SERVER:CHARACTER_INFO:PVP_OUTPOST:ROUND_END_DATE');
423 if( endOfRound
>0 ) then
424 endTimer
= endOfRound
;
428 -- Use a text with a timer?
429 if( endTimer
>0 ) then
430 -- compute the time that lefts in sec (suppose a smooth server tick is 1 ms)
431 local curTick
= getDbPropU('UI:VARIABLES:CURRENT_SERVER_TICK');
432 local timeSec
= (endTimer
- curTick
)/10;
434 local text
= "@{FF6F}" .. runFct('secondsToTimeStringShort', timeSec
);
435 self
:bonusMalusSetText(ui
, textSlot
, text
);
436 -- else Default display
438 self
:bonusMalusSetText(ui
, textSlot
, "@{FF6F}on");
444 ------------------------------------------------------------------------------------------------------------
445 function game
:deathPenaltyUpdateXPMalus()
449 ------------------------------------------------------------------------------------------------------------
450 -- called when someone click on a bonus malus icon. redirect to correct action handler if any
451 function game
:onLeftClickBonus()
452 local ui
= getUICaller();
453 local id
= getIndexInDB(ui
);
454 local ah
= self
.BonusMalus
.BonusAHList
[id
];
460 function game
:onLeftClickMalus()
461 local ui
= getUICaller();
462 local id
= getIndexInDB(ui
);
463 local ah
= self
.BonusMalus
.MalusAHList
[id
];
469 ------------------------------------------------------------------------------------------------------------
470 -- update if needed the ActionHandler and text update from DB
471 function game
:updateBonusMalusTextSetup()
472 local numLocalBonusMalus
= getDefine("num_local_bonus_malus");
473 local uiBonus
= getUI('ui:interface:bonus_malus:header_opened:bonus');
474 local uiMalus
= getUI('ui:interface:bonus_malus:header_opened:malus');
475 local dbXpCat
= "@SERVER:CHARACTER_INFO:XP_CATALYSER:Count";
476 local dbRingXpCat
= "@SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count";
477 local dbOutpost
= "@SERVER:CHARACTER_INFO:PVP_OUTPOST, @UI:VARIABLES:CURRENT_SERVER_TICK";
478 local dbDeathPenalty
= "@SERVER:USER:DEATH_XP_MALUS";
482 self
.BonusMalus
.DeathPenaltyBefore
= self
.BonusMalus
.DeathPenaltyAfter
;
483 self
.BonusMalus
.XPCatSlotBefore
= self
.BonusMalus
.XPCatSlotAfter
;
484 self
.BonusMalus
.RingXPCatSlotBefore
= self
.BonusMalus
.RingXPCatSlotAfter
;
485 self
.BonusMalus
.OutpostSlotBefore
= self
.BonusMalus
.OutpostSlotAfter
;
488 -- *** remove and hide any preceding
489 for i
= 0,numLocalBonusMalus
-1 do
491 self
.BonusMalus
.BonusAHList
[i
]= nil;
492 self
.BonusMalus
.MalusAHList
[i
]= nil;
494 self
:bonusMalusActiveText(uiBonus
, i
, false);
495 -- reset special tooltip
496 setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', i
), game
.TBonusMalusSpecialTT
.None
);
498 removeOnDbChange(uiBonus
, dbXpCat
);
499 removeOnDbChange(uiBonus
, dbRingXpCat
);
500 removeOnDbChange(uiBonus
, dbOutpost
);
503 -- *** set new XPCat setup
504 local slot
= self
.BonusMalus
.XPCatSlotAfter
;
506 -- set AH to use for this slot
507 self
.BonusMalus
.BonusAHList
[slot
]= "xp_catalyser_stop_use";
508 -- add DB change, and call now! else not updated
509 addOnDbChange(uiBonus
, dbXpCat
, formatUI("game:updateXpCatQuantity(#1, nil)", slot
) );
510 self
:updateXpCatQuantity(slot
, uiBonus
);
512 self
:bonusMalusActiveText(uiBonus
, slot
, true);
513 -- set special tooltip (id==1 for xpcat)
514 setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', slot
), game
.TBonusMalusSpecialTT
.XpCatalyser
);
517 -- *** set new RingXPCat setup
518 local slot
= self
.BonusMalus
.RingXPCatSlotAfter
;
520 -- set AH to use for this slot
521 self
.BonusMalus
.BonusAHList
[slot
]= "ring_xp_catalyser_stop_use";
522 -- add DB change, and call now! else not updated
523 addOnDbChange(uiBonus
, dbRingXpCat
, formatUI("game:updateRingXpCatQuantity(#1, nil)", slot
) );
524 self
:updateRingXpCatQuantity(slot
, uiBonus
);
526 self
:bonusMalusActiveText(uiBonus
, slot
, true);
527 -- set special tooltip (id==1 for ringxpcat)
528 setDbProp( formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', slot
), game
.TBonusMalusSpecialTT
.XpCatalyser
);
532 -- *** set new Outpost setup
533 local slot
= self
.BonusMalus
.OutpostSlotAfter
;
536 -- add DB change, and call now! else not updated
537 addOnDbChange(uiBonus
, dbOutpost
, formatUI("game:outpostUpdatePVPTimer(#1, nil)", slot
) );
538 self
:outpostUpdatePVPTimer(slot
, uiBonus
);
540 self
:bonusMalusActiveText(uiBonus
, slot
, true);
541 -- don't set the tooltip here, because redone after return
545 -- *** set new DeathPenalty setup
546 local slot
= self
.BonusMalus
.DeathPenaltyAfter
;
549 -- add DB change, and call now! else not updated
550 addOnDbChange(uiMalus
, dbDeathPenalty
, formatUI("game:deathPenaltyUpdateXPMalus(#1, nil)", slot
) );
551 self
:deathPenaltyUpdateXPMalus(slot
, uiMalus
);
553 self
:bonusMalusActiveText(uiMalus
, slot
, true);
554 -- set special tooltip (id==1 for death penalty)
555 setDbProp( formatUI('UI:VARIABLES:MALUS:#1:SPECIAL_TOOLTIP', slot
), game
.TBonusMalusSpecialTT
.DeathPenalty
);
560 ------------------------------------------------------------------------------------------------------------
561 -- Update Bonus malus local DB according to server DB
562 function game
:updatePlayerBonusMalus()
563 local numServerBonusMalus
= tonumber(getDefine("num_server_bonus_malus"));
564 local numLocalBonusMalus
= tonumber(getDefine("num_local_bonus_malus"));
565 local dbServerBonusBase
= getDefine("bonus") .. ":" ;
566 local dbServerMalusBase
= getDefine("malus") .. ":" ;
567 local dbLocalBonusBase
= "UI:VARIABLES:BONUS:";
568 local dbLocalMalusBase
= "UI:VARIABLES:MALUS:";
571 local mustUpdateTextSetup
= false;
574 -- ***********************
576 -- ***********************
578 local mustShowBonus
= false;
580 -- *** Insert XPCatalyzer first
581 local xpcatCount
= getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Count");
582 if(xpcatCount
~=0) then
583 local xpcatLevel
= getDbProp("SERVER:CHARACTER_INFO:XP_CATALYSER:Level");
584 -- Get the most appropriate icon
587 if(i
<=xpcatLevel
) then
591 -- Set the DB for this brick
593 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":SHEET", getSheetId('big_xpcat_' .. tostring(iconLevel
) .. '.sbrick' ) );
594 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":DISABLED", 0 );
595 self
.BonusMalus
.XPCatSlotAfter
= destIndex
;
596 destIndex
= destIndex
+1;
598 self
.BonusMalus
.XPCatSlotAfter
= -1;
600 if(self
.BonusMalus
.XPCatSlotAfter
~= self
.BonusMalus
.XPCatSlotBefore
) then
601 mustUpdateTextSetup
= true;
604 -- *** Then insert RingXPCatalyzer
605 local ringxpcatCount
= getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Count");
606 if(ringxpcatCount
~=0) then
607 local ringxpcatLevel
= getDbProp("SERVER:CHARACTER_INFO:RING_XP_CATALYSER:Level");
608 -- Get the most appropriate icon
611 if(i
<=ringxpcatLevel
) then
615 -- Set the DB for this brick
617 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":SHEET", getSheetId('big_ring_xpcat_' .. tostring(iconLevel
) .. '.sbrick' ) );
618 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":DISABLED", 0 );
619 self
.BonusMalus
.RingXPCatSlotAfter
= destIndex
;
620 destIndex
= destIndex
+1;
622 self
.BonusMalus
.RingXPCatSlotAfter
= -1;
624 if(self
.BonusMalus
.RingXPCatSlotAfter
~= self
.BonusMalus
.RingXPCatSlotBefore
) then
625 mustUpdateTextSetup
= true;
629 -- *** Insert PVPOutpost
630 local pvpOutpostPresent
= getDbProp("SERVER:CHARACTER_INFO:PVP_OUTPOST:FLAG_PVP");
631 local pvpOutpostEndOfPVPFlag
= 0;
632 local pvpOutpostEndOfRound
= 0;
633 if(pvpOutpostPresent
~=0) then
634 local pvpOutpostLevel
= 0;
635 pvpOutpostEndOfPVPFlag
= getDbPropU('SERVER:CHARACTER_INFO:PVP_OUTPOST:FLAG_PVP_TIME_END');
636 pvpOutpostEndOfRound
= getDbPropU('SERVER:CHARACTER_INFO:PVP_OUTPOST:ROUND_END_DATE');
637 -- set a level only if we have some round, and if the out timer is not set
638 if(pvpOutpostEndOfRound
~=0 and pvpOutpostEndOfPVPFlag
==0) then
639 pvpOutpostLevel
= 1 + getDbProp('SERVER:CHARACTER_INFO:PVP_OUTPOST:ROUND_LVL_CUR');
642 -- Set the DB for this brick
644 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":SHEET", getSheetId('big_outpost_pvp_' .. tostring(pvpOutpostLevel
) .. '.sbrick' ) );
645 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":DISABLED", 0 );
646 self
.BonusMalus
.OutpostSlotAfter
= destIndex
;
647 destIndex
= destIndex
+1;
649 self
.BonusMalus
.OutpostSlotAfter
= -1;
651 if(self
.BonusMalus
.OutpostSlotAfter
~= self
.BonusMalus
.OutpostSlotBefore
) then
652 mustUpdateTextSetup
= true;
656 -- *** Insert standard Bonus
657 for i
=0,numServerBonusMalus
-1 do
659 local sheet
= getDbProp(dbServerBonusBase
.. tostring(i
) .. ":SHEET" );
660 local disabled
= getDbProp(dbServerBonusBase
.. tostring(i
) .. ":DISABLED" );
664 -- copy (to index shifted if needed)
665 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":SHEET", sheet
);
666 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":DISABLED", disabled
);
667 destIndex
= destIndex
+1;
669 if(mustShowBonus
) then
670 setDbProp("UI:VARIABLES:SHOW_BONUS", 1);
672 setDbProp("UI:VARIABLES:SHOW_BONUS", 0);
676 -- *** erase any remaining bonus
677 while destIndex
<numLocalBonusMalus
do
678 setDbProp(dbLocalBonusBase
.. tostring(destIndex
) .. ":SHEET", 0 );
679 destIndex
= destIndex
+ 1;
684 -- ***********************
686 -- ***********************
687 local mustShowMalus
= false;
690 -- *** Insert Death Penalty first
691 local deathPenalty
= getDbProp("SERVER:USER:DEATH_XP_MALUS");
692 if(deathPenalty
~=255 and deathPenalty
~=0) then
693 -- Set the DB for this brick
695 setDbProp(dbLocalMalusBase
.. tostring(destIndex
) .. ":SHEET", getSheetId('death_penalty.sbrick' ) );
696 setDbProp(dbLocalMalusBase
.. tostring(destIndex
) .. ":DISABLED", 0 );
697 self
.BonusMalus
.DeathPenaltyAfter
= destIndex
;
698 destIndex
= destIndex
+1;
700 self
.BonusMalus
.DeathPenaltyAfter
= -1;
702 if(self
.BonusMalus
.DeathPenaltyAfter
~= self
.BonusMalus
.DeathPenaltyBefore
) then
703 mustUpdateTextSetup
= true;
706 -- *** insert standard malus
707 for i
=0,numServerBonusMalus
-1 do
709 local sheet
= getDbProp(dbServerMalusBase
.. tostring(i
) .. ":SHEET" );
710 local disabled
= getDbProp(dbServerMalusBase
.. tostring(i
) .. ":DISABLED" );
715 setDbProp(dbLocalMalusBase
.. tostring(destIndex
) .. ":SHEET", sheet
);
716 setDbProp(dbLocalMalusBase
.. tostring(destIndex
) .. ":DISABLED", disabled
);
717 destIndex
= destIndex
+1;
719 if(mustShowMalus
) then
720 setDbProp("UI:VARIABLES:SHOW_MALUS", 1);
722 setDbProp("UI:VARIABLES:SHOW_MALUS", 0);
726 -- *** erase any remaining malus
727 while destIndex
<numLocalBonusMalus
do
728 setDbProp(dbLocalMalusBase
.. tostring(destIndex
) .. ":SHEET", 0 );
729 destIndex
= destIndex
+ 1;
734 -- ***********************
735 -- *** update Text setup
736 -- ***********************
737 if(mustUpdateTextSetup
) then
738 game
:updateBonusMalusTextSetup();
741 -- set special tooltip for outpost (id==2,3,4 for outpost)
742 if(self
.BonusMalus
.OutpostSlotAfter
~= -1) then
743 local dbFmt
= formatUI('UI:VARIABLES:BONUS:#1:SPECIAL_TOOLTIP', self
.BonusMalus
.OutpostSlotAfter
);
744 if(pvpOutpostEndOfPVPFlag
~= 0) then
745 setDbProp(dbFmt
, game
.TBonusMalusSpecialTT
.OutpostPVPOutOfZone
);
746 elseif(pvpOutpostEndOfRound
~= 0) then
747 setDbProp(dbFmt
, game
.TBonusMalusSpecialTT
.OutpostPVPInRound
);
749 setDbProp(dbFmt
, game
.TBonusMalusSpecialTT
.OutpostPVPOn
);
757 -- ***************************************************************************
758 -- ***************************************************************************
760 -- ***************************************************************************
761 -- ***************************************************************************
764 ------------------------------------------------------------------------------------------------------------
765 function game
:updateCurrentActionPosition()
766 local uiMemory
= getUI("ui:interface:gestionsets");
767 local uiAction
= getUI("ui:interface:current_action");
768 local uiMain
= getUI("ui:interface");
769 if(uiAction
and uiMain
and uiMemory
and uiMemory
.active
) then
771 -- NB: must use harcoded 182 and 40 size for the window, because may not be active at this time
773 -- refresh the x position
774 uiAction
.x
= uiMemory
.x_real
+ uiMemory
.w_real
/2 - 182/2;
776 -- setup the y position according to position of the memory bar
777 local distBelow
= uiMemory
.y_real
;
778 local distAbove
= uiMain
.h
- (uiMemory
.y_real
+ uiMemory
.h_real
);
779 if(distBelow
< distAbove
) then
780 uiAction
.y
= uiMemory
.y_real
+ uiMemory
.h_real
+ 40;
782 uiAction
.y
= uiMemory
.y_real
;
789 LastTooltipPhrase
= nil
791 ------------------------------------------------------------------------------------------------------------
792 -- tool function used by game:updatePhraseTooltip
793 function game
:setPhraseTooltipCarac(ttWin
, name
, value
, textValue
)
794 local icon
= ttWin
:find(name
)
795 local text
= ttWin
:find(name
.. "_text")
802 if textValue
~= nil then
803 text
.uc_hardtext
= textValue
805 text
.hardtext
= tostring(value
)
811 function game
:timeInSecondsToReadableTime(regenTime
)
812 local seconds
= math
.fmod(regenTime
, 60)
813 local minutes
= math
.fmod(math
.floor(regenTime
/ 60), 60)
814 local hours
= math
.floor(regenTime
/ 3600)
816 if seconds
> 0 then result
= concatUCString(tostring(seconds
), i18n
.get("uittSecondsShort")) end
817 if minutes
> 0 then result
= concatUCString(tostring(minutes
), i18n
.get("uittMinutesShort"), result
) end
818 if hours
> 0 then result
= concatUCString(tostring(hours
), i18n
.get("uittHoursShort"), result
) end
822 ------------------------------------------------------------------------------------------------------------
823 -- display the time left for a power / auras in its tooltip
824 function game
:setPhraseTooltipPowerRegenTime(ttWin
, regenTimeInTicks
)
825 local text
= ttWin
:find("regen_time")
826 if regenTimeInTicks
== 0 then
830 text
.uc_hardtext_single_line_format
= concatUCString(i18n
.get("uittRegenTime"), game
:timeInSecondsToReadableTime(math
.floor((regenTimeInTicks
+ 9) * 0.1)))
831 text
:invalidateCoords()
832 ttWin
:invalidateCoords()
837 local EmptyUCString
= ucstring()
839 ------------------------------------------------------------------------------------------------------------
840 -- called by C++ code when the tooltip of a phrase is about to be displayed
841 function game
:updatePhraseTooltip(phrase
)
842 LastTooltipPhrase
= phrase
843 local ttWin
= getUI("ui:interface:action_context_help")
844 local text
= phrase
:getName()
846 if not text
or text
== EmptyUCString
then
850 local desc
= phrase
:getDesc()
851 if desc
and desc
~= EmptyUCString
then
852 local str
= tostring(desc
)
853 local charFound
= false
854 for k
= 1, string.len(str
) do
855 if string.byte(str
, k
) ~= 32 then
861 text
= concatUCString(text
, "\n@{CCCF}", desc
)
864 text
= concatUCString(text
, "@{CCCF}")
866 -- IMPORTANT : the following getters on 'phrase' take in account the 'total action malus' for the timebeing
867 self
:setPhraseTooltipCarac(ttWin
, "hp_cost", phrase
:getHpCost())
868 self
:setPhraseTooltipCarac(ttWin
, "sta_cost", phrase
:getStaCost())
869 self
:setPhraseTooltipCarac(ttWin
, "sap_cost", phrase
:getSapCost())
870 self
:setPhraseTooltipCarac(ttWin
, "focus_cost", phrase
:getFocusCost())
871 self
:setPhraseTooltipCarac(ttWin
, "cast_time", phrase
:getCastTime(), concatUCString(string.format("%.1f", phrase
:getCastTime()), i18n
.get("uittSeconds")))
872 local castRange
= phrase
:getCastRange()
873 if not phrase
:isMagicPhrase() then
876 self
:setPhraseTooltipCarac(ttWin
, "cast_range", castRange
, concatUCString(tostring(castRange
), i18n
.get("uittMeters")))
877 -- if the phrase is a power / aura, then we may want to display its regen time in the tooltip
878 if phrase
:isPowerPhrase() then
879 setOnDraw(ttWin
, "game:updatePowerPhraseTooltip()")
884 local successRateText
= ttWin
:find("success_rate")
885 local successRate
= phrase
:getSuccessRate()
886 if successRate
== 0 then
887 successRateText
.active
= false
889 successRateText
.active
= true
890 successRateText
.uc_hardtext_single_line_format
= concatUCString(i18n
.get("uittSuccessRate"), tostring(successRate
), " %")
893 local disableTimeText
= ttWin
:find("disable_time")
894 if phrase
:isPowerPhrase() then
895 local disableTime
= phrase
:getPowerDisableTime()
896 if disableTime
== 0 then
897 disableTimeText
.active
= false
899 disableTimeText
.active
= true
900 disableTimeText
.uc_hardtext_single_line_format
= concatUCString(i18n
.get("uittDisableTime"), game
:timeInSecondsToReadableTime(disableTime
/ 10))
903 disableTimeText
.active
= false
905 game
:updatePowerPhraseTooltip()
906 updateTooltipCoords()
910 ------------------------------------------------------------------------------------------------------------
911 -- called at each frame when a power/aura tooltip is displayed,in order to update the regen countdown
912 function game
:updatePowerPhraseTooltip()
913 local ttWin
= getUI("ui:interface:action_context_help")
914 local leftRegenTime
= 0
915 if LastTooltipPhrase
:isPowerPhrase() then
916 leftRegenTime
= LastTooltipPhrase
:getTotalRegenTime() - LastTooltipPhrase
:getRegenTime()
918 if leftRegenTime
< 0 then
921 self
:setPhraseTooltipPowerRegenTime(ttWin
, leftRegenTime
)
922 updateTooltipCoords()
926 -- ***************************************************************************
927 -- ***************************************************************************
929 -- ***************************************************************************
930 -- ***************************************************************************
932 ------------------------------------------------------------------------------------------------------------
933 -- called by C++ code when the tooltip of a buff item is about to be displayed
934 function game
:updateBuffItemTooltip(buffItem
)
935 local ttWin
= getUI("ui:interface:buff_item_context_help")
936 local text
= buffItem
:getName()
938 self
:setPhraseTooltipCarac(ttWin
, "hp_buff", buffItem
:getHpBuff())
939 self
:setPhraseTooltipCarac(ttWin
, "sta_buff", buffItem
:getStaBuff())
940 self
:setPhraseTooltipCarac(ttWin
, "sap_buff", buffItem
:getSapBuff())
941 self
:setPhraseTooltipCarac(ttWin
, "focus_buff", buffItem
:getFocusBuff())
943 updateTooltipCoords()
947 -- ***************************************************************************
948 -- ***************************************************************************
949 -- CURRENT CRYSTALLIZED SPELL
950 -- ***************************************************************************
951 -- ***************************************************************************
953 ------------------------------------------------------------------------------------------------------------
954 -- called by C++ code when the tooltip of a cristallized spell is about to be displayed
955 function game
:updateCrystallizedSpellTooltip(crystallizedSpell
)
956 local ttWin
= getUI("ui:interface:crystallized_spell_context_help")
957 local text
= crystallizedSpell
:getName()
959 crystallizedSpell
:buildCrystallizedSpellListBrick()
961 updateTooltipCoords()