示例#1
0
        protected override void AddItems(MyCharacter character)
        {
            base.AddItems(character);

            var ob = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(StartingWeaponId.SubtypeName);
            if (character.WeaponTakesBuilderFromInventory(StartingWeaponId))
            {
                character.GetInventory(0).AddItems(1, ob);
            }

            // else // allowing the inventory items to be added
            {
                foreach (var weaponDef in HumanoidDefinition.InventoryItems)
                {
                    ob = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(weaponDef.SubtypeName);
                    character.GetInventory(0).AddItems(1, ob);
                }
            }

            character.SwitchToWeapon(StartingWeaponId);

            {
                MyDefinitionId weaponDefinitionId;
                weaponDefinitionId = new MyDefinitionId(typeof(MyObjectBuilder_WeaponDefinition), StartingWeaponId.SubtypeName);

                MyWeaponDefinition weaponDefinition;

                if (MyDefinitionManager.Static.TryGetWeaponDefinition(weaponDefinitionId, out weaponDefinition)) //GetWeaponDefinition(StartingWeaponId);
                {
                    if (weaponDefinition.HasAmmoMagazines())
                    {
                        var ammo = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_AmmoMagazine>(weaponDefinition.AmmoMagazinesId[0].SubtypeName);
                        character.GetInventory(0).AddItems(3, ammo);
                    }
                }
            }
        }
示例#2
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);

        }
示例#3
0
        public void AttachPilot(MyCharacter pilot, bool storeOriginalPilotWorld = true, bool calledFromInit = false)
        {
            System.Diagnostics.Debug.Assert(pilot != null);
            System.Diagnostics.Debug.Assert(m_pilot == null);

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

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

            StartLoopSound();

            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);
            m_pilot.Physics.Clear();
            //m_pilot.SetPosition(GetPosition() - WorldMatrix.Forward * 0.5f);

            Hierarchy.AddChild(m_pilot, true, true);

            var gunEntity = m_pilot.CurrentWeapon as MyEntity;
            if (gunEntity != null)
            {
                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;
            }

            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;
            }
        }
示例#4
0
        public void AttachPilot(MyCharacter pilot, bool storeOriginalPilotWorld = true, bool calledFromInit = false)
        {
            System.Diagnostics.Debug.Assert(pilot != null);
            System.Diagnostics.Debug.Assert(m_pilot == null);

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

            //m_soundEmitter.OwnedBy = m_pilot;
            if (MyFakes.ENABLE_NEW_SOUNDS)
                StartLoopSound();

            if (storeOriginalPilotWorld)
            {
                m_pilotRelativeWorld = (Matrix)MatrixD.Multiply(pilot.WorldMatrix, this.PositionComp.GetWorldMatrixNormalizedInv());
                if (Sync.IsServer)
                {
                    var relativeEntry = new MyPositionAndOrientation(m_pilotRelativeWorld.Value);
                    SyncObject.SendPilotRelativeEntryUpdate(ref relativeEntry);
                }
            }

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

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

            Hierarchy.AddChild(m_pilot, true, true);

            var gunEntity = m_pilot.CurrentWeapon as MyEntity;
            if (gunEntity != null)
            {
                var ob = gunEntity.GetObjectBuilder();
                m_pilotGunDefinition = ob.GetId();
            }
            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;
            }

            PlacePilotInSeat(pilot);
            m_rechargeSocket.PlugIn(m_pilot.SuitBattery);

            // Control should be handled elsewhere if we initialize the grid in the Init(...)
            if (!calledFromInit) GiveControlToPilot();
            m_pilot.SwitchToWeapon(null);
        }
        private void AddItems(MyCharacter character)
        {
            character.GetInventory(0).Clear();

            var ob = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(StartingWeaponId.SubtypeName);
            character.GetInventory(0).AddItems(1, ob);

            foreach (var weaponDef in HumanoidDefinition.InventoryItems)
            {
                ob = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(weaponDef.SubtypeName);
                character.GetInventory(0).AddItems(1, ob);
            }

            character.SwitchToWeapon(StartingWeaponId);
        }
示例#6
0
        private void AddItems(MyCharacter character)
        {
            character.GetInventory(0).Clear();

            var ob = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(StartingWeaponId.SubtypeName);
            if (character.WeaponTakesBuilderFromInventory(StartingWeaponId))            
            {
                character.GetInventory(0).AddItems(1, ob);
            }

            if (HumanoidDefinition.InventoryContentGenerated && MyFakes.ENABLE_RANDOM_INVENTORY)
            {

                MyContainerTypeDefinition cargoContainerDefinition = MyDefinitionManager.Static.GetContainerTypeDefinition(HumanoidDefinition.InventoryContainerTypeId.SubtypeName);
                    if (cargoContainerDefinition != null)
                    {
                        character.GetInventory(0).GenerateContent(cargoContainerDefinition);
                    }
                    else
                    {
                        Debug.Fail("CargoContainer type definition " + HumanoidDefinition.InventoryContainerTypeId + " wasn't found.");
                    }
            }
            else
            {
                foreach (var weaponDef in HumanoidDefinition.InventoryItems)
                {
                    ob = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(weaponDef.SubtypeName);
                    character.GetInventory(0).AddItems(1, ob);
                }
            }

            character.SwitchToWeapon(StartingWeaponId);
        }