Fix checkRpItemsPosition
[ryzomcore.git] / ryzom / client / data / gamedev / interfaces_v3 / interaction.lua
blob558904e8190b484c48b6e03ef816f89c6ca33fc1
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] = 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 game:checkRpItemsPosition()
304 local html = getUI("ui:interface:rpitems_actions"):find("html")
305 for k, v in pairs(game.wantedRpTargets) do
306 local a = html:find("action"..v)
307 if a then
308 if a:find("but").onclick_l == "lua" and (string.find(k, left..":"..target..":"..mode) or string.find(k, left..":"..target..":")) then
309 a:find("img").texture = "grey_0.tga"
310 a:find("but").onclick_l = "lua"
311 a:find("but").alpha = 255
312 a:find("text").alpha = 255
313 else
314 a:find("img").texture = "r2ed_toolbar_lock_small.tga"
315 a:find("but").onclick_l = ""
316 a:find("but").alpha = 150
317 a:find("text").alpha = 100
324 function game:checkRpItemsPosition()
325 local x,y,z = getPlayerPos()
326 local sx = tostring(math.floor(x/10))
327 local sy = tostring(math.floor(y/10))
328 local html = getUI("ui:interface:rpitems_actions"):find("html")
329 for k, v in pairs(game.wantedRpPositions) do
330 local a = html:find("action"..v)
331 if a then
332 if string.find(sx..":"..sy, k) then
333 a:find("but").onclick_l = "lua"
334 a:find("img").texture = "grey_0.tga"
335 a:find("text").alpha = 255
336 else
337 a:find("but").onclick_l = "proc"
338 a:find("img").texture = "r2ed_toolbar_lock_small.tga"
339 a:find("text").alpha = 200
345 ------------------------------------------------------------------------------------------------------------
346 -- This function is called when a new target is selected, it should update the 'consider' widget
347 -- Level of the creature
348 -- Is its level known (not too high ...)
349 -- Boss/Mini-bosses/Names colored ring
351 function game:updateTargetConsiderUI()
352 game:updateRpItems(game.usedRpLeftItem, game.usedRpRightItem)
353 local targetWindow = getUI("ui:interface:target")
355 local wgTargetSlotForce = targetWindow:find("slot_force")
356 local wgTargetLevel = targetWindow:find("target_level")
357 local wgImpossible = targetWindow:find("impossible")
358 local wgSlotRing = targetWindow:find("slot_ring")
359 local wgToolTip = targetWindow:find("target_tooltip")
360 local wgPvPTag = targetWindow:find("pvp_tags")
361 local wgHeader = targetWindow:find("header_opened")
362 local wgLock = targetWindow:find("lock")
364 wgTargetSlotForce.active = true
365 wgTargetSlotForce.texture = "consider_bg.tga"
366 wgImpossible.active = true
367 wgTargetSlotForce.h = 16
369 -- no selection ?
370 if twGetTargetLevel() == -1 then
371 wgLock.active = false
372 wgTargetSlotForce.active = false
373 wgTargetLevel.active = false
374 wgImpossible.active = false
375 wgSlotRing.active = false
376 if (isTargetUser() and twIsPlayerInPVPMode()) then
377 wgToolTip.tooltip = ""
378 wgPvPTag.active = true
379 wgHeader.h = 56;
380 else
381 wgPvPTag.active = false
382 wgHeader.h = 34;
383 wgToolTip.tooltip = i18n.get("uittConsiderTargetNoSelection")
385 return
388 local pvpMode = false
389 wgPvPTag.active = false
390 wgHeader.h = 34;
393 -- /luaScript getUI("ui:interface:target:header_opened:lock").active=true
395 -- if the selection is a player, then both the local & targeted player must be in PVP mode for the level to be displayed
396 if (twIsTargetPlayer()) then
397 -- don't display anything ...
398 wgLock.active = false
399 wgTargetSlotForce.active = false
400 wgTargetLevel.active = false
401 wgImpossible.active = false
402 wgSlotRing.active = false
403 wgToolTip.tooltip = ""
404 if twIsTargetInPVPMode() then
405 wgPvPTag.active = true
406 wgHeader.h = 56;
408 return
409 else
410 wgLock.active = false
411 local level = getDbProp(getDefine("target_player_level"))
413 if level == 2 then -- Locked by team of player
414 wgLock.active = true
415 wgLock.color = "50 250 250 255"
416 else
417 if level == 1 then -- Locked by another team
418 wgLock.active = true
419 wgLock.color = "250 50 50 255"
424 -- depending on the number of people in the group, set the max diff for visibility between player level
425 -- & creature level (x 10 per member)
426 local maxDiffLevel = 10
427 if not pvpMode then
428 -- exception there : when "pvping", don't relate the levelof the target to the level of the group, but to thelocal
429 -- player only
430 for gm = 0, 7 do
431 if getDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT") ~= 0 then
432 maxDiffLevel = maxDiffLevel + 10
437 --debugInfo("Max diff level= " .. tostring(maxDiffLevel))
439 local impossible = (twGetTargetLevel() - twGetPlayerLevel() > maxDiffLevel)
441 wgSlotRing.active = false
443 if impossible then
444 -- targeted object is too hard too beat, display a skull
445 wgTargetLevel.active = false
446 wgImpossible.y = -5
447 wgImpossible.color = "255 50 50 255"
448 else
449 -- player can see the level of the targeted creature
450 wgTargetLevel.active = true
451 wgImpossible.y = 6
452 wgTargetLevel.hardtext = tostring(twGetTargetLevel())
453 wgImpossible.color = "255 255 255 255"
454 wgTargetLevel.color = getDefine("region_force_" .. tostring(levelToForceRegion(twGetTargetLevel())))
457 -- based on the 'level force', set a colored ring around the level
458 local levelForce = twGetTargetLevelForce()
459 wgTargetSlotForce.color = getDefine("region_force_" .. tostring(levelToForceRegion(twGetTargetLevel())))
461 wgImpossible.texture = getDefine("force_level_" .. tostring(levelForce))
462 wgImpossible.active = true
463 if levelForce < 6 then
464 wgToolTip.tooltip = i18n.get("uittConsiderTargetLevel")
465 elseif levelForce == 6 then
466 -- Named creature
467 wgImpossible.color = "117 132 126 255"
468 wgSlotRing.color = "117 132 126 255"
469 wgTargetSlotForce.color = "117 132 126 255"
470 wgSlotRing.texture = "consider_ring.tga"
471 wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss")
472 elseif levelForce == 7 then
473 -- Boss
474 wgImpossible.color = "156 98 65 255"
475 wgSlotRing.color = "156 98 65 255"
476 wgTargetSlotForce.color = "156 98 65 255"
477 wgSlotRing.texture = "consider_ring.tga"
478 wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss")
479 elseif levelForce == 8 then
480 -- Mini-Boss
481 wgImpossible.color = "213 212 9 255"
482 wgSlotRing.texture = "consider_ring.tga"
483 wgSlotRing.color = "213 212 9 255"
484 if isTargetNPC() then
485 wgTargetSlotForce.color = "255 255 255 255"
486 wgToolTip.tooltip = i18n.get("uittConsiderBossNpc")
487 else
488 wgTargetSlotForce.color = "213 212 9 255"
489 wgToolTip.tooltip = i18n.get("uittConsiderBoss")
491 elseif levelForce == 12 then
492 wgImpossible.color = "255 255 255 255"
493 wgTargetSlotForce.texture = "episode_step.tga"
494 wgTargetSlotForce.color = "255 255 255 255"
495 wgToolTip.tooltip = i18n.get("uittConsiderUnknownLevel")
496 wgTargetLevel.active = false
497 wgImpossible.y = -5
498 elseif levelForce > 12 then
499 wgImpossible.color = "255 255 255 255"
500 wgTargetSlotForce.texture = "episode_step_ok.tga"
501 wgTargetSlotForce.color = "255 255 255 255"
502 wgToolTip.tooltip = i18n.get("uittConsiderSpecialLevel")
503 wgTargetLevel.active = false
504 wgImpossible.y = -5
507 if impossible then
508 wgToolTip.tooltip = concatUCString(wgToolTip.tooltip, ucstring("\n"), i18n.get("uittConsiderUnknownLevel"))
512 ----------------------
513 -- MISC local tests function
514 -- no selection
515 function twTest0()
516 twTargetLevel = -1
517 twTargetPlayer = false
518 game:updateTargetConsiderUI()
520 -- selection, not impossible
521 function twTest1()
522 twTargetPlayer = false
523 twPlayerLevel = 10
524 twTargetLevel = 15
525 twTargetForceRegion = levelToForceRegion(twTargetLevel)
526 twTargetLevelForce = levelToLevelForce(twTargetLevel)
527 game:updateTargetConsiderUI()
529 -- selection, not impossible (limit)
530 function twTest2()
531 twTargetPlayer = false
532 twPlayerLevel = 10
533 twTargetLevel = 20
534 twTargetForceRegion = levelToForceRegion(twTargetLevel)
535 twTargetLevelForce = levelToLevelForce(twTargetLevel)
536 game:updateTargetConsiderUI()
538 -- selection, impossible
539 function twTest3()
540 twTargetPlayer = false
541 twPlayerLevel = 10
542 twTargetLevel = 21
543 twTargetForceRegion = levelToForceRegion(twTargetLevel)
544 twTargetLevelForce = levelToLevelForce(twTargetLevel)
545 game:updateTargetConsiderUI()
547 ------ NAMED
548 ------
549 -- selection, not impossible, named
550 function twTest4()
551 twTargetPlayer = false
552 twPlayerLevel = 10
553 twTargetLevel = 15
554 twTargetForceRegion = levelToForceRegion(twTargetLevel)
555 twTargetLevelForce = 6
556 game:updateTargetConsiderUI()
558 -- selection, not impossible (limit), named
559 function twTest5()
560 twTargetPlayer = false
561 twPlayerLevel = 10
562 twTargetLevel = 20
563 twTargetForceRegion = levelToForceRegion(twTargetLevel)
564 twTargetLevelForce = 6
565 game:updateTargetConsiderUI()
567 -- selection, impossible, named
568 function twTest6()
569 twTargetPlayer = false
570 twPlayerLevel = 10
571 twTargetLevel = 21
572 twTargetForceRegion = levelToForceRegion(twTargetLevel)
573 twTargetLevelForce = 6
574 game:updateTargetConsiderUI()
576 ------ BOSS
577 ------
578 -- selection, not impossible, boss
579 function twTest7()
580 twTargetPlayer = false
581 twPlayerLevel = 10
582 twTargetLevel = 15
583 twTargetForceRegion = levelToForceRegion(twTargetLevel)
584 twTargetLevelForce = 7
585 game:updateTargetConsiderUI()
587 -- selection, not impossible (limit), boss
588 function twTest8()
589 twTargetPlayer = false
590 twPlayerLevel = 10
591 twTargetLevel = 20
592 twTargetForceRegion = levelToForceRegion(twTargetLevel)
593 twTargetLevelForce = 7
594 game:updateTargetConsiderUI()
596 -- selection, impossible, boss
597 function twTest9()
598 twTargetPlayer = false
599 twPlayerLevel = 10
600 twTargetLevel = 21
601 twTargetForceRegion = levelToForceRegion(twTargetLevel)
602 twTargetLevelForce = 7
603 game:updateTargetConsiderUI()
605 ------ MINI-BOSS
606 ------
607 -- selection, not impossible, boss
608 function twTest10()
609 twTargetPlayer = false
610 twPlayerLevel = 10
611 twTargetLevel = 15
612 twTargetForceRegion = levelToForceRegion(twTargetLevel)
613 twTargetLevelForce = 8
614 game:updateTargetConsiderUI()
616 -- selection, not impossible (limit), boss
617 function twTest11()
618 twTargetPlayer = false
619 twPlayerLevel = 10
620 twTargetLevel = 20
621 twTargetForceRegion = levelToForceRegion(twTargetLevel)
622 twTargetLevelForce = 8
623 game:updateTargetConsiderUI()
625 -- selection, impossible, boss
626 function twTest12()
627 twTargetPlayer = false
628 twPlayerLevel = 10
629 twTargetLevel = 21
630 twTargetForceRegion = levelToForceRegion(twTargetLevel)
631 twTargetLevelForce = 8
632 game:updateTargetConsiderUI()
635 ------ PLAYER SELECTION
636 ------ 2 players, no pvp
637 function twTest13()
638 twTargetPlayer = true
639 twPlayerInPVPMode = false
640 twTargetInPVPMode = false
642 twPlayerLevel = 10
643 twTargetLevel = 15
644 twTargetForceRegion = levelToForceRegion(twTargetLevel)
645 twTargetLevelForce = levelToLevelForce(twTargetLevel)
646 game:updateTargetConsiderUI()
649 function twTest14()
650 twTargetPlayer = true
651 twPlayerInPVPMode = true
652 twTargetInPVPMode = true
654 twPlayerLevel = 10
655 twTargetLevel = 15
656 twTargetForceRegion = levelToForceRegion(twTargetLevel)
657 twTargetLevelForce = levelToLevelForce(twTargetLevel)
658 game:updateTargetConsiderUI()
662 ------ 2 players, pvp
664 -- groups
665 function twGroup(groupSize)
666 for gm = 0, 7 do
667 if gm < groupSize then
668 setDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT", 1)
669 else
670 setDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT", 0)
675 ------------------------------------------------------------------------------------------------------------
677 function game:closeWebIGBrowserHeader()
678 local ui = getUI('ui:interface:webig')
680 -- save size
681 ui_webig_browser_h = ui.h
682 ui_webig_browser_w = ui.w
684 -- reduce window size
685 ui.pop_min_h = 32
686 ui.h = 0
687 ui.w = 150
690 ------------------------------------------------------------------------------------------------------------
692 function game:openWebIGBrowserHeader()
693 local ui = getUI('ui:interface:webig');
694 ui.pop_min_h = 96;
696 -- set size from saved values
697 if (ui_webig_browser_h ~= nil) then
698 ui.h = ui_webig_browser_h;
701 if (ui_webig_browser_w ~= nil) then
702 ui.w = ui_webig_browser_w;
706 ------------------------------------------------------------------------------------------------------------
708 function game:closeWindowHeader()
709 local ui = getUICaller().parent;
710 local id = ui.id;
712 if game.ui_props[id] == nil then
713 game.ui_props[id] = {}
716 -- save size
717 game.ui_props[id].w = ui.w
718 game.ui_props[id].h = ui.h
719 game.ui_props[id].pop_min_h = ui.pop_min_h
721 -- reduce window size
722 ui.pop_min_h = 32
723 ui.h = 0;
724 ui.w = 150
727 ------------------------------------------------------------------------------------------------------------
729 function game:openWindowHeader()
730 local ui = getUICaller().parent;
731 local id = ui.id;
733 if ui ~= nil and game.ui_props[id] ~= nil then
734 -- set size from saved values
735 if game.ui_props[id].pop_min_h ~= nil then
736 ui.pop_min_h = game.ui_props[id].pop_min_h
739 if game.ui_props[id].h ~= nil then
740 ui.h = game.ui_props[id].h
743 if ui_webig_browser_w ~= nil then
744 ui.w = game.ui_props[id].w;
750 ------------------------------------------------------------------------------------------------------------
751 function game:openGuildIsland(url_island)
752 local nbMember = getNbGuildMembers();
753 local params = "";
754 for i = 0,(nbMember-1) do
755 local memberGrade = getGuildMemberGrade(i);
756 if (memberGrade == "Leader") or (memberGrade == "HighOfficer") then
757 params = params .. string.lower(getGuildMemberName(i)) .. "=" .. memberGrade.."&";
760 local x,y,z = getPlayerPos()
761 params = params .. "&posx=" .. tostring(x) .. "&posy=" .. tostring(y) .. "&posz=" .. tostring(z)
763 getUI("ui:interface:guild:content:tab_island:props:html"):browse(url_island.."params="..params);
764 runAH(nil, "browse_home", "name=ui:interface:guild:content:tab_island:inv:html")
767 function game:openGuildSpecialBag()
768 runAH(nil, "browse_home", "name=ui:interface:guild:content:tab_special_bag:inv:html")
773 ------------------------------------------------------------------------------------------------------------
774 local SavedUrl = "";
775 function game:chatUrl(url)
776 SavedUrl = url
777 runAH(nil, "active_menu", "menu=ui:interface:chat_uri_action_menu")
779 function game:chatUrlCopy()
780 runAH(nil, "copy_to_clipboard", SavedUrl)
782 function game:chatUrlBrowse()
783 runAH(nil, "browse", "name=ui:interface:webig:content:html|url=" .. SavedUrl)
786 ------------------------------------------------------------------------------------------------------------
788 if game.sDynChat == nil then game.sDynChat = {} end
790 -- called from onInGameDbInitialized
791 function game:openChannels()
792 if getDbProp("UI:SAVE:CHAT:AUTO_CHANNEL") > 0 then
793 local uc = readUserChannels()
794 if uc then
795 local index = 0
796 for _ in pairs(uc) do
797 index = index + 1
799 local channels = {}
800 for i = 0, index-1 do
801 local node = uc[tostring(i)]
802 channels[tonumber(node.id)] = {
803 rgba = node.rgba,
804 name = node.name,
805 passwd = node.passwd
808 local t = {}
810 for k in pairs(channels) do table.insert(t, k) end
811 table.sort(t)
812 -- sorted
813 for _, id in ipairs(t) do
814 local found = false
815 for i = 0, getMaxDynChan()-1 do
816 if getDbProp("UI:SAVE:ISENABLED:DYNAMIC_CHAT"..i) == 1 then
817 local cname = getDbProp("SERVER:DYN_CHAT:CHANNEL"..i..":NAME")
818 if isDynStringAvailable(cname) then
819 local chan = getDynString(cname):toUtf8()
820 -- already opened?
821 if channels[id].name == chan then found = true end
825 if not found then
826 self:connectUserChannel(channels[id].name.." "..channels[id].passwd)
827 -- now restore colors
828 if channels[id].rgba ~= '' then
829 local i = 0
830 local c = {}
831 local rgba = {[0]="R", [1]="G", [2]="B", [3]="A"}
832 for color in string.gmatch(channels[id].rgba, "%d+") do
833 c[rgba[i]] = tonumber(color)
834 i = i + 1
836 setDbRGBA("UI:SAVE:CHAT:COLORS:DYN:"..id, CRGBA(c.R, c.G, c.B, c.A))
844 -- store channel detail before it open
845 function game:connectUserChannel(args)
846 local argv = {}
847 for w in string.gmatch(args, "%S+") do
848 table.insert(argv, w)
850 if #argv > 0 then
851 local params = argv[1]
852 if #argv == 2 then
853 for _, ch in pairs(self.sDynChat) do
854 if ch[argv[1]] then ch[argv[1]] = nil end
856 if argv[2] ~= '*' and argv[2] ~= '***' then
857 table.insert(self.sDynChat, {[argv[1]]=argv[2]})
859 params = params.." "..argv[2]
861 runAH(nil, "talk", "mode=0|text=/a connectUserChannel "..params)
865 -- save user created channels
866 function game:saveChannel(verbose)
867 if verbose == nil then
868 verbose = false
870 local channels = {}
871 for i = 0, getMaxDynChan()-1 do
872 if getDbProp("UI:SAVE:ISENABLED:DYNAMIC_CHAT"..i) == 1 then
873 local cname = getDbProp("SERVER:DYN_CHAT:CHANNEL"..i..":NAME")
874 if isDynStringAvailable(cname) then
875 local chan = getDynString(cname):toUtf8()
876 local found = false
877 -- avoid empty cvar case
878 if getClientCfgVar("ChannelIgnoreFilter") then
879 for _, k in pairs(getClientCfgVar("ChannelIgnoreFilter")) do
880 if k == chan then found = true end
882 if not found then
883 -- store current colors
884 local cRGBA = getDbRGBA("UI:SAVE:CHAT:COLORS:DYN:"..i)
885 local password = ''
886 -- include private channels
887 for _, k in pairs(game.sDynChat) do
888 if k[chan] then password = k[chan] end
890 channels[tostring(i)] = {
891 rgba = cRGBA,
892 name = chan,
893 passwd = password
900 saveUserChannels(channels, verbose)
903 ------------------------------------------------------------------------------------------------------------
905 function game:chatWelcomeMsg(input)
906 local msg
907 local name
908 if not input then
909 input = getUICaller().params_r
910 if input then
911 input = input:match("ED:([^_]+)"):lower()
914 local chat = input
915 local temp = "UI:TEMP:ONCHAT:"
916 if game.InGameDbInitialized then
917 -- is input chat a dynamic channel?
918 if type(input) == "number" then
919 local id = getDbProp("SERVER:DYN_CHAT:CHANNEL"..input..":NAME")
920 if isDynStringAvailable(id) then
921 name = getDynString(id):toUtf8()
922 -- variable for this session
923 if getDbProp(temp..name) == 0 then
924 -- faction, nation and organization
925 for k, v in pairs({
926 kami = i18n.get("uiFameAllegiance2"),
927 karavan = i18n.get("uiFameAllegiance3"),
928 fyros = i18n.get("uiFameAllegiance4"),
929 matis = i18n.get("uiFameAllegiance5"),
930 tryker = i18n.get("uiFameAllegiance6"),
931 zorai = i18n.get("uiFameAllegiance7"),
932 marauder = i18n.get("uiFameMarauders"),
933 ranger = i18n.get("uiOrganization_7")
934 }) do
935 if name == v:toUtf8() then
936 msg = i18n.get("uiWelcome_"..k)
937 name = v:toUtf8()
941 -- chat_group_filter sParam
942 chat = "dyn_chat"..input
944 else
945 -- around, region and universe
946 if getDbProp(temp..input) == 0 then
947 msg = i18n.get("uiWelcome_"..input)
948 name = input
951 if msg then
952 displayChatMessage(tostring(msg), input)
953 -- save for this session
954 addDbProp(temp..name, 1)
957 runAH(getUICaller(), "chat_group_filter", chat)
961 function game:TalkWithNpc(bullying)
962 setTargetAsInterlocutor()
964 if bullying == 1 then
965 runCommand("a", "openTargetUrl", "1")
966 else
967 runCommand("a", "openTargetUrl")
972 -----------------------------------
973 --- ARK NPC SHOP
975 function tablelength(T)
976 if T == nil then
977 return 0
979 local count = 0
980 for _ in pairs(T) do count = count + 1 end
981 return count
984 function arkNpcShop:showBuy()
985 getUI("ui:interface:ark_shop_buy_item"):find("ok").active=true
988 function arkNpcShop:openSection(url)
989 framewin = getUI("ui:interface:ark_npc_shop"):find("buy"):renderHtml(arkNpcShop.PleaseWait)
990 getUI("ui:interface:web_transactions"):find("html"):browse(url)
993 function arkNpcShop:updateWindow(px, py)
994 local x, y, z = getPlayerPos()
995 local stop = false
996 if (px-x)*(px-x)+(py-y)*(py-y) > 25 then
997 local w = getUI("ui:interface:ark_npc_shop")
998 w.active = false
999 setOnDraw(w, "")
1000 getUI("ui:interface:ark_shop_buy_item").active = false
1001 arkNpcShop.player_can_buy = false
1002 broadcast(arkNpcShop.TooFar)
1005 local diff = math.floor((nltime.getLocalTime() - arkNpcShop.lastMultipleItemsUpdate ) / 10)
1006 if diff >= 100 then
1007 arkNpcShop.lastMultipleItemsUpdate = nltime.getLocalTime()
1008 if arkNpcShop.player_money_per_items ~= nil then
1009 for item, price in pairs(arkNpcShop.player_money_per_items) do
1010 if arkNpcShop.lastMultipleItemsIndex[item] == nil then
1011 arkNpcShop.lastMultipleItemsIndex[item] = {}
1013 for i = 1,5 do
1014 local w = getUI("ui:interface:ark_npc_shop"):find("ark_npc_shop_item_"..item.."_price"..tostring(i))
1015 if w ~= nil and arkNpcShop.all_items[item] ~= nil and arkNpcShop.all_items[item][i] ~= nil then
1016 if price[i] ~= nil and price[i] < 1 then
1017 if arkNpcShop.lastMultipleItemsIndex[item][i] == nil then
1018 arkNpcShop.lastMultipleItemsIndex[item][i] = 0
1021 arkNpcShop.lastMultipleItemsIndex[item][i] = arkNpcShop.lastMultipleItemsIndex[item][i] + 1
1022 if arkNpcShop.lastMultipleItemsIndex[item][i] > tablelength(arkNpcShop.all_items[item][i]) then
1023 arkNpcShop.lastMultipleItemsIndex[item][i] = 1
1026 local sheet = arkNpcShop.all_items[item][i][arkNpcShop.lastMultipleItemsIndex[item][i]]
1027 if sheet ~= ".sitem" then
1028 setDbProp("UI:TEMP:ARK:ITEM:"..item.."_"..tostring(i)..":SHEET", getSheetId(sheet))
1038 function arkNpcShop:checkitems(db, items, quality, id)
1039 total = 0
1040 for i = 0, 499, 1 do
1041 local sheet = getDbProp("SERVER:INVENTORY:BAG:"..tostring(i)..":SHEET")
1042 if sheet ~= 0 then
1043 local name = string.lower(getSheetName(sheet))
1044 for _, item in pairs(items) do
1045 if name == item then
1046 local qual = getDbProp("SERVER:INVENTORY:BAG:"..tostring(i)..":QUALITY")
1047 local quant = getDbProp("SERVER:INVENTORY:BAG:"..tostring(i)..":QUANTITY")
1049 if qual >= quality then
1050 total = total + quant
1051 setDbProp(db..":SHEET", sheet)
1052 setDbProp(db..":QUALITY", qual)
1058 return total
1061 function arkNpcShop:getHtmlIcon(id, item)
1062 if string.sub(item[2], 1, 1) == "#" then
1063 addDbProp("UI:TEMP:ARK:SELECTITEM:RESALE_FLAG", 0)
1065 if string.sub(item[3], 1, 1) == "!" then
1066 webig:addSheet("UI:TEMP:ARK:SELECTITEM", getSheetId(item[7]), item[4], tonumber(string.sub(item[3], 2)))
1067 else
1068 webig:addSheet("UI:TEMP:ARK:SELECTITEM", getSheetId(item[7]), item[4], 1)
1070 addDbProp("UI:TEMP:ARK:SELECTITEM:USER_COLOR", item[9])
1071 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>]]
1072 else
1073 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>]]
1078 function arkNpcShop:OpenSheetInfosWindow(id)
1079 local w = getUI("ui:interface:ark_npc_shop")
1080 local x = w:find("buy"):find("ark_npc_shop_item_"..tostring(id))
1081 runAH(x:find("sheet"), "open_help_auto", "")
1085 function arkNpcShop:HideHelpWindow(id)
1086 -- Check what help window are active
1087 local help_active={}
1088 for i = 0,7 do
1089 help_active[i] = getUI("ui:interface:sheet_help"..i).active
1092 arkNpcShop:OpenSheetInfosWindow(id)
1094 -- Apply previous stats of help window
1095 for i = 0,7 do
1096 getUI("ui:interface:sheet_help"..i).active = help_active[i]
1100 function arkNpcShop:OpenItemWindow(id, buy)
1101 local item = arkNpcShop.items[id]
1102 if arkNpcShop.all_items[id] ~= nil and arkNpcShop.all_items[id].need_real_item ~= nil then
1103 arkNpcShop.max_quantity = 1
1104 else
1105 if string.sub(item[3], 1, 1) == "!" then
1106 arkNpcShop.max_quantity = 1
1107 else
1108 arkNpcShop.max_quantity = item[3]
1112 arkNpcShop:HideHelpWindow(id)
1114 local non_buy_window_w = 400
1116 local ui_item_preview = getUI("ui:interface:ark_shop_buy_item:content:header_opened:item_preview")
1117 if ui_item_preview then
1118 ui_item_preview.active = false
1121 local ui_item_show_desc = getUI("ui:interface:ark_shop_buy_item:content:header_opened:desc")
1122 if ui_item_show_desc then
1123 ui_item_show_desc.active = item[2] == "#sheet"
1126 if string.sub(item[2], 1, 1) == "#" then
1127 local item_type = getSheetFamily(item[7])
1128 local display_preview = item_type == "SHIELD" or item_type == "ARMOR" or item_type == "MELEE_WEAPON" or item_type == "RANGE_WEAPON"
1129 if ui_item_preview then
1130 ui_item_preview.active = display_preview
1133 if display_preview then
1134 non_buy_window_w = 495
1135 else
1136 -- Items who are not named items must display help window when no buy
1137 if buy == nil and item[2] == "#sheet" then
1138 arkNpcShop:OpenSheetInfosWindow(id)
1139 return
1144 if buy == true then
1145 arkNpcShop.price = item[1]
1146 setDbProp("UI:TEMP:ARK_MONEY_PRICE", arkNpcShop.price)
1147 setDbProp("UI:TEMP:ARK_MONEY_TOTAL", arkNpcShop.price)
1149 if arkNpcShop.price > arkNpcShop.player_money then
1150 arkNpcShop.player_can_buy = false
1151 else
1152 arkNpcShop.player_can_buy = true
1156 local framewin = getUI("ui:interface:ark_shop_buy_item")
1157 if framewin == nil then
1158 createRootGroupInstance("webig_bot_chat_buy_item", "ark_shop_buy_item", {id="content", infosclick="arkNpcShop:OpenSheetInfosWindow("..id..")", onclick="arkNpcShop:Buy("..id..")"})
1159 framewin = getUI("ui:interface:ark_shop_buy_item")
1160 framewin.x = math.ceil(((getUI("ui:interface").w - framewin.w))/2)
1161 framewin.y = math.ceil(((getUI("ui:interface").h + framewin.h))/2)
1164 runAH(nil, "proc", "ark_shop_animate_preview_body")
1166 if buy == true then
1167 local eb = framewin:find("edit"):find("eb")
1168 eb.input_string = 1
1169 eb:setFocusOnText()
1170 eb:setSelectionAll()
1171 framewin:find("item_total_price"):find("icone").texture = arkNpcShop.MoneyIcon
1172 framewin:find("item_price"):find("icone").texture = arkNpcShop.MoneyIcon
1173 framewin:find("item_total_price"):find("tt").tooltip = arkNpcShop.Money
1174 framewin:find("item_price"):find("tt").tooltip = arkNpcShop.Money
1175 arkNpcShop.window_params = {-70, 305, 408}
1176 else
1177 arkNpcShop.window_params = {-20, 380, non_buy_window_w}
1180 framewin:find("top").active = buy == true -- active onlye if buy
1181 framewin:find("scroll_text").y=arkNpcShop.window_params[1]
1182 framewin:find("scroll_text").h=arkNpcShop.window_params[2]
1183 framewin.w=arkNpcShop.window_params[3]
1184 framewin.uc_title = getUCtf8(item[6])
1186 if buy == true then
1187 local html = ""
1188 html = arkNpcShop:getHtmlIcon(id, item)
1189 framewin:find("buy_sell_slot"):renderHtml(html)
1190 if string.sub(item[5], 1 , 8) == "https://" then
1191 framewin:find("ok").active=false
1192 framewin:find("infos"):renderHtml(arkNpcShop.PleaseWait)
1193 framewin:find("infos"):browse(item[5])
1194 else
1195 framewin:find("ok").active=true
1196 framewin:find("infos"):renderHtml("<table width='380px'><tr><td>"..item[5].."</td></tr></table>")
1198 arkNpcShop:CheckMoney()
1199 -- framewin:setModalParentList("ui:interface:ark_npc_shop")
1200 else
1201 html = arkNpcShop:getHtmlIcon(id, item)
1202 framewin:find("infos"):renderHtml([[
1203 <table width="100%">
1204 <tr>
1205 <td width="40px" valign="top">]]..html..[[</td>
1206 <td >]]..item[5]..[[</td>
1207 </tr>
1208 </table>
1212 framewin:find("desc").params_l = "arkNpcShop:OpenSheetInfosWindow("..id..")"
1213 framewin:find("ok").params_l = "arkNpcShop:Buy("..id..")"
1214 framewin.opened=true
1215 framewin.active=true
1219 function arkNpcShop:CheckMoney()
1220 local win = getUI("ui:interface:ark_shop_buy_item")
1221 local value = tonumber(win:find("edit"):find("eb").input_string)
1222 if value == nil or value == 0 then
1223 value = 1
1225 if arkNpcShop.max_quantity ~= 0 and value > arkNpcShop.max_quantity then
1226 win:find("edit"):find("eb").input_string = arkNpcShop.max_quantity
1227 value = arkNpcShop.max_quantity
1230 local total = arkNpcShop.price*value
1232 if total > arkNpcShop.player_money then
1233 win:find("ok").hardtext="uiNotEnoughMoney"
1234 arkNpcShop.player_can_buy = false
1235 else
1236 win:find("ok").hardtext = arkNpcShop.ActionName
1237 arkNpcShop.player_can_buy = true
1239 setDbProp("UI:TEMP:ARK_MONEY_TOTAL", total)
1242 function arkNpcShop:Close()
1243 local framewin = getUI("ui:interface:ark_npc_shop")
1244 if framewin ~= nil then
1245 framewin.active=false
1248 framewin = getUI("ui:interface:ark_shop_buy_item")
1249 if framewin ~= nil then
1250 framewin.active=false
1255 function arkNpcShop:timer(id, len)
1256 local diff = math.floor((nltime.getLocalTime() - savedTime) / 50)
1257 getUI("ui:interface:current_action").active=true
1258 setDbProp("UI:PHRASE:ACT_BAR_LEN", (100/len)*diff)
1259 if diff >= len then
1260 getUI("ui:interface:current_action").active=false
1261 setOnDraw(getUI("ui:interface:current_action"), "")
1262 local quantity = getUI("ui:interface:ark_shop_buy_item"):find("edit"):find("eb").input_string
1263 getUI("ui:interface:web_transactions"):find("html"):browse(arkNpcShop.ValidateUrl..quantity.."&item_id="..id.."&item_selection="..arkNpcShop.selectedItems[id])
1268 function arkNpcShop:Buy(id)
1269 local item = arkNpcShop.items[id]
1270 local win = getUI("ui:interface:ark_shop_buy_item")
1271 local quantity = win:find("edit"):find("eb").input_string
1272 if arkNpcShop.player_can_buy then
1273 local message = ucstring()
1274 message:fromUtf8("@{F5FF}"..getUI("ui:interface:target").title..": @{FF0F}I\'m checking to see if you\'re trying to rip him off... ")
1275 -- displaySystemInfo(message, "BC")
1277 if arkNpcShop.AtysPoint then
1278 if item[8] == 0 then
1279 local message = ucstring()
1280 message:fromUtf8(arkNpcShop.AtysPointsBuyMessage)
1281 displaySystemInfo(message, "BC")
1282 savedTime = nltime.getLocalTime()
1283 getUI("ui:interface:current_action").active=true
1284 local len = item[1]
1285 if len > 200 then
1286 len = 200
1288 setOnDraw(getUI("ui:interface:current_action"), "arkNpcShop:timer("..id..", "..tostring(len)..")")
1289 else
1290 getUI("ui:interface:web_transactions"):find("html"):browse(arkNpcShop.ValidateUrl..quantity.."&item_id="..id.."&item_selection="..arkNpcShop.selectedItems[id])
1292 else
1293 getUI("ui:interface:web_transactions"):find("html"):browse(arkNpcShop.ValidateUrl..quantity.."&item_id="..id.."&item_selection="..arkNpcShop.selectedItems[id])
1296 arkNpcShop:Close()
1299 -- VERSION --
1300 RYZOM_INTERACTION_VERSION = 324