public void RunAreaLuaFile(GameMap gameMap, int areaLuaID, string functionName) { GAreaLua areaLua = gameMap.GetAreaLuaByID(areaLuaID); if (null != areaLua) { string fileName = areaLua.LuaScriptFileName; if (!string.IsNullOrEmpty(fileName)) { ProcessAreaScripts.ProcessScripts(this, fileName, functionName, areaLuaID); } } }
/// <summary> /// 初始化安全区列表特效 /// </summary> //public void InitSafeRegionListDeco() //{ // for (int i = 0; i < SafeRegionList.Count; i++) // { // InitSafeRegionDeco(SafeRegionList[i]); // } //} /// <summary> /// 初始化安全区特效 /// </summary> /// <param name="safeRegion"></param> //private void InitSafeRegionDeco(GSafeRegion safeRegion) //{ // Point pos = new Point(0, 0); // for (int gridX = (int)safeRegion.CenterPoint.X; gridX <= (int)safeRegion.CenterPoint.X + (int)safeRegion.Radius; gridX++) // { // int absGridX = (gridX - (int)safeRegion.CenterPoint.X); // int absGridY = (int)safeRegion.Radius - absGridX; // int gridY1 = (int)safeRegion.CenterPoint.Y - absGridY; // int gridY2 = (int)safeRegion.CenterPoint.Y + absGridY; // pos = new Point(gridX * MapGridWidth + MapGridWidth / 2, gridY1 * MapGridHeight + MapGridHeight / 2); // DecorationManager.AddDecoToMap(MapCode, -1, pos, 515, 0, 0, false); // pos = new Point(gridX * MapGridWidth + MapGridWidth / 2, gridY2 * MapGridHeight + MapGridHeight / 2); // DecorationManager.AddDecoToMap(MapCode, -1, pos, 515, 0, 0, false); // if (gridX > (int)safeRegion.CenterPoint.X) // { // pos = new Point(((int)safeRegion.CenterPoint.X - absGridX) * MapGridWidth + MapGridWidth / 2, gridY1 * MapGridHeight + MapGridHeight / 2); // DecorationManager.AddDecoToMap(MapCode, -1, pos, 515, 0, 0, false); // pos = new Point(((int)safeRegion.CenterPoint.X - absGridX) * MapGridWidth + MapGridWidth / 2, gridY2 * MapGridHeight + MapGridHeight / 2); // DecorationManager.AddDecoToMap(MapCode, -1, pos, 515, 0, 0, false); // } // } //} /// <summary> /// 加载区域脚本 /// </summary> private void LoadAreaLua() { Trace.Assert(MapGridWidth > 0); Trace.Assert(MapGridHeight > 0); //首先根据地图编号定位地图文件 string name = string.Format("Map/{0}/AreaLua.xml", MapCode); XElement xml = null; try { xml = Global.GetGameResXml(name); } catch (Exception) { throw new Exception(string.Format("启动时加载xml文件: {0} 失败", name)); } IEnumerable <XElement> images = xml.Element("Areas").Elements(); if (null == images) { return; } // Read the entire XML AreaLuaList = new List <GAreaLua>(); foreach (var image_item in images) { int id = (int)Global.GetSafeAttributeLong(image_item, "ID"); int posX = (int)Global.GetSafeAttributeLong(image_item, "X"); int posY = (int)Global.GetSafeAttributeLong(image_item, "Y"); int radius = (int)Global.GetSafeAttributeLong(image_item, "Radius"); string luaScriptFile = Global.GetSafeAttributeStr(image_item, "LuaScriptFile"); GAreaLua areaLua = new GAreaLua() { ID = id, CenterPoint = new Point((int)(posX / MapGridWidth), (int)(posY / MapGridHeight)), Radius = (int)(radius / MapGridWidth), LuaScriptFileName = luaScriptFile, }; AreaLuaList.Add(areaLua); } xml = null; }
/// <summary> /// 执行区域脚本 /// </summary> /// <param name="areaLuaID"></param> /// <param name="functionName"></param> private void RunAreaLuaFile(GameMap gameMap, int areaLuaID, string functionName) { GAreaLua areaLua = gameMap.GetAreaLuaByID(areaLuaID); if (null == areaLua) { return; } string fileName = areaLua.LuaScriptFileName; if (!string.IsNullOrEmpty(fileName)) { /*string luaFileName = Global.GetAreaLuaScriptFile(fileName); * if (!string.IsNullOrEmpty(luaFileName)) * { * ////执行对话脚本 * Global.ExcuteLuaFunction(this, luaFileName, functionName, null, null); * }*/ ProcessAreaScripts.ProcessScripts(this, fileName, functionName); } }
private void LoadAreaLua() { Trace.Assert(this.MapGridWidth > 0); Trace.Assert(this.MapGridHeight > 0); string name = string.Format("Map/{0}/AreaLua.xml", this.MapCode); XElement xml = null; try { xml = Global.GetResXml(name); } catch (Exception) { throw new Exception(string.Format("启动时加载xml文件: {0} 失败", name)); } IEnumerable <XElement> images = xml.Element("Areas").Elements(); if (null != images) { this.AreaLuaList = new List <GAreaLua>(); foreach (XElement image_item in images) { int id = (int)Global.GetSafeAttributeLong(image_item, "ID"); int posX = (int)Global.GetSafeAttributeLong(image_item, "X"); int posY = (int)Global.GetSafeAttributeLong(image_item, "Y"); int radius = (int)Global.GetSafeAttributeLong(image_item, "Radius"); string luaScriptFile = Global.GetSafeAttributeStr(image_item, "LuaScriptFile"); int taskId = 0; AddtionType addtionType = AddtionType.NowTrigger; Dictionary <AreaEventType, List <int> > eventDict = new Dictionary <AreaEventType, List <int> >(); if (image_item.Attribute("Touch") != null) { string[] addtionInfo = Global.GetSafeAttributeStr(image_item, "Touch").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (addtionInfo.Length > 1) { addtionType = (AddtionType)Convert.ToInt32(addtionInfo[0]); taskId = Convert.ToInt32(addtionInfo[1]); } string[] eventInfos = Global.GetSafeAttributeStr(image_item, "Event").Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); foreach (string eventInfo in eventInfos) { List <int> eventValues = new List <int>(); string[] data = eventInfo.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); if (data.Length > 1) { for (int i = 1; i < data.Length; i++) { eventValues.Add(Convert.ToInt32(data[i])); } eventDict.Add((AreaEventType)Convert.ToInt32(data[0]), eventValues); } } } GAreaLua areaLua = new GAreaLua { ID = id, CenterPoint = new Point((double)(posX / this.MapGridWidth), (double)(posY / this.MapGridHeight)), Radius = Math.Max(radius / this.MapGridWidth, 1), LuaScriptFileName = luaScriptFile, AddtionType = addtionType, TaskId = taskId, AreaEventDict = eventDict }; this.AreaLuaList.Add(areaLua); } xml = null; } }
public void RunAreaLuaFile(GameMap gameMap, RunAreaLuaType runAreaLuaType, List <int> areaLuaIDList, string functionName, int taskId = 0) { List <GAreaLua> GAreaLuaList = null; if (RunAreaLuaType.SelfPoint == runAreaLuaType) { int newGridX = this._ClientData.PosX / gameMap.MapGridWidth; int newGridY = this._ClientData.PosY / gameMap.MapGridHeight; GAreaLuaList = gameMap.GetAreaLuaListByPoint(new Point((double)newGridX, (double)newGridY)); } else if (RunAreaLuaType.AreaLuaIDList == runAreaLuaType) { if (areaLuaIDList == null || areaLuaIDList.Count == 0) { return; } foreach (int areaLuaID in areaLuaIDList) { GAreaLua areaLua = gameMap.GetAreaLuaByID(areaLuaID); if (areaLua != null) { if (GAreaLuaList == null) { GAreaLuaList = new List <GAreaLua>(); } GAreaLuaList.Add(areaLua); } } } if (GAreaLuaList != null) { using (List <GAreaLua> .Enumerator enumerator2 = GAreaLuaList.GetEnumerator()) { while (enumerator2.MoveNext()) { GAreaLua areaLuaEv = enumerator2.Current; bool isTrigger = false; if (areaLuaEv.AddtionType != AddtionType.NowTrigger) { switch (areaLuaEv.AddtionType) { case AddtionType.AccessTask: { TaskData taskData; lock (this.ClientData.TaskDataList) { taskData = this.ClientData.TaskDataList.Find((TaskData x) => x.DoingTaskID == areaLuaEv.TaskId); if (taskData == null) { break; } } SystemXmlItem systemTask = null; if (GameManager.SystemTasksMgr.SystemXmlItemDict.TryGetValue(areaLuaEv.TaskId, out systemTask)) { if (taskData.DoingTaskVal1 < systemTask.GetIntValue(string.Format("TargetNum1", new object[0]), -1) || taskData.DoingTaskVal2 < systemTask.GetIntValue(string.Format("TargetNum2", new object[0]), -1)) { isTrigger = true; } } break; } case AddtionType.FinishTask: { TaskData taskData; lock (this.ClientData.TaskDataList) { taskData = this.ClientData.TaskDataList.Find((TaskData x) => x.DoingTaskID == areaLuaEv.TaskId); if (taskData == null) { break; } } if (Global.JugeTaskComplete(this, areaLuaEv.TaskId, taskData.DoingTaskVal1, taskData.DoingTaskVal2)) { isTrigger = true; } break; } case AddtionType.BackTask: if (taskId != 0) { if (areaLuaEv.TaskId == taskId) { isTrigger = true; } } break; case AddtionType.NewMainTask: if (functionName == "takeNewMainTask" && taskId == areaLuaEv.TaskId) { isTrigger = true; } break; } if (!isTrigger) { continue; } } foreach (KeyValuePair <AreaEventType, List <int> > areaEvent in areaLuaEv.AreaEventDict) { if (areaEvent.Key == AreaEventType.FinishTask) { int eventTaskId = areaEvent.Value[0]; TaskData taskData = this.ClientData.TaskDataList.Find((TaskData x) => x.DoingTaskID == eventTaskId); SystemXmlItem systemTask = null; if (GameManager.SystemTasksMgr.SystemXmlItemDict.TryGetValue(eventTaskId, out systemTask)) { if (taskData.DoingTaskVal1 < systemTask.GetIntValue("TargetNum1", -1)) { taskData.DoingTaskVal1 = systemTask.GetIntValue("TargetNum1", -1); } if (taskData.DoingTaskVal2 < systemTask.GetIntValue("TargetNum2", -1)) { taskData.DoingTaskVal2 = systemTask.GetIntValue("TargetNum2", -1); } GameManager.DBCmdMgr.AddDBCmd(10007, string.Format("{0}:{1}:{2}:{3}:{4}:{5}", new object[] { this.ClientData.RoleID, taskData.DoingTaskID, taskData.DbID, taskData.DoingTaskFocus, taskData.DoingTaskVal1, taskData.DoingTaskVal2 }), null, this.ServerId); GameManager.ClientMgr.NotifyUpdateTask(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, this, taskData.DbID, taskData.DoingTaskID, taskData.DoingTaskVal1, taskData.DoingTaskVal2, taskData.DoingTaskFocus, taskData.ChengJiuVal); int destNPC = systemTask.GetIntValue("DestNPC", -1); if (-1 != destNPC) { int state = Global.ComputeNPCTaskState(this, this.ClientData.TaskDataList, destNPC, 0); GameManager.ClientMgr.NotifyUpdateNPCTaskSate(Global._TCPManager.MySocketListener, Global._TCPManager.TcpOutPacketPool, this, destNPC + 2130706432, state); } ProcessTask.CheckAutoCompleteTask(this); } } else if (areaEvent.Key == AreaEventType.CallMonsters && functionName == "enterArea") { int monsterID = areaEvent.Value[0]; Global.SystemKillSummonMonster(this, MonsterTypes.AreaCallMonster); GameManager.LuaMgr.CallMonstersForGameClient(this, monsterID, 1, 0, 1002, 1); } else if (areaEvent.Key == AreaEventType.RemoveMonsters && functionName == "enterArea") { int monsterid = areaEvent.Value[0]; Global.SystemKillSummonMonster(this, monsterid); } else { string strCmd = string.Format("{0}:{1}:{2}:{3}", new object[] { (int)areaEvent.Key, areaEvent.Value[0], areaLuaEv.CenterPoint.X, areaLuaEv.CenterPoint.Y }); this.sendCmd(3000, strCmd, false); } } string fileName = areaLuaEv.LuaScriptFileName; if (!string.IsNullOrEmpty(fileName)) { ProcessAreaScripts.ProcessScripts(this, fileName, functionName, areaLuaEv.ID); } } } } }