PageRenderTime 34ms CodeModel.GetById 28ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/gametab/Quests.simba

http://github.com/Drags111/Reflection_Dev
Unknown | 285 lines | 219 code | 66 blank | 0 comment | 0 complexity | 3db395301f506df71a539d71ac3dc1e6 MD5 | raw file
  1(*
  2Quests
  3====
  4
  5Quest routines that could be useful.
  6
  7*)
  8
  9(*
 10R_RefreshQuestCache
 11~~~~~~~~~~~~~~~~~~~
 12
 13.. code-block:: pascal
 14
 15    function R_RefreshQuestCache: Boolean;
 16
 17Opens quest tab so that the list is refreshed.
 18
 19.. note::
 20
 21  by mormonman
 22
 23*)
 24function R_RefreshQuestCache: Boolean;
 25var
 26  T: Integer;
 27begin
 28  if (R_CurrentGameTab = RTAB_QUESTS) then
 29  begin
 30    Result := True;
 31    Exit;
 32  end;
 33
 34  MarkTime(T);
 35  while not R_GameTab(RTAB_QUESTS) and (TimeFromMark(T) < 5000) do
 36    Wait(500);
 37
 38  Result := (R_CurrentGameTab = RTAB_QUESTS);
 39end;
 40
 41(*
 42R_GetQuestStatus
 43~~~~~~~~~~~~~~~~~~~
 44
 45.. code-block:: pascal
 46
 47    function R_GetQuestStatus(Quest: String): Integer;
 48
 49Returns the QUEST_ constant.
 50
 51.. note::
 52
 53  by mormonman
 54
 55*)
 56function R_GetQuestStatus(Quest: String): Integer;
 57var
 58  i: Integer;
 59  tempInt: TInterfaceComponent;
 60begin
 61  if not R_RefreshQuestCache then
 62    Exit;
 63  Quest := Lowercase(Quest);
 64
 65  for i := 0 to 192 do
 66    if (Pos(Quest, Lowercase(R_GetInterfaceTextEx(INTERFACE_QUESTS, QUEST_LIST, i))) > 0) then
 67    begin
 68      tempInt := R_GetInterfaceComponent(INTERFACE_QUESTS, QUEST_LIST, i);
 69      Result := tempInt.TextColor;
 70    end;
 71end;
 72
 73(*
 74R_GetQuestPoints
 75~~~~~~~~~~~~~~~~~~~
 76
 77.. code-block:: pascal
 78
 79    function R_GetQuestPoints: Integer;
 80
 81Returns the players quest points.
 82
 83.. note::
 84
 85  by mormonman
 86
 87*)
 88function R_GetQuestPoints: Integer;
 89begin
 90  if not R_RefreshQuestCache then
 91    Exit;
 92  Result := StrToIntDef(Trim(Between(':', '/', R_GetInterfaceText(INTERFACE_QUESTS, QUEST_POINTS))), -1);
 93end;
 94
 95(*
 96R_SetQuestFilters
 97~~~~~~~~~~~~~~~~~~~
 98
 99.. code-block:: pascal
100
101    function R_SetQuestFilters(Filter, Done: Boolean): Boolean;
102
103Sets the two filters in the quest interface.
104  @Filter - Hides quests you can't do
105  @Done - Hides quests you have completed
106
107.. note::
108
109  by mormonman
110
111*)
112function R_SetQuestFilters(Filter, Done: Boolean): Boolean;
113var
114  FCur, DCur: TInterfaceChild;
115  A, B: Boolean;
116  T, TempID: Integer;
117begin
118  if not R_RefreshQuestCache then
119    Exit;
120  FCur := R_GetInterfaceChild(INTERFACE_QUESTS, QUEST_FILTER);
121  DCur := R_GetInterfaceChild(INTERFACE_QUESTS, QUEST_DONE);
122  A := True; B := True;
123
124  if (FCur.TextureID = QUEST_CHECKED) xor Filter then
125  begin
126    A := False;
127    TempID := FCur.TextureID;
128    MarkTime(T);
129    while (TimeFromMark(T) < 3500) do
130    begin
131      FCur := R_GetInterfaceChild(INTERFACE_QUESTS, QUEST_FILTER);
132      if (FCur.TextureID <> TempID) then
133        Break;
134      R_ClickInterface(FCur, mouse_Left);
135      Wait(RandomRange(500, 850));
136    end;
137    A := (TimeFromMark(T) < 3500);
138  end;
139
140  if (DCur.TextureID = QUEST_CHECKED) xor Done then
141  begin
142    B := False;
143    TempID := DCur.TextureID;
144    MarkTime(T);
145    while (TimeFromMark(T) < 3500) do
146    begin
147      DCur := R_GetInterfaceChild(INTERFACE_QUESTS, QUEST_DONE);
148      if (DCur.TextureID <> TempID) then
149        Break;
150      R_ClickInterface(DCur, mouse_Left);
151      Wait(RandomRange(500, 850));
152    end;
153    B := (TimeFromMark(T) < 3500);
154  end;
155
156  Result := A and B;
157end;
158
159(*
160R_ClickQuest
161~~~~~~~~~~~~~~~~~~~
162
163.. code-block:: pascal
164
165    procedure R_ClickQuest(Child: TInterfaceChild; ClickType: Integer);
166
167Clicks the quest, work-around for the scrollbar.
168
169.. note::
170
171  by mormonman
172
173*)
174procedure R_ClickQuest(Child: TInterfaceChild; ClickType: Integer);
175begin
176  MouseBox(Child.X, Child.Y, Child.Bounds.X2 - 50, Child.Bounds.Y2, ClickType);
177end;
178
179(*
180R_OpenQuest
181~~~~~~~~~~~~~~~~~~~
182
183.. code-block:: pascal
184
185    function R_OpenQuest(Quest: String): Boolean;
186
187Opens the quest interface for the given Quest.
188
189.. note::
190
191  by mormonman
192
193*)
194function R_OpenQuest(Quest: String): Boolean;
195var
196  i, T: Integer;
197  QuestI, tempC: TInterfaceComponent;
198  SBar: TInterfaceChild;
199  B: TBox;
200begin
201  if not R_RefreshQuestCache then
202    Exit;
203
204  Quest := Lowercase(Quest);
205
206  Result := R_ValidInterface(INTERFACE_QUESTINFO) and
207    (Pos(Quest, LowerCase(R_GetInterfaceText(INTERFACE_QUESTINFO, QUEST_INFO_NAME))) > 0);
208  if Result then
209    Exit;
210
211  if R_SetQuestFilters(False, False) then
212  begin
213    for i := 0 to 192 do
214      if (Pos(Quest, Lowercase(R_GetInterfaceTextEx(INTERFACE_QUESTS, QUEST_LIST, i))) > 0) then
215      begin
216        QuestI := R_GetInterfaceComponent(INTERFACE_QUESTS, QUEST_LIST, i);
217        Break;
218      end;
219
220    if not (Pos(Quest, Lowercase(QuestI.Text)) > 0) then
221    begin
222      R_Debug('Quest not found', 'R_OpenQuest');
223      Exit;
224    end;
225
226    SBar := R_GetInterfaceChild(INTERFACE_QUESTS, QUEST_SCROLL);
227    B := IntToBox(551, 281, 737, 454);
228
229    if R_ScrollTo(QuestI, SBar, B) or
230      (PointInBox(Point(QuestI.X, QuestI.Y), B) and
231        PointInBox(Point(QuestI.Bounds.X2, QuestI.Bounds.Y2), B)) then
232    begin
233      MarkTime(T);
234      while (TimeFromMark(T) < 10000) do
235      begin
236        if R_ValidInterface(INTERFACE_QUESTINFO) and
237            (Pos(Quest, Lowercase(R_GetInterfaceText(INTERFACE_QUESTINFO, QUEST_INFO_NAME))) > 0) then
238          Break;
239        tempC := R_UpdateInterface(QuestI);
240        R_ClickQuest(tempC, mouse_Left);
241        Wait(RandomRange(1500, 2000));
242      end;
243
244      Result := R_ValidInterface(INTERFACE_QUESTINFO) and
245        (Pos(Quest, LowerCase(R_GetInterfaceText(INTERFACE_QUESTINFO, QUEST_INFO_NAME))) > 0);
246      if (TimeFromMark(T) > 10000) and not Result then
247        R_Debug('Opening quest timed out', 'R_OpenQuest');
248    end else
249    begin
250      R_Debug('Unable to scroll to quest', 'R_OpenQuest');
251    end;
252  end else
253  begin
254    R_Debug('Unable to set quest filters', 'R_OpenQuest');
255  end;
256end;
257
258(*
259R_CloseQuestInfo
260~~~~~~~~~~~~~~~~~~~
261
262.. code-block:: pascal
263
264    function R_CloseQuestInfo: Boolean;
265
266Closes the quest info interface.
267
268.. note::
269
270  by mormonman
271
272*)
273function R_CloseQuestInfo: Boolean;
274var
275  CloseI: TInterfaceChild;
276begin
277  Result := not R_ValidInterface(INTERFACE_QUESTINFO);
278  if Result then
279    Exit;
280
281  CloseI := R_GetInterfaceChild(INTERFACE_QUESTINFO, QUEST_INFO_CLOSE);
282  R_ClickInterface(CloseI, mouse_Left);
283  Result := R_WaitInterfaceClose(INTERFACE_QUESTINFO, 3500);
284end;
285