391 lines
11 KiB
ObjectPascal
391 lines
11 KiB
ObjectPascal
unit fEvents;
|
|
|
|
interface
|
|
|
|
uses
|
|
System.SysUtils, System.Types, System.UITypes, System.Classes,
|
|
System.Variants, System.Generics.Collections, ShellAPI, uSoundManager,
|
|
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
|
|
FMX.Edit, FMX.ListBox, FMX.Controls.Presentation, System.Rtti, FMX.Grid.Style,
|
|
FMX.ScrollBox, FMX.Grid, uRecords, uDataBase, FMX.Menus, uKeyEvent;
|
|
|
|
type
|
|
TfrEvents = class(TFrame)
|
|
Label1: TLabel;
|
|
cbEventList: TComboBox;
|
|
edtIF: TEdit;
|
|
Label2: TLabel;
|
|
Label3: TLabel;
|
|
cbActions: TComboBox;
|
|
cbRevards: TComboBox;
|
|
sgEvents: TStringGrid;
|
|
Label4: TLabel;
|
|
edtParams: TEdit;
|
|
StringColumn1: TStringColumn;
|
|
StringColumn2: TStringColumn;
|
|
StringColumn3: TStringColumn;
|
|
StringColumn4: TStringColumn;
|
|
btnAdd: TButton;
|
|
btnDelete: TButton;
|
|
PopupMenu1: TPopupMenu;
|
|
MenuItem1: TMenuItem;
|
|
OpenDialog1: TOpenDialog;
|
|
pVKGenerate: TPanel;
|
|
cbKey1: TComboBox;
|
|
Label54: TLabel;
|
|
cbKey3: TComboBox;
|
|
cbKey2: TComboBox;
|
|
Label56: TLabel;
|
|
procedure cbEventListChange(Sender: TObject);
|
|
procedure btnAddClick(Sender: TObject);
|
|
procedure btnDeleteClick(Sender: TObject);
|
|
procedure MenuItem1Click(Sender: TObject);
|
|
procedure cbActionsChange(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
procedure toLog(aCode: integer; aMethod: string; aMess: string);
|
|
public
|
|
{ Public declarations }
|
|
ListEvents: TArray<TEventGlobal>;
|
|
CustomRewards: Tlist<TCustomRevards>;
|
|
CustomRewardEvents: Tlist<TCustomRewardEvent>;
|
|
|
|
procedure UpdateGrid;
|
|
procedure LoadCustomRevards();
|
|
procedure ESOnGetCustomReward(CustomReward: TCustomRewardEvent);
|
|
procedure OnDonate(aNick, aMessage, aSum: string);
|
|
end;
|
|
|
|
implementation
|
|
|
|
{$R *.fmx}
|
|
|
|
uses uGeneral;
|
|
|
|
procedure TfrEvents.btnAddClick(Sender: TObject);
|
|
var
|
|
NewRec: TEventGlobal;
|
|
begin
|
|
if (cbEventList.Text = '') or (cbActions.Text = '') then
|
|
exit;
|
|
NewRec.Event := cbEventList.ItemIndex;
|
|
NewRec.Action := cbActions.ItemIndex;
|
|
NewRec.Param := edtParams.Text;
|
|
if edtIF.Visible then
|
|
NewRec.Condition := edtIF.Text;
|
|
if cbRevards.Visible then
|
|
NewRec.Condition := cbRevards.Text;
|
|
|
|
SetLength(ListEvents, Length(ListEvents) + 1);
|
|
ListEvents[High(ListEvents)] := NewRec;
|
|
DB.SaveRecordArray<TEventGlobal>('ListEvents', ListEvents);
|
|
UpdateGrid;
|
|
end;
|
|
|
|
procedure TfrEvents.btnDeleteClick(Sender: TObject);
|
|
var
|
|
i, RowIndex: integer;
|
|
begin
|
|
RowIndex := sgEvents.Row;
|
|
if (RowIndex < 0) or (RowIndex > High(ListEvents)) then
|
|
exit;
|
|
for i := RowIndex to High(ListEvents) - 1 do
|
|
ListEvents[i] := ListEvents[i + 1];
|
|
SetLength(ListEvents, Length(ListEvents) - 1);
|
|
DB.SaveRecordArray<TEventGlobal>('ListEvents', ListEvents);
|
|
UpdateGrid;
|
|
end;
|
|
|
|
procedure TfrEvents.cbActionsChange(Sender: TObject);
|
|
begin
|
|
pVKGenerate.Visible := cbActions.ItemIndex = 0;
|
|
end;
|
|
|
|
procedure TfrEvents.cbEventListChange(Sender: TObject);
|
|
begin
|
|
edtIF.Visible := cbEventList.ItemIndex = 0;
|
|
cbRevards.Visible := cbEventList.ItemIndex = 1;
|
|
Label2.Visible := cbEventList.ItemIndex <= 1;
|
|
|
|
end;
|
|
|
|
procedure TfrEvents.ESOnGetCustomReward(CustomReward: TCustomRewardEvent);
|
|
var
|
|
i, i2: integer;
|
|
req, s: string;
|
|
hr: TCustomRewardEvent;
|
|
sm: TSongMachine;
|
|
myAction: integer;
|
|
begin
|
|
sm := TSongMachine.Create;
|
|
try
|
|
toLog(3, 'ESOnGetCustomReward', 'Íà÷àëî îáðàáîòêè íàãðàäû: ' +
|
|
CustomReward.Event.revard.Title);
|
|
s := '[' + CustomReward.Event.user_name +
|
|
'] êóïèë çà áàëëû êàíàëà íàãðàäó "' +
|
|
CustomReward.Event.revard.Title + '" ';
|
|
if CustomReward.Event.user_input <> '' then
|
|
begin
|
|
toLog(0, 'ESOnGetCustomReward', 'Ïîëüçîâàòåëüñêèé ââîä: ' +
|
|
CustomReward.Event.user_input);
|
|
s := s + ' è ïåðåäàë ñòðîêó ' + CustomReward.Event.user_input
|
|
end;
|
|
|
|
for i := 0 to high(ListEvents) do
|
|
begin
|
|
if ListEvents[i].Event <> 1 then
|
|
continue;
|
|
if ListEvents[i].Condition = CustomReward.Event.revard.Title then
|
|
begin
|
|
myAction := ListEvents[i].Action;
|
|
|
|
{
|
|
0 Íàæàòü íêîïêó íà êëàâèàòóðå
|
|
1 Ïðîèãðàòü çâóê
|
|
2 Kandinsky
|
|
3 Çàïóñòèòü Web Event
|
|
4 Íàïèñàòü â ÷àò
|
|
5 Çàïóñòèòü ïðîãðàììó
|
|
|
|
}
|
|
case myAction of
|
|
0:
|
|
begin // íàæàòü êíîïêó
|
|
toLog(0, 'ESOnGetCustomReward', 'Ñèìóëÿöèÿ íàæàòèÿ: ' +
|
|
ListEvents[i].Param);
|
|
kePoints.SimulateKeyPress(ListEvents[i].Param, 500);
|
|
end;
|
|
1:
|
|
begin // âîñïðîèçâåäåíèå çâóêà
|
|
toLog(0, 'ESOnGetCustomReward', 'Âîñïðîèçâåäåíèå çâóêà: ' +
|
|
ListEvents[i].Param);
|
|
sm.PlayPublic(ListEvents[i].Param, '100');
|
|
end;
|
|
2:
|
|
begin // Kandinsky
|
|
toLog(0, 'ESOnGetCustomReward', 'Ãåíåðàöèÿ Kandinsky äëÿ: ' +
|
|
CustomReward.Event.user_input);
|
|
Kandinsky.generate(CustomReward.Event.user_input,
|
|
CustomReward.Event.user_login);
|
|
end;
|
|
4:
|
|
begin // Íàïèñàòü â ÷àò
|
|
|
|
toLog(0, 'ESOnGetCustomReward', 'Íàïèñàòü â ÷àò: ' +
|
|
CustomReward.Event.user_input);
|
|
end;
|
|
5:
|
|
begin // çàïóñê ôàéëà
|
|
toLog(0, 'ESOnGetCustomReward', 'Çàïóñê ôàéëà: ' + ListEvents
|
|
[i].Param);
|
|
ShellExecute(0, 'open', pwidechar(ListEvents[i].Param),
|
|
nil, nil, 0);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
finally
|
|
sm.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrEvents.LoadCustomRevards();
|
|
var
|
|
cr: TCustomRevards;
|
|
begin
|
|
CustomRewards.Clear;
|
|
cbRevards.Items.Clear;
|
|
TTW_Bot.toLog('fEvents', 'LoadCustomRevards', 'Çàïðîñ íàãðàä ñ ñåðâåðà', 3);
|
|
ttw_API.getCustomReward(CustomRewards);
|
|
for cr in CustomRewards do
|
|
begin
|
|
cbRevards.Items.Add(cr.Title);
|
|
end;
|
|
end;
|
|
|
|
procedure TfrEvents.MenuItem1Click(Sender: TObject);
|
|
begin
|
|
if OpenDialog1.Execute then
|
|
TEdit(PopupMenu1.PopupComponent).Text := OpenDialog1.FileName;
|
|
end;
|
|
|
|
procedure TfrEvents.OnDonate(aNick, aMessage, aSum: string);
|
|
var
|
|
i, i2: integer;
|
|
req, s: string;
|
|
hr: TCustomRewardEvent;
|
|
sm: TSongMachine;
|
|
myAction: integer;
|
|
|
|
j: integer;
|
|
aSumInt: integer;
|
|
BestRow: integer;
|
|
BestPriority: integer;
|
|
BestValue: integer;
|
|
Condition: string;
|
|
CurrentPriority: integer;
|
|
CurrentValue: integer;
|
|
MinVal, MaxVal: integer;
|
|
Parts: tstringlist;
|
|
se: TStyleEvent;
|
|
notify: TEventGlobal;
|
|
|
|
begin
|
|
|
|
aSumInt := StrToIntDef(aSum, 0);
|
|
BestRow := -1;
|
|
BestPriority := -1;
|
|
BestValue := 0;
|
|
|
|
for i := 0 to high(ListEvents) do
|
|
begin
|
|
if ListEvents[i].Event = 0 then
|
|
begin
|
|
Condition := ListEvents[i].Condition;
|
|
CurrentPriority := -1;
|
|
CurrentValue := 0;
|
|
|
|
// Ïðîâåðêà íà òî÷íîå çíà÷åíèå
|
|
if Pos('-', Condition) = 0 then
|
|
begin
|
|
if Pos('>', Condition) = 0 then
|
|
begin
|
|
if Pos('<', Condition) = 0 then
|
|
begin
|
|
// Òî÷íîå çíà÷åíèå
|
|
CurrentValue := StrToIntDef(Condition, -1);
|
|
if aSumInt = CurrentValue then
|
|
CurrentPriority := 4;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
if CurrentPriority = -1 then
|
|
begin
|
|
if Pos('-', Condition) > 0 then
|
|
begin
|
|
// Äèàïàçîí
|
|
Parts := tstringlist.Create;
|
|
try
|
|
Parts.Delimiter := '-';
|
|
Parts.StrictDelimiter := True;
|
|
Parts.DelimitedText := Condition;
|
|
if Parts.Count = 2 then
|
|
begin
|
|
MinVal := StrToIntDef(Trim(Parts[0]), 0);
|
|
MaxVal := StrToIntDef(Trim(Parts[1]), 0);
|
|
if (aSumInt >= MinVal) and (aSumInt <= MaxVal) then
|
|
begin
|
|
CurrentPriority := 3;
|
|
CurrentValue := MinVal; // Ïðèîðèòåò ïî MinVal
|
|
end;
|
|
end;
|
|
finally
|
|
Parts.Free;
|
|
end;
|
|
end
|
|
else if Pos('>', Condition) > 0 then
|
|
begin
|
|
// Óñëîâèå ">X"
|
|
CurrentValue :=
|
|
StrToIntDef(Trim(StringReplace(Condition, '>', '',
|
|
[rfReplaceAll])), 0);
|
|
if aSumInt >= CurrentValue then
|
|
CurrentPriority := 2;
|
|
end
|
|
else if Pos('<', Condition) > 0 then
|
|
begin
|
|
// Óñëîâèå "<X"
|
|
CurrentValue :=
|
|
StrToIntDef(Trim(StringReplace(Condition, '<', '',
|
|
[rfReplaceAll])), 0);
|
|
if aSumInt <= CurrentValue then
|
|
CurrentPriority := 1;
|
|
end;
|
|
end;
|
|
|
|
if CurrentPriority <> -1 then
|
|
begin
|
|
// Îïðåäåëåíèå íàèëó÷øåãî óñëîâèÿ
|
|
if (CurrentPriority > BestPriority) or (CurrentPriority = BestPriority)
|
|
and ((CurrentPriority = 3) and (CurrentValue > BestValue) or
|
|
(CurrentPriority = 2) and (CurrentValue > BestValue) or
|
|
(CurrentPriority = 1) and (CurrentValue < BestValue)) then
|
|
begin
|
|
BestPriority := CurrentPriority;
|
|
BestValue := CurrentValue;
|
|
BestRow := i;
|
|
notify := ListEvents[i];
|
|
end;
|
|
end;
|
|
if BestRow = -1 then
|
|
Break;
|
|
|
|
end;
|
|
end;
|
|
if BestRow = -1 then
|
|
exit;
|
|
sm := TSongMachine.Create;
|
|
try
|
|
myAction := ListEvents[i].Action;
|
|
case myAction of
|
|
0:
|
|
begin // íàæàòü êíîïêó
|
|
toLog(0, 'OnDonate', 'Ñèìóëÿöèÿ íàæàòèÿ: ' + ListEvents[i].Param);
|
|
kePoints.SimulateKeyPress(ListEvents[i].Param, 500);
|
|
end;
|
|
1:
|
|
begin // âîñïðîèçâåäåíèå çâóêà
|
|
toLog(0, 'OnDonate', 'Âîñïðîèçâåäåíèå çâóêà: ' + ListEvents[i].Param);
|
|
sm.PlayPublic(ListEvents[i].Param, '100');
|
|
end;
|
|
2:
|
|
begin // Kandinsky
|
|
toLog(0, 'OnDonate', 'Ãåíåðàöèÿ Kandinsky äëÿ: ' + aNick);
|
|
Kandinsky.generate(aMessage, aNick);
|
|
end;
|
|
4:
|
|
begin // Íàïèñàòü â ÷àò
|
|
|
|
toLog(0, 'OnDonate', 'Íàïèñàòü â ÷àò: ' + aNick);
|
|
end;
|
|
5:
|
|
begin // çàïóñê ôàéëà
|
|
toLog(0, 'OnDonate', 'Çàïóñê ôàéëà: ' + ListEvents[i].Param);
|
|
ShellExecute(0, 'open', pwidechar(ListEvents[i].Param), nil, nil, 0);
|
|
end;
|
|
end;
|
|
|
|
finally
|
|
sm.Free;
|
|
end;
|
|
end;
|
|
|
|
procedure TfrEvents.toLog(aCode: integer; aMethod, aMess: string);
|
|
begin
|
|
TTW_Bot.toLog('fEvents', aMethod, aMess, aCode);
|
|
end;
|
|
|
|
procedure TfrEvents.UpdateGrid;
|
|
var
|
|
i: integer;
|
|
begin
|
|
sgEvents.BeginUpdate;
|
|
try
|
|
sgEvents.RowCount := 0; // Ñáðàñûâàåì ñòðîêè (îñòàâëÿåì òîëüêî çàãîëîâêè)
|
|
|
|
for i := 0 to High(ListEvents) do
|
|
begin
|
|
sgEvents.RowCount := i + 1;
|
|
sgEvents.Cells[0, i] := cbEventList.Items[ListEvents[i].Event];
|
|
sgEvents.Cells[1, i] := ListEvents[i].Condition;
|
|
sgEvents.Cells[2, i] := cbActions.Items[ListEvents[i].Action];
|
|
sgEvents.Cells[3, i] := ListEvents[i].Param;
|
|
end;
|
|
finally
|
|
sgEvents.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
end.
|