示例#1
0
 public void LogEntity(string format, DirectEntity entity)
 {
     if (entity != null)
     {
         Log(string.Format(format, entity.Id, entity.Name, entity.CorpId, entity.AllianceId, entity.TypeName, entity.GivenName));
     }
 }
示例#2
0
文件: Program.cs 项目: ahaw/Questor
        private static void LogEntity(string format, DirectEntity entity)
        {
            if (entity == null)
                return;

            Log(format, "Id", entity.Id);
            Log(format, "OwnerId", entity.OwnerId);
            Log(format, "CorpId", entity.CorpId);
            Log(format, "AllianceId", entity.AllianceId);

            Log(format, "FollowId", entity.FollowId);

            Log(format, "IsNpc", entity.IsNpc);
            Log(format, "IsPc", entity.IsPc);

            Log(format, "TypeId", entity.TypeId);
            Log(format, "GroupId", entity.GroupId);
            Log(format, "TypeName", entity.TypeName);
            Log(format, "Name", entity.Name);
            Log(format, "GivenName", entity.GivenName);

            Log(format, "Distance", entity.Distance);
            Log(format, "Velocity", entity.Velocity);

            Log(format, "IsAttacking", entity.IsAttacking);
            Log(format, "IsCloaked", entity.IsCloaked);
            Log(format, "IsNeutralizingMe", entity.IsNeutralizingMe);
            Log(format, "IsJammingMe", entity.IsJammingMe);
            Log(format, "IsWebbingMe", entity.IsWebbingMe);
            Log(format, "IsSensorDampeningMe", entity.IsSensorDampeningMe);
        }
示例#3
0
        /// <summary>
        ///     Bookmark an entity
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="name"></param>
        /// <param name="comment"></param>
        /// <param name="folderId"></param>
        /// <param name="corp"></param>
        /// <returns></returns>
        public bool BookmarkEntity(DirectEntity entity, string name, string comment, long?folderId, bool corp = false)
        {
            if (!entity.IsValid)
            {
                return(false);
            }

            if (!corp && Session.CharacterId == null)
            {
                return(false);
            }

            if (corp && Session.CorporationId == null)
            {
                return(false);
            }

            if (!corp)
            {
                return(DirectBookmark.BookmarkLocation(this, Session.CharacterId.Value, entity.Id, name, comment, entity.TypeId, Session.SolarSystemId, folderId));
            }
            else
            {
                return(DirectBookmark.BookmarkLocation(this, Session.CorporationId.Value, entity.Id, name, comment, entity.TypeId, Session.SolarSystemId, folderId));
            }
        }
示例#4
0
 public EntityCache(DirectEntity entity)
 {
     _directEntity = entity;
 }
示例#5
0
        internal static Dictionary<long, DirectEntity> GetEntities(DirectEve directEve)
        {
            var pySharp = directEve.PySharp;
            var entitiesById = new Dictionary<long, DirectEntity>();

            // Used by various loops, etc
            DirectEntity entity;

            var uix = pySharp.Import("uix");
            var ballpark = directEve.GetLocalSvc("michelle").Call("GetBallpark");
            var balls = ballpark.Attribute("balls").Call("keys").ToList<long>();
            foreach (var id in balls)
            {
                if (id < 0)
                    continue;

                // Get slim item
                var slimItem = ballpark.Call("GetInvItem", id);

                // Get ball
                var ball = ballpark.Call("GetBall", id);

                // Create the entity
                entitiesById[id] = new DirectEntity(directEve, ballpark, ball, slimItem, id);
            }

            // Mark active target
            var activeTarget = pySharp.Import("state").Attribute("activeTarget");
            var activeTargetId = (long) directEve.GetLocalSvc("state").Call("GetExclState", activeTarget);
            if (entitiesById.TryGetValue(activeTargetId, out entity))
                entity.IsActiveTarget = true;

            var target = directEve.GetLocalSvc("target");
            var targets = target.Attribute("targetsByID").ToDictionary().Keys;
            foreach (var targetId in targets)
            {
                if (!entitiesById.TryGetValue((long) targetId, out entity))
                    continue;

                entity.IsTarget = true;
            }

            var targeting = target.Attribute("targeting").ToDictionary<long>().Keys;
            foreach (var targetId in targeting)
            {
                if (!entitiesById.TryGetValue(targetId, out entity))
                    continue;

                entity.IsTargeting = true;
            }

            var targetedBy = target.Attribute("targetedBy").ToList<long>();
            foreach (var targetId in targetedBy)
            {
                if (!entitiesById.TryGetValue(targetId, out entity))
                    continue;

                entity.IsTargetedBy = true;
            }

            var attackers = directEve.GetLocalSvc("tactical").Attribute("attackers").ToDictionary<long>();
            foreach (var attacker in attackers)
            {
                if (!entitiesById.TryGetValue(attacker.Key, out entity))
                    continue;

                entity.IsAttacking = true;

                var attacks = attacker.Value.ToList();
                foreach (var attack in attacks.Select(a => (string) a.Item(1)))
                {
                    entity.IsWarpScramblingMe |= attack == "effects.WarpScramble";
                    entity.IsWebbingMe |= attack == "effects.ModifyTargetSpeed";
                    entity.Attacks.Add(attack);
                }
            }

            var jammers = directEve.GetLocalSvc("tactical").Attribute("jammers").ToDictionary<long>();
            foreach (var jammer in jammers)
            {
                if (!entitiesById.TryGetValue(jammer.Key, out entity))
                    continue;

                var ews = jammer.Value.ToDictionary<string>().Keys;
                foreach (var ew in ews)
                {
                    entity.IsNeutralizingMe |= ew == "ewEnergyNeut";
                    entity.IsJammingMe |= ew == "electronic";
                    entity.IsSensorDampeningMe |= ew == "ewRemoteSensorDamp";
                    entity.IsTargetPaintingMe |= ew == "ewTargetPaint";
                    entity.IsTrackingDisruptingMe |= ew == "ewTrackingDisrupt";
                    entity.ElectronicWarfare.Add(ew);
                }
            }

            return entitiesById;
        }
示例#6
0
        /// <summary>
        ///     Bookmark an entity
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="name"></param>
        /// <param name="comment"></param>
        /// <param name="folderId"></param>
        /// <returns></returns>
        public bool CorpBookmarkEntity(DirectEntity entity, string name, string comment, long? folderId)
        {
            if (!entity.IsValid)
                return false;

            if (Session.CorporationId == null)
                return false;

            return DirectBookmark.BookmarkLocation(this, Session.CorporationId.Value, entity.Id, name, comment, entity.TypeId, Session.SolarSystemId, folderId);
        }
示例#7
0
        /// <summary>
        ///   Calculate distance from entity
        /// </summary>
        /// <param name = "x"></param>
        /// <param name = "y"></param>
        /// <param name = "z"></param>
        /// <param name="entity"> </param>
        /// <returns></returns>
        public double DistanceFromEntity(double x, double y, double z, DirectEntity entity)
        {
            try
            {
                if (entity == null)
                {
                    return double.MaxValue;
                }

                double curX = entity.X;
                double curY = entity.Y;
                double curZ = entity.Z;

                return Math.Sqrt((curX - x) * (curX - x) + (curY - y) * (curY - y) + (curZ - z) * (curZ - z));
            }
            catch (Exception ex)
            {
                Logging.Log("DistanceFromEntity", "Exception [" + ex + "]", Logging.Debug);
                return 0;
            }
        }
示例#8
0
        /// <summary>
        ///   Calculate distance between 2 entities
        /// </summary>
        public double DistanceBetween2Entities(DirectEntity entity1, DirectEntity entity2)
        {
            try
            {
                if (entity1 == null || entity2 == null)
                {
                    return double.MaxValue;
                }

                double entity1X = entity1.X;
                double entity1Y = entity1.Y;
                double entity1Z = entity1.Z;

                double entity2X = entity2.X;
                double entity2Y = entity2.Y;
                double entity2Z = entity2.Z;

                return Math.Sqrt((entity1X - entity2X) * (entity1X - entity2X) + (entity1Y - entity2Y) * (entity1Y - entity2Y) + (entity1Z - entity2Z) * (entity1Z - entity2Z));
            }
            catch (Exception ex)
            {
                Logging.Log("DistanceBetween2Entities", "Exception [" + ex + "]", Logging.Debug);
                return 0;
            }
        }
示例#9
0
        internal static Dictionary <long, DirectEntity> GetEntities(DirectEve directEve)
        {
            var pySharp      = directEve.PySharp;
            var entitiesById = new Dictionary <long, DirectEntity>();

            // Used by various loops, etc
            DirectEntity entity;

            var uix      = pySharp.Import("uix");
            var ballpark = directEve.GetLocalSvc("michelle").Call("GetBallpark");
            var balls    = ballpark.Attribute("balls").Call("keys").ToList <long>();

            foreach (var id in balls)
            {
                if (id < 0)
                {
                    continue;
                }

                // Get slim item
                var slimItem = ballpark.Call("GetInvItem", id);

                // Get ball
                var ball = ballpark.Call("GetBall", id);

                // Create the entity
                entitiesById[id] = new DirectEntity(directEve, ballpark, ball, slimItem, id);
            }

            // Mark active target
            var activeTarget   = pySharp.Import("state").Attribute("activeTarget");
            var activeTargetId = (long)directEve.GetLocalSvc("state").Call("GetExclState", activeTarget);

            if (entitiesById.TryGetValue(activeTargetId, out entity))
            {
                entity.IsActiveTarget = true;
            }

            var target  = directEve.GetLocalSvc("target");
            var targets = target.Attribute("targetsByID").ToDictionary().Keys;

            foreach (var targetId in targets)
            {
                if (!entitiesById.TryGetValue((long)targetId, out entity))
                {
                    continue;
                }

                entity.IsTarget = true;
            }

            var targeting = target.Attribute("targeting").ToDictionary <long>().Keys;

            foreach (var targetId in targeting)
            {
                if (!entitiesById.TryGetValue(targetId, out entity))
                {
                    continue;
                }

                entity.IsTargeting = true;
            }

            var targetedBy = target.Attribute("targetedBy").ToList <long>();

            foreach (var targetId in targetedBy)
            {
                if (!entitiesById.TryGetValue(targetId, out entity))
                {
                    continue;
                }

                entity.IsTargetedBy = true;
            }

            var attackers = directEve.GetLocalSvc("tactical").Attribute("attackers").ToDictionary <long>();

            foreach (var attacker in attackers)
            {
                if (!entitiesById.TryGetValue(attacker.Key, out entity))
                {
                    continue;
                }

                entity.IsAttacking = true;

                var attacks = attacker.Value.ToList();
                foreach (var attack in attacks.Select(a => (string)a.Item(1)))
                {
                    entity.IsWarpScramblingMe |= attack == "effects.WarpScramble";
                    entity.IsWebbingMe        |= attack == "effects.ModifyTargetSpeed";
                    entity.Attacks.Add(attack);
                }
            }

            var jammers = directEve.GetLocalSvc("tactical").Attribute("jammers").ToDictionary <long>();

            foreach (var jammer in jammers)
            {
                if (!entitiesById.TryGetValue(jammer.Key, out entity))
                {
                    continue;
                }

                var ews = jammer.Value.ToDictionary <string>().Keys;
                foreach (var ew in ews)
                {
                    entity.IsNeutralizingMe       |= ew == "ewEnergyNeut";
                    entity.IsJammingMe            |= ew == "electronic";
                    entity.IsSensorDampeningMe    |= ew == "ewRemoteSensorDamp";
                    entity.IsTargetPaintingMe     |= ew == "ewTargetPaint";
                    entity.IsTrackingDisruptingMe |= ew == "ewTrackingDisrupt";
                    entity.ElectronicWarfare.Add(ew);
                }
            }

            return(entitiesById);
        }
示例#10
0
        /// <summary>
        ///   Calculate distance from entity
        /// </summary>
        /// <param name = "x"></param>
        /// <param name = "y"></param>
        /// <param name = "z"></param>
        /// <param name="entity"> </param>
        /// <returns></returns>
        public double DistanceFromEntity(double x, double y, double z, DirectEntity entity)
        {
            if (entity == null)
            {
                return double.MaxValue;
            }

            double curX = entity.X;
            double curY = entity.Y;
            double curZ = entity.Z;

            return Math.Sqrt((curX - x) * (curX - x) + (curY - y) * (curY - y) + (curZ - z) * (curZ - z));
        }
示例#11
0
 public EntityCache(DirectEntity entity)
 {
     _directEntity = entity;
     //Interlocked.Increment(ref EntityCacheInstances);
     ThisEntityCacheCreated = DateTime.UtcNow;
 }
示例#12
0
 public EntityCache(DirectEntity entity)
 {
     //
     // reminder: this class and all the info within it is created (and destroyed!) each frame for each entity!
     //
     _directEntity = entity;
     //Interlocked.Increment(ref EntityCacheInstances);
     ThisEntityCacheCreated = DateTime.UtcNow;
 }
示例#13
0
        /// <summary>
        ///   Calculate distance between 2 entities
        /// </summary>
        public double DistanceBetween2Entities(DirectEntity entity1, DirectEntity entity2)
        {
            if (entity1 == null || entity2 == null)
            {
                return double.MaxValue;
            }

            double entity1X = entity1.X;
            double entity1Y = entity1.Y;
            double entity1Z = entity1.Z;

            double entity2X = entity2.X;
            double entity2Y = entity2.Y;
            double entity2Z = entity2.Z;

            return Math.Sqrt((entity1X - entity2X) * (entity1X - entity2X) + (entity1Y - entity2Y) * (entity1Y - entity2Y) + (entity1Z - entity2Z) * (entity1Z - entity2Z));
        }
示例#14
0
        private Composite CreateBehavior_SimpleWarp()
        {
            return (
                new Sequence(
                    // Session must be ready (i.e. we are logged in)...
                    new Decorator(ret => Cache.Instance.DirectEve.Session.IsReady, new ActionAlwaysSucceed()),

                    // We must be in space...
                    new Decorator(ret => Cache.Instance.InSpace, new ActionAlwaysSucceed()),

                    // We must not be in warp...
                    new Decorator(ret => Cache.Instance.InWarp == false, new ActionAlwaysSucceed()),

                    // Find a celestial to warp to
                    new TreeSharp.Action( delegate {
                        _warpToMe = null;
                        var entities = Cache.Instance.DirectEve.Entities.Where( e => e.GroupId == 7 );      // 7 is planets
                        if( entities.Count() > 0 )
                        {
                            _warpToMe = entities.OrderByDescending(e => e.Distance).First();
                        }
                    } ),

                    // do we have an entity?
                    new Decorator(ret => _warpToMe != null, new ActionAlwaysSucceed()),

                    // warp to it if we can
                    new Decorator(ret => _warpToMe.Distance > 152000, new TreeSharp.Action(delegate
                    {
                        _warpToMe.WarpTo();
                    })),

                    // Wait for warp to start...  Use 30 seconds for big slow ships
                    new Wait(30, ret => Cache.Instance.InWarp == true, new ActionAlwaysSucceed()),

                    // Wait for warp to complete...
                    new WaitContinue(30, ret => Cache.Instance.InWarp == false, new ActionAlwaysSucceed())
                )
            );
        }