Ejemplo n.º 1
0
 public virtual void SetupForProjector()
 {
     //GK: Only for projector remove ownership of blueprint block at initialization (Or else can cause incosistences to ownership manager)
     Owner     = 0;
     ShareMode = MyOwnershipShareModeEnum.None;
     EntityId  = 0; //GK: Will cause new allocation of ID for projector blueprints. In some cases the id will be the same as in projected grid when welded and entity will not be added
 }
Ejemplo n.º 2
0
        internal void ChangeOwner(long owner, MyOwnershipShareModeEnum shareMode)
        {
            if (m_IDModule == null)
            {
                if (MyFakes.ENABLE_BATTLE_SYSTEM && MySession.Static.Battle)
                {
                    m_IDModule           = new MyIDModule();
                    m_IDModule.Owner     = 0;
                    m_IDModule.ShareMode = MyOwnershipShareModeEnum.None;
                }
                else
                {
                    return;
                }
            }

            bool changed = owner != m_IDModule.Owner || shareMode != m_IDModule.ShareMode;

            if (changed)
            {
                var oldOwner = m_IDModule.Owner;
                m_IDModule.Owner     = owner;
                m_IDModule.ShareMode = shareMode;

                if (MyFakes.ENABLE_TERMINAL_PROPERTIES)
                {
                    CubeGrid.ChangeOwner(this, oldOwner, owner);
                }

                OnOwnershipChanged();
            }
        }
Ejemplo n.º 3
0
        public static VRage.Game.MyRelationsBetweenPlayerAndBlock GetRelation(long owner, long user, MyOwnershipShareModeEnum share = MyOwnershipShareModeEnum.None)
        {
            if (!MyFakes.SHOW_FACTIONS_GUI)
                return VRage.Game.MyRelationsBetweenPlayerAndBlock.NoOwnership;

            if (owner == 0)
                return VRage.Game.MyRelationsBetweenPlayerAndBlock.NoOwnership;

            if (owner == user)
                return VRage.Game.MyRelationsBetweenPlayerAndBlock.Owner;

            IMyFaction playerFaction = MySession.Static.Factions.TryGetPlayerFaction(user);
            IMyFaction faction = MySession.Static.Factions.TryGetPlayerFaction(owner);

            if ((playerFaction != null && playerFaction == faction && share == MyOwnershipShareModeEnum.Faction) || share == MyOwnershipShareModeEnum.All)
                return VRage.Game.MyRelationsBetweenPlayerAndBlock.FactionShare;

            if (playerFaction == null)
                return VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies;

            if (faction == null)
                return VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies;

            var factionRelation = MySession.Static.Factions.GetRelationBetweenFactions(faction.FactionId, playerFaction.FactionId);

            if (factionRelation == MyRelationsBetweenFactions.Neutral)
                return VRage.Game.MyRelationsBetweenPlayerAndBlock.Neutral;

            return VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies;
        }
Ejemplo n.º 4
0
        protected MyOwnershipShareModeEnum GetBlockShareMode( )
        {
            Object factionData = null;

            try
            {
                factionData = GetFactionData( );
            }
            catch { }

            if (factionData == null)
            {
                return(MyOwnershipShareModeEnum.None);
            }

            Object rawResult = GetEntityFieldValue(factionData, FactionsDataShareModeField);

            if (rawResult == null)
            {
                return(MyOwnershipShareModeEnum.None);
            }
            MyOwnershipShareModeEnum result = (MyOwnershipShareModeEnum)rawResult;

            return(result);
        }
Ejemplo n.º 5
0
        public CubeBlockEntity(CubeGridEntity parent, MyObjectBuilder_CubeBlock definition, Object backingObject)
            : base(definition, backingObject)
        {
            m_parent = parent;

            EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent();
            newEvent.type      = EntityEventManager.EntityEventType.OnCubeBlockCreated;
            newEvent.timestamp = DateTime.Now;
            newEvent.entity    = this;
            if (m_parent.IsLoading)
            {
                newEvent.priority = 10;
            }
            else if (EntityId != 0)
            {
                newEvent.priority = 1;
            }
            else
            {
                newEvent.priority = 2;
            }
            EntityEventManager.Instance.AddEvent(newEvent);

            if (EntityId != 0)
            {
                GameEntityManager.AddEntity(EntityId, this);
            }

            m_buildPercent     = definition.BuildPercent;
            m_integrityPercent = definition.IntegrityPercent;
            m_owner            = definition.Owner;
            m_shareMode        = definition.ShareMode;
        }
        /// <summary>
        /// Changes owner of invividual cube block.
        /// </summary>
        /// <param name="cube"></param>
        /// <param name="playerId">new owner id</param>
        /// <param name="shareMode">new share mode</param>
        public static void ChangeOwner(this IMyCubeBlock cube, long playerId, MyOwnershipShareModeEnum shareMode)
        {
            var block = (Sandbox.Game.Entities.MyCubeBlock)cube;

            // TODO: Unsure which of these are required. needs further investigation.
            block.ChangeOwner(playerId, shareMode);
            block.ChangeBlockOwnerRequest(playerId, shareMode);
        }
        public override void Deserialize(MyObjectBuilder_ComponentBase builder)
        {
            base.Deserialize(builder);

            var ob = builder as MyObjectBuilder_EntityOwnershipComponent;

            m_ownerId = ob.OnwerId;
            m_shareMode = ob.ShareMode;
        }
Ejemplo n.º 8
0
        public override void Deserialize(MyObjectBuilder_ComponentBase builder)
        {
            base.Deserialize(builder);

            var ob = builder as MyObjectBuilder_EntityOwnershipComponent;

            m_ownerId   = ob.OwnerId;
            m_shareMode = ob.ShareMode;
        }
Ejemplo n.º 9
0
        private void OnOwnerChanged(long newOwner, MyOwnershipShareModeEnum newShare)
        {
            MyProxyAntenna entity = base.Entity as MyProxyAntenna;

            if (entity != null)
            {
                entity.ChangeOwner(newOwner, newShare);
            }
        }
Ejemplo n.º 10
0
        public CubeBlockEntity(CubeGridEntity parent, MyObjectBuilder_CubeBlock definition)
            : base(definition)
        {
            m_parent = parent;

            m_buildPercent     = definition.BuildPercent;
            m_integrityPercent = definition.IntegrityPercent;
            m_owner            = definition.Owner;
            m_shareMode        = definition.ShareMode;
        }
Ejemplo n.º 11
0
        private void UpdateRemoteControlState(bool hasRemote, long?owner, MyOwnershipShareModeEnum sharing, long?remoteId)
        {
            MyProxyAntenna entity = base.Entity as MyProxyAntenna;

            if (entity != null)
            {
                entity.HasRemoteControl         = hasRemote;
                entity.MainRemoteControlOwner   = owner;
                entity.MainRemoteControlId      = remoteId;
                entity.MainRemoteControlSharing = sharing;
            }
        }
Ejemplo n.º 12
0
        public void UpdateTerminal(MyCubeBlock cubeBlock)
        {
            if (cubeBlock == null || cubeBlock.IDModule == null)
            {
                return;
            }

            MyOwnershipShareModeEnum sharemode = cubeBlock.IDModule.ShareMode;

            cubeBlock.ChangeOwner(cubeBlock.IDModule.Owner, sharemode == MyOwnershipShareModeEnum.None ? MyOwnershipShareModeEnum.Faction : MyOwnershipShareModeEnum.None);
            cubeBlock.ChangeOwner(cubeBlock.IDModule.Owner, sharemode);
        }
Ejemplo n.º 13
0
        public static void ChangeOwnersRequest(MyOwnershipShareModeEnum shareMode, List <MySingleOwnershipRequest> requests, long requestingPlayer)
        {
            System.Diagnostics.Debug.Assert((int)shareMode >= 0);

            var msg = new ChangeOwnershipsMsg();

            msg.RequestingPlayer = requestingPlayer;
            msg.ShareMode        = shareMode;

            msg.Requests = requests;

            Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
        }
        // Context: All
        private void RefreshUI()
        {
            this.me.RefreshCustomInfo();

            MyCubeBlock me = (MyCubeBlock)this.me;

            if (me.IDModule == null || Constants.IsDedicated || MyAPIGateway.Gui.GetCurrentScreen != MyTerminalPageEnum.ControlPanel)
            {
                return;
            }

            MyOwnershipShareModeEnum shareMode = me.IDModule.ShareMode;
            long ownerId = me.IDModule.Owner;

            me.ChangeOwner(ownerId, shareMode != MyOwnershipShareModeEnum.All ? MyOwnershipShareModeEnum.All : MyOwnershipShareModeEnum.Faction);
            me.ChangeOwner(ownerId, shareMode);
        }
        void m_shareModeCombobox_ItemSelected()
        {
            if (!m_canChangeShareMode)
            {
                return;
            }

            m_canChangeShareMode = false;

            bool updateVisuals = false;

            MyOwnershipShareModeEnum shareMode = (MyOwnershipShareModeEnum)m_shareModeCombobox.GetSelectedKey();

            if (m_currentBlocks.Length > 0)
            {
                m_requests.Clear();

                foreach (var block in m_currentBlocks)
                {
                    if (block.IDModule != null)
                    {
                        if (shareMode >= 0 && (block.OwnerId == MySession.Static.LocalPlayerId))
                        {
                            m_requests.Add(new MyCubeGrid.MySingleOwnershipRequest()
                            {
                                BlockId = block.EntityId,
                                Owner   = block.IDModule.Owner
                            });
                            updateVisuals = true;
                        }
                    }
                }

                if (m_requests.Count > 0)
                {
                    MyCubeGrid.ChangeOwnersRequest(shareMode, m_requests, MySession.Static.LocalPlayerId);
                }
            }

            m_canChangeShareMode = true;

            if (updateVisuals)
            {
                block_PropertiesChanged(null);
            }
        }
Ejemplo n.º 16
0
        public static void RefreshUI(IMyTerminalBlock block)
        {
            block.RefreshCustomInfo();

            MyCubeBlock cube = (MyCubeBlock)block;

            if (cube.IDModule == null || Constants.IsDedicated || MyAPIGateway.Gui.GetCurrentScreen != MyTerminalPageEnum.ControlPanel)
            {
                return;
            }

            MyOwnershipShareModeEnum shareMode = cube.IDModule.ShareMode;
            long ownerId = cube.IDModule.Owner;

            cube.ChangeOwner(ownerId, shareMode != MyOwnershipShareModeEnum.All ? MyOwnershipShareModeEnum.All : MyOwnershipShareModeEnum.Faction);
            cube.ChangeOwner(ownerId, shareMode);
        }
        private void ChangeCubeShareMode(IMyEntity selectedShip, MyOwnershipShareModeEnum shareMode)
        {
            var grids = selectedShip.GetAttachedGrids(AttachedGrids.Static);
            foreach (var grid in grids)
            {
                var blocks = new List<IMySlimBlock>();
                grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock.OwnerId != 0);

                foreach (var block in blocks)
                    block.FatBlock.ChangeOwner(block.FatBlock.OwnerId, shareMode);
            }
        }
Ejemplo n.º 18
0
 void IMyCubeGrid.ChangeGridOwnership(long playerId, MyOwnershipShareModeEnum shareMode)
 {
     ChangeGridOwnership(playerId, shareMode);
 }
Ejemplo n.º 19
0
 /// <summary>
 /// Remember, this is only for server-side.
 /// </summary>
 public static void ChangeOwnershipSmart(this IMyCubeGrid Grid, long newOwnerId, MyOwnershipShareModeEnum shareMode)
 {
     if (!MyAPIGateway.Session.IsServer)
     {
         return;
     }
     try
     {
         List <IMyCubeGrid> subgrids = Grid.GetAllSubgrids();
         Grid.ChangeGridOwnership(newOwnerId, shareMode);
         foreach (IMyCubeGrid subgrid in subgrids)
         {
             try
             {
                 subgrid.ChangeGridOwnership(newOwnerId, shareMode);
                 try
                 {
                     foreach (IMyProgrammableBlock pb in subgrid.GetTerminalSystem().GetBlocksOfType <IMyProgrammableBlock>())
                     {
                         try
                         {
                             //if (!string.IsNullOrEmpty(pb.ProgramData)) continue;
                             //ShowIngameMessage.ShowOverrideMessage($"PB's recompiling... {subgrid.CustomName}");
                             pb.Recompile();
                         }
                         catch (Exception)
                         {
                             //ShowIngameMessage.ShowOverrideMessage($"Recompiling this pb threw and error: {e.TargetSite} {e} ");
                             //	MyAPIGateway.Utilities.InvokeOnGameThread(() => { pb.Recompile(); });
                         }
                     }
                 }
                 catch (Exception)
                 {
                     //ShowIngameMessage.ShowOverrideMessage($"PB's recompile threw: {e} ");
                 }
             }
             catch (Exception scrap)
             {
                 Grid.LogError("ChangeOwnershipSmart.ChangeSubgridOwnership", scrap);
             }
         }
     }
     catch (Exception scrap)
     {
         Grid.LogError("ChangeOwnershipSmart", scrap);
     }
 }
Ejemplo n.º 20
0
        public static void BroadcastCubeBlockFactionData(IMyCubeBlock block, long owner, MyOwnershipShareModeEnum shareMode)
        {
            try
            {
                IMyCubeGrid parent     = (IMyCubeGrid)block.Parent;
                object      netManager = BaseObject.InvokeEntityMethod(parent, CubeGridGetNetManagerMethod);

                SandboxGameAssemblyWrapper.Instance.GameAction(() =>
                {
                    BaseObject.InvokeEntityMethod(netManager, CubeGridNetManagerBroadcastCubeBlockFactionDataMethod, new object[] { (object)parent, (object)block, owner, shareMode });
                });
            }
            catch (Exception ex)
            {
                ApplicationLog.BaseLog.Error(ex);
            }
        }
Ejemplo n.º 21
0
        public static VRage.Game.MyRelationsBetweenPlayerAndBlock GetRelation(long owner, long user, MyOwnershipShareModeEnum share = MyOwnershipShareModeEnum.None)
        {
            if (!MyFakes.SHOW_FACTIONS_GUI)
            {
                return(VRage.Game.MyRelationsBetweenPlayerAndBlock.NoOwnership);
            }

            if (owner == 0)
            {
                return(VRage.Game.MyRelationsBetweenPlayerAndBlock.NoOwnership);
            }

            if (owner == user)
            {
                return(VRage.Game.MyRelationsBetweenPlayerAndBlock.Owner);
            }

            IMyFaction playerFaction = MySession.Static.Factions.TryGetPlayerFaction(user);
            IMyFaction faction       = MySession.Static.Factions.TryGetPlayerFaction(owner);

            if ((playerFaction != null && playerFaction == faction && share == MyOwnershipShareModeEnum.Faction) || share == MyOwnershipShareModeEnum.All)
            {
                return(VRage.Game.MyRelationsBetweenPlayerAndBlock.FactionShare);
            }

            if (playerFaction == null)
            {
                return(VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies);
            }

            if (faction == null)
            {
                return(VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies);
            }

            var factionRelation = MySession.Static.Factions.GetRelationBetweenFactions(faction.FactionId, playerFaction.FactionId);

            if (factionRelation == MyRelationsBetweenFactions.Neutral)
            {
                return(VRage.Game.MyRelationsBetweenPlayerAndBlock.Neutral);
            }

            return(VRage.Game.MyRelationsBetweenPlayerAndBlock.Enemies);
        }
 public static void BroadcastCubeBlockFactionData(List <IMyCubeBlock> blocks, long owner, MyOwnershipShareModeEnum shareMode)
 {
     try
     {
         SandboxGameAssemblyWrapper.Instance.GameAction(() =>
         {
             foreach (IMyCubeBlock block in blocks)
             {
                 IMyCubeGrid parent = (IMyCubeGrid)block.Parent;
                 object netManager  = BaseObject.InvokeEntityMethod(parent, CubeGridGetNetManagerMethod);
                 BaseObject.InvokeEntityMethod(netManager, CubeGridNetManagerBroadcastCubeBlockFactionDataMethod, new object[] { (object)parent, (object)block, owner, shareMode });
             }
         });
     }
     catch (Exception ex)
     {
         LogManager.ErrorLog.WriteLine(ex);
     }
 }
Ejemplo n.º 23
0
        public void IncreaseMountLevelToDesiredRatio(float desiredIntegrityRatio, long welderOwnerPlayerId, MyInventoryBase outputInventory = null, float maxAllowedBoneMovement = 0.0f, bool isHelping = false, MyOwnershipShareModeEnum sharing = MyOwnershipShareModeEnum.Faction)
        {
            float desiredIntegrity = desiredIntegrityRatio * MaxIntegrity;
            float welderAmount = desiredIntegrity - Integrity;
            Debug.Assert(welderAmount >= 0f);
            if (welderAmount <= 0f)
                return;

            IncreaseMountLevel(welderAmount / BlockDefinition.IntegrityPointsPerSec, welderOwnerPlayerId, outputInventory: outputInventory, maxAllowedBoneMovement: maxAllowedBoneMovement,
                isHelping: isHelping, sharing: sharing);
        }
Ejemplo n.º 24
0
        public static void ChangeOwnersRequest(MyOwnershipShareModeEnum shareMode, List<MySingleOwnershipRequest> requests, long requestingPlayer)
        {
            System.Diagnostics.Debug.Assert((int)shareMode >= 0);

            var msg = new ChangeOwnershipsMsg();
            msg.RequestingPlayer = requestingPlayer;
            msg.ShareMode = shareMode;

            msg.Requests = requests;

            Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
        }
Ejemplo n.º 25
0
 public static void ChangeOwnersRequest(MyOwnershipShareModeEnum shareMode, List<MySingleOwnershipRequest> requests)
 {
     ChangeOwnersRequest(shareMode, requests, MySession.LocalPlayerId);
 }
Ejemplo n.º 26
0
        public override bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj)
        {
            if (!PluginSettings.Instance.ProtectedEnabled)
            {
                return(false);
            }
            HashSet <MyCubeGrid> processGrids = new HashSet <MyCubeGrid>( );

            if (site.MethodInfo.Name == ChangeOwnerName)
            {
                MyCubeGrid grid = obj as MyCubeGrid;
                if (grid == null)
                {
                    Essentials.Log.Debug("Null grid in BlockOwnHandler");
                    return(false);
                }
                processGrids.Add(grid);
            }
            else if (site.MethodInfo.Name == ChangeOwnersName)
            {
                MyOwnershipShareModeEnum shareMode = MyOwnershipShareModeEnum.None;
                List <MyCubeGrid.MySingleOwnershipRequest> requests = new List <MyCubeGrid.MySingleOwnershipRequest>( );
                long requestingPlayer = 0;

                Serialize(site.MethodInfo, stream, ref shareMode, ref requests, ref requestingPlayer);

                foreach (MyCubeGrid.MySingleOwnershipRequest request in requests)
                {
                    MyEntity entity;
                    MyEntities.TryGetEntityById(request.BlockId, out entity);
                    MyCubeBlock block = entity as MyCubeBlock;
                    if (block?.CubeGrid == null)
                    {
                        continue;
                    }

                    processGrids.Add(block.CubeGrid);
                }
            }

            //Parallel.ForEach( processGrids, grid =>
            foreach (var grid in processGrids)
            {
                foreach (ProtectedItem item in PluginSettings.Instance.ProtectedItems)
                {
                    if (!item.Enabled)
                    {
                        continue;
                    }

                    if (item.EntityId != grid.EntityId && item.EntityId != -1)
                    {
                        continue;
                    }

                    if (!item.ProtectionSettingsDict.Dictionary.ContainsKey(ProtectedItem.ProtectionModeEnum.BlockOwn))
                    {
                        continue;
                    }

                    ProtectedItem.ProtectionSettings settings = item.ProtectionSettingsDict[ProtectedItem.ProtectionModeEnum.BlockOwn];

                    if (Protection.Instance.CheckPlayerExempt(settings, grid, remoteUserId))
                    {
                        continue;
                    }

                    if (item.LogOnly)
                    {
                        Essentials.Log.Info($"Recieved block ownership change request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
                        continue;
                    }

                    if (!string.IsNullOrEmpty(settings.PrivateWarningMessage))
                    {
                        Communication.Notification(remoteUserId, MyFontEnum.Red, 5000, settings.PrivateWarningMessage);
                    }

                    if (!string.IsNullOrEmpty(settings.PublicWarningMessage))
                    {
                        Communication.SendPublicInformation(settings.PublicWarningMessage.Replace("%player%", PlayerMap.Instance.GetFastPlayerNameFromSteamId(remoteUserId)));
                    }

                    if (settings.BroadcastGPS)
                    {
                        MyPlayer player = MySession.Static.Players.GetPlayerById(new MyPlayer.PlayerId(remoteUserId, 0));
                        Vector3D pos    = player.GetPosition( );
                        MyAPIGateway.Utilities.SendMessage($"GPS:{player.DisplayName}:{pos.X}:{pos.Y}:{pos.Z}:");
                    }

                    Essentials.Log.Info($"Intercepted block ownership change request from user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");

                    switch (settings.PunishmentType)
                    {
                    case ProtectedItem.PunishmentEnum.Kick:
                        _kickTimer.Elapsed += (sender, e) =>
                        {
                            Essentials.Log.Info($"Kicked user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for changing block ownership on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
                            MyMultiplayer.Static.KickClient(remoteUserId);
                        };
                        _kickTimer.AutoReset = false;
                        _kickTimer.Start( );
                        break;

                    case ProtectedItem.PunishmentEnum.Ban:
                        _kickTimer.Elapsed += (sender, e) =>
                        {
                            Essentials.Log.Info($"Banned user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )}:{remoteUserId} for changing block ownership on protected grid {grid.DisplayNameText ?? "ID"}:{item.EntityId}");
                            MyMultiplayer.Static.BanClient(remoteUserId, true);
                        };
                        _kickTimer.AutoReset = false;
                        _kickTimer.Start( );
                        break;

                    case ProtectedItem.PunishmentEnum.Speed:
                        Task.Run(() =>
                        {
                            lock (ProcessSpeed.SpeedPlayers)
                            {
                                long playerId = PlayerMap.Instance.GetFastPlayerIdFromSteamId(remoteUserId);
                                ProcessSpeed.SpeedPlayers[playerId] = new Tuple <float, DateTime>((float)settings.SpeedLimit, DateTime.Now + TimeSpan.FromMinutes(settings.SpeedTime));
                            }
                        });
                        Essentials.Log.Info($"Limited user {PlayerMap.Instance.GetFastPlayerNameFromSteamId( remoteUserId )} to {settings.SpeedLimit}m/s for {settings.SpeedTime} minutes");
                        break;
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 27
0
		public CubeBlockEntity( CubeGridEntity parent, MyObjectBuilder_CubeBlock definition, Object backingObject )
			: base( definition, backingObject )
		{
			m_parent = parent;

			EntityEventManager.EntityEvent newEvent = new EntityEventManager.EntityEvent( );
			newEvent.type = EntityEventManager.EntityEventType.OnCubeBlockCreated;
			newEvent.timestamp = DateTime.Now;
			newEvent.entity = this;
			if ( m_parent.IsLoading )
			{
				newEvent.priority = 10;
			}
			else if ( EntityId != 0 )
			{
				newEvent.priority = 1;
			}
			else
			{
				newEvent.priority = 2;
			}
			EntityEventManager.Instance.AddEvent( newEvent );

			if ( EntityId != 0 )
			{
				GameEntityManager.AddEntity( EntityId, this );
			}

			m_buildPercent = definition.BuildPercent;
			m_integrityPercent = definition.IntegrityPercent;
			m_owner = definition.Owner;
			m_shareMode = definition.ShareMode;
		}
        public static bool PatchChangeOwnerRequest(
            MyCubeGrid grid,
            MyCubeBlock block,
            long playerId,
            MyOwnershipShareModeEnum shareMode)
        {
            string gridName = grid.DisplayName;

            string oldOwnerName = PlayerUtils.GetPlayerNameById(block.OwnerId);
            string newOwnerName = PlayerUtils.GetPlayerNameById(playerId);

            /* Only shared mode was changed */
            if (oldOwnerName == newOwnerName)
            {
                return(true);
            }

            bool   isOnline     = PlayerUtils.isOnline(block.OwnerId);
            string onlineString = "[Off]";

            if (isOnline)
            {
                onlineString = "[On]";
            }

            string oldFactionTag = PlayerUtils.GetFactionTagStringForPlayer(block.OwnerId);
            string newFactionTag = PlayerUtils.GetFactionTagStringForPlayer(playerId);

            string oldName = oldOwnerName + " " + onlineString + oldFactionTag;
            string newName = newOwnerName + " " + newFactionTag;

            string causeName = "[Unknown]";

            ChangingEntity cause = OwnershipLoggerPlugin.Instance.DamageCache.Get(block.EntityId);

            string additionalInfo = null;

            if (playerId == 0L && cause != null)
            {
                additionalInfo = cause.AdditionalInfo;

                if (!cause.IsPlanet)
                {
                    long causeId;

                    if (cause.Controller != 0L)
                    {
                        causeId = cause.Controller;
                    }
                    else
                    {
                        causeId = cause.Owner;
                    }

                    /* Can be offline when weapons are the cause */
                    bool   isCauseOnline     = PlayerUtils.isOnline(causeId);
                    string causeOnlineString = "[Off]";
                    if (isCauseOnline)
                    {
                        causeOnlineString = "[On]";
                    }

                    string causePlayerName = PlayerUtils.GetPlayerNameById(causeId);
                    string causeFactionTag = PlayerUtils.GetFactionTagStringForPlayer(causeId);

                    causeName = (causePlayerName + " " + causeOnlineString + causeFactionTag).PadRight(25) + " with " + cause.ChangingCause;
                }
                else
                {
                    causeName = "Planet".PadRight(25) + " with " + cause.ChangingCause;
                }
            }
            else if (playerId != 0L)
            {
                /* Can be offline when weapons are the cause */
                bool   isCauseOnline     = PlayerUtils.isOnline(playerId);
                string causeOnlineString = "[Off]";
                if (isCauseOnline)
                {
                    causeOnlineString = "[On]";
                }

                /* Must be Online then */
                causeName = newOwnerName + " " + causeOnlineString + newFactionTag;
            }

            string blockpairName = block.BlockDefinition.BlockPairName;

            blockpairName = ChangeName(additionalInfo, blockpairName);

            string location = GetLocationWhenNeeded(block);

            Log.Info(causeName.PadRight(45) + " changed owner on block " + blockpairName.PadRight(20) + " from " + oldName.PadRight(25) + " to " + newName.PadRight(20) + " on grid: " + gridName + location);

            return(true);
        }
Ejemplo n.º 29
0
 public void ChangeBlockOwnerRequest(long playerId, MyOwnershipShareModeEnum shareMode)
 {
     CubeGrid.SyncObject.ChangeOwnerRequest(CubeGrid, this, playerId, shareMode);
 }
Ejemplo n.º 30
0
 void IMySlimBlock.IncreaseMountLevel(float welderMountAmount, long welderOwnerPlayerId, IMyInventory outputInventory, float maxAllowedBoneMovement, bool isHelping, MyOwnershipShareModeEnum share)
 {
     IncreaseMountLevel(welderMountAmount, welderOwnerPlayerId, outputInventory as MyInventoryBase, maxAllowedBoneMovement, isHelping, share);
 }
Ejemplo n.º 31
0
 void IMySlimBlock.IncreaseMountLevel(float welderMountAmount, long welderOwnerPlayerId, IMyInventory outputInventory, float maxAllowedBoneMovement, bool isHelping, MyOwnershipShareModeEnum share)
 {
     IncreaseMountLevel(welderMountAmount, welderOwnerPlayerId, outputInventory as MyInventoryBase, maxAllowedBoneMovement, isHelping, share);
 }
Ejemplo n.º 32
0
        internal static void ChangeGridOwner(MyCubeGrid grid, long playerId, MyOwnershipShareModeEnum shareMode)
        {
            var msg = new ChangeGridOwnershipMsg();
            msg.GridEntityId = grid.EntityId;
            msg.Owner = playerId;
            msg.ShareMode = shareMode;

            Sync.Layer.SendMessageToAllAndSelf(ref msg);
        }
Ejemplo n.º 33
0
        public static void ChangeOwnersRequest(MyOwnershipShareModeEnum shareMode, List<MySingleOwnershipRequest> requests)
        {
            System.Diagnostics.Debug.Assert((int)shareMode >= 0);

            var msg = new ChangeOwnershipsMsg();
            msg.RequestingPlayer = MySession.LocalPlayerId; // CH: This is (probably) set only via GUI. If you intend to change this, you'll need playerId
            msg.ShareMode = shareMode;

            msg.Requests = requests;

            Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
        }
Ejemplo n.º 34
0
        public void IncreaseMountLevel(float welderMountAmount, long welderOwnerPlayerId, MyInventoryBase outputInventory = null, float maxAllowedBoneMovement = 0.0f, bool isHelping = false, MyOwnershipShareModeEnum sharing = MyOwnershipShareModeEnum.Faction)
        {
            ProfilerShort.Begin("MySlimBlock.IncreaseMountLevel");
            welderMountAmount *= BlockDefinition.IntegrityPointsPerSec;
            MySession.Static.PositiveIntegrityTotal += welderMountAmount;

            if (MySession.Static.CreativeMode)
            {
                ClearConstructionStockpile(outputInventory);
            }
            else
            {
                MyEntity inventoryOwner = null;
                if (outputInventory != null && outputInventory.Container != null)
                    inventoryOwner = outputInventory.Container.Entity as MyEntity;
                if (inventoryOwner != null && inventoryOwner.InventoryOwnerType() == MyInventoryOwnerTypeEnum.Character)
                {
                    MoveItemsFromConstructionStockpile(outputInventory, MyItemFlags.Damaged);
                }
            }

            float oldPercentage = m_componentStack.BuildRatio;
            float oldDamage = CurrentDamage;


            //Add ownership check in order for the IntegrityChanged not to be called many times
            if (BlockDefinition.RatioEnoughForOwnership(BuildLevelRatio))
            {
                if (FatBlock != null && FatBlock.OwnerId == 0 && outputInventory != null && !isHelping)
                {
                    FatBlock.OnIntegrityChanged(BuildIntegrity, Integrity, true, welderOwnerPlayerId, sharing);
                }
            }

            if (MyFakes.SHOW_DAMAGE_EFFECTS && FatBlock != null && !BlockDefinition.RatioEnoughForDamageEffect((Integrity + welderMountAmount) / MaxIntegrity))
            {//stop effect
                FatBlock.SetDamageEffect(false);
            }

            bool removeDecals = false;

            if (m_stockpile != null)
            {
                m_stockpile.ClearSyncList();
                m_componentStack.IncreaseMountLevel(welderMountAmount, m_stockpile);
                CubeGrid.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
            else
            {
                m_componentStack.IncreaseMountLevel(welderMountAmount, null);
            }

            if (m_componentStack.IsFullIntegrity)
            {
                ReleaseConstructionStockpile();
                removeDecals = true;
            }

            ProfilerShort.Begin("ModelChange");
            MyIntegrityChangeEnum integrityChangeType = MyIntegrityChangeEnum.Damage;
            if (BlockDefinition.ModelChangeIsNeeded(oldPercentage, m_componentStack.BuildRatio) || BlockDefinition.ModelChangeIsNeeded(m_componentStack.BuildRatio, oldPercentage))
            {
                removeDecals = true;
                if (FatBlock != null)
                {
                    // this needs to be detected here because for cubes the following call to UpdateVisual() set FatBlock to null when the construction is complete
                    if (m_componentStack.IsFunctional)
                    {
                        integrityChangeType = MyIntegrityChangeEnum.ConstructionEnd;
                    }
                }

                UpdateVisual();
                if (FatBlock != null)
                {
                    int buildProgressID = CalculateCurrentModelID();
                    if (buildProgressID == 0)
                    {
                        integrityChangeType = MyIntegrityChangeEnum.ConstructionBegin;
                    }
                    else if (!m_componentStack.IsFunctional)
                    {
                        integrityChangeType = MyIntegrityChangeEnum.ConstructionProcess;
                    }
                }

                PlayConstructionSound(integrityChangeType);
                CreateConstructionSmokes();

                if (CubeGrid.GridSystems.GasSystem != null)
                {
                    CubeGrid.GridSystems.GasSystem.Pressurize();
                }
            }
            ProfilerShort.End();

            if (HasDeformation)
                CubeGrid.SetBlockDirty(this);

            if (removeDecals)
                CubeGrid.RenderData.RemoveDecals(Position);

            CubeGrid.SendIntegrityChanged(this, integrityChangeType, 0);
            CubeGrid.OnIntegrityChanged(this);

            if (maxAllowedBoneMovement != 0.0f)
                FixBones(oldDamage, maxAllowedBoneMovement);

            if (MyFakes.ENABLE_GENERATED_BLOCKS && !BlockDefinition.IsGeneratedBlock && BlockDefinition.GeneratedBlockDefinitions != null && BlockDefinition.GeneratedBlockDefinitions.Length > 0)
            {
                UpdateProgressGeneratedBlocks(oldPercentage);
            }

            ProfilerShort.End();
        }
Ejemplo n.º 35
0
 internal override void OnIntegrityChanged(float buildIntegrity, float integrity, bool setOwnership, long owner, MyOwnershipShareModeEnum sharing = MyOwnershipShareModeEnum.Faction)
 {
     base.OnIntegrityChanged(buildIntegrity, integrity, setOwnership, owner, sharing);
     m_termGpsCoords = null;
     m_termGpsName.Clear();
     ShiftModeSync(StateEnum.idle);
 }
Ejemplo n.º 36
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);
             }
         }
     }
 }
        private bool GetShareMode(out MyOwnershipShareModeEnum? shareMode)
        {
            bool propertyMixed = false;
            shareMode = null;
            foreach (var block in m_currentBlocks)
            {
                if (block.IDModule != null)
                {
                    if (!shareMode.HasValue)
                        shareMode = block.IDModule.ShareMode;
                    else
                    {
                        if (shareMode.Value != block.IDModule.ShareMode)
                        {
                            propertyMixed = true;
                            break;
                        }
                    }
                }
            }

            return propertyMixed;
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Remember, this is only for server-side.
 /// </summary>
 public static void ChangeOwnershipSmart(this IMyCubeGrid Grid, long NewOwnerID, MyOwnershipShareModeEnum ShareMode)
 {
     try
     {
         var Subgrids = Grid.GetAllSubgrids();
         Grid.ChangeGridOwnership(NewOwnerID, ShareMode);
         foreach (IMyCubeGrid Subgrid in Subgrids)
         {
             try
             {
                 Subgrid.ChangeGridOwnership(NewOwnerID, ShareMode);
             }
             catch (Exception Scrap)
             {
                 Grid.LogError("ChangeOwnershipSmart.ChangeSubgridOwnership", Scrap);
             }
         }
     }
     catch (Exception Scrap)
     {
         Grid.LogError("ChangeOwnershipSmart", Scrap);
     }
 }
Ejemplo n.º 39
0
 void IMyCubeGrid.ChangeGridOwnership(long playerId, MyOwnershipShareModeEnum shareMode)
 {
     ChangeGridOwnership(playerId, shareMode);
 }
Ejemplo n.º 40
0
        public void IncreaseMountLevel(float welderMountAmount, long welderOwnerPlayerId, MyInventory outputInventory = null, float maxAllowedBoneMovement = 0.0f, bool isHelping = false, MyOwnershipShareModeEnum sharing = MyOwnershipShareModeEnum.Faction)
        {
            welderMountAmount *= BlockDefinition.IntegrityPointsPerSec;
            MySession.Static.PositiveIntegrityTotal += welderMountAmount;

            if (MySession.Static.CreativeMode)
            {
                ClearConstructionStockpile(outputInventory);
            }
            else
            {
                if (outputInventory != null && outputInventory.Owner.InventoryOwnerType == MyInventoryOwnerTypeEnum.Character)
                {
                    MoveItemsFromConstructionStockpile(outputInventory, MyItemFlags.Damaged);
                }
            }

            float oldPercentage = m_componentStack.BuildRatio;
            float oldDamage = CurrentDamage;

            if (!BlockDefinition.RatioEnoughForOwnership(BuildLevelRatio) && BlockDefinition.RatioEnoughForOwnership((BuildIntegrity + welderMountAmount) / BlockDefinition.MaxIntegrity))
            {
                if (FatBlock != null && outputInventory != null && !isHelping)
                {
                    FatBlock.OnIntegrityChanged(BuildIntegrity, Integrity, true, welderOwnerPlayerId, sharing);
                }
            }

            if (MyFakes.SHOW_DAMAGE_EFFECTS && FatBlock != null && !BlockDefinition.RationEnoughForDamageEffect((Integrity+welderMountAmount) / MaxIntegrity))
            {//stop effect
                FatBlock.SetDamageEffect(false);
            }


            if (m_stockpile != null)
            {
                m_stockpile.ClearSyncList();
                m_componentStack.IncreaseMountLevel(welderMountAmount, m_stockpile);
                CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
            else
            {
                m_componentStack.IncreaseMountLevel(welderMountAmount, null);
            }

            if (m_componentStack.IsFullIntegrity)
            {
                ReleaseConstructionStockpile();
            }

            MyCubeGrid.MyIntegrityChangeEnum integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.Damage;
            if (BlockDefinition.ModelChangeIsNeeded(oldPercentage, m_componentStack.BuildRatio) || BlockDefinition.ModelChangeIsNeeded(m_componentStack.BuildRatio, oldPercentage))
            {
                if (FatBlock != null)
                {
                    // this needs to be detected here because for cubes the following call to UpdateVisual() set FatBlock to null when the construction is complete
                    if (m_componentStack.IsFunctional)
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionEnd;
                    }
                }

                UpdateVisual();
                if (FatBlock != null)
                {
                    int buildProgressID = CalculateCurrentModelID();
                    if (buildProgressID == 0)
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionBegin;
                    }
                    else if (!m_componentStack.IsFunctional)
                    {
                        integrityChangeType = MyCubeGrid.MyIntegrityChangeEnum.ConstructionProcess;
                    }
                }

                PlayConstructionSound(integrityChangeType);
                CreateConstructionSmokes();

                if (CubeGrid.GridSystems.OxygenSystem != null)
                {
                    CubeGrid.GridSystems.OxygenSystem.Pressurize();
                }
            }

            if (HasDeformation)
                CubeGrid.SetBlockDirty(this);

            CubeGrid.SyncObject.SendIntegrityChanged(this, integrityChangeType, 0);

            if (maxAllowedBoneMovement != 0.0f)
                FixBones(oldDamage, maxAllowedBoneMovement);
        }
Ejemplo n.º 41
0
        internal void ChangeOwnerRequest(MyCubeGrid grid, MyCubeBlock block, long playerId, MyOwnershipShareModeEnum shareMode)
        {
            System.Diagnostics.Debug.Assert(playerId >= 0);
            System.Diagnostics.Debug.Assert((int)shareMode >= 0);

            var msg = new ChangeOwnershipMsg();
            msg.GridEntityId = grid.EntityId;
            msg.BlockId = block.EntityId;
            msg.Owner = playerId;
            msg.RequestingPlayer = playerId;
            msg.ShareMode = shareMode;

            Sync.Layer.SendMessageToServer(ref msg, MyTransportMessageEnum.Request);
        }
Ejemplo n.º 42
0
		public CubeBlockEntity( CubeGridEntity parent, MyObjectBuilder_CubeBlock definition )
			: base( definition )
		{
			m_parent = parent;

			m_buildPercent = definition.BuildPercent;
			m_integrityPercent = definition.IntegrityPercent;
			m_owner = definition.Owner;
			m_shareMode = definition.ShareMode;
		}
        private void ChangeCubeShareMode(IMyEntity selectedShip, long oldPlayer, long newPlayer, MyOwnershipShareModeEnum shareMode)
        {
            var grids = selectedShip.GetAttachedGrids();
            foreach (var grid in grids)
            {
                var blocks = new List<IMySlimBlock>();
                // we only want to change the share of blocks you own currently.
                grid.GetBlocks(blocks, f => f.FatBlock != null && f.FatBlock.OwnerId == oldPlayer);

                foreach (var block in blocks)
                    block.FatBlock.ChangeOwner(newPlayer, shareMode);
            }
        }