public static string SerializeArguments(object[] args) { if (args == null || args.Length == 0) { return "\xC0"; } var table = new LuaTable(); for (int i = 1; i <= args.Length; i++) { table[i] = args[i - 1]; } /*dynamic luaEnvironment = ScriptEnvironment.CurrentEnvironment.LuaEnvironment; dynamic msgpack = luaEnvironment.msgpack; dynamic pack = msgpack.pack; string str = pack(table);*/ var luaEnvironment = ScriptEnvironment.CurrentEnvironment.LuaEnvironment; var method = (Func<object, LuaResult>)((LuaTable)luaEnvironment["msgpack"])["pack"]; return method(table).ToString(); }
public void OnAllKilled(LuaTable actors, LuaFunction func) { List<Actor> group = new List<Actor>(); foreach (var kv in actors) { Actor actor; if (!kv.Value.TryGetClrValue<Actor>(out actor)) throw new LuaException("OnAllKilled requires a table of int,Actor pairs. Recieved {0},{1}".F(kv.Key.GetType().Name, kv.Value.GetType().Name)); group.Add(actor); } var copy = (LuaFunction)func.CopyReference(); Action<Actor> OnMemberKilled = m => { group.Remove(m); if (!group.Any()) { copy.Call(); copy.Dispose(); } }; foreach (var a in group) GetScriptTriggers(a).OnKilledInternal += OnMemberKilled; }
public void Reload() { CacheTable = null; var ret = LuaModule.Instance.CallScript(LuaPath); Debuger.Assert(ret is LuaTable, "{0} Script Must Return Lua Table with functions!", LuaPath); CacheTable = ret as LuaTable; }
public static LuaTable CreateMetaTable() { LuaTable metatable = new LuaTable(); RegisterFunctions(metatable); metatable.SetNameValue("__index", metatable); return metatable; }
void Awake() { scriptEnv = luaEnv.NewTable(); LuaTable meta = luaEnv.NewTable(); meta.Set("__index", luaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } luaEnv.DoString(luaScript.text, "LuaBehaviour", scriptEnv); Action luaAwake = scriptEnv.Get<Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
public static LuaValue date(LuaValue[] values) { LuaString format = values[0] as LuaString; if (format != null) { if (format.Text == "*t") { LuaTable table = new LuaTable(); DateTime now = DateTime.Now; table.SetNameValue("year", new LuaNumber (now.Year)); table.SetNameValue("month", new LuaNumber (now.Month )); table.SetNameValue("day", new LuaNumber (now.Day)); table.SetNameValue("hour", new LuaNumber (now.Hour)); table.SetNameValue("min", new LuaNumber (now.Minute)); table.SetNameValue("sec", new LuaNumber (now.Second)); table.SetNameValue("wday", new LuaNumber ((int)now.DayOfWeek)); table.SetNameValue("yday", new LuaNumber (now.DayOfYear)); table.SetNameValue("isdst", LuaBoolean.From(now.IsDaylightSavingTime())); } else { return new LuaString(DateTime.Now.ToString(format.Text)); } } return new LuaString (DateTime.Now.ToString ());//[PixelCrushers].ToShortDateString()); }
public static LuaTable ToLuaTable(object o) { LuaTable ret = new LuaTable(); // check if Dictionary... System.Collections.IDictionary dict = o as System.Collections.IDictionary; if (dict != null) { foreach (object obj in dict.Keys) { ret.SetKeyValue(ToLuaValue(obj), ToLuaValue(dict[obj])); } return ret; } System.Collections.IEnumerable ie = (o as System.Collections.IEnumerable); if (ie != null) { foreach (object obj in ie) { ret.AddValue(ToLuaValue(obj)); } return ret; } // check if <type>... // not an array type ret.AddValue(ToLuaValue(o)); return ret; }
public void TestMember05() { dynamic t = new LuaTable(); t.hallo = 42; t.hallo1 = 43; TestResult(new LuaResult(t.hallo, t.hallo1), 42, 43); }
void Start() { lua = new LuaSvr(); self = (LuaTable)lua.start("LuaFiles/building_txt"); //self = (LuaTable)lua.luaState.getObject("data"); //object o = lua.luaState.getFunction("GetData").call(); Debug.Log("table " + ((LuaTable)self[1])["name"]); LuaFunction dataFunction = ((LuaFunction)self["GetData"]); LuaTable dataTable = (LuaTable)dataFunction.call(); LuaFunction callFunction = (LuaFunction)self["CallBack"]; callFunction.call(222); //lua.luaState.getFunction("CallBack").call(); lua.luaState.getFunction("Call").call(2); Debug.Log("table " + ((LuaTable)dataTable[1])["use_money"] + " is Null " + (callFunction == null)); LuaTable d = (LuaTable)((LuaFunction)self["GetData1"]).call(); Debug.Log("---------------- : " + ((LuaTable)d[1])["use_money"]); LuaTable table2 = (LuaTable)lua.start("LuaFiles/building_txt1"); test2 = (LuaFunction)self["test"]; object o = test2.call(self,9,1); Debug.Log("add function :"+o); SetTransform = (LuaFunction)self["SetTransform"]; SetTransform.call(self, tr); //tr.localPosition = new Vector3(2, 2, 2); }
public Actor Create(string type, bool addToWorld, LuaTable initTable) { var initDict = new TypeDictionary(); // Convert table entries into ActorInits foreach (var kv in initTable) { // Find the requested type var typeName = kv.Key.ToString(); var initType = Game.modData.ObjectCreator.FindType(typeName + "Init"); if (initType == null) throw new LuaException("Unknown initializer type '{0}'".F(typeName)); // Cast it up to an IActorInit<T> var genericType = initType.GetInterfaces() .First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IActorInit<>)); var innerType = genericType.GetGenericArguments().First(); // Try and coerce the table value to the required type object value; if (!kv.Value.TryGetClrValue(innerType, out value)) throw new LuaException("Invalid data type for '{0}' (expected '{1}')".F(typeName, innerType.Name)); // Construct the ActorInit. Phew! var test = initType.GetConstructor(new[] { innerType }).Invoke(new[] { value }); initDict.Add(test); } // The actor must be added to the world at the end of the tick var a = context.World.CreateActor(false, type, initDict); if (addToWorld) context.World.AddFrameEndTask(w => w.Add(a)); return a; }
public static void InsertMarketData(int id, int version, LuaTable data) { if (dataMap.ContainsKey(id)) { dataMap.Remove(id); } MarketData d = new MarketData(); d.id = id; d.marketVersion = version; d.hot = Int32.Parse((string)data["1"]); d.hotSort = Int32.Parse((string)data["2"]); d.jewel = Int32.Parse((string)data["3"]); d.jewelSort = Int32.Parse((string)data["4"]); d.item = Int32.Parse((string)data["5"]); d.itemSort = Int32.Parse((string)data["6"]); d.wing = Int32.Parse((string)data["7"]); d.wingSort = Int32.Parse((string)data["8"]); d.mode = Int32.Parse((string)data["9"]); d.label = Int32.Parse((string)data["10"]); d.itemId = Int32.Parse((string)data["11"]); d.itemNumber = Int32.Parse((string)data["12"]); d.priceOrg = Int32.Parse((string)data["13"]); d.priceNow = Int32.Parse((string)data["14"]); d.vipLevel = Int32.Parse((string)data["15"]); d.totalCount = Int32.Parse((string)data["16"]); d.startTime = null; d.duration = Int32.Parse((string)data["18"]); dataMap.Add(id, d); }
public static void LoadLibrary(LuaInstance lua) { LuaTable table = new LuaTable(); table["log"] = new Action<int, string>(log); lua.Register("aero", table); }
public static string ToString(LuaTable table, LuaComment headComment = null) { using (var stringWriter = new StringWriter()) { Write(table, stringWriter, headComment); return stringWriter.ToString(); } }
private static IEnumerable<LuaValue> CreateEnumerateArrayEnumerable(LuaTable self) { // By convention, the 'n' field refers to the array length, if present. using (var n = self["n"]) { var num = n as LuaNumber; if (num != null) { var length = (int)num.Value; for (int i = 1; i <= length; ++i) { yield return self[i]; } yield break; } } // If no 'n' then stop at the first nil element. for (int i = 1; ; ++i) { var value = self[i]; if (value.IsNil()) { yield break; } yield return value; } }
void Awake() { scriptEnv = LuaEnv.NewTable(); LuaTable meta = LuaEnv.NewTable(); meta.Set("__index", LuaEnv.Global); scriptEnv.SetMetaTable(meta); meta.Dispose(); scriptEnv.Set("self", this); foreach (var injection in injections) { scriptEnv.Set(injection.name, injection.value); } TextAsset text = Application.Make<IResources>().Load<TextAsset>(luaPath); LuaEnv.DoString(text.text, "LuaBehaviour", scriptEnv); Action luaAwake = scriptEnv.Get<Action>("awake"); scriptEnv.Get("start", out luaStart); scriptEnv.Get("update", out luaUpdate); scriptEnv.Get("ondestroy", out luaOnDestroy); if (luaAwake != null) { luaAwake(); } }
void Awake() { _instance = this; svr = new LuaSvr(); self = (LuaTable)svr.start("LuaFiles/LuaCallCsAPI"); self["event"] = DataEventSource.Instance; self["name"] = "API"; }
void Start () { svr = new LuaSvr(); svr.init(null, () => { self = (LuaTable)svr.start("circle/circle"); update = (LuaFunction)self["update"]; }); }
/* * Gets the function called name from the provided table, * returning null if it does not exist */ public static LuaFunction getTableFunction(LuaTable luaTable, string name) { object funcObj = luaTable.rawget(name); if(funcObj is LuaFunction) return (LuaFunction)funcObj; else return null; }
/// <summary> /// Creates a new Lua environment and registers various classes and functions from the game to it. /// </summary> public void initializeLua() { global = compiler.CreateEnvironment(); game = new LuaTable(); global["Game"] = game; global["Log"] = new Action<string>(Logger.Log); global["GAME_DIR"] = GAME_DIR_DEFAULT; //TODO: make this load from some kind of config file and only fail to this default global["runFile"] = new Action<string, LuaTable>(runLuaFile); LuaTable loadingInterface = new LuaTable(); loadingInterface["display"] = new Action<string>(Screens.LoadingScreen.Display); loadingInterface["change"] = new Action<string>(Screens.LoadingScreen.ChangeMessage); game["LoadingScreen"] = loadingInterface; game["loadVoxtures"] = new Func<string, LuaTable>(loadVoxtures); LuaType.RegisterTypeAlias("material", typeof(OutpostLibrary.Content.Material)); LuaTable mat = new LuaTable(); game["Material"] = LuaType.GetType(typeof(OutpostLibrary.Content.Material)); game["Transparency"] = LuaType.GetType(typeof(OutpostLibrary.Content.Transparency)); game["Solidity"] = LuaType.GetType(typeof(OutpostLibrary.Content.Solidity)); //TODO: solidity should be a lua-side thing game["Sizes"] = LuaType.GetType(typeof(OutpostLibrary.Navigation.Sizes)); game["Directions"] = LuaType.GetType(typeof(OutpostLibrary.Navigation.Directions)); game["map"] = MainGame.mainGame; //TODO: this clearly needs reworked global["twoDArray"] = new Func<int, LuaTable[,]>(delegate(int size) { return new LuaTable[size, size]; }); global["threeDArray"] = new Func<int, LuaTable[, ,]>(delegate(int size) { return new LuaTable[size, size, size]; }); LuaType.RegisterTypeAlias("IntVector3", typeof(OutpostLibrary.IntVector3)); global["IntVector3"] = LuaType.GetType(typeof(OutpostLibrary.IntVector3)); LuaType.RegisterTypeAlias("Vector3", typeof(Microsoft.Xna.Framework.Vector3)); global["Vector3"] = LuaType.GetType(typeof(Microsoft.Xna.Framework.Vector3)); LuaType.RegisterTypeAlias("Chunk", typeof(Chunk)); global["Chunk"] = LuaType.GetType(typeof(Chunk)); LuaType.RegisterTypeAlias("SolidBlock", typeof(Blocks.SolidBlock)); global["SolidBlock"] = LuaType.GetType(typeof(Blocks.SolidBlock)); LuaType.RegisterTypeAlias("Structure", typeof(MapStructure)); global["Structure"] = LuaType.GetType(typeof(MapStructure)); //global["Double"] = LuaType.GetType(typeof(Double)); runLuaFile("init.lua"); }
public LuaTable Skip(LuaTable table, int numElements) { var t = Context.CreateTable(); for (var i = numElements; i <= table.Count; i++) t.Add(t.Count + 1, table[i]); return t; }
public static bool MsgUnPackTable(out LuaTable luatable, ref MessagePackObject pObj) { LuaTable result = new LuaTable(); luatable = result; var mPk = pObj.AsDictionary(); bool isString = false; string key; object value; foreach (var item in mPk) { //parse for key MessagePackObject mKey = item.Key; if (mKey.IsRaw) { key = mKey.AsString(); isString = true; } else if (true == mKey.IsTypeOf<double>()) { key = mKey.AsDouble().ToString(); } else { LoggerHelper.Error("key type error"); return false; } //parse for value MessagePackObject mValue = item.Value; if (mValue.IsRaw) { value = mValue.AsString(); } else if (mValue.IsDictionary) { LuaTable luatbl; MsgUnPackTable(out luatbl, ref mValue); value = luatbl; } else if (true == mValue.IsTypeOf<bool>()) { value = mValue.AsBoolean(); } else if (true == mValue.IsTypeOf<double>()) { value = mValue.AsDouble(); } else { LoggerHelper.Error("value type error"); return false; } result.Add(key, isString, value); isString = false; } return true; }
// Registers functions in library public static void RegisterFunctions(LuaTable module) { module.SetNameValue("huge", new LuaNumber(double.MaxValue)); module.SetNameValue("pi", new LuaNumber(Math.PI)); module.SetNameValue("e", new LuaNumber(Math.E)); module.Register("pow", pow); module.Register("random", random); module.Register("randomseed", randomseed); module.Register("sqrt", sqrt); }
public void UpdateDoneChargeReward(LuaTable charged) { List<int> temp = new List<int>(); foreach (var i in charged) { temp.Add(int.Parse((string)i.Key)); } chargedReward = temp; UpdateChargeRewardView(); }
private void InitIfNeeds() { if (luaObj != null) return; luaObj = BindLuaScript(luaScript); if (luaObj != null) CallLuaMethod("Init", false, this, gameObject); }
// Registers functions in library public static void RegisterFunctions(LuaTable module) { module.Register("print", print); module.Register("type", type); module.Register("getmetatable", getmetatable); module.Register("setmetatable", setmetatable); module.Register("tostring", tostring); module.Register("tonumber", tonumber); module.Register("assert", assert); module.Register("error", error); }
public static LuaTable QuaternionToTable(Quaternion q) { LuaTable t = new LuaTable(); t.AddValue(new LuaNumber(q.x)); t.AddValue(new LuaNumber(q.y)); t.AddValue(new LuaNumber(q.z)); t.AddValue(new LuaNumber(q.w)); return t; }
private void OnFriendListResp(LuaTable luatable, UInt32 errorid) { try { friendManager.FriendListResp(luatable, (int)errorid); } catch (Exception ex) { LoggerHelper.Except(ex); } }
/* * Gets the function called name from the provided table, * returning null if it does not exist */ public static LuaFunction GetTableFunction (LuaTable luaTable, string name) { if (luaTable == null) return null; object funcObj = luaTable.RawGet (name); if (funcObj is LuaFunction) return (LuaFunction)funcObj; else return null; }
public static void RegisterFunctions(LuaTable module) { module.Register("clock", clock); module.Register("date", date); module.Register("time", time); module.Register("execute", execute); module.Register("exit", exit); module.Register("getenv", getenv); module.Register("remove", remove); module.Register("rename", rename); module.Register("tmpname", tmpname); }
public static void RegisterFunctions(LuaTable module) { module.Register("byte", @byte); module.Register("char", @char); module.Register("format", format); module.Register("len", len); module.Register("sub", sub); module.Register("lower", lower); module.Register("upper", upper); module.Register("rep", rep); module.Register("reverse", reverse); }
public void SetLuaTalbe(LuaTable peerTable) { mPeerTable = peerTable; mOnTagHandlers = mPeerTable.Get <LuaFunction>("OnTagHandlers"); }
public GSubLuaTableMatchEvaluator(LuaTable t) { this.t = t; this.lIgnoreCase = (bool)Lua.RtConvertValue(t.GetMemberValue("__IgnoreCase"), typeof(bool)); } // ctor
public static void CreateWithEmit(string path, LuaTable emitter) { #if UNITY_EDITOR && !_FORCE_AB try { UnityEngine.Object prefab = null; prefab = AssetDatabase.LoadAssetAtPath <UnityEngine.GameObject>("Assets/Art/" + path + ".prefab"); var go = GameObject.Instantiate(prefab) as GameObject; GameObject.DontDestroyOnLoad(go); LuaFunction emitFunc = emitter.GetLuaFunction("Emit"); emitFunc.BeginPCall(); emitFunc.Push(emitter); emitFunc.Push(go); emitFunc.PCall(); emitFunc.EndPCall(); emitFunc.Dispose(); } finally { emitter.Dispose(); } #else string[] nodes = path.Split('/'); path = string.Concat(nodes[0], "/", nodes[nodes.Length - 1]); var resMgr = AppFacade.Instance.GetManager <LuaFramework.ResourceManager>(LuaFramework.ManagerName.Resource); resMgr.LoadPrefab("", nodes[nodes.Length - 1], (objs) => { try { UnityEngine.Object prefab = objs[0] as UnityEngine.GameObject; var go = GameObject.Instantiate(prefab) as GameObject; GameObject.DontDestroyOnLoad(go); LuaFunction emitFunc = emitter.GetLuaFunction("Emit"); emitFunc.BeginPCall(); emitFunc.Push(emitter); emitFunc.Push(go); emitFunc.PCall(); emitFunc.EndPCall(); emitFunc.Dispose(); } finally { emitter.Dispose(); } }); //ResourceManager.Instance.LoadBundle(path.ToLower(), obj => //{ // try // { // UnityEngine.Object prefab = obj as UnityEngine.GameObject; // var go = GameObject.Instantiate(prefab) as GameObject; // GameObject.DontDestroyOnLoad(go); // LuaFunction emitFunc = emitter.GetLuaFunction("Emit"); // emitFunc.BeginPCall(); // emitFunc.Push(emitter); // emitFunc.Push(go); // emitFunc.PCall(); // emitFunc.EndPCall(); // emitFunc.Dispose(); // } // finally // { // emitter.Dispose(); // } //}); #endif }
public UnityEngine.Camera.CameraCallback UnityEngine_Camera_CameraCallback(LuaFunction func, LuaTable self, bool flag) { if (func == null) { UnityEngine.Camera.CameraCallback fn = delegate(UnityEngine.Camera param0) { }; return(fn); } if (!flag) { UnityEngine_Camera_CameraCallback_Event target = new UnityEngine_Camera_CameraCallback_Event(func); UnityEngine.Camera.CameraCallback d = target.Call; target.method = d.Method; return(d); } else { UnityEngine_Camera_CameraCallback_Event target = new UnityEngine_Camera_CameraCallback_Event(func, self); UnityEngine.Camera.CameraCallback d = target.CallWithSelf; target.method = d.Method; return(d); } }
public UnityEngine_Application_AdvertisingIdentifierCallback_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public LuaStringTableNodeProxy(LuaTable source, string key) : base(source, key) { }
public void Add(LuaTable details, LuaFunction fn) { Type criteria_type; string criteria_methodname; Type[] criteria_argtypes = null; bool criteria_instance; bool criteria_public; bool hook_returns; using (var ftype = details["type"]) { if (ftype == null) { throw new LuaException($"type: Expected Type, got null"); } if (!(ftype is IClrObject)) { throw new LuaException($"type: Expected CLR Type object, got non-CLR object of type {ftype.GetType()}"); } else if (!(((IClrObject)ftype).ClrObject is Type)) { throw new LuaException($"type: Expected CLR Type object, got CLR object of type {((IClrObject)ftype).ClrObject.GetType()}"); } criteria_type = ((IClrObject)ftype).ClrObject as Type; using (var method = details["method"] as LuaString) using (var instance = details["instance"] as LuaBoolean) using (var @public = details["public"] as LuaBoolean) using (var returns = details["returns"] as LuaBoolean) using (var args = details["args"] as LuaTable) { if (method == null) { throw new LuaException("method: Expected string, got null"); } if (args != null) { var count = 0; while (true) { using (var value = args[count + 1]) { if (value is LuaNil) { break; } if (!(value is IClrObject)) { throw new LuaException($"args: Expected entry at index {count} to be a CLR Type object, got non-CLR object of type {value.GetType()}"); } else if (!(((IClrObject)value).ClrObject is Type)) { throw new LuaException($"args: Expected entry at index {count} to be a CLR Type object, got CLR object of type {((IClrObject)value).ClrObject.GetType()}"); } } count += 1; } var argtypes = new Type[args.Count]; for (int i = 1; i <= count; i++) { using (var value = args[i]) { argtypes[i - 1] = (Type)args[i].CLRMappedObject; } } criteria_argtypes = argtypes; } criteria_instance = instance?.ToBoolean() ?? true; criteria_public = @public?.ToBoolean() ?? true; criteria_methodname = method.ToString(); hook_returns = returns?.ToBoolean() ?? false; } } var method_info = _TryFindMethod( criteria_type, criteria_methodname, criteria_argtypes, criteria_instance, criteria_public ); if (method_info == null) { throw new LuaException($"Method '{criteria_methodname}' in '{criteria_type.FullName}' not found."); } _CheckForbidden(method_info); RuntimeHooks.InstallDispatchHandler(method_info); var token = RuntimeHooks.MethodToken(method_info); Hooks[token] = fn; fn.DisposeAfterManagedCall = false; if (hook_returns) { HookReturns[token] = method_info.ReturnType; } _Logger.Debug($"Added Lua hook for method '{criteria_methodname}' ({token})"); }
public void SetLuaTalbe(LuaTable peerTable) { mPeerTable = peerTable; callback = peerTable.Cast <ILuaTaskBase>(); }
public UnityEngine_Camera_CameraCallback_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public System_Comparison_int_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public System_Predicate_int_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public UnityEngine_Events_UnityAction_Event(LuaFunction func, LuaTable self) : base(func, self) { }
// dicStartPos : <StartPosID, LocalMapID> public void ParseVillage(Lua lua, ref Dictionary <int, int> dicStartPos) { m_fCameraDistance = 1200.0f; m_fLookAtHeight = 200.0f; m_fEyeHeight = 300.0f; LuaTool.DoFile(lua, ScriptTreeManager.strDialogDir + "DLG_Map_Village.lua"); LuaTable VillageTable; try { VillageTable = lua.GetTable("Village"); } catch (Exception e) { System.Windows.Forms.MessageBox.Show(e.Message); return; } foreach (DictionaryEntry Entry in VillageTable) { int villageID = (int)(double)Entry.Key; LuaTable Villageinfo = (LuaTable)Entry.Value; LuaTool.GetValue(Villageinfo, "NAME", out m_Name_ID, 0); LuaTool.GetValue(Villageinfo, "BaseLocalStateID", out m_BaseLocalStateID, 0); LuaTable HouseIDList; if (true == LuaTool.GetTable(Villageinfo, "HouseIDList", out HouseIDList)) { m_HouseList = new List <int>(); foreach (DictionaryEntry entry in HouseIDList) { m_HouseList.Add((int)(double)entry.Value); } } LuaTool.GetValue(Villageinfo, "WORLD_ID", out m_WorldID, 0); // m_mapWorldMap.insert(std::make_pair((int)villageID, worldId)); LuaTable Camera; if (true == LuaTool.GetTable(Villageinfo, "CAMERA", out Camera)) { m_fCameraDistance = (float)(double)Camera[1]; m_fLookAtHeight = (float)(double)Camera[2]; m_fEyeHeight = (float)(double)Camera[3]; } LuaTable StartPos; if (true == LuaTool.GetTable(Villageinfo, "START_POS", out StartPos)) { m_vecStartPos = new List <VillageStartPos>(); foreach (DictionaryEntry ent in StartPos) { LuaTable startposentry = (LuaTable)ent.Value; VillageStartPos VSP = new VillageStartPos(); VSP.m_VillageID = m_VillageID; LuaTool.GetValue(startposentry, "StartPosId", out VSP.m_StartPosID, 0); float x, y, z; LuaTool.GetValue(startposentry, "StartPosX", out x, 0.0f); VSP.m_StartPos.X = x; LuaTool.GetValue(startposentry, "StartPosY", out y, 0.0f); VSP.m_StartPos.Y = y; LuaTool.GetValue(startposentry, "StartPosZ", out z, 0.0f); VSP.m_StartPos.Z = z; LuaTool.GetValue(startposentry, "IsMarket", out VSP.m_bIsMarket, false); LuaTool.GetValue(startposentry, "IsNPC", out VSP.m_bIsNPC, false); LuaTool.GetValue(startposentry, "IsSummon", out VSP.m_bIsSummon, false); LuaTool.GetValue(startposentry, "IsWarp", out VSP.m_bIsWarp, false); LuaTool.GetValue(startposentry, "LinkDungeon", out VSP.m_iDungeonId, 0); LuaTool.GetValue(startposentry, "LinkDungeonPos", out VSP.m_iDungeonPos, 0); LuaTable LinkPos; if (true == LuaTool.GetTable(startposentry, "LinkPos", out LinkPos)) { VSP.m_vecLinkStartPos = new List <int>(); foreach (DictionaryEntry LinkPosEntry in LinkPos) { if ((int)(double)LinkPosEntry.Value >= 0) { VSP.m_vecLinkStartPos.Add((int)(double)LinkPosEntry.Value); } } } dicStartPos.Add(VSP.m_StartPosID, m_BaseLocalStateID); m_vecStartPos.Add(VSP); } } // StartPos } }
public UnityEngine_Application_LogCallback_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public void SetLuaTalbe(LuaTable peerTable) { mLuaTable = peerTable; callback = mLuaTable.Cast <ILuaSceneBase>(); }
public object[] DoString(string chunk, string chunkName = "chunk", LuaTable env = null) { return(LuaState.DoString(chunk, chunkName, env)); }
public LuaIntTableNodeProxy(LuaTable source, int key) : base(source, key) { }
public static PropObject LoadProp(string scd, string LocalPath) { if (LoadedPropObjects.ContainsKey(LocalPath)) { return(LoadedPropObjects[LocalPath]); } PropObject ToReturn = new PropObject(); byte[] Bytes = LoadBytes(scd, LocalPath); if (Bytes.Length == 0) { Debug.LogError("Prop does not exits: " + LocalPath); return(ToReturn); } string BluePrintString = System.Text.Encoding.UTF8.GetString(Bytes); if (BluePrintString.Length == 0) { Debug.LogError("Loaded blueprint is empty"); return(ToReturn); } BluePrintString = BluePrintString.Replace("PropBlueprint {", "PropBlueprint = {"); // *** Parse Blueprint ToReturn.BP = new PropBluePrint(); // Create Lua Lua BP = new Lua(); BP.LoadCLRPackage(); string[] PathSplit = LocalPath.Split(("/").ToCharArray()); ToReturn.BP.Name = PathSplit[PathSplit.Length - 1].Replace(".bp", ""); //Fix LUA string[] SplitedBlueprint = BluePrintString.Split("\n".ToCharArray()); string NewBlueprintString = ""; for (int i = 0; i < SplitedBlueprint.Length; i++) { if (SplitedBlueprint[i].Length > 0 && !SplitedBlueprint[i].Contains("#")) { NewBlueprintString += SplitedBlueprint[i] + "\n"; } } BluePrintString = NewBlueprintString; ToReturn.BP.Path = LocalPath; try { BP.DoString(MapLuaParser.Current.SaveLuaHeader.text + BluePrintString); } catch (NLua.Exceptions.LuaException e) { Debug.LogError(LuaParser.Read.FormatException(e) + "\n" + LocalPath); return(ToReturn); } // Economy LuaTable EconomyTab = BP.GetTable("PropBlueprint.Economy"); if (EconomyTab != null) { if (EconomyTab.RawGet("ReclaimEnergyMax") != null) { ToReturn.BP.ReclaimEnergyMax = LuaParser.Read.StringToFloat(EconomyTab.RawGet("ReclaimEnergyMax").ToString()); } if (EconomyTab.RawGet("ReclaimMassMax") != null) { ToReturn.BP.ReclaimMassMax = LuaParser.Read.StringToFloat(EconomyTab.RawGet("ReclaimMassMax").ToString()); } if (EconomyTab.RawGet("ReclaimTime") != null) { ToReturn.BP.ReclaimTime = LuaParser.Read.StringToFloat(EconomyTab.RawGet("ReclaimTime").ToString()); } } //Size object SizeX = BP.GetTable("PropBlueprint").RawGet("SizeX"); if (SizeX != null) { ToReturn.BP.SizeX = LuaParser.Read.StringToFloat(SizeX.ToString()); } object SizeY = BP.GetTable("PropBlueprint").RawGet("SizeY"); if (SizeY != null) { ToReturn.BP.SizeY = LuaParser.Read.StringToFloat(SizeY.ToString()); } object SizeZ = BP.GetTable("PropBlueprint").RawGet("SizeZ"); if (SizeZ != null) { ToReturn.BP.SizeY = LuaParser.Read.StringToFloat(SizeZ.ToString()); } //Display if (BP.GetTable("PropBlueprint.Display") != null) { if (BP.GetTable("PropBlueprint.Display").RawGet("UniformScale") != null) { ToReturn.BP.UniformScale = LuaParser.Read.StringToFloat(BP.GetTable("PropBlueprint.Display").RawGet("UniformScale").ToString()); } // Mesh if (BP.GetTable("PropBlueprint.Display.Mesh") != null) { if (BP.GetTable("PropBlueprint.Display.Mesh").RawGet("IconFadeInZoom") != null) { ToReturn.BP.IconFadeInZoom = LuaParser.Read.StringToFloat(BP.GetTable("PropBlueprint.Display.Mesh").RawGet("IconFadeInZoom").ToString()); } //Lods LuaTable LodTable = BP.GetTable("PropBlueprint.Display.Mesh.LODs"); LuaTable[] LodTableValues = new LuaTable[LodTable.Keys.Count]; ToReturn.BP.LODs = new BluePrintLoD[LodTableValues.Length]; LodTable.Values.CopyTo(LodTableValues, 0); for (int i = 0; i < LodTableValues.Length; i++) { ToReturn.BP.LODs[i] = new BluePrintLoD(); if (LodTableValues[i].RawGet("AlbedoName") != null) { ToReturn.BP.LODs[i].AlbedoName = LodTableValues[i].RawGet("AlbedoName").ToString(); } if (LodTableValues[i].RawGet("NormalsName") != null) { ToReturn.BP.LODs[i].NormalsName = LodTableValues[i].RawGet("NormalsName").ToString(); } if (LodTableValues[i].RawGet("ShaderName") != null) { ToReturn.BP.LODs[i].ShaderName = LodTableValues[i].RawGet("ShaderName").ToString(); } if (LodTableValues[i].RawGet("LODCutoff") != null) { ToReturn.BP.LODs[i].LODCutoff = LuaParser.Read.StringToFloat(LodTableValues[i].RawGet("LODCutoff").ToString()); } ToReturn.BP.LODs[i].Scm = LocalPath.Replace("prop.bp", "lod" + i.ToString() + ".scm"); } } } ToReturn.BP.LocalScale = Vector3.one * (ToReturn.BP.UniformScale * 0.1f); for (int i = 0; i < ToReturn.BP.LODs.Length; i++) { ToReturn.BP.LODs[i].Mesh = LoadModel(scd, ToReturn.BP.LODs[i].Scm); //ToReturn.BP.LODs[i].Mat = new Material(Shader.Find("Standard (Specular setup)")); ToReturn.BP.LODs[i].Mat = new Material(EditMap.PropsInfo.Current.PropMaterial); ToReturn.BP.LODs[i].Mat.name = ToReturn.BP.Name + " mat"; if (i > 0 && (string.IsNullOrEmpty(ToReturn.BP.LODs[i].AlbedoName) || ToReturn.BP.LODs[i].AlbedoName == ToReturn.BP.LODs[0].AlbedoName) && (string.IsNullOrEmpty(ToReturn.BP.LODs[i].NormalsName) || ToReturn.BP.LODs[i].NormalsName == ToReturn.BP.LODs[0].NormalsName)) { ToReturn.BP.LODs[i].Mat = ToReturn.BP.LODs[0].Mat; continue; } if (ToReturn.BP.LODs[i].AlbedoName.Length == 0) { ToReturn.BP.LODs[i].AlbedoName = LocalPath.Replace("prop.bp", "albedo.dds"); } else { ToReturn.BP.LODs[i].AlbedoName = OffsetRelativePath(LocalPath, ToReturn.BP.LODs[i].AlbedoName, true); } ToReturn.BP.LODs[i].Albedo = LoadTexture2DFromGamedata(scd, ToReturn.BP.LODs[i].AlbedoName, false); ToReturn.BP.LODs[i].Albedo.anisoLevel = 2; ToReturn.BP.LODs[i].Mat.SetTexture("_MainTex", ToReturn.BP.LODs[i].Albedo); if (ToReturn.BP.LODs[i].ShaderName == "VertexNormal") { ToReturn.BP.LODs[i].NormalsName = ""; } else if (ToReturn.BP.LODs[i].NormalsName.Length == 0 && i == 0) { ToReturn.BP.LODs[i].NormalsName = LocalPath.Replace("prop.bp", "normalsTS.dds"); } else { ToReturn.BP.LODs[i].NormalsName = OffsetRelativePath(LocalPath, ToReturn.BP.LODs[i].NormalsName, true); } if (ToReturn.BP.LODs[i].ShaderName == "NormalMappedTerrain") { ToReturn.BP.LODs[i].Mat.SetInt("_GlowAlpha", 1); } if (!string.IsNullOrEmpty(ToReturn.BP.LODs[i].NormalsName)) { ToReturn.BP.LODs[i].Normal = LoadTexture2DFromGamedata(scd, ToReturn.BP.LODs[i].NormalsName, true); ToReturn.BP.LODs[i].Normal.anisoLevel = 2; ToReturn.BP.LODs[i].Mat.SetTexture("_BumpMap", ToReturn.BP.LODs[i].Normal); } } LoadedPropObjects.Add(LocalPath, ToReturn); return(ToReturn); }
public int preSkill = 0; //保存上次释放的技能id public int ChooseSkill() { int skillid = 0; int usepriority = 0; int level = PlayerData.Instance.BaseAttr.Level; bool ismor = CoreEntry.gMorphMgr.IsMorphing; //是否在变身中 int skillidReal = 0; //普攻技能可以重复释放 foreach (KeyValuePair <int, int> e in m_Actor.m_skillBindsDict) { //跳过冷却中的技能 if (m_Actor.IsInCoolDownTime(e.Value)) { continue; } //等级限制 LuaTable skillDesc = ConfigManager.Instance.Skill.GetSkillConfig(e.Value); if (skillDesc == null || level < skillDesc.Get <int>("needLvl")) { continue; } //变身状态下要使用变身对应的技能 int showtype = skillDesc.Get <int>("showtype"); if ((ismor && showtype != MorphShowType) || (!ismor && showtype == MorphShowType)) { continue; } //配置是否使用特殊技能 if (showtype == SpecialSkillType && !CoreEntry.gAutoAIMgr.Config.UseSpecialSkill) { continue; } //选择优先级最高的技能 int priority = skillDesc.Get <int>("priority"); if (priority == -1) { continue; } if (usepriority == 0 || usepriority < priority) { skillidReal = e.Value; usepriority = priority; //当前技能被卡住强制释放下个技能 if ((preSkill > 0 && preSkill != e.Value) || preSkill <= 0) { skillid = e.Value; } } } if (skillid == 0) { skillid = skillidReal; } preSkill = skillid; return(skillid); }
/// <summary> /// Sets the assignment /// </summary> /// <param name="baseValue"></param> /// <param name="key"></param> /// <param name="value"></param> private static void SetKeyValue(LuaValue baseValue, LuaValue key, LuaValue value) { LuaValue newIndex = LuaNil.Nil; LuaTable table = baseValue as LuaTable; if (table != null) { if (table.MetaTable != null) { newIndex = table.MetaTable.GetValue("__newindex"); // to be finished at the end of this method } if (newIndex == LuaNil.Nil) { table.SetKeyValue(key, value); return; } } else if ((baseValue as LuaClass) != null) { LuaClass c = baseValue as LuaClass; // null checks (mainly for debugging) if (c.Self.MetaTable == null) { c.GenerateMetaTable(); } //throw new Exception("Class metatable is nil!"); newIndex = c.Self.MetaTable.GetValue("__newindex"); if (newIndex == LuaNil.Nil) { c.Self.SetKeyValue(key, value); } else { (newIndex as LuaFunction).Invoke(new LuaValue[] { baseValue, key, value }); } return; } else { LuaUserdata userdata = baseValue as LuaUserdata; if (userdata != null) { if (userdata.MetaTable != null) { newIndex = userdata.MetaTable.GetValue("__newindex"); } if (newIndex == LuaNil.Nil) { throw new Exception("Assign field of userdata without __newindex defined."); } } } LuaFunction func = newIndex as LuaFunction; if (func != null) { func.Invoke(new LuaValue[] { baseValue, key, value }); } else { SetKeyValue(newIndex, key, value); } }
/// <summary> /// 查找目标。 /// </summary> private void FindTarget() { PlayerObj player = CoreEntry.gActorMgr.MainPlayer; if (player == null) { return; } //有任务在身时,判断任务位置 Vector3 selfpos = player.transform.position; int mid = 0; LogMgr.LogAI("AutoAIFindTarget.FindTarget"); if (TaskMgr.RunTaskType != 0 && !IsInDungeon()) { mid = TaskMgr.Instance.GetCurTargetMonsterId(); if (mid != 0) { const float RESET_DISTANCE = 5; //重新回到任务点距离 Vector3 pos = TaskMgr.Instance.goPos; float x = selfpos.x - pos.x; float z = selfpos.z - pos.z; if (x * x + z * z >= RESET_DISTANCE * RESET_DISTANCE) { LogMgr.LogAI("AutoAIFindTarget.FindTarget 离开任务目标位置太远,重新回去"); m_TargetPosition = pos; m_IsHaveTarget = true; return; } } } int mapid = MapMgr.Instance.EnterMapId; LuaTable cfg = ConfigManager.Instance.Map.GetMapConfig(mapid); ActorObj actor = player.FindTarget(cfg.Get <int>("autoFightRange"), mapid); if (actor != null) { //如果选择的不是当前怪物则忽略 if (mid != 0 && actor is MonsterObj) { MonsterObj monster = actor as MonsterObj; if (monster.ConfigID != mid) { return; } } m_TargetPosition = actor.transform.position; m_IsHaveTarget = true; return; } if (MapMgr.Instance.CurMapType == MapMgr.MapType.Map_CrossServer) { return; } //向服务器查询位置 if (WildQuery || IsInDungeon()) { //加载查询列表 if (m_QueryList.Count <= 0) { m_QueryList = GetSortedEntList(player.transform.position); m_QueryIndex = 0; } //开始查询 if (m_QueryList.Count > 0) { Vector3 pos = m_QueryList[m_QueryIndex]; m_QueryIndex = (m_QueryIndex + 1) % m_QueryList.Count; m_IsRequestPositon = true; m_QueryWaitCount = 5; NetLogicGame.Instance.SendQueryMonsterByPosition((int)(pos.x * 1000), (int)(pos.z * 1000)); LogMgr.LogAI("AutoAIFindTarget.FindTarget RequestPositon:{0}", pos); } else { LogMgr.LogAI("AutoAIFindTarget.FindTarget The QueryList is empty!"); } } else { LogMgr.LogAI("AutoAIFindTarget.FindTarget Can not find target."); } }
public System_Func_bool_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public UnityEngine.Events.UnityAction UnityEngine_Events_UnityAction(LuaFunction func, LuaTable self, bool flag) { if (func == null) { UnityEngine.Events.UnityAction fn = delegate() { }; return(fn); } if (!flag) { UnityEngine_Events_UnityAction_Event target = new UnityEngine_Events_UnityAction_Event(func); UnityEngine.Events.UnityAction d = target.Call; target.method = d.Method; return(d); } else { UnityEngine_Events_UnityAction_Event target = new UnityEngine_Events_UnityAction_Event(func, self); UnityEngine.Events.UnityAction d = target.CallWithSelf; target.method = d.Method; return(d); } }
public UnityEngine.Application.LogCallback UnityEngine_Application_LogCallback(LuaFunction func, LuaTable self, bool flag) { if (func == null) { UnityEngine.Application.LogCallback fn = delegate(string param0, string param1, UnityEngine.LogType param2) { }; return(fn); } if (!flag) { UnityEngine_Application_LogCallback_Event target = new UnityEngine_Application_LogCallback_Event(func); UnityEngine.Application.LogCallback d = target.Call; target.method = d.Method; return(d); } else { UnityEngine_Application_LogCallback_Event target = new UnityEngine_Application_LogCallback_Event(func, self); UnityEngine.Application.LogCallback d = target.CallWithSelf; target.method = d.Method; return(d); } }
public UnityEngine.RectTransform.ReapplyDrivenProperties UnityEngine_RectTransform_ReapplyDrivenProperties(LuaFunction func, LuaTable self, bool flag) { if (func == null) { UnityEngine.RectTransform.ReapplyDrivenProperties fn = delegate(UnityEngine.RectTransform param0) { }; return(fn); } if (!flag) { UnityEngine_RectTransform_ReapplyDrivenProperties_Event target = new UnityEngine_RectTransform_ReapplyDrivenProperties_Event(func); UnityEngine.RectTransform.ReapplyDrivenProperties d = target.Call; target.method = d.Method; return(d); } else { UnityEngine_RectTransform_ReapplyDrivenProperties_Event target = new UnityEngine_RectTransform_ReapplyDrivenProperties_Event(func, self); UnityEngine.RectTransform.ReapplyDrivenProperties d = target.CallWithSelf; target.method = d.Method; return(d); } }
public void SetLuaTalbe(LuaTable t) { mLuatable = t; callBack = mLuatable.Cast <ILuaWindow>(); }
public abstract LuaValue Execute(LuaTable enviroment, out bool isBreak);
public void SetLuaTalbe(LuaTable peerTable) { mPeerTable = peerTable; mPeerTable = peerTable; callback = mPeerTable.Cast <IState>(); }
public System_Action_Event(LuaFunction func, LuaTable self) : base(func, self) { }
public T LoadString <T>(string chunk, string chunkName = "chunk", LuaTable env = null) { return(LuaState.LoadString <T>(chunk, chunkName, env)); }