Exemplo n.º 1
0
        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())));
        }
Exemplo n.º 2
0
 public static SmartFactory GetInstance()
 {
     if (instance == null)
     {
         instance = new SmartFactory();
     }
     return(instance);
 }
Exemplo n.º 3
0
        private static string GenerateActionsCpp(List <SmartAction> actions, string invoker)
        {
            List <string> output = new List <string>();

            foreach (SmartAction action in actions)
            {
                SmartGenericJSONData generic_data        = SmartFactory.GetInstance().GetGenericData(SmartType.SMART_ACTION, action.ID);
                SmartGenericJSONData generic_target_data = SmartFactory.GetInstance().GetGenericData(SmartType.SMART_TARGET, action.Target.ID);
                object data = new
                {
                    pram1value = action.parameters[0].GetValue().ToString(),
                    pram2value = action.parameters[1].GetValue().ToString(),
                    pram3value = action.parameters[2].GetValue().ToString(),
                    pram4value = action.parameters[3].GetValue().ToString(),
                    pram5value = action.parameters[2].GetValue().ToString(),
                    pram6value = action.parameters[3].GetValue().ToString(),
                    target     = (generic_target_data.target_cpp == "invoker" ? invoker : generic_target_data.target_cpp),
                    cbra       = "}",
                    obra       = "{",
                };

                string content = SmartFormat.Smart.Format(generic_data.GetCpp(), data);

                object data2 = new
                {
                    pram1value          = action.Target.parameters[0].GetValue().ToString(),
                    pram2value          = action.Target.parameters[1].GetValue().ToString(),
                    pram3value          = action.Target.parameters[2].GetValue().ToString(),
                    content             = content,
                    content_in_brackets = "{\n" + content + "\n}",
                    cbra = "}",
                    obra = "{",
                };


                output.Add(SmartFormat.Smart.Format(generic_target_data.GetCpp(), data2));
            }

            return(String.Join("\n", output));
        }
Exemplo n.º 4
0
 public static SmartFactory GetInstance()
 {
     if (instance==null)
         instance = new SmartFactory();
     return instance;
 }