예제 #1
0
 private static void FarmMenu_FarmPressed(object sender, BoolEventArgs e)
 {
     if (!e.Value)
     {
         foreach (var unit in _oldSelection)
         {
             FarmUnit farmer;
             if (FarmUnits.TryGetValue(unit, out farmer))
             {
                 farmer.RemoveEffects();
             }
         }
         _oldSelection.Clear();
     }
     _farmPressed = e.Value;
 }
예제 #2
0
 private static void FarmMenu_ActiveEffectChanged(object sender, BoolEventArgs e)
 {
     if (e.Value)
     {
         var list = FarmUnits.Where(x => _oldSelection.Contains(x.Key)).Select(x => x.Value).ToList();
         foreach (var farmUnit in list)
         {
             farmUnit.AddFarmActiveEffect();
         }
         foreach (var autoFarmUnit in AutoFarmUnits)
         {
             autoFarmUnit.AddFarmActiveEffect();
         }
     }
     else
     {
         foreach (var source in FarmUnits.Values.Where(x => x.IsFarmActiveEffectActive))
         {
             source.RemoveFarmActiveEffect();
         }
     }
 }
예제 #3
0
 private static void OnRangeEffectChanged(BoolEventArgs e)
 {
     _isRangeEffectActive = e.Value;
     RangeEffectChanged?.Invoke(null, e);
 }
예제 #4
0
 private static void OnFarmPressed(BoolEventArgs e)
 {
     FarmPressed?.Invoke(null, e);
 }
예제 #5
0
 private static void OnAutoFarmChanged(BoolEventArgs e)
 {
     AutoFarmChanged?.Invoke(null, e);
 }
예제 #6
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);
                }
            }
        }