Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / client / mods / syui_v3 / syui / player.lua
blob4753d84a1da4c95efbb4fd489b4d0dc7393ad6fb
1 -- In this file we define functions that serves for player windows
3 function getDbPropU(dbEntry)
4 value = getDbProp(dbEntry)
5 if (value < 0) then
6 value = 4294967296+value
7 end
8 return value
9 end
11 if string.find(_VERSION, "Lua 5.0") then
12 function math.fmod(a, b)
13 return math.mod(a, b)
14 end
15 end
17 ------------------------------------------------------------------------------------------------------------
18 -- create the game namespace without reseting if already created in an other file.
19 if (game==nil) then
20 game= {};
21 end
23 if (game.PVP == nil) then
24 game.PVP = {};
25 game.PVP.tagStartTimer = 0;
26 game.PVP.flagStartTimer = 0;
27 game.PVP.tagTimerStarted = false;
28 game.PVP.flagTimerStarted = false;
29 end
31 if (game.BonusMalus == nil) then
32 game.BonusMalus = {};
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= {};
43 end
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
72 ui.b_sap.y = -18;
73 ui.b_sta.y = -36;
74 ui.b_foc.y = -54;
75 ui.current_action.y = -65;
77 elseif (totalBarDisp == 2) then
79 if (dispSap == 0) then
80 ui.b_sta.y = -18;
81 ui.b_foc.y = -36;
82 end
84 if (dispSta == 0) then
85 ui.b_sap.y = -18;
86 ui.b_foc.y = -36;
87 end
89 if (dispFoc == 0) then
90 ui.b_sap.y = -18;
91 ui.b_sta.y = -36;
92 end
94 ui.current_action.y = -50;
96 elseif (totalBarDisp == 1) then
98 ui.b_sta.y = -18;
99 ui.b_foc.y = -18;
100 ui.b_sta.y = -18;
102 ui.current_action.y = -35;
104 else
105 ui.current_action.y = -18;
112 ------------------------------------------------------------------------------------------------------------
113 -- convert a boolean to a number 0 or 1
114 function booleanToNumber(thebool)
115 if(thebool) then
116 return 1;
117 else
118 return 0;
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
137 local GREEN= 0;
138 local ORANGE= 1;
139 local RED= 2;
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
145 -- ** RED MODE
146 buttonMode= RED;
147 buttonPushed= false;
148 buttonTimer= true;
149 -- else must display correct mode according to the TAG state
150 else
151 -- There are 8 possibilities according to the combination of the 3 flags
152 -- Here: TL= pvpLocalTag, TS= pvpServerTag, AS= pvpServerActivateTimerOn)
153 -- TL TS AS
154 -- ** GREEN MODE **
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
159 -- ** ORANGE MODE **
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
169 buttonMode= GREEN;
170 else
171 buttonMode= ORANGE;
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
176 buttonPushed= true;
177 else
178 buttonPushed= false;
181 -- display a timer only if the timer is activated and server and local tag are equals
182 if( pvpServerActivateTimerOn and pvpLocalTag == pvpServerTag ) then
183 buttonTimer= true;
184 else
185 buttonTimer= false;
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
196 if(buttonTimer) then
197 local uiBar = uiPlayer.pvp_timer;
198 local uiBarBg = uiPlayer.pvp_timer_bg;
199 -- Flag Bar?
200 if(buttonMode==RED) then
201 -- display a reverse timer
202 uiBar.w = uiBarBg.w * (pvpServerFlagTimer - currentServerTick) / (pvpServerFlagTimer - game.PVP.flagStartTimer);
203 else
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);
221 else
222 setDbProp('UI:TEMP:PVP_FACTION:TAG_PVP',0);
224 sendMsgToServerPvpTag(buttonStat == 0);
226 -- update display
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()
264 -- update display
265 self:pvpTagUpdateDisplay();
267 -- try to stop
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));
300 return fmt;
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);
311 local text;
313 -- Flag mode?
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);
320 -- Tag mode
321 else
322 -- base text
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');
331 else
332 text = ucstring();
334 -- timer
335 if(buttonTimer) then
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);
345 -- set the text
346 setContextHelpText(text);
351 -- ***************************************************************************
352 -- ***************************************************************************
353 -- BONUS MALUS
354 -- ***************************************************************************
355 -- ***************************************************************************
358 ------------------------------------------------------------------------------------------------------------
359 function game:bonusMalusActiveText(ui, slot, state)
360 local uiTextGroup= ui["text" .. tostring(slot) ];
361 if(uiTextGroup) then
362 uiTextGroup.active= state;
366 ------------------------------------------------------------------------------------------------------------
367 function game:bonusMalusSetText(ui, slot, fmt)
368 local uiTextGroup= ui["text" .. tostring(slot) ];
369 if(uiTextGroup) then
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
383 if(ui==nil) then
384 ui= getUICaller();
387 -- format the text
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
398 if(ui==nil) then
399 ui= getUICaller();
402 -- format the text
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
412 if(ui==nil) then
413 ui= getUICaller();
416 -- Get the timer of interest (priority to player leaving the zone)
417 local endTimer= 0;
418 local endOfPvpTimer= getDbPropU('SERVER:CHARACTER_INFO:PVP_OUTPOST:FLAG_PVP_TIME_END');
419 if( endOfPvpTimer>0 ) then
420 endTimer= endOfPvpTimer;
421 else
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;
433 -- replace in str
434 local text= "@{FF6F}" .. runFct('secondsToTimeStringShort', timeSec);
435 self:bonusMalusSetText(ui, textSlot, text);
436 -- else Default display
437 else
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];
455 if(ui and ah) then
456 runAH(ui, ah, "");
460 function game:onLeftClickMalus()
461 local ui= getUICaller();
462 local id= getIndexInDB(ui);
463 local ah= self.BonusMalus.MalusAHList[id];
464 if(ui and ah) then
465 runAH(ui, ah, "");
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";
481 -- reset cache
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
490 -- reset AH
491 self.BonusMalus.BonusAHList[i]= nil;
492 self.BonusMalus.MalusAHList[i]= nil;
493 -- hide text view
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;
505 if(slot~=-1) then
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);
511 -- show text
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;
519 if(slot~=-1) then
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);
525 -- show text
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;
534 if(slot~=-1) then
535 -- no AH
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);
539 -- show text
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;
547 if(slot~=-1) then
548 -- no AH
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);
552 -- show text
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:";
570 local i;
571 local mustUpdateTextSetup= false;
574 -- ***********************
575 -- *** Insert Bonus
576 -- ***********************
577 local destIndex= 0;
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
585 local iconLevel= 50;
586 for i= 50,250,50 do
587 if(i<=xpcatLevel) then
588 iconLevel= i;
591 -- Set the DB for this brick
592 mustShowBonus= true;
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;
597 else
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
609 local iconLevel= 50;
610 for i= 50,250,50 do
611 if(i<=ringxpcatLevel) then
612 iconLevel= i;
615 -- Set the DB for this brick
616 mustShowBonus= true;
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;
621 else
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
643 mustShowBonus= true;
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;
648 else
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
658 -- get
659 local sheet= getDbProp(dbServerBonusBase .. tostring(i) .. ":SHEET" );
660 local disabled= getDbProp(dbServerBonusBase .. tostring(i) .. ":DISABLED" );
661 if(sheet~=0) then
662 mustShowBonus= true;
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);
671 else
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 -- ***********************
685 -- *** Insert Malus
686 -- ***********************
687 local mustShowMalus= false;
688 destIndex= 0;
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
694 mustShowMalus= true;
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;
699 else
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
708 -- get
709 local sheet= getDbProp(dbServerMalusBase .. tostring(i) .. ":SHEET" );
710 local disabled= getDbProp(dbServerMalusBase .. tostring(i) .. ":DISABLED" );
711 if(sheet~=0) then
712 mustShowMalus= true;
714 -- copy
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);
721 else
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);
748 else
749 setDbProp(dbFmt, game.TBonusMalusSpecialTT.OutpostPVPOn);
757 -- ***************************************************************************
758 -- ***************************************************************************
759 -- CURRENT ACTION
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;
781 else
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")
796 if value == 0 then
797 icon.active = false
798 text.active = false
799 else
800 icon.active = true
801 text.active = true
802 if textValue ~= nil then
803 text.uc_hardtext = textValue
804 else
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)
815 local result = ""
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
819 return result
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
827 text.active = false
828 else
829 text.active = true
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
847 text = ucstring("")
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
856 charFound = true
857 break
860 if charFound then
861 text = concatUCString(text, "\n@{CCCF}", desc)
863 else
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
874 castRange = 0
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()")
880 else
881 setOnDraw(ttWin, "")
884 local successRateText = ttWin:find("success_rate")
885 local successRate = phrase:getSuccessRate()
886 if successRate == 0 then
887 successRateText.active = false
888 else
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
898 else
899 disableTimeText.active = true
900 disableTimeText.uc_hardtext_single_line_format = concatUCString(i18n.get("uittDisableTime"), game:timeInSecondsToReadableTime(disableTime / 10))
902 else
903 disableTimeText.active = false
905 game:updatePowerPhraseTooltip()
906 updateTooltipCoords()
907 return text
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()
917 end
918 if leftRegenTime < 0 then
919 leftRegenTime = 0
921 self:setPhraseTooltipPowerRegenTime(ttWin, leftRegenTime)
922 updateTooltipCoords()
926 -- ***************************************************************************
927 -- ***************************************************************************
928 -- CURRENT BUFF ITEM
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()
944 return text
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()
962 return text