/// <summary> /// Handles the inputs for the element selection /// </summary> private void SelectElements() { if (this.firstSpirit == null || this.secondSpirit == null) { return; } // Stores the element inputs inside the spirits var elementInput = this.GetElementInput(); if (elementInput != SpiritState.None) { if (this.firstSpirit.state == SpiritState.None) { this.firstSpirit.CmdUpdateState(elementInput); } else if (this.secondSpirit.state == SpiritState.None) { this.secondSpirit.CmdUpdateState(elementInput); } } // Cast Spell if both spirits have en element selected if (this.firstSpirit.state != SpiritState.None && this.secondSpirit.state != SpiritState.None) { if (!this.inputController.castInput && this.inputController.type != MappingType.JoyStick) { return; } this.state = MagicSystemState.SelectSpellcastDirection; this.castIndicator.gameObject.SetActive(true); } }
/// <summary> /// Handles the state and the inputs for the magic system /// </summary> private void Update() { switch (this.state) { case MagicSystemState.ElementSelection: this.SelectElements(); break; case MagicSystemState.SelectSpellcastDirection: this.SelectSpellCastDirection(); break; case MagicSystemState.SpellCasting: this.CastSpell(); break; } // Cancel Spell cast if (this.inputController.cancelInput) { this.firstSpirit.CmdUpdateState(SpiritState.None); this.secondSpirit.CmdUpdateState(SpiritState.None); this.state = MagicSystemState.ElementSelection; this.castIndicator.gameObject.SetActive(false); } }
/// <summary> /// Plays the spellcast animation and creates the spell /// </summary> private void CastSpell() { var firstState = this.firstSpirit.state; var secondState = this.secondSpirit.state; this.firstSpirit.CmdUpdateState(SpiritState.None); this.secondSpirit.CmdUpdateState(SpiritState.None); this.state = MagicSystemState.ElementSelection; this.CmdCreateSpell(firstState, secondState, this.transform.position, this.castIndicator.currentOrientation); }
/// <summary> /// Shows an arrow to select the spell cast direction /// </summary> private void SelectSpellCastDirection() { this.castIndicator.UpdateDirection(this.transform.position, this.inputController.aimDirecton); switch (this.inputController.type) { case MappingType.JoyStick: if (this.inputController.fireElementInput || this.inputController.castInput || this.inputController.waterElementInput || this.inputController.castInput) { this.state = MagicSystemState.SpellCasting; this.castIndicator.gameObject.SetActive(false); } break; case MappingType.KeyBoard: case MappingType.Mouse: if (this.inputController.castInput) { this.state = MagicSystemState.SpellCasting; this.castIndicator.gameObject.SetActive(false); } break; } }
/// <summary> /// Defines some default values on the start of the game /// </summary> void Start() { this.spells = this.GetComponent <SpellStorage>(); this.state = MagicSystemState.ElementSelection; this.castIndicator.gameObject.SetActive(false); }