public IEnumerator StepMultiRoutine(EightDir dir, int count) { if (GetComponent <PCEvent>() != null) { map.GetComponent <LineOfSightEffect>().RecalculateVisibilityMap(); } for (int i = 0; i < count; i += 1) { Vector2Int at = location; yield return(StartCoroutine(StepRoutine(at, at + dir.XY()))); at += dir.XY(); } }
public void Knockback(EightDir dir, int power) { float height = me.map.terrain.HeightAt(location); for (int i = 0; i < power; i += 1) { Vector2Int to = me.location + dir.XY(); float toHeight = me.map.terrain.HeightAt(to); if (!me.CanPassAt(to) || toHeight > height) { break; } chara.PerformWhenDoneAnimating(GetComponent <CharaEvent>().StepRoutine(location, to, false)); me.location = to; if (toHeight < height) { float delta = height - toHeight; if (delta > unit.GetMaxDescent()) { int dmg = unit.CalcDropDamage(delta); battle.Log(unit + " took " + dmg + " damage in the fall!"); unit.TakeDamage(dmg, damageAnimation); break; } } } }
public IEnumerator RawNextMapRoutine() { bool swapped = false; pc.GetComponent <MapEvent>().SetLocation(new Vector2Int(0, 0)); activeMap.GetComponent <BattleController>().Clear(); MapGenerator oldGen = activeMap.GetComponent <MapGenerator>(); Map oldMap = activeMap; int level = oldGen.level; MapGenerator newGen = activeMap.gameObject.AddComponent <MapGenerator>(); newGen.GenerateMesh(oldGen); Destroy(oldGen); activeMap.GetComponent <LineOfSightEffect>().Erase(); if (activeMap != oldMap) { swapped = true; pc.GetComponent <CharaEvent>().facing = EightDir.N; Destroy(oldGen.gameObject); activeMap.AddEvent(pc.GetComponent <MapEvent>()); } MapCamera cam = FindObjectOfType <MapCamera>(); if (cam.target != pc.GetComponent <MapEvent3D>()) { cam.target = activeMap.GetEventNamed("ZoomTarget").GetComponent <MapEvent3D>(); } activeMap.GetComponent <LineOfSightEffect>().RegenSitemap(activeMap.GetComponent <TacticsTerrainMesh>()); RogueUI ui = FindObjectOfType <RogueUI>(); ui.narrator.Clear(); if (level == 0 && !seenTutorial) { seenTutorial = true; yield return(ui.TutorialRoutine()); } yield return(ui.EditSpellsRoutine()); Vector2Int loc = activeMap.GetEventNamed("TeleStart").location; EightDir dir = pc.GetComponent <CharaEvent>().facing; loc += dir.XY() * -2; pc.GetComponent <MapEvent>().SetLocation(loc); activeMap.GetComponent <LineOfSightEffect>().RecalculateVisibilityMap(); if (swapped) { StartCoroutine(activeMap.GetComponent <BattleController>().BattleRoutine()); } }
private bool TryStep(EightDir dir) { //if (Time.fixedTime - lastStepTime < minTimeBetweenMoves) { // return true; //} Vector2Int target = GetComponent <MapEvent>().location + dir.XY(); if (GetComponent <MapEvent>().CanPassAt(target) && constrainer(target)) { StartCoroutine(GetComponent <MapEvent>().StepRoutine(dir)); lastStepTime = Time.fixedTime; } if (scanner != null) { IEnumerator result = scanner(GetComponent <MapEvent>().location); if (result != null) { StartCoroutine(result); } } return(true); }
private void SetDirection(EightDir dir) { currentDir = dir; actor.GetComponent <CharaEvent>().facing = dir; GetComponent <MapEvent>().SetLocation(actor.location + dir.XY()); }
public void StepOrAttack(EightDir dir, Result <bool> executeResult) { MapEvent parent = me; Vector2Int vectors = me.location; Vector2Int target = vectors + dir.XY(); GetComponent <CharaEvent>().facing = dir; List <MapEvent> targetEvents = me.map.GetEventsAt(target); if (!GetComponent <BattleEvent>().CanCrossTileGradient(parent.location, target)) { executeResult.value = false; return; } List <MapEvent> toCollide = new List <MapEvent>(); bool passable = parent.CanPassAt(target); foreach (MapEvent targetEvent in targetEvents) { toCollide.Add(targetEvent); passable &= targetEvent.IsPassableBy(parent); } if (passable) { chara.PerformWhenDoneAnimating(me.StepRoutine(location, location + dir.XY(), false)); me.location = target; if (unit.Get(StatTag.MOVE) > 1) { unit.canActAgain = !unit.canActAgain; } else if (unit.Get(StatTag.MOVE) < 1) { unit.isRecovering = true; } if (GetComponent <PCEvent>() != null) { foreach (MapEvent targetEvent in toCollide) { if (targetEvent.switchEnabled) { StartCoroutine(CoUtils.RunWithCallback(targetEvent.CollideRoutine(GetComponent <PCEvent>()), () => { executeResult.value = true; })); return; } } } executeResult.value = true; return; } else { foreach (MapEvent targetEvent in toCollide) { float h1 = unit.battle.map.terrain.HeightAt(location); float h2 = unit.battle.map.terrain.HeightAt(target); //if (GetComponent<PCEvent>() != null) { // if (targetEvent.switchEnabled && !targetEvent.IsPassableBy(parent) // && Mathf.Abs(h1 - h2) <= AttackHeightMax) { // StartCoroutine(CollideRoutine(GetComponent<PCEvent>()); // } //} if (targetEvent.GetComponent <BattleEvent>() != null) { BattleEvent other = targetEvent.GetComponent <BattleEvent>(); if (unit.align != other.unit.align) { if (Mathf.Abs(h1 - h2) > AttackHeightMax) { if (GetComponent <PCEvent>() != null) { unit.battle.Log("Too high up to attack!"); } executeResult.value = false; return; } else { unit.MeleeAttack(other.unit); executeResult.value = true; return; } } } // 7drl antipattern hack alert if (GetComponent <PCEvent>() != null && targetEvent.GetComponent <ChestEvent>() != null) { ChestEvent chest = targetEvent.GetComponent <ChestEvent>(); if (!chest.opened) { StartCoroutine(CoUtils.RunWithCallback(chest.OpenRoutine(GetComponent <PCEvent>()), () => { executeResult.value = true; })); return; } } } } executeResult.value = false; }
public virtual IEnumerator ExecuteDirectionRoutine(EightDir dir) { Vector2Int target = actor.location + dir.XY(); yield return(ExecuteSingleCellRoutine(target)); }
public IEnumerator StepRoutine(EightDir dir, bool updateLoc = true) { return(StepRoutine(location, location + dir.XY(), updateLoc)); }