private static void SetupPlayer(ref Args args)
        {
            var identity     = Sync.Players.CreateNewIdentity(Sync.Clients.LocalClient.DisplayName);
            var player       = Sync.Players.CreateNewPlayer(identity, Sync.Clients.LocalClient, Sync.MyName);
            var playerStarts = args.Scenario.PossiblePlayerStarts;

            if (playerStarts == null || playerStarts.Length == 0)
            {
                Sync.Players.RespawnComponent.SetupCharacterDefault(player, args);
            }
            else
            {
                Sync.Players.RespawnComponent.SetupCharacterFromStarts(player, playerStarts, args);
            }

            // Setup toolbar
            var defaultToolbar = args.Scenario.DefaultToolbar;

            if (defaultToolbar != null)
            {
                // TODO: JakubD fix this
                MyToolbar toolbar = new MyToolbar(MyToolbarType.Character);
                toolbar.Init(defaultToolbar, player.Character, true);

                MySession.Static.Toolbars.RemovePlayerToolbar(player.Id);
                MySession.Static.Toolbars.AddPlayerToolbar(player.Id, toolbar);
                MyToolbarComponent.InitToolbar(MyToolbarType.Character, defaultToolbar);
                MyToolbarComponent.InitCharacterToolbar(defaultToolbar);
            }
        }
Exemplo n.º 2
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_TimerBlock;

            Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 9, 10);
            Toolbar.Init(ob.Toolbar, this);
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            if (ob.JustTriggered)
            {
                NeedsUpdate |= Common.MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            }
            m_countdownMsStart   = ob.Delay;
            m_countdownMsCurrent = ob.CurrentTime;
            if (m_countdownMsCurrent > 0)
            {
                NeedsUpdate |= Common.MyEntityUpdateEnum.EACH_10TH_FRAME;
            }

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                0.0000001f,
                () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f);
            PowerReceiver.Update();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(PowerReceiver, this));

            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
Exemplo n.º 3
0
        private static void SetupPlayer(ref Args args)
        {
            var identity         = Sync.Players.CreateNewIdentity(Sync.Clients.LocalClient.DisplayName);
            var playerController = Sync.Players.CreateNewPlayer(identity, Sync.Clients.LocalClient, Sync.MyName);
            var playerStarts     = args.Scenario.PossiblePlayerStarts;

            if (playerStarts == null || playerStarts.Length == 0)
            {
                string respawnShipId = MyDefinitionManager.Static.GetFirstRespawnShip();
                playerController.SpawnAtShip(respawnShipId);
            }
            else
            {
                var randomStart = playerStarts[MyUtils.GetRandomInt(playerStarts.Length)];
                randomStart.SetupCharacter(args);
            }


            // Setup toolbar
            if (args.Scenario.DefaultToolbar != null)
            {
                // TODO: JakubD fix this
                MyToolbar toolbar = new MyToolbar(MyToolbarType.Character);
                toolbar.Init(args.Scenario.DefaultToolbar, playerController.Character, true);

                MySession.Static.Toolbars.RemovePlayerToolbar(playerController.Id);
                MySession.Static.Toolbars.AddPlayerToolbar(playerController.Id, toolbar);
                MyToolbarComponent.InitToolbar(MyToolbarType.Character, args.Scenario.DefaultToolbar);
                MyToolbarComponent.InitCharacterToolbar(args.Scenario.DefaultToolbar);
            }
        }
Exemplo n.º 4
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_AirVent)objectBuilder;

            InitializeConveyorEndpoint();
            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME | MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            SourceComp.Init(BlockDefinition.ResourceSourceGroup, new MyResourceSourceInfo {
                ResourceTypeId = m_oxygenGasId, DefinedOutput = BlockDefinition.VentilationCapacityPerSecond, ProductionToCapacityMultiplier = 1
            });
            SourceComp.OutputChanged += Source_OutputChanged;
            var sinkDataList = new List <MyResourceSinkInfo>
            {
                new MyResourceSinkInfo {
                    ResourceTypeId = MyResourceDistributorComponent.ElectricityId, MaxRequiredInput = BlockDefinition.OperationalPowerConsumption, RequiredInputFunc = ComputeRequiredPower
                },
                new MyResourceSinkInfo {
                    ResourceTypeId = m_oxygenGasId, MaxRequiredInput = BlockDefinition.VentilationCapacityPerSecond, RequiredInputFunc = () => VentingCapacity(1f)
                },
            };

            ResourceSink.Init(
                BlockDefinition.ResourceSinkGroup,
                sinkDataList);
            ResourceSink.IsPoweredChanged    += PowerReceiver_IsPoweredChanged;
            ResourceSink.CurrentInputChanged += Sink_CurrentInputChanged;

            m_updateCounter        = 0;
            m_lastOutputUpdateTime = m_updateCounter;
            m_lastInputUpdateTime  = m_updateCounter;
            m_nextGasTransfer      = 0f;

            m_actionToolbar             = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            m_actionToolbar.DrawNumbers = false;
            m_actionToolbar.Init(null, this);

            if (builder.OnFullAction != null)
            {
                m_onFullAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnFullAction);
            }

            if (builder.OnEmptyAction != null)
            {
                m_onEmptyAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnEmptyAction);
            }

            UpdateEmissivity();
            UdpateTexts();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += MyAirVent_IsWorkingChanged;

            SetDepressurizing(builder.IsDepressurizing);
        }
Exemplo n.º 5
0
        public override void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                0.0001f,
                () => IsFunctional ? 0.0001f : 0);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            sinkComp.IsPoweredChanged += ComponentStack_IsFunctionalChanged;
            ResourceSink = sinkComp;

            base.Init(builder, cubeGrid);
            m_emissiveNames = new List <string>(BlockDefinition.ButtonCount);
            for (int i = 1; i <= BlockDefinition.ButtonCount; i++)    //button dummies have 1-based index
            {
                m_emissiveNames.Add(string.Format("Emissive{0}", i)); // because of modding
            }
            var ob = builder as MyObjectBuilder_ButtonPanel;

            Toolbar             = new MyToolbar(MyToolbarType.ButtonPanel, Math.Min(BlockDefinition.ButtonCount, MyToolbar.DEF_SLOT_COUNT), (BlockDefinition.ButtonCount / MyToolbar.DEF_SLOT_COUNT) + 1);
            Toolbar.DrawNumbers = false;
            Toolbar.GetSymbol   = (slot) =>
            {
                var ret = new Sandbox.Graphics.GUI.MyGuiControlGrid.ColoredIcon();
                if (Toolbar.SlotToIndex(slot) < BlockDefinition.ButtonCount)
                {
                    ret.Icon = BlockDefinition.ButtonSymbols[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonSymbols.Length];
                    var color = BlockDefinition.ButtonColors[Toolbar.SlotToIndex(slot) % BlockDefinition.ButtonColors.Length];
                    color.W   = 1;
                    ret.Color = color;
                }
                return(ret);
            };

            Toolbar.Init(ob.Toolbar, this);
            Toolbar.ItemChanged += Toolbar_ItemChanged;
            AnyoneCanUse         = ob.AnyoneCanUse;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            ResourceSink.Update();

            if (ob.CustomButtonNames != null)
            {
                m_customButtonNames = ob.CustomButtonNames;
            }

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;

            UseObjectsComponent.GetInteractiveObjects <MyUseObjectPanelButton>(m_buttonsUseObjects);
        }
Exemplo n.º 6
0
        private void CreateDefaultToolbar(PlayerId playerId)
        {
            if (ContainsToolbar(playerId))
            {
                return;
            }
            var toolbar = new MyToolbar(MyToolbarType.Character);

            toolbar.Init(MySession.Static.Scenario.DefaultToolbar, null, true);
            AddPlayerToolbar(playerId, toolbar);
        }
Exemplo n.º 7
0
 public void LoadToolbars(MyObjectBuilder_Checkpoint checkpoint)
 {
     if (checkpoint.AllPlayersData != null)
     {
         foreach (var item in checkpoint.AllPlayersData.Dictionary)
         {
             var playerId = new PlayerId(item.Key.ClientId, item.Key.SerialId);
             var toolbar  = new MyToolbar(MyToolbarType.Character);
             toolbar.Init(item.Value.Toolbar, null, true);
             AddPlayerToolbar(playerId, toolbar);
         }
     }
 }
Exemplo n.º 8
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            var timerBlockDefinition = BlockDefinition as MyTimerBlockDefinition;

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                timerBlockDefinition.ResourceSinkGroup,
                0.0000001f,
                () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInput : 0f);
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);

            var ob = objectBuilder as MyObjectBuilder_TimerBlock;

            Toolbar = new MyToolbar(MyToolbarType.ButtonPanel, 9, 10);
            Toolbar.Init(ob.Toolbar, this);
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            if (ob.JustTriggered)
            {
                NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
            }

            IsCountingDown       = ob.IsCountingDown;
            m_countdownMsStart   = ob.Delay;
            m_countdownMsCurrent = ob.CurrentTime;
            Silent = ob.Silent;

            if (m_countdownMsCurrent > 0)
            {
                NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;
            }
            NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME;

            ResourceSink.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink.Update();

            AddDebugRenderComponent(new Sandbox.Game.Components.MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            m_beepStart   = new MySoundPair(timerBlockDefinition.TimerSoundStart);
            m_beepMid     = new MySoundPair(timerBlockDefinition.TimerSoundMid);
            m_beepEnd     = new MySoundPair(timerBlockDefinition.TimerSoundEnd);
            m_beepEmitter = new MyEntity3DSoundEmitter(this);
        }
Exemplo n.º 9
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;

            base.Init(objectBuilder, cubeGrid);

            var builder = (MyObjectBuilder_AirVent)objectBuilder;

            m_isDepressurizing = builder.IsDepressurizing;

            InitializeConveyorEndpoint();
            NeedsUpdate = MyEntityUpdateEnum.EACH_10TH_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Factory,
                false,
                BlockDefinition.OperationalPowerConsumption,
                ComputeRequiredPower);
            PowerReceiver.IsPoweredChanged += PowerReceiver_IsPoweredChanged;
            PowerReceiver.Update();

            m_actionToolbar             = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            m_actionToolbar.DrawNumbers = false;
            m_actionToolbar.Init(null, this);

            if (builder.OnFullAction != null)
            {
                m_onFullAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnFullAction);
            }
            if (builder.OnEmptyAction != null)
            {
                m_onEmptyAction = MyToolbarItemFactory.CreateToolbarItem(builder.OnEmptyAction);
            }

            UpdateEmissivity();
            UdpateTexts();

            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint));

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
Exemplo n.º 10
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            SyncFlag = true;
            base.Init(objectBuilder, cubeGrid);

            m_items = new List <ToolbarItem>(2);
            for (int i = 0; i < 2; i++)
            {
                m_items.Add(new ToolbarItem()
                {
                    EntityID = 0
                });
            }
            Toolbar             = new MyToolbar(MyToolbarType.ButtonPanel, 2, 1);
            Toolbar.DrawNumbers = false;

            var builder = (MyObjectBuilder_SensorBlock)objectBuilder;

            m_fieldMin = Vector3.Clamp(builder.FieldMin, new Vector3(-MaxRange), -Vector3.One);
            m_fieldMax = Vector3.Clamp(builder.FieldMax, Vector3.One, new Vector3(MaxRange));

            PlayProximitySound    = builder.PlaySound;
            DetectPlayers         = builder.DetectPlayers;
            DetectFloatingObjects = builder.DetectFloatingObjects;
            DetectSmallShips      = builder.DetectSmallShips;
            DetectLargeShips      = builder.DetectLargeShips;
            DetectStations        = builder.DetectStations;
            DetectAsteroids       = builder.DetectAsteroids;
            DetectOwner           = builder.DetectOwner;
            DetectFriendly        = builder.DetectFriendly;
            DetectNeutral         = builder.DetectNeutral;
            DetectEnemy           = builder.DetectEnemy;
            m_active = builder.IsActive;

            Toolbar.Init(builder.Toolbar, this);

            for (int i = 0; i < 2; i++)
            {
                var item = Toolbar.GetItemAtIndex(i);
                if (item == null)
                {
                    continue;
                }
                m_items.RemoveAt(i);
                m_items.Insert(i, ToolbarItem.FromItem(item));
            }
            Toolbar.ItemChanged += Toolbar_ItemChanged;

            NeedsUpdate |= MyEntityUpdateEnum.EACH_10TH_FRAME;

            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                BlockDefinition.RequiredPowerInput,
                this.CalculateRequiredPowerInput);
            PowerReceiver.IsPoweredChanged     += Receiver_IsPoweredChanged;
            PowerReceiver.RequiredInputChanged += Receiver_RequiredInputChanged;
            PowerReceiver.Update();

            m_fieldShape = GetHkShape();

            OnClose += delegate(MyEntity self)
            {
                m_fieldShape.RemoveReference();
            };
        }