public AI_Command GetAICommand(Cmd_Command command, PlayerDisplay display, out bool mustCheckTrigger) { mustCheckTrigger = true; if (command == null || m_AICmdMap == null) { return(null); } string aiName = command.aiName; if (!string.IsNullOrEmpty(aiName)) { AI_Command cmd; if (!m_AICmdMap.TryGetValue(aiName, out cmd)) { cmd = null; } return(cmd); } else { if (display == null || display.LuaPly == null) { return(null); } AI_Command finder = null; // 遍历所有条件,如果没有满足的再调用LUA的方法GetAIName var iter = m_AICmdMap.GetEnumerator(); while (iter.MoveNext()) { var aiCmd = iter.Current.Value; if (aiCmd != null && aiCmd.OnTriggerEvent != null) { if (aiCmd.CanTrigger(display, command.name)) { mustCheckTrigger = false; finder = aiCmd; break; } } } iter.Dispose(); if (finder != null) { return(finder); } aiName = display.Call_LuaPly_GetAIName(command.name); if (string.IsNullOrEmpty(aiName)) { return(null); } AI_Command cmd; if (!m_AICmdMap.TryGetValue(aiName, out cmd)) { cmd = null; } return(cmd); } }
protected void AddCommand(Cmd_Command command) { if (command == null) { return; } if (m_CommandMap == null) { m_CommandMap = new Dictionary <string, Cmd_Command>(); } m_CommandMap[command.name] = command; }
static int set_name(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); Mugen.Cmd_Command obj = (Mugen.Cmd_Command)o; string arg0 = ToLua.CheckString(L, 2); obj.name = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index name on a nil value")); } }
static int get_aiName(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); Mugen.Cmd_Command obj = (Mugen.Cmd_Command)o; string ret = obj.aiName; LuaDLL.lua_pushstring(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index aiName on a nil value")); } }
// LUA可以调用 public Cmd_Command CreateCommand(string name, string aiName = "") { if (string.IsNullOrEmpty(name)) { return(null); } Cmd_Command ret = GetCommand(name); if (ret != null) { return(ret); } ret = new Cmd_Command(); ret.name = name; ret.aiName = aiName; AddCommand(ret); return(ret); }
static int _CreateMugen_Cmd_Command(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { Mugen.Cmd_Command obj = new Mugen.Cmd_Command(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: Mugen.Cmd_Command.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public bool LoadFromReader(ConfigReader reader) { Clear(); if (reader == null) { return(false); } ConfigSection section = reader.GetSection("Remap"); if (section != null) { m_Remap = new Cmd_Remap(); if (!section.GetPropertysValues(m_Remap)) { m_Remap = null; } } section = reader.GetSection("Defaults"); if (section != null) { for (int i = 0; i < section.ContentListCount; ++i) { string key, value; if (section.GetKeyValue(i, out key, out value)) { if (string.Compare(key, "command.time", true) == 0) { m_Command__Time = int.Parse(value); } else if (string.Compare(key, "command.buffer.time", true) == 0) { m_Command__Buffer__Time = int.Parse(value); } } } } // 创建Command for (int i = 0; i < reader.SectionCount; ++i) { section = reader.GetSections(i); if (section == null) { continue; } if (string.Compare(section.Tile, "Command", true) == 0) { Cmd_Command cmd = null; for (int j = 0; j < section.ContentListCount; ++j) { string key, value; if (section.GetKeyValue(j, out key, out value)) { if (string.Compare(key, "name", true) == 0) { if (cmd == null) { cmd = new Cmd_Command(); } cmd.name = value; } else if (string.Compare(key, "time", true) == 0) { if (cmd == null) { cmd = new Cmd_Command(); } cmd.time = int.Parse(value); } else if (string.Compare(key, "buffer.time", true) == 0) { if (cmd == null) { cmd = new Cmd_Command(); } cmd.buffer__time = int.Parse(value); } else if (string.Compare(key, "command", true) == 0) { if (cmd == null) { cmd = new Cmd_Command(); } cmd.keyCommands = ConfigSection.Split(value); } } } if (cmd != null && !string.IsNullOrEmpty(cmd.name)) { AddCommand(cmd); } } else if (section.Tile.StartsWith("State -1", StringComparison.CurrentCultureIgnoreCase)) { string[] names = ConfigSection.Split(section.Tile); if (names == null || names.Length < 2) { continue; } string aiName = names [1]; AI_Type aiType = AI_Type.none; AI_Command aiCmd = null; for (int j = 0; j < section.ContentListCount; ++j) { string key, value; if (section.GetKeyValue(j, out key, out value)) { if (string.Compare(key, "type", true) == 0) { if (string.Compare(value, "ChangeState", true) == 0) { aiType = AI_Type.ChangeState; if (aiCmd == null) { aiCmd = new AI_Command(); aiCmd.type = aiType; aiCmd.name = aiName; } } } else { if (aiCmd == null) { continue; } if (string.Compare(key, "value", true) == 0) { aiCmd.value = value; } else if (string.Compare(key, "triggerall", true) == 0) { if (value.StartsWith("command", StringComparison.CurrentCultureIgnoreCase)) { int idx = value.IndexOf("="); if (idx >= 0) { aiCmd.command = value.Substring(idx + 1, value.Length - idx - 1).Trim(); if (!string.IsNullOrEmpty(aiCmd.command)) { Cmd_Command cmdCmd = GetCommand(aiCmd.command); if (cmdCmd != null) { cmdCmd.aiName = aiCmd.name; } } } } } } } } if (aiCmd == null || aiCmd.type == AI_Type.none) { continue; } if (m_AICmdMap == null) { m_AICmdMap = new Dictionary <string, AI_Command> (); } m_AICmdMap [aiCmd.name] = aiCmd; } } return(true); }