const
MonsterList = ['Monster','Monster','Monster']; //List of monsters to attack
MonsterMana = [100,100,100] //Pause attack if Mana below
Spell = 'Exori Con'; //Spell to use
SleepS = 1000; //Sleep time after spell in ms
MinCreatureHP = 0; //Stop attacking creature if HP % below (could override "AttackLHP" & "AttackA")
AttackA = 2; //Try(1)/Force(2) to spell attack melee attacking creature only (could override AttackLHP)
AttackLHP = 1; //Attack monsters with lower Health% first
MinHP = 50; //Heal if HP below(0 to disable healing)
HealSpell = 'Exura gran'; //Spell for heal
HealMana = 40; //Heal only when mana over
GMSafe = 0; //Pause all on GM (0 disable, 1 Gm on current floor, 2 GM on any floor)
PlayerSafe = 0; //Pauses attacks if player on screen, but still heals
RampsID = [1950, 1952, 1954, 1956]; //No need to change
function PlayerOnScreen: boolean;
var
x: Integer;
begin
Result := False;
if Creatures.Count > 1 then
begin
for x := 0 to Creatures.Count - 1 do
begin
if Creatures.Creature[x].Name = Self.Name then Continue;
if Creatures.Creature[x].NPC then Continue;
if Creatures.Creature[x].Visible then Result := True;
end;
end;
end;
function GMDetected: boolean;
var
x: Integer;
begin
Result := False;
for x := 0 to Creatures.Count - 1 do
begin
if Creatures.Creature[x].GM then
begin
if (GMSafe = 2) then Result := True;
else if (GMSafe = 1) and (Creatures.Creature[x].Z = Self.Z) then Result := True;
end;
end;
end;
function GetCreatureByID(ID: integer): TCreature;
var
x: integer;
begin
Result := nil;
for x := 0 to Creatures.Count - 1 do
begin
if Creatures.Creature[x].ID = ID then
begin
Result := Creatures.Creature[x];
Break;
end;
end;
end;
function GetTileFromXYZ(X, Y, Z: integer): TTile;
begin
Result := nil;
if abs((Self.X - 7) - X) > 14 then Exit;
if abs((Self.Y - 5) - Y) > 11 then Exit;
if Self.Z <> Z then Exit;
Result := Screen.Tile[abs((Self.X - 7) - X), abs((Self.Y - 5) - Y)];
end;
function IsTileWalkable(Tile: TTile): boolean;
var
x: Integer;
Z: Integer;
begin
Result := True;
for Z := 0 to Tile.Count - 1 do
begin
if not Result then Exit;
if Tile.Item[Z].Properties.Hole then Result := False;
else if Tile.Item[Z].Properties.Stairs then Result := False;
else if not Tile.Item[Z].Properties.Walkable then Result := False;
else
begin
for x := low(RampsID) to high(RampsID) do
begin
if Tile.Item[Z].ID = RampsID[x] then Result := False;
end;
end;
end;
end;
function CreaturePos(Creature: TCreature): Integer;
begin
UpdateWorld;
Result := 0;
if Creature.Z <> Self.Z then Result := 0;
else if (Creature.X - Self.X = 0) and (Creature.Y - Self.Y = 1) then Result := 1;
else if (Creature.X - Self.X = 0) and (Creature.Y - Self.Y = -1) then Result := 2;
else if (Creature.X - Self.X = 1) and (Creature.Y - Self.Y = 0) then Result := 3;
else if (Creature.X - Self.X = -1) and (Creature.Y - Self.Y = 0) then Result := 4;
else if (Creature.X - Self.X = 1) and (Creature.Y - Self.Y = 1) then Result := 5;
else if (Creature.X - Self.X = 1) and (Creature.Y - Self.Y = -1) then Result := 6;
else if (Creature.X - Self.X = -1) and (Creature.Y - Self.Y = 1) then Result := 7;
else if (Creature.X - Self.X = -1) and (Creature.Y - Self.Y = -1) then Result := 8;
end;
function IsAttackable(Name: String): Boolean;
var
z: Integer;
begin
Result := False;
for z := Low(MonsterList) to High(MonsterList) do
begin
UpdateWorld;
if Name = MonsterList[z] then
if Self.Mana > MonsterMana[z] then
begin
Result := True;
Break;
end;
end;
end;
Procedure SpellHunt(Trapped: boolean);
var
x: Integer;
IsClose: Integer;
Att: TCreature;
PosC: Integer;
PosID: Integer;
Tile1: TTile;
begin
UpdateWorld;
if GMSafe > 0 then
begin
if GMDetected then Exit;
end;
if Self.Health < MinHP then
begin
if Self.Mana > HealMana then
begin
Self.Say(HealSpell);
Sleep(SleepS);
end;
Exit;
end;
if PlayerSafe > 0 then
begin
if PlayerOnScreen then Exit;
end;
if Trapped then Sleep(300);
IsClose := 0;
Att := nil;
PosC := 0;
UpdateWorld;
for x := 0 to Creatures.Count - 1 do
begin
if IsAttackable(Creatures.Creature[x].Name) then
begin
IsClose := CreaturePos(Creatures.Creature[x]);
if IsClose <> 0 then
begin
//Attacking options Start
if (Trapped) and (IsClose > 4) then Continue;
if Creatures.Creature[x].Health < MinCreatureHP then Continue;
if (AttackA = 2) and (not Trapped) and (Self.Attacking <> 0) then
begin
if Creatures.Creature[x].Attacking then Att := Creatures.Creature[x];
else Continue;
Break;
end;
else if (Creatures.Creature[x].Attacking) and (AttackA = 1) then
begin
Att := Creatures.Creature[x];
Break;
end;
else if (AttackLHP = 1) and (Att <> nil) then
begin
if (Creatures.Creature[x].Health < Att.Health) then Att := Creatures.Creature[x];
end;
if Att = nil then
begin
Att := Creatures.Creature[x];
end;
end;
end;
end;
if Att <> nil then
begin
PosC := CreaturePos(Att);
PosID := Att.ID;
if PosC = 0 then Exit;
if PosC > 4 then
begin
if (PosC = 6) or (PosC = 5) then
begin
Tile1 := GetTileFromXYZ(Self.X + 1, Self.Y, Self.Z);
if IsTileWalkable(Tile1) then
begin
Self.MoveRight;
Exit;
end;
end;
if (PosC = 7) or (PosC = 8) then
begin
Tile1 := GetTileFromXYZ(Self.X - 1, Self.Y, Self.Z);
if IsTileWalkable(Tile1) then
begin
Self.MoveLeft;
Exit;
end;
end;
if (PosC = 5) or (PosC = 7) then
begin
Tile1 := GetTileFromXYZ(Self.X, Self.Y + 1, Self.Z);
if IsTileWalkable(Tile1) then
begin
Self.MoveDown;
Exit;
end;
end;
if (PosC = 6) or (PosC = 8) then
begin
Tile1 := GetTileFromXYZ(Self.X, Self.Y - 1, Self.Z);
if IsTileWalkable(Tile1) then
begin
Self.MoveUp;
Exit;
end;
end;
SpellHunt(True);
end;
else if PosC < 5 then
begin
if PosC = 1 then Self.FaceDown;
else if PosC = 2 then Self.FaceUp;
else if PosC = 3 then Self.FaceRight;
else if PosC = 4 then Self.FaceLeft;
Sleep(200);
UpdateWorld;
Att := GetCreatureByID(PosID);
if Att = nil then Exit;
if PosC <> CreaturePos(Att) then Exit;
if Att.Health = 0 then Exit;
UpdateWorld;
T := CreaturePos(Att);
if T < 5 then
begin
Self.Say(Spell);
Sleep(SleepS - 100);
end;
sleep(100);
end;
end;
end;
begin
while not Terminated do
begin
SpellHunt(False);
Sleep(300);
end;
end;
Zakładki