-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFeedOMatic.lua
1726 lines (1525 loc) · 56.5 KB
/
FeedOMatic.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
------------------------------------------------------
-- FeedOMatic.lua
------------------------------------------------------
FOM_VERSION = "11200.2";
------------------------------------------------------
-- TODO: if you don't auto-feed, have an option to make the need to feed more noticeable (e.g., pulsing halo around the pet-happiness icon).
-- constants
FOM_WARNING_INTERVAL = 10; -- don't warn more than once per this many seconds
MAX_QUALITY = 35 * 60 + 1; -- We store a notion of a food's "quality": its best happiness-per-tick multiplied by the pet's level as of when that tick occurred. We use "best" because a pet that's closer to "sated" (maximum happiness) will receive less happiness per tick than he would from the same food if he were hungrier. (So, a food that gives 35 happiness per tick to a level 60 pet is "better" than a food that's worth 35 happiness per tick to a level 30 pet.) Foods whose quality hasn't been observed yet are given this value when sorting, so we can prioritize the discovery of new foods' quality ratings.
MAX_KEEPOPEN_SLOTS = 150;
-- Configuration
FOM_Config_Default = {
Enabled = false;
Alert = "emote";
Level = "content";
KeepOpenSlots = 8;
AvoidUsefulFood = true;
AvoidQuestFood = true;
AvoidBonusFood = true;
Fallback = false;
SaveForCookingLevel = 1;
PreferHigherQuality = true;
Tooltip = true;
};
FOM_Config = FOM_Config_Default;
-- FOM_Cooking = { };
-- Has the following internal structure:
-- REALM_PLAYER = {
-- FOODNAME = SKILL_DIFFICULTY,
-- }
-- FOM_QuestFood = { };
-- Has the following internal structure:
-- REALM_PLAYER = {
-- FOODNAME = QUANTITY_REQUIRED,
-- }
-- FOM_FoodQuality = { };
-- Has the following internal structure:
-- REALM_PLAYER = {
-- PETNAME = {
-- FOODNAME = HAPPINESS,
-- }
-- }
-- Variables
FOM_State = { };
FOM_State.InCombat = false;
FOM_State.IsAFK = false;
FOM_State.ShouldFeed = false;
FOM_LastWarning = 0;
FOM_LastFood = nil;
FOM_RealmPlayer = nil;
FOM_LastPetName = nil;
-- Anti-freeze code borrowed from ReagentInfo (in turn, from Quest-I-On):
-- keeps WoW from locking up if we try to scan the tradeskill window too fast.
FOM_TradeSkillLock = { };
FOM_TradeSkillLock.Locked = false;
FOM_TradeSkillLock.EventTimer = 0;
FOM_TradeSkillLock.EventCooldown = 0;
FOM_TradeSkillLock.EventCooldownTime = 1;
-- State variable used to track required quantities of quest food when it's in more than one stack
FOM_Quantity = { };
-- Remember how item IDs map to food names at runtime, but don't bloat long-term memory with it...
FOM_FoodIDsToNames = {};
function FOM_FeedButton_OnClick()
if (arg1 == "RightButton") then
if FOM_OptionsFrame:IsVisible() then
HideUIPanel(FOM_OptionsFrame);
else
ShowUIPanel(FOM_OptionsFrame);
end
else
FOM_Feed();
end
end
function FOM_FeedButton_OnEnter()
if ( PetFrameHappiness.tooltip ) then
GameTooltip:SetOwner(PetFrameHappiness, "ANCHOR_RIGHT");
GameTooltip:SetText(PetFrameHappiness.tooltip);
if ( PetFrameHappiness.tooltipDamage ) then
GameTooltip:AddLine(PetFrameHappiness.tooltipDamage, "", 1, 1, 1);
end
if ( PetFrameHappiness.tooltipLoyalty ) then
GameTooltip:AddLine(PetFrameHappiness.tooltipLoyalty, "", 1, 1, 1);
end
GameTooltip:Show();
end
end
function FOM_FeedButton_OnLeave()
GameTooltip:Hide();
end
function FOM_OnLoad()
-- Register for Events
this:RegisterEvent("VARIABLES_LOADED");
-- Register Slash Commands
SLASH_FEEDOMATIC1 = "/feedomatic";
SLASH_FEEDOMATIC2 = "/fom";
SLASH_FEEDOMATIC3 = "/feed";
SLASH_FEEDOMATIC4 = "/petfeed"; -- Rauen's PetFeed compatibility
SLASH_FEEDOMATIC5 = "/pf";
SlashCmdList["FEEDOMATIC"] = function(msg)
FOM_ChatCommandHandler(msg);
end
-- hook functions so we can manage per-pet saved food quality data
FOM_Original_PetRename = PetRename;
PetRename = FOM_PetRename;
FOM_Original_PetAbandon = PetAbandon;
PetAbandon = FOM_PetAbandon;
--GFWUtils.Debug = true;
GFWUtils.Print("Fizzwidget Feed-O-Matic "..FOM_VERSION.." initialized!");
end
function FOM_CheckSetup()
_, realClass = UnitClass("player");
if (realClass ~= "HUNTER") then return; end
if (FOM_RealmPlayer == nil) then
FOM_RealmPlayer = GetCVar("realmName") .. "." .. UnitName("player");
end
local currentPetName = UnitName("pet");
if (currentPetName and currentPetName ~= "" and currentPetName ~= UNKNOWNOBJECT) then
FOM_LastPetName = currentPetName;
end
if (FOM_FoodQuality == nil) then
FOM_FoodQuality = { };
end
if (FOM_FoodQuality[FOM_RealmPlayer] == nil) then
FOM_FoodQuality[FOM_RealmPlayer] = { };
end
if (FOM_LastPetName) then
if (FOM_FoodQuality[FOM_RealmPlayer][FOM_LastPetName] == nil) then
FOM_FoodQuality[FOM_RealmPlayer][FOM_LastPetName] = { };
end
end
end
function FOM_Tooltip(frame, name, link, source)
if (FOM_Config.Tooltip and name ~= nil and UnitExists("pet")) then
FOM_CheckSetup();
local itemID = FOM_IDFromLink(link);
if (not FOM_IsInDiet(itemID)) then
return false;
end
local color;
local absoluteQuality = FOM_FoodQuality[FOM_RealmPlayer][FOM_LastPetName][itemID];
if (absoluteQuality == nil) then
color = HIGHLIGHT_FONT_COLOR;
frame:AddLine(string.format(FOM_QUALITY_UNKNOWN, FOM_LastPetName), color.r, color.g, color.b);
return true;
else
local currentQuality = absoluteQuality / UnitLevel("pet");
if (currentQuality < 0) then
color = QuestDifficultyColor["trivial"];
frame:AddLine(string.format(FOM_QUALITY_UNDER, FOM_LastPetName), color.r, color.g, color.b);
return true;
elseif (currentQuality == 0) then
color = QuestDifficultyColor["trivial"];
frame:AddLine(string.format(FOM_QUALITY_MIGHT, FOM_LastPetName), color.r, color.g, color.b);
return true;
elseif (currentQuality <= 8) then
color = QuestDifficultyColor["standard"];
frame:AddLine(string.format(FOM_QUALITY_WILL, FOM_LastPetName), color.r, color.g, color.b);
return true;
elseif (currentQuality <= 17) then
color = QuestDifficultyColor["difficult"];
frame:AddLine(string.format(FOM_QUALITY_LIKE, FOM_LastPetName), color.r, color.g, color.b);
return true;
elseif (currentQuality <= 35) then
color = QuestDifficultyColor["verydifficult"];
frame:AddLine(string.format(FOM_QUALITY_LOVE, FOM_LastPetName), color.r, color.g, color.b);
return true;
else
GFWUtils.DebugLog("Unexpected food quality level "..currentQuality);
return false;
end
end
end
end
function FOM_OnEvent(event, arg1)
-- Save Variables
if ( event == "VARIABLES_LOADED" ) then
_, realClass = UnitClass("player");
if (realClass == "HUNTER") then
-- monitor status for whether we're able to feed
this:RegisterEvent("PET_ATTACK_START");
this:RegisterEvent("PET_ATTACK_STOP");
-- this:RegisterEvent("CHAT_MSG_SYSTEM");
-- check your pet roster when at the stables so we don't bloat SavedVariables
this:RegisterEvent("PET_STABLE_SHOW");
this:RegisterEvent("PET_STABLE_UPDATE");
-- track whether foods are useful for Cooking
this:RegisterEvent("TRADE_SKILL_SHOW");
this:RegisterEvent("TRADE_SKILL_UPDATE");
-- figure out what happens when we try to feed pet (gain happiness, didn't like, etc)
this:RegisterEvent("CHAT_MSG_SPELL_TRADESKILLS");
this:RegisterEvent("CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS");
this:RegisterEvent("UI_ERROR_MESSAGE");
-- Events for trying to catch when the pet needs feeding
this:RegisterEvent("PET_BAR_SHOWGRID");
this:RegisterEvent("PET_BAR_UPDATE");
this:RegisterEvent("PET_UI_UPDATE");
this:RegisterEvent("UNIT_HAPPINESS");
this:RegisterEvent("PLAYER_REGEN_ENABLED");
FOM_FeedButton = CreateFrame("Button", "FOM_FeedButton", PetFrameHappiness);
FOM_FeedButton:SetAllPoints(PetFrameHappiness);
FOM_FeedButton:RegisterForClicks("LeftButtonUp", "RightButtonUp");
FOM_FeedButton:SetScript("OnClick", FOM_FeedButton_OnClick);
FOM_FeedButton:SetScript("OnEnter", FOM_FeedButton_OnEnter);
FOM_FeedButton:SetScript("OnLeave", FOM_FeedButton_OnLeave);
table.insert(UISpecialFrames,"FOM_OptionsFrame");
if (FOM_Config.Level == "happy") then
-- we've redefined the Level option and this setting is no loger available
FOM_Config.Level = "content";
end
if (FOM_Config.Tooltip) then
GFWTooltip_AddCallback("GFW_FeedOMatic", FOM_Tooltip);
end
end
return;
elseif ( event == "PET_ATTACK_START" ) then
-- Set Flag
FOM_State.InCombat = true;
return;
elseif ( event == "PET_ATTACK_STOP" ) then
-- Remove Flag
FOM_State.InCombat = false;
elseif ( event == "CHAT_MSG_SPELL_TRADESKILLS" ) then
if (FOM_FEEDPET_LOG_FIRSTPERSON == nil) then
FOM_FEEDPET_LOG_FIRSTPERSON = GFWUtils.FormatToPattern(FEEDPET_LOG_FIRSTPERSON);
end
_, _, foodName = string.find(arg1, FOM_FEEDPET_LOG_FIRSTPERSON);
if (foodName and foodName ~= "") then
local foodID = GFWTable.KeyOf(FOM_FoodIDsToNames, foodName);
if (foodID == nil) then
local bag, slot = FOM_FindSpecificFood(foodName);
local foodLink = GetContainerItemLink(bag, slot);
foodID = FOM_IDFromLink(foodLink);
end
if (foodID) then
FOM_LastFood = GFWUtils.ItemLink(foodID);
GFWUtils.DebugLog("Manually fed "..FOM_LastFood);
end
end
return;
elseif ( event == "CHAT_MSG_SPELL_PERIODIC_SELF_BUFFS" ) then
if (arg1 and FOM_HasFeedEffect()) then
if (FOM_POWERGAIN_OTHER == nil and POWERGAINSELFOTHER) then
FOM_POWERGAIN_OTHER = GFWUtils.FormatToPattern(POWERGAINSELFOTHER);
end
if (FOM_POWERGAIN_OTHER == nil and POWERGAIN_OTHER) then
FOM_POWERGAIN_OTHER = GFWUtils.FormatToPattern(POWERGAIN_OTHER);
end
if (FOM_POWERGAIN_OTHER == nil) then
GFWUtils.PrintOnce(GFWUtils.Red("Feed-O-Matic Error: ").. "Can't find parse pattern for pet happiness.");
return;
end
_, _, name, amount, powerType = string.find(arg1, FOM_POWERGAIN_OTHER);
local happiness;
if (name == UnitName("pet") and powerType == HAPPINESS_POINTS) then
happiness = tonumber(amount);
else
return;
end
if (FOM_LastFood and happiness > 0) then
FOM_CheckSetup();
local itemID = FOM_IDFromLink(FOM_LastFood);
local knownQuality = FOM_FoodQuality[FOM_RealmPlayer][FOM_LastPetName][itemID];
local quality = happiness * UnitLevel("pet");
FOM_FoodQuality[FOM_RealmPlayer][FOM_LastPetName][itemID] = math.max((knownQuality or 0), quality);
FOM_LastFood = nil;
end
end
return;
elseif ( event == "UI_ERROR_MESSAGE" ) then
if (arg1 and string.find(arg1, SPELL_FAILED_FOOD_LOWLEVEL)) then
FOM_CheckSetup();
if not (FOM_LastFood == nil) then
local itemID = FOM_IDFromLink(FOM_LastFood);
FOM_FoodQuality[FOM_RealmPlayer][FOM_LastPetName][itemID] = -1;
FOM_LastFood = nil;
if ( FOM_Config.Alert == "chat") then
GFWUtils.Print(string.format(FOM_FEEDING_EAT_ANOTHER, UnitName("pet")));
elseif ( FOM_Config.Alert == "emote") then
SendChatMessage(string.format(FOM_FEEDING_FEED_ANOTHER, UnitName("pet")), "EMOTE");
end
return;
end
elseif (arg1 and string.find(arg1, SPELL_FAILED_WRONG_PET_FOOD)) then
FOM_CheckSetup();
if (FOM_LastFood) then
if ( FOM_Config.Alert == "chat") then
GFWUtils.Print(string.format(FOM_FEEDING_EAT_ANOTHER, UnitName("pet")));
elseif ( FOM_Config.Alert == "emote") then
SendChatMessage(string.format(FOM_FEEDING_FEED_ANOTHER, UnitName("pet")), "EMOTE");
end
-- remove from quality tracking
local itemID = FOM_IDFromLink(FOM_LastFood);
FOM_FoodQuality[FOM_RealmPlayer][FOM_LastPetName][itemID] = nil;
-- remove from diet
local dietList = {GetPetFoodTypes()};
for _, diet in dietList do
if ( FOM_RemoveFood(string.lower(diet), itemID) ) then
local capDiet = string.upper(string.sub(diet, 1, 1)) .. string.sub(diet, 2); -- print a nicely capitalized version
GFWUtils.Print("Removed "..FOM_LastFood.." from "..GFWUtils.Hilite(capDiet).." list.");
end
end
FOM_LastFood = nil;
return;
end
end
return;
elseif (event == "TRADE_SKILL_SHOW" or event == "TRADE_SKILL_UPDATE") then
if (GetTradeSkillLine() ~= nil and GetTradeSkillLine() == FOM_CookingSpellName()) then
if (FOM_Config.SaveForCookingLevel >= 0 and FOM_Config.SaveForCookingLevel <= 3) then
-- Update Cooking reagents list so we can avoid consuming food we could skillup from.
if (FOM_RealmPlayer == nil) then
FOM_RealmPlayer = GetCVar("realmName") .. "." .. UnitName("player");
end
if (FOM_Cooking == nil) then
FOM_Cooking = { };
end
if (FOM_Cooking[FOM_RealmPlayer] == nil) then
FOM_Cooking[FOM_RealmPlayer] = { };
end
if (FOM_Cooking ~= nil and FOM_Cooking[FOM_RealmPlayer] ~= nil and TradeSkillFrame and TradeSkillFrame:IsVisible() and not FOM_TradeSkillLock.Locked) then
-- This prevents further update events from being handled if we're already processing one.
-- This is done to prevent the game from freezing under certain conditions.
FOM_TradeSkillLock.Locked = true;
for i=1, GetNumTradeSkills() do
local itemName, type, _, _ = GetTradeSkillInfo(i);
if (type ~= "header") then
for j=1, GetTradeSkillNumReagents(i) do
local reagentLink = GetTradeSkillReagentItemLink(i, j);
local itemID = FOM_IDFromLink(reagentLink);
if (itemID and FOM_IsKnownFood(itemID)) then
if (FOM_Cooking[FOM_RealmPlayer][itemID] == nil) then
FOM_Cooking[FOM_RealmPlayer][itemID] = FOM_DifficultyToNum(type);
else
FOM_Cooking[FOM_RealmPlayer][itemID] = max(FOM_Cooking[FOM_RealmPlayer][itemID], FOM_DifficultyToNum(type));
end
end
end
end
end
end
end
end
return;
elseif (event == "PET_STABLE_SHOW" or event == "PET_STABLE_UPDATE") then
-- clean up the FOM_FoodQuality sub-tables in case we missed you abandoning a pet
FOM_CheckSetup();
local stabledPetNames = {};
for petIndex = 0, 2 do
local _, petName, _, _, _ = GetStablePetInfo(petIndex);
if (petName) then
table.insert(stabledPetNames, petName);
end
end
local orphanedPetNames = {};
for savedPetName in FOM_FoodQuality[FOM_RealmPlayer] do
if (stabledPetNames == nil) then
GFWUtils.DebugLog("stabledPetNames == nil");
end
if (stabledPetNames ~= nil and GFWTable.IndexOf(stabledPetNames, savedPetName) == 0) then
table.insert(orphanedPetNames, savedPetName);
end
end
for _, orphanedPet in orphanedPetNames do
FOM_FoodQuality[FOM_RealmPlayer][orphanedPet] = nil;
end
return;
elseif (FOM_Config.Level) then
FOM_CheckHappiness();
end
end
-- Update our list of quest objectives so we can avoid consuming food we want to accumulate for a quest.
function FOM_ScanQuests()
FOM_QuestFood = nil;
for questNum=1, GetNumQuestLogEntries() do
local QText, level, questTag, isHeader, isCollapsed, isComplete = GetQuestLogTitle(questNum);
if (not isHeader) then
for objectiveNum=1, GetNumQuestLeaderBoards(questNum) do
local text, type, finished = GetQuestLogLeaderBoard(objectiveNum, questNum);
if (text ~= nil and strlen(text) > 0) then
local _, _, objectiveName, numCurrent, numRequired = string.find(text, "(.*): (%d+)/(%d+)");
if (FOM_IsKnownFood(objectiveName)) then
if (FOM_QuestFood == nil) then
FOM_QuestFood = { };
end
if (FOM_QuestFood[FOM_RealmPlayer] == nil) then
FOM_QuestFood[FOM_RealmPlayer] = { };
end
if (FOM_QuestFood[FOM_RealmPlayer][objectiveName] == nil) then
FOM_QuestFood[FOM_RealmPlayer][objectiveName] = tonumber(numRequired);
else
FOM_QuestFood[FOM_RealmPlayer][objectiveName] = max(FOM_QuestFood[FOM_RealmPlayer][objectiveName], tonumber(numRequired));
end
end
end
end
end
end
end
function FOM_DifficultyToNum(level)
if (level == "optimal" or level == "orange") then
return 3;
elseif (level == "medium" or level == "yellow") then
return 2;
elseif (level == "easy" or level == "green") then
return 1;
elseif (level == "trivial" or level == "gray" or level == "grey") then
return 1;
else -- bad input
return nil;
end
end
function FOM_OnUpdate(elapsed)
_, realClass = UnitClass("player");
if (realClass ~= "HUNTER") then return; end
-- If it's been more than a second since our last tradeskill update,
-- we can allow the event to process again.
FOM_TradeSkillLock.EventTimer = FOM_TradeSkillLock.EventTimer + elapsed;
if (FOM_TradeSkillLock.Locked) then
FOM_TradeSkillLock.EventCooldown = FOM_TradeSkillLock.EventCooldown + elapsed;
if (FOM_TradeSkillLock.EventCooldown > FOM_TradeSkillLock.EventCooldownTime) then
FOM_TradeSkillLock.EventCooldown = 0;
FOM_TradeSkillLock.Locked = false;
end
end
--GFWUtils.Debug = true;
if (FOM_State.ShouldFeed and FOM_Config.IconWarning and PetFrameHappiness) then
if (PetFrameHappiness:IsVisible() and PetFrameHappiness:GetAlpha() == 1) then
FOM_FadeOut();
end
end
end
function FOM_FadeOut()
local fadeInfo = {};
fadeInfo.mode = "OUT";
fadeInfo.timeToFade = 0.5;
fadeInfo.finishedFunc = FOM_FadeIn;
UIFrameFade(PetFrameHappiness, fadeInfo);
end
--hack since a frame can't have a reference to itself in it
function FOM_FadeIn()
UIFrameFadeIn(PetFrameHappiness, 0.5);
end
function FOM_CanFeed()
if ( not UnitExists("pet") ) then
GFWUtils.DebugLog("Can't feed; pet doesn't exist.");
return false;
end
if ( UnitHealth("pet") <= 0 ) then
GFWUtils.DebugLog("Can't feed; pet is dead.");
return false;
end
if ( UnitHealth("player") <= 0 ) then
GFWUtils.DebugLog("Can't feed; I'm dead.");
return false;
end
if ( CastingBarFrameStatusBar:IsVisible() ) then
GFWUtils.DebugLog("Can't feed; casting a spell / tradeksill.");
return false;
end
if ( UnitOnTaxi("player") ) then
GFWUtils.DebugLog("Can't feed; flying.");
return false;
end
if ( FOM_State.InCombat ) or ( PlayerFrame.inCombat ) then
GFWUtils.DebugLog("Can't feed; in combat.");
return false;
end
if ( LootFrame:IsVisible() ) then
GFWUtils.DebugLog("Shouldn't feed; loot window is open.");
return false;
end
local buff, buffIndex;
local dontFeedBuffTextures = {
"Interface\\Icons\\Ability_Ambush", -- NE Shadowmeld (maybe not unique buff icon?)
"Interface\\Icons\\Ability_Rogue_FeignDeath", -- Feign Death
"Interface\\Icons\\INV_Drink_07", -- drinking
"Interface\\Icons\\INV_Misc_Fork&Knife", -- eating
};
local mountTextureSubStrings = {
"Ability_Mount",
"INV_Misc_Foot_Kodo",
};
for buffIndex=0, 15 do
local buff = GetPlayerBuffTexture(buffIndex);
if ( buff ~= nil) then
for _, buffTexture in dontFeedBuffTextures do
if ( buff == buffTexture ) then
GFWUtils.DebugLog("Can't feed; currently, eating, drinking, or feigning death.");
return false;
end
end
if ( UnitLevel("player") >= 40 ) then
for _, buffTexture in mountTextureSubStrings do
if ( string.find(buff, buffTexture) ) then
FOMTooltip:SetUnitBuff("player", buffIndex+1);
local msg = FOMTooltipTextLeft1:GetText();
if (msg ~= nil) then
msg = string.lower(msg);
for _, mountName in FOM_MOUNT_NAME_SUBSTRINGS do
if (string.find(msg, mountName)) then
GFWUtils.DebugLog("Can't feed; mounted.");
return false;
end
end
end
end
end
end
end
end
return true;
end
function FOM_ChatCommandHandler(msg)
if ( msg == "" ) then
if FOM_OptionsFrame:IsVisible() then
HideUIPanel(FOM_OptionsFrame);
else
ShowUIPanel(FOM_OptionsFrame);
end
return;
end
-- Check for Pet (we don't really need one for most of our chat commands, but we conveniently use its name.)
if ( UnitExists("pet") ) then
petName = UnitName("pet");
if (GetLocale() ~= "enUS") then
if (FOM_LocaleInfo == nil) then
FOM_LocaleInfo = {};
end
FOM_LocaleInfo[UnitCreatureFamily("pet")] = {GetPetFoodTypes()};
end
else
petName = "Your pet";
end
-- Print Help
if ( msg == "help" ) or ( msg == "" ) then
GFWUtils.Print("Fizzwidget Feed-O-Matic "..FOM_VERSION..":");
GFWUtils.Print("/feedomatic /fom <command>");
GFWUtils.Print("- "..GFWUtils.Hilite("help").." - Print this helplist.");
GFWUtils.Print("- "..GFWUtils.Hilite("status").." - Check current settings.");
GFWUtils.Print("- "..GFWUtils.Hilite("reset").." - Reset to default settings.");
GFWUtils.Print("- "..GFWUtils.Hilite("clear").." - Clearing saved variables about food. It Does NOT reset your settings."); --Monteo
GFWUtils.Print("- "..GFWUtils.Hilite("alert chat").." | "..GFWUtils.Hilite("emote").." | "..GFWUtils.Hilite("off").." - Alert via chat window or emote channel when feeding.");
GFWUtils.Print("- "..GFWUtils.Hilite("level content").." | "..GFWUtils.Hilite("happy").." | "..GFWUtils.Hilite("off").." - Provide an extra reminder to feed your pet when happiness is below this level.");
GFWUtils.Print("- "..GFWUtils.Hilite("saveforcook orange").." | "..GFWUtils.Hilite("yellow").." | "..GFWUtils.Hilite("green").." | "..GFWUtils.Hilite("gray").." | "..GFWUtils.Hilite("off").." - Avoid foods used in cooking recipes (based on their difficulty).");
GFWUtils.Print("- "..GFWUtils.Hilite("savequest on").." | "..GFWUtils.Hilite("off").." - Avoid foods you need to collect for a quest.");
GFWUtils.Print("- "..GFWUtils.Hilite("savebonus on").." | "..GFWUtils.Hilite("off").." - Avoid foods which have bonus effects.");
GFWUtils.Print("- "..GFWUtils.Hilite("fallback on").." | "..GFWUtils.Hilite("off").." - Fall back to foods we'd normally avoid if no other food is available.");
GFWUtils.Print("- "..GFWUtils.Hilite("keepopen <number>").." - Set when to prefer smaller stacks of food versus evaluating food based on quality. Specify "..GFWUtils.Hilite("off").." instead of a number to always select foods by quality, or "..GFWUtils.Hilite("max").." to always prefer smaller stacks.");
GFWUtils.Print("- "..GFWUtils.Hilite("quality high").." | "..GFWUtils.Hilite("low").." - Set whether to prefer foods that give your pet more happiness faster or less happiness more slowly.");
GFWUtils.Print("- "..GFWUtils.Hilite("tooltip on").." | "..GFWUtils.Hilite("off").." - Identifies and rates pet foods in their tooltips.");
GFWUtils.Print("- "..GFWUtils.Hilite("feed").." - Feed your pet (automatically finds an appropriate food).");
GFWUtils.Print("- "..GFWUtils.Hilite("feed <name>").." - Feed your pet a specific food.");
GFWUtils.Print("- "..GFWUtils.Hilite("add <diet> <name>").." - Add food to list.");
GFWUtils.Print("- "..GFWUtils.Hilite("remove <diet> <name>").." - Remove food from list.");
GFWUtils.Print("- "..GFWUtils.Hilite("show <diet>").." - Show food list.");
return;
end
if ( msg == "version" ) then
GFWUtils.Print("Fizzwidget Feed-O-Matic "..FOM_VERSION..":");
return;
end
-- Check Status
if ( msg == "status" ) then
if (FOM_Config.Level) then
GFWUtils.Print("Feed-O-Matic will help remind you to feed your pet when he's "..GFWUtils.Hilite(FOM_Config.Level)..".");
else
GFWUtils.Print("Feed-O-Matic will "..GFWUtils.Hilite("not").." help remind you when to feed your pet.");
end
if (FOM_Config.KeepOpenSlots < MAX_KEEPOPEN_SLOTS) then
if (FOM_Config.PreferHigherQuality) then
GFWUtils.Print("Feed-O-Matic will prefer to use higher quality foods first.");
else
GFWUtils.Print("Feed-O-Matic will prefer to use lower quality foods first.");
end
if (FOM_Config.KeepOpenSlots == 0) then
GFWUtils.Print("Feed-O-Matic will look first at food quality when determining what to feed to your pet.");
else
GFWUtils.Print("If fewer than "..GFWUtils.Hilite(FOM_Config.KeepOpenSlots).." spaces are open in your inventory, Feed-O-Matic will prefer smaller stacks of food regardless of quality.");
end
else
GFWUtils.Print("Feed-O-Matic will always prefer smaller stacks of food regardless of quality.");
end
if (FOM_Config.Alert == "emote") then
GFWUtils.Print("You will automatically emote when feeding "..petName..".");
elseif (FOM_Config.Alert == "chat") then
GFWUtils.Print("Feed-O-Matic will notify you in chat when feeding "..petName..".");
else
GFWUtils.Print("There will be no alert when feeding "..petName..".");
end
if (FOM_Config.SaveForCookingLevel >= 0 and FOM_Config.SaveForCookingLevel <= 3) then
if (FOM_Config.SaveForCookingLevel == 3) then
level = "orange";
elseif (FOM_Config.SaveForCookingLevel == 2) then
level = "yellow";
elseif (FOM_Config.SaveForCookingLevel == 1) then
level = "green";
elseif (FOM_Config.SaveForCookingLevel == 0) then
level = "gray";
end
GFWUtils.Print("Feed-O-Matic will avoid foods used in "..GFWUtils.Hilite(level).." or higher Cooking recipes.");
else
GFWUtils.Print("Feed-O-Matic will choose foods without regard to whether they're used in Cooking.");
end
if (FOM_Config.AvoidQuestFood) then
GFWUtils.Print("Feed-O-Matic will avoid foods you need to collect for quests.");
else
GFWUtils.Print("Feed-O-Matic will choose foods without regard to whether they're needed for quests.");
end
if (FOM_Config.AvoidBonusFood) then
GFWUtils.Print("Feed-O-Matic will avoid foods that have an additional bonus effect when eaten by a player.");
else
GFWUtils.Print("Feed-O-Matic will choose foods without regard to whether they have bonus effects.");
end
if (FOM_Config.Fallback) then
GFWUtils.Print("Feed-O-Matic will fall back to food it would otherwise avoid if no other food is available.");
else
GFWUtils.Print("Feed-O-Matic will not feed your pet if the only foods available are foods you'd prefer to avoid feeding.");
end
if (FOM_Config.Tooltip) then
GFWUtils.Print("Adding food quality information to tooltips for foods your current pet can eat.");
else
GFWUtils.Print("Not adding information to item tooltips.");
end
return;
end
-- Reset Variables
if ( msg == "reset" ) then
FOM_Config = FOM_Config_Default;
FOM_Cooking = nil;
FOM_FoodQuality = nil;
FOM_AddedFoods = nil;
FOM_RemovedFoods = nil;
FOM_QuestFood = nil;
GFWUtils.Print("Feed-O-Matic configuration reset.");
FOM_ChatCommandHandler("status");
return;
end
-- Cleaning of the data used by the food --Monteo
if ( msg == "clear" ) then
FOM_Cooking = nil;
FOM_FoodQuality = nil;
GFWUtils.Print("Feed-O-Matic data on food are cleared.");
return;
end
-- Turn automatic feeding On
if ( msg == "on" ) then
GFWUtils.Print("Automatic feeding is no longer available due to changes in the WoW client as of Patch 1.10.");
return;
end
local _, _, cmd, option = string.find(msg, "(%w+) (%w+)");
-- Toggle Alert
if ( cmd == "alert" ) then
if (option == "emote") then
FOM_Config.Alert = "emote";
GFWUtils.Print("You will automatically emote when feeding "..petName..".");
elseif (option == "chat") then
FOM_Config.Alert = "chat";
GFWUtils.Print("Feed-O-Matic will notify you in chat when feeding "..petName..".");
elseif (option == "off") then
FOM_Config.Alert = nil;
GFWUtils.Print("There will be no alert when feeding "..petName..".");
else
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic alert chat").." | "..GFWUtils.Hilite("emote").." | "..GFWUtils.Hilite("off"));
end
return;
end
-- Set Happiness Level
if ( cmd == "level" ) then
if ( option == "content" ) then
FOM_Config.Level = "content";
elseif ( option == "happy" ) then
FOM_Config.Level = "happy";
elseif ( option == "debug" ) then
FOM_Config.Level = "debug";
else
FOM_Config.Level = nil;
end
if (FOM_Config.Level) then
GFWUtils.Print("Feed-O-Matic will help remind you to feed your pet when he's less than "..GFWUtils.Hilite(FOM_Config.Level)..".");
FOM_CheckHappiness();
else
GFWUtils.Print("Feed-O-Matic will "..GFWUtils.Hilite("not").." help remind you when to feed your pet.");
FOM_Status.ShouldFeed = nil;
end
return;
end
-- Set Cooking recipe level
if ( cmd == "saveforcook" ) then
local level = option;
if (level ~= nil) then
local levelNum = FOM_DifficultyToNum(level);
if (levelNum ~= nil) then
FOM_Config.SaveForCookingLevel = levelNum;
FOM_Config.AvoidUsefulFood = true;
GFWUtils.Print("Feed-O-Matic will avoid foods used in "..GFWUtils.Hilite(level).." or higher Cooking recipes. You'll need to open your Cooking window for Feed-O-Matic to cache information about what recipes you know.");
return;
elseif (level == "off") then
FOM_Config.SaveForCookingLevel = 4;
if (not FOM_Config.AvoidQuestFood and not FOM_Config.Avoid9) then
FOM_Config.AvoidUsefulFood = false;
end
GFWUtils.Print("Feed-O-Matic will choose foods without regard to whether they're used in Cooking.");
return;
end
end
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic saveforcook orange").." | "..GFWUtils.Hilite("yellow").." | "..GFWUtils.Hilite("green").." | "..GFWUtils.Hilite("gray").." | "..GFWUtils.Hilite("off"));
return;
end
-- Set avoiding food with bonuses
if ( cmd == "savequest" ) then
if (option == "on") then
FOM_Config.AvoidQuestFood = true;
FOM_Config.AvoidUsefulFood = true;
FOM_ScanQuests();
GFWUtils.Print("Feed-O-Matic will avoid foods you need to collect for quests.");
elseif (option == "off") then
FOM_Config.AvoidQuestFood = true;
if not (FOM_Config.SaveForCookingLevel >= 0 and FOM_Config.SaveForCookingLevel <= 3 and not FOM_Config.AvoidBonusFood) then
FOM_Config.AvoidUsefulFood = false;
end
GFWUtils.Print("Feed-O-Matic will choose foods without regard to whether they're needed for quests.");
else
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic savequest on").." | "..GFWUtils.Hilite("off"));
end
return;
end
-- Set avoiding quest-objective food
if ( cmd == "savebonus" ) then
if (option == "on") then
FOM_Config.AvoidBonusFood = true;
FOM_Config.AvoidUsefulFood = true;
GFWUtils.Print("Feed-O-Matic will avoid foods that have an additional bonus effect when eaten by a player.");
elseif (option == "off") then
FOM_Config.AvoidBonusFood = true;
if not (FOM_Config.SaveForCookingLevel >= 0 and FOM_Config.SaveForCookingLevel <= 3 and not FOM_Config.AvoidQuestFood) then
FOM_Config.AvoidUsefulFood = false;
end
GFWUtils.Print("Feed-O-Matic will choose foods without regard to whether they have bonus effects.");
else
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic savebonus on").." | "..GFWUtils.Hilite("off"));
end
return;
end
if ( cmd == "fallback" ) then
if (option == "on") then
FOM_Config.Fallback = true;
GFWUtils.Print("Feed-O-Matic will fall back to food it would otherwise avoid if no other food is available.");
elseif (option == "off") then
FOM_Config.Fallback = false;
GFWUtils.Print("Feed-O-Matic will not feed your pet if the only foods available are foods you'd prefer to avoid feeding.");
else
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic fallback on").." | "..GFWUtils.Hilite("off"));
end
return;
end
if ( cmd == "tooltip" ) then
if (option == "on") then
FOM_Config.Tooltip = true;
GFWTooltip_AddCallback("GFW_FeedOMatic", FOM_Tooltip);
GFWUtils.Print("Adding food quality information to tooltips for foods your current pet can eat.");
elseif (option == "off") then
FOM_Config.Tooltip = false;
GFWUtils.Print("Not adding information to item tooltips.");
else
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic tooltip on").." | "..GFWUtils.Hilite("off"));
end
return;
end
-- Set quality sorting direction
if ( cmd == "quality" ) then
if (option == "high") then
FOM_Config.PreferHigherQuality = true;
GFWUtils.Print("Feed-O-Matic will prefer to use higher quality foods first.");
elseif (option == "low") then
FOM_Config.PreferHigherQuality = false;
GFWUtils.Print("Feed-O-Matic will prefer to use lower quality foods first.");
else
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic quality high").." | "..GFWUtils.Hilite("low"));
end
return;
end
-- Set inventory management threshold
if ( cmd == "keepopen" ) then
if (option == "off" or option == "none") then
newNum = 0;
elseif (option == "max") then
newNum = MAX_KEEPOPEN_SLOTS;
else
newNum = tonumber(option);
end
if (newNum == nil) then
GFWUtils.Print("Usage: "..GFWUtils.Hilite("/feedomatic keepopen <number>"));
return;
end
FOM_Config.KeepOpenSlots = newNum;
GFWUtils.Print("Feed-O-Matic will try to keep at least "..GFWUtils.Hilite(FOM_Config.KeepOpenSlots).." spaces open in your inventory when looking for food.");
return;
end
-- Feed Pet
local _, _, cmd, foodString = string.find(msg, "(%w+) *(.*)");
if ( cmd == "feed" ) then
if (foodString == "") then
FOM_Feed(nil); -- automatically find a food and feed it
else
local inputFoods = { };
for itemLink in string.gfind(foodString, "%[[%w%s:()\"'-]+%]") do
local _, _, foodName = string.find(itemLink, "^%[([%w%s:()\"'-]+)%]$");
table.insert(inputFoods, foodName);
end
if (table.getn(inputFoods) == 0) then
table.insert(inputFoods, foodString); -- if no item links, treat whole input line as one food's name
end
for _, food in inputFoods do
FOM_Feed(food);
end
end
return;
end
local _, _, cmd, diet, foodString = string.find(msg, "(%w+) (%w+) *(.*)");
if ( cmd == "add" or cmd == "remove" or cmd == "show" or cmd == "list" ) then
diet = string.lower(diet); -- let's be case insensitive
if ( FOM_Foods[diet] == nil and diet ~= FOM_DIET_ALL) then
local usageString = "Usage: "..GFWUtils.Hilite("/feedomatic "..cmd..FOM_DIET_MEAT).." | "..GFWUtils.Hilite(FOM_DIET_FISH).." | "..GFWUtils.Hilite(FOM_DIET_BREAD).." | "..GFWUtils.Hilite(FOM_DIET_CHEESE).." | "..GFWUtils.Hilite(FOM_DIET_FRUIT).." | "..GFWUtils.Hilite(FOM_DIET_FUNGUS).." | "..GFWUtils.Hilite(FOM_DIET_BONUS)
if (cmd ~= "show" and cmd ~= "list") then
usageString = usageString.." <item link>.";
end
GFWUtils.Print(usageString);
return;
end
if (cmd == "show" or cmd == "list") then
if ( diet == FOM_DIET_ALL ) then
diets = {FOM_DIET_MEAT, FOM_DIET_FISH, FOM_DIET_BREAD, FOM_DIET_CHEESE, FOM_DIET_FRUIT, FOM_DIET_FUNGUS, FOM_DIET_BONUS};
else
diets = {diet};
end
for _, aDiet in diets do
local capDiet = string.upper(string.sub(aDiet, 1, 1)) .. string.sub(aDiet, 2); -- print a nicely capitalized version
GFWUtils.Print("Feed-O-Matic "..GFWUtils.Hilite(capDiet).." List:");
local dietFoods = FOM_Foods[aDiet];
if (FOM_AddedFoods ~= nil and FOM_AddedFoods[aDiet] ~= nil) then
dietFoods = GFWTable.Merge(dietFoods, FOM_AddedFoods[aDiet]);
end
if (FOM_RemovedFoods ~= nil and FOM_RemovedFoods[aDiet] ~= nil) then
dietFoods = GFWTable.Subtract(dietFoods, FOM_RemovedFoods[aDiet]);
end
table.sort(dietFoods);
for _, food in dietFoods do
local foodName = GetItemInfo(food);
if (foodName) then
if (FOM_FoodIDsToNames == nil) then
FOM_FoodIDsToNames = {};
end
FOM_FoodIDsToNames[food] = foodName;
GFWUtils.Print(GFWUtils.Hilite(" - ")..foodName);
else
GFWUtils.Print(GFWUtils.Hilite(" - ").."item id "..food.." (name not available)");
end
end
end
return;
else
local inputFoods = { };
for itemLink in string.gfind(foodString, "|c%x+|Hitem:%d+:%d+:%d+:%d+|h%[.-%]|h|r") do
table.insert(inputFoods, itemLink);
local foodID = FOM_IDFromLink(itemLink);
if (foodID) then
local foodName = FOM_NameFromLink(itemLink);
if (FOM_FoodIDsToNames == nil) then
FOM_FoodIDsToNames = {};
end
FOM_FoodIDsToNames[foodID] = foodName;
end
end
if (table.getn(inputFoods) == 0) then
GFWUtils.Print("The "..GFWUtils.Hilite("/fom "..cmd).." command requires an item link; shift-click an item to insert a link.");
return;
end
local capDiet = string.upper(string.sub(diet, 1, 1)) .. string.sub(diet, 2); -- print a nicely capitalized version
if ( cmd == "add" ) then
for _, food in inputFoods do
local foodID = FOM_IDFromLink(food);
if ( FOM_AddFood(diet, tonumber(foodID)) ) then
GFWUtils.Print("Added "..food.." to "..GFWUtils.Hilite(capDiet).." list.");
else