- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
function TCalc.getRewardItems(items : AnsiString; countItems : integer; userId : Integer; from:integer) : ISuperObject;
var tmpFirstOdds : integer;
strLines, extrLines : TStringList;
strItems, strOdds, strOdds2: TIntegerList;
i, j, tmpCountItems : integer;
tmpOddsItems, sum : Integer;
str: ansistring;
begin
Result := nil;
// parse items line [id1,odd1],[id2,odd2],[id3,odd3]
strLines := TStringList.Create;
extrLines := TStringList.Create;
strItems := TIntegerList.Create;
strOdds := TIntegerList.Create;
ExtractStrings(['[', ']'],[','], PChar(items), strLines);
for i := 0 to strLines.Count - 1 do
begin
ExtractStrings([','],[' '], PChar(strLines[i]), extrLines);
strItems.Add(StrToInt(extrLines[0]));
strOdds.Add(StrToInt(extrLines[1]));
extrLines.Clear;
end;
// calculate odds [a,b,c,d] as [a,a+b,a+b+c,a+b+c+d]
sum := 0;
strOdds2 := TIntegerList.Create;
for i := 0 to strOdds.Count-1 do
begin
sum := sum + strOdds.Items[i];
strOdds2.Add(sum);
end;
// select items
str := '';
for i := 0 to countItems - 1 do
begin
tmpFirstOdds := Random(101); // 0-100
for j := 0 to strOdds2.Count-1 do
begin
if tmpFirstOdds < strOdds2.Items[j] then
begin
str := str + IntToStr(strItems[j]) + ',';
break;
end;
end;
end;
str := '['+Copy(str,1,Length(str)-1)+']';
// from monster
if from=0 then Result := so('{"part":"battle","func":"itemsdropped","data":'+str+'}');
// from chest
if from=1 then Result := so('{"part":"battle","func":"itemsdroppedchest","data":'+str+'}');
strLines.Free;
extrLines.Free;
strItems.Free;
strOdds.Free;
strOdds2.Free;
end;
У меня чуть глаза не вытекли от такого решения. Код по идее сообщает клиенту, что выпало из монстра после победы над ним.
betking1 27.11.2014 15:33 # 0
try - для слабаков