mirror of
https://bitbucket.org/grumdrig/pq-web.git
synced 2026-09-29 08:44:00 -06:00
Converted to JS. Node.js can parse it at least.
This commit is contained in:
@@ -1,267 +1,160 @@
|
|||||||
unit NewGuy;
|
/* copyright (c)2002-2010 Eric Fredricksen all rights reserved */
|
||||||
{ copyright (c)2002 Eric Fredricksen all rights reserved }
|
|
||||||
|
|
||||||
interface
|
function UrlEncode(s) {
|
||||||
|
NewGuyForm.PoorCodeDesign.InputString = s;
|
||||||
|
return NewGuyForm.PoorCodeDesign.Encode;
|
||||||
|
}
|
||||||
|
|
||||||
uses
|
function Roll(stat) {
|
||||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
stat.Tag = 3 + Random(6) + Random(6) + Random(6);
|
||||||
Dialogs, StdCtrls, ExtCtrls, ComCtrls, AppEvnts, NMURL;
|
stat.Caption = IntToStr(stat.Tag);
|
||||||
|
}
|
||||||
|
|
||||||
type
|
function Choose(n, k) {
|
||||||
TNewGuyForm = class(TForm)
|
var result = n;
|
||||||
Race: TRadioGroup;
|
var d = 1;
|
||||||
Klass: TRadioGroup;
|
for (var i = 2; i <= k; ++i) {
|
||||||
Label2: TLabel;
|
result *= (1+n-i);
|
||||||
STR: TPanel;
|
d = d * i;
|
||||||
Label3: TLabel;
|
}
|
||||||
CON: TPanel;
|
return result / d;
|
||||||
Label4: TLabel;
|
}
|
||||||
DEX: TPanel;
|
|
||||||
Label5: TLabel;
|
|
||||||
INT: TPanel;
|
|
||||||
Label6: TLabel;
|
|
||||||
WIS: TPanel;
|
|
||||||
Label7: TLabel;
|
|
||||||
CHA: TPanel;
|
|
||||||
Reroll: TButton;
|
|
||||||
GroupBox1: TGroupBox;
|
|
||||||
Label8: TLabel;
|
|
||||||
Total: TPanel;
|
|
||||||
Sold: TButton;
|
|
||||||
Unroll: TButton;
|
|
||||||
Name: TLabeledEdit;
|
|
||||||
OldRolls: TListBox;
|
|
||||||
Button2: TButton;
|
|
||||||
PoorCodeDesign: TNMURL;
|
|
||||||
Account: TLabeledEdit;
|
|
||||||
Password: TLabeledEdit;
|
|
||||||
ApplicationEvents1: TApplicationEvents;
|
|
||||||
Gen: TButton;
|
|
||||||
procedure RerollClick(Sender: TObject);
|
|
||||||
procedure UnrollClick(Sender: TObject);
|
|
||||||
procedure SoldClick(Sender: TObject);
|
|
||||||
procedure FormShow(Sender: TObject);
|
|
||||||
procedure ApplicationEvents1Minimize(Sender: TObject);
|
|
||||||
procedure GenClick(Sender: TObject);
|
|
||||||
procedure FormActivate(Sender: TObject);
|
|
||||||
procedure FormCreate(Sender: TObject);
|
|
||||||
private
|
|
||||||
procedure RollEm;
|
|
||||||
function GetAccount: String;
|
|
||||||
function GetPassword: String;
|
|
||||||
procedure ParseSoldResponse(body: String);
|
|
||||||
public
|
|
||||||
function Go: Boolean;
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
function TNewGuyForm_RollEm() {
|
||||||
NewGuyForm: TNewGuyForm;
|
ReRoll.Tag = RandSeed();
|
||||||
|
|
||||||
function UrlEncode(s: string): string;
|
|
||||||
function GenerateName: string;
|
|
||||||
|
|
||||||
implementation
|
|
||||||
|
|
||||||
uses Main, SelServ, StrUtils, Web, Config;
|
|
||||||
|
|
||||||
{$R *.dfm}
|
|
||||||
|
|
||||||
function UrlEncode(s: string): string;
|
|
||||||
begin
|
|
||||||
NewGuyForm.PoorCodeDesign.InputString := s;
|
|
||||||
Result := NewGuyForm.PoorCodeDesign.Encode;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure Roll(stat: TPanel);
|
|
||||||
begin
|
|
||||||
stat.Tag := 3 + Random(6) + Random(6) + Random(6);
|
|
||||||
stat.Caption := IntToStr(stat.Tag);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function Choose(n, k: Integer): Real;
|
|
||||||
var
|
|
||||||
d, i: Longint;
|
|
||||||
begin
|
|
||||||
Result := n;
|
|
||||||
d := 1;
|
|
||||||
for i := 2 to k do begin
|
|
||||||
Result := Result * (1+n-i);
|
|
||||||
d := d * i;
|
|
||||||
end;
|
|
||||||
Result := Result / d;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TNewGuyForm.RollEm;
|
|
||||||
begin
|
|
||||||
ReRoll.Tag := RandSeed;
|
|
||||||
Roll(STR);
|
Roll(STR);
|
||||||
Roll(CON);
|
Roll(CON);
|
||||||
Roll(DEX);
|
Roll(DEX);
|
||||||
Roll(INT);
|
Roll(INT);
|
||||||
Roll(WIS);
|
Roll(WIS);
|
||||||
Roll(CHA);
|
Roll(CHA);
|
||||||
Total.tag := STR.Tag + Con.Tag + DEX.Tag + Int.Tag + Wis.Tag + CHA.Tag;
|
Total.tag = STR.Tag + Con.Tag + DEX.Tag + Int.Tag + Wis.Tag + CHA.Tag;
|
||||||
Total.Caption := IntToStr(Total.Tag);
|
Total.Caption = IntToStr(Total.Tag);
|
||||||
if Total.Tag >= (63+18) then Total.Color := clRed
|
if (Total.Tag >= (63+18)) Total.Color = clRed
|
||||||
else if Total.Tag > (4 * 18) then Total.Color := clYellow
|
else if (Total.Tag > (4 * 18)) Total.Color = clYellow
|
||||||
else if Total.Tag <= (63-18) then Total.Color := clGray
|
else if (Total.Tag <= (63-18)) Total.Color = clGray
|
||||||
else if Total.Tag < (3 * 18) then Total.Color := clSilver
|
else if (Total.Tag < (3 * 18)) Total.Color = clSilver
|
||||||
else Total.Color := clWhite;
|
else Total.Color = clWhite;
|
||||||
end;
|
}
|
||||||
|
|
||||||
procedure TNewGuyForm.RerollClick(Sender: TObject);
|
function TNewGuyForm_RerollClick() {
|
||||||
begin
|
|
||||||
OldRolls.Items.Insert(0, IntToStr(ReRoll.Tag));
|
OldRolls.Items.Insert(0, IntToStr(ReRoll.Tag));
|
||||||
Unroll.Enabled := true;
|
Unroll.Enabled = true;
|
||||||
RollEm;
|
RollEm();
|
||||||
end;
|
}
|
||||||
|
|
||||||
function TNewGuyForm.Go: Boolean;
|
function TNewGuyForm_Go() {
|
||||||
begin
|
Tag = 1;
|
||||||
Tag := 1;
|
return mrOk == ShowModa();
|
||||||
Result := mrOk = ShowModal;
|
}
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TNewGuyForm.FormShow(Sender: TObject);
|
function TNewGuyForm_FormShow() {
|
||||||
begin
|
if (Tag > 0) {
|
||||||
if Tag > 0 then begin
|
Tag = 0;
|
||||||
Tag := 0;
|
Caption = 'Progress Quest - New Character';
|
||||||
Caption := 'Progress Quest - New Character';
|
if (MainForm.GetHostName != '')
|
||||||
if MainForm.GetHostName <> '' then
|
Caption = Caption + ' [' + MainForm.GetHostName + ']';
|
||||||
Caption := Caption + ' [' + MainForm.GetHostName + ']';
|
Randomize();
|
||||||
Randomize;
|
RollEm();
|
||||||
RollEm;
|
with (Race)
|
||||||
with Race do
|
ItemIndex = Random(Items.Count);
|
||||||
ItemIndex := Random(Items.Count);
|
with (Klass)
|
||||||
with Klass do
|
ItemIndex = Random(Items.Count);
|
||||||
ItemIndex := Random(Items.Count);
|
}
|
||||||
end;
|
}
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TNewGuyForm.UnrollClick(Sender: TObject);
|
function TNewGuyForm_UnrollClick() {
|
||||||
begin
|
RandSeed = StrToInt(OldRolls.Items[0]);
|
||||||
RandSeed := StrToInt(OldRolls.Items[0]);
|
|
||||||
OldRolls.Items.Delete(0);
|
OldRolls.Items.Delete(0);
|
||||||
Unroll.Enabled := OldRolls.Items.Count > 0;
|
Unroll.Enabled = OldRolls.Items.Count > 0;
|
||||||
RollEm;
|
RollEm();
|
||||||
end;
|
}
|
||||||
|
|
||||||
procedure TNewGuyForm.ParseSoldResponse(body: String);
|
function TNewGuyForm_ParseSoldResponse(body) {
|
||||||
begin
|
if ((LowerCase(Split(body,0)) == 'ok')) {
|
||||||
if (LowerCase(Split(body,0)) = 'ok') then begin
|
|
||||||
MainForm.SetPasskey(Split(body,1));
|
MainForm.SetPasskey(Split(body,1));
|
||||||
MainForm.SetLogin(GetAccount);
|
MainForm.SetLogin(GetAccount);
|
||||||
MainForm.SetPassword(GetPassword);
|
MainForm.SetPassword(GetPassword);
|
||||||
ModalResult := mrOk;
|
ModalResult = mrOk;
|
||||||
end else begin
|
} else {
|
||||||
ShowMessage(body);
|
ShowMessage(body);
|
||||||
end;
|
}
|
||||||
end;
|
}
|
||||||
|
|
||||||
function TNewGuyForm.GetAccount: String;
|
function TNewGuyForm_GetAccount() {
|
||||||
begin
|
return Account.Visible ? Account.Text : '';
|
||||||
Result := '';
|
}
|
||||||
if Account.Visible then Result := Account.Text;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TNewGuyForm.GetPassword: String;
|
function TNewGuyForm_GetPassword() {
|
||||||
begin
|
return (Password.Visible) ? Password.Text : '';
|
||||||
Result := '';
|
}
|
||||||
if Password.Visible then Result := Password.Text;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TNewGuyForm.SoldClick(Sender: TObject);
|
function TNewGuyForm_SoldClick() {
|
||||||
var url, args: String;
|
if (MainForm.GetHostAddr == '') {
|
||||||
begin
|
ModalResult = mrOk;
|
||||||
if MainForm.GetHostAddr = ''
|
} else {
|
||||||
then ModalResult := mrOk
|
try {
|
||||||
else begin
|
Screen.Cursor = crHourglass;
|
||||||
try
|
try {
|
||||||
Screen.Cursor := crHourglass;
|
if ((MainForm.Label8.Tag && 16) == 0
|
||||||
try
|
) url = MainForm.GetHostAddr
|
||||||
if (MainForm.Label8.Tag and 16) = 0
|
else url = 'http://www.progressquest.com/create.php?';
|
||||||
then url := MainForm.GetHostAddr
|
// url = StringReplace(url, '.com/', '.com/dev/', []);
|
||||||
else url := 'http://www.progressquest.com/create.php?';
|
if ((GetAccount() != '') || (GetPassword != ''))
|
||||||
// url := StringReplace(url, '.com/', '.com/dev/', []);
|
url = StuffString(url, 8, 0, GetAccount() + ':' + GetPassword() + '@');
|
||||||
if (GetAccount <> '') or (GetPassword <> '') then
|
args = 'cmd=create' +
|
||||||
url := StuffString(url, 8, 0, GetAccount+':'+GetPassword+'@');
|
|
||||||
args := 'cmd=create' +
|
|
||||||
'&name=' + UrlEncode(Name.Text) +
|
'&name=' + UrlEncode(Name.Text) +
|
||||||
'&realm=' + UrlEncode(MainForm.GetHostName) +
|
'&realm=' + UrlEncode(MainForm.GetHostName) +
|
||||||
RevString;
|
RevString;
|
||||||
ParseSoldResponse(DownloadString(url + args));
|
ParseSoldResponse(DownloadString(url + args));
|
||||||
except
|
} catch (EWebError) {
|
||||||
on EWebError do begin
|
|
||||||
ShowMessage('Error connecting to server');
|
ShowMessage('Error connecting to server');
|
||||||
end;
|
}
|
||||||
end;
|
} finally {
|
||||||
finally
|
Screen.Cursor = crDefault;
|
||||||
Screen.Cursor := crDefault;
|
}
|
||||||
end;
|
}
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
{
|
|
||||||
procedure TNewGuyForm.ServerAboutToSend(Sender: TObject);
|
|
||||||
begin
|
|
||||||
Server.SendHeader.Values['Content-Type'] := 'text/plain';
|
|
||||||
Server.SendHeader.Values['Motto'] := MainForm.GetMotto;
|
|
||||||
Server.SendHeader.Values['Guild'] := MainForm.GetGuild;
|
|
||||||
end;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
procedure TNewGuyForm.ApplicationEvents1Minimize(Sender: TObject);
|
function TNewGuyForm_ApplicationEvents1Minimize() {
|
||||||
begin
|
MainForm.MinimizeIt();
|
||||||
MainForm.MinimizeIt;
|
}
|
||||||
end;
|
|
||||||
|
|
||||||
function GenerateName: string;
|
function GenerateName() {
|
||||||
const
|
var KParts = [
|
||||||
KParts: array [0..2] of string = (
|
|
||||||
'br|cr|dr|fr|gr|j|kr|l|m|n|pr||||r|sh|tr|v|wh|x|y|z',
|
'br|cr|dr|fr|gr|j|kr|l|m|n|pr||||r|sh|tr|v|wh|x|y|z',
|
||||||
'a|a|e|e|i|i|o|o|u|u|ae|ie|oo|ou',
|
'a|a|e|e|i|i|o|o|u|u|ae|ie|oo|ou',
|
||||||
'b|ck|d|g|k|m|n|p|t|v|x|z');
|
'b|ck|d|g|k|m|n|p|t|v|x|z'];
|
||||||
var
|
|
||||||
i: Integer;
|
|
||||||
|
|
||||||
function Pick(s: string): string;
|
function Pick(s) {
|
||||||
var
|
var count = 1;
|
||||||
count, i: Integer;
|
for (var i = 0; i <= Length(s)-1; ++i)
|
||||||
begin
|
if (s[i] == '|') Inc(count);
|
||||||
count := 1;
|
return Split(s, Random(count));
|
||||||
for i := 0 to Length(s)-1 do
|
}
|
||||||
if s[i] = '|' then Inc(count);
|
|
||||||
Result := Split(s, Random(count));
|
|
||||||
end;
|
|
||||||
begin
|
|
||||||
for i := 0 to 5 do
|
|
||||||
Result := Result + Pick(KParts[i mod 3]);
|
|
||||||
Result := UpperCase(Copy(Result,1,1)) + Copy(Result,2,Length(Result));
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TNewGuyForm.GenClick(Sender: TObject);
|
var result = '';
|
||||||
begin
|
for (var i = 0; i <= 5; ++i)
|
||||||
Name.Text := GenerateName;
|
result += Pick(KParts[i % 3]);
|
||||||
end;
|
return UpperCase(Copy(result,1,1)) + Copy(result,2,Length(result));
|
||||||
|
}
|
||||||
|
|
||||||
procedure TNewGuyForm.FormActivate(Sender: TObject);
|
function TNewGuyForm_GenClick() {
|
||||||
begin
|
Name.Text = GenerateName();
|
||||||
if Name.Text = '' then begin
|
}
|
||||||
GenClick(Sender);
|
|
||||||
Name.SetFocus;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TNewGuyForm.FormCreate(Sender: TObject);
|
function TNewGuyForm_FormActivate() {
|
||||||
var
|
if (Name.Text == '') {
|
||||||
i: Integer;
|
GenClick();
|
||||||
begin
|
Name.SetFocus();
|
||||||
Race.Items.Clear;
|
}
|
||||||
for i := 0 to K.Races.Lines.Count-1 do
|
}
|
||||||
|
|
||||||
|
function TNewGuyForm_FormCreate() {
|
||||||
|
Race.Items.Clear();
|
||||||
|
for (var i = 0; i <= K.Races.Lines.Count-1; ++i)
|
||||||
Race.Items.Add(Split(K.Races.Lines[i],0));
|
Race.Items.Add(Split(K.Races.Lines[i],0));
|
||||||
Klass.Items.Clear;
|
Klass.Items.Clear();
|
||||||
for i := 0 to K.Klasses.Lines.Count-1 do
|
for (var i = 0; i <= K.Klasses.Lines.Count-1; ++i)
|
||||||
Klass.Items.Add(Split(K.Klasses.Lines[i],0));
|
Klass.Items.Add(Split(K.Klasses.Lines[i],0));
|
||||||
end;
|
}
|
||||||
|
|
||||||
end.
|
|
||||||
|
|||||||
Reference in New Issue
Block a user