Ejemplo n.º 1
0
        static void Main()
        {
            FarmMenu.Initialize();

            Events.OnClose += Events_OnClose;

            FarmMenu.FarmPressed         += FarmMenu_FarmPressed;
            FarmMenu.AutoFarmChanged     += FarmMenu_AutoFarmChanged;
            FarmMenu.ActiveEffectChanged += FarmMenu_ActiveEffectChanged;
            FarmMenu.RangeEffectChanged  += FarmMenu_RangeEffectChanged;
            FarmMenu.RangeChanged        += FarmMenu_RangeChanged;
            ;
            Game.OnIngameUpdate += Game_OnIngameUpdate;
        }
Ejemplo n.º 2
0
        private static void FarmMenu_AutoFarmChanged(object sender, BoolEventArgs e)
        {
            if (!e.Value)
            {
                return;
            }

            if (!Game.IsInGame || Game.IsPaused)
            {
                return;
            }

            var player = ObjectManager.LocalPlayer;

            if (player == null)
            {
                return;
            }

            var selection = player.Selection.Where(x => x is Unit).Cast <Unit>().ToList();

            if (!selection.Any())
            {
                return;
            }

            var newOne  = false;
            var tmpList = new List <FarmUnit>();

            foreach (var unit in selection)
            {
                if (!unit.IsAlive || !unit.IsControllable)
                {
                    continue;
                }

                FarmUnit farmer;
                if (!FarmUnits.TryGetValue(unit, out farmer))
                {
                    farmer = CreateFarmer(unit);
                    FarmUnits.Add(unit, farmer);
                    newOne = true;
                }
                if (!newOne && !AutoFarmUnits.Contains(farmer))
                {
                    newOne = true;
                }
                tmpList.Add(farmer);
            }
            // if one new unit is in selection then let all autofarm, else toggle them off
            if (newOne)
            {
                foreach (var farmUnit in tmpList)
                {
                    if (!AutoFarmUnits.Contains(farmUnit))
                    {
                        AutoFarmUnits.Add(farmUnit);
                        farmUnit.AddEffects();

                        FarmMenu.AddAutoFarmEntry(farmUnit.ControlledUnit);
                    }
                }
            }
            else
            {
                foreach (var farmUnit in tmpList)
                {
                    AutoFarmUnits.Remove(farmUnit);
                    farmUnit.RemoveEffects();
                    FarmMenu.RemoveAutoFarmEntry(farmUnit.ControlledUnit);
                }
            }
        }