public override IEnumerator ExecuteCellsRoutine(List <Vector2Int> locations) { yield return(battler.SyncPlayAnim(skill.castAnim)); foreach (Vector2Int location in locations) { BattleEvent target = map.GetEventAt <BattleEvent>(location); if (target == null) { continue; } BattleUnit other = target.unit; battler.GetComponent <CharaEvent>().FaceToward(other.battler.GetComponent <MapEvent>()); EightDir dir = battler.GetComponent <MapEvent>().DirectionTo(other.battler.GetComponent <MapEvent>()); int power = Mathf.RoundToInt(Random.Range(knockbackMin, knockbackMax)); other.battler.Knockback(dir, power); yield return(CoUtils.Wait(0.2f)); if (actor.Get(StatTag.ATTACKS) < 0.5) { actor.isRecovering = true; } if (damageHigh > 0) { int dmg = Mathf.RoundToInt(Random.Range(damageLow, damageHigh)); battle.Log(other + " took " + dmg + " damage."); other.TakeDamage(dmg, damageAnimation); } } }
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 override void OnInspectorGUI() { base.OnInspectorGUI(); CharaEvent chara = (CharaEvent)target; Texture2D tex = (Texture2D)EditorGUILayout.ObjectField("Appearance", chara.spritesheet, typeof(Texture2D), false); if (tex != chara.spritesheet) { chara.spritesheet = tex; chara.UpdateAppearance(); EditorUtility.SetDirty(target); } EightDir facing = (EightDir)EditorGUILayout.EnumPopup("Facing", chara.facing); if (facing != chara.facing) { chara.facing = facing; chara.UpdateAppearance(); EditorUtility.SetDirty(target); } if (Application.isPlaying) { if (GUILayout.Button("Walk test")) { chara.StartCoroutine(WalkTestRoutine(chara)); } } }
public static OrthoDir FromEight(EightDir dir, OrthoDir currentDir) { switch (dir) { case EightDir.N: return(OrthoDir.North); case EightDir.E: return(OrthoDir.East); case EightDir.S: return(OrthoDir.South); case EightDir.W: return(OrthoDir.West); case EightDir.NE: return(currentDir == OrthoDir.North ? OrthoDir.North : OrthoDir.East); case EightDir.SE: return(currentDir == OrthoDir.South ? OrthoDir.South : OrthoDir.East); case EightDir.NW: return(currentDir == OrthoDir.North ? OrthoDir.North : OrthoDir.West); case EightDir.SW: return(currentDir == OrthoDir.South ? OrthoDir.South : OrthoDir.West); default: return(0); } }
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 void UpdateHighlight() { foreach (SpellCard card in cards.Values) { card.selected = false; } if (downButtons.Count > 0) { EightDir dir = EightDir.South; if (downButtons.Contains(OrthoDir.East)) { if (downButtons.Contains(OrthoDir.North)) { dir = EightDir.Northeast; } else if (downButtons.Contains(OrthoDir.South)) { dir = EightDir.Southeast; } else { dir = EightDir.East; } } else if (downButtons.Contains(OrthoDir.West)) { if (downButtons.Contains(OrthoDir.North)) { dir = EightDir.Northwest; } else if (downButtons.Contains(OrthoDir.South)) { dir = EightDir.Southwest; } else { dir = EightDir.West; } } else if (downButtons.Contains(OrthoDir.North)) { dir = EightDir.North; } else if (downButtons.Contains(OrthoDir.South)) { dir = EightDir.South; } if (cards.ContainsKey(dir)) { cards[dir].selected = true; } } }
public IEnumerator NextMapRoutine() { EightDir facing = pc.GetComponent <CharaEvent>().facing; yield return(pc.GetComponent <MapEvent>().StepMultiRoutine(facing, 3)); TransitionData data = Global.Instance().Database.Transitions.GetData(DefaultTransitionTag); yield return(camera.cam.GetComponent <FadeImageEffect>().TransitionRoutine(data, RawNextMapRoutine())); facing = pc.GetComponent <CharaEvent>().facing; yield return(pc.GetComponent <MapEvent>().StepMultiRoutine(facing, 3)); }
public override IEnumerator TryAIUse(AIController ai, Effector effect) { if (Vector2Int.Distance(actor.location, ai.pc.location) < 1.5) { battle.Log(actor + " used " + skill.skillName); EightDir dir = EightDirExtensions.DirectionOf(ai.pc.location - actor.location); return(effect.ExecuteDirectionRoutine(dir)); } else { return(null); } }
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 Enable() { if (gameObject.activeSelf) { return; } gameObject.SetActive(true); currentDir = EightDir.N; Global.Instance().Input.PushListener(this); if (cameraFollows) { Global.Instance().Maps.camera.target = GetComponent <MapEvent3D>(); } }
public static List <EightDir> RandomOrder() { List <EightDir> list = new List <EightDir>((EightDir[])Enum.GetValues(typeof(EightDir))); int n = list.Count; while (n > 1) { n--; int k = UnityEngine.Random.Range(0, n); EightDir value = list[k]; list[k] = list[n]; list[n] = value; } return(list); }
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); }
public static IntVector2 XY(this EightDir dir) { return(dir.GetAttribute <OrthoDirAttribute>().XY); }
public static int Px3DZ(this EightDir dir) { return(dir.GetAttribute <OrthoDirAttribute>().Px3DZ); }
public static string DirectionName(this EightDir dir) { return(dir.GetAttribute <EightDirAttribute>().DirectionName); }
public static int Ordinal(this EightDir dir) { return(dir.GetAttribute <EightDirAttribute>().Ordinal); }
public static Vector3Int Px(this EightDir dir) { return(dir.GetAttribute <EightDirAttribute>().Px); }
public virtual IEnumerator ExecuteDirectionRoutine(EightDir dir) { Vector2Int target = actor.location + dir.XY(); yield return(ExecuteSingleCellRoutine(target)); }
public static Vector2Int XY(this EightDir dir) { return(dir.GetAttribute <EightDirAttribute>().XY); }
public IEnumerator TakeTurnAction() { if (pc.IsDead() || unit.IsDead()) { return(null); } int intel = (int)unit.Get(StatTag.INTELLIGENCE); Result <bool> result = new Result <bool>(); if (HasLeader()) { leaderAI.seenMap[battler.location.x, battler.location.y] += 1; } else { seenMap[battler.location.x, battler.location.y] += 1; } turnsHunting -= 1; // hunt down the hero if we've recently seen them if (battler.CanSeeLocation(battle.map.terrain, pc.location)) { turnsHunting = intel; foreach (SkillData data in unit.unit.innateSkills) { Skill skill = new Skill(data); IEnumerator aiTry = skill.TryAIUse(this); if (aiTry != null) { return(aiTry); } } } if (turnsHunting > 0 || (HasLeader() && leaderAI.turnsHunting > 0)) { List <Vector2Int> path = battle.map.FindPath(battler.GetComponent <MapEvent>(), pc.location, intel); if (path != null && path.Count > 0) { battler.StepOrAttack(battler.GetComponent <MapEvent>().DirectionTo(path[0]), result); return(null); } else { battler.StepOrAttack(battler.GetComponent <MapEvent>().DirectionTo(pc.location), result); return(null); } } // wander randomly EightDir bestDir = EightDirExtensions.RandomDir(); if (HasLeader() && Vector2Int.Distance(unit.location, leader.location) > 2) { bestDir = unit.battler.GetComponent <MapEvent>().DirectionTo(leader.GetComponent <MapEvent>()); } else { if (intel > WanderCutoffInt) { short lowestSeen = short.MaxValue; foreach (EightDir dir in EightDirExtensions.RandomOrder()) { Vector2Int target = battler.location + dir.XY(); if (target.x < 0 || target.x >= battle.map.size.x || target.y < 0 || target.y >= battle.map.size.y) { continue; } int val; if (HasLeader()) { val = leaderAI.seenMap[target.x, target.y]; } else { val = seenMap[target.x, target.y]; } if (val < lowestSeen && battler.GetComponent <MapEvent>().CanPassAt(target)) { lowestSeen = seenMap[target.x, target.y]; bestDir = dir; } } } } battler.StepOrAttack(bestDir, result); return(null); }
private void SetDirection(EightDir dir) { currentDir = dir; actor.GetComponent <CharaEvent>().facing = dir; GetComponent <MapEvent>().SetLocation(actor.location + dir.XY()); }
public static IntVector3 Px3D(this EightDir dir) { return(new IntVector3(dir.Px3DX(), dir.Px3DY(), dir.Px3DZ())); }
public static int Y(this EightDir dir) { return(dir.GetAttribute <OrthoDirAttribute>().Y); }
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 IEnumerator StepRoutine(EightDir dir, bool updateLoc = true) { return(StepRoutine(location, location + dir.XY(), updateLoc)); }
public static int PxZ(this EightDir dir) { return(dir.GetAttribute <EightDirAttribute>().PxZ); }
public bool OnCommand(InputManager.Command command, InputManager.Event eventType) { if (eventType != InputManager.Event.Up || halting) { return(true); } switch (command) { case InputManager.Command.Up: case InputManager.Command.Down: case InputManager.Command.Right: case InputManager.Command.Left: case InputManager.Command.UpLeft: case InputManager.Command.DownLeft: case InputManager.Command.DownRight: case InputManager.Command.UpRight: EightDir dir = EightDirExtensions.FromCommand(command); Global.Instance().Input.RemoveListener(this); unit.battler.StepOrAttack(dir, executeResult); break; case InputManager.Command.Wait: Global.Instance().Input.RemoveListener(this); executeResult.value = true; break; case InputManager.Command.Skill1: case InputManager.Command.Skill2: case InputManager.Command.Skill3: case InputManager.Command.Skill4: case InputManager.Command.Skill5: case InputManager.Command.Skill6: int skillNumber = Global.Instance().Input.CommandToNumber(command) - 1; if (skillNumber < pc.activeBook.spells.Count) { Skill skill = pc.activeBook.spells[skillNumber]; if (unit.CanUse(skill)) { Global.Instance().Input.RemoveListener(this); StartCoroutine(skill.PlaySkillRoutine(unit, executeResult)); } else { if (skill.costMP > 0) { narrator.Log(skill + " costs too much MP to cast.", true); } else { narrator.Log(skill + " is on cooldown.", true); } } } break; case InputManager.Command.Examine: case InputManager.Command.Confirm: Global.Instance().Input.RemoveListener(this); StartCoroutine(ScanRoutine()); rightDisplayEnabled = false; break; case InputManager.Command.Debug: StartCoroutine(spellEditor.ActivateRoutine(this, pc, pc.GetComponent <MapEvent>().map.GetComponent <MapGenerator>().level)); break; case InputManager.Command.Zoom: MapCamera cam = FindObjectOfType <MapCamera>(); if (cam.target == pc.GetComponent <MapEvent3D>()) { cam.target = pc.battle.map.GetEventNamed("ZoomTarget").GetComponent <MapEvent3D>(); cam.targetDistance = 100.0f; } else { cam.targetDistance = 25.0f; cam.target = pc.GetComponent <MapEvent3D>(); } break; } return(true); }
public override IEnumerator ExecuteDirectionRoutine(EightDir dir) { yield return(battler.SyncPlayAnim(skill.castAnim)); actorEvent.GetComponent <CharaEvent>().PerformWhenDoneAnimating(actorEvent.StepRoutine(dir)); }
private void AttemptSetDirection(EightDir dir) { SetDirection(dir); }
void UpdateMoveYawOnPC(ref GameInput input) { //处理输入方向 EightDir inputDir = EightDir.Empty; //前后 float keyForward = Input.GetAxis(KeyboardInput.forward); float gamepadForward = Input.GetAxis(GamePadInput.forward); if (keyForward > 0 || gamepadForward > GamePadInput.joystickThreshold) { inputDir = EightDir.Front; } else if (keyForward < 0 || gamepadForward < -GamePadInput.joystickThreshold) { inputDir = EightDir.Back; } //左右 float keyRight = Input.GetAxis(KeyboardInput.right); float gamepadRight = Input.GetAxis(GamePadInput.right); if (keyRight > 0 || gamepadRight > GamePadInput.joystickThreshold) { if (inputDir == EightDir.Front) { inputDir = EightDir.FrontRight; } else if (inputDir == EightDir.Back) { inputDir = EightDir.BackRight; } else { inputDir = EightDir.Right; } } else if (keyRight < 0 || gamepadRight < -GamePadInput.joystickThreshold) { if (inputDir == EightDir.Front) { inputDir = EightDir.FrontLeft; } else if (inputDir == EightDir.Back) { inputDir = EightDir.BackLeft; } else { inputDir = EightDir.Left; } } if (inputDir == EightDir.Empty) { input.hasMove = false; //没输入方向 } else { input.hasMove = true; //输入方向 } //从八方向转到yaw float yaw = input.aimAngle.y; switch (inputDir) { case EightDir.Front: input.moveYaw = yaw; break; case EightDir.FrontLeft: input.moveYaw = yaw - 45; break; case EightDir.Left: input.moveYaw = yaw - 90; break; case EightDir.BackLeft: input.moveYaw = yaw - 135; break; case EightDir.Back: input.moveYaw = yaw + 180; break; case EightDir.BackRight: input.moveYaw = yaw + 135; break; case EightDir.Right: input.moveYaw = yaw + 90; break; case EightDir.FrontRight: input.moveYaw = yaw + 45; break; default: break; } }