public static bool TryCall(string func, DynValue[] param = null) { if (UnitaleUtil.IsOverworld) { return(false); } try { if (EnemyEncounter.script.GetVar(func) == null) { return(false); } if (param != null) { EnemyEncounter.script.Call(func, param); } else { EnemyEncounter.script.Call(func); } return(true); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message); return(true); } }
public static bool TryCall(string func, DynValue[] param = null) { bool overworld = false; if (GameObject.Find("Main Camera OW")) { overworld = true; } if (!overworld) { try { if (LuaEnemyEncounter.script.GetVar(func) == null) { return(false); } if (param != null) { LuaEnemyEncounter.script.Call(func, param); } else { LuaEnemyEncounter.script.Call(func); } return(true); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, ex.DecoratedMessage); return(true); } } else { return(false); } }
string BuildTalkString() { DynValue talks, talkResults; try { talks = script.GetVar("talklist").Table.Get(1); talkResults = script.GetVar("talklist").Table.Get(2); } catch { UnitaleUtil.DisplayLuaError("Creating the Talk menu", "The variable talklist must be an array which contains two other arrays."); return(""); } string result = "[font:uidialoglilspace][linespacing:11]"; if (talks.Type == DataType.Table) { mainName = new string[talks.Table.Length]; mainInfo = new DynValue[talks.Table.Length]; for (int i = 0; i < talks.Table.Length; i++) { mainName[i] = talks.Table.Get(i + 1).String; result += " " + mainName[i] + "\n"; mainInfo[i] = talkResults.Table.Get(i + 1); } } else { UnitaleUtil.DisplayLuaError("Creating the Talk menu", "The variable talklist must be an array which contains two other arrays."); return(""); } return(result + " Exit"); }
private static void loadAllFrom(string folderName, string script_prefix, bool needed) { string directoryPath = FileLoader.pathToModFile("Lua/" + folderName); DirectoryInfo dInfo = new DirectoryInfo(directoryPath); if (!dInfo.Exists) { if (needed) { UnitaleUtil.DisplayLuaError("mod loading", "You tried to load the mod \"" + StaticInits.MODFOLDER + "\" but it can't be found, or at least its \"Lua/" + folderName + "\" folder can't be found.\nAre you sure it exists?"); throw new CYFException("mod loading"); } return; } FileInfo[] fInfo = dInfo.GetFiles("*.lua", SearchOption.AllDirectories); foreach (FileInfo file in fInfo) { //UnitaleUtil.writeInLog(file.Name); string scriptName = FileLoader.getRelativePathWithoutExtension(directoryPath, file.FullName).ToLower(); string temp = ""; dict.TryGetValue(script_prefix + scriptName, out temp); if (dict.ContainsKey(script_prefix + scriptName) && temp == FileLoader.getTextFrom(file.FullName)) { continue; } else if (dict.ContainsKey(script_prefix + scriptName)) { dict.Remove(script_prefix + scriptName); } Set(script_prefix + scriptName, FileLoader.getTextFrom(file.FullName)); } }
public static void BattleDialog(DynValue arg) { if (UIController.instance == null) { UnitaleUtil.WriteInLogAndDebugger("[WARN]BattleDialog can only be used as early as EncounterStarting."); } else { UIController.instance.battleDialogued = true; TextMessage[] msgs = null; if (arg.Type == DataType.String) { msgs = new TextMessage[] { new RegularMessage(arg.String) } } ; else if (arg.Type == DataType.Table) { msgs = new TextMessage[arg.Table.Length]; for (int i = 0; i < arg.Table.Length; i++) { msgs[i] = new RegularMessage(arg.Table.Get(i + 1).String); } } else { UnitaleUtil.DisplayLuaError("BattleDialog", "You need to input a non-empty array or a string here." + "\n\nIf you're sure that you've entered what's needed, you may contact the dev."); } UIController.instance.ActionDialogResult(msgs, UIController.UIState.ENEMYDIALOGUE); } }
///<summary> ///Overrideable item handler on a per-encounter basis. Should return true if a custom action is executed for the given item. ///</summary> ///<param name="item">Item to be checked for custom action</param> ///<returns>true if a custom action should be executed for given item, false if the default action should happen</returns> //public override bool CustomItemHandler(UnderItem item) { return CallOnSelfOrChildren("HandleItem", new DynValue[] { DynValue.NewString(item.Name) }); } public override void UpdateWave() { string currentScript = ""; try { for (int i = 0; i < waves.Length; i++) { currentScript = waveNames[i]; try { waves[i].script.Call(waves[i].script.Globals["Update"]); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(currentScript, ex.DecoratedMessage); return; } catch (Exception ex) { if (!GlobalControls.retroMode) { if (waves[i].script.Globals["Update"] == null) { UnitaleUtil.DisplayLuaError(currentScript, "All the wave scripts need an Update() function!"); } else { UnitaleUtil.DisplayLuaError(currentScript, "This error is a " + ex.GetType().ToString() + " error.\nPlease send this error to the main dev.\n\n" + ex.Message + "\n\n" + ex.StackTrace); } } return; } } } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(currentScript, ex.DecoratedMessage); return; } }
public static void calcDataRoot() { DirectoryInfo rootInfo = new DirectoryInfo(Application.dataPath); string SysDepDataRoot = rootInfo.FullName; while (true) { DirectoryInfo[] dfs = rootInfo.GetDirectories(); foreach (DirectoryInfo df in dfs) { if (df.FullName == Path.Combine(SysDepDataRoot, "Mods")) { DataRoot = SysDepDataRoot; return; } } try { rootInfo = new DirectoryInfo(rootInfo.Parent.FullName); } catch { UnitaleUtil.DisplayLuaError("CYF's Startup", "The engine detected no Mods folder in your files: are you sure that it exists?"); return; } SysDepDataRoot = rootInfo.FullName; //Debug.Log(SysDepDataRoot); } //if (Application.platform == RuntimePlatform.OSXPlayer) /*OSX has stuff bundled in .app things*/ SysDepDataRoot = rootInfo.Parent.Parent.FullName; //else if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor) { /*everything is fine*/ } //else SysDepDataRoot = rootInfo.Parent.FullName; }
// NOTE: According to this guide (https://blogs.unity3d.com/2020/04/09/learn-to-save-memory-usage-by-improving-the-way-you-use-assetbundles/) // using AssetBundle.LoadFromFile (and LoadFromFileAsync) is only recommended when you intend to take out a lot of assets at once, or continually. // That is very not the goal for shaders in CYF, especially not Default shaders. // As such, instead of using AssetBundle.LoadFromFile, I'm using the page's recommended alternative, UnityWebRequestAssetBundle.GetAssetBundle. // If you wish to use the AssetBundle.LoadFromFile approach instead, uncomment the first line and comment the rest. private static AssetBundle retrieveAssetBundle(string fullPath) { //return AssetBundle.LoadFromFile(fullPath); try { UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(new Uri(fullPath).AbsoluteUri.Replace("+", "%2B")); uwr.SendWebRequest(); while (!uwr.isDone) { } // hold up a bit while it's loading; delay isn't noticeable and loading will fail otherwise AssetBundle content = DownloadHandlerAssetBundle.GetContent(uwr); if (content == null) { throw new CYFException("Error while loading the shader \"" + fullPath + "\".\n\nIt's likely that you have two identical shader AssetBundles loaded at once."); } if (uwr.error != null) { throw new CYFException(uwr.error); } return(content); } catch (CYFException e) { UnitaleUtil.DisplayLuaError("loading a shader", e.Message); } catch (Exception e) { UnitaleUtil.DisplayLuaError("loading a shader", "This is a " + e.GetType() + " error. Please show this screen to a developer.\n\n" + e.Message + "\n\n" + e.StackTrace); } return(null); }
public override void EndWave(bool death = false) { Table t = script["Wave"].Table; if (!death) { foreach (object obj in t.Keys) { try { ((ScriptWrapper)t[obj]).Call("EndingWave"); } catch { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "You shouldn't override Wave, now you get an error :P"); } } } if (!GlobalControls.retroMode) { foreach (LuaProjectile p in FindObjectsOfType <LuaProjectile>()) { if (!p.ctrl.isPersistent) { p.ctrl.Remove(); } } } if (!death) { CallOnSelfOrChildren("DefenseEnding"); } ArenaManager.instance.resetArena(); EncounterText = script.GetVar("encountertext").String; EraseDust(); script.SetVar("Wave", DynValue.NewTable(new Table(null))); // Projectile.Z_INDEX_NEXT = Projectile.Z_INDEX_INITIAL; // doesn't work yet }
/// <summary> /// Displays a text. /// </summary> /// <param name="texts"></param> /// <param name="formatted"></param> /// <param name="mugshots"></param> [CYFEventFunction] public void SetDialog(DynValue texts, bool formatted = true, DynValue mugshots = null, DynValue forcePosition = null) { // Unfortunately, either C# or MoonSharp (don't know which) has a ridiculous limit in place // Calling `SetDialog({""}, true, nil, true)` fails to pass the final argument if (mugshots != null && mugshots.Type == DataType.Table && forcePosition != null) { PlayerOverworld.instance.UIPos = forcePosition.Type == DataType.Boolean ? (forcePosition.Boolean == true ? 2 : 1) : 0; } else { PlayerOverworld.instance.UIPos = 0; } if (EventManager.instance.coroutines.ContainsKey(appliedScript) && EventManager.instance.script != appliedScript) { UnitaleUtil.DisplayLuaError(EventManager.instance.events[EventManager.instance.actualEventIndex].name, "General.SetDialog: You can't use that function in a coroutine."); return; } else if (EventManager.instance.LoadLaunched) { UnitaleUtil.DisplayLuaError(EventManager.instance.events[EventManager.instance.actualEventIndex].name, "General.SetDialog: You can't use that function in a page 0 function."); return; } TextMessage[] textmsgs = new TextMessage[texts.Table.Length]; for (int i = 0; i < texts.Table.Length; i++) { textmsgs[i] = new TextMessage(texts.Table.Get(i + 1).String, formatted, false, mugshots != null ? mugshots.Type == DataType.Table ? mugshots.Table.Get(i + 1) : mugshots : null); } textmgr.SetTextQueue(textmsgs); textmgr.transform.parent.parent.SetAsLastSibling(); }
/*private static void loadAllFrom(string directoryPath, bool mod = false) { * DirectoryInfo dInfo = new DirectoryInfo(directoryPath); * FileInfo[] fInfo = dInfo.GetFiles("*.*", SearchOption.AllDirectories).Where(file => extensions.Contains(file.Extension)).ToArray(); * foreach (FileInfo file in fInfo) { * string voiceName = FileLoader.getRelativePathWithoutExtension(directoryPath, file.FullName).ToLower(); * AudioClip temp; * dict.TryGetValue(voiceName, out temp); * * if (dict.ContainsKey(voiceName) && temp == FileLoader.getAudioClip(directoryPath, file.FullName) &&!mod) * continue; * * //string voiceName = FileLoader.getRelativePathWithoutExtension(directoryPath, file.FullName).ToLower(); * //if (dict.ContainsKey(voiceName)) * // continue; * FileLoader.getAudioClip(directoryPath, file.FullName); * } * }*/ private static void loadAllFrom(string directoryPath, bool mod = false) { DirectoryInfo dInfo = new DirectoryInfo(directoryPath); if (!dInfo.Exists) { UnitaleUtil.DisplayLuaError("mod loading", "You tried to load the mod \"" + StaticInits.MODFOLDER + "\" but it can't be found.\nAre you sure it exists?"); throw new CYFException("mod loading"); } FileInfo[] fInfo = dInfo.GetFiles("*.*", SearchOption.AllDirectories).Where(file => extensions.Contains(file.Extension)).ToArray(); if (mod) { currentPath = directoryPath; dictMod.Clear(); foreach (FileInfo file in fInfo) { dictMod[FileLoader.getRelativePathWithoutExtension(directoryPath, file.FullName).ToLower()] = file; } } else { dictDefault.Clear(); foreach (FileInfo file in fInfo) { dictDefault[FileLoader.getRelativePathWithoutExtension(directoryPath, file.FullName).ToLower()] = file; } } }
// Use this for initialization void Start() { FindObjectOfType <Fading>().BeginFade(-1); tmMain = GameObject.Find("TextManager Main").GetComponent <TextManager>(); tmChoice = GameObject.Find("TextManager Choice").GetComponent <TextManager>(); tmInfo = GameObject.Find("TextManager Info").GetComponent <TextManager>(); tmBigTalk = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>(); tmGold = GameObject.Find("TextManager Gold").GetComponent <TextManager>(); tmItem = GameObject.Find("TextManager Item").GetComponent <TextManager>(); tmInfoParent = tmInfo.transform.parent.parent.gameObject; tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); utHeart = GameObject.Find("utHeart"); EnableBigText(false); if (scriptName == null) { throw new CYFException("You must give a valid script name to the function General.EnterShop()"); } script = new ScriptWrapper() { scriptname = scriptName }; string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName); if (scriptText == null) { throw new CYFException("You must give a valid script name to the function General.EnterShop()"); } try { script.DoString(scriptText); script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>()))); script.script.Globals["Interrupt"] = ((Action <DynValue, string>)Interrupt); script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite; script.script.Globals["CreateLayer"] = (Action <string, string, bool>)SpriteUtil.CreateLayer; script.script.Globals["CreateText"] = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText; TryCall("Start"); tmMain.SetCaller(script); tmChoice.SetCaller(script); tmInfo.SetCaller(script); tmBigTalk.SetCaller(script); tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) }); tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9] Buy\n Sell\n Talk\n Exit", false, true) }); tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) }); tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) }); tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String); Camera.main.GetComponent <AudioSource>().time = 0; Camera.main.GetComponent <AudioSource>().Play(); SetPlayerOnSelection(); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage != null ? UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message : ex.Message); } catch (Exception ex) { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); } }
public static Sprite[] AtlasFromXml(XmlNode sheetNode, Sprite source) { try { return((from XmlNode child in sheetNode.ChildNodes where child.Name.Equals("sprite") select SpriteWithXml(child, source)).ToArray()); } catch (Exception ex) { UnitaleUtil.DisplayLuaError("[XML document]", "One of the sprites' XML documents was invalid. This could be a corrupt or edited file.\n\n" + ex.Message); return(null); } }
public string GetItem(int index) { if (index > Inventory.inventory.Count) { UnitaleUtil.DisplayLuaError("Getting an item", "Out of bounds. You tried to access item number " + index + 1 + " in your inventory, but you only have " + Inventory.inventory.Count + " items."); return(""); } return(Inventory.inventory[index - 1].Name); }
public int GetType(int index) { if (index <= Inventory.inventory.Count) { return(Inventory.inventory[index - 1].Type); } UnitaleUtil.DisplayLuaError("Getting an item", "Out of bounds. You tried to access item number " + index + 1 + " in your inventory, but you only have " + Inventory.inventory.Count + " items."); return(-1); }
// Use this for initialization void Start() { if (!SaveLoad.started) { StaticInits.Start(); SaveLoad.Start(); new ControlPanel(); new PlayerCharacter(); #if UNITY_STANDALONE_WIN || UNITY_EDITOR_WIN if (GlobalControls.crate) { Misc.WindowName = ControlPanel.instance.WinodwBsaisNmae; } else { Misc.WindowName = ControlPanel.instance.WindowBasisName; } #endif SaveLoad.LoadAlMighty(); LuaScriptBinder.Set(null, "ModFolder", MoonSharp.Interpreter.DynValue.NewString("@Title")); UnitaleUtil.AddKeysToMapCorrespondanceList(); } Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic("mus_intro"); Camera.main.GetComponent <AudioSource>().Play(); if (imagePaths.Length != textsToDisplay.Length) { throw new Exception("You need to have the same number of images and lines of text."); } text = GameObject.FindObjectOfType <TextManager>(); img = GameObject.Find("CutsceneImages").GetComponent <Image>(); text.SetVerticalSpacing(6); text.SetHorizontalSpacing(6); if (SpriteRegistry.Get("Intro/mask") != null) { mask = true; GameObject.Find("Mask").GetComponent <Image>().sprite = SpriteRegistry.Get("Intro/mask"); GameObject.Find("Mask").GetComponent <Image>().color = new Color(1, 1, 1, 1); } TextMessage[] mess = new TextMessage[textsToDisplay.Length]; for (int i = 0; i < mess.Length; i++) { mess[i] = new TextMessage("[waitall:2]" + textsToDisplay[i], false, false); } text.SetTextQueue(mess); img.sprite = SpriteRegistry.Get("Intro/" + imagePaths[0]); img.SetNativeSize(); if (specialEffects[0] != string.Empty) { try { ApplyEffect((Effect)Enum.Parse(typeof(Effect), specialEffects[currentIndex].ToUpper())); } catch { UnitaleUtil.DisplayLuaError("IntroManager", "The effect " + specialEffects[currentIndex] + " doesn't exist."); } } if (goToNextDirect[0] == "Y") { timer = 0.5f; } }
public static DynValue MakeIngameSprite(string filename, string tag = "BelowArena", int childNumber = -1) { if (ParseUtil.TestInt(tag) && childNumber == -1) { childNumber = ParseUtil.GetInt(tag); tag = "BelowArena"; } Image i = GameObject.Instantiate <Image>(SpriteRegistry.GENERIC_SPRITE_PREFAB); if (!string.IsNullOrEmpty(filename)) { SwapSpriteFromFile(i, filename); } else { throw new CYFException("You can't create a sprite object with a nil sprite!"); } if (!GameObject.Find(tag + "Layer") && tag != "none") { UnitaleUtil.DisplayLuaError("Creating a sprite", "The sprite layer " + tag + " doesn't exist."); } else { if (childNumber == -1) { if (tag == "none") { i.transform.SetParent(GameObject.Find("Canvas").transform, true); } else { i.transform.SetParent(GameObject.Find(tag + "Layer").transform, true); } } else { RectTransform[] rts = GameObject.Find(tag + "Layer").GetComponentsInChildren <RectTransform>(); for (int j = 0; j < rts.Length; j++) { if (j >= childNumber) { rts[j].SetParent(null, true); } } i.transform.SetParent(GameObject.Find(tag + "Layer").transform, true); for (int j = 0; j < rts.Length; j++) { if (j >= childNumber) { rts[j].SetParent(GameObject.Find(tag + "Layer").transform, true); } } } } return(UserData.Create(new LuaSpriteController(i), LuaSpriteController.data)); }
// Use this for initialization void Start() { FindObjectOfType <Fading>().BeginFade(-1); tmMain = GameObject.Find("TextManager Main").GetComponent <TextManager>(); tmChoice = GameObject.Find("TextManager Choice").GetComponent <TextManager>(); tmInfo = GameObject.Find("TextManager Info").GetComponent <TextManager>(); tmBigTalk = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>(); tmGold = GameObject.Find("TextManager Gold").GetComponent <TextManager>(); tmItem = GameObject.Find("TextManager Item").GetComponent <TextManager>(); tmInfoParent = tmInfo.transform.parent.parent.gameObject; tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); utHeart = GameObject.Find("utHeart"); EnableBigText(false); if (scriptName == null) { UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()"); return; } script = new ScriptWrapper() { scriptname = scriptName }; string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName); if (scriptText == null) { UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()"); return; } script.DoString(scriptText); script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>()))); script.script.Globals["Interrupt"] = ((Action <DynValue, string>)Interrupt); script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite; script.script.Globals["CreateLayer"] = (Action <string, string, bool>)SpriteUtil.CreateLayer; script.script.Globals["CreateText"] = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText; script.Call("Start"); tmMain.SetCaller(script); tmChoice.SetCaller(script); tmInfo.SetCaller(script); tmBigTalk.SetCaller(script); tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) }); tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9] Buy\n Sell\n Talk\n Exit", false, true) }); tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) }); tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) }); tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String); Camera.main.GetComponent <AudioSource>().Play(); }
private void Advance() { NextLine(); if (caller.script.Globals["OnTextAdvance"] == null || caller.script.Globals.Get("OnTextAdvance") == null) { return; } try { caller.script.Call(caller.script.Globals["OnTextAdvance"], this, autoDestroyed); } catch (ScriptRuntimeException ex) { UnitaleUtil.DisplayLuaError(caller.scriptname, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message, ex.DoNotDecorateMessage); } }
private void PrepareWave() { DynValue nextWaves = script.GetVar("nextwaves"); waves = new ScriptWrapper[nextWaves.Table.Length]; waveNames = new string[waves.Length]; int currentWaveScript = 0; try { List <int> indexes = new List <int>(); for (int i = 0; i < waves.Length; i++) { currentWaveScript = i; DynValue ArenaStatus = UserData.Create(ArenaManager.luaStatus); waves[i] = new ScriptWrapper() { script = LuaScriptBinder.BoundScript() }; waves[i].script.Globals.Set("Arena", ArenaStatus); waves[i].script.Globals["EndWave"] = (Action)EndWaveTimer; waves[i].script.Globals["State"] = (Action <Script, string>)UIController.SwitchStateOnString; waves[i].script.Globals["CreateProjectile"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectile; waves[i].script.Globals["CreateProjectileAbs"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectileAbs; if (nextWaves.Table.Get(i + 1).Type != DataType.String) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Non-string value encountered in nextwaves table"); return; } else { waveNames[i] = nextWaves.Table.Get(i + 1).String; } waves[i].script.Globals["wavename"] = nextWaves.Table.Get(i + 1).String; try { waves[i].DoString(ScriptRegistry.Get(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String)); indexes.Add(i); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(i + 1).String + ".lua", ex.DecoratedMessage); } catch (Exception ex) { if (!GlobalControls.retroMode && !ScriptRegistry.dict.ContainsKey(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String)) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "The wave " + nextWaves.Table.Get(i + 1).String + " doesn't exist."); } else { UnitaleUtil.DisplayLuaError("<UNKNOWN LOCATION>", ex.Message + "\n\n" + ex.StackTrace); } } } Table luaWaveTable = new Table(null); for (int i = 0; i < indexes.Count; i++) { luaWaveTable.Set(i + 1, UserData.Create(waves[indexes[i]])); } script.SetVar("Wave", DynValue.NewTable(luaWaveTable)); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(currentWaveScript + 1).String + ".lua", ex.DecoratedMessage); } }
public void Show() { if (UIController.instance.GetState() == UIController.UIState.DEFENDING) { ArenaManager.instance.Show(); } else { UnitaleUtil.DisplayLuaError("NOT THE WAVE SCRIPT", "sorry but pls don't"); } }
public void ResizeImmediate(int w, int h) { if (UIController.instance.GetState() == UIController.UIState.DEFENDING) { ArenaManager.instance.ResizeImmediate(w, h); } else { UnitaleUtil.DisplayLuaError("NOT THE WAVE SCRIPT", "sorry but pls don't"); } }
public static void SetPPAlphaLimit(float f) { if (f < 0 || f > 1) { UnitaleUtil.DisplayLuaError("Pixel-Perfect alpha limit", "The alpha limit should be between 0 and 1."); } else { ControlPanel.instance.MinimumAlpha = f; } }
[CYFEventFunction] public void EndDialog() { if (EventManager.instance.LoadLaunched) { UnitaleUtil.DisplayLuaError(appliedScript.scriptname, "General.EndDialog: This function cannot be used in EventPage0."); return; } else if (EventManager.instance.script == appliedScript) { UnitaleUtil.DisplayLuaError(appliedScript.scriptname, "General.EndDialog: This function can only be used in a coroutine."); return; } if (GameObject.Find("textframe_border_outer") && GameObject.Find("textframe_border_outer").GetComponent <UnityEngine.UI.Image>().color.a != 0) { // Clean up text manager textmgr.SetTextFrameAlpha(0); textmgr.textQueue = new TextMessage[] { }; textmgr.DestroyChars(); // Clean up SetChoice if applicable if (EventManager.instance.script != null && EventManager.instance.script == textmgr.caller) { string key = EventManager.instance.script.GetVar("_internalScriptName").String + ".ISetChoice"; if (EventManager.instance.cSharpCoroutines.ContainsKey(key)) { // Stop the ISetChoice coroutine EventManager.instance.ForceEndCoroutine(key); // Remove the "tempHeart" GameObject if it already exists if (GameObject.Find("Canvas OW/tempHeart")) { GameObject.Destroy(GameObject.Find("Canvas OW/tempHeart")); } } } // End event appliedScript.Call("CYFEventNextCommand"); if (EventManager.instance.script != null && EventManager.instance.script == textmgr.caller) // End text from event { textmgr.caller.Call("CYFEventNextCommand"); } else { PlayerOverworld.instance.PlayerNoMove = false; // End text no event } } else { appliedScript.Call("CYFEventNextCommand"); } }
//public override void OnUpdate() { // destroy projectiles outside of the screen /*if (!screen.Contains(self.position)) * BulletPool.instance.Requeue(this);*/ //} public override void OnProjectileHit() { if (owner.Globals["OnHit"] != null && owner.Globals.Get("OnHit") != null) { try { owner.Call(owner.Globals["OnHit"], this.ctrl); } catch (ScriptRuntimeException ex) { UnitaleUtil.DisplayLuaError("[wave script filename here]\n(should be a filename, sorry! missing feature)", ex.DecoratedMessage); } } else { PlayerController.instance.Hurt(3); } }
private void Start() { try { string scriptText = ScriptRegistry.Get(ScriptRegistry.MONSTER_PREFIX + scriptName); if (scriptText == null) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Tried to load monster script " + scriptName + ".lua but it didn't exist. Is it misspelled?"); return; } script.scriptname = scriptName; script.Bind("SetSprite", (Action <string>)SetSprite); script.Bind("SetActive", (Action <bool>)SetActive); script.Bind("isActive", (Func <bool>)InFight); script.Bind("Kill", (Action)DoKill); script.Bind("Spare", (Action)DoSpare); script.Bind("Move", (Action <float, float, bool>)Move); script.Bind("MoveTo", (Action <float, float, bool>)MoveTo); script.Bind("BindToArena", (Action <bool, bool>)BindToArena); script.Bind("SetDamage", (Action <int>)SetDamage); script.Bind("SetBubbleOffset", (Action <int, int>)SetBubbleOffset); script.Bind("SetDamageUIOffset", (Action <int, int>)SetDamageUIOffset); script.Bind("SetSliceAnimOffset", (Action <int, int>)SetSliceAnimOffset); script.Bind("GetLetters", (Func <Letter[]>)GetLetters); script.Bind("State", (Action <Script, string>)UIController.SwitchStateOnString); script.SetVar("canmove", DynValue.NewBoolean(false)); sprite = new LuaSpriteController(GetComponent <Image>()); script.SetVar("monstersprite", UserData.Create(sprite, LuaSpriteController.data)); script.DoString(scriptText); string spriteFile = script.GetVar("sprite").String; if (spriteFile != null) { SetSprite(spriteFile); } else { throw new CYFException("missing sprite"); } ui = FindObjectOfType <UIController>(); if (MaxHP == 0) { MaxHP = HP; } textBubbleSprite = Resources.Load <Sprite>("Sprites/UI/SpeechBubbles/right"); /*if (script.GetVar("canspare") == null) CanSpare = false; * if (script.GetVar("cancheck") == null) CanCheck = true;*/ } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage); } catch (Exception ex) { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); } }
void Interrupt(DynValue text, string nextState = "MENU") { if (currentState != State.INTERRUPT) { script.Call("OnInterrupt", DynValue.NewString(nextState)); try { interruptState = (State)Enum.Parse(typeof(State), nextState, true); } catch { UnitaleUtil.DisplayLuaError("Interrupting the shop menu", "\"" + nextState + "\" is not a valid shop state."); return; } ChangeState(State.INTERRUPT, 0, text); } }
public void ForceAttack(int enemyNumber, int damage = -478294) { if (enemyNumber <= UIController.instance.encounter.EnabledEnemies.Length && enemyNumber > 0) { //UIController.instance.SwitchState(UIController.UIState.ATTACKING); UIController.instance.fightUI.targetNumber = 1; UIController.instance.fightUI.targetIDs = new int[] { enemyNumber - 1 }; UIController.instance.fightUI.quickInit(UIController.instance.encounter.EnabledEnemies[enemyNumber - 1], damage); } else { UnitaleUtil.DisplayLuaError("Force Attack", "Enemy number " + enemyNumber + " doesn't exist."); } }
public void ChangeTarget(int index) { if (UIController.instance.state == UIController.UIState.ATTACKING) { if (index <= UIController.instance.encounter.EnabledEnemies.Length && index > 0) { UIController.instance.fightUI.ChangeTarget(UIController.instance.encounter.EnabledEnemies[index - 1]); } else { UnitaleUtil.DisplayLuaError("Changing the target", "Enemy number " + index + " doesn't exist."); } } }
/// <summary> /// Sets an encounter of the current mod folder, with a given encounter name /// The boolean is used to tell if the encounter anim will be short /// </summary> /// <param name="encounterName"></param> /// <param name="quickAnim"></param> [CYFEventFunction] public void SetBattle(string encounterName = "", string anim = "normal", bool ForceNoFlee = false) { try { anim = anim.ToLower(); if (anim != "normal" && anim != "fast" && anim != "instant") { throw new System.Exception(); } } catch { UnitaleUtil.DisplayLuaError(appliedScript.scriptname, "General.SetBattle: Invalid animation \"" + anim.ToString() + "\".\nIt should be\"normal\", \"fast\" or \"instant\"."); } PlayerOverworld.instance.SetEncounterAnim(encounterName, anim, ForceNoFlee); }