unit takegump; 
interface 

implementation

var 
GumpLines_List : TStringList; 
g_i,g_k       : Integer;
num1,num2 : Integer;
res       : Integer;
temp_SL   : TStringList;
oper      : Byte;
flag      : Boolean;
StrNums   : array of String;
NumsVal   : array of Word;
AMGumpfound : Boolean;


procedure SumByCondition(Condition : Boolean;var TrueCondOper,FalseCondOper : Integer;OperSum : Word);
begin
if Condition then
TrueCondOper := TrueCondOper + OperSum
else
FalseCondOper := FalseCondOper + OperSum;
end;
 
procedure OnIncomingGump(Serial,GumpID,X,Y : Cardinal); 
Begin
AMGumpfound := False;
GumpLines_List := TStringList.Create;
SetSilentMode(True);
GetGumpTextLines(GetGumpsCount - 1,GumpLines_List);
for g_i := 0 to (GumpLines_List.Count-1) do
  if GumpLines_List.Strings[g_i] = 'Антимакрос' then begin AMGumpfound := True; Break; end;
if not AMGumpfound then begin GumpLines_List.free; Exit; end;
temp_SL :=  TStringList.Create;
flag := False;
num1 := 0;
num2 := 0;
oper := $FF;
if GumpLines_List.Count >= 2 then 
  begin
    AddToSystemJournal('Вопрос антимакроса: '+ GumpLines_List.Strings[1] );
    StrBreakApart(GumpLines_List.Strings[1],' ',temp_SL);
    for g_i := 0 to (temp_SL.Count-1) do
      begin
        if (temp_SL.Strings[g_i] = '=') then Break;  // = ? нам ненадо
        for g_k := 0 to GetArrayLength(StrNums) - 1  do
          if StrNums[g_k] = temp_SL.Strings[g_i] then
            begin
              if g_k <= GetArrayLength(StrNums) then
                begin
                  if g_k < 3 then begin oper := g_k; flag := True; Continue; end;
                  SumByCondition(flag,num2,num1,NumsVal[g_k]);
                end;
              break;
            end;
      end;
        
    AddToSystemJournal('число один: '  + IntToStr(num1));
    case oper of
      0 : begin res := num1 + num2; AddToSystemJournal('операция: плюс'); end;
      1 : begin res := num1 - num2; AddToSystemJournal('операция: минус'); end;
      2 : begin res := num1 * num2; AddToSystemJournal('операция: умножение'); end;
      3 : begin res := num1 / num2; AddToSystemJournal('операция: деление'); end;
      $FF:begin AddToSystemJournal('операция: не обнаружена! Выход'); Exit; end;
    end;
    AddToSystemJournal('число два: '  + IntToStr(num2));

    if (num1 = 0) and (num2 = 0) then begin AddToSystemJournal('число(а) получены неправильно! Выход'); Exit; end;
      if NumGumpTextEntry(GetGumpsCount - 1,0, IntToStr(res)) then 
        AddToSystemJournal('отправили ответ - ' + IntToStr(res));
    NumGumpButton(GetGumpsCount - 1, 77);
    GumpLines_List.free;
    temp_SL.free;   
  end;
end;

begin
StrNums := ['Сложить','Отнять','Умножить','Разделить','Один','Два','Три','Четыре','Пять','Шесть','Семь','Восемь','Девять','Десять','Одиннадцать','Двенадцать','Тринадцать','Четырнадцать','Пятнадцать','Шестнадцать','Семнадцать','Восемнадцать','Девятнадцать','Двадцать','Тридцать','Сорок','Пятьдесят','Шестьдесят','Семьдесят','Восемьдесят','Девяносто','Сто','Двести','Триста','Четыреста','Пятьсот','Шестьсот','Семьсот','Восемьсот','Девятьсот']
NumsVal := [0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,30,40,50,60,70,80,90,100,200,300,400,500,600,700,800,900]
SetEventProc(evIncomingGump, 'OnIncomingGump'); 
End.