File diff 5dfd4e336063 → 8ef575a5da38
journey_zayslanotrr.lua
Show inline comments
 
@@ -1213,16 +1213,16 @@ za_plaetlarr_fight = battlefield {
 
        --TODO prepend player associate - anna, learr, walter or jack
 
        if (char_learr.follow) then
 
            table.insert(s.obj, 2, za_cmbt_learr);
 
            s.plX = 2;
 
            s.plX = 3;
 
        elseif (char_anna.follow) then
 
            table.insert(s.obj, 2, za_cmbt_anna);
 
            s.plX = 2;
 
            s.plX = 3;
 
        elseif (char_wright.follow) then
 
            table.insert(s.obj, 2, za_cmbt_wright);
 
            s.plX = 2;
 
            s.plX = 3;
 
        elseif (char_radcliffe.follow) then
 
            table.insert(s.obj, 2, za_cmbt_radcliffe);
 
            s.plX = 2;
 
            s.plX = 3;
 
        end;
 
    end;
 
    obj = {
 
@@ -1278,8 +1278,6 @@ za_cmbt_phaetlarr = combatant {
 
        -- If enemy close and enemy doesn't have spear - hit with claws
 

	
 
        if s.hasSpear then
 
            here():canShoot(s.x, s.y, enemy.x, enemy.y);
 

	
 
            if (math.abs(s.x - enemy.x) + math.abs(s.y - enemy.y) <= 2 and here():canShoot(s.x,s.y, enemy.x, enemy.y)) then
 
                --50%
 
                if (rnd(2) > 1) then
 
@@ -1288,6 +1286,7 @@ za_cmbt_phaetlarr = combatant {
 
                else
 
                    pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                end;
 
                return;
 
            elseif  (math.abs(s.x - enemy.x) == 1 and math.abs(s.y - enemy.y) == 1) then
 
                --75%
 
                if (rnd(4) > 1) then
 
@@ -1296,18 +1295,34 @@ za_cmbt_phaetlarr = combatant {
 
                else
 
                    pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                end;
 
            else
 
                return;
 
            elseif (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
                s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
                --100%
 
                enemy.hp = enemy.hp - 2;
 
                pn("Фаэтларр бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                return;
 
            else
 
                local dist = math.sqrt((s.x - here().plX) * (s.x - here().plX) + (s.y - here().plY) * (s.y - here().plY));--here().getDistance(here().plX, here().plY, s.x, s.y);
 
                if (rnd(4) > dist - 2) then
 
                    s.hasSpear = false;
 
                    enemy.hp = enemy.hp - 2;
 
                    pn("Фаэтларр бросает копье в " .. enemy.disp2 .. " и попадает. ");
 
                else
 
                    pn("Фаэтларр бросает копье в " .. enemy.disp2 .. ", но промахивается. ");
 
                end;
 
            end;
 
            return;
 
        else
 
            if (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
                s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
                enemy.hp = enemy.hp - 1;
 
                pn("Фаэтларр бьет " .. enemy.disp2 .. " и попадает. ");
 
                return;
 
                if (enemy.hasSpear) then
 
                    enemy.hasSpear = false;
 
                    s.hasSpear = true;
 
                    pn("Фаэтларр забирает копье у " .. enemy.disp2 .. ". ");
 
                else
 
                    enemy.hp = enemy.hp - 1;
 
                    pn("Фаэтларр бьет " .. enemy.disp2 .. " и попадает. ");
 
                end;
 
            end;
 
        end;
 
        
 
@@ -1744,68 +1759,88 @@ za_cmbt_guard = function(nam, index, x, 
 
            for item=1,#here().obj do
 
                local obj = here().obj[item];
 
                if (obj.ally and obj.hp > 0) then
 
                    table.insert(enemies, obj);
 
                    local p = here():getWalkDistance(s.x, s.y, obj.x, obj.y);
 
                    if (p) then
 
                        table.insert(enemies, {
 
                            o = obj,
 
                            p = p
 
                        });
 
                    end;
 
                end;
 
            end;
 
            table.sort(enemies, function(a, b)
 
                return (here().getDistance(s.x, s.y, b.x, b.y) > here().getDistance(s.x, s.y, a.x, a.y));
 
                return (a.p.l < b.p.l);
 
            end);
 
            
 
            local enemy = enemies[1];
 
            local dist = 9000;
 
            if (not enemy) then
 
            local path = here():getWalkDistance(s.x, s.y, here().plX, here().plY);
 
            if (not enemy or path and enemy.p.l > path.l ) then
 
                enemy = pl;
 
                dist = here().getDistance(s.x, s.y, here().plX, here().plY);
 
            else
 
                dist = here().getDistance(s.x, s.y, enemy.x, enemy.y);
 
                path = enemy.p;
 
                enemy = enemy.o;
 
            end;
 
            
 
            if (not enemy or not path) then
 
                pn("Стражник ".. tostring(index).. " ждет. ");
 
                return;
 
            end;
 
            
 
            if (dist > here().getDistance(s.x, s.y, here().plX, here().plY)) then
 
                enemy = pl;
 
            end;
 
            -- AI Order:
 
            -- If has spear and enemy is far   - throw spear
 
            -- If has spear and enemy is close - hit with spear
 
            -- if spear is nearer than any enemy - walk towards spear
 
            -- walk towards nearest enemy
 
            -- If enemy close and enemy has spear - take spear from enemy
 
            -- If enemy close and enemy doesn't have spear - hit with claws
 
            -- If enemy close - hit with claws
 
            
 
            if (s.hasSpear and dist == 1) then
 
                if (rnd(4) > 1) then
 
                    pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                    enemy.hp = enemy.hp - 2;
 
                else
 
                    pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем, но промахивается. "); 
 
            if (s.hasSpear) then
 
                here():canShoot(s.x,s.y, enemy.x, enemy.y);
 
                
 
                if (math.abs(s.x - enemy.x) + math.abs(s.y - enemy.y) <= 2 and here():canShoot(s.x,s.y, enemy.x, enemy.y)) then
 
                    if (math.abs(s.x - enemy.x) == 2 or math.abs(s.y - enemy.y) == 2) then
 
                        --50%
 
                        if (rnd(2) > 1) then
 
                            enemy.hp = enemy.hp - 2;
 
                            pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                        else
 
                            pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                        end;
 
                        return;
 
                    elseif  (math.abs(s.x - enemy.x) == 1 and math.abs(s.y - enemy.y) == 1) then
 
                        --75%
 
                        if (rnd(4) > 1) then
 
                            enemy.hp = enemy.hp - 2;
 
                            pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                        else
 
                            pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем, но промахивается. ");
 
                        end;
 
                        return;
 
                    elseif (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
                    s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
                        --100%
 
                        enemy.hp = enemy.hp - 2;
 
                        pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
                        return;
 
                    end;
 
                end;
 
            elseif (s.hasSpear and dist == 0) then
 
                enemy.hp = enemy.hp - 2;
 
                pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " копьем и попадает. ");
 
            elseif dist == 0 then
 
                enemy.hp = enemy.hp - 1;
 
                pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " и попадает. ");
 
            else
 
                if (enemy.x > s.x) then
 
                    s.x = s.x + 1;
 
                elseif (enemy.x < s.x) then
 
                    s.x = s.x - 1;
 
                if (math.abs(s.x - enemy.x) == 1 and s.y == enemy.y or
 
                    s.x == enemy.x and math.abs(s.y - enemy.y) == 1) then
 
                    enemy.hp = enemy.hp - 1;
 
                    pn("Стражник ".. tostring(index).. " бьет " .. enemy.disp2 .. " и попадает. ");
 
                    return;
 
                end;
 
                
 
                if (enemy.y > s.y) then
 
                    s.y = s.y + 1;
 
                elseif (enemy.y < s.y) then
 
                    s.y = s.y - 1;
 
                end;
 
                
 
                pn("Стражник ".. tostring(index).. " идет к " .. enemy.disp3 .. ". ");
 
            end;
 
            print("fug2",path);
 
            s.x = path.p[2][1];
 
            s.y = path.p[2][2];
 
            pn("Стражник ".. tostring(index).. " идет к " .. enemy.disp3 .. ". ");
 
        end;
 
    };
 
end;
 

	
 
za_cmbt_guard1 = za_cmbt_guard("za_cmbt_guard1", 1, 1, 5, true);
 
za_cmbt_guard2 = za_cmbt_guard("za_cmbt_guard2", 2, 2, 5, false);
 
za_cmbt_guard3 = za_cmbt_guard("za_cmbt_guard3", 3, 4, 5, true);
 
za_cmbt_guard4 = za_cmbt_guard("za_cmbt_guard4", 4, 5, 5, true);
 
za_cmbt_guard1 = za_cmbt_guard("za_cmbt_guard1", 1, 3, 5, true);
 
za_cmbt_guard2 = za_cmbt_guard("za_cmbt_guard2", 2, 5, 5, false);
 
za_cmbt_guard3 = za_cmbt_guard("za_cmbt_guard3", 3, 3, 7, true);
 
za_cmbt_guard4 = za_cmbt_guard("za_cmbt_guard4", 4, 5, 7, true);
 

	
 
za_phaetlarr_dlg = dlg {
 
    var {