protected ObjCharacter ScanEnemy(ObjNPC npc, float distance) { if (null == npc) { return(null); } if (null == npc.Zone) { return(null); } var sq = distance * distance; ObjCharacter target = null; var objs = npc.Zone.EnumAllVisibleObj(); foreach (var obj in objs) { if (null == obj) { continue; } if (obj.ObjId == npc.ObjId) { continue; } if (!obj.IsCharacter()) { continue; } var character = obj as ObjCharacter; if (null == character) { continue; } if (character.IsDead()) { continue; } if (!npc.IsMyEnemy(character)) { continue; } var temp = (npc.GetPosition() - character.GetPosition()).LengthSquared(); if (temp <= sq) { target = character; sq = temp; } } return(target); }