public void CompleteTarget(IMySlimBlock obj)
        {
            Logging.Instance.WriteLine(string.Format("[Construction] Completing Construction/Repair Target: {0} - {1} (EntityID={2},Position={3})",
                                                     m_constructionBlock.ConstructionBlock.EntityId, obj.GetType().Name, obj.FatBlock != null ? obj.FatBlock.EntityId : 0, obj.Position), 1);

            var localBlockBuiltBy = (MyCubeBlock)m_constructionBlock.ConstructionBlock;
            var ownerId           = m_constructionBlock.ConstructionBlock.OwnerId;

            // no defined owner
            if (ownerId == 0)
            {
                if (obj != null && obj.CubeGrid != null && obj.CubeGrid.BigOwners[0] != null)
                {
                    ownerId = obj.CubeGrid.BigOwners[0];
                }

                if (ownerId == 0 && localBlockBuiltBy != null && localBlockBuiltBy.BuiltBy != null)
                {
                    ownerId = localBlockBuiltBy.BuiltBy;
                }
            }

            if (obj != null && ownerId > 0)
            {
                var cubeBlock = (MyCubeBlock)obj.FatBlock;
                if (cubeBlock != null)
                {
                    cubeBlock.ChangeOwner(ownerId, MyOwnershipShareModeEnum.Faction);
                }
            }

            if (Sync.IsServer)
            {
                m_constructionBlock.SendCompleteTarget(obj, TargetTypes.Construction);
            }

            m_constructionBlock.ParticleManager.CompleteTarget(obj);
            m_constructionBlock.ToolManager.Remove(obj);
            Remove(obj);
            m_remoteTargets.Remove(obj);
            m_areaTargetBlocks.Remove(obj);
        }
        public void CancelTarget(IMySlimBlock obj)
        {
            Logging.Instance.WriteLine(string.Format("[Construction] Cancelling Construction/Repair Target: {0} - {1} (EntityID={2},Position={3})",
                                                     m_constructionBlock.ConstructionBlock.EntityId, obj.GetType().Name, obj.FatBlock != null ? obj.FatBlock.EntityId : 0, obj.Position), 1);

            if (Sync.IsServer)
            {
                m_constructionBlock.SendCancelTarget(obj, TargetTypes.Construction);
            }

            m_constructionBlock.ParticleManager.CancelTarget(obj);
            m_constructionBlock.ToolManager.Remove(obj);
            Remove(obj);
            m_remoteTargets.Remove(obj);
            m_areaTargetBlocks.Remove(obj);
        }
Example #3
0
        public virtual void Close()
        {
            //Logging.Instance.WriteLine(string.Format("Close"));

            int pos = 0;

            try
            {
                if (m_performanceFriendly)
                {
                    if (Sync.IsClient)
                    {
                        NaniteConstructionManager.ParticleManager.RemoveParticle(m_cubeEntityId, m_position);
                    }
                    else
                    {
                        m_constructionBlock.SendRemoveParticleEffect(m_cubeEntityId, m_position);
                    }

                    if (m_isGrinder && m_removed)
                    {
                        TransferRemainingComponents();
                        Logging.Instance.WriteLine(string.Format("GRINDING completed.  Target block: {0} - (EntityID: {1} Elapsed: {2})", m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.EntityId : 0, m_completeTime + m_waitTime));
                    }

                    m_completed = true;
                    return;
                }

                if (m_constructionBlock != null && m_constructionBlock.ConstructionBlock != null)
                {
                    var toolInventory = ((MyEntity)m_tool).GetInventory(0);

                    // Since grinding in creative gives no components.  Insert hack.
                    if (MyAPIGateway.Session.CreativeMode && m_tool is Sandbox.ModAPI.Ingame.IMyShipGrinder)
                    {
                        MyObjectBuilder_CubeBlock block = (MyObjectBuilder_CubeBlock)m_targetBlock.GetObjectBuilder();
                        MyCubeBlockDefinition     blockDefinition;
                        if (MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition))
                        {
                            foreach (var item in blockDefinition.Components)
                            {
                                var inventoryItem = (MyObjectBuilder_PhysicalObject)MyObjectBuilderSerializer.CreateNewObject(item.DeconstructItem.Id);
                                toolInventory.AddItems(item.Count, inventoryItem);
                            }
                        }
                    }

                    if (toolInventory.GetItemsCount() > 0)
                    {
                        TransferFromTarget((MyCubeBlock)m_tool);
                    }
                }

                m_completed = true;
                if (m_tool != null)
                {
                    m_tool.Enabled = false;
                }

                if (!m_toolEntity.Closed)
                {
                    m_toolEntity.Close();
                }
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("Close() {1}: {0}", ex.ToString(), pos));
            }
        }
        public void CompleteTarget(IMySlimBlock target)
        {
            Logging.Instance.WriteLine(string.Format("COMPLETING Projection Target: {0} - {1} (EntityID={2},Position={3})", m_constructionBlock.ConstructionBlock.EntityId, target.GetType().Name, target.FatBlock != null ? target.FatBlock.EntityId : 0, target.Position));
            if (Sync.IsServer)
            {
                m_constructionBlock.SendCompleteTarget(target, TargetTypes.Projection, GetProjectorByBlock(target));
            }

            m_constructionBlock.ParticleManager.CompleteTarget(target);
            m_constructionBlock.ToolManager.Remove(target);
            Remove(target);
            m_targetBlocks.Remove(target);
        }
        public void CancelTarget(IMySlimBlock obj)
        {
            Logging.Instance.WriteLine(string.Format("CANCELLING Deconstruction Target: {0} - {1} (EntityID={2},Position={3})", m_constructionBlock.ConstructionBlock.EntityId, obj.GetType().Name, obj.FatBlock != null ? obj.FatBlock.EntityId : 0, obj.Position));
            if (Sync.IsServer)
            {
                m_constructionBlock.SendCancelTarget(obj, TargetTypes.Deconstruction);
            }

            m_constructionBlock.ParticleManager.CancelTarget(obj);
            m_constructionBlock.ToolManager.Remove(obj);
            Remove(obj);

            using (Lock.AcquireExclusiveUsing())
                PotentialTargetList.Add(obj);
        }
        public void CompleteTarget(IMySlimBlock obj)
        {
            Logging.Instance.WriteLine(string.Format("COMPLETING Deconstruction Target: {0} - {1} (EntityID={2},Position={3})", m_constructionBlock.ConstructionBlock.EntityId, obj.GetType().Name, obj.FatBlock != null ? obj.FatBlock.EntityId : 0, obj.Position));
            if (Sync.IsServer)
            {
                m_constructionBlock.SendCompleteTarget(obj, TargetTypes.Deconstruction);
            }

            m_constructionBlock.ParticleManager.CompleteTarget(obj);
            m_constructionBlock.ToolManager.Remove(obj);
            Remove(obj);
        }
        private void CreateDeconstructionParticle(IMySlimBlock target)
        {
            if (!m_targetBlocks.ContainsKey(target))
            {
                m_targetBlocks.Add(target, 0);
            }

            if (NaniteParticleManager.TotalParticleCount > NaniteParticleManager.MaxTotalParticles)
            {
                return;
            }

            m_targetBlocks[target]++;
            int size = (int)Math.Max(60f, NaniteParticleManager.TotalParticleCount);

            if ((float)m_targetBlocks[target] / size < 1f)
            {
                return;
            }

            m_targetBlocks[target] = 0;
            Vector4 startColor = new Vector4(0.55f, 0.95f, 0.95f, 0.75f);
            Vector4 endColor   = new Vector4(0.05f, 0.35f, 0.35f, 0.75f);

            m_constructionBlock.ParticleManager.AddParticle(startColor, endColor, GetMinTravelTime() * 1000f, GetSpeed(), target);

            var distance = EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, target);

            if (distance > 1000f)
            {
                Logging.Instance.WriteLine(string.Format("PROBLEM Creating particle that has to travel {0}m: {1} - {2} - {3} ({4} {5} {6} {7})", distance, target.FatBlock != null ? target.FatBlock.GetType().Name : target.GetType().Name, m_constructionBlock.ConstructionBlock.EntityId, target.Position, target.FatBlock != null ? target.FatBlock.Physics == null : false, target.CubeGrid.Physics == null, target.CubeGrid.Closed, target.FatBlock != null ? target.FatBlock.Closed : target.IsDestroyed));
            }
        }
Example #8
0
        public virtual void Close()
        {
            int pos = 0;

            try
            {
                /*  if (Sync.IsClient)
                 *    NaniteConstructionManager.ParticleManager.RemoveParticle(m_cubeEntityId, m_position);
                 * else
                 *    m_constructionBlock.SendRemoveParticleEffect(m_cubeEntityId, m_position);
                 */
                if (m_isGrinder && m_removed)
                {
                    TransferRemainingComponents();
                    Logging.Instance.WriteLine(string.Format("GRINDER completed.  Target block: {0} - (EntityID: {1} Elapsed: {2})", m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.EntityId : 0, m_completeTime + m_waitTime));
                    return;
                }

                Logging.Instance.WriteLine(string.Format("TOOL completed.  Target block: {0} - (EntityID: {1} Elapsed: {2})", m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.EntityId : 0, m_completeTime + m_waitTime));
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("Close() {1}: {0}", ex.ToString(), pos));
            }
        }
Example #9
0
        public virtual void Close()
        {
            try
            {
                if (m_isGrinder && m_removed)
                {
                    TransferRemainingComponents();

                    Logging.Instance.WriteLine(string.Format("GRINDER completed.  Target block: {0} - (EntityID: {1} Elapsed: {2})",
                                                             m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.EntityId : 0,
                                                             m_completeTime + m_waitTime), 1);

                    return;
                }

                Logging.Instance.WriteLine(string.Format("TOOL completed.  Target block: {0} - (EntityID: {1} Elapsed: {2})",
                                                         m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.GetType().Name : m_targetBlock.GetType().Name, m_targetBlock.FatBlock != null ? m_targetBlock.FatBlock.EntityId : 0,
                                                         m_completeTime + m_waitTime), 1);
            }
            catch (Exception ex)
            {
                Logging.Instance.WriteLine(string.Format("NaniteToolBase.Close() exception:\n{0}", ex.ToString()));
            }
        }