public SmartEvent EventFactory(ISmartScriptLine line) { SmartEvent ev = EventFactory(line.EventType); ev.Chance.SetValue(line.EventChance); ev.Phases.SetValue(line.EventPhaseMask); ev.Flags.SetValue(line.EventFlags); ev.CooldownMin.SetValue(line.EventCooldownMin); ev.CooldownMax.SetValue(line.EventCooldownMax); for (int i = 0; i < SmartEvent.SmartEventParamsCount; ++i) { ev.SetParameter(i, GetEventParameter(line, i)); } return(ev); }
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()); }
private void BuildInsert() { if (_script.Events.Count == 0) { return; } _sql.AppendLine( "INSERT INTO smart_scripts (entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, target_type, target_param1, target_param2, target_param3, target_x, target_y, target_z, target_o, comment) VALUES"); int eventId = 0; List <string> lines = new List <string>(); bool previousWasWait = false; int nextTriggerId = 1000; //@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(59); actualEvent.SetParameter(0, nextTriggerId++); } else if (index > 0) { actualEvent = smartFactory.EventFactory(61); } int linkTo = (e.Actions.Count - 1 == index ? 0 : eventId + 1); SmartAction actualAction = e.Actions[index]; if (actualAction.Id == 9999) { linkTo = 0; SmartAction waitAction = actualAction; actualAction = smartFactory.ActionFactory(67, smartFactory.SourceFactory(0), smartFactory.TargetFactory(0)); actualAction.SetParameter(0, nextTriggerId); actualAction.SetParameter(1, waitAction.GetParameter(0).GetValue()); actualAction.SetParameter(2, waitAction.GetParameter(0).GetValue()); previousWasWait = true; } else { previousWasWait = false; } lines.Add(GenerateSingleSai(eventId, actualEvent, actualAction, linkTo)); eventId++; } } _sql.Append(string.Join(",\n", lines)); _sql.AppendLine(";"); }