unit JobCommon;
interface
uses
Inifiles , SysUtils , Misc , Classes, DebugUnit;
type
EClacSeed = Class(Exception);
TjobClass = Class(TObject)
private
FfHp : double;
FfAp : double;
FfAttack: double;
FfMagic : double;
FfHit : double;
FfEvasion : double;
FfCritical : double;
FfRecoveryHp : double;
FfRecoveryAp : double;
FAssignedSeed : array[0..8] of boolean;
FCAssignedSeed : boolean;
FUseSkillLv : boolean;
FJobData : PJob;
FJDHp : array[0..4] of double;
FJDAp : array[0..4] of double;
FJDAttack : array[0..4] of double;
FJDMagic : array[0..4] of double;
FJDHit : array[0..4] of double;
FJDEvasion : array[0..4] of double;
FJDCritical : array[0..4] of double;
FJDRHP : array[0..4] of double;
FJDRAP : array[0..4] of double;
FStatus : PStatus;
FintLv : integer;
FintStr : integer;
FintCon : integer;
FintInt : integer;
FintPhy : integer;
FintMen : integer;
FintSen : integer;
FintFam : integer;
FOnDataChange: TNotifyEvent;
procedure CalcStatus(const JobData : PJob;const Status : PStatus);
procedure SetStatus(const Value: PStatus);
procedure SetfAP(const Value: double);
procedure SetfAttack(const Value: double);
procedure SetfCritical(const Value: double);
procedure SetfEvasion(const Value: double);
procedure SetfHit(const Value: double);
procedure SetfHP(const Value: double);
procedure SetfMagic(const Value: double);
procedure SetfRecoveryAp(const Value: double);
procedure SetfRecoveryHp(const Value: double);
procedure initializeAssSeed;
procedure DoDataChange;
property Status : PStatus read FStatus write SetStatus;
function GetfState(index:integer):integer;
function AssignedSeed : boolean;
protected
procedure DataChange;virtual;
property fState[index:integer]:integer read GetfState;
published
public
constructor Create;
destructor Destroy; override;
function GetCalcSeedList : string;
property UseSkillLv : boolean read FUseSkillLv write FUseSkillLv default False;
procedure SetStatuses(intLv,intStr,intCon,intInt,intPhy,intMen,
intSen,intFam : integer);
procedure SetJobDatas(jobOp : TJobOption;fSeedA,fSeedB,fSeedC:double;
intFixedA : double = -1;intStatusA : double = -1);
procedure Calc;
procedure Clear;
property OnDataChange : TNotifyEvent read FOnDataChange write FOnDataChange;
property fHp : double read FfHP write SetfHP;
property fAp : double read FfAP write SetfAP;
property fAttack : double read FfAttack write SetfAttack;
property fMagic : double read FfMagic write SetfMagic;
property fHit : double read FfHit write SetfHit;
property fEvasion : double read FfEvasion write SetfEvasion;
property fCritical : double read FfCritical write SetfCritical;
property fRecoveryHp : double read FfRecoveryHp write SetfRecoveryHp stored 0;
property fRecoveryAp : double read FfRecoveryAp write SetfRecoveryAp stored 0;
end;
const
CalcAttention = '係数が正常に初期化されていない可能性があります。';
implementation
constructor TjobClass.Create;
begin
New(FJobData);
New(FJobData.PHp);
New(FJobData.PAp);
New(FJobData.PAttack);
New(FJobData.PMagic);
New(FJobData.PHit);
New(FJobData.PEvasion);
New(FJobData.PCritical);
New(FJobData.PRhp);
New(FJobData.PRap);
New(FStatus);
initializeAssSeed;
DebugOut(ClassParent.ClassName + ' -> ' + ClassName + '.Create');
end;
destructor TjobClass.Destroy;
begin
Dispose(FStatus);
Dispose(FJobData.PRap);
Dispose(FJobData.PRhp);
Dispose(FJobData.PCritical);
Dispose(FJobData.PEvasion);
Dispose(FJobData.PHit);
Dispose(FJobData.PMagic);
Dispose(FJobData.PAttack);
Dispose(FJobData.PAp);
Dispose(FJobData.PHp);
Dispose(FJobData);
DebugOut(ClassParent.ClassName + ' -> ' + ClassName + '.Destroy');
inherited;
end;
procedure TjobClass.initializeAssSeed;
var
i : integer;
begin
FCAssignedSeed := false;
for i:=0 to High(FAssignedSeed) do
begin
FAssignedSeed[i] := false;
end;
end;
function TjobClass.AssignedSeed : boolean;
var
i : integer;
begin
for i:=0 to High(FAssignedSeed) do
begin
if not(FAssignedSeed[i])then
begin
result := false;
exit;
end
else
begin
result := true;
end;
end;
DebugOut(ClassParent.ClassName + ' -> ' + ClassName + '(AssignedSeed)');
end;
procedure TjobClass.DoDataChange;
begin
if Assigned(FOnDataChange) then
FOnDataChange(Self);
end;
procedure TjobClass.DataChange;
begin
DoDataChange;
end;
function TjobClass.GetfState(index:integer):integer;
begin
Result := -1;
case index of
0:Result := Status.intLv;
1:Result := Status.intStr;
2:Result := Status.intCon;
3:Result := Status.intInt;
4:Result := Status.intPhy;
5:Result := Status.intMen;
6:Result := Status.intSen;
7:Result := Status.intFam;
end;
end;
function TjobClass.GetCalcSeedList: string;
var
ResultList : TStringList;
begin
ResultList := TStringList.Create;
try
ResultList.Add('JDHp='+FloattoStr(FJDHp[0])+','+FloattoStr(FJDHp[1])+','+
FloattoStr(FJDHp[2])+','+FloattoStr(FJDHp[3])+','+ FloattoStr(FJDHp[4]));
ResultList.Add('JDAp='+FloattoStr(FJDAp[0])+','+FloattoStr(FJDAp[1])+','+
FloattoStr(FJDAp[2])+','+FloattoStr(FJDAp[3])+','+ FloattoStr(FJDAp[4]));
ResultList.Add('JDAp='+FloattoStr(FJDAp[0])+','+FloattoStr(FJDAp[1])+','+
FloattoStr(FJDAp[2])+','+FloattoStr(FJDAp[3])+','+ FloattoStr(FJDAp[4]));
ResultList.Add('JDAttack='+FloattoStr(FJDAttack[0])+','+FloattoStr(FJDAttack[1])+','+
FloattoStr(FJDAttack[2])+','+FloattoStr(FJDAttack[3])+','+ FloattoStr(FJDAttack[4]));
ResultList.Add('JDMagic='+FloattoStr(FJDMagic[0])+','+FloattoStr(FJDMagic[1])+','+
FloattoStr(FJDMagic[2])+','+FloattoStr(FJDMagic[3])+','+ FloattoStr(FJDMagic[4]));
ResultList.Add('JDHit='+FloattoStr(FJDHit[0])+','+FloattoStr(FJDHit[1])+','+
FloattoStr(FJDHit[2])+','+FloattoStr(FJDHit[3])+','+ FloattoStr(FJDHit[4]));
ResultList.Add('JDEvasion='+FloattoStr(FJDEvasion[0])+','+FloattoStr(FJDEvasion[1])+','+
FloattoStr(FJDEvasion[2])+','+FloattoStr(FJDEvasion[3])+','+ FloattoStr(FJDEvasion[4]));
ResultList.Add('JDCritical='+FloattoStr(FJDCritical[0])+','+FloattoStr(FJDCritical[1])+','+
FloattoStr(FJDCritical[2])+','+FloattoStr(FJDCritical[3])+','+ FloattoStr(FJDCritical[4]));
ResultList.Add('JDRHp='+FloattoStr(FJDRHp[0])+','+FloattoStr(FJDRHp[1])+','+
FloattoStr(FJDRHp[2])+','+FloattoStr(FJDRHp[3])+','+ FloattoStr(FJDRHp[4]));
ResultList.Add('JDRAp='+FloattoStr(FJDRAp[0])+','+FloattoStr(FJDRAp[1])+','+
FloattoStr(FJDRAp[2])+','+FloattoStr(FJDRAp[3])+','+ FloattoStr(FJDRAp[4]));
Result := ResultList.Text;
finally
ResultList.Free;
end;
end;
procedure TjobClass.CalcStatus(const JobData: PJob;const Status : PStatus);
begin
if Not(FCAssignedSeed) then
begin
raise EClacSeed.Create(CalcAttention);
end;
FfHp := JobData.PHp.fSeedA +
int(Status.intPhy * JobData.PHp.fSeedB) +
int(Status.intLv * JobData.PHp.fSeedC);
FfAp := JobData.PAp.fSeedA +
int(Status.intMen * JobData.PAp.fSeedB) +
int(Status.intLv * JobData.PAp.fSeedC);
FfAttack := JobData.PAttack.fSeedA +
int(Status.intStr * JobData.PAttack.fSeedB) +
int(Status.intCon * JobData.PAttack.fSeedC);
FfMagic := int(Status.intInt * JobData.PMagic.fSeedB);
FfHit := JobData.PHit.fSeedA +
int(Status.intCon * JobData.PHit.fSeedB) +
int(Status.intLv * JobData.Phit.fSeedC);
FfEvasion := JobData.PEvasion.fSeedA +
int(Status.intSen * JobData.PEvasion.fSeedB) +
int(Status.intLv * JobData.PEvasion.fSeedC);
FfCritical := int(Status.intCon * JobData.PCritical.fSeedB);
FfRecoveryHp := 0;
FfRecoveryAp := 0;
DataChange;
end;
procedure TjobClass.Calc;
begin
CalcStatus(Self.FJobData,Self.Status);
end;
procedure TjobClass.Clear;
begin
end;
procedure TjobClass.SetfAP(const Value: double);
begin
FfAP := Value;
end;
procedure TjobClass.SetfAttack(const Value: double);
begin
FfAttack := Value;
end;
procedure TjobClass.SetfCritical(const Value: double);
begin
FfCritical := Value;
end;
procedure TjobClass.SetfEvasion(const Value: double);
begin
FfEvasion := Value;
end;
procedure TjobClass.SetfHit(const Value: double);
begin
FfHit := Value;
end;
procedure TjobClass.SetfHP(const Value: double);
begin
FfHP := Value;
end;
procedure TjobClass.SetfMagic(const Value: double);
begin
FfMagic := Value;
end;
procedure TjobClass.SetStatus(const Value: PStatus);
begin
FStatus := Value;
end;
procedure TjobClass.SetfRecoveryAp(const Value: double);
begin
FfRecoveryAp := Value;
end;
procedure TjobClass.SetfRecoveryHp(const Value: double);
begin
FfRecoveryHp := Value;
end;
procedure TjobClass.SetStatuses(intLv, intStr, intCon, intInt, intPhy,
intMen, intSen, intFam : integer);
begin
FintLv := intLv;
FintStr := intStr;
FintCon := intCon;
FintInt := intInt;
FintPhy := intPhy;
FintMen := intMen;
FintSen := intSen;
FintFam := intFam;
if Assigned(FStatus)then
begin
FStatus^.intLv := FintLv;
FStatus^.intStr := FintStr;
FStatus^.intCon := FintCon;
FStatus^.intInt := FintInt;
FStatus^.intPhy := FintPhy;
FStatus^.intMen := FintMen;
FStatus^.intSen := FintSen;
FStatus^.intFam := FintFam;
Self.SetStatus(FStatus);
end;
end;
procedure TjobClass.SetJobDatas(jobOp: TJobOption; fSeedA, fSeedB,fSeedC: double;
intFixedA, intStatusA: double);
procedure SetArrayData(var TargetVarArray : array of double;
const Source : array of double);
begin
TargetVarArray[0] := Source[0];
TargetVarArray[1] := Source[1];
TargetVarArray[2] := Source[2];
TargetVarArray[3] := Source[3];
TargetVarArray[4] := Source[4];
end;
begin
if FCAssignedSeed then
initializeAssSeed;
case jobop of
opHP:begin
SetArrayData(FJDHp,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.Php^.fSeedA := FJDHp[0];
FJobData.Php^.fSeedB := FJDhp[1];
FJobData.Php^.fSeedC := FJDhp[2];
FJobData.Php^.fFixedA := FJDhp[3];
FJobData.Php^.fStatusA := FJDhp[4];
FAssignedSeed[0] := True;
end;
opAP:begin
SetArrayData(FJDAp,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PAp^.fSeedA := FJDAp[0];
FJobData.PAp^.fSeedB := FJDAp[1];
FJobData.PAp^.fSeedC := FJDAp[2];
FJobData.PAp^.fFixedA := FJDAp[3];
FJobData.PAp^.fStatusA := FJDAp[4];
FAssignedSeed[1] := True;
end;
opATTACK:begin
SetArrayData(FJDAttack,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PAttack^.fSeedA := FJDAttack[0];
FJobData.PAttack^.fSeedB := FJDAttack[1];
FJobData.PAttack^.fSeedC := FJDAttack[2];
FJobData.PAttack^.fFixedA := FJDAttack[3];
FJobData.PAttack^.fStatusA := FJDAttack[4];
FAssignedSeed[2] := True;
end;
opMAGIC:begin
SetArrayData(FJDMagic,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PMagic^.fSeedA := FJDMagic[0];
FJobData.PMagic^.fSeedB := FJDMagic[1];
FJobData.PMagic^.fSeedC := FJDMagic[2];
FJobData.PMagic^.fFixedA := FJDMagic[3];
FJobData.PMagic^.fStatusA := FJDMagic[4];
FAssignedSeed[3] := True;
end;
opHIT:begin
SetArrayData(FJDHit,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PHit^.fSeedA := FJDHit[0];
FJobData.PHit^.fSeedB := FJDHit[1];
FJobData.PHit^.fSeedC := FJDHit[2];
FJobData.PHit^.fFixedA := FJDHit[3];
FJobData.PHit^.fStatusA := FJDHit[4];
FAssignedSeed[4] := True;
end;
opEVASION:begin
SetArrayData(FJDEvasion,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PEvasion^.fSeedA := FJDEvasion[0];
FJobData.PEvasion^.fSeedB := FJDEvasion[1];
FJobData.PEvasion^.fSeedC := FJDEvasion[2];
FJobData.PEvasion^.fFixedA := FJDEvasion[3];
FJobData.PEvasion^.fStatusA := FJDEvasion[4];
FAssignedSeed[5] := True;
end;
opCRITICAL:begin
SetArrayData(FJDCritical,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PCritical^.fSeedA := FJDCritical[0];
FJobData.PCritical^.fSeedB := FJDCritical[1];
FJobData.PCritical^.fSeedC := FJDCritical[2];
FJobData.PCritical^.fFixedA := FJDCritical[3];
FJobData.PCritical^.fStatusA := FJDCritical[4];
FAssignedSeed[6] := True;
end;
opRHP:begin
SetArrayData(FJDRHP,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PRhp^.fSeedA := FJDRHp[0];
FJobData.PRhp^.fSeedB := FJDRHp[1];
FJobData.PRhp^.fSeedC := FJDRHp[2];
FJobData.PRhp^.fFixedA := FJDRHp[3];
FJobData.PRhp^.fStatusA := FJDRHp[4];
FAssignedSeed[7] := True;
end;
opRAP:begin
SetArrayData(FJDRAP,[fSeedA,fSeedB,fSeedC,intFixedA,intStatusA]);
FJobData.PRap^.fSeedA := FJDRAp[0];
FJobData.PRap^.fSeedB := FJDRAp[1];
FJobData.PRap^.fSeedC := FJDRAp[2];
FJobData.PRap^.fFixedA := FJDRAp[3];
FJobData.PRap^.fStatusA := FJDRAp[4];
FAssignedSeed[8] := True;
end;
end;
FCAssignedSeed := AssignedSeed;
end;
end.