-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKatiaBuilderToolkit.lua
2196 lines (1984 loc) · 69.8 KB
/
KatiaBuilderToolkit.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
require "Window"
require "CombatFloater"
require "ICCommLib"
require "ICComm"
require "Sound"
local KatiaBuilderToolkit = {}
local Batcher = Apollo.GetPackage("Module:KatiaBatcher-1.0").tPackage
local Utils = Apollo.GetPackage("Module:KatiaBuildUtils-1.0").tPackage
local SetManager = Apollo.GetPackage("Module:KatiaSetManager-1.0").tPackage
local DecorEditor = Apollo.GetPackage("Module:KatiaDecorEditor-1.0").tPackage
local DecorFinder = Apollo.GetPackage("Module:KatiaDecorFinder-1.0").tPackage
local PlotFinder = Apollo.GetPackage("Module:KatiaPlotFinder-1.0").tPackage
function KatiaBuilderToolkit:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function KatiaBuilderToolkit:Init()
local bHasConfigureFunction = false
local strConfigureButtonText = ""
local tDependencies = {}
Apollo.RegisterAddon(self, bHasConfigureFunction, strConfigureButtonText, tDependencies)
end
function KatiaBuilderToolkit:OnLoad()
self.xmlDoc = XmlDoc.CreateFromFile("KatiaBuilderToolkit.xml")
self.xmlDoc:RegisterCallback("OnDocLoaded", self)
self.kbtVersion = 8.3
self.donates = {
["Entity"] = {
[Unit.CodeEnumFaction.ExilesPlayer] = "Katia Managan",
[Unit.CodeEnumFaction.DominionPlayer] = "Bizarro Katia",
},
["Jabbit"] = {
[Unit.CodeEnumFaction.ExilesPlayer] = "Katia Managan",
[Unit.CodeEnumFaction.DominionPlayer] = "Bizarro Katia",
},
}
self.slots = {}
self.options = {}
self.shopresults = {}
self.checklist = {}
self.tCategoryItems = {}
self.acknowledged = {}
self.rpplots = {}
self.players = {}
self.playersSeen = 0
self.soundtracks = {
{file="1.wav", duration=23.262},
{file="2.wav", duration=28.687},
{file="3.wav", duration=23.493},
{file="win.wav", duration=12.024},
}
self.npcNicknames = {}
self.queuedCommands = {}
-- Register handlers for events, slash commands, etc.
Apollo.RegisterSlashCommand("katia", "OnKatiaBuilderToolkitOn", self)
Apollo.RegisterSlashCommand("kbt", "OnKatiaBuilderToolkitOn", self)
Apollo.RegisterSlashCommand("katiaset", "OnKatiaBuilderSet", self)
Apollo.RegisterSlashCommand("katiadecor", "OnKatiaBuilderDecor", self)
Apollo.RegisterSlashCommand("katiacolor", "OnKatiaBuilderColor", self)
Apollo.RegisterSlashCommand("katiashop", "OnKatiaBuilderShop", self)
Apollo.RegisterSlashCommand("katiainteract", "OnKatiaBuilderInteractables", self)
Apollo.RegisterSlashCommand("katiacleaner", "OnKatiaBuilderCleaner", self)
Apollo.RegisterSlashCommand("katiarp", "OnKatiaBuilderRP", self)
Apollo.RegisterSlashCommand("krp", "OnKatiaBuilderRP", self)
Apollo.RegisterSlashCommand("kcopy", "ParseCommand", self)
Apollo.RegisterSlashCommand("kpaste", "ParseCommand", self)
Apollo.RegisterSlashCommand("kclone", "ParseCommand", self)
Apollo.RegisterSlashCommand("kplace", "ParseCommand", self)
Apollo.RegisterSlashCommand("kcrate", "ParseCommand", self)
Apollo.RegisterSlashCommand("kcratelink", "ParseCommand", self)
Apollo.RegisterSlashCommand("kdiff", "ParseCommand", self)
Apollo.RegisterSlashCommand("kaverage", "ParseCommand", self)
Apollo.RegisterSlashCommand("ktarget", "ParseCommand", self)
Apollo.RegisterSlashCommand("kltt", "ParseCommand", self)
Apollo.RegisterSlashCommand("kfixlinks", "ParseCommand", self)
Apollo.RegisterSlashCommand("kfixchairs", "ParseCommand", self)
Apollo.RegisterSlashCommand("kfixghosts", "ParseCommand", self)
Apollo.RegisterSlashCommand("krevertskyiunderstandtherisk", "ParseCommand", self)
Apollo.RegisterSlashCommand("visit", "ParseCommand", self)
Apollo.RegisterSlashCommand("kvisit", "ParseCommand", self)
Apollo.RegisterSlashCommand("home", "ParseCommand", self)
Apollo.RegisterSlashCommand("khome", "ParseCommand", self)
Apollo.RegisterSlashCommand("kadd", "ParseCommand", self)
Apollo.RegisterSlashCommand("kaddall", "ParseCommand", self)
Apollo.RegisterSlashCommand("kaddlinkedset", "ParseCommand", self)
Apollo.RegisterSlashCommand("kaudit", "ParseCommand", self)
Apollo.RegisterSlashCommand("kremove", "ParseCommand", self)
Apollo.RegisterSlashCommand("kreloc", "ParseCommand", self)
Apollo.RegisterSlashCommand("kplaceall", "ParseCommand", self)
Apollo.RegisterSlashCommand("kplacealllink", "ParseCommand", self)
Apollo.RegisterSlashCommand("kclear", "ParseCommand", self)
Apollo.RegisterSlashCommand("klink", "ParseCommand", self)
Apollo.RegisterSlashCommand("klocate", "ParseCommand", self)
Apollo.RegisterSlashCommand("kworld", "ParseCommand", self)
Apollo.RegisterSlashCommand("kobject", "ParseCommand", self)
Apollo.RegisterSlashCommand("kdrag", "ParseCommand", self)
Apollo.RegisterSlashCommand("ktrap", "OnTrap", self)
Apollo.RegisterSlashCommand("ksummon", "ParseCommand", self)
Apollo.RegisterSlashCommand("kget", "ParseCommand", self)
Apollo.RegisterSlashCommand("kfind", "ParseCommand", self)
Apollo.RegisterSlashCommand("kfindplot", "ParseCommand", self)
Apollo.RegisterSlashCommand("kround", "ParseCommand", self)
Apollo.RegisterSlashCommand("ksnapshot", "ParseCommand", self)
Apollo.RegisterSlashCommand("kreconstruct", "ParseCommand", self)
Apollo.RegisterSlashCommand("kplay", "PlaySound", self)
Apollo.RegisterSlashCommand("kventriloquist", "Vent", self)
Apollo.RegisterSlashCommand("kvent", "Vent", self)
Apollo.RegisterSlashCommand("kv", "Vent", self)
Apollo.RegisterSlashCommand("kpuppet", "Puppet", self)
Apollo.RegisterSlashCommand("kp", "Puppet", self)
Apollo.RegisterEventHandler("HousingMyResidenceDecorChanged", "OnDecorChange", self)
Apollo.RegisterEventHandler("HousingFreePlaceDecorCancelled", "OnDecorCancel", self)
Apollo.RegisterEventHandler("HousingFreePlaceDecorMoveBegin", "OnDecorMoveBegin", self)
Apollo.RegisterEventHandler("HousingFreePlaceDecorMoveEnd", "OnDecorMoveEnd", self)
Apollo.RegisterEventHandler("UnitCreated", "OnUnitCreated", self)
Apollo.RegisterEventHandler("UnitDestroyed", "OnUnitDestroyed", self)
self.HousingAddon = Apollo.GetAddon("Housing")
self.connectTimer = ApolloTimer.Create(1, true, "ConnectVer", self)
self.connectTimer:Start()
self.rpDecayTimer = ApolloTimer.Create(155, true, "RPDecay", self)
self.rpDecayTimer:Start()
self.rpReportTimer = ApolloTimer.Create(30 + math.random(120), false, "RPReport", self)
self.rpReportTimer:Start()
self.bNotified = false
self.highestVer = self.kbtVersion
end
function KatiaBuilderToolkit:HookChat()
if not self.chatAddon then
self.chatAddon = Apollo.GetAddon("ChatLog")
self.chatAddon.oldChatHandler = self.chatAddon.OnChatMessage
self.chatAddon.kbtExceptions = {}
self.chatAddon.OnChatMessage = function (root, chan, msg)
if chan:GetType() == ChatSystemLib.ChatChannel_Say or chan:GetType() == ChatSystemLib.ChatChannel_Emote then
if root.kbtExceptions[msg.strSender .. ":" .. msg.arMessageSegments[1].strText] then
root.kbtExceptions[msg.strSender .. ":" .. msg.arMessageSegments[1].strText] = nil
else
root.oldChatHandler(root, chan, msg)
end
else
root.oldChatHandler(root, chan, msg)
end
end
end
end
function KatiaBuilderToolkit:PlaySound(strCmd, strArg)
local ind = tonumber(strArg) or 1
if self.playTimer ~= nil then
self.playQueue = ind
else
self.playTimer = ApolloTimer.Create(self.soundtracks[ind].duration, false, "RePlay", self)
Sound.PlayFile(self.soundtracks[ind].file)
end
self.verComm:SendMessage("sound " .. ind)
end
function KatiaBuilderToolkit:QueueCommand(command)
table.insert(self.queuedCommands, command)
if self.commandTimer then
self.commandTimer:Stop()
end
self.commandTimer = ApolloTimer.Create(1, false, "RunCommands", self)
self.commandTimer:Start()
end
function KatiaBuilderToolkit:RunCommands()
for _, command in ipairs(self.queuedCommands) do
ChatSystemLib.Command(command)
end
self.queuedCommands = {}
if self.commandTimer then
self.commandTimer:Stop()
self.commandTimer = nil
end
end
function KatiaBuilderToolkit:Vent(strCmd, strArg)
if not self.verComm then return end
local target = GameLib.GetPlayerUnit():GetTarget()
if target == nil then
self:FloatText("Target an npc to ventriloquist!")
return
end
local tid = target:GetId()
local msg = "vent " .. tid .. " " .. strArg
if string.sub(strArg, 1, 2) == "((" and string.find(strArg, ")) ") then
self.npcNicknames[tid] = string.sub(strArg, 3, string.find(strArg, ")) ") - 1)
self:OnVersionReceived(nil, msg, GameLib.GetPlayerUnit():GetName())
self.verComm:SendMessage(msg)
self:QueueCommand("/s " .. strArg)
else
if self.npcNicknames[tid] then
msg = "vent " .. tid .. " ((" .. self.npcNicknames[tid] .. ")) " .. strArg
self:OnVersionReceived(nil, msg, GameLib.GetPlayerUnit():GetName())
self.verComm:SendMessage(msg)
self:QueueCommand("/s ((" .. self.npcNicknames[tid] .. ")) " .. strArg)
else
self:OnVersionReceived(nil, msg, GameLib.GetPlayerUnit():GetName())
self.verComm:SendMessage(msg)
self:QueueCommand("/s ((" .. target:GetName() .. ")) " .. strArg)
end
end
end
function KatiaBuilderToolkit:Puppet(strCmd, strArg)
if not self.verComm then return end
local target = GameLib.GetPlayerUnit():GetTarget()
if target == nil then
self:FloatText("Target an npc to ventriloquist!")
return
end
local tid = target:GetId()
local msg = "puppet " .. tid .. " " .. strArg
if string.sub(strArg, 1, 2) == "((" and string.find(strArg, ")) ") then
self.npcNicknames[tid] = string.sub(strArg, 3, string.find(strArg, ")) ") - 1)
self:OnVersionReceived(nil, msg, GameLib.GetPlayerUnit():GetName())
self.verComm:SendMessage(msg)
self:QueueCommand("/e " .. strArg)
else
if self.npcNicknames[tid] then
msg = "puppet " .. tid .. " ((" .. self.npcNicknames[tid] .. ")) " .. strArg
self:OnVersionReceived(nil, msg, GameLib.GetPlayerUnit():GetName())
self.verComm:SendMessage(msg)
self:QueueCommand("/e ((" .. self.npcNicknames[tid] .. ")) " .. strArg)
else
self:OnVersionReceived(nil, msg, GameLib.GetPlayerUnit():GetName())
self.verComm:SendMessage(msg)
self:QueueCommand("/e ((" .. target:GetName() .. ")) " .. strArg)
end
end
end
function KatiaBuilderToolkit:RePlay()
if self.playQueue ~= nil then
self.playTimer = ApolloTimer.Create(self.soundtracks[self.playQueue].duration, false, "RePlay", self)
Sound.PlayFile(self.soundtracks[self.playQueue].file)
self.playQueue = nil
else
self.playTimer = nil
end
end
function KatiaBuilderToolkit:OnUnitCreated(unit)
if unit ~= nil and unit:IsACharacter() and self.players[unit:GetName()] == nil then
self.playersSeen = self.playersSeen + 1
self.players[unit:GetName()] = 1
end
end
function KatiaBuilderToolkit:OnUnitDestroyed(unit)
if unit ~= nil and unit:IsACharacter() and self.players[unit:GetName()] ~= nil then
self.playersSeen = self.playersSeen - 1
self.players[unit:GetName()] = nil
end
end
function KatiaBuilderToolkit:ConnectVer()
if not self.verComm then
self.verComm = ICCommLib.JoinChannel("KBTVersion", ICCommLib.CodeEnumICCommChannelType.Global);
if self.verComm then
self.verComm:SetReceivedMessageFunction("OnVersionReceived", self)
self.verComm:SendMessage(tostring(self.kbtVersion))
end
elseif not self.rpmonComm then
self.rpmonComm = ICCommLib.JoinChannel("KBTRPMon", ICCommLib.CodeEnumICCommChannelType.Global);
if self.rpmonComm then
self.rpmonComm:SetReceivedMessageFunction("OnRPMonReceived", self)
end
else
self.connectTimer:Stop()
end
end
local function PlayerDistance(a, b)
return math.sqrt((a.x - b.x) * (a.x - b.x) +
(a.y - b.y) * (a.y - b.y) +
(a.z - b.z) * (a.z - b.z))
end
function KatiaBuilderToolkit:OnVersionReceived(iccomm, strMessage, strSender)
local seenVer = tonumber(strMessage)
if seenVer then
if seenVer > self.highestVer then
self.highestVer = seenVer
if not self.bNotified then
self.wndMain:FindChild("Title"):SetText("UPDATE NEEDED")
self.wndMain:FindChild("Title"):SetTextColor({r=1,b=0,g=0,a=1})
self.bNotified = true
end
end
elseif strMessage == "request" then
self.verComm:SendPrivateMessage(strSender, "running version " .. tostring(self.kbtVersion) .. " reporting: " .. tostring(self.bReporter))
elseif strMessage == "showerrors" then
local errors = Apollo.GetAddonInfo("KatiaBuilderToolkit").arErrors
if errors ~= nil then
for _, e in pairs(errors) do
self.verComm:SendPrivateMessage(strSender, e)
end
end
elseif string.sub(strMessage, 1, 5) == "vent " and
(strSender == "Katia Managan" or (HousingLib.GetResidence() and HousingLib.GetResidence():GetPropertyOwnerName() == strSender)) then
local args = string.sub(strMessage, 6, -1)
local spaceInd = string.find(args, " ")
if spaceInd ~= nil and spaceInd > 1 then
local id = tonumber(string.sub(args, 1, spaceInd - 1))
local message = string.sub(args, spaceInd + 1)
if id ~= nil then
local unit = GameLib.GetUnitById(id)
if unit ~= nil and not unit:IsACharacter() and
PlayerDistance(unit:GetPosition(), GameLib.GetPlayerUnit():GetPosition()) < 30 then
local dialogue
local npc
if string.sub(message, 1, 2) == "((" and string.find(message, ")) ") then
local talkIndex = string.find(message, ")) ")
dialogue = string.sub(message, talkIndex + 3)
npc = string.sub(message, 3, talkIndex - 1)
else
dialogue = message
npc = unit:GetName()
end
unit:AddTextBubble(dialogue)
ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Say,
dialogue, "((" .. npc .. "))")
self:HookChat()
self.chatAddon.kbtExceptions[strSender .. ":((" .. npc .. ")) " .. dialogue] = true
end
end
end
elseif string.sub(strMessage, 1, 7) == "puppet " and
(strSender == "Katia Managan" or (HousingLib.GetResidence() and HousingLib.GetResidence():GetPropertyOwnerName() == strSender)) then
local args = string.sub(strMessage, 8, -1)
local spaceInd = string.find(args, " ")
if spaceInd ~= nil and spaceInd > 1 then
local id = tonumber(string.sub(args, 1, spaceInd - 1))
local message = string.sub(args, spaceInd + 1)
if id ~= nil then
local unit = GameLib.GetUnitById(id)
if unit ~= nil and not unit:IsACharacter() and
PlayerDistance(unit:GetPosition(), GameLib.GetPlayerUnit():GetPosition()) < 30 then
local dialogue
local npc
if string.sub(message, 1, 2) == "((" and string.find(message, ")) ") then
local talkIndex = string.find(message, ")) ")
dialogue = string.sub(message, talkIndex + 3)
npc = string.sub(message, 3, talkIndex - 1)
else
dialogue = message
npc = unit:GetName()
end
ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Emote,
dialogue, "((" .. npc .. "))")
self:HookChat()
self.chatAddon.kbtExceptions[strSender .. ":((" .. npc .. ")) " .. dialogue] = true
end
end
end
elseif string.sub(strMessage, 1, 6) == "sound " then
local res = HousingLib.GetResidence()
if res == nil then return end
if res:GetPropertyOwnerName() ~= strSender then return end
local ind = tonumber(string.sub(strMessage, 7)) or 1
if self.playTimer ~= nil then
self.playQueue = ind
else
self.playTimer = ApolloTimer.Create(self.soundtracks[ind].duration, false, "RePlay", self)
Sound.PlayFile(self.soundtracks[ind].file)
end
elseif string.find(GameLib.GetPlayerUnit():GetName(), "Katia") ~= nil then -- Assuming nobody else wants to see this stuff:P
Print(strSender .. ": " .. strMessage)
end
end
function KatiaBuilderToolkit:OnDocLoaded()
if self.xmlDoc ~= nil and self.xmlDoc:IsLoaded() then
self.wndMain = Apollo.LoadForm(self.xmlDoc, "KatiaBuilderToolkitForm", nil, self)
if self.wndMain == nil then
Apollo.AddAddonErrorText(self, "Could not load the main window for some reason.")
return
end
self.wndShop = Apollo.LoadForm(self.xmlDoc, "ShopForm", nil, self)
if self.wndShop == nil then
Apollo.AddAddonErrorText(self, "Could not load the shop window for some reason.")
return
end
self.wndCleaner = Apollo.LoadForm(self.xmlDoc, "CleanerForm", nil, self)
if self.wndCleaner == nil then
Apollo.AddAddonErrorText(self, "Could not load the crate cleaner window for some reason.")
return
end
self.wndInteract = Apollo.LoadForm(self.xmlDoc, "InteractForm", nil, self)
if self.wndInteract == nil then
Apollo.AddAddonErrorText(self, "Could not load the interactables window for some reason.")
return
end
self.wndRP = Apollo.LoadForm(self.xmlDoc, "RPForm", nil, self)
if self.wndRP == nil then
Apollo.AddAddonErrorText(self, "Could not load the RP window for some reason.")
return
end
self.wndRPAsk = Apollo.LoadForm(self.xmlDoc, "AskReport", nil, self)
if self.wndRPAsk == nil then
Apollo.AddAddonErrorText(self, "Could not load the RP report dialog for some reason.")
return
end
self.wndOptions = Apollo.LoadForm(self.xmlDoc, "OptionsForm", nil, self)
if self.wndOptions == nil then
Apollo.AddAddonErrorText(self, "Could not load the options window for some reason.")
return
end
self.wndDonate = Apollo.LoadForm(self.xmlDoc, "DonateForm", nil, self)
if self.wndDonate == nil then
Apollo.AddAddonErrorText(self, "Could not load the donation window for some reason.")
return
end
self.wndMenu = Apollo.LoadForm(self.xmlDoc, "MenuForm", self.wndMain, self)
if self.wndMenu == nil then
Apollo.AddAddonErrorText(self, "Could not load the menu window for some reason.")
return
end
self.wndBack = Apollo.LoadForm(self.xmlDoc, "Background", "InWorldHudStratum", self)
if self.wndBack == nil then
Apollo.AddAddonErrorText(self, "Could not load the background window for some reason.")
return
end
self.wndMain:Show(false, true)
self.wndShop:Show(false, true)
self.wndCleaner:Show(false, true)
self.wndInteract:Show(false, true)
self.wndRP:Show(false, true)
self.wndRPAsk:Show(false, true)
self.wndOptions:Show(false, true)
self.wndDonate:Show(false, true)
self.wndMenu:Show(false, true)
self.wndMain:FindChild("Position"):SetCheck(true)
self.wndMain:FindChild("Rotation"):SetCheck(true)
self.wndMain:FindChild("Scale"):SetCheck(true)
self:ApplyOptions()
self.interactTimer = ApolloTimer.Create(0.5, true, "OnInteractTick", self)
self.interactTimer:Start()
end
end
-----------------------------------------------------
-- Rotation bug fix
-----------------------------------------------------
function KatiaBuilderToolkit:OnDecorMoveBegin(dec)
if HousingLib.GetResidence():GetCustomizationMode() == HousingLib.ResidenceCustomizationMode.Advanced then
self.premove = Utils:DecorToPack(dec)
end
end
function KatiaBuilderToolkit:OnDecorMoveEnd(dec)
DecorEditor:Refresh()
if self.premove == nil then
return
end
local pack = Utils:DecorToPack(dec)
-- If the move is a translation, make sure the scale and rotation don't change
if math.abs(pack.X - self.premove.X) > .01 or
math.abs(pack.Y - self.premove.Y) > .01 or
math.abs(pack.Z - self.premove.Z) > .01 then
dec:SetRotation(self.premove.P, self.premove.R, self.premove.Yaw)
dec:SetScale(self.premove.S)
end
self.premove = nil
end
-----------------------------------------------------
-- Helper functions
-----------------------------------------------------
-- sorted iterator
local function __genOrderedIndex( t )
local orderedIndex = {}
for key in pairs(t) do
table.insert( orderedIndex, key )
end
table.sort( orderedIndex )
return orderedIndex
end
local function snext(t, state)
key = nil
if state == nil then
t.__orderedIndex = __genOrderedIndex( t )
key = t.__orderedIndex[1]
else
for i = 1,table.getn(t.__orderedIndex) do
if t.__orderedIndex[i] == state then
key = t.__orderedIndex[i+1]
end
end
end
if key then
return key, t[key]
end
t.__orderedIndex = nil
return
end
local function spairs(t)
return snext, t, nil
end
-- Update slot selectors in UI
function Increment(window, label, amount)
local value = tonumber(window:FindChild(label):GetText())
if value == nil then
self:FloatText("Not a number")
return
end
window:FindChild(label):SetText(string.format("%d", value + amount))
end
function IncrementF(window, label, amount)
local value = tonumber(window:FindChild(label):GetText())
if value == nil then
self:FloatText("Not a number")
return
end
window:FindChild(label):SetText(string.format("%.2f", value + amount))
end
-- Display screen message to user
function KatiaBuilderToolkit:FloatText(strMessage)
local tTextOption = {
strFontFace = "CRB_FloaterLarge",
fDuration = 3.5,
fScale = 1,
fExpand = 1,
fVibrate = 0,
fSpinAroundRadius = 0,
fFadeInDuration = 0.2,
fFadeOutDuration = 0.5,
fVelocityDirection = 0,
fVelocityMagnitude = 0,
fAccelDirection = 0,
fAccelMagnitude = 0,
fEndHoldDuration = 1,
eLocation = CombatFloater.CodeEnumFloaterLocation.Bottom,
fOffsetDirection = 0,
fOffset = 0,
eCollisionMode = CombatFloater.CodeEnumFloaterCollisionMode.Horizontal,
fExpandCollisionBoxWidth = 1,
fExpandCollisionBoxHeight = 1,
nColor = 0xFF0000,
iUseDigitSpriteSet = nil,
bUseScreenPos = true,
bShowOnTop = true,
fRotation = 0,
fDelay = 0,
nDigitSpriteSpacing = 0,
}
CombatFloater.ShowTextFloater(GameLib.GetControlledUnit(), strMessage, tTextOption)
end
-- Check if all strings in matchers are in check
local function CheckMatchers(check, matchers)
for _,i in pairs(matchers) do
if string.find(string.lower(check), string.lower(i)) == nil then
return false
end
end
return true
end
-----------------------------------------------------
-- Slash commands
-----------------------------------------------------
-- /katia
function KatiaBuilderToolkit:OnKatiaBuilderToolkitOn()
self.wndMain:Invoke() -- show the window
end
-- /katiaset
function KatiaBuilderToolkit:OnKatiaBuilderSet()
SetManager:Open()
self.wndMenu:Close() -- hide the menu if it was used to get here
end
-- /katiashop
function KatiaBuilderToolkit:OnKatiaBuilderShop()
self.wndShop:Invoke() -- show the window
self.wndMenu:Close() -- hide the menu if it was used to get here
self:ShowShopResults()
end
function KatiaBuilderToolkit:OnKatiaBuilderOptions()
self.wndOptions:Invoke() -- show the window
self.wndMenu:Close() -- hide the menu if it was used to get here
end
function KatiaBuilderToolkit:OnKatiaBuilderDecor()
DecorEditor:Open()
self.wndMenu:Close() -- hide the menu if it was used to get here
end
function KatiaBuilderToolkit:OnShopScan()
if not HousingLib.IsOnMyResidence() then
self:FloatText("Please return to your home to scan")
return
end
self.wndShop:Close()
local todo = Batcher:Prepare(
function (b, id)
local dec = HousingLib.PreviewVendorDecor(id)
if dec ~= nil and dec:GetName() ~= "" then
table.insert(self.catalog, {I=id, N=dec:GetName(), T=dec:GetDecorType()})
dec:CancelTransform()
if id > self.highestKnownDecorID then
self.highestKnownDecorID = id
end
--self:FloatText("LastAdded: "..b.lastAdded)
if id + 1000 >= b.lastAdded then
for i = b.lastAdded, id + 1010 do
table.insert(b.todo, i)
end
b.lastAdded = id + 1010
b.barProg:SetMax(b.lastAdded)
end
end
end,
nil,
nil
)
if todo == nil then return end
self.catalog = {}
if self.highestKnownDecorID == nil or self.highestKnownDecorID < 4300 then
self.highestKnownDecorID = 4300
end
Batcher.lastAdded = self.highestKnownDecorID + 1000
for i=1,Batcher.lastAdded do
table.insert(todo, i)
end
Batcher:StartTimed(0.03)
end
function KatiaBuilderToolkit:OnShopSearch()
if self.catalog == nil then
self:FloatText("Please scan the decor list first")
return
end
self.shopresults = {}
local terms = {}
local rescan = true
string.gsub(self.wndShop:FindChild("Terms"):GetText(),
"([^ ]+)", function(c) table.insert(terms, c) end)
for _, dec in pairs(self.catalog) do
if CheckMatchers(dec.N, terms) and (dec.T == nil or self.shopfilter == nil or self.shopfilter[dec.T]) then
table.insert(self.shopresults, dec)
end
if dec.T ~= nil then rescan = false end
end
if rescan then self:FloatText("Redo scan to enable search by category") end
self.wndShop:FindChild("Page"):SetText("1")
self:ShowShopResults()
end
function KatiaBuilderToolkit:OnSortByCheck()
self:PopulateCategoryList()
self.wndShop:FindChild("SortByWindow"):Show(true)
end
function KatiaBuilderToolkit:OnSortByUncheck()
self.wndShop:FindChild("SortByWindow"):Show(false)
end
function KatiaBuilderToolkit:PopulateCategoryList()
local wndSortByList = self.wndShop:FindChild("SortByList")
local nScrollPosition = wndSortByList:GetVScrollPos()
for _, item in pairs(self.tCategoryItems) do
item:Destroy()
end
self.tCategoryItems = {}
local tCategoryList = {}
for _, dec in pairs(HousingLib.GetDecorTypeList()) do
if dec.strName ~= nil and dec.strName ~= "" then
if tCategoryList[dec.strName] == nil then
tCategoryList[dec.strName] = {strName = dec.strName, nIds = {}}
end
tCategoryList[dec.strName].nIds[dec.nId] = true
end
end
-- populate the list
if tCategoryList ~= nil then
local tFirstItemData = {}
tFirstItemData.strName = Apollo.GetString("HousingDecorate_AllTypes")
self:AddCategoryItem(wndSortByList, tFirstItemData)
for _, item in spairs(tCategoryList) do
self:AddCategoryItem(wndSortByList, item)
end
end
self.tCategoryList = tCategoryList
-- now all the iteam are added, call ArrangeChildrenVert to list out the list items vertically
wndSortByList:ArrangeChildrenVert()
wndSortByList:SetVScrollPos(nScrollPosition)
end
function KatiaBuilderToolkit:AddCategoryItem(wndSortByList, tItemData)
local wndListItem = Apollo.LoadForm(self.xmlDoc, "CategoryListItem", wndSortByList, self)
table.insert(self.tCategoryItems, wndListItem)
local wndItemBtn = wndListItem:FindChild("CategoryBtn")
if wndItemBtn then -- make sure the text wndListItem exist
local strName = tItemData.strName
wndItemBtn:SetText(strName)
wndItemBtn:SetData(tItemData)
end
end
function KatiaBuilderToolkit:OnSortByItemSelected(wndHandler, wndControl)
if not wndControl then
return
end
local tData = wndControl:GetData()
self.shopfilter = tData.nIds
self.wndShop:FindChild("SortByBtn"):SetText(tData.strName)
self.wndShop:FindChild("SortByBtn"):SetCheck(false)
self:OnSortByUncheck()
end
function KatiaBuilderToolkit:Acknowledge()
local tDecorVendorList = HousingLib.GetDecorCatalogList()
if tDecorVendorList ~= nil then
self.acknowledged = {}
for idx = 1, #tDecorVendorList do
local tVendorDecorData = tDecorVendorList[idx]
self.acknowledged[tVendorDecorData.nId] = true
end
end
self:ShowNewVendor()
end
function KatiaBuilderToolkit:ShowNewVendor()
self.shopresults = {}
local tDecorVendorList = HousingLib.GetDecorCatalogList()
if tDecorVendorList ~= nil then
for idx = 1, #tDecorVendorList do
local tVendorDecorData = tDecorVendorList[idx]
if not self.acknowledged[tVendorDecorData.nId] then
table.insert(self.shopresults, {I = tVendorDecorData.nId, N = tVendorDecorData.strName, T = tVendorDecorData.eDecorType})
end
end
end
self.wndShop:FindChild("Page"):SetText("1")
self:ShowShopResults()
end
function KatiaBuilderToolkit:ShowShopResults()
local maxresults = tonumber(self.wndShop:FindChild("MaxResults"):GetText())
if maxresults == nil then maxresults = 50 end
self.wndShop:FindChild("MaxResults"):SetText(tostring(maxresults))
local start = (tonumber(self.wndShop:FindChild("Page"):GetText()) - 1) * maxresults + 1
local finish = start + maxresults - 1
local pages = math.floor((#self.shopresults + maxresults - 1) / maxresults)
self.wndShop:FindChild("PageMax"):SetText(tostring(pages))
local wndList = self.wndShop:FindChild("List")
wndList:DestroyChildren()
for i=start,finish,1 do
local dec = self.shopresults[i]
if dec ~= nil then
local wndListItem = Apollo.LoadForm(self.xmlDoc, "ShopItem", wndList, self)
wndListItem:SetData(dec)
local wndMod = wndListItem:FindChild("ModelWindow")
wndMod:SetDecorInfo(dec.I)
local wndName = wndListItem:FindChild("Name")
wndName:SetText(dec.N)
end
end
wndList:ArrangeChildrenTiles()
end
function KatiaBuilderToolkit:OnShopSelect(wndHandler, wndControl, eMouseButton)
local dec = wndHandler:GetData()
self.wndShop:FindChild("SelectedName"):SetText(dec.N)
self.wndShop:FindChild("SelectedId"):SetText(dec.I)
self.wndShop:FindChild("SelectedJabbit"):SetText("www.jabbithole.com/search?q=" .. string.gsub(dec.N, " ", "+"))
self.wndShop:FindChild("SelectedModel"):SetDecorInfo(dec.I)
self.shopDecorID = dec.I
end
function KatiaBuilderToolkit:OnShopAddToCrate( wndHandler, wndControl, eMouseButton )
if self.shopDecorID ~= nil then
local sendCommand = string.format("!house decoradd %s 1", self.shopDecorID)
ChatSystemLib.Command(sendCommand)
end
end
function KatiaBuilderToolkit:OnShopSearchAH()
local wndAuc = Apollo.GetAddon("MarketplaceAuction").wndMain
if wndAuc == nil or not wndAuc:IsShown() then
self:FloatText("Please open the auction house")
return
end
wndAuc:ToFront()
local searches = {}
for _, dat in pairs(MarketplaceLib.SearchAuctionableItems(self.wndShop:FindChild("SelectedName"):GetText())) do
table.insert(searches, dat.nId or 0)
end
MarketplaceLib.RequestItemAuctionsByItems(searches, 0, MarketplaceLib.AuctionSort.Buyout, false, {}, false, false)
end
-- /kfindplot
function KatiaBuilderToolkit:FindPlot(strArg)
if strArg == "" then
PlotFinder:OnFindPlot()
return
end
local terms = {}
string.gsub(strArg, "([^ ]+)", function(c) table.insert(terms, c) end)
local tries = tonumber(terms[1])
if tries ~= nil then
table.remove(terms, 1)
end
PlotFinder:ScanPlots(tries, terms)
end
function ToHundredth(num)
return math.floor(num * 100 + .5) / 100
end
-- /ktrap easter egg :)
function KatiaBuilderToolkit:OnTrap()
local target = GameLib.GetPlayerUnit():GetTarget()
if target == nil then
self:FloatText("Target a victim!")
return
end
local tPos = target:GetPosition()
local dPos = Utils:PlayerToDecorPos(tPos)
dPos.Y = dPos.Y + 8
dPos.P = 180
dPos.R = 0
dPos.Yaw = 0
dPos.S = .8
dPos.N = "Coffin (Spiked)"
Utils:ClonePack(dPos)
Utils:Place()
end
-----------------------------------------------------
-- Rest of the slash commands
-----------------------------------------------------
function KatiaBuilderToolkit:ParseCommand(strCmd, strArg)
if strCmd == "kcopy" then
if tonumber(strArg) == nil then
self:OnCopy()
else
self:Copy(tonumber(strArg))
end
elseif strCmd == "kpaste" then
if tonumber(strArg) == nil then
self:OnPaste()
else
self:Paste(tonumber(strArg))
end
elseif strCmd == "kclone" then
if tonumber(strArg) == nil then
self:OnClone()
else
self:Clone(tonumber(strArg))
end
elseif strCmd == "kplace" then
Utils:Place()
elseif strCmd == "kcrate" then
Utils:Crate()
elseif strCmd == "kcratelink" then
Utils:CrateLinkedSet()
elseif strCmd == "kdiff" then
if strArg == "" then
self:OnDiff()
else
local x, y = string.find(strArg, " ")
if x == nil or y == nil then
self:FloatText("Must specify from and to")
return
end
self:Diff(tonumber(string.sub(strArg, 1, x - 1)), tonumber(string.sub(strArg, x + 1, -1)))
end
elseif strCmd == "kaverage" then
if strArg == "" then
self:OnAverage()
else
local x, y = string.find(strArg, " ")
if x == nil or y == nil then
self:FloatText("Must specify from and to")
return
end
self:Average(tonumber(string.sub(strArg, 1, x - 1)), tonumber(string.sub(strArg, x + 1, -1)))
end
elseif strCmd == "ktarget" then
self:Target()
elseif strCmd == "kltt" then
DecorEditor:LinkToTarget()
elseif strCmd == "kfixlinks" then
self:FixLinks()
elseif strCmd == "kfixchairs" then
self:FixChairs()
elseif strCmd == "kfixghosts" then
self:FixGhosts()
elseif strCmd == "krevertskyiunderstandtherisk" then
self:RevertSky()
elseif strCmd == "visit" or strCmd == "kvisit" then
self:Visit(strArg)
elseif strCmd == "home" or strCmd == "khome" then
self:Visit(GameLib.GetPlayerUnit():GetName())
elseif strCmd == "kadd" then
SetManager:Add()
elseif strCmd == "kaddlinkedSet" then
if tonumber(strArg) == nil then
SetManager:OnAddLinkedSet()
else
SetManager:AddLinkedSet(tonumber(strArg))
end
elseif strCmd == "kaddall" then
SetManager:AddAll()
elseif strCmd == "kremove" then
SetManager:Remove()
elseif strCmd == "kclear" then
if tonumber(strArg) == nil then
SetManager:OnClear()
else
SetManager:Clear(tonumber(strArg))
end
elseif strCmd == "kaudit" then
if tonumber(strArg) == nil then
SetManager:OnAudit()
else
SetManager:Audit(tonumber(strArg))
end
elseif strCmd == "kreloc" then
SetManager:Reloc()
elseif strCmd == "kplaceall" then
SetManager:PlaceAll(false)
elseif strCmd == "kplacealllink" then
SetManager:PlaceAll(true)
elseif strCmd == "klink" then
DecorEditor:OnLink()
elseif strCmd == "klocate" then
Utils:Locate()
elseif strCmd == "kworld" then
DecorEditor:OnWorld()
elseif strCmd == "kobject" then
DecorEditor:OnObject()
elseif strCmd == "kdrag" then
DecorEditor:OnDrag()
elseif strCmd == "ksummon" then
Utils:Summon(strArg)
elseif strCmd == "kget" then
Utils:Summon(strArg)
elseif strCmd == "kfind" then
DecorFinder:Find(strArg)
elseif strCmd == "kfindplot" then