// CH: TODO: This is here just temporarily. We should move it to a better place later
        public virtual void AfterCharacterCreate(MyCharacter character) {
			if (MyFakes.ENABLE_MEDIEVAL_INVENTORY)
			{
				character.InventoryAggregate = new Sandbox.Game.Entities.Inventory.MyInventoryAggregate();
				character.InventoryAggregate.AddComponent(new Sandbox.Game.Entities.Inventory.MyInventoryAggregate());
			}
		}
Beispiel #2
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);
        }
Beispiel #3
0
        public MyBattery(MyCharacter owner)
        {
            m_owner = owner;
            SyncObject = new MySyncBattery(this);
			ResourceSink = new MyResourceSinkComponent();
			ResourceSource = new MyResourceSourceComponent();
        }
 protected override void OnShow()
 {
     m_playerCharacter = MySession.LocalCharacter;
     if (m_playerCharacter != null)
     {
         m_playerCharacter.OnWeaponChanged += OnWeaponChanged;
     }
     base.OnShow();
 }
Beispiel #5
0
        public void SendCapacitySync(MyCharacter owner, float remainingCapacity)
        {
            var msg = new CapacitySyncMsg();

            msg.EntityId = owner.EntityId;
            msg.RemainingCapacity = remainingCapacity;

            Sync.Layer.SendMessageToAll(ref msg, MyTransportMessageEnum.Success);
        }
Beispiel #6
0
            public void RequestUse(UseActionEnum actionEnum, MyCharacter user)
            {
                var msg = new UseMsg();

                msg.EntityId = m_block.EntityId;
                msg.UsedByEntityId = user.EntityId;
                msg.ActionEnum = actionEnum;

                Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);

            }
 public bool UpdateLose(MyCharacter me)
 {
     foreach (var trigger in m_loseTriggers) 
         if (trigger.IsTrue || trigger.Update(me))
         {//Lost
             if (IsLocal(me))
                 trigger.DisplayMessage(false);
             Lost = true;
             return true;
         }
     return false;
 }
 public bool UpdateWin(MyCharacter me)
 {
     foreach (var trigger in m_winTriggers)
         if (trigger.IsTrue || trigger.Update(me))
         { //Won!
             if (IsLocal(me))
                 trigger.DisplayMessage(true);
             Won = true;
             return true;
         }
     return false;
 }
        /*public bool Update(MyFaction faction, MyCharacter me)
        {
            bool res = false;
            if (faction != null)
                res = Update(faction.FactionId, me);
            else
                res = Update(me.EntityId, me);

            return res;
        }*/
        /*public bool Update()
        {
            return false;
        }*/

        public bool Update(MyPlayer.PlayerId Id, MyCharacter me)
        {
            MyMissionTriggers mtrig;
            if (!MissionTriggers.TryGetValue(Id, out mtrig))
            {
                //Debug.Assert(false,"Bad ID for update in missionTriggers");
                return false;
            }
            mtrig.UpdateWin(me);

            mtrig.UpdateLose(me);//!!
            return false;
        }
Beispiel #10
0
        public virtual void OnControlAcquired(Sandbox.Game.Entities.Character.MyCharacter owner)
        {
            m_owner = owner;

            InitBlockingPhysics(m_owner);

            foreach (var c in m_toolComponents.Values)
            {
                c.OnControlAcquired(owner);
            }

            this.RaiseEntityEvent(MyStringHash.GetOrCompute("ControlAcquired"), new MyEntityContainerEventExtensions.ControlAcquiredParams(owner));
        }
        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);
        }
        void IMyUseObject.Use(UseActionEnum actionEnum, MyCharacter user)
        {
            // How to distinct between server sending message?
            // - it's response...always

            // This is request
            // 1) use - server call
            // -- on server: take control of entity
            // -- -- on success, use it, broadcast
            // -- -- on failure, don't use it, report back

            // Something like:
            // -- extension method IControllableEntity.RequestUse(actionEnum, user, handler)
            if(Cockpit is MyCockpit)
                (Cockpit as MyCockpit).RequestUse(actionEnum, user);
        }
        void IMyUseObject.Use(UseActionEnum actionEnum, MyCharacter user)
        {
            var relation = Block.GetUserRelationToOwner(user.ControllerInfo.ControllingIdentityId);
            if (relation != Common.MyRelationsBetweenPlayerAndBlock.Owner && relation != Common.MyRelationsBetweenPlayerAndBlock.FactionShare)
            {
                if (user.ControllerInfo.IsLocallyHumanControlled())
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.AccessDenied);
                }
                return;
            }

            switch (actionEnum)
            {
                case UseActionEnum.Manipulate:
                    MyGuiSandbox.AddScreen(MyGuiScreenGamePlay.ActiveGameplayScreen = new MyGuiScreenWardrobe(user));
                    break;
            }
        }
        public MyGuiScreenWardrobe(MyCharacter user)
            : base(size: new Vector2(0.31f, 0.55f),
                   position: MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_RIGHT_AND_VERTICAL_TOP),
                   backgroundColor: MyGuiConstants.SCREEN_BACKGROUND_COLOR,
                   backgroundTexture: MyGuiConstants.TEXTURE_SCREEN_BACKGROUND.Texture)
        {
            EnabledBackgroundFade = false;

            m_user        = user;
            m_storedModel = m_user.ModelName;
            m_storedHSV   = m_user.ColorMask;

            m_selectedModel = GetDisplayName(m_user.ModelName);
            m_selectedHSV   = m_storedHSV;

            m_displayModels = new Dictionary<string, int>();
            m_models = new Dictionary<int, string>();

            int i = 0;
            foreach (var character in MyDefinitionManager.Static.Characters)
            {
                if (!character.UsableByPlayer) continue;

                var key = GetDisplayName(character.Name);
                m_displayModels[key] = i;
                m_models[i++] = character.Name;
            }

            RecreateControls(true);

            m_sliderHue.Value        = m_selectedHSV.X * 360f;
            m_sliderSaturation.Value = m_selectedHSV.Y * 100f;
            m_sliderValue.Value      = m_selectedHSV.Z * 100f;

            m_sliderHue.ValueChanged        += OnValueChange;
            m_sliderSaturation.ValueChanged += OnValueChange;
            m_sliderValue.ValueChanged      += OnValueChange;

            ChangeCamera();
            UpdateLabels();
        }
        void IMyUseObject.Use(UseActionEnum actionEnum, MyCharacter user)
        {
            var relation = Block.GetUserRelationToOwner(user.ControllerInfo.ControllingIdentityId);
            if (relation != Common.MyRelationsBetweenPlayerAndBlock.Owner && relation != Common.MyRelationsBetweenPlayerAndBlock.FactionShare)
            {
                if (user.ControllerInfo.IsLocallyHumanControlled())
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.AccessDenied);
                }
                return;
            }

            switch (actionEnum)
            {
                case UseActionEnum.OpenTerminal:
                    MyGuiScreenTerminal.Show(MyTerminalPageEnum.ControlPanel, user, Block);
                    break;
                case UseActionEnum.OpenInventory:
                    if (Block as IMyInventoryOwner != null)
                        MyGuiScreenTerminal.Show(MyTerminalPageEnum.Inventory, user, Block);
                    break;
            }
        }
        void IMyUseObject.Use(UseActionEnum actionEnum, MyCharacter user)
        {
            var relation = Door.GetUserRelationToOwner(user.ControllerInfo.ControllingIdentityId);
            if (relation != Common.MyRelationsBetweenPlayerAndBlock.Owner && relation != Common.MyRelationsBetweenPlayerAndBlock.FactionShare)
            {
                if (user.ControllerInfo.IsLocallyHumanControlled())
                {
                    MyHud.Notifications.Add(MyNotificationSingletons.AccessDenied);
                }
                return;
            }

            switch (actionEnum)
            {
                case UseActionEnum.Manipulate:
                    Door.SetOpenRequest(!Door.Open, user.ControllerInfo.ControllingIdentityId);
                    break;

                case UseActionEnum.OpenTerminal:
                    MyGuiScreenTerminal.Show(MyTerminalPageEnum.ControlPanel, user, Door);
                    break;
            }
        }
Beispiel #17
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);
                    }
                }
            }
        }
 public MyDeltaNetCommand(MyCharacter character, ref Vector3D delta)
 {
     m_character = character;
     m_delta = delta;
 }
Beispiel #19
0
        public override bool AddConstruction(MyCharacter character)
        {
            // The new ship creation clipboard is handled separately
            if (m_shipCreationClipboard.IsActive)
            {
                return m_shipCreationClipboard.PasteGrid(character.GetInventory());
            }

            if (MyFakes.ENABLE_MULTIBLOCKS && MultiBlockCreationIsActivated)
            {
                if (m_multiBlockCreationClipboard.PasteGrid(character.GetInventory(), false))
                {
                    if (MySession.Static.SimpleSurvival)
                        m_lastBlockBuildTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                    return true;
                }
                return false;
            }

            var gizmoSpace = m_gizmo.SpaceDefault;

            if (gizmoSpace.Enabled && BuildInputValid && gizmoSpace.m_buildAllowed && !MyEntities.MemoryLimitReachedReport)
            {
                m_blocksBuildQueue.Clear();
                bool added = AddBlocksToBuildQueueOrSpawn(gizmoSpace);
                if (added)
                {
                    if (CurrentGrid != null && m_blocksBuildQueue.Count > 0)
                        CurrentGrid.BuildBlocks(MyToolbar.ColorMaskHSV, m_blocksBuildQueue);

                    if (MySession.Static.SimpleSurvival)
                        m_lastBlockBuildTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                }
                return added;
            }

            return false;
        }
Beispiel #20
0
 public override bool CanStartConstruction(MyCharacter character)
 {
     if (m_shipCreationClipboard.IsActive)
     {
         return m_shipCreationClipboard.CharacterCanPaste(character);
     }
     else
     {
         if (MySession.Static.SimpleSurvival)
         {
             return true;
         }
         else
         {
             var gizmoSpace = m_gizmo.SpaceDefault;
             return character.CanStartConstruction(gizmoSpace.m_blockDefinition);
         }
     }
 }
 public void RequestUse(UseActionEnum actionEnum, MyCharacter user)
 {
     SyncObject.RequestUse(actionEnum, user);
 }
Beispiel #22
0
 public MyDeltaNetCommand(MyCharacter character, ref Vector3D delta)
 {
     this.m_character = character;
     this.m_delta     = delta;
 }
		public override void OnBeforeRemovedFromContainer()
		{
			m_character = null;

			base.OnBeforeRemovedFromContainer();
		}
		public override void OnBeforeRemovedFromContainer()
		{
			StopStateSound();

			m_character = null;
			base.OnBeforeRemovedFromContainer();
		}
Beispiel #25
0
 public MyCharacterBreath(MyCharacter character)
 {
     CurrentState = State.NoBreath;
     m_character  = character;
 }
        private static MyCharacter CreateCharacterBase(MatrixD worldMatrix, ref Vector3 velocity, string characterName, string model, Vector3? colorMask, bool AIMode, bool useInventory = true, MyBotDefinition botDefinition = null)
        {
            MyCharacter character = new MyCharacter();
            MyObjectBuilder_Character objectBuilder = MyCharacter.Random();
            objectBuilder.CharacterModel = model ?? objectBuilder.CharacterModel;

            if (colorMask.HasValue)
                objectBuilder.ColorMaskHSV = colorMask.Value;

            objectBuilder.JetpackEnabled = MySession.Static.CreativeMode;
            objectBuilder.Battery = new MyObjectBuilder_Battery { CurrentCapacity = 1 };
            objectBuilder.AIMode = AIMode;
            objectBuilder.DisplayName = characterName;
            objectBuilder.LinearVelocity = velocity;
            objectBuilder.PositionAndOrientation = new MyPositionAndOrientation(worldMatrix);
            character.Init(objectBuilder);

            MyEntities.RaiseEntityCreated(character);
            MyEntities.Add(character);

            System.Diagnostics.Debug.Assert(character.GetInventory() as MyInventory != null, "Null or unexpected inventory type returned!");
            if (useInventory)
                MyWorldGenerator.InitInventoryWithDefaults(character.GetInventory() as MyInventory);
            else if (botDefinition != null)
            {
                // use inventory from bot definition
                botDefinition.AddItems(character);
            }
            //character.PositionComp.SetWorldMatrix(worldMatrix);
            if (velocity.Length() > 0)
            {
                var jetpack = character.JetpackComp;

                if (jetpack != null)
                    jetpack.EnableDampeners(false, false);
            }

            return character;
        }
Beispiel #27
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 MyMoveNetCommand(MyCharacter character, ref Vector3 move, ref Vector2 rotate, ref float roll)
 {
     m_character = character;
     m_move = move;
     m_rotate = rotate;
     m_roll = roll;
 }
Beispiel #29
0
 public void OnControlAcquired(Sandbox.Game.Entities.Character.MyCharacter owner)
 {
     Owner = owner;
 }
		public override void OnAddedToContainer()
		{
			base.OnAddedToContainer();
			m_character = Entity as MyCharacter;
			foreach(var soundEmitter in m_soundEmitters)
			{
				soundEmitter.Entity = Entity as MyEntity;
			}
            if(m_windEmitter != null)
                m_windEmitter.Entity = Entity as MyEntity;
            if (m_oxygenEmitter != null)
                m_oxygenEmitter.Entity = Entity as MyEntity;
			m_lastUpdateMovementState = m_character.GetCurrentMovementState();
            m_characterPhysicalMaterial = MyStringHash.GetOrCompute(m_character.Definition.PhysicalMaterial);
			InitSounds();
		}
		public override void OnAddedToContainer()
		{
			base.OnAddedToContainer();
			m_character = Entity as MyCharacter;
			foreach(var soundEmitter in m_soundEmitters)
			{
				soundEmitter.Entity = Entity as MyEntity;
			}
			m_lastUpdateMovementState = m_character.GetCurrentMovementState();
			InitSounds();
		}
		public override void OnAddedToContainer()
		{
			base.OnAddedToContainer();

			m_character = Container.Entity as MyCharacter;
		}
        private bool TryFindSavedEntity()
        {
            MyEntity oldControllerEntity;
            if (m_savedPreviousControlledEntityId.HasValue && MyEntities.TryGetEntityById(m_savedPreviousControlledEntityId.Value, out oldControllerEntity))
            {
                m_previousControlledEntity = (IMyControllableEntity)oldControllerEntity;
                if (m_previousControlledEntity != null)
                {
                    AddPreviousControllerEvents();

                    if (m_previousControlledEntity is MyCockpit)
                    {
                        cockpitPilot = (m_previousControlledEntity as MyCockpit).Pilot;
                    }
                    return true;
                }
            }

            return false;
        }
 public void SetCharacter(MyCharacter character)
 {
     m_character = character;
 }
        private void AcquireControl(IMyControllableEntity previousControlledEntity)
        {
            if (!CheckPreviousEntity(previousControlledEntity))
            {
                return;
            }

            if (m_autoPilotEnabled)
            {
                SetAutoPilotEnabled(false);
            }

            PreviousControlledEntity = previousControlledEntity;
            var shipController = (PreviousControlledEntity as MyShipController);
            if (shipController != null)
            {
                m_enableFirstPerson = shipController.EnableFirstPerson;
                cockpitPilot = shipController.Pilot;
                if (cockpitPilot != null)
                {
                    cockpitPilot.CurrentRemoteControl = this;
                }
            }
            else
            {
                m_enableFirstPerson = true;

                var character = PreviousControlledEntity as MyCharacter;
                if (character != null)
                {
                    character.CurrentRemoteControl = this;
                }
            }

            //MySession.Static.SetCameraController(MyCameraControllerEnum.Entity, this);

            if (MyCubeBuilder.Static.IsActivated)
            {
                //MyCubeBuilder.Static.Deactivate();
                MySession.Static.GameFocusManager.Clear();
            }

            UpdateEmissivity();
        }