예제 #1
0
        private void OnClearPassiveRadarTargetEvent(KeyCode keyCode)
        {
            if (StatMaster.isClient)
            {
                return;
            }
            if (!Machine.Active().isSimulating)
            {
                return;
            }
            if (!gameObject.activeSelf)
            {
                return;
            }
            if (parentBlock == null)
            {
                return;
            }
            if (RadarType == RadarTypes.ActiveRadar)
            {
                return;
            }

            KeyCode key = parentBlock.GetComponent <RocketScript>().GroupFireKey.GetKey(0);

            if (key == keyCode)
            {
                ClearTarget(false);
                OnNotifyActiveRadarForNewTarget?.Invoke(key);
            }
        }
예제 #2
0
        public void SetTarget(Target tempTarget)
        {
            if (tempTarget == null)
            {
                return;
            }

            RadarTarget = tempTarget;
            //blockList.Add(tempTarget.block);

            if (StatMaster.isHosting)
            {
                SendTargetToClient();
            }

            if (receivedRayFromClient)
            {
                receivedRayFromClient = false;
            }

            if (RadarType == RadarTypes.ActiveRadar)
            {
                OnNotifyActiveRadarForNewTarget?.Invoke(parentBlock.GetComponent <RocketScript>().GroupFireKey.GetKey(0));
            }
        }
예제 #3
0
        private void Update()
        {
            if (lastSwitchState != Switch)
            {
                lastSwitchState = Switch;
                if (Switch)
                {
                    if (RadarType == RadarTypes.ActiveRadar)
                    {
                        ActivateDetectionZone();
                    }
                    else
                    {
                        OnNotifyActiveRadarForNewTarget?.Invoke(parentBlock.GetComponent <RocketScript>().GroupFireKey.GetKey(0));
                    }
                }
                else
                {
                    DeactivateDetectionZone();
                }
            }

            if (!Switch)
            {
                return;
            }
            if (StatMaster.isClient)
            {
                return;
            }
            if (canBeOverridden || RadarType == RadarTypes.PassiveRadar)
            {
                return;
            }

            if (RadarTarget != null)
            {
                if (!InRadarRange(RadarTarget))
                {
                    ClearTarget(true);
                }
            }

            if (targetList.Count > 0 && !targetList.SetEquals(lastTargetList) || RadarTarget == null)
            {
#if DEBUG
                //Debug.Log(blockList.Count));
#endif
                if (!isChoosingBlock)
                {
#if DEBUG
                    Debug.Log("choose target");
#endif
                    isChoosingBlock = true;
                    lastTargetList  = targetList;
                    if (RadarTarget == null)
                    {
                        RadarTarget = new Target();
                    }

                    ChooseTargetInTargetList(targetList);

                    void ChooseTargetInTargetList(HashSet <Target> targets)
                    {
                        foreach (var itemTarget in targets)
                        {
                            CompareTarget(itemTarget);
                        }
                        isChoosingBlock = false;

                        void CompareTarget(Target other)
                        {
                            //Debug.Log(ignoreList.Contains(other.ReturnTargetName()) + " exist");
                            //if (ignoreList.Contains(other.ReturnTargetName())) return;
                            if (CheckIfSameGroupRocket(other))
                            {
                                return;
                            }

                            RadarTarget.RefreshWarningValue();
                            other.RefreshWarningValue();

                            if (other.WarningValue > RadarTarget.WarningValue)
                            {
                                SetTarget(other);
                            }
                            else if (other.WarningValue == RadarTarget.WarningValue)
                            {
                                var distance = (other.Position - transform.position).magnitude;
                                if (distance < TargetDistance)
                                {
                                    SetTarget(other);
                                }
                            }
                        }

                        bool CheckIfSameGroupRocket(Target target)
                        {
                            if (StatMaster.isMP)
                            {
                                return(false);
                            }
                            if (target.ReturnTimedrocket() == null)
                            {
                                return(false);
                            }

                            RocketScript rs     = target.ReturnBlockBehaviour().GetComponentInAll <RocketScript>();
                            RocketScript selfRS = parentBlock.GetComponentInAll <RocketScript>();

                            if (selfRS == null)
                            {
                                return(false);
                            }
                            if (rs == null)
                            {
                                return(false);
                            }

                            if (selfRS.SPTeamKey.GetKey(0) == rs.SPTeamKey.GetKey(0))
                            {
                                return(true);
                            }

                            return(false);
                        }
                    }
                }
            }
        }
        private void Update()
        {
            if (lastSwitchState != Switch)
            {
                lastSwitchState = Switch;
                if (Switch)
                {
                    if (RadarType == RadarTypes.ActiveRadar)
                    {
                        ActivateDetectionZone();
                    }
                    else
                    {
                        OnNotifyActiveRadarForNewTarget?.Invoke(parentBlock.GetComponent <RocketScript>().GroupFireKey.GetKey(0));
                    }
                }
                else
                {
                    DeactivateDetectionZone();
                }
            }

            if (!Switch)
            {
                return;
            }
            if (StatMaster.isClient)
            {
                return;
            }
            if (canBeOverridden || RadarType == RadarTypes.PassiveRadar)
            {
                return;
            }

            //if (target != null)
            //{
            //    if (!InRadarRange(target))
            //    {
            //        ClearTarget(true);
            //    }
            //}

            if (targetList.Count > 0 && !targetList.SetEquals(lastTargetList) || target == null)
            {
#if DEBUG
                //Debug.Log(blockList.Count));
#endif
                if (!isChoosingBlock)
                {
#if DEBUG
                    Debug.Log("choose target");
#endif
                    isChoosingBlock = true;
                    lastTargetList  = targetList;
                    if (target == null)
                    {
                        target = new Target();
                    }

                    chooseTargetInTargetList(targetList);

                    void chooseTargetInTargetList(HashSet <Target> targets)
                    {
                        foreach (var itemTarget in targets)
                        {
                            ComparerTarget(itemTarget);
                        }
                        isChoosingBlock = false;

                        void ComparerTarget(Target other)
                        {
                            target.RefreshWarningValue();
                            other.RefreshWarningValue();
                            if (other.WarningValue > target.WarningValue)
                            {
                                target = other;
                                return;
                            }
                            else if (other.WarningValue == target.WarningValue)
                            {
                                var distance = (other.Position - transform.position).magnitude;

                                if (distance < TargetDistance)
                                {
                                    target = other;
                                    return;
                                }
                            }
                        }
                    }
                }
            }
        }