private void EditActionCommand(SmartAction obj)
        {
            ParametersEditView v = new ParametersEditView();
            List <KeyValuePair <Parameter, string> > paramss = new List <KeyValuePair <Parameter, string> >();

            for (int i = 0; i < obj.Source.ParametersCount; ++i)
            {
                paramss.Add(new KeyValuePair <Parameter, string>(obj.Source.GetParameter(i), "Source"));
            }

            for (int i = 0; i < obj.ParametersCount; ++i)
            {
                paramss.Add(new KeyValuePair <Parameter, string>(obj.GetParameter(i), "Action"));
            }

            for (int i = 0; i < obj.Target.ParametersCount; ++i)
            {
                paramss.Add(new KeyValuePair <Parameter, string>(obj.Target.GetParameter(i), "Target"));
            }

            for (int i = 0; i < 4; ++i)
            {
                int       j       = i;
                Parameter wrapper = new FloatIntParameter(obj.Target.Position[i].Name);
                wrapper.SetValue((int)(obj.Target.Position[i].GetValue() * 1000));
                wrapper.OnValueChanged += (sender, value) => obj.Target.Position[j].SetValue(wrapper.GetValue() / 1000.0f);
                paramss.Add(new KeyValuePair <Parameter, string>(wrapper, "Target"));
            }

            v.DataContext = new ParametersEditViewModel(_container, obj, paramss);
            v.ShowDialog();
        }
Example #2
0
 public ActionAddedAction(SmartEvent parent, SmartAction smartAction, int index)
 {
     this.parent      = parent;
     this.smartAction = smartAction;
     this.index       = index;
     this.readable    = smartAction.Readable.RemoveTags();
 }
        private void AddActionCommand(SmartEvent obj)
        {
            int?sourceId = _container.Resolve <ISmartTypeListProvider>().Get(SmartType.SmartSource, data =>
            {
                if (data.IsOnlyTarget)
                {
                    return(false);
                }

                return(data.UsableWithEventTypes == null || data.UsableWithEventTypes.Contains(script.SourceType));
            }
                                                                             );

            if (!sourceId.HasValue)
            {
                return;
            }

            int?actionId = _container.Resolve <ISmartTypeListProvider>().Get(SmartType.SmartAction, data =>
            {
                return(data.UsableWithEventTypes == null || data.UsableWithEventTypes.Contains(script.SourceType));
            });

            if (!actionId.HasValue)
            {
                return;
            }

            var actionData = SmartDataManager.GetInstance().GetRawData(SmartType.SmartAction, actionId.Value);

            SmartTarget target = null;

            if (actionData.UsesTarget)
            {
                int?targetId = _container.Resolve <ISmartTypeListProvider>().Get(SmartType.SmartTarget, data =>
                {
                    return((data.UsableWithEventTypes == null || data.UsableWithEventTypes.Contains(script.SourceType)) &&
                           actionData.Targets.Intersect(data.Types).Any());
                });

                if (!targetId.HasValue)
                {
                    return;
                }

                target = _container.Resolve <ISmartFactory>().TargetFactory(targetId.Value);
            }
            else
            {
                target = _container.Resolve <ISmartFactory>().TargetFactory(0);
            }


            SmartSource source = _container.Resolve <ISmartFactory>().SourceFactory(sourceId.Value);

            SmartAction ev = _container.Resolve <ISmartFactory>().ActionFactory(actionId.Value, source, target);

            EditActionCommand(ev);
            obj.Actions.Add(ev);
        }
Example #4
0
        private void UnbindAction(SmartAction smartAction)
        {
            smartAction.Source.OnConditionsChanged -= SmartSourceOnConditionsChanged;
            smartAction.Target.OnConditionsChanged -= SmartSourceOnConditionsChanged;
            smartAction.Target.OnIdChanged         -= SmartTargetOnOnIdChanged;
            smartAction.Source.OnIdChanged         -= SmartSourceOnOnIdChanged;
            smartAction.OnIdChanged         -= SmartActionOnOnIdChanged;
            smartAction.BulkEditingStarted  -= OnBulkEditingStarted;
            smartAction.BulkEditingFinished -= OnBulkEditingFinished;

            for (var i = 0; i < smartAction.ParametersCount; ++i)
            {
                smartAction.GetParameter(i).OnValueChanged -= Parameter_OnValueChanged;
            }

            for (var i = 0; i < smartAction.Source.ParametersCount; ++i)
            {
                smartAction.Source.GetParameter(i).OnValueChanged -= Parameter_OnValueChanged;
            }

            for (var i = 0; i < smartAction.Target.ParametersCount; ++i)
            {
                smartAction.Target.GetParameter(i).OnValueChanged -= Parameter_OnValueChanged;
            }

            for (var i = 0; i < 4; ++i)
            {
                smartAction.Target.Position[i].OnValueChanged -= ParameterFloat_OnValueChange;
            }

            smartAction.CommentParameter.OnValueChanged -= ParameterString_OnValueChanged;
        }
Example #5
0
        private void BindAction(SmartAction smartAction)
        {
            smartAction.BulkEditingStarted  += OnBulkEditingStarted;
            smartAction.BulkEditingFinished += OnBulkEditingFinished;

            for (int i = 0; i < smartAction.ParametersCount; ++i)
            {
                smartAction.GetParameter(i).OnValueChanged += Parameter_OnValueChanged;
            }

            for (int i = 0; i < smartAction.Source.ParametersCount; ++i)
            {
                smartAction.Source.GetParameter(i).OnValueChanged += Parameter_OnValueChanged;
            }

            for (int i = 0; i < smartAction.Target.ParametersCount; ++i)
            {
                smartAction.Target.GetParameter(i).OnValueChanged += Parameter_OnValueChanged;
            }

            for (int i = 0; i < 4; ++i)
            {
                smartAction.Target.Position[i].OnValueChanged += ParameterFloat_OnValueChange;
            }
        }
        private string GenerateSingleSai(int eventId, SmartEvent ev, SmartAction action, int link = 0, string comment = null)
        {
            System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)System.Threading.Thread.CurrentThread.CurrentCulture.Clone();
            customCulture.NumberFormat.NumberDecimalSeparator = ".";

            System.Threading.Thread.CurrentThread.CurrentCulture = customCulture;

            //if (action.Id == 188) // ACTION DEBUG MESSAGE
            //    comment = action.Comment;
            object data = new
            {
                entryorguid = "@ENTRY",
                source_type = ((int)_script.SourceType).ToString(),
                id          = eventId.ToString(),
                linkto      = link.ToString(),

                event_id     = ev.Id.ToString(),
                phasemask    = ev.Phases.GetValue().ToString(),
                chance       = ev.Chance.ToString(),
                flags        = ev.Flags.GetValue().ToString(),
                event_param1 = ev.GetParameter(0).GetValue().ToString(),
                event_param2 = ev.GetParameter(1).GetValue().ToString(),
                event_param3 = ev.GetParameter(2).GetValue().ToString(),
                event_param4 = ev.GetParameter(3).GetValue().ToString(),

                event_cooldown_min = ev.CooldownMin.GetValue().ToString(),
                event_cooldown_max = ev.CooldownMax.GetValue().ToString(),

                action_id     = action.Id.ToString(),
                action_param1 = action.GetParameter(0).GetValue().ToString(),
                action_param2 = action.GetParameter(1).GetValue().ToString(),
                action_param3 = action.GetParameter(2).GetValue().ToString(),
                action_param4 = action.GetParameter(3).GetValue().ToString(),
                action_param5 = action.GetParameter(4).GetValue().ToString(),
                action_param6 = action.GetParameter(5).GetValue().ToString(),

                action_source_id    = action.Source.Id.ToString(),
                source_param1       = action.Source.GetParameter(0).GetValue().ToString(),
                source_param2       = action.Source.GetParameter(1).GetValue().ToString(),
                source_param3       = action.Source.GetParameter(2).GetValue().ToString(),
                source_condition_id = action.Source.Condition.GetValue().ToString(),

                target_id           = action.Target.Id.ToString(),
                target_param1       = action.Target.GetParameter(0).GetValue().ToString(),
                target_param2       = action.Target.GetParameter(1).GetValue().ToString(),
                target_param3       = action.Target.GetParameter(2).GetValue().ToString(),
                target_condition_id = action.Target.Condition.GetValue().ToString(),


                x = action.Target.X.ToString(),
                y = action.Target.X.ToString(),
                z = action.Target.X.ToString(),
                o = action.Target.X.ToString(),

                comment = comment ?? (ev.Readable + " - " + action.Readable)
            };

            return(SmartFormat.Smart.Format(SAI_SQL, data));
        }
 public SmartActionProperty(SmartAction action)
     : base(action)
 {
     this.action = action;
     m_dctd.GetProperty("name").SetCategory("Action");
     m_dctd.GetProperty("name").SetDisplayName("Action name");
     Parameter[] parameters = action.Target.parameters;
     for (int i = 0; i < 3; ++i)
     {
         CustomPropertyDescriptor property = m_dctd.GetProperty("targetpram" + (i + 1));
         Init(property, parameters[i]);
     }
 }
 public SmartActionProperty(SmartAction action)
     : base(action)
 {
     this.action = action;
     m_dctd.GetProperty("name").SetCategory("Action");
     m_dctd.GetProperty("name").SetDisplayName("Action name");
     Parameter[] parameters = action.Target.parameters;
     for (int i = 0; i < 3; ++i)
     {
         CustomPropertyDescriptor property = m_dctd.GetProperty("targetpram" + (i + 1));
         Init(property, parameters[i]);
     }
 }
        public static string GenerateComment(SmartEvent ev, SmartAction action)
        {
            StringBuilder comment = new StringBuilder();


            comment.Append(ev);
            comment.Append(" - ");
            comment.Append(action);
            comment.Append(" // " + action.Comment);


            return comment.ToString();
        }
Example #10
0
        public static string GenerateComment(SmartEvent ev, SmartAction action)
        {
            StringBuilder comment = new StringBuilder();


            comment.Append(ev);
            comment.Append(" - ");
            comment.Append(action);
            comment.Append(" // " + action.Comment);


            return(comment.ToString());
        }
Example #11
0
        public SmartAction ActionFactory(int id, SmartSource source, SmartTarget target)
        {
            if (!smartDataManager.Contains(SmartType.SmartAction, id))
            {
                throw new NullReferenceException("No data for action id " + id);
            }

            SmartAction action = new SmartAction(id, source, target);

            SetParameterObjects(action, smartDataManager.GetRawData(SmartType.SmartAction, id));

            return(action);
        }
Example #12
0
        public SmartAction ActionFactory(ISmartScriptLine line)
        {
            SmartSource source = SourceFactory(line);
            SmartTarget target = TargetFactory(line);

            SmartAction action = ActionFactory(line.ActionType, source, target);

            for (int i = 0; i < SmartAction.SmartActionParametersCount; ++i)
            {
                action.SetParameter(i, GetActionParameter(line, i));
            }

            return(action);
        }
Example #13
0
        public void UpdateAction(SmartAction smartAction, int id)
        {
            if (smartAction.Id == id)
            {
                return;
            }

            SmartGenericJsonData raw = smartDataManager.GetRawData(SmartType.SmartAction, id);

            smartAction.CommentParameter.IsUsed = raw.CommentField != null;
            smartAction.CommentParameter.Name   = raw.CommentField ?? "Comment";
            SetParameterObjects(smartAction, raw, true);
            UpdateTargetPositionVisibility(smartAction.Target);
        }
        public InspectionResult?Inspect(SmartAction a)
        {
            var valid = validator.Evaluate(new SmartValidationContext(a.Parent !.Parent !, a.Parent, a));

            if (!valid)
            {
                return(new InspectionResult()
                {
                    Severity = rule.Level,
                    Message = rule.Description,
                    Line = a.LineId
                });
            }
            return(null);
        }
Example #15
0
        public void UpdateAction(SmartAction smartAction, int id)
        {
            if (smartAction.Id == id)
            {
                return;
            }

            SmartGenericJsonData raw = smartDataManager.GetRawData(SmartType.SmartAction, id);

            smartAction.CommentParameter.IsUsed = id == SmartConstants.ActionComment;
            foreach (var t in smartAction.Target.Position)
            {
                t.IsUsed = raw.UsesTargetPosition;
            }
            SetParameterObjects(smartAction, raw, true);
        }
Example #16
0
        public SmartAction ActionFactory(ISmartScriptLine line)
        {
            SmartSource source = SourceFactory(line);
            SmartTarget target = TargetFactory(line);

            var raw = smartDataManager.GetRawData(SmartType.SmartAction, line.ActionType);

            if (raw.ImplicitSource != null)
            {
                UpdateSource(source, smartDataManager.GetDataByName(SmartType.SmartSource, raw.ImplicitSource).Id);
            }

            SmartAction action = ActionFactory(line.ActionType, source, target);

            for (var i = 0; i < SmartAction.SmartActionParametersCount; ++i)
            {
                action.GetParameter(i).Value = line.GetActionParam(i);
            }

            return(action);
        }
Example #17
0
        public SmartAction ActionFactory(ISmartScriptLine line)
        {
            SmartSource source = SourceFactory(line);
            SmartTarget target = TargetFactory(line);

            var raw = smartDataManager.GetRawData(SmartType.SmartAction, line.ActionType);

            if (raw.ImplicitSource != null)
            {
                UpdateSource(source, smartDataManager.GetDataByName(SmartType.SmartSource, raw.ImplicitSource).Id);
            }

            SmartAction action = ActionFactory(line.ActionType, source, target);

            for (var i = 0; i < SmartAction.SmartActionParametersCount; ++i)
            {
                action.GetParameter(i).Value = line.GetActionParam(i);
            }

            if (raw.SourceStoreInAction)
            {
                try
                {
                    UpdateSource(source,
                                 smartDataManager.GetRawData(SmartType.SmartSource, (int)action.GetParameter(2).Value).Id);
                    source.GetParameter(0).Value = action.GetParameter(3).Value;
                    source.GetParameter(1).Value = action.GetParameter(4).Value;
                    source.GetParameter(2).Value = action.GetParameter(5).Value;
                    action.GetParameter(2).Value = 0;
                    action.GetParameter(3).Value = 0;
                    action.GetParameter(4).Value = 0;
                    action.GetParameter(5).Value = 0;
                }
                catch (Exception)
                {
                }
            }

            return(action);
        }
        private void UnbindAction(SmartAction smartAction)
        {
            for (int i = 0; i < smartAction.ParametersCount; ++i)
            {
                smartAction.GetParameter(i).OnValueChanged -= Parameter_OnValueChanged;
            }

            for (int i = 0; i < smartAction.Source.ParametersCount; ++i)
            {
                smartAction.Source.GetParameter(i).OnValueChanged -= Parameter_OnValueChanged;
            }

            for (int i = 0; i < smartAction.Target.ParametersCount; ++i)
            {
                smartAction.Target.GetParameter(i).OnValueChanged -= Parameter_OnValueChanged;
            }

            for (int i = 0; i < 4; ++i)
            {
                smartAction.Target.Position[i].OnValueChanged -= ParameterFloat_OnValueChange;
            }
        }
Example #19
0
        private void AdjustCoreCompatibleAction(SmartAction action)
        {
            if (action.Id == SmartConstants.ActionComment)
            {
                smartFactory.UpdateAction(action, SmartConstants.ActionNone);
                smartFactory.UpdateSource(action.Source, SmartConstants.ActionNone);
                smartFactory.UpdateTarget(action.Target, SmartConstants.ActionNone);
            }

            var actionData = smartDataManager.GetRawData(SmartType.SmartAction, action.Id);

            if (actionData.ImplicitSource != null)
            {
                smartFactory.UpdateSource(action.Source,
                                          smartDataManager.GetDataByName(SmartType.SmartSource, actionData.ImplicitSource).Id);
            }

            if (actionData.TargetIsSource)
            {
                smartFactory.UpdateTarget(action.Target, action.Source.Id);
                for (int i = 0; i < action.Target.ParametersCount; ++i)
                {
                    action.Target.GetParameter(i).Copy(action.Source.GetParameter(i));
                }

                // do not reset source, it doesn't matter, but at least correct comment will be generated
                // smartFactory.UpdateSource(actualAction.Source, 0);
            }

            if (actionData.SourceStoreInAction)
            {
                action.GetParameter(2).Value = action.Source.Id;
                action.GetParameter(3).Value = action.Source.GetParameter(0).Value;
                action.GetParameter(4).Value = action.Source.GetParameter(1).Value;
                action.GetParameter(5).Value = action.Source.GetParameter(2).Value;
            }
        }
Example #20
0
        public InspectionResult?Inspect(SmartAction a)
        {
            if (a.Parent == null)
            {
                return(null);
            }

            if (a.Id != SmartConstants.ActionCreateTimed)
            {
                return(null);
            }

            if (a.Parent.Id != SmartConstants.EventTriggerTimed)
            {
                return(null);
            }

            return(new InspectionResult()
            {
                Severity = DiagnosticSeverity.Error,
                Line = a.LineId,
                Message = "You may not create timed event inside a timed event, core will crash"
            });
        }
Example #21
0
        public (ISmartScriptLine[], IConditionLine[]) ToDatabaseCompatibleSmartScript(SmartScript script)
        {
            if (script.Events.Count == 0)
            {
                return(new ISmartScriptLine[0], null);
            }

            var  eventId         = 0;
            var  lines           = new List <ISmartScriptLine>();
            var  conditions      = new List <IConditionLine>();
            var  previousWasWait = false;
            long nextTriggerId   = script.Events.Where(e => e.Id == SmartConstants.EventTriggerTimed)
                                   .Select(e => e.GetParameter(0).Value)
                                   .DefaultIfEmpty(0)
                                   .Max() + 1;

            var usedTimedActionLists = script.Events
                                       .SelectMany(e => e.Actions)
                                       .Where(a => a.Id == SmartConstants.ActionCallTimedActionList ||
                                              a.Id == SmartConstants.ActionCallRandomTimedActionList ||
                                              a.Id == SmartConstants.ActionCallRandomRangeTimedActionList)
                                       .SelectMany(a =>
            {
                if (a.Id == SmartConstants.ActionCallRandomTimedActionList)
                {
                    return new int[]
                    {
                        (int)a.GetParameter(0).Value,
                        (int)a.GetParameter(1).Value,
                        (int)a.GetParameter(2).Value,
                        (int)a.GetParameter(3).Value,
                        (int)a.GetParameter(4).Value,
                        (int)a.GetParameter(5).Value,
                    }
                }
                ;
                if (a.Id == SmartConstants.ActionCallRandomRangeTimedActionList &&
                    a.GetParameter(1).Value - a.GetParameter(0).Value < 20)
                {
                    return(Enumerable.Range((int)a.GetParameter(0).Value, (int)(a.GetParameter(1).Value - a.GetParameter(0).Value + 1)));
                }
                return(new int[] { (int)a.GetParameter(0).Value });
            })
                                       .Where(id => id != 0)
                                       .ToHashSet();

            int firstUnusedActionList = Math.Abs(script.EntryOrGuid) * 100 - 1;

            int GetNextUnusedTimedActionList()
            {
                do
                {
                    firstUnusedActionList++;
                } while (usedTimedActionLists.Contains(firstUnusedActionList));

                usedTimedActionLists.Add(firstUnusedActionList);
                return(firstUnusedActionList);
            }

            foreach (var gv in script.GlobalVariables)
            {
                lines.Add(gv.ToMetaSmartScriptLine(script.EntryOrGuid, script.SourceType, eventId++));
            }

            if (script.SourceType == SmartScriptType.TimedActionList)
            {
                foreach (SmartEvent e in script.Events)
                {
                    for (var index = 0; index < e.Actions.Count; ++index)
                    {
                        SmartEvent eventToSerialize = index == 0 ? e.ShallowCopy() : smartFactory.EventFactory(SmartConstants.EventUpdateInCombat);

                        SmartAction actualAction = e.Actions[index].Copy();
                        AdjustCoreCompatibleAction(actualAction);

                        eventToSerialize.Parent = script;
                        eventToSerialize.Actions.Add(actualAction);

                        var serialized = eventToSerialize.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, eventId++, false, 0);

                        if (serialized.Length != 1)
                        {
                            throw new InvalidOperationException();
                        }

                        lines.Add(serialized[0]);
                    }
                }
            }
            else
            {
                SmartEvent        originalEvent;
                List <SmartEvent> additionalEvents = new();

                void FlushLines(SmartEvent?eventForConditions)
                {
                    if (eventForConditions != null)
                    {
                        var serializedConditions = eventForConditions.ToConditionLines(SmartConstants.ConditionSourceSmartScript, script.EntryOrGuid, script.SourceType, eventId);
                        if (serializedConditions != null)
                        {
                            conditions.AddRange(serializedConditions);
                        }
                    }

                    foreach (var toSerialize in new SmartEvent[] { originalEvent }.Concat(additionalEvents))
                    {
                        if (toSerialize.Actions.Count == 0)
                        {
                            continue;
                        }
                        var serialized = toSerialize.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, eventId, true);
                        eventId += serialized.Length;
                        lines.AddRange(serialized);
                    }
                    additionalEvents.ForEach(d => d.Actions.Clear());
                    originalEvent.Actions.Clear();
                }

                foreach (SmartEvent e in script.Events)
                {
                    if (e.Actions.Count == 0)
                    {
                        continue;
                    }

                    originalEvent        = e.ShallowCopy();
                    originalEvent.Parent = script;
                    additionalEvents.Clear();
                    SmartEvent lastEvent = originalEvent;

                    long accumulatedWaits = 0;
                    for (var index = 0; index < e.Actions.Count; ++index)
                    {
                        if (previousWasWait)
                        {
                            var eventTimed = smartFactory.EventFactory(SmartConstants.EventTriggerTimed);
                            eventTimed.Parent = script;
                            eventTimed.GetParameter(0).Value = nextTriggerId++;
                            additionalEvents.Add(eventTimed);
                            lastEvent = eventTimed;
                        }

                        if (e.Actions[index].Id == SmartConstants.ActionBeginInlineActionList ||
                            e.Actions[index].Id == SmartConstants.ActionAfter)
                        {
                            var         timedActionListId   = GetNextUnusedTimedActionList();
                            SmartAction callTimedActionList = smartFactory.ActionFactory(SmartConstants.ActionCallTimedActionList,
                                                                                         smartFactory.SourceFactory(SmartConstants.SourceSelf),
                                                                                         smartFactory.TargetFactory(SmartConstants.TargetSelf));
                            callTimedActionList.GetParameter(0).Value = timedActionListId;
                            if (e.Actions[index].Id == SmartConstants.ActionBeginInlineActionList)
                            {
                                callTimedActionList.GetParameter(1).Value = e.Actions[index].GetParameter(0).Value;
                                callTimedActionList.GetParameter(2).Value = e.Actions[index].GetParameter(1).Value;
                                index++;
                            }
                            callTimedActionList.Comment = SmartConstants.CommentInlineActionList;
                            lastEvent.AddAction(callTimedActionList);

                            FlushLines(e);

                            long afterTimeMin = 0;
                            long afterTimeMax = 0;
                            int  timedEventId = 0;
                            for (; index < e.Actions.Count; ++index)
                            {
                                if (e.Actions[index].Id == SmartConstants.ActionAfter || e.Actions[index].Id == SmartConstants.ActionWait)
                                {
                                    afterTimeMin += e.Actions[index].GetParameter(0).Value;
                                    afterTimeMax += e.Actions[index].GetParameter(1).Value;
                                    if (e.Actions[index].GetParameter(1).Value == 0)
                                    {
                                        afterTimeMax += e.Actions[index].GetParameter(0).Value;
                                    }
                                }
                                else if (e.Actions[index].Id == SmartConstants.ActionAfterMovement && index > 0)
                                {
                                    afterTimeMin = 0;
                                    afterTimeMax = 0;
                                    var pathId = e.Actions[index - 1].GetParameter(1).Value;
                                    timedActionListId = GetNextUnusedTimedActionList();

                                    var eventFinishedMovement =
                                        smartFactory.EventFactory(SmartConstants.EventWaypointsEnded);
                                    eventFinishedMovement.Parent = script;
                                    eventFinishedMovement.GetParameter(1).Value = pathId;

                                    var callAnotherTimedActionList = smartFactory.ActionFactory(SmartConstants.ActionCallTimedActionList,
                                                                                                smartFactory.SourceFactory(SmartConstants.SourceSelf),
                                                                                                smartFactory.TargetFactory(SmartConstants.TargetSelf));
                                    callAnotherTimedActionList.GetParameter(0).Value = timedActionListId;
                                    callAnotherTimedActionList.Comment = SmartConstants.CommentInlineMovementActionList;

                                    eventFinishedMovement.AddAction(callAnotherTimedActionList);
                                    additionalEvents.Add(eventFinishedMovement);
                                    FlushLines(null);
                                }
                                else
                                {
                                    SmartEvent after = smartFactory.EventFactory(SmartConstants.EventUpdateInCombat);
                                    after.GetParameter(0).Value = afterTimeMin;
                                    after.GetParameter(1).Value = afterTimeMax;
                                    SmartAction actualAction = e.Actions[index].Copy();
                                    AdjustCoreCompatibleAction(actualAction);

                                    after.Parent = new SmartScript(new SmartScriptSolutionItem(timedActionListId, SmartScriptType.TimedActionList), smartFactory, smartDataManager, messageBoxService);
                                    after.AddAction(actualAction);

                                    var serialized = after.ToSmartScriptLines(timedActionListId, SmartScriptType.TimedActionList, timedEventId++, false, 0);

                                    if (serialized.Length != 1)
                                    {
                                        throw new InvalidOperationException();
                                    }

                                    lines.Add(serialized[0]);
                                    afterTimeMin = 0;
                                    afterTimeMax = 0;
                                }
                            }
                        }
                        else if (e.Actions[index].Id == SmartConstants.ActionWait)
                        {
                            accumulatedWaits += e.Actions[index].GetParameter(0).Value;

                            if (index == e.Actions.Count - 1 || e.Actions[index + 1].Id == SmartConstants.ActionWait)
                            {
                                continue;
                            }

                            SmartAction createTimedAction = smartFactory.ActionFactory(SmartConstants.ActionCreateTimed,
                                                                                       smartFactory.SourceFactory(SmartConstants.SourceNone),
                                                                                       smartFactory.TargetFactory(SmartConstants.TargetNone));
                            createTimedAction.GetParameter(0).Value = nextTriggerId;
                            createTimedAction.GetParameter(1).Value = accumulatedWaits;
                            createTimedAction.GetParameter(2).Value = accumulatedWaits;
                            createTimedAction.Comment = SmartConstants.CommentWait;
                            previousWasWait           = true;

                            originalEvent.AddAction(createTimedAction);
                        }
                        else
                        {
                            previousWasWait = false;
                            SmartAction actualAction = e.Actions[index].Copy();
                            AdjustCoreCompatibleAction(actualAction);
                            lastEvent.AddAction(actualAction);
                        }
                    }

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

                    FlushLines(e);
                }
            }

            return(lines.ToArray(), conditions.ToArray());
        }
Example #22
0
        public (ISmartScriptLine[], IConditionLine[]) ToDatabaseCompatibleSmartScript(SmartScript script)
        {
            if (script.Events.Count == 0)
            {
                return(new ISmartScriptLine[0], null);
            }

            var  eventId         = 0;
            var  lines           = new List <ISmartScriptLine>();
            var  conditions      = new List <IConditionLine>();
            var  previousWasWait = false;
            long nextTriggerId   = script.Events.Where(e => e.Id == SmartConstants.EventTriggerTimed)
                                   .Select(e => e.GetParameter(0).Value)
                                   .DefaultIfEmpty(0)
                                   .Max() + 1;

            foreach (SmartEvent e in script.Events)
            {
                if (e.Actions.Count == 0)
                {
                    continue;
                }

                e.ActualId = eventId;

                for (var index = 0; index < e.Actions.Count; ++index)
                {
                    SmartEvent actualEvent = e;

                    if (previousWasWait)
                    {
                        actualEvent = smartFactory.EventFactory(SmartConstants.EventTriggerTimed);
                        actualEvent.GetParameter(0).Value = nextTriggerId++;
                    }
                    else if (index > 0)
                    {
                        actualEvent = smartFactory.EventFactory(SmartConstants.EventLink);
                    }

                    int linkTo = e.Actions.Count - 1 == index ? 0 : eventId + 1;

                    SmartAction actualAction = e.Actions[index].Copy();

                    if (actualAction.Id == SmartConstants.ActionWait)
                    {
                        linkTo = 0;
                        SmartAction waitAction = actualAction;
                        actualAction = smartFactory.ActionFactory(SmartConstants.ActionTriggerTimed,
                                                                  smartFactory.SourceFactory(SmartConstants.SourceNone),
                                                                  smartFactory.TargetFactory(SmartConstants.TargetNone));
                        actualAction.GetParameter(0).Value = nextTriggerId;
                        actualAction.GetParameter(1).Value = waitAction.GetParameter(0).Value;
                        actualAction.GetParameter(2).Value = waitAction.GetParameter(0).Value;
                        actualAction.Comment = SmartConstants.CommentWait;
                        previousWasWait      = true;
                    }
                    else
                    {
                        if (actualAction.Id == SmartConstants.ActionComment)
                        {
                            SmartAction commentAction = actualAction;
                            actualAction = smartFactory.ActionFactory(SmartConstants.ActionNone,
                                                                      smartFactory.SourceFactory(SmartConstants.SourceNone),
                                                                      smartFactory.TargetFactory(SmartConstants.TargetNone));
                            actualAction.Comment = commentAction.Comment;
                        }
                        previousWasWait = false;
                    }

                    var actionData = smartDataManager.GetRawData(SmartType.SmartAction, actualAction.Id);

                    if (actionData.TargetIsSource)
                    {
                        smartFactory.UpdateTarget(actualAction.Target, actualAction.Source.Id);
                        for (int i = 0; i < actualAction.Target.ParametersCount; ++i)
                        {
                            actualAction.Target.GetParameter(i).Copy(actualAction.Source.GetParameter(i));
                        }

                        smartFactory.UpdateSource(actualAction.Source, 0);
                    }

                    if (actionData.ImplicitSource != null)
                    {
                        smartFactory.UpdateSource(actualAction.Source, smartDataManager.GetDataByName(SmartType.SmartSource, actionData.ImplicitSource).Id);
                    }
                    else if (actionData.SourceStoreInAction)
                    {
                        actualAction.GetParameter(2).Value = actualAction.Source.Id;
                        actualAction.GetParameter(3).Value = actualAction.Source.GetParameter(0).Value;
                        actualAction.GetParameter(4).Value = actualAction.Source.GetParameter(1).Value;
                        actualAction.GetParameter(5).Value = actualAction.Source.GetParameter(2).Value;
                    }

                    SmartEvent eventToSerialize = actualEvent.ShallowCopy();
                    eventToSerialize.Parent = script;
                    eventToSerialize.Actions.Add(actualAction);

                    var serialized           = eventToSerialize.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, eventId, linkTo);
                    var serializedConditions = actualEvent.ToConditionLines(script.EntryOrGuid, script.SourceType, eventId);

                    if (serialized.Length != 1)
                    {
                        throw new InvalidOperationException();
                    }

                    lines.Add(serialized[0]);
                    if (serializedConditions != null)
                    {
                        conditions.AddRange(serializedConditions);
                    }

                    eventId++;
                }
            }

            return(lines.ToArray(), conditions.ToArray());
        }
 private void EditAction(SmartAction action)
 {
     EditActionCommand?.Execute(action);
 }
Example #24
0
        private static string GenerateSingleSAI(SAIType sourcetype, int entry, int id, SmartEvent ev, SmartAction action, int link = 0)
        {
            object data = new
            {
                entryorguid = (entry<0?"@GUID":"@ENTRY"),
                source_type = ((int)sourcetype).ToString(),
                id = id.ToString(),
                linkto = link.ToString(),

                event_id = ev.ID.ToString(),
                phasemask = ((int)ev.phasemask).ToString(),
                chance = ev.chance.ToString(),
                flags = ((int)ev.flags).ToString(),
                event_param1 = ev.parameters[0].GetValue().ToString(),
                event_param2 = ev.parameters[1].GetValue().ToString(),
                event_param3 = ev.parameters[2].GetValue().ToString(),
                event_param4 = ev.parameters[3].GetValue().ToString(),

                action_id = action.ID.ToString(),
                action_param1 = action.parameters[0].GetValue().ToString(),
                action_param2 = action.parameters[1].GetValue().ToString(),
                action_param3 = action.parameters[2].GetValue().ToString(),
                action_param4 = action.parameters[3].GetValue().ToString(),
                action_param5 = action.parameters[4].GetValue().ToString(),
                action_param6 = action.parameters[5].GetValue().ToString(),

                target_id = action.Target.ID.ToString(),
                target_param1 = action.Target.parameters[0].GetValue().ToString(),
                target_param2 = action.Target.parameters[1].GetValue().ToString(),
                target_param3 = action.Target.parameters[2].GetValue().ToString(),

                target_position = String.Join(", ", action.Target.position),

                comment = CommentGenerator.GenerateComment(ev, action)
            };

            return SmartFormat.Smart.Format(SAI_SQL, data);
        }
Example #25
0
        private void RemovedAction(SmartAction smartAction, SmartEvent parent, int index)
        {
            UnbindAction(smartAction);

            PushAction(new ActionRemovedAction(parent, smartAction, index));
        }
        public static ISmartScriptLine[] ToWaitFreeSmartScriptLines(this SmartScript script, ISmartFactory smartFactory)
        {
            if (script.Events.Count == 0)
            {
                return(new ISmartScriptLine[0]);
            }

            int eventId = 0;
            List <ISmartScriptLine> lines = new List <ISmartScriptLine>();
            bool previousWasWait          = false;
            int  nextTriggerId            = script.Events.Where(e => e.Id == SmartConstants.EVENT_TRIGGER_TIMED).Select(e => e.GetParameter(0).Value).DefaultIfEmpty(0).Max() + 1;

            //@todo: don't use hardcoded IDs!!!!
            foreach (SmartEvent e in script.Events)
            {
                if (e.Actions.Count == 0)
                {
                    continue;
                }

                e.ActualId = eventId;

                for (int index = 0; index < e.Actions.Count; ++index)
                {
                    SmartEvent actualEvent = e;

                    if (previousWasWait)
                    {
                        actualEvent = smartFactory.EventFactory(SmartConstants.EVENT_TRIGGER_TIMED);
                        actualEvent.SetParameter(0, nextTriggerId++);
                    }
                    else if (index > 0)
                    {
                        actualEvent = smartFactory.EventFactory(SmartConstants.EVENT_LINK);
                    }

                    int linkTo = (e.Actions.Count - 1 == index ? 0 : eventId + 1);

                    SmartAction actualAction = e.Actions[index];

                    if (actualAction.Id == SmartConstants.ACTION_WAIT)
                    {
                        linkTo = 0;
                        SmartAction waitAction = actualAction;
                        actualAction = smartFactory.ActionFactory(SmartConstants.ACTION_TRIGGER_TIMED, smartFactory.SourceFactory(SmartConstants.SOURCE_NONE), smartFactory.TargetFactory(SmartConstants.TARGET_NONE));
                        actualAction.SetParameter(0, nextTriggerId);
                        actualAction.SetParameter(1, waitAction.GetParameter(0).GetValue());
                        actualAction.SetParameter(2, waitAction.GetParameter(0).GetValue());
                        actualAction.Comment = SmartConstants.COMMENT_WAIT;
                        previousWasWait      = true;
                    }
                    else
                    {
                        previousWasWait = false;
                    }

                    SmartEvent eventToSerialize = actualEvent.ShallowCopy();
                    eventToSerialize.Actions.Add(actualAction.Copy());

                    var serialized =
                        eventToSerialize.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, eventId, linkTo);

                    if (serialized.Length != 1)
                    {
                        throw new InvalidOperationException();
                    }

                    lines.Add(serialized[0]);

                    eventId++;
                }
            }

            return(lines.ToArray());
        }
Example #27
0
        private void AddedAction(SmartAction smartAction, SmartEvent parent, int index)
        {
            PushAction(new ActionAddedAction(parent, smartAction, index));

            BindAction(smartAction);
        }
Example #28
0
 public ActionRemovedAction(SmartEvent parent, SmartAction smartAction, int index)
 {
     _parent      = parent;
     _smartAction = smartAction;
     _index       = index;
 }
Example #29
0
        public (ISmartScriptLine[], IConditionLine[]) ToDatabaseCompatibleSmartScript(SmartScript script)
        {
            if (script.Events.Count == 0)
            {
                return(new ISmartScriptLine[0], null);
            }

            var  eventId         = 0;
            var  lines           = new List <ISmartScriptLine>();
            var  conditions      = new List <IConditionLine>();
            var  previousWasWait = false;
            long nextTriggerId   = script.Events.Where(e => e.Id == SmartConstants.EventTriggerTimed)
                                   .Select(e => e.GetParameter(0).Value)
                                   .DefaultIfEmpty(0)
                                   .Max() + 1;

            foreach (var gv in script.GlobalVariables)
            {
                lines.Add(gv.ToMetaSmartScriptLine(script.EntryOrGuid, script.SourceType, eventId++));
            }

            if (script.SourceType == SmartScriptType.TimedActionList)
            {
                foreach (SmartEvent e in script.Events)
                {
                    for (var index = 0; index < e.Actions.Count; ++index)
                    {
                        SmartEvent eventToSerialize = index == 0 ? e.ShallowCopy() : smartFactory.EventFactory(SmartConstants.EventUpdateInCombat);

                        SmartAction actualAction = e.Actions[index].Copy();
                        AdjustCoreCompatibleAction(actualAction);

                        eventToSerialize.Parent = script;
                        eventToSerialize.Actions.Add(actualAction);

                        var serialized = eventToSerialize.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, eventId++, false, 0);

                        if (serialized.Length != 1)
                        {
                            throw new InvalidOperationException();
                        }

                        lines.Add(serialized[0]);
                    }
                }
            }
            else
            {
                foreach (SmartEvent e in script.Events)
                {
                    if (e.Actions.Count == 0)
                    {
                        continue;
                    }

                    SmartEvent originalEvent = e.ShallowCopy();
                    originalEvent.Parent = script;
                    List <SmartEvent> delayedWaits = new();
                    SmartEvent        lastEvent    = originalEvent;

                    long accumulatedWaits = 0;
                    for (var index = 0; index < e.Actions.Count; ++index)
                    {
                        if (previousWasWait)
                        {
                            var eventTimed = smartFactory.EventFactory(SmartConstants.EventTriggerTimed);
                            eventTimed.Parent = script;
                            eventTimed.GetParameter(0).Value = nextTriggerId++;
                            delayedWaits.Add(eventTimed);
                            lastEvent = eventTimed;
                        }

                        if (e.Actions[index].Id == SmartConstants.ActionWait)
                        {
                            accumulatedWaits += e.Actions[index].GetParameter(0).Value;

                            if (index == e.Actions.Count - 1 || e.Actions[index + 1].Id == SmartConstants.ActionWait)
                            {
                                continue;
                            }

                            SmartAction createTimedAction = smartFactory.ActionFactory(SmartConstants.ActionCreateTimed,
                                                                                       smartFactory.SourceFactory(SmartConstants.SourceNone),
                                                                                       smartFactory.TargetFactory(SmartConstants.TargetNone));
                            createTimedAction.GetParameter(0).Value = nextTriggerId;
                            createTimedAction.GetParameter(1).Value = accumulatedWaits;
                            createTimedAction.GetParameter(2).Value = accumulatedWaits;
                            createTimedAction.Comment = SmartConstants.CommentWait;
                            previousWasWait           = true;

                            originalEvent.AddAction(createTimedAction);
                        }
                        else
                        {
                            previousWasWait = false;
                            SmartAction actualAction = e.Actions[index].Copy();
                            AdjustCoreCompatibleAction(actualAction);
                            lastEvent.AddAction(actualAction);
                        }
                    }

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

                    var serializedConditions = e.ToConditionLines(SmartConstants.ConditionSourceSmartScript, script.EntryOrGuid, script.SourceType, eventId);
                    if (serializedConditions != null)
                    {
                        conditions.AddRange(serializedConditions);
                    }

                    foreach (var toSerialize in new SmartEvent[] { originalEvent }.Concat(delayedWaits))
                    {
                        var serialized = toSerialize.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, eventId, true);
                        eventId += serialized.Length;
                        lines.AddRange(serialized);
                    }
                }
            }

            return(lines.ToArray(), conditions.ToArray());
        }
        private AbstractSmartScriptLine GenerateSingleSai(int eventId, SmartEvent ev, SmartAction action, int link = 0, string comment = null)
        {
            AbstractSmartScriptLine line = new AbstractSmartScriptLine
            {
                EntryOrGuid      = _item.Entry,
                ScriptSourceType = (int)_item.SmartType,
                Id                = eventId,
                Link              = link,
                EventType         = ev.Id,
                EventPhaseMask    = ev.Phases.Value,
                EventChance       = ev.Chance.Value,
                EventFlags        = ev.Flags.Value,
                EventParam1       = ev.GetParameter(0).Value,
                EventParam2       = ev.GetParameter(1).Value,
                EventParam3       = ev.GetParameter(2).Value,
                EventParam4       = ev.GetParameter(3).Value,
                EventCooldownMin  = ev.CooldownMin.Value,
                EventCooldownMax  = ev.CooldownMax.Value,
                ActionType        = action.Id,
                ActionParam1      = action.GetParameter(0).Value,
                ActionParam2      = action.GetParameter(1).Value,
                ActionParam3      = action.GetParameter(2).Value,
                ActionParam4      = action.GetParameter(3).Value,
                ActionParam5      = action.GetParameter(4).Value,
                ActionParam6      = action.GetParameter(5).Value,
                SourceType        = action.Source.Id,
                SourceParam1      = action.Source.GetParameter(0).Value,
                SourceParam2      = action.Source.GetParameter(1).Value,
                SourceParam3      = action.Source.GetParameter(2).Value,
                SourceConditionId = action.Source.Condition.Value,
                TargetType        = action.Target.Id,
                TargetParam1      = action.Target.GetParameter(0).Value,
                TargetParam2      = action.Target.GetParameter(1).Value,
                TargetParam3      = action.Target.GetParameter(2).Value,
                TargetConditionId = action.Target.Condition.Value,
                TargetX           = action.Target.X,
                TargetY           = action.Target.Y,
                TargetZ           = action.Target.Z,
                TargetO           = action.Target.O,
                Comment           = ev.Readable + " - " + action.Readable
            };

            return(line);
        }
 private void DeleteActionCommand(SmartAction obj)
 {
     obj.Parent.Actions.Remove(obj);
 }
 public InspectionResult?Inspect(SmartAction a)
 {
     return(Inspect((SmartBaseElement)a));
 }
Example #33
0
 public ActionRemovedAction(SmartEvent parent, SmartAction smartAction, int index)
 {
     this.parent      = parent;
     this.smartAction = smartAction;
     this.index       = index;
 }