Esempio n. 1
0
        private void InitOwnership(MyObjectBuilder_CubeBlock builder)
        {
            bool canHaveOwnership = BlockDefinition.ContainsComputer() || (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle);

            if (UseObjectsComponent != null)
            {
                canHaveOwnership = canHaveOwnership || UseObjectsComponent.GetDetectors("ownership").Count > 0;
            }

            if (canHaveOwnership)
            {
                m_IDModule = new MyIDModule();

                bool resetOwnership = MySession.Static.Settings.ResetOwnership && Sync.IsServer;

                if (resetOwnership)
                {
                    m_IDModule.Owner     = 0;
                    m_IDModule.ShareMode = MyOwnershipShareModeEnum.None;
                }
                else
                {
                    if ((int)builder.ShareMode == -1)
                    {
                        builder.ShareMode = MyOwnershipShareModeEnum.None;
                    }

                    var ownerType = MyEntityIdentifier.GetIdObjectType(builder.Owner);
                    if (builder.Owner != 0 && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.NPC && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.SPAWN_GROUP)
                    {
                        System.Diagnostics.Debug.Assert(ownerType == MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, "Old save detected, reseting owner to Nobody, please resave.");

                        if (!Sync.Players.HasIdentity(builder.Owner))
                        {
                            builder.Owner = 0; //reset, it was old version
                        }
                    }

                    m_IDModule.Owner     = builder.Owner;
                    m_IDModule.ShareMode = builder.ShareMode;
                }
            }
        }
Esempio n. 2
0
 internal virtual void OnIntegrityChanged(float buildIntegrity, float integrity, bool setOwnership, long owner, MyOwnershipShareModeEnum sharing = MyOwnershipShareModeEnum.Faction)
 {
     if (BlockDefinition.ContainsComputer())
     {
         if (setOwnership)
         {
             if (m_IDModule.Owner == 0)
             {
                 if (Sync.IsServer)
                 {
                     CubeGrid.SyncObject.ChangeOwnerRequest(CubeGrid, this, owner, sharing);
                 }
             }
         }
         else
         {
             if (m_IDModule.Owner != 0)
             {
                 sharing = MyOwnershipShareModeEnum.None;
                 CubeGrid.SyncObject.ChangeOwnerRequest(CubeGrid, this, 0, sharing);
             }
         }
     }
 }
Esempio n. 3
0
        public virtual void Init(MyObjectBuilder_CubeBlock builder, MyCubeGrid cubeGrid)
        {
            //objectBuilder.PersistentFlags |= MyPersistentEntityFlags2.CastShadows;
            // Ensure that if we went from not serializing to serializing, we have a valid entity id.
            if (builder.EntityId == 0)
            {
                EntityId = MyEntityIdentifier.AllocateId();
            }
            else if (builder.EntityId != 0)
            {
                EntityId = builder.EntityId;
            }

            NumberInGrid        = cubeGrid.BlockCounter.GetNextNumber(builder.GetId());
            Render.ColorMaskHsv = builder.ColorMaskHSV;

            if (BlockDefinition.ContainsComputer())
            {
                m_IDModule = new MyIDModule();

                if (MySession.Static.Settings.ResetOwnership && Sync.IsServer)
                {
                    m_IDModule.Owner     = 0;
                    m_IDModule.ShareMode = MyOwnershipShareModeEnum.None;
                }
                else
                {
                    if ((int)builder.ShareMode == -1)
                    {
                        builder.ShareMode = MyOwnershipShareModeEnum.None;
                    }

                    var ownerType = MyEntityIdentifier.GetIdObjectType(builder.Owner);
                    if (builder.Owner != 0 && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.NPC && ownerType != MyEntityIdentifier.ID_OBJECT_TYPE.SPAWN_GROUP)
                    {
                        System.Diagnostics.Debug.Assert(ownerType == MyEntityIdentifier.ID_OBJECT_TYPE.IDENTITY, "Old save detected, reseting owner to Nobody, please resave.");

                        if (!Sync.Players.HasIdentity(builder.Owner))
                        {
                            builder.Owner = 0; //reset, it was old version
                        }
                    }

                    m_IDModule.Owner     = builder.Owner;
                    m_IDModule.ShareMode = builder.ShareMode;
                }
            }

            if (MyFakes.ENABLE_SUBBLOCKS)
            {
                if (builder.SubBlocks != null)
                {
                    foreach (var subblockInfo in builder.SubBlocks)
                    {
                        m_subBlockIds.Add(subblockInfo.SubGridName, new MySubBlockLoadInfo()
                        {
                            GridId = subblockInfo.SubGridId, SubBlockPosition = subblockInfo.SubBlockPosition
                        });
                    }

                    m_subBlocksLoaded = m_subBlockIds.Count > 0;

                    if (BlockDefinition.SubBlockDefinitions != null && BlockDefinition.SubBlockDefinitions.Count > 0 && m_subBlockIds.Count == 0)
                    {
                        m_subBlocksInitialized = true;
                        m_subBlocksLoaded      = true;
                    }

                    // Set update flag for InitSubBlocks
                    NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME;
                }
            }


            base.Init(null);
            base.Render.PersistentFlags |= MyPersistentEntityFlags2.CastShadows;
            Init();
            AddDebugRenderComponent(new MyDebugRenderComponentCubeBlock(this));
        }