Ejemplo n.º 1
0
        public void AttachPilot(MyCharacter pilot, bool storeOriginalPilotWorld = true, bool calledFromInit = false, bool merged = false)
        {
            System.Diagnostics.Debug.Assert(pilot != null);
            System.Diagnostics.Debug.Assert(m_pilot == null);

            if (Sync.IsServer)
            {
                MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(pilot), MyExternalReplicable.FindByObject(this.CubeGrid));
            }

            MyAnalyticsHelper.ReportActivityStart(pilot, "cockpit", "cockpit", string.Empty, string.Empty);

            m_pilot = pilot;
            m_pilot.OnMarkForClose += m_pilotClosedHandler;
            m_pilot.IsUsing = this;

            if (storeOriginalPilotWorld)
            {
                m_pilotRelativeWorld.Value = (Matrix)MatrixD.Multiply(pilot.WorldMatrix, this.PositionComp.WorldMatrixNormalizedInv);
            }

            if (pilot.InScene)
                MyEntities.Remove(pilot);

            m_pilot.Physics.Enabled = false;
            m_pilot.PositionComp.SetWorldMatrix(WorldMatrix, this);
            m_pilot.Physics.Clear();
            //m_pilot.SetPosition(GetPosition() - WorldMatrix.Forward * 0.5f);

            if (!Hierarchy.Children.Any(x => x.Entity == m_pilot))  //may contain after load
                Hierarchy.AddChild(m_pilot, true, true);

            var gunEntity = m_pilot.CurrentWeapon as MyEntity;
            if (gunEntity != null && !m_forgetTheseWeapons.Contains(m_pilot.CurrentWeapon.DefinitionId))
            {
                m_pilotGunDefinition = m_pilot.CurrentWeapon.DefinitionId;
            }
            else
                m_pilotGunDefinition = null;

            MyAnimationDefinition animationDefinition;
            MyDefinitionId id = new MyDefinitionId(typeof(MyObjectBuilder_AnimationDefinition), BlockDefinition.CharacterAnimation);
            if (!MyDefinitionManager.Static.TryGetDefinition(id, out animationDefinition) && !MyFileSystem.FileExists(BlockDefinition.CharacterAnimation))
            {
                BlockDefinition.CharacterAnimation = null;
            }
            m_pilotFirstPerson = pilot.IsInFirstPersonView;
            PlacePilotInSeat(pilot);
            m_pilot.SuitBattery.ResourceSink.TemporaryConnectedEntity = this;
            m_rechargeSocket.PlugIn(m_pilot.SuitBattery.ResourceSink);

            if (pilot.ControllerInfo.Controller != null)
            {
                Sync.Players.SetPlayerToCockpit(pilot.ControllerInfo.Controller.Player, this);
            }
            // Control should be handled elsewhere if we initialize the grid in the Init(...)
            if (!calledFromInit)
            {
                GiveControlToPilot();
                m_pilot.SwitchToWeapon(null);

            }

            if (Sync.IsServer)
            {               
                m_attachedCharacterId.Value = m_pilot.EntityId;
                m_storeOriginalPlayerWorldMatrix.Value = storeOriginalPilotWorld;
            }

            var jetpack = m_pilot.JetpackComp;
            if (jetpack != null)
            {
                m_pilotJetpackEnabledBackup = jetpack.TurnedOn;
                m_pilot.JetpackComp.TurnOnJetpack(false);
            }
            else
            {
                m_pilotJetpackEnabledBackup = null;
            }

            m_lastPilot = pilot;
            if (GetInCockpitSound != MySoundPair.Empty && !calledFromInit && !merged)
                PlayUseSound(true);
            m_playIdleSound = true;

            if(MyVisualScriptLogicProvider.PlayerEnteredCockpit != null)
                MyVisualScriptLogicProvider.PlayerEnteredCockpit(Name, pilot.GetPlayerIdentityId(), CubeGrid.Name);

        }
        public void DebugUnlockAllResearch(MyCharacter character)
        {
            if (character == null)
                return;

            long identityId = character.GetPlayerIdentityId();
            HashSet<MyDefinitionId> unlockedItems;
            if (!m_unlockedResearch.TryGetValue(identityId, out unlockedItems))
                unlockedItems = new HashSet<MyDefinitionId>();

            foreach (var research in m_requiredResearch)
                unlockedItems.Add(research);

            m_unlockedResearch[identityId] = unlockedItems;
        }
Ejemplo n.º 3
0
        public static bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint,
                                             Vector3D playerPosition, bool keepOriginalLocation, long steamID, string Name, CommandContext context = null, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Log.Warn("No grids in blueprint!");

                if (context != null)
                {
                    context.Respond("No grids in blueprint!");
                }

                return(false);
            }

            foreach (var grid in grids)
            {
                foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks)
                {
                    long ownerID = AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).IdentityId;
                    block.Owner   = ownerID;
                    block.BuiltBy = ownerID;
                }
            }

            List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList());

            if (!keepOriginalLocation)
            {
                /* Where do we want to paste the grids? Lets find out. */
                var pos = FindPastePosition(grids, playerPosition);
                if (pos == null)
                {
                    Log.Warn("No free Space found!");

                    if (context != null)
                    {
                        context.Respond("No free space available!");
                    }

                    return(false);
                }

                var newPosition = pos.Value;

                /* Update GridsPosition if that doesnt work get out of here. */
                if (!UpdateGridsPosition(grids, newPosition))
                {
                    if (context != null)
                    {
                        context.Respond("The File to be imported does not seem to be compatible with the server!");
                    }

                    return(false);
                }
                Sandbox.Game.Entities.Character.MyCharacter player = MySession.Static.Players.GetPlayerByName(AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).DisplayName).Character;
                MyGps           gps           = CreateGps(pos.Value, Color.LightGreen, 60, Name);
                MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS;
                MyGps           gpsRef        = gps;
                long            entityId      = 0L;
                entityId = gps.EntityId;
                gpsCollection.SendAddGps(player.GetPlayerIdentityId(), ref gpsRef, entityId, true);
            }
            else if (!force)
            {
                var sphere = FindBoundingSphere(grids);

                var position = grids[0].PositionAndOrientation.Value;

                sphere.Center = position.Position;

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities);

                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        if (context != null)
                        {
                            context.Respond("There are potentially other grids in the way. If you are certain is free you can set 'force' to true!");
                        }

                        return(false);
                    }
                }
            }
            /* Stop grids */
            foreach (var grid in grids)
            {
                grid.AngularVelocity = new SerializableVector3();
                grid.LinearVelocity  = new SerializableVector3();

                Random random = new Random();
            }
            /* Remapping to prevent any key problems upon paste. */
            MyEntities.RemapObjectBuilderCollection(objectBuilderList);

            bool hasMultipleGrids = objectBuilderList.Count > 1;

            if (!hasMultipleGrids)
            {
                foreach (var ob in objectBuilderList)
                {
                    MyEntities.CreateFromObjectBuilderParallel(ob, true);
                }
            }
            else
            {
                MyEntities.Load(objectBuilderList, out _);
            }

            return(true);
        }
        public void ResetResearch(MyCharacter character)
        {
            if (character == null)
                return;

            ResetResearch(character.GetPlayerIdentityId());
        }
        public bool IsResearchUnlocked(MyCharacter character, MyDefinitionId id)
        {
            if (character == null)
                return true;

            return IsResearchUnlocked(character.GetPlayerIdentityId(), id);
        }
        public bool CanUse(MyCharacter character, MyDefinitionId id)
        {
            if (character == null)
                return true;

            return CanUse(character.GetPlayerIdentityId(), id);
        }
        public bool UnlockResearch(MyCharacter character, MyDefinitionId id)
        {
            Debug.Assert(Sync.IsServer);
            if (character == null)
                return false;

            var definition = MyDefinitionManager.Static.GetDefinition(id);
            SerializableDefinitionId serializableId = id;
            if (CanUnlockResearch(character.GetPlayerIdentityId(), definition))
            {
                MyMultiplayer.RaiseStaticEvent(x => UnlockResearchSuccess, character.GetPlayerIdentityId(), serializableId);
                return true;
            }
            else if (character.ControllerInfo.Controller != null)
            {
                var endpoint = new EndpointId(character.ControllerInfo.Controller.Player.Client.SteamUserId);
                MyMultiplayer.RaiseStaticEvent(x => UnlockResearchFailed, serializableId, targetEndpoint: endpoint);
            }

            return false;
        }
        public bool TryGetResearch(MyCharacter character, out HashSet<MyDefinitionId> research)
        {
            if (character == null)
            {
                research = null;
                return false;
            }

            return TryGetResearch(character.GetPlayerIdentityId(), out research);
        }