Fix
[ryzomcore.git] / ryzom / client / data / gamedev / interfaces_v3 / interaction.lua
blob663d352a1bcccd805545adfb4137d45dd96299cb
1 -- In this file we define functions that serves for interaction windows
4 ------------------------------------------------------------------------------------------------------------
5 -- create the game namespace without reseting if already created in an other file.
6 if (game == nil) then
7 game={}
8 end
10 if (game.ui_props == nil) then
11 game.ui_props = {}
12 end
14 if arkNpcShop == nil then
15 arkNpcShop = {}
16 end
18 ------------------------------------------------------------------------------------------------------------
20 function string:split(Pattern)
21 local Results = {}
22 local Start = 1
23 local SplitStart, SplitEnd = string.find(self, Pattern, Start)
24 while(SplitStart)do
25 table.insert(Results, string.sub(self, Start, SplitStart-1))
26 Start = SplitEnd+1
27 SplitStart, SplitEnd = string.find(self, Pattern, Start)
28 end
29 table.insert(Results, string.sub(self, Start))
30 return Results
31 end
33 ------------------------------------------------------------------------------------------------------------
34 -- called when server send an invitaion we receive a text id containing the string to display (invitor name)
35 function game:onTeamInvation(textID)
37 local ui = getUI('ui:interface:join_team_proposal')
38 ui.content.inside.invitor_name.textid = textID
39 ui.active = true
40 setTopWindow(ui)
41 ui:center()
42 ui:blink(2)
43 end
45 ------------------------------------------------------------------------------------------------------------
47 function game:teamInvitationAccept()
49 local ui = getUI('ui:interface:join_team_proposal')
50 ui.active = false
51 sendMsgToServer('TEAM:JOIN')
52 end
54 ------------------------------------------------------------------------------------------------------------
56 function game:teamInvitationRefuse()
58 local ui = getUI('ui:interface:join_team_proposal')
59 ui.active = false
60 sendMsgToServer('TEAM:JOIN_PROPOSAL_DECLINE')
61 end
63 ------------------------------------------------------------------------------------------------------------
64 -- send team invite from friendslist
65 function game:teamInvite(uiID)
66 runAH(nil, 'talk', 'mode=0|text=/invite '.. getUI('ui:interface:' .. uiID).title)
67 end
69 ------------------------------------------------------------------------------------------------------------
70 -- send team invite from guildwindow
71 function game:teamInviteFromGuild(uiID)
72 runAH(nil, 'talk', 'mode=0|text=/invite ' .. getGuildMemberName(tonumber(uiID:split(":m")[2])))
73 end
75 ------------------------------------------------------------------------------------------------------------
76 --Send Guild invite from guildwindow
77 function game:invToGuild()
78 player = getUI('ui:interface:add_guild'):find('edit_text').hardtext:split(">")[2]
79 if(player ~= '')then
80 runAH(nil, 'talk', 'mode=0|text=/guildinvite ' .. player)
81 end
82 runAH(nil, 'leave_modal', '')
83 end
85 ------------------------------------------------------------------------------------------------------------
86 --Check and active invite to guild button
87 function game:updateGLinvB()
88 if(getUI('ui:interface:guild').active)then
89 for v = 0, (getNbGuildMembers()-1) do
90 local invB = getUI('ui:interface:guild:content:tab_guild_info:invite')
91 if(getPlayerName() == getGuildMemberName(v))then
92 --debugInfo(getGuildMemberName(v))
93 if(getGuildMemberGrade(v) ~= 'Member')then
94 if(invB.active == false)then
95 invB.active = true
96 end
97 else
98 invB.active = false
99 end
105 ------------------------------------------------------------------------------------------------------------
107 function game:switchChatTab(dbEntry)
108 local db= 'UI:SAVE:ISENABLED:' .. dbEntry
109 local val= getDbProp(db)
110 -- switch value
111 if(val==0) then
112 setDbProp(db, 1)
113 else
114 setDbProp(db, 0)
118 ------------------------------------------------------------------------------------------------------------
120 if (ui_free_chat_h == nil) then
121 ui_free_chat_h = {}
124 if (ui_free_chat_w == nil) then
125 ui_free_chat_w = {}
128 ------------------------------------------------------------------------------------------------------------
130 function game:closeTellHeader(uiID)
131 local ui = getUI('ui:interface:' .. uiID);
133 -- save size
134 ui_free_chat_h[uiID] = ui.h;
135 ui_free_chat_w[uiID] = ui.w;
137 -- reduce window size
138 ui.pop_min_h = 32;
139 ui.h = 0;
140 ui.w = 216;
143 ------------------------------------------------------------------------------------------------------------
145 function game:openTellHeader(uiID)
146 local ui = getUI('ui:interface:' .. uiID);
147 ui.pop_min_h = 96;
149 -- set size from saved values
150 if (ui_free_chat_h[uiID] ~= nil) then
151 ui.h = ui_free_chat_h[uiID];
154 if (ui_free_chat_w[uiID] ~= nil) then
155 ui.w = ui_free_chat_w[uiID];
158 -- set Header Color to normal values (when a tell is closed and the telled player say someone, header change to "UI:SAVE:WIN:COLORS:INFOS")
159 ui:setHeaderColor('UI:SAVE:WIN:COLORS:COM');
163 --/////////////////////////
164 --// TARGET WINDOW SETUP //
165 --/////////////////////////
167 -- local functions for tests
168 local function levelToForceRegion(level)
169 if level < 20 then
170 return 1
171 elseif level >= 250 then
172 return 6
173 else
174 return math.floor(level / 50) + 2
178 local function levelToLevelForce(level)
179 return math.floor(math.fmod(level, 50) * 5 / 50) + 1
184 -- tmp var for tests in local mode
185 local twPlayerLevel = 10
186 local twTargetLevel = 19
187 local twTargetForceRegion = levelToForceRegion(twTargetLevel)
188 local twTargetLevelForce = levelToLevelForce(twTargetLevel)
189 local twTargetPlayer = false
190 local twPlayerInPVPMode = false
191 local twTargetInPVPMode = false
194 -----------------------------------
195 local function twGetPlayerLevel()
196 if config.Local == 1 then
197 return twPlayerLevel
198 else
199 return getPlayerLevel()
203 -----------------------------------
204 local function twGetTargetLevel()
205 if config.Local == 1 then
206 return twTargetLevel
207 else
208 return getTargetLevel()
212 -----------------------------------
213 local function twGetTargetForceRegion()
214 if config.Local == 1 then
215 return twTargetForceRegion
216 else
217 return getTargetForceRegion()
221 -----------------------------------
222 local function twGetTargetLevelForce()
223 if config.Local == 1 then
224 return twTargetLevelForce
225 else
226 return getTargetLevelForce()
230 -----------------------------------
231 local function twIsTargetPlayer()
232 if config.Local == 1 then
233 return twTargetPlayer
234 else
235 return isTargetPlayer()
239 -----------------------------------
240 local function twIsPlayerInPVPMode()
241 if config.Local == 1 then
242 return twPlayerInPVPMode
243 else
244 return isPlayerInPVPMode()
248 -----------------------------------
249 local function twIsTargetInPVPMode()
250 if config.Local == 1 then
251 return twTargetInPVPMode
252 else
253 return isTargetInPVPMode()
258 game.updateRpItemsUrl = nil
259 game.wantedRpLeftItem = ""
260 game.wantedRpRightItem = ""
261 game.wantedRpTargets = {}
262 game.wantedRpPositions = {}
264 function game:addRequireRpItemsPosition(x, y, id)
265 local sx = tostring(math.floor(x/10))
266 local sy = tostring(math.floor(y/10))
267 game.wantedRpPositions[sx..":"..sy] = id
270 function game:addRequireRpItems(left, target, mode, id)
271 game.wantedRpTargets[left..":"..target..":"..mode] = id
274 game.usedRpLeftItem = "_"
275 game.usedRpRightItem = "_"
277 function game:updateRpItems()
278 local left = getPlayerTag(6)
279 local right = getPlayerTag(5)
281 if getDbProp("LOCAL:INVENTORY:HAND:1:INDEX_IN_BAG") ~= 0 then
282 left = "_"
285 if getDbProp("LOCAL:INVENTORY:HAND:0:INDEX_IN_BAG") ~= 0 then
286 right = "_"
289 if game.updateRpItemsUrl then
290 if game.usedRpLeftItem ~= left or game.usedRpRightItem ~= right then
291 game.usedRpLeftItem = left
292 game.usedRpRightItem = right
293 webig:openUrl(game.updateRpItemsUrl.."&left_hand="..left.."&right_hand="..right)
296 local target = tostring(getTargetSheet())
298 local mode = ""
299 if target ~= "" then
300 mode = tostring(getTargetMode())
303 local html = getUI("ui:interface:rpitems_actions"):find("html")
304 for k, v in pairs(game.wantedRpTargets) do
305 local a = html:find("action"..v)
306 if a then
307 if string.find(left..":"..target..":"..mode, k) or string.find(left..":"..target..":*", k) then
308 a:find("but").frozen = false
309 a:find("text").alpha = 255
310 else
311 a:find("but").frozen = true
312 a:find("text").alpha = 155
319 function game:checkRpItemsPosition()
320 local x,y,z = getPlayerPos()
321 local sx = tostring(math.floor(x/10))
322 local sy = tostring(math.floor(y/10))
323 local html = getUI("ui:interface:rpitems_actions"):find("html")
324 for k, v in pairs(game.wantedRpPositions) do
325 local a = html:find("action"..v)
326 if a then
327 if string.find(sx..":"..sy, k) then
328 a:find("but").frozen = false
329 a:find("text").alpha = 255
330 else
331 a:find("but").frozen = true
332 a:find("text").alpha = 155
338 ------------------------------------------------------------------------------------------------------------
339 -- This function is called when a new target is selected, it should update the 'consider' widget
340 -- Level of the creature
341 -- Is its level known (not too high ...)
342 -- Boss/Mini-bosses/Names colored ring
344 function game:updateTargetConsiderUI()
345 game:updateRpItems(game.usedRpLeftItem, game.usedRpRightItem)
346 local targetWindow = getUI("ui:interface:target")
348 local wgTargetSlotForce = targetWindow:find("slot_force")
349 local wgTargetLevel = targetWindow:find("target_level")
350 local wgImpossible = targetWindow:find("impossible")
351 local wgSlotRing = targetWindow:find("slot_ring")
352 local wgToolTip = targetWindow:find("target_tooltip")
353 local wgPvPTag = targetWindow:find("pvp_tags")
354 local wgHeader = targetWindow:find("header_opened")
355 local wgLock = targetWindow:find("lock")
357 wgTargetSlotForce.active = true
358 wgTargetSlotForce.texture = "consider_bg.tga"
359 wgImpossible.active = true
360 wgTargetSlotForce.h = 16
362 -- no selection ?
363 if twGetTargetLevel() == -1 then
364 wgLock.active = false
365 wgTargetSlotForce.active = false
366 wgTargetLevel.active = false
367 wgImpossible.active = false
368 wgSlotRing.active = false
369 if (isTargetUser() and twIsPlayerInPVPMode()) then
370 wgToolTip.tooltip = ""
371 wgPvPTag.active = true
372 wgHeader.h = 56;
373 else
374 wgPvPTag.active = false
375 wgHeader.h = 34;
376 wgToolTip.tooltip = i18n.get("uittConsiderTargetNoSelection")
378 return
381 local pvpMode = false
382 wgPvPTag.active = false
383 wgHeader.h = 34;
386 -- /luaScript getUI("ui:interface:target:header_opened:lock").active=true
388 -- if the selection is a player, then both the local & targeted player must be in PVP mode for the level to be displayed
389 if (twIsTargetPlayer()) then
390 -- don't display anything ...
391 wgLock.active = false
392 wgTargetSlotForce.active = false
393 wgTargetLevel.active = false
394 wgImpossible.active = false
395 wgSlotRing.active = false
396 wgToolTip.tooltip = ""
397 if twIsTargetInPVPMode() then
398 wgPvPTag.active = true
399 wgHeader.h = 56;
401 return
402 else
403 wgLock.active = false
404 local level = getDbProp(getDefine("target_player_level"))
406 if level == 2 then -- Locked by team of player
407 wgLock.active = true
408 wgLock.color = "50 250 250 255"
409 else
410 if level == 1 then -- Locked by another team
411 wgLock.active = true
412 wgLock.color = "250 50 50 255"
417 -- depending on the number of people in the group, set the max diff for visibility between player level
418 -- & creature level (x 10 per member)
419 local maxDiffLevel = 10
420 if not pvpMode then
421 -- exception there : when "pvping", don't relate the levelof the target to the level of the group, but to thelocal
422 -- player only
423 for gm = 0, 7 do
424 if getDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT") ~= 0 then
425 maxDiffLevel = maxDiffLevel + 10
430 --debugInfo("Max diff level= " .. tostring(maxDiffLevel))
432 local impossible = (twGetTargetLevel() - twGetPlayerLevel() > maxDiffLevel)
434 wgSlotRing.active = false
436 if impossible then
437 -- targeted object is too hard too beat, display a skull
438 wgTargetLevel.active = false
439 wgImpossible.y = -5
440 wgImpossible.color = "255 50 50 255"
441 else
442 -- player can see the level of the targeted creature
443 wgTargetLevel.active = true
444 wgImpossible.y = 6
445 wgTargetLevel.hardtext = tostring(twGetTargetLevel())
446 wgImpossible.color = "255 255 255 255"
447 wgTargetLevel.color = getDefine("region_force_" .. tostring(levelToForceRegion(twGetTargetLevel())))
450 -- based on the 'level force', set a colored ring around the level
451 local levelForce = twGetTargetLevelForce()
452 wgTargetSlotForce.color = getDefine("region_force_" .. tostring(levelToForceRegion(twGetTargetLevel())))
454 wgImpossible.texture = getDefine("force_level_" .. tostring(levelForce))
455 wgImpossible.active = true
456 if levelForce < 6 then
457 wgToolTip.tooltip = i18n.get("uittConsiderTargetLevel")
458 elseif levelForce == 6 then
459 -- Named creature
460 wgImpossible.color = "117 132 126 255"
461 wgSlotRing.color = "117 132 126 255"
462 wgTargetSlotForce.color = "117 132 126 255"
463 wgSlotRing.texture = "consider_ring.tga"
464 wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss")
465 elseif levelForce == 7 then
466 -- Boss
467 wgImpossible.color = "156 98 65 255"
468 wgSlotRing.color = "156 98 65 255"
469 wgTargetSlotForce.color = "156 98 65 255"
470 wgSlotRing.texture = "consider_ring.tga"
471 wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss")
472 elseif levelForce == 8 then
473 -- Mini-Boss
474 wgImpossible.color = "213 212 9 255"
475 wgSlotRing.texture = "consider_ring.tga"
476 wgSlotRing.color = "213 212 9 255"
477 if isTargetNPC() then
478 wgTargetSlotForce.color = "255 255 255 255"
479 wgToolTip.tooltip = i18n.get("uittConsiderBossNpc")
480 else
481 wgTargetSlotForce.color = "213 212 9 255"
482 wgToolTip.tooltip = i18n.get("uittConsiderBoss")
484 elseif levelForce == 12 then
485 wgImpossible.color = "255 255 255 255"
486 wgTargetSlotForce.texture = "episode_step.tga"
487 wgTargetSlotForce.color = "255 255 255 255"
488 wgToolTip.tooltip = i18n.get("uittConsiderUnknownLevel")
489 wgTargetLevel.active = false
490 wgImpossible.y = -5
491 elseif levelForce > 12 then
492 wgImpossible.color = "255 255 255 255"
493 wgTargetSlotForce.texture = "episode_step_ok.tga"
494 wgTargetSlotForce.color = "255 255 255 255"
495 wgToolTip.tooltip = i18n.get("uittConsiderSpecialLevel")
496 wgTargetLevel.active = false
497 wgImpossible.y = -5
500 if impossible then
501 wgToolTip.tooltip = concatUCString(wgToolTip.tooltip, ucstring("\n"), i18n.get("uittConsiderUnknownLevel"))
505 ----------------------
506 -- MISC local tests function
507 -- no selection
508 function twTest0()
509 twTargetLevel = -1
510 twTargetPlayer = false
511 game:updateTargetConsiderUI()
513 -- selection, not impossible
514 function twTest1()
515 twTargetPlayer = false
516 twPlayerLevel = 10
517 twTargetLevel = 15
518 twTargetForceRegion = levelToForceRegion(twTargetLevel)
519 twTargetLevelForce = levelToLevelForce(twTargetLevel)
520 game:updateTargetConsiderUI()
522 -- selection, not impossible (limit)
523 function twTest2()
524 twTargetPlayer = false
525 twPlayerLevel = 10
526 twTargetLevel = 20
527 twTargetForceRegion = levelToForceRegion(twTargetLevel)
528 twTargetLevelForce = levelToLevelForce(twTargetLevel)
529 game:updateTargetConsiderUI()
531 -- selection, impossible
532 function twTest3()
533 twTargetPlayer = false
534 twPlayerLevel = 10
535 twTargetLevel = 21
536 twTargetForceRegion = levelToForceRegion(twTargetLevel)
537 twTargetLevelForce = levelToLevelForce(twTargetLevel)
538 game:updateTargetConsiderUI()
540 ------ NAMED
541 ------
542 -- selection, not impossible, named
543 function twTest4()
544 twTargetPlayer = false
545 twPlayerLevel = 10
546 twTargetLevel = 15
547 twTargetForceRegion = levelToForceRegion(twTargetLevel)
548 twTargetLevelForce = 6
549 game:updateTargetConsiderUI()
551 -- selection, not impossible (limit), named
552 function twTest5()
553 twTargetPlayer = false
554 twPlayerLevel = 10
555 twTargetLevel = 20
556 twTargetForceRegion = levelToForceRegion(twTargetLevel)
557 twTargetLevelForce = 6
558 game:updateTargetConsiderUI()
560 -- selection, impossible, named
561 function twTest6()
562 twTargetPlayer = false
563 twPlayerLevel = 10
564 twTargetLevel = 21
565 twTargetForceRegion = levelToForceRegion(twTargetLevel)
566 twTargetLevelForce = 6
567 game:updateTargetConsiderUI()
569 ------ BOSS
570 ------
571 -- selection, not impossible, boss
572 function twTest7()
573 twTargetPlayer = false
574 twPlayerLevel = 10
575 twTargetLevel = 15
576 twTargetForceRegion = levelToForceRegion(twTargetLevel)
577 twTargetLevelForce = 7
578 game:updateTargetConsiderUI()
580 -- selection, not impossible (limit), boss
581 function twTest8()
582 twTargetPlayer = false
583 twPlayerLevel = 10
584 twTargetLevel = 20
585 twTargetForceRegion = levelToForceRegion(twTargetLevel)
586 twTargetLevelForce = 7
587 game:updateTargetConsiderUI()
589 -- selection, impossible, boss
590 function twTest9()
591 twTargetPlayer = false
592 twPlayerLevel = 10
593 twTargetLevel = 21
594 twTargetForceRegion = levelToForceRegion(twTargetLevel)
595 twTargetLevelForce = 7
596 game:updateTargetConsiderUI()
598 ------ MINI-BOSS
599 ------
600 -- selection, not impossible, boss
601 function twTest10()
602 twTargetPlayer = false
603 twPlayerLevel = 10
604 twTargetLevel = 15
605 twTargetForceRegion = levelToForceRegion(twTargetLevel)
606 twTargetLevelForce = 8
607 game:updateTargetConsiderUI()
609 -- selection, not impossible (limit), boss
610 function twTest11()
611 twTargetPlayer = false
612 twPlayerLevel = 10
613 twTargetLevel = 20
614 twTargetForceRegion = levelToForceRegion(twTargetLevel)
615 twTargetLevelForce = 8
616 game:updateTargetConsiderUI()
618 -- selection, impossible, boss
619 function twTest12()
620 twTargetPlayer = false
621 twPlayerLevel = 10
622 twTargetLevel = 21
623 twTargetForceRegion = levelToForceRegion(twTargetLevel)
624 twTargetLevelForce = 8
625 game:updateTargetConsiderUI()
628 ------ PLAYER SELECTION
629 ------ 2 players, no pvp
630 function twTest13()
631 twTargetPlayer = true
632 twPlayerInPVPMode = false
633 twTargetInPVPMode = false
635 twPlayerLevel = 10
636 twTargetLevel = 15
637 twTargetForceRegion = levelToForceRegion(twTargetLevel)
638 twTargetLevelForce = levelToLevelForce(twTargetLevel)
639 game:updateTargetConsiderUI()
642 function twTest14()
643 twTargetPlayer = true
644 twPlayerInPVPMode = true
645 twTargetInPVPMode = true
647 twPlayerLevel = 10
648 twTargetLevel = 15
649 twTargetForceRegion = levelToForceRegion(twTargetLevel)
650 twTargetLevelForce = levelToLevelForce(twTargetLevel)
651 game:updateTargetConsiderUI()
655 ------ 2 players, pvp
657 -- groups
658 function twGroup(groupSize)
659 for gm = 0, 7 do
660 if gm < groupSize then
661 setDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT", 1)
662 else
663 setDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT", 0)
668 ------------------------------------------------------------------------------------------------------------
670 function game:closeWebIGBrowserHeader()
671 local ui = getUI('ui:interface:webig')
673 -- save size
674 ui_webig_browser_h = ui.h
675 ui_webig_browser_w = ui.w
677 -- reduce window size
678 ui.pop_min_h = 32
679 ui.h = 0
680 ui.w = 150
683 ------------------------------------------------------------------------------------------------------------
685 function game:openWebIGBrowserHeader()
686 local ui = getUI('ui:interface:webig');
687 ui.pop_min_h = 96;
689 -- set size from saved values
690 if (ui_webig_browser_h ~= nil) then
691 ui.h = ui_webig_browser_h;
694 if (ui_webig_browser_w ~= nil) then
695 ui.w = ui_webig_browser_w;
699 ------------------------------------------------------------------------------------------------------------
701 function game:closeWindowHeader()
702 local ui = getUICaller().parent;
703 local id = ui.id;
705 if game.ui_props[id] == nil then
706 game.ui_props[id] = {}
709 -- save size
710 game.ui_props[id].w = ui.w
711 game.ui_props[id].h = ui.h
712 game.ui_props[id].pop_min_h = ui.pop_min_h
714 -- reduce window size
715 ui.pop_min_h = 32
716 ui.h = 0;
717 ui.w = 150
720 ------------------------------------------------------------------------------------------------------------
722 function game:openWindowHeader()
723 local ui = getUICaller().parent;
724 local id = ui.id;
726 if ui ~= nil and game.ui_props[id] ~= nil then
727 -- set size from saved values
728 if game.ui_props[id].pop_min_h ~= nil then
729 ui.pop_min_h = game.ui_props[id].pop_min_h
732 if game.ui_props[id].h ~= nil then
733 ui.h = game.ui_props[id].h
736 if ui_webig_browser_w ~= nil then
737 ui.w = game.ui_props[id].w;
743 ------------------------------------------------------------------------------------------------------------
744 function game:openGuildIsland(url_island)
745 local nbMember = getNbGuildMembers();
746 local params = "";
747 for i = 0,(nbMember-1) do
748 local memberGrade = getGuildMemberGrade(i);
749 if (memberGrade == "Leader") or (memberGrade == "HighOfficer") then
750 params = params .. string.lower(getGuildMemberName(i)) .. "=" .. memberGrade.."&";
753 local x,y,z = getPlayerPos()
754 params = params .. "&posx=" .. tostring(x) .. "&posy=" .. tostring(y) .. "&posz=" .. tostring(z)
756 getUI("ui:interface:guild:content:tab_island:props:html"):browse(url_island.."params="..params);
757 runAH(nil, "browse_home", "name=ui:interface:guild:content:tab_island:inv:html")
760 function game:openGuildSpecialBag()
761 runAH(nil, "browse_home", "name=ui:interface:guild:content:tab_special_bag:inv:html")
766 ------------------------------------------------------------------------------------------------------------
767 local SavedUrl = "";
768 function game:chatUrl(url)
769 SavedUrl = url
770 runAH(nil, "active_menu", "menu=ui:interface:chat_uri_action_menu")
772 function game:chatUrlCopy()
773 runAH(nil, "copy_to_clipboard", SavedUrl)
775 function game:chatUrlBrowse()
776 runAH(nil, "browse", "name=ui:interface:webig:content:html|url=" .. SavedUrl)
779 ------------------------------------------------------------------------------------------------------------
781 if game.sDynChat == nil then game.sDynChat = {} end
783 -- called from onInGameDbInitialized
784 function game:openChannels()
785 if getDbProp("UI:SAVE:CHAT:AUTO_CHANNEL") > 0 then
786 local uc = readUserChannels()
787 if uc then
788 local index = 0
789 for _ in pairs(uc) do
790 index = index + 1
792 local channels = {}
793 for i = 0, index-1 do
794 local node = uc[tostring(i)]
795 channels[tonumber(node.id)] = {
796 rgba = node.rgba,
797 name = node.name,
798 passwd = node.passwd
801 local t = {}
803 for k in pairs(channels) do table.insert(t, k) end
804 table.sort(t)
805 -- sorted
806 for _, id in ipairs(t) do
807 local found = false
808 for i = 0, getMaxDynChan()-1 do
809 if getDbProp("UI:SAVE:ISENABLED:DYNAMIC_CHAT"..i) == 1 then
810 local cname = getDbProp("SERVER:DYN_CHAT:CHANNEL"..i..":NAME")
811 if isDynStringAvailable(cname) then
812 local chan = getDynString(cname):toUtf8()
813 -- already opened?
814 if channels[id].name == chan then found = true end
818 if not found then
819 self:connectUserChannel(channels[id].name.." "..channels[id].passwd)
820 -- now restore colors
821 if channels[id].rgba ~= '' then
822 local i = 0
823 local c = {}
824 local rgba = {[0]="R", [1]="G", [2]="B", [3]="A"}
825 for color in string.gmatch(channels[id].rgba, "%d+") do
826 c[rgba[i]] = tonumber(color)
827 i = i + 1
829 setDbRGBA("UI:SAVE:CHAT:COLORS:DYN:"..id, CRGBA(c.R, c.G, c.B, c.A))
837 -- store channel detail before it open
838 function game:connectUserChannel(args)
839 local argv = {}
840 for w in string.gmatch(args, "%S+") do
841 table.insert(argv, w)
843 if #argv > 0 then
844 local params = argv[1]
845 if #argv == 2 then
846 for _, ch in pairs(self.sDynChat) do
847 if ch[argv[1]] then ch[argv[1]] = nil end
849 if argv[2] ~= '*' and argv[2] ~= '***' then
850 table.insert(self.sDynChat, {[argv[1]]=argv[2]})
852 params = params.." "..argv[2]
854 runAH(nil, "talk", "mode=0|text=/a connectUserChannel "..params)
858 -- save user created channels
859 function game:saveChannel(verbose)
860 if verbose == nil then
861 verbose = false
863 local channels = {}
864 for i = 0, getMaxDynChan()-1 do
865 if getDbProp("UI:SAVE:ISENABLED:DYNAMIC_CHAT"..i) == 1 then
866 local cname = getDbProp("SERVER:DYN_CHAT:CHANNEL"..i..":NAME")
867 if isDynStringAvailable(cname) then
868 local chan = getDynString(cname):toUtf8()
869 local found = false
870 -- avoid empty cvar case
871 if getClientCfgVar("ChannelIgnoreFilter") then
872 for _, k in pairs(getClientCfgVar("ChannelIgnoreFilter")) do
873 if k == chan then found = true end
875 if not found then
876 -- store current colors
877 local cRGBA = getDbRGBA("UI:SAVE:CHAT:COLORS:DYN:"..i)
878 local password = ''
879 -- include private channels
880 for _, k in pairs(game.sDynChat) do
881 if k[chan] then password = k[chan] end
883 channels[tostring(i)] = {
884 rgba = cRGBA,
885 name = chan,
886 passwd = password
893 saveUserChannels(channels, verbose)
896 ------------------------------------------------------------------------------------------------------------
898 function game:chatWelcomeMsg(input)
899 local msg
900 local name
901 if not input then
902 input = getUICaller().params_r
903 if input then
904 input = input:match("ED:([^_]+)"):lower()
907 local chat = input
908 local temp = "UI:TEMP:ONCHAT:"
909 if game.InGameDbInitialized then
910 -- is input chat a dynamic channel?
911 if type(input) == "number" then
912 local id = getDbProp("SERVER:DYN_CHAT:CHANNEL"..input..":NAME")
913 if isDynStringAvailable(id) then
914 name = getDynString(id):toUtf8()
915 -- variable for this session
916 if getDbProp(temp..name) == 0 then
917 -- faction, nation and organization
918 for k, v in pairs({
919 kami = i18n.get("uiFameAllegiance2"),
920 karavan = i18n.get("uiFameAllegiance3"),
921 fyros = i18n.get("uiFameAllegiance4"),
922 matis = i18n.get("uiFameAllegiance5"),
923 tryker = i18n.get("uiFameAllegiance6"),
924 zorai = i18n.get("uiFameAllegiance7"),
925 marauder = i18n.get("uiFameMarauders"),
926 ranger = i18n.get("uiOrganization_7")
927 }) do
928 if name == v:toUtf8() then
929 msg = i18n.get("uiWelcome_"..k)
930 name = v:toUtf8()
934 -- chat_group_filter sParam
935 chat = "dyn_chat"..input
937 else
938 -- around, region and universe
939 if getDbProp(temp..input) == 0 then
940 msg = i18n.get("uiWelcome_"..input)
941 name = input
944 if msg then
945 displayChatMessage(tostring(msg), input)
946 -- save for this session
947 addDbProp(temp..name, 1)
950 runAH(getUICaller(), "chat_group_filter", chat)
954 function game:TalkWithNpc(bullying)
955 setTargetAsInterlocutor()
957 if bullying == 1 then
958 runCommand("a", "openTargetUrl", "1")
959 else
960 runCommand("a", "openTargetUrl")
965 -----------------------------------
966 --- ARK NPC SHOP
968 function tablelength(T)
969 if T == nil then
970 return 0
972 local count = 0
973 for _ in pairs(T) do count = count + 1 end
974 return count
977 function arkNpcShop:showBuy()
978 getUI("ui:interface:ark_shop_buy_item"):find("ok").active=true
981 function arkNpcShop:openSection(url)
982 framewin = getUI("ui:interface:ark_npc_shop"):find("buy"):renderHtml(arkNpcShop.PleaseWait)
983 getUI("ui:interface:web_transactions"):find("html"):browse(url)
986 function arkNpcShop:updateWindow(px, py)
987 local x, y, z = getPlayerPos()
988 local stop = false
989 if (px-x)*(px-x)+(py-y)*(py-y) > 25 then
990 local w = getUI("ui:interface:ark_npc_shop")
991 w.active = false
992 setOnDraw(w, "")
993 getUI("ui:interface:ark_shop_buy_item").active = false
994 arkNpcShop.player_can_buy = false
995 broadcast(arkNpcShop.TooFar)
998 local diff = math.floor((nltime.getLocalTime() - arkNpcShop.lastMultipleItemsUpdate ) / 10)
999 if diff >= 100 then
1000 arkNpcShop.lastMultipleItemsUpdate = nltime.getLocalTime()
1001 if arkNpcShop.player_money_per_items ~= nil then
1002 for item, price in pairs(arkNpcShop.player_money_per_items) do
1003 if arkNpcShop.lastMultipleItemsIndex[item] == nil then
1004 arkNpcShop.lastMultipleItemsIndex[item] = {}
1006 for i = 1,5 do
1007 local w = getUI("ui:interface:ark_npc_shop"):find("ark_npc_shop_item_"..item.."_price"..tostring(i))
1008 if w ~= nil and arkNpcShop.all_items[item] ~= nil and arkNpcShop.all_items[item][i] ~= nil then
1009 if price[i] ~= nil and price[i] < 1 then
1010 if arkNpcShop.lastMultipleItemsIndex[item][i] == nil then
1011 arkNpcShop.lastMultipleItemsIndex[item][i] = 0
1014 arkNpcShop.lastMultipleItemsIndex[item][i] = arkNpcShop.lastMultipleItemsIndex[item][i] + 1
1015 if arkNpcShop.lastMultipleItemsIndex[item][i] > tablelength(arkNpcShop.all_items[item][i]) then
1016 arkNpcShop.lastMultipleItemsIndex[item][i] = 1
1019 local sheet = arkNpcShop.all_items[item][i][arkNpcShop.lastMultipleItemsIndex[item][i]]
1020 if sheet ~= ".sitem" then
1021 setDbProp("UI:TEMP:ARK:ITEM:"..item.."_"..tostring(i)..":SHEET", getSheetId(sheet))
1031 function arkNpcShop:checkitems(db, items, quality, id)
1032 total = 0
1033 for i = 0, 499, 1 do
1034 local sheet = getDbProp("SERVER:INVENTORY:BAG:"..tostring(i)..":SHEET")
1035 if sheet ~= 0 then
1036 local name = string.lower(getSheetName(sheet))
1037 for _, item in pairs(items) do
1038 if name == item then
1039 local qual = getDbProp("SERVER:INVENTORY:BAG:"..tostring(i)..":QUALITY")
1040 local quant = getDbProp("SERVER:INVENTORY:BAG:"..tostring(i)..":QUANTITY")
1042 if qual >= quality then
1043 total = total + quant
1044 setDbProp(db..":SHEET", sheet)
1045 setDbProp(db..":QUALITY", qual)
1051 return total
1054 function arkNpcShop:getHtmlIcon(id, item)
1055 if string.sub(item[2], 1, 1) == "#" then
1056 addDbProp("UI:TEMP:ARK:SELECTITEM:RESALE_FLAG", 0)
1058 if string.sub(item[3], 1, 1) == "!" then
1059 webig:addSheet("UI:TEMP:ARK:SELECTITEM", getSheetId(item[7]), item[4], tonumber(string.sub(item[3], 2)))
1060 else
1061 webig:addSheet("UI:TEMP:ARK:SELECTITEM", getSheetId(item[7]), item[4], 1)
1063 addDbProp("UI:TEMP:ARK:SELECTITEM:USER_COLOR", item[9])
1064 return [[<div class="ryzom-ui-grouptemplate" style="template:arkshop_inv_item;id:inv_special_bag_item;usesheet:true;isvirtual:false;sheetdb:UI:TEMP:ARK:SELECTITEM;w:40;params_r:arkNpcShop:OpenSheetInfosWindow(]]..id..[[);"></div>]]
1065 else
1066 return [[<div class="ryzom-ui-grouptemplate" style="template:arkshop_inv_item;id:inv_special_bag_item;usesheet:false;isvirtual:true;w:44;quantity: ;quality:]]..item[4]..[[;tooltip:u:]]..item[6]..[[;gc2:true;gc1:true;img1:]]..item[2]..[[;col_over:0 0 0 0"></div>]]
1071 function arkNpcShop:OpenSheetInfosWindow(id)
1072 local w = getUI("ui:interface:ark_npc_shop")
1073 local x = w:find("buy"):find("ark_npc_shop_item_"..tostring(id))
1074 runAH(x:find("sheet"), "open_help_auto", "")
1078 function arkNpcShop:HideHelpWindow(id)
1079 -- Check what help window are active
1080 local help_active={}
1081 for i = 0,7 do
1082 help_active[i] = getUI("ui:interface:sheet_help"..i).active
1085 arkNpcShop:OpenSheetInfosWindow(id)
1087 -- Apply previous stats of help window
1088 for i = 0,7 do
1089 getUI("ui:interface:sheet_help"..i).active = help_active[i]
1093 function arkNpcShop:OpenItemWindow(id, buy)
1094 local item = arkNpcShop.items[id]
1095 if arkNpcShop.all_items[id] ~= nil and arkNpcShop.all_items[id].need_real_item ~= nil then
1096 arkNpcShop.max_quantity = 1
1097 else
1098 if string.sub(item[3], 1, 1) == "!" then
1099 arkNpcShop.max_quantity = 1
1100 else
1101 arkNpcShop.max_quantity = item[3]
1105 arkNpcShop:HideHelpWindow(id)
1107 local non_buy_window_w = 400
1109 local ui_item_preview = getUI("ui:interface:ark_shop_buy_item:content:header_opened:item_preview")
1110 if ui_item_preview then
1111 ui_item_preview.active = false
1114 local ui_item_show_desc = getUI("ui:interface:ark_shop_buy_item:content:header_opened:desc")
1115 if ui_item_show_desc then
1116 ui_item_show_desc.active = item[2] == "#sheet"
1119 if string.sub(item[2], 1, 1) == "#" then
1120 local item_type = getSheetFamily(item[7])
1121 local display_preview = item_type == "SHIELD" or item_type == "ARMOR" or item_type == "MELEE_WEAPON" or item_type == "RANGE_WEAPON"
1122 if ui_item_preview then
1123 ui_item_preview.active = display_preview
1126 if display_preview then
1127 non_buy_window_w = 495
1128 else
1129 -- Items who are not named items must display help window when no buy
1130 if buy == nil and item[2] == "#sheet" then
1131 arkNpcShop:OpenSheetInfosWindow(id)
1132 return
1137 if buy == true then
1138 arkNpcShop.price = item[1]
1139 setDbProp("UI:TEMP:ARK_MONEY_PRICE", arkNpcShop.price)
1140 setDbProp("UI:TEMP:ARK_MONEY_TOTAL", arkNpcShop.price)
1142 if arkNpcShop.price > arkNpcShop.player_money then
1143 arkNpcShop.player_can_buy = false
1144 else
1145 arkNpcShop.player_can_buy = true
1149 local framewin = getUI("ui:interface:ark_shop_buy_item")
1150 if framewin == nil then
1151 createRootGroupInstance("webig_bot_chat_buy_item", "ark_shop_buy_item", {id="content", infosclick="arkNpcShop:OpenSheetInfosWindow("..id..")", onclick="arkNpcShop:Buy("..id..")"})
1152 framewin = getUI("ui:interface:ark_shop_buy_item")
1153 framewin.x = math.ceil(((getUI("ui:interface").w - framewin.w))/2)
1154 framewin.y = math.ceil(((getUI("ui:interface").h + framewin.h))/2)
1157 runAH(nil, "proc", "ark_shop_animate_preview_body")
1159 if buy == true then
1160 local eb = framewin:find("edit"):find("eb")
1161 eb.input_string = 1
1162 eb:setFocusOnText()
1163 eb:setSelectionAll()
1164 framewin:find("item_total_price"):find("icone").texture = arkNpcShop.MoneyIcon
1165 framewin:find("item_price"):find("icone").texture = arkNpcShop.MoneyIcon
1166 framewin:find("item_total_price"):find("tt").tooltip = arkNpcShop.Money
1167 framewin:find("item_price"):find("tt").tooltip = arkNpcShop.Money
1168 arkNpcShop.window_params = {-70, 305, 408}
1169 else
1170 arkNpcShop.window_params = {-20, 380, non_buy_window_w}
1173 framewin:find("top").active = buy == true -- active onlye if buy
1174 framewin:find("scroll_text").y=arkNpcShop.window_params[1]
1175 framewin:find("scroll_text").h=arkNpcShop.window_params[2]
1176 framewin.w=arkNpcShop.window_params[3]
1177 framewin.uc_title = getUCtf8(item[6])
1179 if buy == true then
1180 local html = ""
1181 html = arkNpcShop:getHtmlIcon(id, item)
1182 framewin:find("buy_sell_slot"):renderHtml(html)
1183 if string.sub(item[5], 1 , 8) == "https://" then
1184 framewin:find("ok").active=false
1185 framewin:find("infos"):renderHtml(arkNpcShop.PleaseWait)
1186 framewin:find("infos"):browse(item[5])
1187 else
1188 framewin:find("ok").active=true
1189 framewin:find("infos"):renderHtml("<table width='380px'><tr><td>"..item[5].."</td></tr></table>")
1191 arkNpcShop:CheckMoney()
1192 -- framewin:setModalParentList("ui:interface:ark_npc_shop")
1193 else
1194 html = arkNpcShop:getHtmlIcon(id, item)
1195 framewin:find("infos"):renderHtml([[
1196 <table width="100%">
1197 <tr>
1198 <td width="40px" valign="top">]]..html..[[</td>
1199 <td >]]..item[5]..[[</td>
1200 </tr>
1201 </table>
1205 framewin:find("desc").params_l = "arkNpcShop:OpenSheetInfosWindow("..id..")"
1206 framewin:find("ok").params_l = "arkNpcShop:Buy("..id..")"
1207 framewin.opened=true
1208 framewin.active=true
1212 function arkNpcShop:CheckMoney()
1213 local win = getUI("ui:interface:ark_shop_buy_item")
1214 local value = tonumber(win:find("edit"):find("eb").input_string)
1215 if value == nil or value == 0 then
1216 value = 1
1218 if arkNpcShop.max_quantity ~= 0 and value > arkNpcShop.max_quantity then
1219 win:find("edit"):find("eb").input_string = arkNpcShop.max_quantity
1220 value = arkNpcShop.max_quantity
1223 local total = arkNpcShop.price*value
1225 if total > arkNpcShop.player_money then
1226 win:find("ok").hardtext="uiNotEnoughMoney"
1227 arkNpcShop.player_can_buy = false
1228 else
1229 win:find("ok").hardtext = arkNpcShop.ActionName
1230 arkNpcShop.player_can_buy = true
1232 setDbProp("UI:TEMP:ARK_MONEY_TOTAL", total)
1235 function arkNpcShop:Close()
1236 local framewin = getUI("ui:interface:ark_npc_shop")
1237 if framewin ~= nil then
1238 framewin.active=false
1241 framewin = getUI("ui:interface:ark_shop_buy_item")
1242 if framewin ~= nil then
1243 framewin.active=false
1248 function arkNpcShop:timer(id, len)
1249 local diff = math.floor((nltime.getLocalTime() - savedTime) / 50)
1250 getUI("ui:interface:current_action").active=true
1251 setDbProp("UI:PHRASE:ACT_BAR_LEN", (100/len)*diff)
1252 if diff >= len then
1253 getUI("ui:interface:current_action").active=false
1254 setOnDraw(getUI("ui:interface:current_action"), "")
1255 local quantity = getUI("ui:interface:ark_shop_buy_item"):find("edit"):find("eb").input_string
1256 getUI("ui:interface:web_transactions"):find("html"):browse(arkNpcShop.ValidateUrl..quantity.."&item_id="..id.."&item_selection="..arkNpcShop.selectedItems[id])
1261 function arkNpcShop:Buy(id)
1262 local item = arkNpcShop.items[id]
1263 local win = getUI("ui:interface:ark_shop_buy_item")
1264 local quantity = win:find("edit"):find("eb").input_string
1265 if arkNpcShop.player_can_buy then
1266 local message = ucstring()
1267 message:fromUtf8("@{F5FF}"..getUI("ui:interface:target").title..": @{FF0F}I\'m checking to see if you\'re trying to rip him off... ")
1268 -- displaySystemInfo(message, "BC")
1270 if arkNpcShop.AtysPoint then
1271 if item[8] == 0 then
1272 local message = ucstring()
1273 message:fromUtf8(arkNpcShop.AtysPointsBuyMessage)
1274 displaySystemInfo(message, "BC")
1275 savedTime = nltime.getLocalTime()
1276 getUI("ui:interface:current_action").active=true
1277 local len = item[1]
1278 if len > 200 then
1279 len = 200
1281 setOnDraw(getUI("ui:interface:current_action"), "arkNpcShop:timer("..id..", "..tostring(len)..")")
1282 else
1283 getUI("ui:interface:web_transactions"):find("html"):browse(arkNpcShop.ValidateUrl..quantity.."&item_id="..id.."&item_selection="..arkNpcShop.selectedItems[id])
1285 else
1286 getUI("ui:interface:web_transactions"):find("html"):browse(arkNpcShop.ValidateUrl..quantity.."&item_id="..id.."&item_selection="..arkNpcShop.selectedItems[id])
1289 arkNpcShop:Close()