localdb.pas

来自「2009最新 传奇汉化0599代码 传奇汉化」· PAS 代码 · 共 1,924 行 · 第 1/5 页

PAS
1,924
字号
              //nFlag,boFlag,Monster,Item,Quest,boGrouped
            end else Result:= -i;
          end else Result:= -i;
        end;
      end;
      tMapQuestList.Free;
    end;
    QMangeNPC();
    QFunctionNPC();
    RobotNPC();
end;


function TFrmDB.LoadMerchant(): Integer;
var
{$IFDEF UseTXT}
  sFileName,sLineText,sScript,sMapName,sX,sY,sName,sFlag,sAppr,sIsCalste,sCanMove,sMoveTime:String;
  tMerchantList:TStringList;
  tMerchantNPC:TMerchant;
  i:Integer;
{$ELSE}
  i:Integer;
  boUse:Boolean;
  tMerchantNPC:TMerchant;
ResourceString
  sSQLString = 'SELECT * FROM TBL_MERCHANT';
{$ENDIF}
begin
  Result:= -1;
  EnterCriticalSection(ProcessHumanCriticalSection);
  try
{$IFDEF UseTXT}
    sFileName:=g_Config.sEnvirDir + 'Merchant.txt';
    if FileExists(sFileName) then begin
      tMerchantList:=TStringList.Create;
      tMerchantList.LoadFromFile(sFileName);
      for i:=0 to tMerchantList.Count -1 do begin
        sLineText:=Trim(tMerchantList.Strings[i]);
        if (sLineText <> '') and (sLineText[1] <> ';') then begin
          sLineText:=GetValidStr3(sLineText, sScript, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sMapName, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sX, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sY, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sName, [' ', #9]);
          if (sName <> '') and (sName[1] = '"') then
            ArrestStringEx(sName,'"','"',sName);
          sLineText:=GetValidStr3(sLineText, sFlag, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sAppr, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sIsCalste, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sCanMove, [' ', #9]);
          sLineText:=GetValidStr3(sLineText, sMoveTime, [' ', #9]);

          if (sScript <> '') and (sMapName <> '') and (sAppr <> '') then begin
            tMerchantNPC:=TMerchant.Create;
            tMerchantNPC.m_sScript:=sScript;
            tMerchantNPC.m_sMapName:=sMapName;
            tMerchantNPC.m_nCurrX:=Str_ToInt(sX,0);
            tMerchantNPC.m_nCurrY:=Str_ToInt(sY,0);
            tMerchantNPC.m_sCharName:=sName;
            tMerchantNPC.m_nFlag:=Str_ToInt(sFlag,0);
            tMerchantNPC.m_wAppr:=Str_ToInt(sAppr,0);
            tMerchantNPC.m_dwMoveTime:=Str_ToInt(sMoveTime,0);
            if Str_ToInt(sIsCalste,0) <> 0 then
              tMerchantNPC.m_boCastle:=True;
            if (Str_ToInt(sCanMove,0) <> 0) and (tMerchantNPC.m_dwMoveTime > 0) then
              tMerchantNPC.m_boCanMove:=True;
            UserEngine.AddMerchant(tMerchantNPC); //00487B4D
          end;
        end;
      end;
      tMerchantList.Free;
    end;
    Result:= 1;
{$ELSE}
  try
    UseSQL();
    Query.SQL.Clear;
    Query.SQL.Add(sSQLString);
    try
      Query.Open;
    except
      Result:= -2;
    end;
    for i:=0 to Query.RecordCount -1 do begin
      boUse                       := GetBoolean(Query,'FLD_ENABLED');
      if boUse then begin
        tMerchantNPC:=TMerchant.Create;

        tMerchantNPC.m_sScript      := Query.FieldByName('FLD_SCRIPTFILE').AsString;
        tMerchantNPC.m_sMapName     := Query.FieldByName('FLD_MAPNAME').AsString;
        tMerchantNPC.m_nCurrX       := Query.FieldByName('FLD_X').AsInteger;
        tMerchantNPC.m_nCurrY       := Query.FieldByName('FLD_Y').AsInteger;
        tMerchantNPC.m_sCharName    := Query.FieldByName('FLD_NAME').AsString;
        tMerchantNPC.m_nFlag        := Query.FieldByName('FLD_FLAG').AsInteger;
        tMerchantNPC.m_wAppr        := Query.FieldByName('FLD_APPEARANCE').AsInteger;
        tMerchantNPC.m_boCastle     := GetBoolean(Query,'FLD_ISCASTLE');
        tMerchantNPC.m_boCanMove    := GetBoolean(Query,'FLD_CANMOVE');
        tMerchantNPC.m_dwMoveTime   := Query.FieldByName('FLD_MOVETIME').AsInteger;
        
        if (tMerchantNPC.m_sScript <> '') and (tMerchantNPC.m_sMapName <> '') then
          UserEngine.AddMerchant(tMerchantNPC)
        else
          tMerchantNPC.Free;
      end;

      Result := 1;
      Query.Next;
    end;
  finally
    Query.Close;
  end;
{$ENDIF}
  finally
    LeaveCriticalSection(ProcessHumanCriticalSection);
  end;
end;

//004867F4
function TFrmDB.LoadMonGen(): Integer;
{$IFDEF UseTXT}
  procedure LoadMapGen(MonGenList:TStringList;sFileName:String);
  var
    I: Integer;
    sFilePatchName:String;
    sFileDir:String;
    LoadList:TStringList;
  begin
    sFileDir:=g_Config.sEnvirDir + 'MonGen\';
    if not DirectoryExists(sFileDir) then begin
      CreateDir(sFileDir);
    end;
      
    sFilePatchName:=sFileDir + sFileName;
    if FileExists(sFilePatchName) then begin
      LoadList:=TStringList.Create;
      LoadList.LoadFromFile(sFilePatchName);
      for I := 0 to LoadList.Count - 1 do begin
        MonGenList.Add(LoadList.Strings[I]);
      end;
      LoadList.Free;
    end;
  end;
var
  sFileName,sLineText,sData:String;
  MonGenInfo:pTMonGenInfo;
  LoadList:TStringList;
  sMapGenFile:String;
  i:Integer;
{$ELSE}
var
  i:Integer;
  boLoads:Boolean;
  MonGenInfo:pTMonGenInfo;
ResourceString
  sSQLString = 'SELECT * FROM TBL_MONGEN ORDER BY FLD_MAPNAME';
  {$ENDIF}
begin
  Result:=0;
  EnterCriticalSection(ProcessHumanCriticalSection);
  try
    {$IFDEF UseTXT}
    sFileName:=g_Config.sEnvirDir + 'MonGen.txt';
    if FileExists(sFileName) then begin
      LoadList:=TStringList.Create;
      LoadList.LoadFromFile(sFileName);
      I:=0;
      while (True) do begin
        if I >= LoadList.Count then break;
        if CompareLStr('loadgen',LoadList.Strings[I],Length('loadgen')) then begin
          sMapGenFile:=GetValidStr3(LoadList.Strings[I], sLineText, [' ', #9]);
          LoadList.Delete(I);
          if sMapGenFile <> '' then begin
            LoadMapGen(LoadList,sMapGenFile);
          end;
        end;
        Inc(I);
      end;
      for i:=0 to LoadList.Count -1 do begin
        sLineText:=LoadList.Strings[i];
        if (sLineText <> '') and (sLineText[1] <> ';') then begin
          New(MonGenInfo);
          sLineText:=GetValidStr3(sLineText, sData, [' ', #9]);
          MonGenInfo.sMapName:=sData;

          sLineText:=GetValidStr3(sLineText, sData, [' ', #9]);
          MonGenInfo.nX:=Str_ToInt(sData,0);

          sLineText:=GetValidStr3(sLineText, sData, [' ', #9]);
          MonGenInfo.nY:=Str_ToInt(sData,0);

          sLineText:=GetValidStrCap(sLineText, sData, [' ', #9]);
          if (sData <> '') and (sData[1] = '"') then
            ArrestStringEx(sData,'"','"',sData);
            
          MonGenInfo.sMonName:=sData;

          sLineText:=GetValidStr3(sLineText, sData, [' ', #9]);
          MonGenInfo.nRange:=Str_ToInt(sData,0);

          sLineText:=GetValidStr3(sLineText, sData, [' ', #9]);
          MonGenInfo.nCount:=Str_ToInt(sData,0);

          sLineText:=GetValidStr3(sLineText, sData, [' ', #9]);
          MonGenInfo.dwZenTime:=Str_ToInt(sData, -1) * 60 * 1000;

          sLineText:=GetValidStr3(sLineText, sData, [' ', #9]);
          MonGenInfo.nMissionGenRate:=Str_ToInt(sData,0); // 1-100
          if (MonGenInfo.sMapName <> '') and
             (MonGenInfo.sMonName <> '') and
             (MonGenInfo.dwZenTime <> 0) and
             (g_MapManager.GetMapInfo(nServerIndex,MonGenInfo.sMapName) <> nil) then begin

            MonGenInfo.CertList:=TList.Create;
            MonGenInfo.Envir:=g_MapManager.FindMap(MonGenInfo.sMapName);
            if MonGenInfo.Envir <> nil then begin
              UserEngine.m_MonGenList.Add(MonGenInfo);
            end else begin
              Dispose(MonGenInfo);
            end;
          end;
          //tMonGenInfo.nRace:=UserEngine.GetMonRace(tMonGenInfo.sMonName);

        end;//00486B5B
      end;//00486B67
      //00486B67
      New(MonGenInfo);
      MonGenInfo.sMapName:='';
      MonGenInfo.sMonName:='';
      MonGenInfo.CertList:=TList.Create;
      MonGenInfo.Envir:=nil;
      UserEngine.m_MonGenList.Add(MonGenInfo);

      LoadList.Free;
      Result:=1;
    end;      
    {$ELSE}
    UseSQL();
    Query.SQL.Clear;
    Query.SQL.Add(sSQLString);
    try
      Query.Open;
    except
      Result:= -1;
    end;
    for i:=0 to Query.RecordCount -1 do begin
      boLoads                 := GetBoolean(Query,'FLD_LOAD');
      if boLoads then begin
        New(MonGenInfo);
        MonGenInfo.sMapName   := Trim(Query.FieldByName('FLD_MAPNAME').AsString);
        MonGenInfo.nX         := Query.FieldByName('FLD_X').AsInteger;
        MonGenInfo.nY         := Query.FieldByName('FLD_Y').AsInteger;
        MonGenInfo.sMonName   := Trim(Query.FieldByName('FLD_MONNAME').AsString);
        MonGenInfo.nRange     := Query.FieldByName('FLD_RANGE').AsInteger;
        MonGenInfo.nCount     := Query.FieldByName('FLD_COUNT').AsInteger;
        MonGenInfo.dwZenTime  := Query.FieldByName('FLD_GENTIME').AsInteger * 60 * 1000;
        MonGenInfo.nMissionGenRate  := Query.FieldByName('FLD_SMALLGENRATE').AsInteger;

        if (MonGenInfo.sMapName <> '') and
           (MonGenInfo.sMonName <> '') and
           (MonGenInfo.dwZenTime <> 0) and
           (g_MapManager.GetMapInfo(nServerIndex,MonGenInfo.sMapName) <> nil) then begin

          MonGenInfo.CertList:=TList.Create;
          MonGenInfo.Envir:=g_MapManager.FindMap(MonGenInfo.sMapName);
          if MonGenInfo.Envir <> nil then begin
            UserEngine.m_MonGenList.Add(MonGenInfo);
          end else begin
            Dispose(MonGenInfo);
          end;
        end;
      end;

      Result := 1;
      Query.Next;
    end;
    Query.Close;
  {$ENDIF}
  finally
    LeaveCriticalSection(ProcessHumanCriticalSection);
  end;
end;


//00485E04
function TFrmDB.LoadMonsterDB():Integer;
var
  i:Integer;
  Monster:pTMonInfo;
ResourceString
  sSQLString = 'SELECT * FROM TBL_MONSTER';
begin
  Result:=0;
  EnterCriticalSection(ProcessHumanCriticalSection);
  try
    for I := 0 to UserEngine.MonsterList.Count - 1 do begin
      Dispose(pTMonInfo(UserEngine.MonsterList.Items[I]));
    end;
    UserEngine.MonsterList.Clear;
    UseSQL();
    Query.SQL.Clear;
    Query.SQL.Add(sSQLString);
    try
      Query.Open;
    except
      Result:= -1;
    end;
    for i:=0 to Query.RecordCount -1 do begin
      New(Monster);
      Monster.ItemList     := TList.Create;
      Monster.sName        := Trim(Query.FieldByName('FLD_NAME').AsString);
      Monster.btRace       := Query.FieldByName('FLD_RACE').AsInteger;
      Monster.btRaceImg    := Query.FieldByName('FLD_RACEIMG').AsInteger;
      Monster.wAppr        := Query.FieldByName('FLD_IMGINDEX').AsInteger;
      Monster.wLevel       := Query.FieldByName('FLD_LV').AsInteger;
      Monster.btLifeAttrib := Query.FieldByName('FLD_UNDEAD').AsInteger;
      Monster.wCoolEye     := Query.FieldByName('FLD_COOLEYE').AsInteger;
      Monster.dwExp        := Query.FieldByName('FLD_EXP').AsInteger;

      if Monster.btRace in [110,111] then begin
        Monster.wHP          := Query.FieldByName('FLD_HP').AsInteger;
      end else begin
        Monster.wHP          := ROUND(Query.FieldByName('FLD_HP').AsInteger * (g_Config.nMonsterPowerRate / 10));
      end;

      Monster.wMP          := ROUND(Query.FieldByName('FLD_MP').AsInteger * (g_Config.nMonsterPowerRate / 10));
      Monster.wAC          := ROUND(Query.FieldByName('FLD_AC').AsInteger * (g_Config.nMonsterPowerRate / 10));
      Monster.wMAC         := ROUND(Query.FieldByName('FLD_MAC').AsInteger * (g_Config.nMonsterPowerRate / 10));
      Monster.wDC          := ROUND(Query.FieldByName('FLD_DC').AsInteger * (g_Config.nMonsterPowerRate / 10));
      Monster.wMaxDC       := ROUND(Query.FieldByName('FLD_DCMAX').AsInteger * (g_Config.nMonsterPowerRate / 10));
      Monster.wMC          := ROUND(Query.FieldByName('FLD_MC').AsInteger * (g_Config.nMonsterPowerRate / 10));
      Monster.wSC          := ROUND(Query.FieldByName('FLD_SC').AsInteger * (g_Config.nMonsterPowerRate / 10));
      Monster.wSpeed       := Query.FieldByName('FLD_AGILITY').AsInteger;
      Monster.wHitPoint    := Query.FieldByName('FLD_ACCURATE').AsInteger;
      Monster.wWalkSpeed   := _MAX(200,Query.FieldByName('FLD_WALK_SPD').AsInteger);
      Monster.wWalkStep    := _MAX(1,Query.FieldByName('FLD_WALKSTEP').AsInteger);
      Monster.wWalkWait    := Query.FieldByName('FLD_WALKWAIT').AsInteger;
      Monster.wAttackSpeed := Query.FieldByName('FLD_ATTACK_SPD').AsInteger;
      Monster.wAntiPush    := Query.FieldByName('FLD_ATTACK_SPD').AsInteger;
      Monster.boAggro      := GetBoolean(Query,'FLD_AGGRO');
      Monster.boTame       := GetBoolean(Query,'FLD_TAME');

      if Monster.wWalkSpeed < 200 then Monster.wWalkSpeed:= 200;
      if Monster.wAttackSpeed < 200 then Monster.wAttackSpeed:= 200;
      Monster.ItemList:=nil;
      LoadMonitems(Monster.sName,Monster.ItemList);

      UserEngine.MonsterList.Add(Monster);
      Result := 1;
      Query.Next;
    end;
    Query.Close;
  finally
    LeaveCriticalSection(ProcessHumanCriticalSection);
  end;
end;

function TFrmDB.LoadMonitems(MonName:String;var ItemList:TList):Integer;//00485ABC
var
  I: Integer;
  s24:String;
  LoadList:TStringList;
  MonItem:pTMonItem;
  s28,s2C,s30:String;
  n18,n1C,n20:Integer;
begin
  Result:=0;
  s24:=g_Config.sEnvirDir + 'MonItems\' + MonName + '.txt';
  if FileExists(s24) then begin
    if ItemList <> nil then begin
      for I := 0 to Itemlist.Count - 1 do begin
        DisPose(pTMonItem(ItemList.Items[I]));
      end;
      ItemList.Clear;
    end; //00485B81
    LoadList:=TStringList.Create;
    LoadList.LoadFromFile(s24);
    for I := 0 to LoadList.Count - 1 do begin
      s28:=LoadList.Strings[I];
      if (s28 <> '') and (s28[1] <> ';') then begin
        s28:=GetValidStr3(s28,s30,[' ','/',#9]);
        n18:=Str_ToInt(s30,-1);
        s28:=GetValidStr3(s28,s30,[' ','/',#9]);
        n1C:=Str_ToInt(s30,-1);
        s28:=GetValidStr3(s28,s30,[' ',#9]);
        if s30 <> '' then begin

⌨️ 快捷键说明

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