public void Populate(BattleUnit unit) { this.unit = unit; face.sprite = unit.unit.face; hpBar.Populate(unit.Get(StatTag.MHP), unit.Get(StatTag.HP)); mpBar.Populate(unit.Get(StatTag.MMP), unit.Get(StatTag.MP)); cdBar.Populate(unit.maxCD, unit.Get(StatTag.CD)); }
public void OnTurn() { if (unit != null && !unit.IsDead()) { StartCoroutine(CoUtils.RunParallel(new IEnumerator[] { hpBar.AnimateWithTimeRoutine(unit.Get(StatTag.MHP), unit.Get(StatTag.HP), 0.125f), mpBar.AnimateWithTimeRoutine(unit.Get(StatTag.MMP), unit.Get(StatTag.MP), 0.125f), cdBar.AnimateWithTimeRoutine(unit.maxCD, unit.Get(StatTag.CD), 0.125f), }, this)); } }
void Start() { // Load map XmlDocument mapDoc = new XmlDocument(); mapDoc.PreserveWhitespace = false; try { mapDoc.Load("Assets/Battle/Data/Maps/" + NextMapFile + ".xml"); XmlNode root = mapDoc.SelectSingleNode("map"); grid.info = root.SelectSingleNode("grid") as XmlElement; foreach (XmlElement battleInfo in root.SelectNodes("battle")) { if (battleInfo.GetAttribute("id").Equals(NextBattle)) { // Load agents BattleUnit.Reset(); foreach (XmlElement characterInfo in battleInfo.SelectNodes("character")) { try { string unit = characterInfo.HasAttribute("unit") ? characterInfo.GetAttribute("unit") : "civilian"; BattleBehaviour behaviour; if (characterInfo.HasAttribute("behaviour")) { behaviour = BattleBehaviour.Parse(characterInfo.GetAttribute("behaviour")); } else if (unit.Equals("player")) { behaviour = null; } else if (unit.Equals("civilian")) { behaviour = null; // TODO run away } else { behaviour = new BattleOffensiveBehaviour(); } Character character = AssetHolder.Characters[characterInfo.GetAttribute("name")]; BattleAgent agent = new BattleAgent(character, behaviour); agent.Coordinates = new Vector2Int( int.Parse(characterInfo.GetAttribute("x")), int.Parse(characterInfo.GetAttribute("y")) ); agent.Unit = BattleUnit.Get(unit); agents.Add(agent); BattleTile tile = grid[agent.Coordinates]; BattleActor actor = Instantiate <BattleActor>((BattleActor)AssetHolder.Objects["actor"], tile.ground.transform); actor.Agent = agent; tile.Actor = actor; } catch (System.Exception e) { Debug.Log(e); // TODO } } // Load cutscenes m_Cutscenes = new Dictionary <string, BattleAction>(); foreach (XmlElement cutsceneInfo in battleInfo.SelectNodes("cutscene")) { try { List <BattleAction> cutsceneSequence = new List <BattleAction>(); foreach (XmlNode sceneInfoNode in cutsceneInfo.ChildNodes) { XmlElement sceneInfo = sceneInfoNode as XmlElement; if (sceneInfo != null) { if (sceneInfo.Name.Equals("move")) { string character = sceneInfo.GetAttribute("character"); BattleAgent target = null; foreach (BattleAgent agent in agents) { if (agent.BaseCharacter.Name.Equals(character)) { target = agent; break; } } if (target != null) { cutsceneSequence.Add( new BattleMoveAction( target, new Vector2Int( int.Parse(sceneInfo.GetAttribute("x")), int.Parse(sceneInfo.GetAttribute("y")) ) ) ); } } else if (sceneInfo.Name.Equals("text")) { string character = sceneInfo.GetAttribute("character"); BattleAgent target = null; foreach (BattleAgent agent in agents) { if (agent.BaseCharacter.Name.Equals(character)) { target = agent; break; } } if (target != null) { cutsceneSequence.Add( new BattleDialogueAction(target, sceneInfo.InnerText.Trim()) ); } } } } m_Cutscenes.Add(cutsceneInfo.GetAttribute("trigger"), new BattleSequenceAction(cutsceneSequence)); } catch (System.Exception e) { Debug.Log(e); } } } } BattleAgentUI.Shown = false; BattleSelector.Shown = false; } catch (System.Exception e) { Debug.Log(e); // TODO } }
public void Populate(BattleUnit unit) { text.text = unit.unit.unitName; hpBar.Populate(unit.Get(StatTag.MHP), unit.Get(StatTag.HP)); stagger.Populate(BattleUnit.MaxStagger, unit.Get(StatTag.STAGGER)); }
public IEnumerator SelectSpellsRoutine(Result <List <Intent> > result, BattleUnit hero) { List <Intent> queuedIntents = new List <Intent>(); List <Spell> previousSpells = new List <Spell>(); linker.SetUp((int)hero.Get(StatTag.MAP)); yield return(spellSelect.EnableRoutine(hero.unit.spells)); while (hero.Get(StatTag.AP) > 0) { linker.Populate(previousSpells); Result <Selectable> cardResult = new Result <Selectable>(); yield return(spellSelect.SelectSpellRoutine(cardResult, previousSpells)); if (cardResult.canceled) { // canceled the selection if (queuedIntents.Count > 0) { Global.Instance().Audio.PlaySFX("cancel"); Intent canceled = queuedIntents.Last(); hero.unit.stats.Add(StatTag.AP, canceled.APCost()); queuedIntents.RemoveAt(queuedIntents.Count - 1); previousSpells.RemoveAt(previousSpells.Count - 1); } } else if (cardResult.value.GetComponent <SpellCard>()) { // selected a spell Spell spell = cardResult.value.GetComponent <SpellCard>().spell; linker.Populate(new List <Spell>(previousSpells) { spell }); if (hero.Get(StatTag.AP) > spell.apCost || (hero.Get(StatTag.AP) >= spell.apCost && !spell.LinksToNextSpell())) { Global.Instance().Audio.PlaySFX("confirm"); hero.unit.stats.Sub(StatTag.AP, spell.apCost); // find a target for the spell Result <List <BattleUnit> > targetsResult = new Result <List <BattleUnit> >(); IntentSpell intent = new IntentSpell(this.battle, hero, spell); yield return(intent.AcquireTargetsRoutine(targetsResult)); if (!targetsResult.canceled) { queuedIntents.Add(intent); previousSpells.Add(spell); } else { hero.unit.stats.Add(StatTag.AP, spell.apCost); } } else { Global.Instance().Audio.PlaySFX("error"); } } else { // selected the go ahead if (queuedIntents.Count > 0) { Global.Instance().Audio.PlaySFX("confirm"); break; } else { Global.Instance().Audio.PlaySFX("error"); } } } yield return(spellSelect.DisableRoutine()); result.value = queuedIntents; }