?? script.pas
字號:
unit Script;
interface
uses
Windows, Types, SysUtils, Common, MMSystem, Classes, Globals;
//==============================================================================
// 娭悢掕媊
procedure NPCScript(tc:TChara; value:cardinal = 0; mode:byte = 0);
//==============================================================================
implementation
//==============================================================================
procedure NPCScript(tc:TChara; value:cardinal = 0; mode:byte = 0);
var
i,j,k,l :integer;
m :integer;
cnt :integer;
str :string;
txt2 :TextFile;
sl :TStringList;
p :pointer;
len :cardinal;
flag :boolean;
tn :TNPC;
td :TItemDB;
{NPC僀儀儞僩捛壛}
ts :TMob;
ts1 :TMob;
tm :TMap;
tm1 :TMap;
tn1 :TNPC;
tc1 :TChara;
tg :TGuild;
tgc :TCastle;
w :word;
Tick :cardinal;
tr :NTimer;
tcr :TChatRoom;
mi :MapTbl;
tGlobal :TGlobalVars;
{NPC僀儀儞僩捛壛僐僐傑偱}
begin
flag := false;
if (tc.AMode <> 3) then exit;
tn := tc.AData;
//with tn do begin
//嫍棧僠僃僢僋
{NPC僀儀儞僩捛壛}
if (mode = 0) then begin
if (tc.Map <> tn.Map) or (abs(tc.Point.X - tn.Point.X) > 15) or (abs(tc.Point.Y - tn.Point.Y) > 15) then begin
tc.AMode := 0;
exit;
end;
end;
tm := Map.Objects[Map.IndexOf(tn.Map)] as TMap;
Tick := timeGetTime();
{NPC僀儀儞僩捛壛僐僐傑偱}
cnt := 0;
while (tc.ScriptStep < tn.ScriptCnt) and (cnt < 100) do begin
case tn.Script[tc.ScriptStep].ID of
0: //(nop)
begin
Inc(tc.ScriptStep);
end;
1: //mes
begin
str := tn.Script[tc.ScriptStep].Data1[0];
i := AnsiPos('$[', str);
while i <> 0 do begin
j := AnsiPos(']', Copy(str, i + 2, 256));
if j <= 1 then break;
{NPC僀儀儞僩捛壛}
if (Copy(str, i + 2, 1) = '$') then begin
str := Copy(str, 1, i - 1) + tc.Flag.Values[Copy(str, i + 2, j - 1)] + Copy(str, i + j + 2, 256);
end else if (Copy(str, i + 2, 2) = '\$') then begin
str := Copy(str, 1, i - 1) + ServerFlag.Values[Copy(str, i + 2, j - 1)] + Copy(str, i + j + 2, 256);
end else begin
k := ConvFlagValue(tc, Copy(str, i + 2, j - 1), true);
if k <> -1 then begin
str := Copy(str, 1, i - 1) + IntToStr(k) + Copy(str, i + j + 2, 256);
end else begin
str := Copy(str, 1, i - 1) + Copy(str, i + j + 2, 256);
end;
end;
{NPC僀儀儞僩捛壛僐僐傑偱}
i := AnsiPos('$[', str);
end;
str := StringReplace(str, '$codeversion', CodeVersion, [rfReplaceAll]);
str := StringReplace(str, '$charaname', tc.Name, [rfReplaceAll]);
str := StringReplace(str, '$guildname', GetGuildName(tn), [rfReplaceAll]);
str := StringReplace(str, '$guildmaster', GetGuildMName(tn), [rfReplaceAll]);
str := StringReplace(str, '$edegree', IntToStr(GetGuildEDegree(tn)), [rfReplaceAll]);
str := StringReplace(str, '$etrigger', IntToStr(GetGuildETrigger(tn)), [rfReplaceAll]);
str := StringReplace(str, '$ddegree', IntToStr(GetGuildDDegree(tn)), [rfReplaceAll]);
str := StringReplace(str, '$dtrigger', IntToStr(GetGuildDTrigger(tn)), [rfReplaceAll]);
str := StringReplace(str, '$$', '$', [rfReplaceAll]);
i := Length(str);
WFIFOW(0, $00b4);
WFIFOW(2, i + 8);
WFIFOL(4, tn.ID);
WFIFOS(8, str, i);
tc.Socket.SendBuf(buf[0], i + 8);
Inc(tc.ScriptStep);
end;
2: //next
begin
WFIFOW(0, $00b5);
WFIFOL(2, tn.ID);
tc.Socket.SendBuf(buf[0], 6);
Inc(tc.ScriptStep);
break;
end;
3: //close
begin
WFIFOW(0, $00b6);
WFIFOL(2, tn.ID);
tc.Socket.SendBuf(buf[0], 6);
tc.ScriptStep := $FFFF;
break;
end;
4: //menu
begin
if value = 0 then begin
for i := 0 to tn.Script[tc.ScriptStep].DataCnt - 1 do begin
if i = 0 then
str := tn.Script[tc.ScriptStep].Data1[i]
else
str := str + ':' + tn.Script[tc.ScriptStep].Data1[i];
end;
i := Length(str);
WFIFOW(0, $00b7);
WFIFOW(2, i + 8);
WFIFOL(4, tn.ID);
WFIFOS(8, str, i);
tc.Socket.SendBuf(buf[0], i + 8);
break;
end else begin
if value = $FF then begin
{惛楤NPC婡擻捛壛}
//EqLock夝彍
if tc.EqLock = true then tc.EqLock := false;
{惛楤NPC婡擻捛壛僐僐傑偱}
tc.ScriptStep := $FFFF;
break;
end;
Dec(value);
if tn.Script[tc.ScriptStep].DataCnt <= value then begin
tc.ScriptStep := $FFFF;
break;
end;
tc.ScriptStep := tn.Script[tc.ScriptStep].Data3[value];
value := 0;
end;
end;
5: //goto
begin
tc.ScriptStep := tn.Script[tc.ScriptStep].Data3[0];
end;
6: //cutin
begin
WFIFOW(0, $0145);
WFIFOS(2, tn.Script[tc.ScriptStep].Data1[0], 16);
WFIFOB(18, tn.Script[tc.ScriptStep].Data3[0]);
tc.Socket.SendBuf(buf[0], 19);
Inc(tc.ScriptStep);
end;
7: //store
begin
tc.AMode := 4;
SendCStoreList(tc);
Inc(tc.ScriptStep);
end;
8: //warp
begin
SendCLeave(tc, 2);
tc.tmpMap := tn.Script[tc.ScriptStep].Data1[0];
tc.Point := Point(tn.Script[tc.ScriptStep].Data3[0],tn.Script[tc.ScriptStep].Data3[1]);
MapMove(tc.Socket, tc.tmpMap, tc.Point);
exit;
end;
9: //save
begin
{NPC僀儀儞僩捛壛}
i := MapInfo.IndexOf(tm.Name);
if (i <> -1) then begin
mi := MapInfo.Objects[i] as MapTbl;
if (mi.noSave <> true) then begin
tc.SaveMap := tn.Script[tc.ScriptStep].Data1[0];
tc.SavePoint := Point(tn.Script[tc.ScriptStep].Data3[0],tn.Script[tc.ScriptStep].Data3[1]);
end;
end;
{NPC僀儀儞僩捛壛僐僐傑偱}
Inc(tc.ScriptStep);
end;
10: //heal
begin
Inc(tc.HP, tn.Script[tc.ScriptStep].Data3[0]);
if tc.HP > tc.MAXHP then tc.HP := tc.MAXHP;
Inc(tc.SP, tn.Script[tc.ScriptStep].Data3[1]);
if tc.SP > tc.MAXSP then tc.SP := tc.MAXSP;
//僷働憲怣
WFIFOW( 0, $011a);
WFIFOW( 2, 28);
WFIFOW( 4, tn.Script[tc.ScriptStep].Data3[0]);
WFIFOL( 6, tc.ID);
WFIFOL(10, tn.ID);
WFIFOB(14, 1);
SendBCmd(tc.MData, tn.Point, 15);
{
WFIFOW( 0, $013d);
WFIFOW( 2, $0007);
WFIFOW( 4, tn.Script[tc.ScriptStep].Data3[1]);
tc.Socket.SendBuf(buf, 6);
}
SendCStat1(tc, 0, 5, tc.HP);
SendCStat1(tc, 0, 7, tc.SP);
Inc(tc.ScriptStep);
end;
11: //set
begin
str := tn.Script[tc.ScriptStep].Data1[0];
p := nil;
len := 0;
if str = 'zeny' then begin p := @tc.Zeny; len := 4; end
else if str = 'job' then begin p := @tc.JID; len := 2; end
else if str = 'baselevel' then begin p := @tc.BaseLV; len := 2; end
else if str = 'joblevel' then begin p := @tc.JobLV; len := 2; end
else if str = 'statuspoint' then begin p := @tc.StatusPoint; len := 2; end
else if str = 'skillpoint' then begin p := @tc.SkillPoint; len := 2; end
else if str = 'Baseexp' then begin p := @tc.BaseEXP; len := 2; end
else if str = 'Jobexp' then begin p := @tc.JobEXP; len := 2; end
else if str = 'option' then begin p := @tc.Option; len := 4; end
else if str = 'speed' then begin p := @tc.Speed; len := 2; end;
if len <> 0 then begin
//嵍曈偼僷儔儊乕僞
{NPC僀儀儞僩捛壛}
j := ConvFlagValue(tc, tn.Script[tc.ScriptStep].Data1[1]);
{NPC僀儀儞僩捛壛僐僐傑偱}
i := 0;
if tn.Script[tc.ScriptStep].Data3[0] <> 0 then CopyMemory(@i, p, len);
case tn.Script[tc.ScriptStep].Data3[0] of
0,1: i := i + j;
2: i := i - j;
3: i := i * j;
4: i := i div j;
end;
if i < 0 then i := 0;
if (tn.Script[tc.ScriptStep].Data3[1] <> 0) and
(i > tn.Script[tc.ScriptStep].Data3[1]) then i := tn.Script[tc.ScriptStep].Data3[1];
CopyMemory(p, @i, len);
SendCStat(tc);
end else begin
//嵍曈偼僼儔僌
{NPC僀儀儞僩捛壛}
j := ConvFlagValue(tc, tn.Script[tc.ScriptStep].Data1[1]);
if (tn.Script[tc.ScriptStep].Data3[0] = 0) then begin
i := 0;
end else begin
i := ConvFlagValue(tc, str);
end;
{NPC僀儀儞僩捛壛僐僐傑偱}
case tn.Script[tc.ScriptStep].Data3[0] of
0,1: i := i + j;
2: i := i - j;
3: i := i * j;
4: i := i div j;
end;
if i < 0 then i := 0;
if (tn.Script[tc.ScriptStep].Data3[1] <> 0) and
(i > tn.Script[tc.ScriptStep].Data3[1]) then i := tn.Script[tc.ScriptStep].Data3[1];
{NPC僀儀儞僩捛壛}
if (Copy(str, 1, 1) <> '\') then begin
tc.Flag.Values[str] := IntToStr(i);
end else begin
ServerFlag.Values[str] := IntToStr(i);
end;
{NPC僀儀儞僩捛壛僐僐傑偱}
end;
Inc(tc.ScriptStep);
end;
12: //additem
begin
{NPC僀儀儞僩捛壛}
i := ConvFlagValue(tc, tn.Script[tc.ScriptStep].Data1[0]);
j := ConvFlagValue(tc, tn.Script[tc.ScriptStep].Data1[1]);
{NPC僀儀儞僩捛壛僐僐傑偱}
td := ItemDB.IndexOfObject(i) as TItemDB;
if tc.MaxWeight >= tc.Weight + cardinal(td.Weight) * cardinal(j) then begin
k := SearchCInventory(tc, i, td.IEquip);
if k <> 0 then begin
if tc.Item[k].Amount + j > 30000 then j := 30000 - tc.Item[k].Amount;
if td.IEquip then j := 1;
//傾僀僥儉捛壛
tc.Item[k].ID := i;
tc.Item[k].Amount := tc.Item[k].Amount + j;
tc.Item[k].Equip := 0;
tc.Item[k].Identify := 1;
tc.Item[k].Refine := 0;
tc.Item[k].Attr := 0;
tc.Item[k].Card[0] := 0;
tc.Item[k].Card[1] := 0;
tc.Item[k].Card[2] := 0;
tc.Item[k].Card[3] := 0;
tc.Item[k].Data := td;
// Update weight
tc.Weight := tc.Weight + cardinal(td.Weight) * cardinal(j);
SendCStat1(tc, 0, $0018, tc.Weight);
//傾僀僥儉僎僢僩捠抦
SendCGetItem(tc, k, j);
end;
end else begin
//廳検僆乕僶乕
WFIFOW( 0, $00a0);
WFIFOB(22, 2);
tc.Socket.SendBuf(buf, 23);
end;
Inc(tc.ScriptStep);
end;
13: //delitem
begin
{NPC僀儀儞僩捛壛}
i := ConvFlagValue(tc, tn.Script[tc.ScriptStep].Data1[0]);
j := ConvFlagValue(tc, tn.Script[tc.ScriptStep].Data1[1]);
{NPC僀儀儞僩捛壛僐僐傑偱}
k := SearchCInventory(tc, i, false);
if k <> 0 then begin
if j > tc.Item[k].Amount then j := tc.Item[k].Amount;
//憰旛拞側傜憰旛夝彍
if tc.Item[k].Equip <> 0 then begin
reset_skill_effects(tc);
WFIFOW(0, $00ac);
WFIFOW(2, k);
WFIFOW(4, tc.Item[k].Equip);
tc.Item[k].Equip := 0;
WFIFOB(6, 1);
tc.Socket.SendBuf(buf, 7);
remove_equipcard_skills(tc, k);
CalcStat(tc);
SendCStat(tc);
end;
//傾僀僥儉悢尭彮
Dec(tc.Item[k].Amount, j);
if tc.Item[k].Amount = 0 then tc.Item[k].ID := 0;
WFIFOW( 0, $00af);
WFIFOW( 2, k);
WFIFOW( 4, j);
tc.Socket.SendBuf(buf, 6);
// Update weight
tc.Weight := tc.Weight - tc.Item[k].Data.Weight * cardinal(j);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -