Exemplo n.º 1
0
        public override void Do()
        {
            if (InsertIndex.Equals(-1))
            {
                foreach (var lyric in Items)
                {
                    if (!IsReverseAdd)
                    {
                        TargetList.Add(lyric);
                    }
                    else
                    {
                        TargetList.Insert(0, lyric);
                    }
                }
                return;
            }

            foreach (var lyric in Items)
            {
                if (!IsReverseAdd)
                {
                    TargetList.Insert(InsertIndex + 1, lyric);
                }
                else
                {
                    TargetList.Insert(InsertIndex, lyric);
                }
            }
        }
Exemplo n.º 2
0
        getTargets(String targetListString)
        {
            TargetList targetList   = new TargetList();
            string     defaultPorts = "II7";

            // Before we start, strip any leading and trailing parentheses,
            // get the host names inside the list,
            // and save the default ports after the host list.
            targetListString =
                getTargetListString(targetListString, ref defaultPorts);

            //
            // First, extract the semi-colon separated host/port targets.
            //
            String[] targets = parseList(targetListString, ';');

            //
            // Next, extract host and port list from each target.
            //
            for (int i = 0; i < targets.Length; i++)
            {
                String   host  = getHost(targets[i]);
                String[] ports = getPort(targets[i], defaultPorts);

                for (int j = 0; j < ports.Length; j++)
                {
                    targetList.Add(host, ports[j]);
                }
            }

            return(targetList);
        }         // getTargets
Exemplo n.º 3
0
            public MyDetectedEntityInfo?CheckTarget(TargetList targetList)
            {
                if (!turret.IsShooting)
                {
                    return(null);
                }

                Vector3D coords = GetTargetCoords(currentScanRange);

                foreach (IMyCameraBlock c in Cameras)
                {
                    if (c.CanScan(coords))
                    {
                        MyDetectedEntityInfo temp = c.Raycast(coords);
                        if (!temp.IsEmpty())
                        {
                            if (targetList.IsFriendly(temp))
                            {
                                currentScanRange = 32;
                                return(null);
                            }

                            currentScanRange = (temp.Position - turret.GetPosition()).Length();

                            targetList.Add(temp);

                            return(temp);
                        }
                        currentScanRange = scanRange;
                    }
                }
                return(null);
            }
 // Start is called before the first frame update
 public override void FindTargets()
 {
     for (int i = 0; i < EnemyManager.Singleton.enemyList.Count; i++)
     {
         if (EnemyManager.Singleton.enemyList[i].secondName != "Grape")
         {
             if (!TargetList.Contains(EnemyManager.Singleton.enemyList[i]))
             {
                 if ((EnemyManager.Singleton.enemyList[i].transform.position - towerPosition).magnitude <= range)
                 {
                     print(EnemyManager.Singleton.enemyList[i].secondName);
                     TargetList.Add(EnemyManager.Singleton.enemyList[i]);
                 }
             }
             else
             {
                 if ((EnemyManager.Singleton.enemyList[i].transform.position - towerPosition).magnitude > range)
                 {
                     TargetList.Remove(EnemyManager.Singleton.enemyList[i]);
                 }
             }
         }
     }
     SortTargetList();
 }
Exemplo n.º 5
0
        private void FindKeyboardTargets(ViewBase parent, TargetList targets)
        {
            IContextMenuTarget target = null;

            // Any target interface will be implemented on a controller instance
            if (parent.KeyController != null)
            {
                target = parent.KeyController as IContextMenuTarget;
            }
            else if (parent.MouseController != null)
            {
                target = parent.MouseController as IContextMenuTarget;
            }

            // Did we find a target associated with the view element?
            if (target != null)
            {
                targets.Add(target);
            }

            // Recurse into each of the child elements
            foreach (ViewBase child in parent)
            {
                FindKeyboardTargets(child, targets);
            }
        }
Exemplo n.º 6
0
    /// <summary>
    /// Fire on the targets
    /// </summary>
    private void OnFire()
    {
        // Log a message to show what is being fired on
        if (this.debugLevel > DEBUG_LEVELS.Off)
        {
            string msg = string.Format("Firing on: {0}\nHitEffects{1}",
                                       this.targetsString, this.effectsOnTarget.ToString());
            Debug.Log(string.Format("{0}: {1}", this, msg));
        }

        // Create a new list of targets which have this target tracker reference.
        var    targetCopies = new TargetList();
        Target target;

        foreach (Target inTarget in this.targets)
        {
            // Can't edit a struct in a foreach loop, so need to copy and store
            target = new Target(inTarget);
            target.fireController = this;  // Add reference. null before t
            targetCopies.Add(target);

            switch (this.notifyTargets)
            {
            case NOTIFY_TARGET_OPTIONS.Direct:
                target.targetable.OnHit(this.effectsOnTarget, target);
                this.SpawnAmmunition(target, false, false);
                break;

            case NOTIFY_TARGET_OPTIONS.PassToProjectile:
                this.SpawnAmmunition(target, true, true);
                break;

            case NOTIFY_TARGET_OPTIONS.UseProjectileEffects:
                this.SpawnAmmunition(target, true, false);
                break;
            }

            if (this.notifyTargets > NOTIFY_TARGET_OPTIONS.Off)
            {
                // Just for debug. Show a gizmo line when firing
                if (this.debugLevel > DEBUG_LEVELS.Off)
                {
                    Debug.DrawLine(this.emitter.position,
                                   target.transform.position,
                                   Color.red);
                }
            }
        }

        // Write the result over the old target list. This is for output so targets
        //   which are handled at all by this target tracker are stamped with a
        //   reference.
        this.targets = targetCopies;

        // Trigger the delegates
        if (this.onFireDelegates != null)
        {
            this.onFireDelegates(this.targets);
        }
    }
    public override void FindTargets()
    {
        for (int i = 0; i < EnemyManager.Singleton.enemyList.Count; i++)
        {
            // if (EnemyManager.Singleton.enemyList[i].enemySpeed > 1.25f) {// Only Targets Bikes
            if (!TargetList.Contains(EnemyManager.Singleton.enemyList[i]))
            {
                if ((EnemyManager.Singleton.enemyList[i].transform.position - towerPosition).magnitude <= range)
                {
                    TargetList.Add(EnemyManager.Singleton.enemyList[i]);
                    Fire();
                }
            }
            else
            {
                if ((EnemyManager.Singleton.enemyList[i].transform.position - towerPosition).magnitude > range)
                {
                    EnemyManager.Singleton.enemyList[i].enemySpeed = EnemyManager.Singleton.enemyList[i].enemySpeed / .85f;
                    TargetList.Remove(EnemyManager.Singleton.enemyList[i]);
                }
            }

            // }
        }
        // SortTargetList();
    }
Exemplo n.º 8
0
    protected override void Do()
    {
        TargetList.Clear();
        TargetList.Add(Owner.Mgr.Raid.GetRandom());
        Target.TakeDamage(TotalPower);

        base.Do();
    }
Exemplo n.º 9
0
        public static TargetEntry[] GetTextTargetsWithSpecial(string aName, uint aType)
        {
            TargetList targetlist = GetTextTargetList();

            if (aName.Trim() != "")
            {
                targetlist.Add(aName.Trim(), 0, aType);
            }
            return((TargetEntry[])targetlist);
        }
Exemplo n.º 10
0
 public void Init()
 {
     if (LoadValue != null)
     {
         var l = LoadValue();
         TargetList.Clear();
         if (l != null)
         {
             TargetList.Add(l);
         }
     }
 }
Exemplo n.º 11
0
        void UpdateTargetList(Entity faction, EntityManager manager)
        {
            var ownedEntites = manager.GetEntitiesByFaction(faction.Guid);

            foreach (var entityItem in ownedEntites)//entity.Manager.GetAllEntitiesWithDataBlob<PositionDB>())
            {
                if (entityItem.HasDataBlob <PositionDB>() && entityItem.HasDataBlob <NameDB>())
                {
                    TargetList.Add(entityItem.Guid, entityItem.GetDataBlob <NameDB>().GetName(faction.Guid));
                    _targetDict.Add(entityItem.Guid, entityItem);
                }
            }
        }
Exemplo n.º 12
0
    /// <summary>
    /// 创建单位
    /// </summary>
    private void CreateItems()
    {
        quadtree = new TargetList <Holder>(Width * 0.5f, Heght * 0.5f, Width, Heght, 1);
        var random = new Random(DateTime.Now.Millisecond);

        for (var i = 0; i < ItemCount; i++)
        {
            var circle = new CircleGraphics(new Vector2(random.Next(0, Width), random.Next(0, Heght)), random.Next(1, 10));
            var holder = new Holder();
            holder.Direction           = new Vector2(random.Next(-10, 10), random.Next(-10, 10));
            holder.MyCollisionGraphics = circle;
            quadtree.Add(holder);
        }
    }
Exemplo n.º 13
0
    private void OnTriggerEnter(Collider other)
    {
        CharacterMono target = other.GetComponent <CharacterMono>();

        if (target != null)
        {
            TargetList.Add(target);

            //Debug.Log("单位进入了触发器");
            if (HaloSkillExecute != null && speller != null)
            {
                HaloSkillExecute(speller, target);
            }
        }
    }
Exemplo n.º 14
0
        public void AddToTargetList(Character target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }
            if (target == m_character)
            {
                throw new ArgumentOutOfRangeException(nameof(target));
            }

            if (TargetList.Contains(target) == false)
            {
                TargetList.Add(target);
            }
        }
Exemplo n.º 15
0
        public void EnterPassenger(Person person)
        {
            if (person == null)
            {
                throw new NullReferenceException("Person får inte vara null.");
            }
            if (Passengers.Count >= Capacity)
            {
                throw new Exception($"Något har gått fel med Capacity för {Name}.");
            }
            if (person.TargetFloor == CurrentFloor)
            {
                throw new Exception($"Personen har gått in i en hiss, fast den är på sin TargetFloor.");
            }

            Passengers.Add(person);
            TargetList.Add(person.TargetFloor);
        }
Exemplo n.º 16
0
        new private void PacketHandler(Packet packet)
        {
            var arpPacket = packet.Ethernet.Arp;

            switch (arpPacket.Operation)
            {
            case PcapDotNet.Packets.Arp.ArpOperation.Reply:
                var senderIp = arpPacket.SenderProtocolIpV4Address.ToString();
                if (_isOwnIpIncluded || _ownIp != senderIp)
                {
                    if (senderIp == _gatewayIp)
                    {
                        if (!_gateways.ContainsIP(senderIp))
                        {
                            var target = new Target();
                            target.IP = senderIp;
                            //target.MAC = arpPacket.SenderHardwareAddress.ToString();
                            target.PMAC   = new PhysicalAddress(arpPacket.SenderHardwareAddress.ToArray());
                            target.MAC    = Helper.AddSeperatorToNakedMac(target.PMAC.ToString(), ":");
                            target.Vendor = VendorCodeResolver.instance.Resolve(target.MAC);
                            Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                            {
                                _gateways.Add(target);
                            }));
                        }
                    }
                    else if (!_targets.ContainsIP(senderIp))
                    {
                        var target = new Target();
                        target.IP = senderIp;
                        //target.MAC = arpPacket.SenderHardwareAddress.ToString();
                        target.PMAC   = new PhysicalAddress(arpPacket.SenderHardwareAddress.ToArray());
                        target.MAC    = Helper.AddSeperatorToNakedMac(target.PMAC.ToString(), ":");
                        target.Vendor = VendorCodeResolver.instance.Resolve(target.MAC);
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            _targets.Add(target);
                        }));
                    }
                }
                break;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 获取各部门某月move target
        /// </summary>
        /// <param name="month">eg:2019-05</param>
        /// <returns></returns>
        public void GetTargetListByMonth(string month)
        {
            int    year     = Convert.ToInt16(month.Split('-')[0]);
            int    mon      = Convert.ToInt16(month.Split('-')[1]);
            string strMonth = string.Format("{0}-{1}", year, mon < 10?"0" + mon:mon.ToString());
            string sql      = string.Format(@"select 
t.Dept_code,plan_date,target_value,c.description department
from istrpt.Rpt_Move_Target t
left join 
mmview.frcode c
on
c.category_id='Department'
and c.code_id=t.dept_code where t.plan_date like '{0}-%'", strMonth);

            Days          = DateTime.DaysInMonth(year, mon);
            Month         = year.ToString() + "年" + mon.ToString() + "月";
            TargetCatcher = new DB2DataCatcher <Rpt_Move_Target>("", sql);
            var list = TargetCatcher.GetEntities().EntityList;

            if (!list.Any())
            {
                return;
            }
            var deptList = list.Select(s => s.Dept_Code).Distinct();

            foreach (var dept in deptList)
            {
                var list_dept = list.Where(w => w.Dept_Code == dept);
                ReqRpt002MoveTargetEntity targetEntity = new ReqRpt002MoveTargetEntity()
                {
                    DeptCode = dept
                };
                targetEntity.Department = list_dept.First().Department;
                for (var i = 1; i <= Days; i++)
                {
                    var date = i < 10 ? ("0" + i): i.ToString();
                    var val  = list_dept.Where(w => w.Plan_Date == strMonth + "-" + date);
                    targetEntity.TargetList.Add(val.Any()?val.First().Target_Value:0);
                }
                TargetList.Add(targetEntity);
            }
        }
Exemplo n.º 18
0
        private void AddTarget(object obj)
        {
            if (SelectedTarget.Id == 0)
            {
                int periodValue = 0;
                switch (SelectedTarget.TargetType)
                {
                case TargetType.Year:
                    periodValue = CurrentYear.Data;
                    break;

                case TargetType.Month:
                    periodValue = currentMonth.Data.Key;
                    break;

                case TargetType.Week:
                    periodValue = CurrentWeek.Data.Key;
                    break;

                case TargetType.Day:
                    periodValue = CurrentDay.Data.Key;
                    break;
                }
                Target newTarget = new Target(SelectedTarget.Name,
                                              SelectedTarget.Description,
                                              SelectedTarget.TargetType,
                                              CurrentYear.Data, periodValue,
                                              SelectedTarget.LastDate,
                                              SelectedTarget.Important, null);
                newTarget.Tasks = SelectedTarget.Tasks;
                TargetList.Add(newTarget);
            }
            else
            {
                TargetList.Edit(SelectedTarget);
            }
            CloseAction();
        }
Exemplo n.º 19
0
 public void InitPortfolio(IPortfolio portfolio)
 {
     TargetPortfolio = portfolio;
     //TargetList.Clear();
     if (portfolio != null)
     {
         portfolio.PositionList.ForEach(v =>
         {
             var pos = TargetList.FirstOrDefault(x => x.TargetTicker == v.Name);
             if (pos == null)
             {
                 PosWeightTarget posweight     = new PosWeightTarget();
                 posweight.TargetTicker        = v.Name;
                 posweight.Shares              = v.Shares;
                 posweight.CurrentPrice        = v.CurrentPrice;
                 posweight.CurrentWeight       = v.CurrentValue / portfolio.CurrentValue;
                 posweight.DataTime            = v.DataTime;
                 posweight.CurrentCurrency     = v.CurrentCurrency;
                 posweight.TargetPortfolioName = portfolio.Name;
                 TargetList.Add(posweight);
             }
         });
     }
 }
        public override void FindTargets(ref Dictionary <string, int> available)
        {
            ComponentsRequired.Clear();

            if (!IsEnabled())
            {
                return;
            }

            if (TargetList.Count >= GetMaximumTargets())
            {
                if (PotentialTargetList.Count > 0)
                {
                    m_lastInvalidTargetReason = "Maximum targets reached.  Add more upgrades!";
                }

                return;
            }

            NaniteConstructionInventory inventoryManager = m_constructionBlock.InventoryManager;
            Vector3D sourcePosition          = m_constructionBlock.ConstructionBlock.GetPosition();
            Dictionary <string, int> missing = new Dictionary <string, int>();

            using (m_lock.AcquireExclusiveUsing())
            {
                foreach (var item in PotentialTargetList.OrderBy(x => Vector3D.Distance(sourcePosition, EntityHelper.GetBlockPosition((IMySlimBlock)x))))
                {
                    if (m_constructionBlock.IsUserDefinedLimitReached())
                    {
                        m_lastInvalidTargetReason = "User defined maximum nanite limit reached";
                        return;
                    }

                    if (TargetList.Contains(item))
                    {
                        continue;
                    }

                    missing = inventoryManager.GetProjectionComponents((IMySlimBlock)item);
                    bool haveComponents = inventoryManager.CheckComponentsAvailable(ref missing, ref available);
                    if (haveComponents && NaniteConstructionPower.HasRequiredPowerForNewTarget((IMyFunctionalBlock)m_constructionBlock.ConstructionBlock, this))
                    {
                        if (((IMySlimBlock)item).CubeGrid.GetPosition() == Vector3D.Zero)
                        {
                            m_lastInvalidTargetReason = "Target blocks grid is in an invalid position (Vector3D.Zero, this shouldn't happen!)";
                            continue;
                        }

                        var  blockList = NaniteConstructionManager.GetConstructionBlocks((IMyCubeGrid)m_constructionBlock.ConstructionBlock.CubeGrid);
                        bool found     = false;
                        foreach (var block in blockList)
                        {
                            if (block.GetTarget <NaniteProjectionTargets>().TargetList.Contains(item))
                            {
                                found = true;
                                break;
                            }
                        }

                        if (found)
                        {
                            m_lastInvalidTargetReason = "Another factory has this block as a target";
                            continue;
                        }

                        TargetList.Add(item);
                        IMySlimBlock slimBlock = (IMySlimBlock)item;
                        var          def       = slimBlock.BlockDefinition as MyCubeBlockDefinition;
                        Logging.Instance.WriteLine(string.Format("ADDING Projection Target: conid={0} subtypeid={1} entityID={2} position={3}", m_constructionBlock.ConstructionBlock.EntityId, def.Id.SubtypeId, slimBlock.FatBlock != null ? slimBlock.FatBlock.EntityId : 0, slimBlock.Position));
                        if (TargetList.Count >= GetMaximumTargets())
                        {
                            break;
                        }
                    }
                    else if (!haveComponents)
                    {
                        m_lastInvalidTargetReason = "Missing components to start projected block";
                    }
                    else if (!NaniteConstructionPower.HasRequiredPowerForNewTarget((IMyFunctionalBlock)m_constructionBlock.ConstructionBlock, this))
                    {
                        m_lastInvalidTargetReason = "Insufficient power for another target.";
                    }
                }
            }
        }
Exemplo n.º 21
0
 private void OnFire()
 {
     if (this.debugLevel > DEBUG_LEVELS.Off)
     {
         string arg = string.Format("Firing on: {0}\nHitEffects{1}", this.targetsString, this.effectsOnTarget.ToString());
         UnityEngine.Debug.Log(string.Format("{0}: {1}", this, arg));
     }
     TargetList targetList = new TargetList();
     foreach (Target current in this.targets)
     {
         Target target = new Target(current);
         target.fireController = this;
         targetList.Add(target);
         switch (this.notifyTargets)
         {
         case FireController.NOTIFY_TARGET_OPTIONS.Direct:
             target.targetable.OnHit(this.effectsOnTarget, target);
             this.SpawnAmmunition(target, false, false);
             break;
         case FireController.NOTIFY_TARGET_OPTIONS.PassToProjectile:
             this.SpawnAmmunition(target, true, true);
             break;
         case FireController.NOTIFY_TARGET_OPTIONS.UseProjectileEffects:
             this.SpawnAmmunition(target, true, false);
             break;
         }
         if (this.notifyTargets > FireController.NOTIFY_TARGET_OPTIONS.Off && this.debugLevel > DEBUG_LEVELS.Off)
         {
             UnityEngine.Debug.DrawLine(this.emitter.position, target.transform.position, Color.red);
         }
     }
     this.targets = targetList;
     if (this.onFireDelegates != null)
     {
         this.onFireDelegates(this.targets);
     }
 }
Exemplo n.º 22
0
        public override void FindTargets(ref Dictionary <string, int> available)
        {
            if (!IsEnabled())
            {
                return;
            }

            if (TargetList.Count >= GetMaximumTargets())
            {
                if (PotentialTargetList.Count > 0)
                {
                    m_lastInvalidTargetReason = "Maximum targets reached.  Add more upgrades!";
                }

                return;
            }

            using (Lock.AcquireExclusiveUsing())
            {
                for (int r = PotentialTargetList.Count - 1; r >= 0; r--)
                {
                    if (m_constructionBlock.IsUserDefinedLimitReached())
                    {
                        m_lastInvalidTargetReason = "User defined maximum nanite limit reached";
                        return;
                    }

                    var item = (IMyPlayer)PotentialTargetList[r];
                    if (TargetList.Contains(item))
                    {
                        continue;
                    }

                    if (item.Controller == null || item.Controller.ControlledEntity == null || item.Controller.ControlledEntity.Entity == null)
                    {
                        PotentialTargetList.RemoveAt(r);
                        continue;
                    }

                    var  blockList = NaniteConstructionManager.GetConstructionBlocks((IMyCubeGrid)m_constructionBlock.ConstructionBlock.CubeGrid);
                    bool found     = false;
                    foreach (var block in blockList)
                    {
                        if (block.Targets.First(x => x is NaniteMedicalTargets).TargetList.Contains(item))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        m_lastInvalidTargetReason = "Another factory has this block as a target";
                        continue;
                    }

                    if (Vector3D.DistanceSquared(m_constructionBlock.ConstructionBlock.GetPosition(), item.GetPosition()) < m_maxDistance * m_maxDistance &&
                        NaniteConstructionPower.HasRequiredPowerForNewTarget((IMyFunctionalBlock)m_constructionBlock.ConstructionBlock, this))
                    {
                        TargetList.Add(item);
                        Logging.Instance.WriteLine(string.Format("ADDING Medical Target: conid={0} type={1} playerName={2} position={3}", m_constructionBlock.ConstructionBlock.EntityId, item.GetType().Name, item.DisplayName, item.GetPosition()));
                        if (TargetList.Count >= GetMaximumTargets())
                        {
                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
    private IEnumerator Detonate()
    {
        if (this.debugLevel > DEBUG_LEVELS.Off)
        {
            string msg = "Detonating...";
            Debug.Log(string.Format("Detonator ({0}): {1}", this.name, msg));
        }

        // Wait for next frame to begin to be sure targets have been propegated
        // This also makes this loop easier to manage.
        yield return(new WaitForFixedUpdate());  // Because of physics...matters?

        // START EVENT
        if (this.OnDetonatingDelegates != null)
        {
            this.OnDetonatingDelegates();
        }

        // Keep track of targets which have already been processed so they
        //      aren't hit twice
        var processedTargetList = new TargetList();

        this.range = Vector3.zero;

        float timer    = 0;
        float progress = 0;  // Normalized mount processed 0-1

        // The timer can exit the loop if used
        while (true)
        {
            // UPDATE EVENT
            if (this.OnDetonatingUpdateDelegates != null)
            {
                this.OnDetonatingUpdateDelegates(progress);
            }

            // Exit?
            if (timer >= this.durration)
            {
                break;
            }
            timer += Time.deltaTime;

            progress = timer / this.durration;

            this.range = this.maxRange * progress;

            // Build a list of targets in range which have NOT been processed yet.
            var newTargets = new TargetList();
            foreach (Target target in this.targets)
            {
                if (!processedTargetList.Contains(target))
                {
                    newTargets.Add(target);
                }
            }

            if (newTargets.Count > 0)
            {
                if (this.debugLevel > DEBUG_LEVELS.Off)
                {
                    string msg = string.Format("Detonation hitting targets: {0}", this.targets);
                    Debug.Log(string.Format("Detonator ({0}): {1}", this.name, msg));
                }

                foreach (Target target in newTargets)
                {
                    target.targetable.OnHit
                    (
                        this.effectsOnTarget,
                        target,
                        this.perimeter.collider
                    );

                    processedTargetList.Add(target);
                }
            }

            yield return(new WaitForFixedUpdate());  // Because of physics...matters?
        }

        // Prevent being run more than once in a frame where it has already
        //   been destroyed.
        if (!this.gameObject.activeInHierarchy)
        {
            yield break;  // Same as return
        }
        TargetPro.InstanceManager.Despawn(this.transform);
    }
Exemplo n.º 24
0
        /// <summary>
        /// Destroys the projectile on impact and finds objects in range to 
        ///	affect if they share the same tag as target.
        /// </summary>
        public void DetonateProjectile()
        {
            // Prevent being run more than once in a frame where it has already 
            //   been destroyed.
            if (!this.gameObject.activeInHierarchy) return;

            // Build a new list of targets depending on the options used
            var targetList = new TargetList();
            if (this.areaHit)
            {
                // This is turned back off OnDisable() (base class)
                this.perimeter.enabled = true;

                targetList.AddRange(this.targets); // Add all targets in range
            }
            else
            {
                if (this.target != Target.Null)
                    targetList.Add(this.target); // Add projectile target
            }

            if (this.debugLevel > DEBUG_LEVELS.Off)
            {
                string msg = string.Format("Detonating with targets: {0}", targetList);
                Debug.Log(string.Format("Projectile ({0}): {1}", this.name, msg));
            }

            // Create a new list of targets which have this target tracker reference.
            //   This is for output so targets which are handled at all by this Projectile
            //   are stamped with a reference.
            var targetCopies = new TargetList();
            Target target;
            foreach (Target inTarget in targetList)
            {
                if (inTarget == Target.Null)
                    continue;

                // Can't edit a struct in a foreach loop, so need to copy and store
                target = new Target(inTarget);
                target.projectile = this;  // Add reference. null before t
                targetCopies.Add(target);

                switch (this.notifyTargets)
                {
                    case NOTIFY_TARGET_OPTIONS.Direct:
                        target.targetable.OnHit(this.effectsOnTarget, target, this.collider);
                        break;
                }

                // Just for debug. Show a gizmo line when firing
                if (this.debugLevel > DEBUG_LEVELS.Off)
                    Debug.DrawLine
                    (
                        this.xform.position,
                        target.transform.position,
                        Color.red
                    );

            }

            switch (this.notifyTargets)
            {
                case NOTIFY_TARGET_OPTIONS.Direct:
                    this.SpawnDetonatorPrefab(false);
                    break;

                case NOTIFY_TARGET_OPTIONS.PassToDetonator:
                    this.SpawnDetonatorPrefab(true);
                    break;
            }


            // Trigger delegates
            if (this.OnDetonationDelegates != null) this.OnDetonationDelegates(targetCopies);

            // Clean-up in case this instance is used in a pooling system like PoolManager
            this.target = Target.Null;

            InstanceManager.Despawn(this.transform);
        }
        public override void FindTargets(ref Dictionary <string, int> available, List <NaniteConstructionBlock> blockList)
        {
            var maxTargets = GetMaximumTargets();

            if (TargetList.Count >= maxTargets)
            {
                if (m_potentialMiningTargets.Count > 0)
                {
                    InvalidTargetReason("Maximum targets reached. Add more upgrades!");
                }

                return;
            }

            string LastInvalidTargetReason = "";

            int targetListCount = m_targetList.Count;

            HashSet <Vector3D>      usedPositions = new HashSet <Vector3D>();
            List <NaniteMiningItem> removeList    = new List <NaniteMiningItem>();

            foreach (NaniteMiningItem item in m_potentialMiningTargets.ToList())
            {
                if (item == null || TargetList.Contains(item))
                {
                    removeList.Add(item);
                    continue;
                }
                if (m_globalPositionList.Contains(item.Position) || usedPositions.Contains(item.Position))
                {
                    LastInvalidTargetReason = "Mining position was already targeted";
                    removeList.Add(item);
                    continue;
                }
                if (!m_constructionBlock.HasRequiredPowerForNewTarget(this))
                {
                    LastInvalidTargetReason = "Insufficient power for another target";
                    break;
                }

                bool found = false;
                foreach (var block in blockList.ToList())
                {
                    if (block != null && block.GetTarget <NaniteMiningTargets>().TargetList.FirstOrDefault(x => ((NaniteMiningItem)x).Position == item.Position) != null)
                    {
                        found = true;
                        LastInvalidTargetReason = "Another factory has this voxel as a target";
                        break;
                    }
                }

                if (found)
                {
                    removeList.Add(item);
                    continue;
                }
                var nearestFactory = GetNearestFactory(TargetName, item.Position);
                if (IsInRange(nearestFactory, item.Position, m_maxDistance))
                {
                    Logging.Instance.WriteLine(string.Format("[Mining] Adding Mining Target: conid={0} pos={1} type={2}",
                                                             m_constructionBlock.ConstructionBlock.EntityId, item.Position, MyDefinitionManager.Static.GetVoxelMaterialDefinition(item.VoxelMaterial).MinedOre), 1);

                    removeList.Add(item);
                    usedPositions.Add(item.Position);

                    MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                    {
                        try
                        {
                            if (m_constructionBlock.IsUserDefinedLimitReached())
                            {
                                InvalidTargetReason("User defined maximum nanite limit reached");
                            }
                            else if (item != null)
                            {
                                removeList.Add(item);
                                TargetList.Add(item);
                            }
                        }
                        catch (Exception e)
                        {
                            Logging.Instance.WriteLine("NaniteMiningTargets.FindTargets.Invocation1: " + e.ToString());
                        }
                    });

                    if (targetListCount++ >= maxTargets)
                    {
                        break;
                    }
                }
                else
                {
                    removeList.Add(item);
                }
            }

            foreach (var item in removeList)
            {
                m_potentialMiningTargets.Remove(item);
            }

            if (LastInvalidTargetReason != "")
            {
                InvalidTargetReason(LastInvalidTargetReason);
            }
        }
Exemplo n.º 26
0
 /// <summary>
 /// 加入单位
 /// </summary>
 /// <param name="member">单位</param>
 public void Add(PositionObject member)
 {
     targetList.Add(member);
 }
Exemplo n.º 27
0
 public static void AddTargetEntry(this TargetList targetList, TargetEntry entry)
 {
     targetList.Add(entry.Target, (uint)entry.Flags, (uint)entry.Info);
 }
        public override void FindTargets(ref Dictionary <string, int> available)
        {
            m_lastInvalidTargetReason = "";

            if (!IsEnabled())
            {
                return;
            }

            if (TargetList.Count >= GetMaximumTargets())
            {
                if (PotentialTargetList.Count > 0)
                {
                    m_lastInvalidTargetReason = "Maximum targets reached.  Add more upgrades!";
                }

                return;
            }

            using (Lock.AcquireExclusiveUsing())
            {
                foreach (IMySlimBlock item in PotentialTargetList.ToList())
                {
                    if (m_constructionBlock.IsUserDefinedLimitReached())
                    {
                        m_lastInvalidTargetReason = "User defined maximum nanite limit reached";
                        return;
                    }

                    if (TargetList.Contains(item))
                    {
                        continue;
                    }

                    if (!NaniteConstructionPower.HasRequiredPowerForNewTarget((IMyFunctionalBlock)m_constructionBlock.ConstructionBlock, this))
                    {
                        m_lastInvalidTargetReason = "Insufficient power for another target.";
                        break;
                    }

                    if (item.CubeGrid.Closed || item.IsDestroyed || item.IsFullyDismounted || (item.FatBlock != null && item.FatBlock.Closed))
                    {
                        m_lastInvalidTargetReason = "Potential target is destroyed";
                        continue;
                    }

                    var  blockList = NaniteConstructionManager.GetConstructionBlocks((IMyCubeGrid)m_constructionBlock.ConstructionBlock.CubeGrid);
                    bool found     = false;
                    foreach (var block in blockList)
                    {
                        if (block.Targets.First(x => x is NaniteDeconstructionTargets).TargetList.Contains(item as IMySlimBlock))
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        m_lastInvalidTargetReason = "Another factory has this block as a target";
                        continue;
                    }

                    /*
                     * var blocks = NaniteConstructionManager.NaniteBlocks.Select(x => x.Value).Where(y => y.ConstructionBlock.CubeGrid == m_constructionBlock.ConstructionBlock.CubeGrid && y.ConstructionBlock != m_constructionBlock.ConstructionBlock);
                     * Logging.Instance.WriteLine(string.Format("Count: {0}", blocks.Count()));
                     * var found = blocks.FirstOrDefault(x => x.Targets.First(y => y is NaniteDeconstructionTargets).TargetList.Contains(item)) != null;
                     * if (found)
                     * {
                     *  Logging.Instance.WriteLine("Found");
                     *  continue;
                     * }
                     */

                    PotentialTargetList.Remove(item);
                    TargetList.Add(item);

                    var def = item.BlockDefinition as MyCubeBlockDefinition;
                    Logging.Instance.WriteLine(string.Format("ADDING Deconstruction Target: conid={0} subtypeid={1} entityID={2} position={3}", m_constructionBlock.ConstructionBlock.EntityId, def.Id.SubtypeId, item.FatBlock != null ? item.FatBlock.EntityId : 0, item.Position));

                    if (TargetList.Count >= GetMaximumTargets())
                    {
                        break;
                    }
                }
            }
        }
Exemplo n.º 29
0
    /// <summary>
    /// Destroys the projectile on impact and finds objects in range to
    ///	affect if they share the same tag as target.
    /// </summary>
    public void DetonateProjectile()
    {
        // Prevent being run more than once in a frame where it has already
        //   been destroyed.
        if (!this.gameObject.activeInHierarchy)
        {
            return;
        }

        // Build a new list of targets depending on the options used
        var targetList = new TargetList();

        if (this.areaHit)
        {
            // This is turned back off OnDisable() (base class)
            this.perimeter.enabled = true;

            targetList.AddRange(this.targets); // Add all targets in range
        }
        else
        {
            if (this.target != Target.Null)
            {
                targetList.Add(this.target); // Add projectile target
            }
        }

        if (this.debugLevel > DEBUG_LEVELS.Off)
        {
            string msg = string.Format("Detonating with targets: {0}", targetList);
            Debug.Log(string.Format("Projectile ({0}): {1}", this.name, msg));
        }

        // Create a new list of targets which have this target tracker reference.
        //   This is for output so targets which are handled at all by this Projectile
        //   are stamped with a reference.
        var    targetCopies = new TargetList();
        Target target;

        foreach (Target inTarget in targetList)
        {
            if (inTarget == Target.Null)
            {
                continue;
            }

            // Can't edit a struct in a foreach loop, so need to copy and store
            target            = new Target(inTarget);
            target.projectile = this;  // Add reference. null before t
            targetCopies.Add(target);

            switch (this.notifyTargets)
            {
            case NOTIFY_TARGET_OPTIONS.Direct:
                target.targetable.OnHit(this.effectsOnTarget, target, this.collider);
                break;
            }

            // Just for debug. Show a gizmo line when firing
            if (this.debugLevel > DEBUG_LEVELS.Off)
            {
                Debug.DrawLine
                (
                    this.xform.position,
                    target.transform.position,
                    Color.red
                );
            }
        }

        switch (this.notifyTargets)
        {
        case NOTIFY_TARGET_OPTIONS.Direct:
            this.SpawnDetonatorPrefab(false);
            break;

        case NOTIFY_TARGET_OPTIONS.PassToDetonator:
            this.SpawnDetonatorPrefab(true);
            break;
        }


        // Trigger delegates
        if (this.OnDetonationDelegates != null)
        {
            this.OnDetonationDelegates(targetCopies);
        }

        // Clean-up in case this instance is used in a pooling system like PoolManager
        this.target = Target.Null;

        InstanceManager.Despawn(this.transform);
    }
        /// <summary>
        /// Fire on the targets
        /// </summary>
        protected void Fire()
        {
#if UNITY_EDITOR
            // Log a message to show what is being fired on
            if (this.debugLevel > DEBUG_LEVELS.Off)
            {
                string[] names = new string[this.targets.Count];
                for (int i = 0; i < this.targets.Count; i++)
                    names[i] = this.targets[i].transform.name;

                string msg = string.Format
				(
					"Firing on: {0}\nEventInfo: {1}",
					string.Join(", ", names), 
					this.eventInfoList.ToString()
				);
				
                Debug.Log(string.Format("{0}: {1}", this, msg));
            }
#endif 
			
            // 
			// Create a new list of targets which have this fire controller reference.
			//
            var targetCopies = new TargetList();
            Target newTarget;
            foreach (Target target in this.targets)
            {
                // Can't edit a struct in a foreach loop, so need to copy and store
                newTarget = new Target(target);
                newTarget.fireController = this;  // Add reference. null before this
                targetCopies.Add(newTarget);
            }

            // Write the result over the old target list. This is for output so targets
            //   which are handled at all by this target tracker are stamped with a 
            //   reference.
            this.targets = targetCopies;
			
			//
			// Hnadle delivery
			//
            foreach (Target target in this.targets)
            {
                switch (this.notifyTargets)
                {
                    case NOTIFY_TARGET_OPTIONS.Direct:
                        target.targetable.OnHit(this.eventInfoList, target);
                        break;

                    case NOTIFY_TARGET_OPTIONS.PassInfoToEventTrigger:
                        this.SpawnEventTrigger(target, true);
                        break;

                    case NOTIFY_TARGET_OPTIONS.UseEventTriggerInfo:
                        this.SpawnEventTrigger(target, false);
                        break;
                }

			}

#if UNITY_EDITOR
			// When in the editor, if debugging, draw a line to each hit target.
			if (this.debugLevel > DEBUG_LEVELS.Off && this.notifyTargets > NOTIFY_TARGET_OPTIONS.Off)
			{
				foreach (Target target in this.targets)	
                    Debug.DrawLine(this.spawnEventTriggerAtTransform.position, target.transform.position, Color.red);
			}
#endif	
            // Trigger the delegates
            if (this.onFireDelegates != null) this.onFireDelegates(this.targets);
        }
Exemplo n.º 31
0
 public void DetonateProjectile()
 {
     if (!base.gameObject.activeInHierarchy)
     {
         return;
     }
     TargetList targetList = new TargetList();
     if (this.areaHit)
     {
         base.perimeter.enabled = true;
         targetList.AddRange(this.targets);
     }
     else if (this.target != Target.Null)
     {
         targetList.Add(this.target);
     }
     if (this.debugLevel > DEBUG_LEVELS.Off)
     {
         string arg = string.Format("Detonating with targets: {0}", targetList);
         UnityEngine.Debug.Log(string.Format("Projectile ({0}): {1}", base.name, arg));
     }
     TargetList targetList2 = new TargetList();
     Projectile.NOTIFY_TARGET_OPTIONS nOTIFY_TARGET_OPTIONS;
     foreach (Target current in targetList)
     {
         if (!(current == Target.Null))
         {
             Target target = new Target(current);
             target.projectile = this;
             targetList2.Add(target);
             nOTIFY_TARGET_OPTIONS = this.notifyTargets;
             if (nOTIFY_TARGET_OPTIONS == Projectile.NOTIFY_TARGET_OPTIONS.Direct)
             {
                 target.targetable.OnHit(this.effectsOnTarget, target, base.GetComponent<Collider>());
             }
             if (this.debugLevel > DEBUG_LEVELS.Off)
             {
                 UnityEngine.Debug.DrawLine(this.xform.position, target.transform.position, Color.red);
             }
         }
     }
     nOTIFY_TARGET_OPTIONS = this.notifyTargets;
     if (nOTIFY_TARGET_OPTIONS != Projectile.NOTIFY_TARGET_OPTIONS.Direct)
     {
         if (nOTIFY_TARGET_OPTIONS == Projectile.NOTIFY_TARGET_OPTIONS.PassToDetonator)
         {
             this.SpawnDetonatorPrefab(true);
         }
     }
     else
     {
         this.SpawnDetonatorPrefab(false);
     }
     if (this.OnDetonationDelegates != null)
     {
         this.OnDetonationDelegates(targetList2);
     }
     this.target = Target.Null;
     InstanceManager.Despawn(base.transform);
 }
Exemplo n.º 32
0
    /// <summary>
    /// Fire on the targets
    /// </summary>
    private void OnFire()
    {
        // Log a message to show what is being fired on
        if (this.debugLevel > DEBUG_LEVELS.Off)
        {
            string msg = string.Format("Firing on: {0}\nHitEffects{1}",
                                  this.targetsString, this.effectsOnTarget.ToString());
            Debug.Log(string.Format("{0}: {1}", this, msg));
        }

        // Create a new list of targets which have this target tracker reference.
        var targetCopies = new TargetList();
        Target target;
        foreach (Target inTarget in this.targets)
        {
            // Can't edit a struct in a foreach loop, so need to copy and store
            target = new Target(inTarget);
            target.fireController = this;  // Add reference. null before t
            targetCopies.Add(target);

            switch (this.notifyTargets)
            {
                case NOTIFY_TARGET_OPTIONS.Direct:
                    target.targetable.OnHit(this.effectsOnTarget, target);
                    this.SpawnAmmunition(target, false, false);
                    break;

                case NOTIFY_TARGET_OPTIONS.PassToProjectile:
                    this.SpawnAmmunition(target, true, true);
                    break;

                case NOTIFY_TARGET_OPTIONS.UseProjectileEffects:
                    this.SpawnAmmunition(target, true, false);
                    break;
            }

            if (this.notifyTargets > NOTIFY_TARGET_OPTIONS.Off)
            {
                // Just for debug. Show a gizmo line when firing
                if (this.debugLevel > DEBUG_LEVELS.Off)
                    Debug.DrawLine(this.emitter.position,
                                   target.transform.position,
                                   Color.red);
            }
        }

        // Write the result over the old target list. This is for output so targets
        //   which are handled at all by this target tracker are stamped with a
        //   reference.
        this.targets = targetCopies;

        // Trigger the delegates
        if (this.onFireDelegates != null) this.onFireDelegates(this.targets);
    }
Exemplo n.º 33
0
    /// <summary>
    /// 创建测试单元
    /// </summary>
    /// <param name="count">创建单元个数</param>
    private void CreateAllMember(int count)
    {
        var random = new System.Random();

        // 测试 四叉树遇上超大目标
        for (var i = 0; i < count; i++)
        {
            // TODO 创建数据
            var memberData = new VOBase
            {
                SpaceSet    = 10,
                MoveSpeed   = 10,
                AttackRange = 20
            };
            var gameObj = GameObject.CreatePrimitive(PrimitiveType.Cube);
            var member  = gameObj.AddComponent <ClusterData>();
            var x       = random.Next(0, MapWidth);
            var y       = random.Next(0, MapHeight);


            memberData.SpaceSet    = i % 5 + 1;
            memberData.CurrentHP   = i % 5 + 1;
            memberData.AttackRange = 100;
            memberData.TotalHp     = 10;
            memberData.GeneralType = (short)random.Next(1, 4);
            //member.IsSurface = random.Next(1) > 0;
            //member.IsAir = !member.IsSurface;
            //member.IsBuild = random.Next(1) > 0;
            memberData.ArmyType = (short)random.Next(1, 4);
            memberData.IsHide   = random.Next(1) > 0;

            member.AllData.MemberData = memberData;
            //    new VOBase()
            //{
            //    AttackRange = 20,
            //    SpaceSet = 3,
            //    ObjID = new ObjectID(ObjectID.ObjectType.MySoldier),
            //    MoveSpeed = 60
            //};
            // TODO 物理信息中一部分来自于数据
            member.MaxSpeed                = 10;
            member.RotateSpeed             = 10;
            member.transform.localPosition = new Vector3((i % 3) * 2 + x, 0, i / 3 * 2 + y);
            member.name     = "item" + i;
            member.Diameter = (i) % 5 + 1;
            //member.Name = "member" + i;
            member.X = x;
            member.Y = y;
            //member.IsTaunt = random.Next(1) > 0;

            // 随机给方向
            member.Direction = new Vector3(random.Next(1, 100), 0, random.Next(1, 100));

            var fightData = member.AllData.SelectWeightData;
            fightData = new SelectWeightData();
            // 选择目标数据
            fightData.AirWeight     = -1;
            fightData.BuildWeight   = 100;
            fightData.SurfaceWeight = 100;

            fightData.HumanWeight = 10;
            fightData.OrcWeight   = 10;
            fightData.OmnicWeight = 10;
            //member.TankWeight = 10;
            //member.LVWeight = 10;
            //member.CannonWeight = 10;
            //member.AirCraftWeight = 10;
            //member.SoldierWeight = 10;

            fightData.HideWeight  = -1;
            fightData.TauntWeight = 1000;

            fightData.HealthMaxWeight = 0;
            fightData.HealthMinWeight = 10;
            //member.AngleWeight = 10;
            fightData.DistanceMaxWeight = 0;
            fightData.DistanceMinWeight = 10;

            member.AllData.MemberData.Accuracy    = 0.9f;
            member.AllData.MemberData.SpreadRange = 10;

            //memberData.MultiAimMax = 10;
            MemberList.Add(member);
            if (i == 0)
            {
                _leader = member;
            }
        }
    }
Exemplo n.º 34
0
        private async Task SetContentAsync(DataPackage content)
        {
            var data          = content?.GetView();
            var targetList    = new TargetList();
            var targetStrings = new List <string>();

            bool CheckFormat(string format, out uint id)
            {
                if (data?.Contains(format) ?? false)
                {
                    id = (uint)targetStrings.Count;
                    targetStrings.Add(format);
                    return(true);
                }
                id = 0;
                return(false);
            }

            async void SetDataNative(Clipboard clipboard, SelectionData nativeData, uint info)
            {
                var format = targetStrings[(int)info];

                var uris = new List <string>();

                // Cannot use switch here, these strings are not constants!!!
                if (format == StandardDataFormats.Text)
                {
                    nativeData.Text = await data.GetTextAsync();
                }
                else if (format == StandardDataFormats.Bitmap)
                {
                    var streamRef = await data.GetBitmapAsync();

                    var uwpStream = await streamRef.OpenReadAsync();

                    var stream = uwpStream.AsStreamForRead();
                    nativeData.SetPixbuf(new Pixbuf(stream));
                }
                else if (format == StandardDataFormats.Html)
                {
                    var htmlString = await data.GetHtmlFormatAsync();

                    nativeData.Set(HtmlContent, 8, Encoding.UTF8.GetBytes(htmlString));
                }
                else if (format == StandardDataFormats.Rtf)
                {
                    var rtfString = await data.GetRtfAsync();

                    nativeData.Set(RtfContent, 8, Encoding.UTF8.GetBytes(rtfString));
                }
                else if (format == StandardDataFormats.StorageItems)
                {
                    var items = await data.GetStorageItemsAsync();

                    var builder = new StringBuilder();

                    builder.AppendLine("copy");
                    foreach (var item in items)
                    {
                        var path = item.Path;
                        builder.AppendLine(FileUriHelper.UrlEncode(path));
                    }

                    nativeData.Set(GnomeCopiedFilesContent, 8, Encoding.UTF8.GetBytes(builder.ToString().Trim()));
                }
                else if (format == StandardDataFormats.ApplicationLink)
                {
                    uris.Add((await data.GetApplicationLinkAsync()).ToString());
                }
                else if (format == StandardDataFormats.WebLink)
                {
                    uris.Add((await data.GetWebLinkAsync()).ToString());
                }
                else if (format == StandardDataFormats.Uri)
                {
                    uris.Add((await data.GetUriAsync()).ToString());
                }

                if (uris.Count != 0)
                {
                    nativeData.SetUris(uris.ToArray());
                }
            }

            uint id;

            if (CheckFormat(StandardDataFormats.Text, out id))
            {
                targetList.AddTextTargets(id);
            }
            if (CheckFormat(StandardDataFormats.Bitmap, out id))
            {
                targetList.AddImageTargets(id, true);
            }
            if (CheckFormat(StandardDataFormats.Html, out id))
            {
                targetList.Add(HtmlContent, 0, id);
            }
            if (CheckFormat(StandardDataFormats.Rtf, out id))
            {
                targetList.Add(RtfContent, 0, id);
            }
            if (CheckFormat(StandardDataFormats.StorageItems, out id))
            {
                targetList.Add(GnomeCopiedFilesContent, 0, id);
            }
            if (CheckFormat(StandardDataFormats.ApplicationLink, out id))
            {
                targetList.AddUriTargets(id);
            }
            if (CheckFormat(StandardDataFormats.WebLink, out id))
            {
                targetList.AddUriTargets(id);
            }
            if (CheckFormat(StandardDataFormats.Uri, out id))
            {
                targetList.AddUriTargets(id);
            }

            _clipboard.SetWithData((TargetEntry [])targetList, SetDataNative, (clipboard) => { });
        }
Exemplo n.º 35
0
        public override void FindTargets(ref Dictionary <string, int> available)
        {
            if (!IsEnabled())
            {
                return;
            }

            if (TargetList.Count >= GetMaximumTargets())
            {
                if (PotentialTargetList.Count > 0)
                {
                    m_lastInvalidTargetReason = "Maximum targets reached.  Add more upgrades!";
                }

                return;
            }

            DateTime start = DateTime.Now;

            using (Lock.AcquireExclusiveUsing())
            {
                if (m_constructionBlock.IsUserDefinedLimitReached())
                {
                    m_lastInvalidTargetReason = "User defined maximum nanite limit reached";
                    return;
                }

                //foreach (NaniteMiningItem item in PotentialTargetList)
                for (int r = PotentialTargetList.Count - 1; r >= 0; r--)
                {
                    var item = (NaniteMiningItem)PotentialTargetList[r];
                    if (TargetList.Contains(item))
                    {
                        continue;
                    }

                    if (m_globalPositionList.Contains(item.Position))
                    {
                        m_lastInvalidTargetReason = "Another factory has this voxel as a target";
                        continue;
                    }

                    var  blockList = NaniteConstructionManager.GetConstructionBlocks((IMyCubeGrid)m_constructionBlock.ConstructionBlock.CubeGrid);
                    bool found     = false;
                    foreach (var block in blockList)
                    {
                        // This can be sped up if necessary by indexing items by position
                        if (block.GetTarget <NaniteMiningTargets>().TargetList.FirstOrDefault(x => ((NaniteMiningItem)x).Position == item.Position) != null)
                        {
                            found = true;
                            break;
                        }
                    }

                    if (found)
                    {
                        m_lastInvalidTargetReason = "Another factory has this voxel as a target";
                        continue;
                    }

                    if (!NaniteMining.CheckVoxelContent(item.VoxelId, item.Position))
                    {
                        continue;
                    }

                    if (Vector3D.DistanceSquared(m_constructionBlock.ConstructionBlock.GetPosition(), item.Position) < m_maxDistance * m_maxDistance &&
                        NaniteConstructionPower.HasRequiredPowerForNewTarget((IMyFunctionalBlock)m_constructionBlock.ConstructionBlock, this))
                    {
                        Logging.Instance.WriteLine(string.Format("ADDING Mining Target: conid={0} pos={1} type={2}", m_constructionBlock.ConstructionBlock.EntityId, item.Position, MyDefinitionManager.Static.GetVoxelMaterialDefinition(item.VoxelMaterial).MinedOre));

                        //PotentialTargetList.Remove(item);
                        TargetList.Add(item);
                        m_globalPositionList.Add(item.Position);
                        if (TargetList.Count >= GetMaximumTargets())
                        {
                            break;
                        }
                    }
                }
            }

            //Logging.Instance.WriteLine(string.Format("FindTargets took {0}ms", (DateTime.Now - start).TotalMilliseconds));
        }
Exemplo n.º 36
0
        private IEnumerator Detonate()
        {
            if (this.debugLevel > DEBUG_LEVELS.Off)
            {
                string msg = "Detonating...";
                Debug.Log(string.Format("Detonator ({0}): {1}", this.name, msg));
            }

            // Wait for next frame to begin to be sure targets have been propegated
            // This also makes this loop easier to manage.
            yield return new WaitForFixedUpdate();  // Because of physics...matters?

            // START EVENT
            if (this.OnDetonatingDelegates != null) this.OnDetonatingDelegates();

            // Keep track of targets which have already been processed so they 
            //      aren't hit twice
            var processedTargetList = new TargetList();

            this.range = Vector3.zero;

            float timer = 0;
            float progress = 0;  // Normalized mount processed 0-1

            // The timer can exit the loop if used 
            while (true)
            {
                // UPDATE EVENT
                if (this.OnDetonatingUpdateDelegates != null)
                    this.OnDetonatingUpdateDelegates(progress);

                // Exit?
                if (timer >= this.durration) break;
                timer += Time.deltaTime;

                progress = timer / this.durration;

                this.range = this.maxRange * progress;

                // Build a list of targets in range which have NOT been processed yet.
                var newTargets = new TargetList();
                foreach (Target target in this.targets)
                    if (!processedTargetList.Contains(target))
                        newTargets.Add(target);

                if (newTargets.Count > 0)
                {
                    if (this.debugLevel > DEBUG_LEVELS.Off)
                    {
                        string msg = string.Format("Detonation hitting targets: {0}", this.targets);
                        Debug.Log(string.Format("Detonator ({0}): {1}", this.name, msg));
                    }

                    foreach (Target target in newTargets)
                    {
                        target.targetable.OnHit
                        (
                            this.effectsOnTarget,
                            target,
                            this.perimeter.collider
                        );

                        processedTargetList.Add(target);
                    }
                }

                yield return new WaitForFixedUpdate();  // Because of physics...matters?
            }

            // Prevent being run more than once in a frame where it has already 
            //   been destroyed.
            if (!this.gameObject.activeInHierarchy)
                yield break;  // Same as return

            PathologicalGames.InstanceManager.Despawn(this.transform);
        }
Exemplo n.º 37
0
        /*
        ** Name: getTargets
        **
        ** Description:
        **	Parses a target list and returns an array of host/port pairs.
        **
        **	    (<host>:<port>[,<port>][;<host>:port[,port]])
        **
        ** Input:
        **	targetList
        **
        ** Output:
        **	None.
        **
        ** Returns:
        **	TargetList    ArrayList of host/port pairs.
        **
        ** History:
        **	12-May-09 (thoda04)
        **	    Created.
        */
        private TargetList getTargets(String targetListString)
        {
            TargetList targetList = new TargetList();
            string     defaultPorts = "II7";

            // Before we start, strip any leading and trailing parentheses,
            // get the host names inside the list,
            // and save the default ports after the host list.
            targetListString =
                getTargetListString(targetListString, ref defaultPorts);

            //
            // First, extract the semi-colon separated host/port targets.
            //
            String[] targets = parseList(targetListString, ';');

            //
            // Next, extract host and port list from each target.
            //
            for (int i = 0; i < targets.Length; i++)
            {
                String   host  = getHost(targets[i]);
                String[] ports = getPort(targets[i], defaultPorts);

                for (int j = 0; j < ports.Length; j++)
                {
                    targetList.Add(host, ports[j]);
                }
            }

            return( targetList );
        }