public IEnumerable <InspectionResult> Inspect(SmartScriptBase script)
        {
            if (script.SourceType == SmartScriptType.TimedActionList)
            {
                yield break;
            }

            if (script.Events.Count == 0)
            {
                yield break;
            }

            SmartEvent previous = script.Events[0];

            for (var index = 1; index < script.Events.Count; index++)
            {
                var current = script.Events[index];

                if (current.Chance.Value == 100 && current.Conditions.Count == 0 && previous.Conditions.Count == 0 && previous.Equals(current))
                {
                    yield return(new InspectionResult()
                    {
                        Line = current.LineId,
                        Severity = DiagnosticSeverity.Info,
                        Message = "The event is a duplicate of the previous one. You can put all actions in a single event."
                    });
                }

                previous = current;
            }
        }
Beispiel #2
0
 public EventAddedAction(SmartScriptBase script, SmartEvent smartEvent, int index)
 {
     this.script     = script;
     this.smartEvent = smartEvent;
     this.index      = index;
     readable        = smartEvent.Readable;
 }
Beispiel #3
0
        public SaiHistoryHandler(SmartScriptBase script, ISmartFactory smartFactory)
        {
            this.script       = script;
            this.smartFactory = smartFactory;
            this.script.Events.CollectionChanged += Events_CollectionChanged;
            this.script.BulkEditingStarted       += OnBulkEditingStarted;
            this.script.BulkEditingFinished      += OnBulkEditingFinished;

            variablesDisposable = this.script.GlobalVariables.ToStream().Subscribe(e =>
            {
                if (e.Type == CollectionEventType.Add)
                {
                    e.Item.CommentChanged      += OnGlobalVariableCommentChanged;
                    e.Item.VariableTypeChanged += OnGlobalVariableTypeChanged;
                    e.Item.NameChanged         += OnGlobalVariableNameChanged;
                    e.Item.KeyChanged          += OnGlobalVariableKeyChanged;
                }
                else
                {
                    e.Item.CommentChanged      -= OnGlobalVariableCommentChanged;
                    e.Item.VariableTypeChanged -= OnGlobalVariableTypeChanged;
                    e.Item.NameChanged         -= OnGlobalVariableNameChanged;
                    e.Item.KeyChanged          -= OnGlobalVariableKeyChanged;
                }
            });

            script.GlobalVariables.CollectionChanged += GlobalVariablesOnCollectionChanged;

            foreach (SmartEvent ev in this.script.Events)
            {
                BindEvent(ev);
            }
        }
Beispiel #4
0
 public GlobalVariableRemovedAction(SmartScriptBase script, GlobalVariable variable, int index)
 {
     this.script   = script;
     this.variable = variable;
     this.index    = index;
     readable      = variable.Readable;
 }
Beispiel #5
0
        public IEnumerable <InspectionResult> Inspect(SmartScriptBase script)
        {
            var anyDisableReset = script.AllActions.Any(a => a.Id == disableResetAi);

            if (anyDisableReset)
            {
                yield break;
            }

            foreach (var e in script.Events)
            {
                if (e.Id == 5 || e.Id == 7)
                {
                    var anyWait = e.Actions.Any(a => a.Id == waitActionId);
                    if (anyWait)
                    {
                        yield return(new InspectionResult()
                        {
                            Line = e.LineId,
                            Severity = DiagnosticSeverity.Error,
                            Message = "WAIT action can't work in On Evade and On Kill unless you put action 'Disable AI Reset State'"
                        });
                    }
                }
            }
        }
        public void Fix(SmartScriptBase script)
        {
            if (!CanInspect(script))
            {
                return;
            }

            for (var index = 1; index < script.Events.Count; index++)
            {
                var current = script.Events[index];

                if (current.Actions.Count == 0)
                {
                    continue;
                }

                if (current.GetParameter(0).Value == 0)
                {
                    var previous = script.Events[index - 1];

                    foreach (var action in current.Actions)
                    {
                        previous.Actions.Add(action.Copy());
                    }
                    for (int i = current.Actions.Count - 1; i >= 0; --i)
                    {
                        current.Actions.RemoveAt(i);
                    }
                    script.Events.RemoveAt(index);

                    index--;
                }
            }
        }
        public IEnumerable <InspectionResult> Inspect(SmartScriptBase script)
        {
            if (!CanInspect(script))
            {
                yield break;
            }

            for (var index = 1; index < script.Events.Count; index++)
            {
                var current = script.Events[index];

                if (current.Actions.Count == 0)
                {
                    continue;
                }

                if (current.GetParameter(0).Value == 0)
                {
                    yield return(new InspectionResult()
                    {
                        Line = current.LineId,
                        Severity = DiagnosticSeverity.Info,
                        Message = "This event can be merged with the previous one."
                    });
                }
            }
        }
    public async Task <long?> PickVariable(GlobalVariableType type, SmartScriptBase script, long?currentValue)
    {
        var vm = containerProvider.Resolve <VariablePickerViewModel>((typeof(GlobalVariableType), type),
                                                                     (typeof(SmartScriptBase), script), (typeof(long?), currentValue));

        if (await windowManager.ShowDialog(vm))
        {
            return(vm.SelectedItem?.Id);
        }

        return(null);
    }
Beispiel #9
0
        public SaiHistoryHandler(SmartScriptBase script, ISmartFactory smartFactory)
        {
            this.script       = script;
            this.smartFactory = smartFactory;
            this.script.Events.CollectionChanged += Events_CollectionChanged;
            this.script.BulkEditingStarted       += OnBulkEditingStarted;
            this.script.BulkEditingFinished      += OnBulkEditingFinished;

            foreach (SmartEvent ev in this.script.Events)
            {
                BindEvent(ev);
            }
        }
        private bool CanInspect(SmartScriptBase script)
        {
            if (script.SourceType != SmartScriptType.TimedActionList)
            {
                return(false);
            }

            if (script.Events.Count <= 1)
            {
                return(false);
            }

            return(true);
        }
Beispiel #11
0
 public EventRemovedAction(SmartScriptBase script, SmartEvent smartEvent, int index)
 {
     this.script     = script;
     this.smartEvent = smartEvent;
     this.index      = index;
 }
    public VariablePickerViewModel(GlobalVariableType type, SmartScriptBase script, long?initial)
    {
        this.type   = type;
        this.script = script;
        Items       = new(script.GlobalVariables.Where(gv => gv.VariableType == type)
                          .OrderBy(i => i.Key)
                          .Distinct(Compare.By <GlobalVariable, long>(i => i !.Key))
                          .Select(gv => new VariableItemViewModel(gv)));

        SelectedItem = initial.HasValue ? Items.FirstOrDefault(i => i.Id == initial) : null;

        if (SelectedItem == null && initial != null)
        {
            var phantom = VariableItemViewModel.CreatePhantom(initial.Value);
            Items.Add(phantom);
            SelectedItem = phantom;
        }

        Cancel = new DelegateCommand(() =>
        {
            CloseCancel?.Invoke();
        });
        Accept = new DelegateCommand(() =>
        {
            var dict = Items.Where(i => !i.IsPhantom).SafeToDictionary(i => i.OriginalId ?? i.Id, i => i);
            for (var i = script.GlobalVariables.Count - 1; i >= 0; i--)
            {
                var existing = script.GlobalVariables[i];
                if (existing.VariableType == type)
                {
                    if (dict.TryGetValue(existing.Key, out var item))
                    {
                        existing.Key     = item.Id;
                        existing.Name    = item.Name;
                        existing.Comment = item.Comment;
                        dict.Remove(item.OriginalId ?? item.Id);
                    }
                    else
                    {
                        script.GlobalVariables.RemoveAt(i);
                    }
                }
            }

            foreach (var pair in dict)
            {
                script.GlobalVariables.Add(new GlobalVariable()
                {
                    Key          = pair.Key,
                    Name         = pair.Value.Name,
                    Comment      = pair.Value.Comment,
                    VariableType = type
                });
            }

            CloseOk?.Invoke();
        });

        AddItemCommand = new DelegateCommand(() =>
        {
            var phantom = VariableItemViewModel.CreatePhantom((Items.Count > 0 ? Items.Max(i => i.Id) : 0) + 1);
            Items.Add(phantom);
            SelectedItem = phantom;
        });

        RemoveItemCommand = new DelegateCommand(() =>
        {
            if (SelectedItem != null)
            {
                Items.Remove(SelectedItem);
                SelectedItem = null;
            }
        }, () => SelectedItem != null).ObservesProperty(() => SelectedItem);

        Items.DisposeOnRemove();
        AutoDispose(new ActionDisposable(() => Items.Clear()));
    }