/// <summary> /// Sets a tone directly, without transition /// </summary> /// <param name="anim"></param> /// <param name="waitEnd"></param> /// <param name="r"></param> /// <param name="g"></param> /// <param name="b"></param> /// <param name="a"></param> [CYFEventFunction] public void SetTone(bool anim, bool waitEnd, int r = 255, int g = 255, int b = 255, int a = 128) { if (r < 0 || r > 255 || r % 1 != 0 || g < 0 || g > 255 || g % 1 != 0 || b < 0 || b > 255 || b % 1 != 0) { throw new CYFException("Screen.SetTone: You can't input a value out of [0; 255] for a color value, as it is clamped from 0 to 255.\nThe number have to be an integer."); } if (GameObject.Find("Tone") == null) { GameObject image = Object.Instantiate(Resources.Load <GameObject>("Prefabs/ImageEvent")); image.GetComponent <Image>().color = new Color(r / 255f, g / 255f, b / 255f, 0); image.name = "Tone"; image.tag = "Event"; image.GetComponent <RectTransform>().SetParent(GameObject.Find("Canvas OW").transform); image.GetComponent <RectTransform>().sizeDelta = new Vector2(1000, 800); image.GetComponent <RectTransform>().position = (Vector2)Camera.main.transform.position; EventManager.instance.events.Add(image); } if (!anim) { GameObject.Find("Tone").GetComponent <Image>().color = new Color32((byte)r, (byte)g, (byte)b, (byte)a); if (a == 0) { EventManager.instance.luaEventOw.Remove("Tone"); } appliedScript.Call("CYFEventNextCommand"); } else if (StCoroutine != null) { StCoroutine("ISetTone", new object[] { waitEnd, r, g, b, a }, appliedScript.GetVar("_internalScriptName").String); } }
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); } }
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); } }
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("Kill", (Action)DoKill); script.Bind("Spare", (Action)DoSpare); script.DoString(scriptText); string spriteFile = script.GetVar("sprite").String; if (spriteFile != null) { SetSprite(spriteFile); } else { throw new InvalidOperationException("missing sprite"); } ui = FindObjectOfType <UIController>(); maxHP = HP; currentHP = 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" + ex.StackTrace); } }
[CYFEventFunction] public void SpawnBoxMenu() { if (StCoroutine != null) { StCoroutine("ISpawnBoxMenu", null, appliedScript.GetVar("_internalScriptName").String); } }
// 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(); }
public bool TryCall(string func, DynValue[] param = null) { try { if (script.GetVar(func) == null) { return(false); } if (param != null) { script.Call(func, param); } else { script.Call(func); } return(true); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message); return(true); } }
private void prepareWave() { DynValue nextWaves = script.GetVar("nextwaves"); waves = new Script[nextWaves.Table.Length]; waveNames = new string[waves.Length]; int currentWaveScript = 0; try { for (int i = 0; i < waves.Length; i++) { currentWaveScript = i; waves[i] = LuaScriptBinder.boundScript(); DynValue ArenaStatus = UserData.Create(ArenaSizer.luaStatus); waves[i].Globals.Set("Arena", ArenaStatus); waves[i].Globals["State"] = (Action <string>)UIController.instance.SwitchStateOnString; waves[i].Globals["CreateProjectile"] = (Func <Script, string, float, float, DynValue>)CreateProjectile; waves[i].Globals["CreateProjectileAbs"] = (Func <Script, string, float, float, DynValue>)CreateProjectileAbs; waves[i].Globals["EndWave"] = (Action)endWaveTimer; 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].DoString(ScriptRegistry.Get(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String)); } } catch (InterpreterException ex) { UnitaleUtil.displayLuaError(nextWaves.Table.Get(currentWaveScript + 1).String + ".lua", ex.DecoratedMessage); } }
/// <summary> /// Makes a choice, like when you have to choose between cinnamon and butterscotch /// </summary> /// <param name="question"></param> /// <param name="varIndex"></param> [CYFEventFunction] public void SetChoice(DynValue choices, string question = "", DynValue forcePosition = null) { // Unfortunately, something weird is happening here // Calling `SetChoice({"Yes", "No"}, nil, true)` fails to pass the final argument if (question != null && forcePosition != null) { PlayerOverworld.instance.UIPos = forcePosition.Type == DataType.Boolean ? (forcePosition.Boolean == true ? 2 : 1) : 0; } else { PlayerOverworld.instance.UIPos = 0; } TextMessage textMsgChoice = new TextMessage("", false, false, true); textMsgChoice.AddToText("[mugshot:null]"); List <string> finalText = new List <string>(); bool[] oneLiners = new bool[2]; List <string[]> preTexts = new List <string[]>(); bool threeLiner = false; //Do not put more than 3 lines and 2 choices //If the 3rd parameter is a string, it has to be a question if (question != "") { textMsgChoice.AddToText("* " + question + "\n"); } for (int i = 0; i < 2; i++) { //If there's no text, just don't print it if (choices.Table.Get(i + 1).String == null) { continue; } preTexts.Add(choices.Table.Get(i + 1).String.Split('\n')); string[] preText = preTexts[preTexts.Count - 1]; oneLiners[i] = preText.Length == 1 && question != ""; if (preText.Length == 3) { threeLiner = true; } if (oneLiners[i]) { string line = preText[0]; preTexts[preTexts.Count - 1] = new string[] { "", line }; } } for (int i = 0; i < 2; i++) { string[] preText = preTexts[i]; for (int j = 0; j < (threeLiner ? 3 : 2); j++) { if (j == finalText.Count) { finalText.Add(""); } finalText[j] += "[charspacing:8] [charspacing:2]" + (j >= preText.Length ? "" : preText[j]) + (i == 0 ? "\t" : "") + "[charspacing:default]"; } } //Add the text to the text to print then the SetChoice function with its parameters for (int i = 0; i < finalText.Count; i++) { if (finalText[i] != "\t") { textMsgChoice.AddToText(finalText[i] + ((i == finalText.Count - 1) ? "" : "\n")); } } textmgr.SetEffect(null); textmgr.SetText(textMsgChoice); textmgr.transform.parent.parent.SetAsLastSibling(); StCoroutine("ISetChoice", new object[] { question != "", oneLiners }, appliedScript.GetVar("_internalScriptName").String); }
void ChangeState(State state, int select = 0, object arg = null) { EnableBigText(bigTexts.Contains(state)); if (currentState == State.INTERRUPT) { interrupted = false; } currentState = state; //Switch comparison states string text; switch (state) { case State.MENU: script.Call("EnterMenu"); if (!interrupted) { sellItem = -1; selection = select; numberOfChoices = 4; tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9] Buy\n Sell\n Talk\n Exit", false, true) }); tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) }); 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) }); infoActive = false; tmInfoParent.transform.position = new Vector3(tmInfoParent.transform.position.x, 70, tmInfoParent.transform.position.z); } break; case State.BUYCONFIRM: currentItemIndex = selection; selection = 1; numberOfChoices = 2; tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][font:uidialoglilspace][linespacing:0][novoice]Buy for\n" + mainPrice[selection] + "G?\n \n Yes\n No", false, true) }); break; case State.SELLCONFIRM: currentItemIndex = selection; selection = 1; numberOfChoices = 2; tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[linespacing:11][noskipatall][font:uidialoglilspace][novoice] Sell for " + Inventory.NametoPrice[Inventory.inventory[currentItemIndex].Name] / 5 + "G?\n Yes\tNo", false, true) }); break; case State.BUY: script.Call("EnterBuy"); if (!interrupted) { selection = select; text = BuildBuyString().Replace("\n", " \n").Replace("\r", " \r").Replace("\t", " \t"); numberOfChoices = text.Split(new char[] { '\n', '\r', '\t' }).Length; tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:9][font:uidialoglilspace]" + script.GetVar("buytalk").String, false, false) }); tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][linespacing:11][font:uidialoglilspace]" + text, 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) }); } break; case State.SELL: script.Call("EnterSell"); if (!interrupted) { selection = select; if (sellItem == -1) { sellItem = Inventory.inventory.Count; } text = BuildSellString(); numberOfChoices = Inventory.inventory.Count + 1; tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:11]" + text, false, true) }); if (Inventory.inventory.Count == 0) { script.Call("FailSell"); if (!interrupted) { HandleCancel(); } } } break; case State.TALK: script.Call("EnterTalk"); if (!interrupted) { selection = select; text = BuildTalkString(); tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + text, false, true) }); tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][font:uidialoglilspace][linespacing:9]" + script.GetVar("talktalk").String, false, false) }); } break; case State.TALKINPROGRESS: script.Call("SuccessTalk", DynValue.NewString(mainName[selection])); if (!interrupted) { selection = 1; TextMessage[] texts = BuildTalkResultStrings(); tmBigTalk.SetTextQueue(texts); utHeart.GetComponent <Image>().enabled = false; } break; case State.EXIT: script.Call("EnterExit"); if (!interrupted) { TextMessage[] texts2 = BuildTextFromTable(script.GetVar("exittalk"), "[linespacing:11]"); tmBigTalk.SetTextQueue(texts2); utHeart.GetComponent <Image>().enabled = false; } break; case State.INTERRUPT: tmBigTalk.SetTextQueue(BuildTextFromTable((DynValue)arg, "[linespacing:11]")); utHeart.GetComponent <Image>().enabled = false; interrupted = true; break; } if (canSelect.Contains(state)) { waitForSelection = true; } }
// 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); } }
[CYFEventFunction] public string GetName() { try { return(appliedScript.GetVar("_internalScriptName").String); } catch { return("4eab1af3ab6a932c23b3cdb8ef618b1af9c02088"); } finally { appliedScript.Call("CYFEventNextCommand"); } }