------------------------------------------- -- 先攻型で、 -- 自分を攻撃する敵 -- →主人が攻撃している敵 -- →自分の10セル内にいて他PCが4セル以内におらず他PCと交戦状態になっていない敵 -- の順で敵をサーチするGetMyEnemy ------------------------------------------- function GetMyEnemyC (myid) local result = 0 local owner = GetV (V_OWNER,myid) local actors = GetActors () local enemysA = {} local enemysB = {} local ownerenemy = 0 local others = {} local indexO = 1 local indexB = 1 local indexA = 1 local target local check for i,v in ipairs(actors) do if (v ~= owner and v ~= myid) then local type = GetV(V_HOMUNTYPE,v) if ((0 <= type and type <= 23) or (4001 <= type and type <= 4046)) then others[indexO] = v--画面内のオブジェクトの内、他PCをothersに保存 indexO = indexO + 1 end end end for i,v in ipairs(actors) do if (v ~= owner and v ~= myid) then target = GetV (V_TARGET,v) if (target == myid) then local motion = GetV(V_MOTION,v) if (motion == MOTION_ATTACK or motion == MOTION_ATTACK2) then enemysA[indexA] = v--ホム自身をタゲってたらenemysAに追加 indexA = indexA+1 end elseif (1 == IsMonster(v))then check = true --まず、交戦状態と距離のチェックフラグをtrueににして for j,w in ipairs(others) do if (true == check) then if (GetV (V_TARGET,w) == v) or (GetV(V_TARGET,v) == w) or (GetDistance2 (v,w) < 4) then check =false--他PCと交戦状態or距離が4未満ならcheckをfalseに TraceAI("check") end end end --この時点で、他PCリストのどれも交戦状態or距離フラグに引っかかっていなければcheckはtrueのまま if (check==true) then --交戦状態でなく距離も充分ならenemysBに追加 TraceAI("ADDenemyB") enemysB[indexB] = v indexB = indexB+1 end end end end local ownermotion = GetV(V_MOTION,owner) --主人のモーションを取得 if(ownermotion == MOTION_ATTACK or ownermotion == MOTION_ATTACK2) then --攻撃中なら ownerenemy = GetV(V_TARGET,owner)--主人の攻撃対象を取得 end if (indexA > 1) then--enemysAが空ではない(=ホムをタゲっている敵がいる)ならば local min_dis = 100 local dis for i,v in ipairs(enemysA) do --enemysAの中から最寄の敵を探す dis = GetDistance2 (myid,v) if (dis < min_dis) then result = v min_dis = dis end end elseif (ownerenemy ~= 0) then--主人が誰かを殴ってるならば result = ownerenemy elseif (indexB > 1) then--enemysBが空ではない(=近くに他PCがおらずフリーの敵がいる)ならば local min_dis = 11 local dis for i,v in ipairs(enemysB) do--enemysBの中から最寄の敵を探す dis = GetDistance2 (myid,v) if (dis < min_dis) then result = v min_dis = dis end end end return result end