📄 castle.pas
字号:
m_CenterWall.sName:=CastleConf.ReadString('Defense','CenterWallName','CenterWall');
m_CenterWall.nHP:=CastleConf.ReadInteger('Defense','CenterWallHP',2000);
m_CenterWall.BaseObject:=nil;
m_RightWall.nX:=CastleConf.ReadInteger('Defense','RightWallX',634);
m_RightWall.nY:=CastleConf.ReadInteger('Defense','RightWallY',271);
m_RightWall.sName:=CastleConf.ReadString('Defense','RightWallName','RightWall');
m_RightWall.nHP:=CastleConf.ReadInteger('Defense','RightWallHP',2000);
m_RightWall.BaseObject:=nil;
for I := Low(m_Archer) to High(m_Archer) do begin
ObjUnit:=@m_Archer[I];
ObjUnit.nX:=CastleConf.ReadInteger('Defense','Archer_' + IntToStr(I + 1) + '_X',0);
ObjUnit.nY:=CastleConf.ReadInteger('Defense','Archer_' + IntToStr(I + 1) + '_Y',0);
ObjUnit.sName:=CastleConf.ReadString('Defense','Archer_' + IntToStr(I + 1) + '_Name','Archer');
ObjUnit.nHP:=CastleConf.ReadInteger('Defense','Archer_' + IntToStr(I + 1) + '_HP',2000);
ObjUnit.BaseObject:=nil;
end;
for I := Low(m_Guard) to High(m_Guard) do begin
ObjUnit:=@m_Guard[I];
ObjUnit.nX:=CastleConf.ReadInteger('Defense','Guard_' + IntToStr(I + 1) + '_X',0);
ObjUnit.nY:=CastleConf.ReadInteger('Defense','Guard_' + IntToStr(I + 1) + '_Y',0);
ObjUnit.sName:=CastleConf.ReadString('Defense','Guard_' + IntToStr(I + 1) + '_Name','Guard');
ObjUnit.nHP:=CastleConf.ReadInteger('Defense','Guard_' + IntToStr(I + 1) + '_HP',2000);
ObjUnit.BaseObject:=nil;
end;
CastleConf.Free;
end;
m_MasterGuild:=g_GuildManager.FindGuild(m_sOwnGuild);
end;
procedure TUserCastle.SaveConfigFile();//0048EFCC
var
CastleConf:TIniFile;
ObjUnit:pTObjUnit;
sFileName,sConfigFile:String;
sMapList:String;
I:Integer;
begin
if not DirectoryExists(g_Config.sCastleDir + m_sConfigDir) then begin
CreateDir(g_Config.sCastleDir + m_sConfigDir);
end;
if g_MapManager.GetMapOfServerIndex(m_sMapName) <> nServerIndex then exit;
sConfigFile:='SabukW.txt';
sFileName:=g_Config.sCastleDir + m_sConfigDir + '\' + sConfigFile;
CastleConf:=TIniFile.Create(sFileName);
if CastleConf <> nil then begin
if m_sName <> '' then CastleConf.WriteString('Setup','CastleName',m_sName);
if m_sOwnGuild <> '' then CastleConf.WriteString('Setup','OwnGuild',m_sOwnGuild);
CastleConf.WriteDateTime('Setup','ChangeDate',m_ChangeDate);
CastleConf.WriteDateTime('Setup','WarDate',m_WarDate);
CastleConf.WriteDateTime('Setup','IncomeToday',m_IncomeToday);
if m_nTotalGold <> 0 then CastleConf.WriteInteger('Setup','TotalGold',m_nTotalGold);
if m_nTodayIncome <> 0 then CastleConf.WriteInteger('Setup','TodayIncome',m_nTodayIncome);
for I := 0 to m_EnvirList.Count - 1 do begin
sMapList:=sMapList+ m_EnvirList.Strings[I] + ',';
end;
if sMapList <> '' then CastleConf.WriteString('Defense','CastleMapList',sMapList);
if m_sMapName <> '' then CastleConf.WriteString('Defense','CastleMap',m_sMapName);
if m_sHomeMap <> '' then CastleConf.WriteString('Defense','CastleHomeMap',m_sHomeMap);
if m_nHomeX <> 0 then CastleConf.WriteInteger('Defense','CastleHomeX',m_nHomeX);
if m_nHomeY <> 0 then CastleConf.WriteInteger('Defense','CastleHomeY',m_nHomeY);
if m_nWarRangeX <> 0 then CastleConf.WriteInteger('Defense','CastleWarRangeX',m_nWarRangeX);
if m_nWarRangeY <> 0 then CastleConf.WriteInteger('Defense','CastleWarRangeY',m_nWarRangeY);
if m_sPalaceMap <> '' then CastleConf.WriteString('Defense','CastlePlaceMap',m_sPalaceMap);
if m_sSecretMap <> '' then CastleConf.WriteString('Defense','CastleSecretMap',m_sSecretMap);
if m_nPalaceDoorX <> 0 then CastleConf.WriteInteger('Defense','CastlePalaceDoorX',m_nPalaceDoorX);
if m_nPalaceDoorY <> 0 then CastleConf.WriteInteger('Defense','CastlePalaceDoorY',m_nPalaceDoorY);
if m_MainDoor.nX <> 0 then CastleConf.WriteInteger('Defense','MainDoorX',m_MainDoor.nX);
if m_MainDoor.nY <> 0 then CastleConf.WriteInteger('Defense','MainDoorY',m_MainDoor.nY);
if m_MainDoor.sName <> '' then CastleConf.WriteString('Defense','MainDoorName',m_MainDoor.sName);
if m_MainDoor.BaseObject <> nil then begin
CastleConf.WriteBool('Defense','MainDoorOpen',m_MainDoor.nStatus);
CastleConf.WriteInteger('Defense','MainDoorHP',m_MainDoor.BaseObject.m_WAbil.HP);
end;
if m_LeftWall.nX <> 0 then CastleConf.WriteInteger('Defense','LeftWallX',m_LeftWall.nX);
if m_LeftWall.nY <> 0 then CastleConf.WriteInteger('Defense','LeftWallY',m_LeftWall.nY);
if m_LeftWall.sName <> '' then CastleConf.WriteString('Defense','LeftWallName',m_LeftWall.sName);
if m_LeftWall.BaseObject <> nil then begin
CastleConf.WriteInteger('Defense','LeftWallHP',m_LeftWall.BaseObject.m_WAbil.HP);
end;
if m_CenterWall.nX <> 0 then CastleConf.WriteInteger('Defense','CenterWallX',m_CenterWall.nX);
if m_CenterWall.nY <> 0 then CastleConf.WriteInteger('Defense','CenterWallY',m_CenterWall.nY);
if m_CenterWall.sName <> '' then CastleConf.WriteString('Defense','CenterWallName',m_CenterWall.sName);
if m_CenterWall.BaseObject <> nil then begin
CastleConf.WriteInteger('Defense','CenterWallHP',m_CenterWall.BaseObject.m_WAbil.HP);
end;
if m_RightWall.nX <> 0 then CastleConf.WriteInteger('Defense','RightWallX',m_RightWall.nX);
if m_RightWall.nY <> 0 then CastleConf.WriteInteger('Defense','RightWallY',m_RightWall.nY);
if m_RightWall.sName <> '' then CastleConf.WriteString('Defense','RightWallName',m_RightWall.sName);
if m_RightWall.BaseObject <> nil then begin
CastleConf.WriteInteger('Defense','RightWallHP',m_RightWall.BaseObject.m_WAbil.HP);
end;
for I := Low(m_Archer) to High(m_Archer) do begin
ObjUnit:=@m_Archer[I];
if ObjUnit.nX <> 0 then CastleConf.WriteInteger('Defense','Archer_' + IntToStr(I + 1) + '_X',ObjUnit.nX);
if ObjUnit.nY <> 0 then CastleConf.WriteInteger('Defense','Archer_' + IntToStr(I + 1) + '_Y',ObjUnit.nY);
if ObjUnit.sName <> '' then CastleConf.WriteString('Defense','Archer_' + IntToStr(I + 1) + '_Name',ObjUnit.sName);
if ObjUnit.BaseObject <> nil then begin
CastleConf.WriteInteger('Defense','Archer_' + IntToStr(I + 1) + '_HP',ObjUnit.BaseObject.m_WAbil.HP);
end else begin
CastleConf.WriteInteger('Defense','Archer_' + IntToStr(I + 1) + '_HP',0);
end;
end;
for I := Low(m_Guard) to High(m_Guard) do begin
ObjUnit:=@m_Guard[I];
if ObjUnit.nX <> 0 then CastleConf.WriteInteger('Defense','Guard_' + IntToStr(I + 1) + '_X',ObjUnit.nX);
if ObjUnit.nY <> 0 then CastleConf.WriteInteger('Defense','Guard_' + IntToStr(I + 1) + '_Y',ObjUnit.nY);
if ObjUnit.sName <> '' then CastleConf.WriteString('Defense','Guard_' + IntToStr(I + 1) + '_Name',ObjUnit.sName);
if ObjUnit.BaseObject <> nil then begin
CastleConf.WriteInteger('Defense','Guard_' + IntToStr(I + 1) + '_HP',ObjUnit.BaseObject.m_WAbil.HP);
end else begin
CastleConf.WriteInteger('Defense','Guard_' + IntToStr(I + 1) + '_HP',0);
end;
end;
CastleConf.Free;
end;
end;
procedure TUserCastle.LoadAttackSabukWall();//0048ED60
var
I: Integer;
sFileName,sConfigFile:String;
LoadList:TStringList;
sData:String;
s20,sGuildName:String;
Guild:TGuild;
AttackerInfo:pTAttackerInfo;
begin
// sFileName:=g_Config.sCastleDir + 'AttackSabukWall.txt';
if not DirectoryExists(g_Config.sCastleDir + m_sConfigDir) then begin
CreateDir(g_Config.sCastleDir + m_sConfigDir);
end;
sConfigFile:='AttackSabukWall.txt';
sFileName:=g_Config.sCastleDir + m_sConfigDir + '\' + sConfigFile;
if FileExists(sFileName) then begin
LoadList:=TStringList.Create;
try
LoadList.LoadFromFile(sFileName);
for I := 0 to m_AttackWarList.Count - 1 do begin
Dispose(pTAttackerInfo(m_AttackWarList.Items[I]));
end;
m_AttackWarList.Clear;
for I := 0 to LoadList.Count - 1 do begin
sData:=LoadList.Strings[I];
s20:=GetValidStr3(sData,sGuildName,[' ',#9]);
Guild:=g_GuildManager.FindGuild(sGuildName);
if Guild <> nil then begin
New(AttackerInfo);
ArrestStringEx(s20,'"','"',s20);
try
AttackerInfo.AttackDate:=StrToDate(s20);
except
AttackerInfo.AttackDate:=Now();
end;
AttackerInfo.sGuildName:=sGuildName;
AttackerInfo.Guild:=Guild;
m_AttackWarList.Add(AttackerInfo);
end;
end;
except
MainOutMessage('[Error] UserCastle.LoadAttackSabukWall');
end;
LoadList.Free;
end;
end;
procedure TUserCastle.SaveAttackSabukWall();//0048EBD0
var
I: Integer;
sFileName,sConfigFile:String;
LoadLis:TStringList;
AttackerInfo:pTAttackerInfo;
begin
if not DirectoryExists(g_Config.sCastleDir + m_sConfigDir) then begin
CreateDir(g_Config.sCastleDir + m_sConfigDir);
end;
sConfigFile:='AttackSabukWall.txt';
sFileName:=g_Config.sCastleDir + m_sConfigDir + '\' + sConfigFile;
LoadLis:=TStringList.Create;
for I := 0 to m_AttackWarList.Count - 1 do begin
AttackerInfo:=m_AttackWarList.Items[I];
LoadLis.Add(AttackerInfo.sGuildName + ' "' + DateToStr(AttackerInfo.AttackDate) + '"');
end;
try
LoadLis.SaveToFile(sFileName);
except
MainOutMessage('保存攻城信息失败: ' + sFileName);
end;
LoadLis.Free;
end;
procedure TUserCastle.Run;//0048FE4C
{$IF SoftVersion <> VERDEMO}
var
I: Integer;
Year, Month, Day, Hour, Min, Sec, MSec: Word;
wYear, wMonth, wDay: Word;
AttackerInfo:pTAttackerInfo;
s20:String;
{$IFEND}
ResourceString
sWarStartMsg = '[%s 攻城战已经开始]';
sWarStopTimeMsg = '[%s 攻城战离结束还有%d分钟]';
sExceptionMsg = '[Exception] TUserCastle::Run';
begin
try
if nServerIndex <> g_MapManager.GetMapOfServerIndex(m_sMapName) then exit;
{$IF SoftVersion <> VERDEMO}
DecodeDate(Now,Year,Month,Day);
DecodeDate(m_IncomeToday,wYear,wMonth,wDay);
if (Year <> wYear) or (Month <> wMonth) or (Day <> wDay) then begin
m_nTodayIncome:=0;
m_IncomeToday:=Now();
m_boStartWar:=False;
end;
if not m_boStartWar and (not m_boUnderWar) then begin
DecodeTime(Time,Hour, Min, Sec, MSec);
if Hour = g_Config.nStartCastlewarTime{20} then begin
m_boStartWar := True;;
m_AttackGuildList.Clear;
for I := m_AttackWarList.Count - 1 downto 0 do begin
AttackerInfo:=m_AttackWarList.Items[I];
DecodeDate(AttackerInfo.AttackDate,wYear,wMonth,wDay);
if (Year = wYear) and (Month = wMonth) and (Day = wDay) then begin
m_boUnderWar:=True;
m_boShowOverMsg:=False;
m_WarDate:=Now();
m_dwStartCastleWarTick:=GetTickCount();
m_AttackGuildList.Add(AttackerInfo.Guild);
Dispose(AttackerInfo);
m_AttackWarList.Delete(I);
end;
end;
if m_boUnderWar then begin
m_AttackGuildList.Add(m_MasterGuild);
StartWallconquestWar();
SaveAttackSabukWall();
UserEngine.SendServerGroupMsg(SS_212,nServerIndex,'');
s20:=format(sWarStartMsg,[m_sName]);
UserEngine.SendBroadCastMsgExt(s20,t_System);
UserEngine.SendServerGroupMsg(SS_204,nServerIndex,s20);
MainOutMessage(s20);
MainDoorControl(True);
end;
end;
end;
for i:=Low(m_Guard) to High(m_Guard) do begin
if (m_Guard[i].BaseObject <> nil) and (m_Guard[i].BaseObject.m_boGhost) then begin
m_Guard[i].BaseObject:=nil;
end;
end;
for i:=Low(m_Archer) to High(m_Archer) do begin
if (m_Archer[i].BaseObject <> nil) and (m_Archer[i].BaseObject.m_boGhost) then begin
m_Archer[i].BaseObject:=nil;
end;
end;
if m_boUnderWar then begin
if m_LeftWall.BaseObject <> nil then m_LeftWall.BaseObject.m_boStoneMode:=False;
if m_CenterWall.BaseObject <> nil then m_CenterWall.BaseObject.m_boStoneMode:=False;
if m_RightWall.BaseObject <> nil then m_RightWall.BaseObject.m_boStoneMode:=False;
if not m_boShowOverMsg then begin //00490181
if (GetTickCount - m_dwStartCastleWarTick) > (g_Config.dwCastleWarTime - g_Config.dwShowCastleWarEndMsgTime) {3 * 60 * 60 * 1000 - 10 * 60 * 1000} then begin
m_boShowOverMsg:=True;
s20:=format(sWarStopTimeMsg,[m_sName,g_Config.dwShowCastleWarEndMsgTime div (60 * 1000)]);
UserEngine.SendBroadCastMsgExt(s20,t_System);
UserEngine.SendServerGroupMsg(SS_204,nServerIndex,s20);
MainOutMessage(s20);
end;
end;
if (GetTickCount - m_dwStartCastleWarTick) > g_Config.dwCastleWarTime {3 * 60 * 60 * 1000} then begin
StopWallconquestWar();
end;
end else begin
if m_LeftWall.BaseObject <> nil then m_LeftWall.BaseObject.m_boStoneMode:=True;
if m_CenterWall.BaseObject <> nil then m_CenterWall.BaseObject.m_boStoneMode:=True;
if m_RightWall.BaseObject <> nil then m_RightWall.BaseObject.m_boStoneMode:=True;
end;
{$IFEND}
except
MainOutMessage(sExceptionMsg);
end;
end;
procedure TUserCastle.Save; //0048EBA4
begin
SaveConfigFile();
SaveAttackSabukWall();
end;
function TUserCastle.InCastleWarArea(Envir: TEnvirnoment; nX, nY: Integer): Boolean;//004910F4
var
I:Integer;
begin
Result:=False;
if (Envir = m_MapCastle) and
(abs(m_nHomeX - nX) < m_nWarRangeX{100}) and
(abs(m_nHomeY - nY) < m_nWarRangeY{100}) then begin
Result:=True;
exit;
end;
if (Envir = m_MapPalace) or (Envir = m_MapSecret) then begin
Result:=True;
exit;
end;
//增加取得城堡所有地图列表
for I := 0 to m_EnvirList.Count - 1 do begin
if m_EnvirList.Objects[I] = Envir then begin
Result:=True;
break;
end;
end;
end;
function TUserCastle.IsMember(Cert: TBaseObject): Boolean;//00490438
begin
Result:=IsMasterGuild(TGuild(Cert.m_MyGuild));
end;
//检查是否为攻城方行会的联盟行会
function TUserCastle.IsAttackAllyGuild(Guild: TGuild): Boolean;
var
I: Integer;
AttackGuild:TGuild;
begin
Result:=False;
for I := 0 to m_AttackGuildList.Count - 1 do begin
AttackGuild:= TGuild(m_AttackGuildList.Items[I]);
if (AttackGuild <> m_MasterGuild) and AttackGuild.IsAllyGuild(Guild) then begin
Result:=True;
break;
end;
end;
end;
//检查是否为攻城方行会
function TUserCastle.IsAttackGuild(Guild: TGuild): Boolean;//00491160
var
I: Integer;
AttackGuild:TGuild;
begin
Result:=False;
for I := 0 to m_AttackGuildList.Count - 1 do begin
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -