Beispiel #1
0
        private static bool processPotentialEnemy(Vector3 position, float range, IMyEntity entity, IMyFaction faction,
                                                  out IMyEntity findNearbyEnemy1)
        {
            findNearbyEnemy1 = null;
            long entityOwner = 0;

            var character = entity as IMyCharacter;

            if (character != null)
            {
                var player = findByCharacter(character);
                if (player != null)
                {
                    entityOwner = player.IdentityId;
                }
            }
            else
            {
                var grid = entity as IMyCubeGrid;
                if (grid == null || grid.BigOwners.Count < 1)
                {
                    return(false);
                }

                var blocks = new List <IMySlimBlock>();
                grid.GetBlocks(blocks);
                var isNPC = blocks.Count == 1 && blocks[0].BlockDefinition.Id.SubtypeId.String.StartsWith("NPC_");

                if (blocks.Count < 3 && !isNPC)
                {
                    return(false);
                }

                entityOwner = grid.BigOwners[0];
            }

            if (entityOwner == 0)
            {
                return(false);
            }
            var isEnemy = faction.IsEnemy(entityOwner);

            var dist = Vector3.Distance(position, entity.GetPosition());

            if (dist < range && isEnemy)
            {
                {
                    findNearbyEnemy1 = entity;
                    return(true);
                }
            }

            return(false);
        }