private void SkillsBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ViewModel)this.DataContext).SelectedBot != null && skillsBox.SelectedIndex != -1)
            {
                NukeRulesListBox.SelectedIndex = -1;
                var newNuke = new NukeRule(((ViewModel)this.DataContext).SelectedBot.PlayerData)
                {
                    Enabled  = true,
                    NukeType = (NukeType)((ViewModel)this.DataContext).SelectedBot.Engine.NukeHandler.NukeTypeToAdd
                };

                int index  = skillsBox.SelectedIndex;
                int nukeId = ((MultiThreadObservableCollection <dynamic>)skillsBox.ItemsSource)[index].Id;
                newNuke.NukeId = nukeId;
                ((ViewModel)this.DataContext).SelectedBot.Engine.NukeHandler.SelectedNuke = newNuke;
            }
        }
        private void NukeRulesListBox_Drop(object sender, DragEventArgs e)
        {
            NukeRule droppedData = e.Data.GetData(typeof(NukeRule)) as NukeRule;
            NukeRule target      = ((ListBoxItem)(sender)).DataContext as NukeRule;

            int removedIdx = NukeRulesListBox.Items.IndexOf(droppedData);
            int targetIdx  = NukeRulesListBox.Items.IndexOf(target);

            if (removedIdx < targetIdx)
            {
                MainWindow.ViewModel.SelectedBot.Engine.NukeHandler.NukesToUse.Insert(targetIdx + 1, droppedData);
                MainWindow.ViewModel.SelectedBot.Engine.NukeHandler.NukesToUse.RemoveAt(removedIdx);
            }
            else
            {
                int remIdx = removedIdx + 1;
                if (MainWindow.ViewModel.SelectedBot.Engine.NukeHandler.NukesToUse.Count + 1 > remIdx)
                {
                    MainWindow.ViewModel.SelectedBot.Engine.NukeHandler.NukesToUse.Insert(targetIdx, droppedData);
                    MainWindow.ViewModel.SelectedBot.Engine.NukeHandler.NukesToUse.RemoveAt(remIdx);
                }
            }
        }
Esempio n. 3
0
        public NukeRule GetNukeToCast(GameFigure target)
        {
            //if (Math.Abs(Environment.TickCount - _timeStamp) < 50)
            //{
            //    return _latestRule;
            //}

            _timeStamp = Environment.TickCount;

            NukeRule nuke = null;

            if (target != null)
            {
                foreach (var nukeRule in NukesToUse)
                {
                    if ((nukeRule.NukeType == NukeType.Item ? !_data.Inventory.Any(item => item.Value.ItemId == nukeRule.NukeId) : false) ||
                        (nukeRule.NukeType == NukeType.Skill ? !_data.Skills.Any(skill => skill.Value.SkillId == nukeRule.NukeId) : false))
                    {
                        continue;
                    }

                    GameFigure selfCondFigure = _data.MainHero;

                    if (!nukeRule.Enabled)
                    {
                        continue;
                    }

                    //cond checks
                    if (selfCondFigure != null)
                    {
                        if (nukeRule.HealthPercentOver > 0 && nukeRule.HealthPercentOver > selfCondFigure.HealthPercent)
                        {
                            continue;
                        }

                        if (nukeRule.HealthPercentBelow > 0 && nukeRule.HealthPercentBelow < selfCondFigure.HealthPercent)
                        {
                            continue;
                        }

                        if (nukeRule.ManaPercentOver > 0 && nukeRule.ManaPercentOver > selfCondFigure.ManaPercent)
                        {
                            continue;
                        }

                        if (nukeRule.ManaPercentBelow > 0 && nukeRule.ManaPercentBelow < selfCondFigure.ManaPercent)
                        {
                            continue;
                        }

                        if (selfCondFigure is MainHero && nukeRule.CombatPointsPercentOver > 0 && nukeRule.CombatPointsPercentOver > selfCondFigure.CombatPointsPercent)
                        {
                            continue;
                        }

                        if (selfCondFigure is MainHero && nukeRule.CombatPointsPercentBelow > 0 && nukeRule.CombatPointsPercentBelow < selfCondFigure.CombatPointsPercent)
                        {
                            continue;
                        }
                    }

                    if (target != null && target.Health > 0)
                    {
                        if (nukeRule.TargetHealthPercentOver > 0 && nukeRule.TargetHealthPercentOver > target.HealthPercent)
                        {
                            continue;
                        }

                        if (nukeRule.TargetHealthPercentBelow > 0 && nukeRule.TargetHealthPercentBelow < target.HealthPercent)
                        {
                            continue;
                        }

                        if (nukeRule.TargetManaPercentOver > 0 && nukeRule.TargetManaPercentOver > target.ManaPercent)
                        {
                            continue;
                        }

                        if (nukeRule.TargetManaPercentBelow > 0 && nukeRule.TargetManaPercentBelow < target.ManaPercent)
                        {
                            continue;
                        }
                    }

                    if (nukeRule.TargetIsDead && !target.IsDead)
                    {
                        continue;
                    }

                    if (!nukeRule.TargetIsDead && target.IsDead)
                    {
                        continue;
                    }

                    if (nukeRule.TargetIsSpoiled && (!(target is Npc) || ((Npc)target).IsSweepable == false))
                    {
                        continue;
                    }

                    if (nukeRule.RepeatUntilSuccess && _data.LandedSkills.ContainsKey(nukeRule.NukeId) && _data.LandedSkills[nukeRule.NukeId] == target.ObjectId)
                    {
                        continue;
                    }

                    if (Math.Abs(Environment.TickCount - nukeRule.LastUsed) < nukeRule.Interval * 1000)
                    {
                        continue;
                    }

                    if (nukeRule.MonsterFilterType == FilterType.Inclusive && nukeRule.MonsterFilterStr.Trim().Length > 0 &&
                        !nukeRule.MonsterFilter.Any(mob => mob.Enable && mob.Name.Trim().Equals(ExportedData.NpcIdToName[target.UnitId].Trim(), StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }

                    if (nukeRule.MonsterFilterType == FilterType.Exclusive && nukeRule.MonsterFilterStr.Trim().Length > 0 &&
                        nukeRule.MonsterFilter.Any(mob => mob.Enable && mob.Name.Trim().Equals(ExportedData.NpcIdToName[target.UnitId].Trim(), StringComparison.OrdinalIgnoreCase)))
                    {
                        continue;
                    }

                    if (nukeRule.AoeActivated)
                    {
                        if (nukeRule.AoeMonstersAroundType == TargetType.Self)
                        {
                            int mobsCount = _data.SurroundingMonsters.Count(mob => mob.RangeTo(_data.MainHero) < nukeRule.AoeRange && !mob.IsDead);
                            if (nukeRule.AoeCountComparisonTypeEnum == ComparisonType.Less && mobsCount >= nukeRule.AoeMonsterCount)
                            {
                                continue;
                            }
                            else if (nukeRule.AoeCountComparisonTypeEnum == ComparisonType.More && mobsCount <= nukeRule.AoeMonsterCount)
                            {
                                continue;
                            }
                        }
                        else
                        {
                            int mobsCount = _data.SurroundingMonsters.Count(mob => mob.RangeTo(target) < nukeRule.AoeRange && !mob.IsDead);
                            if (nukeRule.AoeCountComparisonTypeEnum == ComparisonType.Less && mobsCount >= nukeRule.AoeMonsterCount)
                            {
                                continue;
                            }
                            else if (nukeRule.AoeCountComparisonTypeEnum == ComparisonType.More && mobsCount <= nukeRule.AoeMonsterCount)
                            {
                                continue;
                            }
                        }
                    }

                    if (nukeRule.NukeType == NukeType.Skill && !_data.Skills[nukeRule.NukeId].CanBeUsed())
                    {
                        continue;
                    }

                    if (nukeRule.NukeType == NukeType.Skill && _data.MainHero.Mana < ExportedData.SkillManaConsumption[nukeRule.NukeId][_data.Skills[nukeRule.NukeId].SkillLevel])
                    {
                        continue;
                    }

                    nuke = nukeRule;
                    break;
                }
            }

            _latestRule = nuke;
            return(nuke);
        }