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()))); }
// DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=22 AND `SourceGroup`=12 AND `SourceEntry`=456; // INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES public static string GenerateConditionsSQL(SAIType source_type, int entryorguid, SmartEventsCollection events) { List <string> lines = new List <string>(); foreach (SmartEvent e in events) { int else_group = 0; foreach (SmartCondition condition in e.conditions) { if (condition.ID == CONDITION_LOGICAL_OR._ID) { else_group++; } else { lines.Add(GenerateSingleCondition(condition, source_type, entryorguid, e.actualID, else_group)); } } } string header = "DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=22 AND `SourceEntry`=" + entryorguid + " AND SourceId = " + (int)source_type + ";\n"; header += "INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES\n"; if (lines.Count > 0) { return(header + String.Join(",\n", lines) + ";"); } return(null); }
// DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=22 AND `SourceGroup`=12 AND `SourceEntry`=456; // INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES public static string GenerateConditionsSQL(SAIType source_type, int entryorguid, SmartEventsCollection events) { List<string> lines = new List<string>(); foreach (SmartEvent e in events) { int else_group = 0; foreach(SmartCondition condition in e.conditions) { if (condition.ID == CONDITION_LOGICAL_OR._ID) { else_group++; } else { lines.Add(GenerateSingleCondition(condition, source_type, entryorguid, e.actualID, else_group)); } } } string header = "DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=22 AND `SourceEntry`="+entryorguid+" AND SourceId = "+(int)source_type+";\n"; header += "INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES\n"; if (lines.Count > 0) return header+String.Join(",\n", lines) + ";"; return null; }
public static string GenerateSAISQL(SAIType source_type, int entryorguid, SmartEventsCollection events) { int event_id = 0; List <string> lines = new List <string>(); foreach (SmartEvent e in events) { if (e.GetActions().Count == 0) { continue; } e.actualID = event_id; lines.Add(GenerateSingleSAI(source_type, entryorguid, event_id, e, e.GetAction(0), (e.GetActions().Count == 1 ? 0 : event_id + 1))); event_id++; for (int index = 1; index < e.GetActions().Count; ++index) { lines.Add(GenerateSingleSAI(source_type, entryorguid, event_id, Events.EVENT_LINK.GetInstance(), e.GetAction(index), (e.GetActions().Count - 1 == index ? 0 : event_id + 1))); event_id++; } } return(GenerateHeader(source_type, entryorguid) + String.Join(",\n", lines) + ";"); }
private static string GenerateSingleCondition(SmartCondition condition, SAIType type, int entryorguid, int id, int else_group) { object data = new { source_type = 22, // SMART_EVENT source_group = (id + 1).ToString(), source_entry = entryorguid.ToString(), source_id = ((int)type).ToString(), else_group = else_group.ToString(), condition_id = condition.ID.ToString(), target = ((int)condition.target).ToString(), param1 = condition.parameters[0].GetValue().ToString(), param2 = condition.parameters[1].GetValue().ToString(), param3 = condition.parameters[2].GetValue().ToString(), inversed = (condition.invert?"1":"0"), error_text_id = "", script_name = "", comment = condition.ToString() }; return(SmartFormat.Smart.Format(COND_SQL, data)); }
public StorageType StorageForType(SAIType type, bool guid) { switch (type) { case SAIType.Creature: if (guid) { return(StorageType.CreatureGuid); } return(StorageType.Creature); case SAIType.Gameobject: if (guid) { return(StorageType.GameObjectGuid); } return(StorageType.GameObject); case SAIType.AreaTrigger: return(StorageType.AreaTrigger); case SAIType.TimedActionList: return(StorageType.TimedActionList); } return(StorageType.Creature); }
// DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=22 AND `SourceGroup`=12 AND `SourceEntry`=456; // INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES public static string GenerateConditionsSQL(SAIType source_type, int entryorguid, SmartEventsCollection events) { List <string> lines = new List <string>(); foreach (SmartEvent e in events) { int else_group = 0; foreach (SmartCondition condition in e.conditions) { if (condition.ID == CONDITION_LOGICAL_OR._ID) { else_group++; } else { lines.Add(GenerateSingleCondition(condition, source_type, entryorguid, e.actualID, else_group)); } } } if (lines.Count > 0) { return(String.Join(",\n", lines) + ";"); } return(null); }
public void insert(SAIType type, int entry, string name) { OpenedHistoryAction action = new OpenedHistoryAction(); action.type = type; action.entry = entry; action.name = name; insert(action); }
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())); }
public bool IsEventValidType(string id, SAIType saitype) { if (events_name_types.ContainsKey(id)) { if (events_name_types[id] != null && events_name_types[id].Contains(saitype)) { return(true); } return(false); } return(true); }
//private readonly static string SAI_SQL = " ({entryorguid,13}, {source_type,13}, {id,4}, {linkto,6}, {event_id, 12}, {phasemask,18}, {chance, 3}, {flags}, {event_param1,5}, {event_param2,5}, {event_param3,5}, {event_param4,5}, {action_id}, {action_param1,5}, {action_param2,5}, {action_param3,5}, {action_param4,5}, {action_param5,2}, {action_param6,2}, {target_id}, {target_param1,5}, {target_param2,5}, {target_param3,5}, {target_position}, \"{comment}\")"; // @TODO; so messy xd private static string GenerateHeader(SAIType source_type, int entryorguid) { StringBuilder ret = new StringBuilder(); int guid = 0; int entry = entryorguid; string name = DB.GetInstance().GetString(DB.GetInstance().StorageForType(source_type, (entryorguid < 0)), entryorguid); if (entryorguid < 0) { guid = -entryorguid; entry = 0; } ret.AppendLine("-- " + source_type.ToString() + " " + name + " " + entryorguid + " SAI"); ret.AppendLine("SET @ENTRY := " + entry + ";"); if (guid > 0) { ret.AppendLine("SET @GUID := " + entryorguid + ";"); } switch (source_type) { case SAIType.Creature: ret.AppendLine("UPDATE `creature_template` SET `AIName`=\"SmartAI\" WHERE `entry`= @ENTRY;"); break; case SAIType.Gameobject: ret.AppendLine("UPDATE `gameobject_template` SET `AIName`=\"SmartGameObjectAI\" WHERE `entry`= @ENTRY;"); break; case SAIType.AreaTrigger: ret.AppendLine("DELETE FROM `areatrigger_scripts` WHERE `entry`=@ENTRY;"); ret.AppendLine("INSERT INTO `areatrigger_scripts` (`entry`,`ScriptName`) VALUES (@ENTRY,\"SmartTrigger\");"); break; } ret.AppendLine("DELETE FROM `smart_scripts` WHERE `entryorguid`=@ENTRY AND `source_type`=" + (int)source_type + ";"); ret.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"); return(ret.ToString()); }
private string GetName(SAIType type, int entry) { switch (type) { case SAIType.Creature: if (entry >= 0) { return(DB.GetInstance().GetString(StorageType.Creature, entry)); } return(DB.GetInstance().GetString(StorageType.CreatureGuid, -entry)); case SAIType.Gameobject: if (entry >= 0) { return(DB.GetInstance().GetString(StorageType.GameObject, entry)); } return(DB.GetInstance().GetString(StorageType.GameObjectGuid, -entry)); } return(null); }
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)); }
// DELETE FROM `conditions` WHERE `SourceTypeOrReferenceId`=22 AND `SourceGroup`=12 AND `SourceEntry`=456; // INSERT INTO `conditions` (`SourceTypeOrReferenceId`,`SourceGroup`,`SourceEntry`,`SourceId`,`ElseGroup`,`ConditionTypeOrReference`,`ConditionTarget`,`ConditionValue1`,`ConditionValue2`,`ConditionValue3`,`ErrorTextId`,`ScriptName`,`Comment`) VALUES public static string GenerateConditionsSQL(SAIType source_type, int entryorguid, SmartEventsCollection events) { List<string> lines = new List<string>(); foreach (SmartEvent e in events) { int else_group = 0; foreach(SmartCondition condition in e.conditions) { if (condition.ID == CONDITION_LOGICAL_OR._ID) { else_group++; } else { lines.Add(GenerateSingleCondition(condition, source_type, entryorguid, e.actualID, else_group)); } } } if (lines.Count > 0) return String.Join(",\n", lines) + ";"; return null; }
//private readonly static string SAI_SQL = " ({entryorguid,13}, {source_type,13}, {id,4}, {linkto,6}, {event_id, 12}, {phasemask,18}, {chance, 3}, {flags}, {event_param1,5}, {event_param2,5}, {event_param3,5}, {event_param4,5}, {action_id}, {action_param1,5}, {action_param2,5}, {action_param3,5}, {action_param4,5}, {action_param5,2}, {action_param6,2}, {target_id}, {target_param1,5}, {target_param2,5}, {target_param3,5}, {target_position}, \"{comment}\")"; // @TODO; so messy xd private static string GenerateHeader(SAIType source_type, int entryorguid) { StringBuilder ret = new StringBuilder(); int guid = 0; int entry = entryorguid; string name = DB.GetInstance().GetString(DB.GetInstance().StorageForType(source_type, (entryorguid < 0)), entryorguid); if (entryorguid < 0) { guid = -entryorguid; entry = 0; } ret.AppendLine("-- " +source_type.ToString() + " " + name + " " + entryorguid + " SAI"); ret.AppendLine("SET @ENTRY := "+entry+";"); if (guid > 0) ret.AppendLine("SET @GUID := " + entryorguid + ";"); switch (source_type) { case SAIType.Creature: ret.AppendLine("UPDATE `creature_template` SET `AIName`=\"SmartAI\" WHERE `entry`= @ENTRY;"); break; case SAIType.Gameobject: ret.AppendLine("UPDATE `gameobject_template` SET `AIName`=\"SmartGameObjectAI\" WHERE `entry`= @ENTRY;"); break; case SAIType.AreaTrigger: ret.AppendLine("DELETE FROM `areatrigger_scripts` WHERE `entry`=@ENTRY;"); ret.AppendLine("INSERT INTO `areatrigger_scripts` (`entry`,`ScriptName`) VALUES (@ENTRY,\"SmartTrigger\");"); break; } ret.AppendLine("DELETE FROM `smart_scripts` WHERE `entryorguid`=@ENTRY AND `source_type`="+(int)source_type+";"); ret.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"); return ret.ToString(); }
public static string GenerateSAISQL(SAIType source_type, int entryorguid, SmartEventsCollection events) { int event_id = 0; List<string> lines = new List<string>(); foreach (SmartEvent e in events) { if (e.GetActions().Count == 0) continue; e.actualID = event_id; lines.Add(GenerateSingleSAI(source_type, entryorguid, event_id, e, e.GetAction(0), (e.GetActions().Count == 1 ? 0 : event_id + 1))); event_id++; for (int index = 1; index < e.GetActions().Count; ++index) { lines.Add(GenerateSingleSAI(source_type, entryorguid, event_id, Events.EVENT_LINK.GetInstance(), e.GetAction(index), (e.GetActions().Count -1 == index ? 0 : event_id + 1))); event_id++; } } return GenerateHeader(source_type, entryorguid)+String.Join(",\n", lines) + ";"; }
public SelectSAI(SAIType saitype) { this.type = saitype; InitializeComponent(); }
public OpenedScratch(SAIType type, int entry) : this() { this.type = type; this.entry = entry; }
public EventArgsRequestNewSAIWindow(int entryorguid, SAIType type) { this.entryorguid = entryorguid; this.type = type; }
public void SetSAIType(SAIType type) { saiTypeFilter.Type = type; }
public OpenedHistoryAction(SAIType type, int entry, string name) : this() { this.type = type; this.entry = entry; this.name = name; }
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); }
private string GetName(SAIType type, int entry) { switch (type) { case SAIType.Creature: if (entry >= 0) return DB.GetInstance().GetString(StorageType.Creature, entry); return DB.GetInstance().GetString(StorageType.CreatureGuid, -entry); case SAIType.Gameobject: if (entry >= 0) return DB.GetInstance().GetString(StorageType.GameObject, entry); return DB.GetInstance().GetString(StorageType.GameObjectGuid, -entry); } return null; }
public bool IsEventValidType(string id, SAIType saitype) { if (events_name_types.ContainsKey(id)) { if (events_name_types[id] != null && events_name_types[id].Contains(saitype)) return true; return false; } return true; }
private static string GenerateSingleCondition(SmartCondition condition, SAIType type, int entryorguid, int id, int else_group) { object data = new { source_type = 22, // SMART_EVENT source_group = (id+1).ToString(), source_entry = entryorguid.ToString(), source_id = ((int)type).ToString(), else_group = else_group.ToString(), condition_id = condition.ID.ToString(), target = ((int)condition.target).ToString(), param1 = condition.parameters[0].GetValue().ToString(), param2 = condition.parameters[1].GetValue().ToString(), param3 = condition.parameters[2].GetValue().ToString(), inversed = (condition.invert?"1":"0"), error_text_id = "", script_name = "", comment = condition.ToString() }; return SmartFormat.Smart.Format(COND_SQL, data); }