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); } }
/// <summary> /// Attempts to initialize the encounter's script file and bind encounter-specific functions to it. /// </summary> /// <returns>True if initialization succeeded, false if there was an error.</returns> private bool initScript() { script = new ScriptWrapper(); script.scriptname = StaticInits.ENCOUNTER; string scriptText = ScriptRegistry.Get(ScriptRegistry.ENCOUNTER_PREFIX + StaticInits.ENCOUNTER); try { script.DoString(scriptText); } catch (InterpreterException ex) { UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, ex.DecoratedMessage); return(false); } script.Bind("RandomEncounterText", (Func <string>)RandomEncounterText); script.Bind("CreateProjectile", (Func <Script, string, float, float, DynValue>)CreateProjectile); script.Bind("CreateProjectileAbs", (Func <Script, string, float, float, DynValue>)CreateProjectileAbs); script_ref = script; return(true); }
private void Start() { try { GameObject go = Resources.Load <GameObject>("Prefabs/MonsterDuster"); if (go != null && go.ToString().ToLower() != "null") { MonsterDusterPrefab = go; } 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.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; } Sprite _spr = Resources.Load <Sprite>("Sprites/UI/SpeechBubbles/right"); if (_spr != null && _spr.ToString().ToLower() != "null") { textBubbleSprite = _spr; } /*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); } }