-
Notifications
You must be signed in to change notification settings - Fork 0
/
Core.lua
435 lines (388 loc) · 15 KB
/
Core.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
TCM = LibStub("AceAddon-3.0"):NewAddon("TCM", "AceConsole-3.0", "AceComm-3.0", "AceSerializer-3.0");
local AceGUI = LibStub("AceGUI-3.0");
TCM.Channel = "RAID";
TCM.GroupType = "raid";
function TCM:OnInitialize()
TCM:InitDB();
TCM:RegisterChatCommand("tcm", "SlashCmds");
TCM:InitComms();
TCM:InitButton();
end
function TCM:OnEnable()
end
function TCM:OnDisable()
end
function TCM:InitButton()
TCM.BtnFrame = CreateFrame("Frame", "BtnFrame", UIParent);
TCM.BtnFrame:SetMovable(true);
TCM.BtnFrame:EnableMouse(true);
TCM.BtnFrame:SetPoint("CENTER");
TCM.BtnFrame:SetWidth(80);
TCM.BtnFrame:SetHeight(100);
TCM.BtnFrame:SetBackdrop(StaticPopup1:GetBackdrop());
TCM.BtnFrame:RegisterForDrag("LeftButton");
TCM.BtnFrame:SetScript("OnDragStart", TCM.BtnFrame.StartMoving);
TCM.BtnFrame:SetScript("OnDragStop", TCM.BtnFrame.StopMovingOrSizing);
TCM.BtnFrame:SetScript("OnUpdate", function()
TCM.BtnFrame:SetSize(80, (TCM.BtnFrame:GetNumChildren()*25)+25);
end);
local BeginBtn = CreateFrame("Button", "BeginBtn", TCM.BtnFrame, "UIPanelButtonTemplate");
BeginBtn:SetWidth(50);
BeginBtn:SetHeight(25);
BeginBtn:SetPoint("BOTTOM", TCM.BtnFrame, 0, 38);
BeginBtn:SetMovable(true);
BeginBtn:SetText("begin");
BeginBtn:RegisterForClicks("AnyUp");
BeginBtn:SetScript("OnClick", function()
TCM:BeginCmd();
end);
local NextBtn = CreateFrame("Button", "NextBtn", TCM.BtnFrame, "UIPanelButtonTemplate");
NextBtn:SetSize(50, 25);
NextBtn:SetPoint("BOTTOM", TCM.BtnFrame, 0, 13);
NextBtn:SetMovable(true);
NextBtn:SetText("next");
NextBtn:RegisterForClicks("AnyUp");
NextBtn:SetScript("OnClick", function()
if (UnitIsGroupLeader("player")) then
TCM:Print("Next button not ready yet");
end
end);
TCM.BtnFrame:Hide();
end
-- UI functions --
function TCM:TestingUI()
for k in pairs(TCM.FriendFrame.StatusBars) do
TCM:Print(k .. " = " .. TCM.FriendFrame.StatusBars[k]);
end
for k in pairs(TCM.BadGuyFrame.StatusBars) do
TCM:Print(k .. " = " .. TCM.BadGuyFrame.StatusBars[k])
end
end
function TCM:LoadFriendUI()
if not TCM.FriendFrame then
TCM.FriendFrame = CreateFrame("Frame", "FriendFrame", UIParent);
end
TCM.FriendFrame:SetMovable(true);
TCM.FriendFrame:SetResizable(true);
TCM.FriendFrame:EnableMouse(true);
TCM.FriendFrame:SetPoint("CENTER");
TCM.FriendFrame:SetHeight(10);
TCM.FriendFrame:SetWidth(125);
TCM.FriendFrame:SetBackdrop(StaticPopup1:GetBackdrop());
TCM.FriendFrame:RegisterForDrag("LeftButton");
TCM.FriendFrame:SetScript("OnDragStart", TCM.FriendFrame.StartMoving);
TCM.FriendFrame:SetScript("OnDragStop", TCM.FriendFrame.StopMovingOrSizing);
TCM.FriendFrame:SetScript("OnUpdate", function()
TCM.FriendFrame:SetSize(125, ((TCM.FriendFrame:GetNumChildren()) * 25)+ 25);
end);
TCM.FriendFrame.StatusBars = {};
end
function TCM:LoadBadGuysUI()
local width = 150;
if not TCM.BadGuyFrame then
TCM.BadGuyFrame = CreateFrame("Frame", "BadGuyFrame", UIParent);
end
TCM.BadGuyFrame:SetMovable(true);
TCM.BadGuyFrame:SetResizable(true);
TCM.BadGuyFrame:EnableMouse(true);
TCM.BadGuyFrame:SetPoint("CENTER");
TCM.BadGuyFrame:SetHeight(25);
TCM.BadGuyFrame:SetWidth(width);
TCM.BadGuyFrame:SetBackdrop(StaticPopup1:GetBackdrop());
TCM.BadGuyFrame:RegisterForDrag("LeftButton");
TCM.BadGuyFrame:SetScript("OnDragStart", TCM.BadGuyFrame.StartMoving);
TCM.BadGuyFrame:SetScript("OnDragStop", TCM.BadGuyFrame.StopMovingOrSizing);
TCM.BadGuyFrame:SetScript("OnUpdate", function()
TCM.BadGuyFrame:SetSize(150, ((TCM.BadGuyFrame:GetNumChildren() / 2) * 25) + 38);
end);
local AttackBtn = CreateFrame("Button", "AttackBtn", TCM.BadGuyFrame, "UIPanelButtonTemplate");
AttackBtn:SetSize(125, 25);
AttackBtn:SetPoint("BOTTOM", TCM.BadGuyFrame, 0, 12);
AttackBtn:SetMovable(true);
AttackBtn:SetText("attack");
AttackBtn:RegisterForClicks("AnyUp");
AttackBtn:SetScript("OnClick", function()
if not UnitName("target") then
TCM:Print("No target found");
else
TCM:AttackCmd(UnitName("target"));
end
end);
TCM.BadGuyFrame.StatusBars = {};
TCM.BadGuyFrame.CheckButtons = {};
end
function TCM:LoadUI(number)
if IsInGroup() then
TCM:LoadFriendUI();
TCM:LoadBadGuysUI();
if IsInRaid() then
TCM.Channel = "RAID";
TCM.PartyType = "raid";
for i=1, GetNumGroupMembers() do
local name = GetUnitName(TCM.GroupType .. i);
TCM:AddPlayerBar(name);
end
else
TCM.Channel = "PARTY";
TCM.GroupType = "party";
TCM:AddPlayerBar(GetUnitName("player"));
for i=1, GetNumGroupMembers()-1 do
local name = GetUnitName(TCM.GroupType .. i);
TCM:AddPlayerBar(name);
end
end
for i=1, number do
TCM:AddBadGuyBar(i);
end
else
TCM:Print("Not in group");
end
end
function TCM:AddPlayerBar(name)
TCM.FriendFrame.StatusBars[name] = CreateFrame("StatusBar", name, TCM.FriendFrame);
TCM.FriendFrame.StatusBars[name]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar");
TCM.FriendFrame.StatusBars[name]:GetStatusBarTexture():SetHorizTile(false);
TCM.FriendFrame.StatusBars[name]:SetMinMaxValues(0, 6);
TCM.FriendFrame.StatusBars[name]:SetWidth(100);
TCM.FriendFrame.StatusBars[name]:SetHeight(25);
TCM.FriendFrame.StatusBars[name]:SetPoint("TOP", TCM.FriendFrame, 0, -((TCM:tablelength(TCM.FriendFrame.StatusBars)-1) * 25)-13);
TCM.FriendFrame.StatusBars[name]:SetStatusBarColor(0,1,0);
TCM.FriendFrame.StatusBars[name].text = TCM.FriendFrame.StatusBars[name]:CreateFontString(name, "OVERLAY", "GameFontNormal");
TCM.FriendFrame.StatusBars[name].text:SetAllPoints();
TCM.FriendFrame.StatusBars[name].text:SetText(name);
TCM.FriendFrame.StatusBars[name].text:SetPoint("LEFT");
end
function TCM:AddBadGuyBar(number)
local index = "BadGuy" .. number;
TCM.BadGuyFrame.StatusBars[index] = CreateFrame("StatusBar", index, TCM.BadGuyFrame);
TCM.BadGuyFrame.StatusBars[index]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar");
TCM.BadGuyFrame.StatusBars[index]:GetStatusBarTexture():SetHorizTile(false);
TCM.BadGuyFrame.StatusBars[index]:SetMinMaxValues(0, 4);
TCM.BadGuyFrame.StatusBars[index]:SetWidth(100);
TCM.BadGuyFrame.StatusBars[index]:SetHeight(25);
TCM.BadGuyFrame.StatusBars[index]:SetPoint("BOTTOMLEFT", TCM.BadGuyFrame, 15, (TCM:tablelength(TCM.BadGuyFrame.StatusBars) * 25) + 13);
TCM.BadGuyFrame.StatusBars[index]:SetStatusBarColor(1,0,0);
TCM.BadGuyFrame.StatusBars[index].text = TCM.BadGuyFrame.StatusBars[index]:CreateFontString(index, "OVERLAY", "GameFontNormal");
TCM.BadGuyFrame.StatusBars[index].text:SetAllPoints();
TCM.BadGuyFrame.StatusBars[index].text:SetText(index);
TCM.BadGuyFrame.StatusBars[index].text:SetPoint("LEFT");
TCM.BadGuyFrame.CheckButtons[index] = CreateFrame("CheckButton", index, TCM.BadGuyFrame, "UICheckButtonTemplate");
TCM.BadGuyFrame.CheckButtons[index]:SetSize(25, 25);
TCM.BadGuyFrame.CheckButtons[index]:SetPoint("BOTTOMLEFT", TCM.BadGuyFrame, 115, TCM:tablelength(TCM.BadGuyFrame.StatusBars) * TCM.BadGuyFrame.StatusBars[index]:GetHeight() + 13);
TCM.BadGuyFrame.CheckButtons[index]:SetScript("PreClick", function()
for k in pairs(TCM.BadGuyFrame.CheckButtons) do
TCM.BadGuyFrame.CheckButtons[k]:SetChecked(false);
end
end);
end
function TCM:UpdateUI()
if TCM.BadGuyFrame then
if TCM.BadGuyFrame.StatusBars then
for key, values in pairs(TCM.BadGuyFrame.StatusBars) do
TCM:Print(key);
end
end
end
if TCM.FriendFrame then
if TCM.FriendFrame.StatusBars then
for key, values in pairs(TCM.FriendFrame.StatusBars) do
TCM:Print(key);
end
end
end
end
function TCM:ConfgUI()
-- Config Frame --
TCM.ConfigScreen = AceGUI:Create("Frame");
TCM.ConfigScreen:SetCallback("OnClose",function(widget)
AceGUI:Release(widget);
end);
TCM.ConfigScreen:SetTitle("Event Config");
TCM.ConfigScreen:SetLayout("List");
-- Label for number of enemies --
TCM.ConfigScreen.NumEnemyLabel = AceGUI:Create("Label");
TCM.ConfigScreen.NumEnemyLabel:SetText("Number of enemies");
TCM.ConfigScreen:AddChild(TCM.ConfigScreen.NumEnemyLabel);
-- EditBox for number of enemies --
TCM.ConfigScreen.EnemyNumEditBox = AceGUI:Create("EditBox");
TCM.ConfigScreen:AddChild(TCM.ConfigScreen.EnemyNumEditBox);
-- Submit button --
TCM.ConfigScreen.SubmitBtn = AceGUI:Create("Button");
TCM.ConfigScreen.SubmitBtn:SetText("Apply");
TCM.ConfigScreen.SubmitBtn:SetCallback("OnClick", function(widget)
--TCM:Print("Num enemies: " .. TCM.ConfigScreen.EnemyNumEditBox:GetText());
local number = tonumber(TCM.ConfigScreen.EnemyNumEditBox:GetText());
TCM:LoadUI(number);
TCM:SendCommMessage("begin", tostring(number), TCM.Channel);
end);
TCM.ConfigScreen:AddChild(TCM.ConfigScreen.SubmitBtn);
end
-- init functions --
function TCM:InitDB()
if self.db then
TCM:Print("DB already exists");
else
self.db = LibStub("AceDB-3.0"):New("TruesightsCombatModifierDB");
end
end
function TCM:InitComms()
TCM:RegisterComm("attack", "HandleAttackFunc");
TCM:RegisterComm("heal", "HandleHealFunc");
TCM:RegisterComm("begin", "HandleBeginFunc");
end
function TCM:InitBadGuys(number)
self.db.char.BadGuys = {};
for i=0,number do
self.db.char.BadGuys[i] = {};
self.db.char.BadGuys[i].health = 4;
end
end
--Comm handlers --
function TCM:HandleHealFunc(prefix, message, distribution, sender)
-- TCM:heal(tonumber(message));
TCM:MessageReceived(prefix, message, distribution, sender);
end
function TCM:HandleAttackFunc(prefix, message, distribution, sender)
if sender == UnitName("player") then
TCM:Print("Attack from you received");
else
local success, from, damage, target = TCM:Deserialize(message);
TCM:Print(success);
if not success then
TCM:Print("Something happened when Deserializing")
else
if target == UnitName("player") then
TCM:Print(from .. " hit " .. target .. " for " .. damage .. " points of damage you are now at " .. self.db.char.Character.health);
SendChatMessage(from .. " hit you for " .. damage .. " points of damage you are now at " .. self.db.char.Character.health, TCM.Channel);
TCM:TakeDamage(tonumber(damage));
end
end
end
end
function TCM:HandleBeginFunc(prefix, message, distribution, sender)
TCM:MessageReceived(prefix, message, distribution, sender);
local player = tostring(GetUnitName("player"));
if sender == player then
TCM:Print("Your message got sent to you");
else
TCM:begin();
TCM:LoadUI(tonumber(message));
end
end
function TCM:MessageReceived(prefix, message, distribution, sender)
SendChatMessage("'" .. message .. "' recieved from '" .. sender .. "' via " .. distribution .. " prefixed with " .. prefix, TCM.Channel);
-- TCM:Print("'" .. message .. "' recieved from '" .. sender .. "' via " .. distribution .. " prefixed with " .. prefix);
end
-- combat actions --
function TCM:begin()
self.db.char.Character = {};
self.db.char.Character.maxhealth = 6;
self.db.char.Character.health = 6;
self.db.char.Character.heal = 20;
self.db.char.Character.attack = 20;
end
function TCM:TakeDamage(amount)
if(self.db.char.Character.health - amount <=0) then
self.db.char.Character.health = 0;
else
self.db.char.Character.health = self.db.char.Character.health - amount;
end
end
function TCM:Attack(target)
local attack = math.random(self.db.char.Character.attack);
if attack <= 2 then
TCM:Print("Epic Fail. AKA, Take 2 damage from " .. target);
TCM:TakeDamage(2);
return 0;
elseif attack <= 7 then
TCM:Print("Fail. Take 1 damage from " .. target);
TCM:TakeDamage(1);
return 0;
elseif attack <= 11 then
TCM:Print("WHIFF! You dodged " .. target .. "'s incoming attack!");
return 0;
elseif attack <= 14 then
TCM:Print("-small whack- .5 damage to " .. target);
return 0.5;
elseif attack <= 17 then
TCM:Print("-WHACK- Hit that enemy! 1 damage to " .. target);
return 1;
elseif attack <= 19 then
TCM:Print("-CRIT- A critical strike! 2 damage to " .. target);
return 2;
elseif attack == 20 then
TCM:Print("-SUPA CRIT- 4 damage to " .. target);
return 4;
else
TCM:Print("Something odd happened and you roll > 20 or < 1");
return 0;
end
end
function TCM:heal(heal)
if(self.db.char.Character.health + heal >= self.db.char.Character.maxhealth)then
self.db.char.Character.health = self.db.char.Character.maxhealth;
else
self.db.char.Character.health = self.db.char.Character.health + heal;
end
TCM:UpdateUI();
end
-- slash command handlers --
function TCM:BeginCmd()
TCM:begin();
if (UnitIsGroupLeader("player")) then
TCM:ConfgUI();
else
TCM:Print("You aren't the leader");
end
end
function TCM:HealCmd(target)
if self.db.char.Character.health then
local heal = math.random(self.db.char.Character.heal);
TCM:heal(heal);
TCM:Print("Heal: " .. heal);
TCM:Print("Healh: " .. self.db.char.Character.health);
TCM:SendCommMessage("heal", tostring(heal), "WHISPER", target);
else
TCM:Print("use must start a battle with /tcm begin first");
end
end
function TCM:AttackCmd(target)
if self.db.char.Character.health then
local player = UnitName("player");
local damage = TCM:Attack(target);
local targetPlayer = target;
if damage > 0 then
local data = TCM:Serialize(player, damage, targetPlayer);
TCM:SendCommMessage("attack", data, TCM.Channel);
end
else
TCM:Print("use must start a battle with /tcm begin first");
end
end
function TCM:SlashCmds(input)
if(input == "attack")then
TCM:AttackCmd(UnitName("target"));
elseif(input == "heal")then
TCM:HealCmd(UnitName("target"));
elseif(input == "begin")then
TCM:BeginCmd();
elseif(input == "health")then
SendChatMessage("Health: " .. self.db.char.Character.health, TCM.Channel);
elseif(input == "test")then
TCM:TestingUI();
else
if(TCM.BtnFrame:IsShown())then
TCM.BtnFrame:Hide();
else
TCM.BtnFrame:Show();
end
end
end
-- Utility Functions --
function TCM:tablelength(T)
local count = 0
for _ in pairs(T) do
count = count + 1
end
return count
end