public void Load(IEnumerable <ISmartScriptLine> lines) { int? entry = null; SmartScriptType?source = null; int previousLink = -1; SmartEvent currentEvent = null; foreach (var line in lines) { if (!entry.HasValue) { entry = line.EntryOrGuid; } else { Debug.Assert(entry.Value == line.EntryOrGuid); } if (!source.HasValue) { source = (SmartScriptType)line.ScriptSourceType; } else { Debug.Assert((int)source.Value == line.ScriptSourceType); } if (previousLink != line.Id) { currentEvent = SafeEventFactory(line); if (currentEvent != null) { Events.Add(currentEvent); } else { continue; } } var action = SafeActionFactory(line); if (action != null) { currentEvent.AddAction(action); } previousLink = line.Link; } }
public void Load(IEnumerable <ISmartScriptLine> lines) { int? entry = null; SmartScriptType?source = null; int previousLink = -1; SmartEvent currentEvent = null; foreach (var line in lines) { if (!entry.HasValue) { entry = line.EntryOrGuid; } else { Debug.Assert(entry.Value == line.EntryOrGuid); } if (!source.HasValue) { source = (SmartScriptType)line.ScriptSourceType; } else { Debug.Assert((int)source.Value == line.ScriptSourceType); } if (previousLink != line.Id) { currentEvent = _container.Resolve <ISmartFactory>().EventFactory(line); Events.Add(currentEvent); } currentEvent.AddAction(_container.Resolve <ISmartFactory>().ActionFactory(line)); previousLink = line.Link; } }
public void InsertFromClipboard(int index, IEnumerable <ISmartScriptLine> lines) { SmartEvent currentEvent = null; int prevIndex = 0; foreach (var line in lines) { if (currentEvent == null || prevIndex != line.Id) { prevIndex = line.Id; currentEvent = SafeEventFactory(line); Events.Insert(index++, currentEvent); } if (line.ActionType != -1) { var action = SafeActionFactory(line); if (action != null) { currentEvent.AddAction(action); } } } }
public SmartGenericJsonData?TryGetEventData(SmartEvent e) => smartDataManager.Contains(SmartType.SmartEvent, e.Id) ? smartDataManager.GetRawData(SmartType.SmartEvent, e.Id) : null;
public SmartGenericJsonData GetEventData(SmartEvent e) => smartDataManager.GetRawData(SmartType.SmartEvent, e.Id);
public void Load(IEnumerable <ISmartScriptLine> lines) { int? entry = null; SmartScriptType?source = null; int previousLink = -1; SmartEvent currentEvent = null; SortedDictionary <int, SmartEvent> triggerIdToActionParent = new(); SortedDictionary <int, SmartEvent> triggerIdToEvent = new(); foreach (var line in lines) { if (!entry.HasValue) { entry = line.EntryOrGuid; } else { Debug.Assert(entry.Value == line.EntryOrGuid); } if (!source.HasValue) { source = (SmartScriptType)line.ScriptSourceType; } else { Debug.Assert((int)source.Value == line.ScriptSourceType); } if (previousLink != line.Id) { currentEvent = SafeEventFactory(line); if (currentEvent != null) { if (currentEvent.Id == SmartConstants.EVENT_TRIGGER_TIMED) { triggerIdToEvent[currentEvent.GetParameter(0).Value] = currentEvent; } Events.Add(currentEvent); } else { continue; } } var comment = line.Comment.Contains(" // ") ? line.Comment.Substring(line.Comment.IndexOf(" // ") + 4).Trim() : ""; var action = SafeActionFactory(line); if (action != null) { if (comment != SmartConstants.COMMENT_WAIT) { action.Comment = comment; } if (action.Id == SmartConstants.ACTION_TRIGGER_TIMED && comment == SmartConstants.COMMENT_WAIT) { triggerIdToActionParent[action.GetParameter(0).Value] = currentEvent; } currentEvent.AddAction(action); } previousLink = line.Link; } var sortedTriggers = triggerIdToEvent.Keys.ToList(); sortedTriggers.Reverse(); foreach (int triggerId in sortedTriggers) { var @event = triggerIdToEvent[triggerId]; if (!triggerIdToActionParent.ContainsKey(triggerId)) { continue; } var caller = triggerIdToActionParent[triggerId]; var lastAction = caller.Actions[caller.Actions.Count - 1]; if (lastAction.Id != SmartConstants.ACTION_TRIGGER_TIMED || lastAction.GetParameter(1).Value != lastAction.GetParameter(2).Value) { continue; } var waitTime = lastAction.GetParameter(1).Value; var waitAction = smartFactory.ActionFactory(SmartConstants.ACTION_WAIT, smartFactory.SourceFactory(SmartConstants.SOURCE_NONE), smartFactory.TargetFactory(SmartConstants.TARGET_NONE)); waitAction.SetParameter(0, waitTime); caller.Actions.RemoveAt(caller.Actions.Count - 1); caller.AddAction(waitAction); foreach (var a in @event.Actions) { caller.AddAction(a); } Events.Remove(@event); } }
public void Load(IList <ISmartScriptLine> lines, IList <IConditionLine> conditions) { int? entry = null; SmartScriptType?source = null; var conds = ParseConditions(conditions); SortedDictionary <long, SmartEvent> triggerIdToActionParent = new(); SortedDictionary <long, SmartEvent> triggerIdToEvent = new(); Dictionary <int, SmartEvent> linkToSmartEventParent = new(); // find double links (multiple events linking to same event, this is not supported by design) var doubleLinks = lines .Where(line => line.Link > 0) .GroupBy(link => link.Link) .Where(pair => pair.Count() > 1) .Select(pair => pair.Key) .ToHashSet(); Dictionary <int, int> linkToTriggerTimedEventId = null; if (doubleLinks.Count > 0) { int nextFreeTriggerTimedEvent = lines.Where(e => e.Id == SmartConstants.EventTriggerTimed) .Select(e => (int)e.EventParam1) .DefaultIfEmpty(0) .Max() + 1; linkToTriggerTimedEventId = doubleLinks.Select(linkId => (linkId, nextFreeTriggerTimedEvent++)) .ToDictionary(pair => pair.linkId, pair => pair.Item2); } foreach (ISmartScriptLine line in lines) { SmartEvent currentEvent = null; if (!entry.HasValue) { entry = line.EntryOrGuid; } else { Debug.Assert(entry.Value == line.EntryOrGuid); } if (!source.HasValue) { source = (SmartScriptType)line.ScriptSourceType; } else { Debug.Assert((int)source.Value == line.ScriptSourceType); } if (!linkToSmartEventParent.TryGetValue(line.Id, out currentEvent)) { currentEvent = SafeEventFactory(line); if (currentEvent != null) { if (currentEvent.Id == SmartConstants.EventTriggerTimed) { triggerIdToEvent[currentEvent.GetParameter(0).Value] = currentEvent; } else if (currentEvent.Id == SmartConstants.EventLink && doubleLinks.Contains(line.Id)) { smartFactory.UpdateEvent(currentEvent, SmartConstants.EventTriggerTimed); currentEvent.GetParameter(0).Value = linkToTriggerTimedEventId ![line.Id];
public SmartValidationContext(SmartScriptBase script, SmartEvent @event, SmartAction?action) { this.script = script; this.@event = @event; this.action = action; }