public static string GenerateSAICpp(SAIType source_type, int entryorguid, SmartEventsCollection events) { Dictionary <EventMethod, List <SmartEvent> > methods = new Dictionary <EventMethod, List <SmartEvent> >(); StringBuilder output = new StringBuilder(); foreach (SmartEvent ev in events) { SmartGenericJSONData generic_data = SmartFactory.GetInstance().GetGenericData(SmartType.SMART_EVENT, ev.ID); if (!methods.ContainsKey(generic_data.event_method)) { methods.Add(generic_data.event_method, new List <SmartEvent>()); } methods[generic_data.event_method].Add(ev); } foreach (EventMethod event_method in methods.Keys) { cppMethodAttribute method_data = Extensions.GetAttribute <cppMethodAttribute>(event_method); InvokerAttribute invoker_data = Extensions.GetAttribute <InvokerAttribute>(event_method); output.AppendLine(method_data.method); output.AppendLine("{"); string invoker = "me"; if (invoker_data != null) { invoker = invoker_data.invoker; } int id = 0; foreach (SmartEvent ev in methods[event_method]) { SmartGenericJSONData generic_data = SmartFactory.GetInstance().GetGenericData(SmartType.SMART_EVENT, ev.ID); id++; string actions = GenerateActionsCpp(ev.actions, invoker); object data = new { pram1value = ev.parameters[0].GetValue().ToString(), pram2value = ev.parameters[1].GetValue().ToString(), pram3value = ev.parameters[2].GetValue().ToString(), pram4value = ev.parameters[3].GetValue().ToString(), content = actions, content_in_brackets = "{\n" + actions + "\n}", no_id = id.ToString(), cbra = "}", obra = "{", }; output.AppendLine(SmartFormat.Smart.Format(generic_data.GetCpp(), data)); } output.AppendLine("}\n"); } string npc = DB.GetInstance().GetString(DB.GetInstance().StorageForType(SAIType.Creature, entryorguid < 0), entryorguid); return(Indent(GenerateScriptedAIHeader(npc, output.ToString()))); }
internal ActorType(Type actor, Type endpoint) { this.actor = actor; Name = ActorTypeName.Of(actor); Sticky = StickyAttribute.IsApplied(actor); keepAliveTimeout = Sticky ? TimeSpan.FromDays(365 * 10) : KeepAliveAttribute.Timeout(actor); Invoker = InvocationPipeline.Instance.GetInvoker(actor, InvokerAttribute.From(actor)); interleavePredicate = ReentrantAttribute.MayInterleavePredicate(actor); dispatcher = new Dispatcher(actor); dispatchers.Add(actor, dispatcher); Init(endpoint); }
internal ActorType(Type @class, ActorInterface @interface, Type grain, string[] conventions) { Class = @class; Interface = @interface; Grain = grain; TypeCode = grain.TypeCode(); Sticky = StickyAttribute.IsApplied(@class); keepAliveTimeout = Sticky ? TimeSpan.FromDays(365 * 10) : KeepAliveAttribute.Timeout(@class); interleavePredicate = InterleaveAttribute.MayInterleavePredicate(@class); invoker = InvokerAttribute.From(@class); dispatcher = new Dispatcher(@class, conventions); dispatchers.Add(@class, dispatcher); Init(grain); }