⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sqldata.pas

📁 RO模拟器!!适合玩仙境传说的玩家们呦~
💻 PAS
📖 第 1 页 / 共 5 页
字号:
			// 读取人物组队资料
			for i := 0 to PartyNameList.Count - 1 do begin
				tpa := PartyNameList.Objects[i] as TParty;
				for j := 0 to 11 do begin
					if (tpa.MemberID[j] <> 0) AND (tpa.MemberID[j] = tc.CID) then begin
						tc.PartyName := tpa.Name;
						tpa.Member[j] := tc;
						break;
					end;
				end;
			end;

//	    SQLDataSet.Next;
	  end;
	end else begin
	  debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Get Character data from MySQL Error: %d', [GID]));
		Exit;
	end;

    sl.Free;
end;

//------------------------------------------------------------------------------
// 从数据库删除人物
//------------------------------------------------------------------------------
function DeleteChar(GID: cardinal) : Boolean;
begin
  Result := False;

	debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete Character data from MySQL: %d', [GID]));

  {删除人物资料}
	if not ExecuteSqlCmd(format('DELETE FROM characters WHERE GID=''%d'' LIMIT 1', [GID])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete Character data from MySQL Error: %d', [GID]));
		Exit;
	end;
  {删除人物技能资料}
	if not ExecuteSqlCmd(format('DELETE FROM skills WHERE GID=''%d'' LIMIT 1', [GID])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete Character skill data from MySQL Error: %d', [GID]));
		Exit;
	end;
  {删除人物物品资料}
	if not ExecuteSqlCmd(format('DELETE FROM inventory WHERE GID=''%d'' LIMIT 1', [GID])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete Character item data from MySQL Error: %d', [GID]));
		Exit;
	end;
  {删除人物手推车资料}
	if not ExecuteSqlCmd(format('DELETE FROM cart WHERE GID=''%d'' LIMIT 1', [GID])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete Character cartItem data from MySQL Error: %d', [GID]));
		Exit;
	end;
  {删除人物所在工会成员资料}
	if not ExecuteSqlCmd(format('DELETE FROM guild_members WHERE GID=''%d'' LIMIT 1', [GID])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete guildMinfo data from MySQL Error: %d', [GID]));
		Exit;
	end;
  {删除人物MEMO记录点资料}
	if not ExecuteSqlCmd(format('DELETE FROM warpmemo WHERE GID=''%d'' LIMIT 1', [GID])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete warpInfo data from MySQL Error: %d', [GID]));
		Exit;
	end;

	if not ExecuteSqlCmd(format('DELETE FROM character_flags WHERE GID=''%d'' LIMIT 1', [GID])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Delete character_flag data from MySQL Error: %d', [GID]));
		Exit;
	end;

	Result := True;
end;

//------------------------------------------------------------------------------
// 检查人物是否存在
//------------------------------------------------------------------------------
function  CheckUserExist(userid: String) : Boolean;
begin
  Result := False;

  if not ExecuteSqlCmd(format('SELECT count(GID) as count FROM characters WHERE Name=''%s'' LIMIT 1', [addslashes(userid)])) then begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Get character data from MySQL Error: %s', [userid]));
		Result := True;
		Exit;
	end;
	if SQLDataSet.FieldValues['count'] = 0 then
	  Exit;

	Result := True;
end;

//------------------------------------------------------------------------------
// 取得帐号的宠物资料
//------------------------------------------------------------------------------
function  GetPetData(AID: cardinal) : Boolean;
var
  i   : Integer;
  tpe : TPet;
	tp  : TPlayer;
	tc  : TChara;
begin
  Result := False;

	debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('Load Character''s Pet Data From MySQL: PlayerID = %d', [AID]));

	if ExecuteSqlCmd(Format('SELECT * FROM pet WHERE PlayerID=''%d''', [AID])) then begin
	  while not SQLDataSet.Eof do
    begin
      i := PetDB.IndexOf( StrToInt( SQLDataSet.FieldValues['JID'] ) );
		  if i <> -1 then begin
        tpe := TPet.Create;
        with tpe do begin
          PlayerID    := StrToInt( SQLDataSet.FieldValues['PlayerID'] );
          CharaID     := StrToInt( SQLDataSet.FieldValues['CharaID'] );
          Cart        := StrToInt( SQLDataSet.FieldValues['Cart'] );
          Index       := StrToInt( SQLDataSet.FieldValues['PIndex'] );
          Incubated   := StrToInt( SQLDataSet.FieldValues['Incubated'] );
          PetID       := StrToInt( SQLDataSet.FieldValues['PID'] );
          JID         := StrToInt( SQLDataSet.FieldValues['JID'] );
          Name        := unaddslashes(SQLDataSet.FieldValues['Name']);
          Renamed     := StrToInt( SQLDataSet.FieldValues['Renamed'] );
          LV          := StrToInt( SQLDataSet.FieldValues['LV'] );
					Relation    := StrToInt( SQLDataSet.FieldValues['Relation'] );
          Fullness    := StrToInt( SQLDataSet.FieldValues['Fullness'] );
          Accessory   := StrToInt( SQLDataSet.FieldValues['Accessory'] );

          Data        := PetDB.Objects[i] as TPetDB;
        end;
        PetList.AddObject( tpe.PetID, tpe );

        {把宠物资料对应到人物、帐号上}
			  if tpe.PlayerID <> 0 then begin
				  if tpe.CharaID = 0 then begin  // 在仓库里
					  try
              tp := Player.IndexofObject( tpe.PlayerID ) as TPlayer;
						  with tp.Kafra.Item[ tpe.Index ] do begin
						  	Attr    := 0;
						  	Card[0] := $FF00;
						  	Card[2] := tpe.PetID mod $10000;
						  	Card[3] := tpe.PetID div $10000;
						  end;
						except
						end;
					end else begin
						tc := Chara.IndexOfObject( tpe.CharaID ) as TChara;
						if tpe.Cart = 0 then begin  // 在身上
						  try
							  with tc.Item[ tpe.Index ] do begin
							  	Attr    := tpe.Incubated;
							  	Card[0] := $FF00;
							  	Card[2] := tpe.PetID mod $10000;
							  	Card[3] := tpe.PetID div $10000;
							  end;
							except
							end;
						end else begin  // 在手推车里
						  try
							  with tc.Cart.Item[ tpe.Index ] do begin
						  		Attr    := 0;
						  		Card[0] := $FF00;
						  		Card[2] := tpe.PetID mod $10000;
					  			Card[3] := tpe.PetID div $10000;
								end;
							except
							end;
						end;
					end;
		  	end;
      end;

			SQLDataSet.Next;
		end;
	end else begin
	  debugout.lines.add('[' + TimeToStr(Now) + '] ' + 'Pet data loading error...');
		Exit;
	end;
end;

//------------------------------------------------------------------------------
// 取得当前的帐号ID编号
//------------------------------------------------------------------------------
function  GetNowLoginID() : cardinal;
begin
  Result := 100101;
	if not ExecuteSqlCmd('SELECT AID FROM accounts ORDER BY AID DESC LIMIT 1') then begin
		Exit;
	end;
  SQLDataSet.First;

  if SQLDataSet.Eof then exit;

	Result := StrToInt( SQLDataSet.FieldValues['AID'] ) + 1;
end;
//------------------------------------------------------------------------------
// 取得当前的人物ID编号
//------------------------------------------------------------------------------
function  GetNowCharaID() : cardinal;
begin
  Result := 100001;
	if not ExecuteSqlCmd('SELECT GID FROM characters ORDER BY GID DESC LIMIT 1') then begin
		Exit;
	end;
  SQLDataSet.First;

  if SQLDataSet.Eof then exit;

	Result := StrToInt( SQLDataSet.FieldValues['GID'] ) + 1;
end;
//------------------------------------------------------------------------------
// 取得当前的宠物ID编号
//------------------------------------------------------------------------------
function  GetNowPetID() : cardinal;
begin
  Result := 1;
	if not ExecuteSqlCmd('SELECT PID FROM pet ORDER BY PID DESC LIMIT 1') then begin
		Exit;
	end;
  SQLDataSet.First;

  if SQLDataSet.Eof then exit;

	Result := StrToInt( SQLDataSet.FieldValues['PID'] ) + 1;
end;

//------------------------------------------------------------------------------
// 保存宠物资料(place是指宠物存放的地点,1是身上,2是仓库,3是手推车)
//------------------------------------------------------------------------------
function  SavePetData(tpe : Tpet; PIndex: Integer; place: Integer) : Boolean;
var
  CharaID   : cardinal;
	Cart      : byte;
	Incubated : byte;
begin
  Result := False;

  case place of
	  1: begin
			Cart      := 0;
		  CharaID   := tpe.CharaID;
		  Incubated := tpe.Incubated;
		end;
		2: begin
		  Cart      := 0;
		  CharaID   := 0;
		  Incubated := 0;
		end;
		3: begin
			Cart      := 1;
		  CharaID   := tpe.CharaID;
		  Incubated := 0;
		end;
    else begin
	  Exit;
	  end;
	end;

  if not ExecuteSqlCmd(Format('REPLACE INTO pet (PID,PlayerID,CharaID,Cart,PIndex,Incubated,JID,Name,Renamed,LV,Relation,Fullness,Accessory) VALUES (''%d'',''%d'',''%d'',''%d'',''%d'',''%d'',''%d'',''%s'',''%d'',''%d'',''%d'',''%d'',''%d'')', [tpe.PetID, tpe.PlayerID, CharaID, Cart, PIndex, Incubated, tpe.JID, addslashes(tpe.Name), tpe.Renamed, tpe.LV, tpe.Relation, tpe.Fullness, tpe.Accessory])) then
  begin
    debugout.lines.add('[' + TimeToStr(Now) + '] ' + '*** Save Pet data error.');
		Exit;
  end;

	Result := True;
end;

//------------------------------------------------------------------------------
// 保存工会头衔资料
//------------------------------------------------------------------------------
function  SaveGuildMPosition(GDID: cardinal; PosName: string; PosInvite: boolean; PosPunish: boolean; PosEXP: byte; Grade: Integer) : Boolean;
begin
  Result := False;

  {删除旧资料}
	ExecuteSqlCmd(Format('DELETE FROM guild_positions WHERE GDID=''%d'' AND Grade=''%d'' LIMIT 1', [GDID, Grade]));
  if not ExecuteSqlCmd(Format('INSERT INTO guild_positions (GDID,Grade,PosName,PosInvite,PosPunish,PosEXP) VALUES (''%d'',''%d'',''%s'',''%s'',''%s'',''%d'')', [GDID, Grade, addslashes(PosName), BoolToStr(PosInvite), BoolToStr(PosPunish), PosEXP])) then
	begin
	  debugout.lines.add('[' + TimeToStr(Now) + '] ' + '*** Save Guild Position data error.');
	  Exit;
	end;

	Result := True;
end;

//------------------------------------------------------------------------------
// 取得人物的工会资料
//------------------------------------------------------------------------------
function  GetCharaGuildData(GID: cardinal) : Boolean;
var
  j  : Integer;
  tc : TChara;
	tg : TGuild;
begin
  Result := False;
	
	if not ExecuteSqlCmd(Format('SELECT GDID FROM guild_members WHERE GID=''%d'' LIMIT 1', [GID])) then begin
		Exit;
	end;
  SQLDataSet.First;

	tc := Chara.Objects[Chara.IndexOf(GID)] as TChara;
  if SQLDataSet.Eof then begin
	  tc.GuildID := 0;
		tc.GuildName := '';
		tc.ClassName := '';
		tc.GuildPos := 0;
	  exit;
	end;

  tg := GuildList.Objects[GuildList.IndexOf(StrToInt(SQLDataSet.FieldValues['GDID']))] as TGuild;
	with tg do begin
		for j := 0 to 35 do begin
			if MemberID[j] = tc.CID then begin
				tc.GuildName := Name;
				tc.GuildID := StrToInt(SQLDataSet.FieldValues['GDID']);
				tc.ClassName := PosName[MemberPos[j]];
				tc.GuildPos := j;
				Member[j] := tc;
				if (j = 0) then MasterName := tc.Name;
				SLV := SLV + tc.BaseLV;
				break;
			end;
		end;
	end;

	Result := True;
end;

//------------------------------------------------------------------------------
// 从数据库删除工会成员(mtype=1为退会,mtype=2为开除)
//------------------------------------------------------------------------------
function  DeleteGuildMember(GID: cardinal; mtype: Integer; tgb: TGBan; GDID: cardinal) : Boolean;
begin
  Result := False;
	
	if mtype = 2 then begin
	  if not ExecuteSqlCmd(format('INSERT INTO guild_banish (GDID,MemberName,MemberAccount,Reason) VALUES (''%d'',''%s'',''%s'',''%s'')', [GDID, addslashes(tgb.Name), addslashes(tgb.AccName), addslashes(tgb.Reason)])) then begin
      debugout.lines.add('[' + TimeToStr(Now) + '] ' + format('INSERT guild_banish data to MySQL Error: %d', [GID]));
//		  Exit;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -