PageRenderTime 29ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/antirandoms/Sandwich.simba

http://github.com/Drags111/Reflection_Dev
Unknown | 217 lines | 190 code | 27 blank | 0 comment | 0 complexity | 23028e7d58705bcc3d47689b3a14c191 MD5 | raw file
  1const
  2  RSandwichConst_NPCID = 8630;
  3  RSandwichConst_FoodInterface = 297;
  4  RSandwichConst_FoodAssigned = 48;
  5
  6var
  7  RSandwichVars_PortalIDs, RSandwichVars_ModelIDs: TIntegerArray;
  8  RSandwichVars_ModelNames, RSandwichVars_Finished: TStringArray;
  9
 10procedure RSandwich_SetVars;
 11begin
 12  RSandwichVars_PortalIDs := [12731, 11373];
 13  RSandwichVars_ModelIDs := [10728, 10732, 10727, 10730, 10726, 45666, 10731];
 14  RSandwichVars_ModelNames := ['chocolate', 'triangle', 'roll', 'pie',
 15   'baguette', 'doughnut', 'square'];
 16  RSandwichVars_Finished := ['leave', 'portal', 'exit'];
 17end;
 18
 19function RSandwich_InRandom: Boolean;
 20var
 21  SWLady: TNPC;
 22begin
 23  Result := R_FindNPC(RSandwichConst_NPCID, True, SWLady);
 24end;
 25
 26function RSandwich_HandleChat: Boolean;
 27var
 28  Chat: String;
 29  SWLady: TNPC;
 30begin
 31  Result := False;
 32
 33  if R_FindNPC(RSandwichConst_NPCID, True, SWLady) then
 34    if RRandom_TalkToNPC(SWLady, False, 'Sandwich') then
 35    begin
 36      Chat := R_GetNPCChatMessage;
 37      Result := ArrInStr(RSandwichVars_Finished, R_GetNPCChatMessage);
 38
 39      while ClickContinue(True, True) do
 40      begin
 41        if not Result then
 42          Result := ArrInStr(RSandwichVars_Finished, R_GetNPCChatMessage);
 43        Wait(500);
 44      end;
 45
 46      if Result then
 47        R_Debug('Finished, trying to exit', 'Sandwich');
 48    end else
 49    begin
 50      R_Debug('Could not find Sandwich Lady', 'Sandwich');
 51      Exit;
 52    end;
 53
 54
 55end;
 56
 57function RSandwich_InterfaceUp: Boolean;
 58begin
 59  Result := R_ValidInterface(RSandwichConst_FoodInterface);
 60end;
 61
 62function RSandwich_TargetString: String;
 63begin
 64  Result := Trim(Between('Have a', 'for free!',
 65                    R_GetInterfaceText(RSandwichConst_FoodInterface,
 66                                       RSandwichConst_FoodAssigned)));
 67end;
 68
 69function RSandwich_HandleInterface: Boolean;
 70var
 71  TargetString: String;
 72  TargetModel, i, T: Integer;
 73  TempInterface, ClickInterface: TInterfaceChild;
 74begin
 75  if not RSandwich_InterfaceUp then Exit;
 76  TargetModel := -1;
 77
 78  TargetString := RSandwich_TargetString;
 79  if (TargetString = '') then
 80  begin
 81    R_Debug('Unable to retrieve food string', 'Sandwich');
 82    Exit;
 83  end;
 84
 85  for i := 0 to High(RSandwichVars_ModelNames) do
 86    if (Pos(RSandwichVars_ModelNames[i], TargetString) > 0) then
 87    begin
 88      R_Debug('Target food: ' + RSandwichVars_ModelNames[i], 'Sandwich');
 89      TargetModel := RSandwichVars_ModelIDs[i];
 90      Break;
 91    end;
 92
 93  if (TargetModel > 0) then
 94  begin
 95    for i := 10 to 23 do
 96    begin
 97      TempInterface := R_GetInterfaceChild(RSandwichConst_FoodInterface, i);
 98      if (TargetModel = TempInterface.ModelID) then
 99      begin
100        ClickInterface := R_GetInterfaceChild(RSandwichConst_FoodInterface, i);
101        R_Debug('Found model match at child[' + ToStr(i) + ']', 'Sandwich');
102        MarkTime(T);
103        while (TimeFromMark(T) < 8000) do
104        begin
105          Result := not RSandwich_InterfaceUp;
106          if Result then
107          begin
108            R_Debug('Clicked on Target model', 'Sandwich');
109            Exit;
110          end;
111          R_ClickInterface(ClickInterface, 1);
112          Wait(250);
113        end;
114        R_Debug('Clicking timed out', 'Sandwich');
115        Exit;
116      end;
117    end;
118    R_Debug('Unable to match Target model with any model', 'Sandwich');
119    R_Debug('Trying to use child[22]', 'Sandwich');
120    ClickInterface := R_GetInterfaceChild(RSandwichConst_FoodInterface, 22);
121    MarkTime(T);
122    while (TimeFromMark(T) < 8000) do
123    begin
124      Result := not RSandwich_InterfaceUp;
125      if Result then
126      begin
127        R_Debug('Clicked on Target model', 'Sandwich');
128        Exit;
129      end;
130      R_ClickInterface(ClickInterface, 1);
131      Wait(250);
132    end;
133    R_Debug('Clicking timed out', 'Sandwich');
134    Exit;
135  end else
136  begin
137    R_Debug('Unable to match Target string with model ID', 'Sandwich');
138    Exit;
139  end;
140end;
141
142function RSandwich_Leave: Boolean;
143var
144  Portal: TRSObject;
145  P: TPoint;
146  X, Y, T: Integer;
147begin
148  Portal := R_GetObjectEx(RSandwichVars_PortalIDs, OBJ_INTERACTABLE, 30);
149  if(Portal = NULL_RSOBJECT)then
150  begin
151    R_Debug('Unable to find portal. Go buy Portal 2..', 'Sandwich');
152    Exit;
153  end;
154
155  if(R_DistanceFromTile(Portal.Tile) > 4)then
156  begin
157    if not R_WalkToTile(Portal.Tile, 1, 0)then
158    begin
159      R_Debug('Unable to walk to Portal.', 'Sandwich');
160      Exit;
161    end;
162    Wait(300+Random(50));
163  end;
164
165  P := R_TileToMS(Portal.Tile, 0);
166  MMouse(P.x, P.y, 10, 10);
167  wait(25+Random(25));
168  Result := R_OptionExists('enter');
169  if not Result then
170    Exit;
171
172  GetMousePos(X, Y);
173  Mouse(X, Y, 0, 0, false);
174  wait(25+Random(25));
175  Result := R_ChooseOption('enter');
176  if not Result then
177    Exit;
178
179  R_WaitToMove(3000);
180  R_Flag;
181
182  MarkTime(T);
183  while (RSandwich_InRandom and (TimeFromMark(T) < 8000)) do
184  begin
185    if not RSandwich_InRandom then Break;
186    Wait(500);
187  end;
188
189  Result := not RSandwich_InRandom;
190end;
191
192function RSandwich_Solve: Boolean;
193var
194  T: Integer;
195begin
196  Result := False;
197  RSandwich_SetVars;
198
199  MarkTime(T);
200  while RSandwich_InRandom and (TimeFromMark(T) < 240000) do
201  begin
202    if RSandwich_InterfaceUp then
203      if not RSandwich_HandleInterface then
204      begin
205        R_Debug('Failed to handle food interface', 'Sandwich');
206      end;
207
208    if RSandwich_HandleChat then
209      if not RSandwich_Leave then
210      begin
211        R_Debug('Unable to exit', 'Sandwich');
212      end;
213
214  end;
215
216  Result := not RSandwich_InRandom;
217end;