Exemplo n.º 1
0
        protected virtual void Dispose(bool disposing)
        {
            if (Disposed)
            {
                return;
            }

            if (disposing)
            {
                ModifierMonitor.Dispose();
                UnitMonitor.Dispose();
                ParticleMonitor.Dispose();

                SpiritBreakerCharge.Dispose();

                Range.Dispose();
                TrueSightVision.Dispose();
                //VisibleByEnemy.Dispose();
                TowerHelper.Dispose();
                Additional.Dispose();
                LinkenShow.Dispose();
                //IllusionShow.Dispose();

                Verification.Dispose();

                NetworthPanel.Dispose();
                EnemyOverlay.Dispose();
                AllyOverlay.Dispose();

                MenuConfig.Dispose();
            }

            Disposed = true;
        }
Exemplo n.º 2
0
    private void Start()
    {
        loweredHeight = rectTransform.localPosition.y;
        raisedHeight  = rectTransform.localPosition.y + 55;
        heisterList.AddRange(FindObjectsOfType <HeisterInfo>());
        //Creates a Monitor object for each heister and fills in the correct information
        for (int i = 0; i < heisterList.Count; i++)
        {
            HeisterInfo h = heisterList[i];

            UnitMonitor newMonitor = Instantiate(UnitMonitor, transform).GetComponent <UnitMonitor>();
            h.unit.unitMonitor            = newMonitor;
            newMonitor.unit               = h.unit;
            newMonitor.className.text     = h.className;
            newMonitor.characterName.text = h.characterName;
            newMonitor.hp.text            = h.unit.hp.ToString();
            newMonitor.sprite.sprite      = h.unit.GetComponent <SpriteRenderer>().sprite;
            //If there are an odd amount of heisters
            if ((float)heisterList.Count % 2 != 0)
            {
                newMonitor.GetComponent <RectTransform>().localPosition = new Vector3(newMonitor.GetComponent <RectTransform>().rect.width *(i + 1 - Mathf.Ceil((float)heisterList.Count / 2)),
                                                                                      newMonitor.GetComponent <RectTransform>().localPosition.y,
                                                                                      newMonitor.GetComponent <RectTransform>().localPosition.z);
            }
            //If there are an even amount of heisters
            else
            {
                newMonitor.GetComponent <RectTransform>().localPosition = new Vector3((newMonitor.GetComponent <RectTransform>().rect.width *i) -
                                                                                      ((heisterList.Count - 1) * newMonitor.GetComponent <RectTransform>().rect.width / 2),
                                                                                      newMonitor.GetComponent <RectTransform>().localPosition.y,
                                                                                      newMonitor.GetComponent <RectTransform>().localPosition.z);
            }
        }
    }
Exemplo n.º 3
0
        public void TestMethodVratitZaklNastaveni9()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                //var data = await m.ReadZaklNastaveni();
                //var task = m.ReadZaklNastaveni();

                //PrintByteArray(task.Result);

                byte minOk;
                byte minNg;
                byte adrLocal;
                byte verzeSw1;
                byte verzeSw2;
                byte verzeSw3;

                Assert.IsTrue(m.ReadZaklNastaveni(out minOk, out minNg, out adrLocal, out verzeSw1, out verzeSw2, out verzeSw3));

                Console.WriteLine($"minOK={minOk} minNG={minNg} verzeSw1={verzeSw1}");

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodVratitZaklNastaveni9 - OK");
        }
Exemplo n.º 4
0
        public void TestMethodVratitStavCitacu96()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                //var data = await m.ReadZaklNastaveni();
                //var task = m.ReadZaklNastaveni();

                //PrintByteArray(task.Result);

                int ok;
                int ng;

                Console.WriteLine($"TestMethodVratitZaklNastaveni9 - OK");

                Assert.IsTrue(m.ReadStavCitacu(out ok, out ng));

                Console.WriteLine($"OK={ok} NG={ng}");

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodVratitStavCitacu96 - OK");
        }
Exemplo n.º 5
0
        public void TestMethodZapsatCitace4()
        {
            Console.WriteLine($"TestMethodZapsatCitace4 - start");
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                try
                {
                    serialPort.Open();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    //throw;
                }

                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                var res = m.SetCitace(99, 33);

                Assert.IsTrue(res);

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodZapsatCitace4 - OK");
        }
Exemplo n.º 6
0
        public UCPointMoveCutPara(PointMoveCutModel model) : this()
        {
            this.Model = this.mvvmContext1.GetViewModel <PointMoveCutModel>();
            CopyUtil.CopyModel(this.Model, model ?? DefaultParaHelper.GetDefaultPointMoveModel());
            this.InitializeBindings();
            var monitor = new UnitMonitor(this, () => this.Model.RaisePropertiesChanged());

            monitor.Listen();
        }
Exemplo n.º 7
0
        public UCLayerCoolingPara(LayerCoolingModel layerCooling) : this()
        {
            this.Model = this.mvvmContext1.GetViewModel <LayerCoolingModel>();
            CopyUtil.CopyModel(this.Model, layerCooling ?? DefaultParaHelper.GetDefaultLayerCoolingModel());
            this.InitializeBindings();
            var monitor = new UnitMonitor(this, () => this.Model.RaisePropertiesChanged());

            monitor.Listen();
        }
Exemplo n.º 8
0
        public FrmLayerConfig(LayerConfigModel layerConfig) : this()
        {
            this.Model = mvvmContext1.GetViewModel <LayerConfigModel>();
            CopyUtil.CopyModel(this.Model, layerConfig ?? DefaultParaHelper.GetDefaultLayerConfigModel());
            this.InitializeBindings();
            this.InitializePointMoveCutParaPage();
            var monitor = new UnitMonitor(this.tPageLayerGlobal, () => this.Model.RaisePropertiesChanged());

            monitor.Listen();
        }
Exemplo n.º 9
0
        public UCLayerEvaporatePara(LayerEvaporateModel layerEvaporate) : this()
        {
            this.Model = this.mvvmContext1.GetViewModel <LayerEvaporateModel>();
            CopyUtil.CopyModel(this.Model, layerEvaporate ?? DefaultParaHelper.GetDefaultLayerEvaporateModel());
            this.InitializeBindings();
            this.InitializeCurve();
            var monitor = new UnitMonitor(this, () => this.Model.RaisePropertiesChanged());

            monitor.Listen();
            UnitObserverFacade.Instance.SpeedUnitObserver.UnitChanged += x => this.InitializeCurve();
        }
Exemplo n.º 10
0
        public UCMannual()
        {
            InitializeComponent();
            InitializeBindings();

            this.Load += (sender, e) =>
            {
                var viewModel = MVVMContext.FromControl(this).GetViewModel <ManualViewModel>();
                var monitor   = new UnitMonitor(this, () => viewModel.RaisePropertiesChanged());
                monitor.Listen();
            };
        }
Exemplo n.º 11
0
        public FrmLayerConfig(LayerConfigModel layerConfig, List <int> layers) : this()
        {
            this.Model  = mvvmContext1.GetViewModel <LayerConfigModel>();
            this.layers = layers;
            CopyUtil.CopyModel(this.Model, layerConfig ?? DefaultParaHelper.GetDefaultLayerConfigModel());
            this.InitializeBindings();
            this.InitializeTabPages(layers);
            this.UcLayer_OnPathRecoolingChanged(false, "冷却参数");
            this.UcLayer_OnEvaporationFilmChanged(false, "蒸发参数");
            var monitor = new UnitMonitor(this.tPageLayerGlobal, () => this.Model.RaisePropertiesChanged());

            monitor.Listen();
        }
Exemplo n.º 12
0
        static void TestReadPort()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();

                //serialPort.DataReceived += SerialPort_DataReceived;
                serialPort.ErrorReceived += SerialPort_ErrorReceived;


                Console.WriteLine($"Port is open: {serialPort.IsOpen}");

                if (!serialPort.IsOpen)
                {
                    Console.WriteLine($"Port not open - exit");
                    return;
                }

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                //m.Set6f();

                //m.SetHandshake(255, 1);

                //Assert.IsTrue(res);

                Thread.Sleep(500);

                int c = 0;
                int ok;
                int ng;

                while (c++ < 10)
                {
                    var res = m.ReadStavCitacu(out ok, out ng);

                    Console.WriteLine($"res = {res}  OK = {ok}  NG = {ng}");

                    Thread.Sleep(300);
                }


                //MessageBox.Show("Hello, world!");

                serialPort.Close();
            }
            Console.WriteLine($"TestMethodZapsatNacistCitace - OK");
            Console.ReadLine();
        }
Exemplo n.º 13
0
        public void Activate()
        {
            this.owner = EntityManager9.Owner;

            this.particleMonitor   = new ParticleMonitor(this.EvadableAbilities);
            this.phaseMonitor      = new PhaseMonitor(this.EvadableAbilities);
            this.projectileMonitor = new ProjectileMonitor(this.EvadableAbilities);
            this.unitMonitor       = new UnitMonitor(this.EvadableAbilities);
            this.modifierMonitor   = new ModifierMonitor(this.menu, this.EvadableAbilities);
            this.attackMonitor     = new AttackMonitor(this.EvadableAbilities);

            EntityManager9.AbilityAdded   += this.OnAbilityAdded;
            EntityManager9.AbilityRemoved += this.OnAbilityRemoved;

            this.menu.Hotkeys.ProactiveEvade.ValueChange += this.ProactiveEvadeOnValueChange;

            this.assemblyEventManager.OnAssemblyLoad += this.OnAssemblyLoad;
        }
Exemplo n.º 14
0
        public UCMachineControl()
        {
            InitializeComponent();
            InitializeBindings();

            this.btnPause.Enabled           = false;
            this.btnBreakPointStart.Enabled = false;
            this.btnLocate.Enabled          = false;
            this.btnForward.Enabled         = false;
            this.btnBackward.Enabled        = false;

            this.Load += (sender, e) =>
            {
                var viewModel = MVVMContext.FromControl(this).GetViewModel <MachineViewModel>();
                var monitor   = new UnitMonitor(this, () => viewModel.RaisePropertiesChanged());
                monitor.Listen();
            };
        }
Exemplo n.º 15
0
        public void TestMethodReset7()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                Assert.IsTrue(m.Reset());

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodReset7 - OK");
        }
Exemplo n.º 16
0
        public void TestMethod1()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                m.Set6f();

                m.SetHandshake(0, 1);

                //Assert.IsTrue(res);

                Thread.Sleep(500);

                int c = 0;
                int ok;
                int ng;

                while (c++ < 100)
                {
                    var res = m.ReadStavCitacu(out ok, out ng);

                    if (res)
                    {
                        m.UnitStatus.Ok = ok;
                        m.UnitStatus.Ng = ng;
                    }

                    Console.WriteLine($"OK = {ok}  NG = {ng}");

                    Thread.Sleep(300);
                }


                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");
            }
            Console.WriteLine($"TestMethodZapsatNacistCitace - OK");
        }
Exemplo n.º 17
0
        static EntityManager9()
        {
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(x => !x.IsAbstract && x.IsClass))
            {
                if (typeof(Ability9).IsAssignableFrom(type))
                {
                    foreach (var attribute in type.GetCustomAttributes <AbilityIdAttribute>())
                    {
                        abilityTypes.Add(attribute.AbilityId, type);
                    }
                }
                else if (typeof(Hero9).IsAssignableFrom(type))
                {
                    foreach (var attribute in type.GetCustomAttributes <HeroIdAttribute>())
                    {
                        heroTypes.Add(attribute.HeroId, type);
                    }
                }
                else if (typeof(Unit9).IsAssignableFrom(type))
                {
                    foreach (var attribute in type.GetCustomAttributes <UnitNameAttribute>())
                    {
                        unitTypes.Add(attribute.Name, type);
                    }
                }
            }

            Owner                = new Owner();
            UnitMonitor          = new UnitMonitor();
            AbilityMonitor       = new AbilityMonitor();
            delayedEntityHandler = UpdateManager.CreateIngameUpdate(1000, false, DelayedEntitiesOnUpdate);

            AddCurrentUnits();
            AddCurrentAbilities();

            EntityManager.EntityAdded   += OnEntityAdded;
            EntityManager.EntityRemoved += OnEntityRemoved;

            UpdateManager.BeginInvoke(2000, DemoModeCheck);
            UpdateManager.BeginInvoke(5000, LoadCheck);
        }
Exemplo n.º 18
0
        static EntityManager9()
        {
            foreach (var type in Assembly.GetExecutingAssembly().GetTypes().Where(x => !x.IsAbstract && x.IsClass))
            {
                if (typeof(Ability9).IsAssignableFrom(type))
                {
                    foreach (var attribute in type.GetCustomAttributes <AbilityIdAttribute>())
                    {
                        abilityTypes.Add(attribute.AbilityId, type);
                    }
                }
                else if (typeof(Hero9).IsAssignableFrom(type))
                {
                    foreach (var attribute in type.GetCustomAttributes <HeroIdAttribute>())
                    {
                        heroTypes.Add(attribute.HeroId, type);
                    }
                }
                else if (typeof(Unit9).IsAssignableFrom(type))
                {
                    foreach (var attribute in type.GetCustomAttributes <UnitNameAttribute>())
                    {
                        unitTypes.Add(attribute.Name, type);
                    }
                }
            }

            Owner                = new Owner();
            UnitMonitor          = new UnitMonitor();
            AbilityMonitor       = new AbilityMonitor();
            delayedEntityHandler = UpdateManager.Subscribe(DelayedEntitiesOnUpdate, 1000, false);

            AddCurrentUnits();
            AddCurrentAbilities();

            ObjectManager.OnAddEntity    += OnAddEntity;
            ObjectManager.OnRemoveEntity += OnRemoveEntity;

            UpdateManager.BeginInvoke(DemoModeCheck, 2000);
            UpdateManager.BeginInvoke(LoadCheck, 5000);
        }
Exemplo n.º 19
0
        //[TestMethod]
        public void TestMethodNastavJas()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                var res = m.SetJasLcd(10);

                Assert.IsTrue(res);

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodVratitZaklNastaveni9 - OK");
        }
Exemplo n.º 20
0
        public Common()
        {
            MenuConfig = new MenuConfig();

            MessageCreator = new MessageCreator(this);
            SoundHelper    = new SoundHelper(this);

            AllyOverlay   = new AllyOverlay(this);
            EnemyOverlay  = new EnemyOverlay(this);
            NetworthPanel = new NetworthPanel(this);

            Verification = new Verification(this);

            SpiritBreakerCharge       = new SpiritBreakerCharge(this);
            MiranaArrow               = new MiranaArrow(this);
            InvokerEMP                = new InvokerEMP(this);
            InvokerSunStrike          = new InvokerSunStrike(this);
            KunkkaTorrent             = new KunkkaTorrent(this);
            LeshracSplitEarth         = new LeshracSplitEarth(this);
            LifeStealerInfest         = new LifeStealerInfest(this);
            LinaLightStrikeArray      = new LinaLightStrikeArray(this);
            PhantomAssassinBlur       = new PhantomAssassinBlur(this);
            PudgeHook                 = new PudgeHook(this);
            AncientApparitionIceBlast = new AncientApparitionIceBlast(this);
            BloodseekerRupture        = new BloodseekerRupture(this);
            WindrunnerPowershot       = new WindrunnerPowershot(this);

            //IllusionShow = new IllusionShow(this);
            LinkenShow  = new LinkenShow(this);
            Additional  = new Additional(this);
            TowerHelper = new TowerHelper(this);
            //VisibleByEnemy = new VisibleByEnemy(this);
            TrueSightVision = new TrueSightVision(this);
            Range           = new Range(this);

            ParticleMonitor = new ParticleMonitor(this);
            UnitMonitor     = new UnitMonitor(this);
            ModifierMonitor = new ModifierMonitor(this);
        }
Exemplo n.º 21
0
        public void TestMethodNastavCileSmen18()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");


                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                var res = m.SetCileSmen('A', 100, 50, 10);

                Assert.IsTrue(res);

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodNastavCileSmen18 - OK");
        }
Exemplo n.º 22
0
        public void TestMethodZapsatNacistCitace()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                short okVal = 123;
                short ngVal = 54;

                var res = m.SetCitace(okVal, ngVal);

                Assert.IsTrue(res);

                int ok;
                int ng;

                Thread.Sleep(500);

                Assert.IsTrue(m.ReadStavCitacu(out ok, out ng));

                Console.WriteLine($"OK={ok} NG={ng}");

                Assert.AreEqual(ok, okVal);
                Assert.AreEqual(ng, ngVal);

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodZapsatNacistCitace - OK");
        }
Exemplo n.º 23
0
        public void TestMethodNastavCileSmen()
        {
            using (var serialPort = new SerialPortWraper(_portCfg))
            {
                serialPort.Open();
                Assert.IsTrue(serialPort.IsOpen, $"port {_portCfg.Port} nelze otevřít");

                UnitMonitor m = new UnitMonitor(100);
                m.SerialPort = serialPort;

                short okVal = 123;
                short ngVal = 54;

                var res = m.SetDefektivita('A', 1000, 1001, 1002);

                Assert.IsTrue(res);

                serialPort.Close();
                Assert.IsFalse(serialPort.IsOpen, $"port {_portCfg.Port} nelze uzařít");

                Thread.Sleep(500);
            }
            Console.WriteLine($"TestMethodZapsatNacistCitace - OK");
        }
Exemplo n.º 24
0
        internal static Unit9 AddUnit(Unit unit)
        {
            try
            {
                if (ignoredUnits.Contains(unit.Name))
                {
                    return(null);
                }

                var newUnit = GetUnitFast(unit.Handle);
                if (newUnit != null)
                {
                    return(newUnit);
                }

                if (unit is Hero hero)
                {
                    if (hero.HeroId == HeroId.npc_dota_hero_base || hero.Inventory == null)
                    {
                        DelayedAdd(hero);
                        return(null);
                    }

                    if (heroTypes.TryGetValue(hero.HeroId, out var type))
                    {
                        newUnit = (Hero9)Activator.CreateInstance(type, hero);
                    }
                    else
                    {
                        newUnit = new Hero9(hero);
                    }

                    if (!newUnit.IsIllusion && newUnit.Handle == EntityManager.LocalHero.Handle)
                    {
                        Owner.SetHero(newUnit);
                    }
                }
                else
                {
                    if (unitTypes.TryGetValue(unit.Name, out var type))
                    {
                        newUnit = (Unit9)Activator.CreateInstance(type, unit);
                    }
                    else
                    {
                        newUnit = new Unit9(unit);
                    }
                }

                SaveUnit(newUnit);

                if (newUnit.BaseOwner is Unit owner && owner.IsValid)
                {
                    newUnit.Owner = AddUnit(owner);
                }

                UnitMonitor.CheckModifiers(newUnit);
                unitAdded?.Invoke(newUnit);

                return(newUnit);
            }
            catch (Exception e)
            {
                Logger.Error(e, unit);
                return(null);
            }
        }
Exemplo n.º 25
0
    void FixedUpdate()
    {
        if (state != State.Dead)           // Unit alive

        {
            if (building)
            {
                if (currentConstruction)
                {
                    Vector3 dist = this.transform.position - currentConstruction.transform.position;
                    //print (dist.magnitude);
                    if (dist.magnitude < 2)
                    {
                        currentConstruction.GetComponent <build> ().percentage += 1;
                        currentConstruction.GetComponent <build> ().t           = team;
                    }
                    else
                    {
                        //print ("GO");
                        MoveUnit(transform.position, currentConstruction.transform.position);
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.P) && !patrolPointSelection)
            {
                patrolPointSelection = true;
                print("Set patrol points");
                patroling        = false;
                patrolPointCount = 0;
            }

            if (TargetReached && !attacking && state != State.Idle)
            {
                changeState(State.Idle);
            }
            if (state != State.Idle && attacking && target != null)
            {
                transform.LookAt(target.transform);                 //Makes unit look at current attack target
            }

            if (health <= 0)              //Checks to see if target is dead
            {
                changeState(State.Dead);
                audio.PlayOneShot(death);
            }

            CheckState();             //Checks the state of the target
            if (state != State.Attacking)
            {
                CheckForEnemies();
            }
            int targetHealth = 0;

            //Gets the health of the target
            if (target != null)
            {
                if (targetType == TargetType.Unit)
                {
                    targetHealth = target.gameObject.GetComponent <Unit> ().health;
                }
                else if (targetType == TargetType.Building)
                {
                    targetHealth = target.gameObject.GetComponent <DestructableBuilding> ().health;
                }
            }
            //If target is out of range or dead remove it as target
            if (state != State.Idle && target != null && !instructedAttack && Vector3.Distance(target.transform.position, transform.position) >= ((float)attackRange) || targetHealth <= 0)
            {
                target    = null;
                attacking = false;
                if (state != State.Moving)
                {
                    changeState(State.Idle);
                }
            }

            //Gathering
            if ((MAX_LOAD == currentLoad) || (collectGoods && gathering && currentResource == null))               // If the unit has reached its max load return to base or If the resource is destroyed and the grunt has not filled its capacity
            {
                collectGoods    = false;
                collectedAmount = currentLoad;
                currentLoad     = 0;
                StartCoroutine("FollowPath");
            }

            if (unitClass == Type.Grunt && collectGoods && MAX_LOAD > currentLoad && currentResource != null)              // While gathering goods increase current load
            {
                currentLoad += gatherSpeed;
                Debug.Log(currentLoad);
                currentResource.GetComponent <Resource> ().ReduceAmountOfMaterial(gatherSpeed);
                collectedAmount = currentLoad;
            }

            if (Input.GetMouseButton(0) && !EventSystem.current.IsPointerOverGameObject())
            {
                // Helps the selection of troops either multiple or single troop selection
                if (!clicked)
                {
                    Vector3 cameraPosition = Camera.main.WorldToScreenPoint(transform.position);
                    cameraPosition.y = Screen.height - cameraPosition.y;
                    selected         = AICamera.selectedArea.Contains(cameraPosition);
                    GameObject aiCamera = GameObject.FindGameObjectWithTag("MainCamera");

                    if (renderer.isVisible && selected && !UnitMonitor.selectedUnits.Contains(this.gameObject) && UnitMonitor.LimitNotReached() && this.team == VarMan.Instance.pNum)
                    {
                        UnitMonitor.AddUnit(this.gameObject);
                        wasSelected = true;
                        audio.PlayOneShot(selectionConfirmation);
                    }
                    else if (!selected && wasSelected && !UnitMonitor.isShiftPressed())
                    {
                        //If either of the shift buttons are pushed then dont deselct it just add it
                        UnitMonitor.RemoveUnit(this.gameObject);
                        wasSelected   = false;
                        TargetReached = false;
                    }
                    else if (this.team != VarMan.Instance.pNum)
                    {
                        Debug.Log("Not me!");
                    }
                }
                //Create the particle effect object that shows which object is selected
                if (wasSelected && glow == null)
                {
                    glow = (GameObject)GameObject.Instantiate(glowSelection);
                    glow.transform.parent        = transform;
                    glow.transform.localPosition = new Vector3(0, 0, 0);
                    if (transform.FindChild("Health Bar"))
                    {
                        transform.FindChild("Health Bar").gameObject.renderer.enabled = true;
                        transform.FindChild("Health Bar").transform.FindChild("Bar").gameObject.renderer.enabled = true;
                    }
                }

                //If unselected remove it
                else if (renderer.isVisible && !wasSelected && glow != null)
                {
                    GameObject.Destroy(glow);
                    glow = null;
                    if (transform.FindChild("Health Bar"))
                    {
                        transform.FindChild("Health Bar").gameObject.renderer.enabled = false;
                        transform.FindChild("Health Bar").transform.FindChild("Bar").gameObject.renderer.enabled = false;
                    }
                }
            }
            //Makes the units setup a patrol point and patrol between two points
            if (Input.GetMouseButtonDown(1) && patrolPointSelection && wasSelected)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    mouseClick = hit.point;
                    if (patrolPointCount == 0)
                    {
                        patrolPointCount = 0;
                        patrolPoint1     = mouseClick;
                        audio.PlayOneShot(moveConfirmation);
                        MoveUnit(transform.position, patrolPoint1);
                        patrolPointCount++;
                    }
                    else if (patrolPointCount == 1)
                    {
                        patrolPoint2         = mouseClick;
                        patrolPointSelection = false;
                        patroling            = true;
                        patrolPointCount     = 0;
                        audio.PlayOneShot(moveConfirmation);
                    }

                    if (patroling && !patrolPointSelection)
                    {
                        Patrol(patrolPoint1, patrolPoint2);
                    }
                }
            }
            else if (Input.GetMouseButtonDown(1) && wasSelected && !patrolPointSelection)
            {
                // Detects a players right click  and moves the selected troops top that position
                path = null;
                //Stops the players movement
                StopCoroutine("FollowPath");
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                Debug.Log("click");

                if (Physics.Raycast(ray, out hit))
                {
                    TargetReached    = false;
                    mouseClick       = hit.point;
                    notOverrideable  = true;
                    instructedAttack = false;
                    Transform attackPoint = null;
                    patroling = false;
                    //If enemy unit attack
                    if ((hit.collider.gameObject.tag == "Unit" || hit.collider.gameObject.tag == "Grunt") && hit.collider.gameObject.GetComponent <Unit> ().team != this.team)
                    {
                        audio.PlayOneShot(attackConfirmation);
                        this.target      = hit.collider.gameObject;
                        targetType       = TargetType.Unit;
                        attacking        = true;
                        instructedAttack = true;
                        notOverrideable  = false;
                        print("Attack unit");
                    }

                    //If enemy building attack
                    if ((hit.collider.gameObject.tag == "Building" || hit.collider.gameObject.tag == "Home Base" || hit.collider.gameObject.tag == "School") && hit.collider.gameObject.GetComponent <DestructableBuilding> ().team != this.team)
                    {
                        audio.PlayOneShot(attackConfirmation);
                        this.target      = hit.collider.gameObject;
                        targetType       = TargetType.Building;
                        attacking        = true;
                        instructedAttack = true;
                        notOverrideable  = false;
                        attackPoint      = hit.transform.Find("AttackPoint");
                        print("Attack Building");
                    }

                    //If resource and grunt start gathering

                    if (hit.collider.gameObject.tag == "Scafold" && unitClass.Equals(Type.Grunt))
                    {
                        //print ("GO BUILD");
                        var buildPoint = hit.transform.FindChild("BuildPoint");
                        if (buildPoint)
                        {
                            //print ("SCAFFOLD SET");
                            building = true;
                            print(buildPoint.localPosition);
                            MoveUnit(transform.position, buildPoint.position);
                            currentConstruction = buildPoint.gameObject;
                        }
                    }
                    else if (hit.collider.gameObject.tag == "Resource" && unitClass.Equals(Type.Grunt))
                    {
                        audio.PlayOneShot(gatherConfirmation);
                        currentResource = hit.transform.gameObject;

                        if (resourceType != Resource.ResourceType.Nothing)
                        {
                            collectedAmount = 0;
                            currentLoad     = 0;
                        }

                        resourceType = currentResource.GetComponent <Resource> ().type;
                        var gatherPoint = hit.transform.Find("GatherPoint");
                        gathering = true;
                        attacking = false;

                        if (gatherPoint)
                        {
                            collectGoods  = false;
                            returning     = false;
                            resourcePoint = gatherPoint.position;
                            MoveUnit(transform.position, gatherPoint.position);
                        }
                    }
                    else if (hit.collider.gameObject.tag == "Resource" || (hit.collider.gameObject.tag == "Home Base" && !unitClass.Equals(Type.Grunt) && hit.collider.gameObject.GetComponent <DestructableBuilding> ().team == this.team))
                    {
                        //If not grunt just stop moving
                        changeState(State.Idle);
                    }
                    else if (hit.collider.gameObject.tag == "Home Base" && unitClass.Equals(Type.Grunt) && hit.collider.gameObject.GetComponent <DestructableBuilding> ().team == this.team)
                    {
                        //Return to homebase and deposit goods
                        var returnPoint = hit.transform.Find("ReturnPoint");
                        attacking = false;

                        if (unitClass.Equals(Type.Grunt))
                        {
                            depositing = true;
                            MoveUnit(transform.position, returnPoint.position);
                        }
                    }
                    else
                    {
                        //Just move the unit
                        if (!attacking)
                        {
                            audio.PlayOneShot(moveConfirmation);
                        }
                        building     = false;
                        gathering    = false;
                        returning    = false;
                        collectGoods = false;
                        currentLoad  = 0;

                        if (targetType == TargetType.Building && attackPoint != null)
                        {
                            MoveUnit(transform.position, attackPoint.position);
                        }
                        else
                        {
                            MoveUnit(transform.position, mouseClick);
                        }
                    }
                }
            }
        }
        else
        {
            CheckState();
        }
    }