private void CreateProjectionParticle(IMySlimBlock target)
        {
            if (!m_targetBlocks.ContainsKey(target))
            {
                Logging.Instance.WriteLine($"ADD ProjectionParticle Target: {target.Position}");
                NaniteProjectionTarget projectionTarget = new NaniteProjectionTarget();
                projectionTarget.ParticleCount = 0;
                projectionTarget.StartTime     = (int)MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds;
                m_targetBlocks.Add(target, projectionTarget);
            }

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

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

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

            m_targetBlocks[target].ParticleCount = 0;
            Vector4 startColor = new Vector4(0.95f, 0.0f, 0.95f, 0.75f);
            Vector4 endColor   = new Vector4(0.035f, 0.0f, 0.35f, 0.75f);

            m_constructionBlock.ParticleManager.AddParticle(startColor, endColor, GetMinTravelTime() * 1000f, GetSpeed(), target);
        }
예제 #2
0
        private void ProcessProjectedItem(IMySlimBlock target)
        {
            if (Sync.IsServer)
            {
                if (target.CubeGrid.GetPosition() == Vector3D.Zero)
                {
                    Logging.Instance.WriteLine("[Projection] Cancelling Projection Target due to invalid position", 1);
                    CancelTarget(target);
                    return;
                }

                if (!((m_constructionBlock.FactoryState == NaniteConstructionBlock.FactoryStates.Active || m_constructionBlock.FactoryState == NaniteConstructionBlock.FactoryStates.MissingParts) && (TargetList.Count > 0 || PotentialTargetList.Count > 0)))
                {
                    return;
                }

                if (!IsInRange(target, m_maxDistance))
                {
                    Logging.Instance.WriteLine("[Projection] Cancelling Projection Target due to being out of range", 1);
                    CancelTarget(target);
                }

                double distance = EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, target);
                int    time     = (int)Math.Max(GetMinTravelTime() * 1000f, (distance / GetSpeed()) * 1000f);

                if (!m_targetBlocks.ContainsKey(target))
                {
                    NaniteProjectionTarget projectionTarget = new NaniteProjectionTarget();
                    projectionTarget.ParticleCount = 0;
                    projectionTarget.StartTime     = (int)MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds;
                    m_targetBlocks.Add(target, projectionTarget);
                    int subgridIndex;
                    var projectorId = GetProjectorAndSubgridByBlock(target, out subgridIndex);
                    m_constructionBlock.SendAddTarget(target, TargetTypes.Projection, projectorId, subgridIndex);
                }

                if (MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds - m_targetBlocks[target].StartTime >= time / 2.5 && !m_targetBlocks[target].CheckInventory)
                {
                    m_targetBlocks[target].CheckInventory = true;
                    if (!m_constructionBlock.InventoryManager.ProcessMissingComponents(target) && !MyAPIGateway.Session.CreativeMode)
                    {
                        Logging.Instance.WriteLine("[Projection] Cancelling Projection Target due to missing components", 1);
                        CancelTarget(target);
                        return;
                    }
                }

                if (MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds - m_targetBlocks[target].StartTime >= time / 2)
                {
                    ProcessBuildBlock(target);
                    CompleteTarget(target);
                    return;
                }
            }
            CreateProjectionParticle(target);
        }
예제 #3
0
        private void CreateProjectionParticle(IMySlimBlock target)
        {
            if (!m_targetBlocks.ContainsKey(target))
            {
                Logging.Instance.WriteLine($"[Projection] Adding ProjectionParticle Target: {target.Position}", 1);
                NaniteProjectionTarget projectionTarget = new NaniteProjectionTarget();
                projectionTarget.ParticleCount = 0;
                projectionTarget.StartTime     = (int)MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds;
                m_targetBlocks.Add(target, projectionTarget);
            }

            MyAPIGateway.Parallel.Start(() =>
            {
                try
                {
                    Vector3D targetPosition = default(Vector3D);

                    if (target.FatBlock != null)
                    {
                        targetPosition = target.FatBlock.GetPosition();
                    }
                    else
                    {
                        var size = target.CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.5f : 2.5f;
                        var destinationPosition = new Vector3D(target.Position * size);
                        targetPosition          = Vector3D.Transform(destinationPosition, target.CubeGrid.WorldMatrix);
                    }

                    NaniteConstructionBlock nearestFactory = GetNearestFactory(TargetName, targetPosition);

                    Vector4 startColor = new Vector4(0.95f, 0.0f, 0.95f, 0.75f);
                    Vector4 endColor   = new Vector4(0.035f, 0.0f, 0.35f, 0.75f);

                    if (nearestFactory.ParticleManager.Particles.Count < NaniteParticleManager.MaxTotalParticles)
                    {
                        MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                        {
                            nearestFactory.ParticleManager.AddParticle(startColor, endColor, GetMinTravelTime() * 1000f, GetSpeed(), target);
                        });
                    }
                }
                catch (Exception e)
                { Logging.Instance.WriteLine($"{e}"); }
            });
        }
        private void ProcessProjectedItem(IMySlimBlock target)
        {
            if (Sync.IsServer)
            {
                if (target.CubeGrid.GetPosition() == Vector3D.Zero)
                {
                    Logging.Instance.WriteLine("CANCELLING Projection Target due to invalid position");
                    CancelTarget(target);
                    return;
                }

                if (!IsEnabled())
                {
                    Logging.Instance.WriteLine("CANCELLING Projection Target due to being disabled");
                    CancelTarget(target);
                    return;
                }

                if (!NaniteConstructionPower.HasRequiredPowerForCurrentTarget((IMyFunctionalBlock)m_constructionBlock.ConstructionBlock))
                {
                    Logging.Instance.WriteLine("CANCELLING Projection Target due to power shortage");
                    CancelTarget(target);
                    return;
                }

                if (m_constructionBlock.FactoryState != NaniteConstructionBlock.FactoryStates.Active)
                {
                    return;
                }

                double distance = EntityHelper.GetDistanceBetweenBlockAndSlimblock((IMyCubeBlock)m_constructionBlock.ConstructionBlock, target);
                int    time     = (int)Math.Max(GetMinTravelTime() * 1000f, (distance / GetSpeed()) * 1000f);
                if (!m_targetBlocks.ContainsKey(target))
                {
                    NaniteProjectionTarget projectionTarget = new NaniteProjectionTarget();
                    projectionTarget.ParticleCount = 0;
                    projectionTarget.StartTime     = (int)MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds;
                    m_targetBlocks.Add(target, projectionTarget);
                    m_constructionBlock.SendAddTarget(target, TargetTypes.Projection, GetProjectorByBlock(target));
                }

                if (MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds - m_targetBlocks[target].StartTime >= time / 2.5 && !m_targetBlocks[target].CheckInventory)
                {
                    m_targetBlocks[target].CheckInventory = true;
                    if (!m_constructionBlock.InventoryManager.ProcessMissingComponents(target))
                    {
                        Logging.Instance.WriteLine("CANCELLING Projection Target due to missing components");
                        CancelTarget(target);
                        return;
                    }
                }

                if (MyAPIGateway.Session.ElapsedPlayTime.TotalMilliseconds - m_targetBlocks[target].StartTime >= time / 2)
                {
                    //BuildBlock(target, (MyCubeBlock)m_constructionBlock.ConstructionBlock);
                    ProcessBuildBlock(target);
                    CompleteTarget(target);
                    return;
                }

                if (!m_potentialTargetList.Contains(target))
                {
                    Logging.Instance.WriteLine("COMPLETING Projection Target since potential target is missing");
                    CompleteTarget(target);
                    return;
                }
            }

            CreateProjectionParticle(target);
        }