private void GetOB()
        {
            try
            {
                if (!MyAPIGateway.Session.IsServer)
                {
                    if (PhysCache == null)
                    {
                        topEntity.InitBoxPhysics(MyStringHash.NullOrEmpty, Vector3.Zero, Vector3.One, 0, 0, 0, 0, RigidBodyFlag.RBF_STATIC);
                        PhysCache = topEntity.Physics;

                        missile           = topEntity.GetObjectBuilder() as MyObjectBuilder_Missile;
                        topEntity.Physics = null;
                    }
                    else
                    {
                        topEntity.Physics = PhysCache;

                        missile           = topEntity.GetObjectBuilder() as MyObjectBuilder_Missile;
                        topEntity.Physics = null;
                    }
                }
            }
            catch (Exception e)
            {
                //MyAPIGateway.Utilities.ShowNotification("[ Error in " + GetType().FullName + ": " + e.Message + " ]", 10000, MyFontEnum.Red);
                MyLog.Default.WriteLine(e);
            }
        }
Пример #2
0
 public MissileProfile(IMyEntity entity, MyObjectBuilder_Missile ob)
 {
     Entity        = entity;
     EntityId      = entity.EntityId;
     Owner         = ob.Owner;
     LauncherId    = ob.LauncherId;
     ExplodeRadius = 4;
     Removed       = false;
     RemovalCoords = Vector3D.Zero;
     RemovalTime   = MyAPIGateway.Session.GameDateTime;
     HitObjects    = new List <object>();
     //Logger.AddMsg("Owner: " + ob.Owner.ToString(), true);
     //Logger.AddMsg("Origin: " + ob.OriginEntity.ToString(), true);
     //Logger.AddMsg("Launcher: " + ob.LauncherId.ToString(), true);
 }
Пример #3
0
        public static void NewEntityDetected(IMyEntity entity)
        {
            var ob = new MyObjectBuilder_Missile();

            try {
                ob = entity.GetObjectBuilder() as MyObjectBuilder_Missile;
            } catch (Exception) {
                return;
            }

            if (ob == null)
            {
                return;
            }

            CurrentMissiles.Add(new MissileProfile(entity, ob));
        }
        public static IMyIdentity EntityToIdentity(IMyEntity entity)
        {
            if (entity == null)
            {
                return(null);
            }

            if (entity is IMyCharacter)
            {
                return(CharacterToIdentity((IMyCharacter)entity));
            }
            else if (entity is IMyEngineerToolBase)
            {
                var tool = (IMyEngineerToolBase)entity;
                if (tool == null)
                {
                    return(null);
                }

                var toolOwner = MyAPIGateway.Entities.GetEntityById(tool.OwnerId);
                if (toolOwner == null)
                {
                    return(null);
                }

                var character = (IMyCharacter)toolOwner;
                if (character == null)
                {
                    return(null);
                }

                return(CharacterToIdentity(character));
            }
            else if (entity is MyCubeBlock)
            {
                var block = (MyCubeBlock)entity;
                if (block == null)
                {
                    return(null);
                }
                return(CubeBlockOwnerToIdentity(block));
            }
            else if (entity is IMyGunBaseUser)
            {
                var weapon = (IMyGunBaseUser)entity;
                if (weapon == null)
                {
                    return(null);
                }

                var weaponOwner = weapon.Owner;
                if (weaponOwner == null)
                {
                    return(null);
                }

                var character = (IMyCharacter)weaponOwner;
                if (character == null)
                {
                    return(null);
                }

                return(CharacterToIdentity(character));
            }
            else if (entity is IMyCubeGrid)
            {
                return(GridToIdentity((IMyCubeGrid)entity));
            }
            else if (entity.GetType().Name == "MyMissile")
            {
                try
                {
                    MyObjectBuilder_Missile builder = (MyObjectBuilder_Missile)entity.GetObjectBuilder();
                    var identities = new List <IMyIdentity>();
                    MyAPIGateway.Players.GetAllIdentites(identities, i => i.IdentityId == builder.Owner);
                    return(identities.FirstOrDefault());
                } catch (Exception e)
                {
                    Logging.Instance.WriteLine("Could not parse missileentity");
                }
            }

            return(null);
        }
        public override void OnAddedToScene()
        {
            try
            {
                // spawn missile trail emmitter on client only
                if (MyAPIGateway.Session.IsServer && MyAPIGateway.Utilities.IsDedicated)
                {
                    return;
                }

                topEntity = Entity;

                if (topEntity == null)
                {
                    return;
                }

                if (topEntity?.GetType().ToString() == MyMissile)
                {
                    // if client on a server, temporarily add physics before getting objectbuilder of missile
                    if (!MyAPIGateway.Session.IsServer)
                    {
                        MyAPIGateway.Utilities.InvokeOnGameThread(GetOB);
                    }
                    else
                    {
                        missile = topEntity.GetObjectBuilder() as MyObjectBuilder_Missile;
                    }



                    //issue with this cache and separate missile type situations

                    //if (missile != null && typeCache == null)
                    //{
                    //    missileType = missile.AmmoMagazineId.SubtypeId;
                    //    typeCache = missileType;
                    //}
                    //else
                    //{
                    //    missileType = typeCache;
                    //}

                    //temporary
                    if (missile != null)
                    {
                        missileType = missile.AmmoMagazineId.SubtypeId;
                    }


                    //add identical smoke particle back to vanilla 200mm missiles (original sbc library nulled)
                    if (missileType == "Missile200mm")
                    {
                        typeCache = null;

                        // make sure to get initial entity location, then spawn emitter
                        UpdateMissileLocation();
                        MyParticlesManager.TryCreateParticleEffect("Rocket_Fume", ref missileWorldMatrix, ref missilePosition, topEntity.Render.ParentIDs[0], out missileTrail);
                    }
                }
            }
            catch (Exception e)
            {
                //MyAPIGateway.Utilities.ShowNotification("[ Error in " + GetType().FullName + ": " + e.Message + " ]", 10000, MyFontEnum.Red);
                MyLog.Default.WriteLine(e);
            }
        }