Advertisement
WarPie90

ItemDatabase - proto

May 8th, 2016
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.18 KB | None | 0 0
  1. {$I SRL/OSR.simba}
  2.  
  3. type
  4.   TDatabaseItem = record
  5.     Name: String;
  6.     Data: T2DIntArray;
  7.   end;
  8.   TItemDatabase = record
  9.     Items: array [0..$2000] of TDatabaseItem;
  10.   end;
  11.  
  12. var
  13.   ItemDatabase:TItemDatabase;
  14.  
  15. function TItemDatabase.NameToId(var Name:String): Int32;
  16. var
  17.   i:Int32;
  18.   id, imgurl, url, data:String;
  19. begin
  20.   url := 'http://services.runescape.com/m=itemdb_oldschool/results';
  21.   data := GetPage(url + '?query='+LowerCase(Name));
  22.   data := Between('class=''table-item-link''>', '</a>', data);
  23.   imgurl := Between('<img src=''', '">', data);
  24.   Result := StrToIntDef(Between('id=', '''', imgurl), -1);
  25.   if Result <> -1 then
  26.   begin
  27.     i := pos('alt=', imgurl) + 5;
  28.     Name := Copy(imgurl, i, Length(imgurl)-i+1);
  29.   end;
  30. end;
  31.  
  32. function TItemDatabase.FetchImage(id:Int32): T2DIntArray;
  33. var
  34.   i: Int32;
  35.   stream: TStringStream;
  36.   im: TMufasaBitmap;
  37.   pic: TPicture;
  38.   ptr: PRGB32;
  39. begin
  40.   stream.Init(GetPage('http://services.runescape.com/m=itemdb_oldschool/5182_obj_sprite.gif?id='+IntToStr(id)));
  41.   pic.Init;
  42.   pic.LoadFromStream(stream);
  43.   im.Init(client.GetMBitmaps);
  44.   im.LoadFromTBitmap(pic.GetBitmap());
  45.   ptr := im.GetData();
  46.   for i:=0 to im.GetWidth() * im.GetHeight() - 1 do
  47.     if (ptr[i]^.A <> 255) then
  48.       UInt32(ptr[i]^) := 0
  49.     else
  50.       ptr[i]^.A := 0;
  51.   Result := im.ToMatrix();
  52.   im.Free();
  53.   pic.Free();
  54.   stream.Free();
  55. end;
  56.  
  57.  
  58. function TItemDatabase.GetItem(Name:String): TDatabaseItem;
  59. var
  60.   i,id:Int32;
  61. begin
  62.   Name := Lowercase(Name);
  63.   for i:=0 to High(Items) do
  64.     if Items[i].Name = Name then
  65.       Exit(Items[i]);
  66.  
  67.   id := Self.NameToId(Name);
  68.   if (id = -1) then Exit;
  69.   Items[id].Data := FetchImage(id);
  70.   Items[id].Name := Name;
  71.   Result := Items[id];
  72. end;
  73.  
  74. function TItemDatabase.GetItemBitmap(Name:String): Integer;
  75. var
  76.   img:TMufasaBitmap;
  77. begin
  78.   img.Init(client.GetMBitmaps);
  79.   img.DrawMatrix( ItemDatabase.Find('Red cape').Data );
  80.   Result := img.GetIndex();
  81. end;
  82.  
  83. var
  84.   item:TDatabaseItem;
  85.   ex:TMufasaBitmap;
  86. begin
  87.   item := ItemDatabase.Find('Red cape');
  88.   WriteLn(item.Name);
  89.  
  90.   ex.Init(client.GetMBitmaps);
  91.   ex.DrawMatrix( item.Data );
  92.   ex.Debug();
  93.  
  94.   ex.Free();
  95. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement