public void ConsumeTurn(Dungeon.Dungeon dungeon) { if (_character != null) { _character.TickTurn_Status(); _character.Tick_StatRegen(); } }
protected MoveResult Move(Dungeon.Dungeon dungeon, MoveDirection dir, bool isPlayer) { if (_character == null) { return(MoveResult.None); } var move = DirectionToVec(dir); return(Character.Move(move, isPlayer)); }
private void TickTargetPosition(Dungeon.Dungeon dungeon) { if (_itemPendingUseFromTargetPosition == null) { _mode = InputMode.Character; //_targetGameObject?.SetActive(false); if (_targetGameObject != null) { GameObject.Destroy(_targetGameObject); } return; } if (Input.GetKeyDown(KeyCode.Escape)) { _mode = InputMode.Character; _itemPendingUseFromTargetPosition = null; //_targetGameObject?.SetActive(false); if (_targetGameObject != null) { GameObject.Destroy(_targetGameObject); } return; } if (Input.GetKeyDown(KeyCode.E)) { _mode = InputMode.Character; if (Character.TryCastSpell(_itemPendingUseFromTargetPosition, _targetPosition)) { SpendTurn(dungeon); } _itemPendingUseFromTargetPosition = null; //_targetGameObject?.SetActive(false); if (_targetGameObject != null) { GameObject.Destroy(_targetGameObject); } return; } MoveResult result = MoveResult.None; MoveDirection dir = CheckMoveInput(); var move = DirectionToVec(dir); _targetPosition += move; if (_targetGameObject != null) { _targetGameObject.transform.position = new Vector3(_targetPosition.x, _targetPosition.y, 0); } }
public override void Tick(Dungeon.Dungeon dungeon) { switch (_mode) { case InputMode.Character: TickCharacter(dungeon); break; case InputMode.TargetPosition: TickTargetPosition(dungeon); break; } }
public void UpdateVisibility(Dungeon.Dungeon dungeon) { if (Character != null) { foreach (var tile in dungeon.Tiles) { if (Character.Context.FieldOfView.ContainsKey(tile.Key)) { tile.Value.Visibility(true); } else { tile.Value.Visibility(false); } } foreach (var character in dungeon.Characters) { if (character == Character) { continue; } if (Character.Context.FieldOfView.ContainsKey(character.Position)) { character.Visibility(true); } else { character.Visibility(false); } } foreach (var item in dungeon.WorldItems) { if (Character.Context.FieldOfView.ContainsKey(item.WorldPosition)) { item.Visibility(true); } else { item.Visibility(false); } } } }
private void SpendTurn(Dungeon.Dungeon dungeon) { // We tick the AI first, so that we're not updating status effects until NPCs have had the chance to add new ones. dungeon.TickAI(); if (Character == null || Character.IsDead) { return; } ConsumeTurn(dungeon); Character.TickTurn_Sensors(); UpdateVisibility(dungeon); UpdateMap(); UpdateInventory(); UpdateScraps(); UpdateStatuses(); }
public override void Tick(Dungeon.Dungeon dungeon) { if (Character == null || Character.IsDead) { return; } Character.TickTurn_Sensors(); if (_brain != null) { int steps = 0; Character.Context.SetState(CharacterWorldState.HasConsumedTurn, false, EffectType.Permanent); while (Character.Context.HasState(CharacterWorldState.HasConsumedTurn) == false) { steps++; _brainHandler.Tick(_brain, Character.Context); if (steps > 10) { break; } } if (Character.Context.LogDecomposition) { UnityEngine.Debug.Log("---------------------- DECOMP LOG --------------------------"); while (Character.Context.DecompositionLog?.Count > 0) { var entry = Character.Context.DecompositionLog.Dequeue(); var depth = FluidHTN.Debug.Debug.DepthToString(entry.Depth); //Console.ForegroundColor = entry.Color; var color = ColorUtility.ToHtmlStringRGB(FromColor(entry.Color)); UnityEngine.Debug.Log($"<color={color}>{depth}{entry.Name}: {entry.Description}</color>"); } //Console.ResetColor(); UnityEngine.Debug.Log("-------------------------------------------------------------"); } } ConsumeTurn(dungeon); }
public static bool IsConnected(Dungeon dungeon, DungeonTheme theme, int2 start, int2 end) { List <int2> closed = new List <int2>(); return(Floodfill(dungeon, theme, start, end, closed)); }
private void AddCaveFeatures(Dungeon dungeon, bool leftToRight, bool upToDown, int maxModifications) { if (maxModifications <= 0) { return; } var halfWidth = _meta.Width / 2; var halfHeight = _meta.Height / 2; int modifications = 0; var startIndexW = leftToRight ? -halfWidth : halfWidth; var endIndexW = leftToRight ? halfWidth : -halfWidth; var incrementW = leftToRight ? 1 : -1; var startIndexH = upToDown ? -halfHeight : halfHeight; var endIndexH = upToDown ? halfHeight : -halfHeight; var incrementH = upToDown ? 1 : -1; for (var dx = startIndexW; dx <= endIndexW; dx += incrementW) { for (var dy = startIndexH; dy <= endIndexH; dy += incrementH) { var x = _meta.CenterX + dx; var y = _meta.CenterY + dy; var key = new int2(x, y); if (dungeon.ValueMap.ContainsKey(key) == false) { continue; } var value = dungeon.ValueMap[key]; if (value.Room != this) { continue; } if (value.Index == DungeonTile.Index.Wall) { if (GetAdjacentIndex(dungeon, key, BuilderDirection.East) == DungeonTile.Index.Wall && GetAdjacentIndex(dungeon, key, BuilderDirection.West) == DungeonTile.Index.Floor) { if (TryConvertIndexAtoB(dungeon, key, BuilderDirection.West, DungeonTile.Index.Floor, DungeonTile.Index.Wall, 10)) { modifications++; } } else if (GetAdjacentIndex(dungeon, key, BuilderDirection.East) == DungeonTile.Index.Floor && GetAdjacentIndex(dungeon, key, BuilderDirection.West) == DungeonTile.Index.Wall) { if (TryConvertIndexAtoB(dungeon, key, BuilderDirection.East, DungeonTile.Index.Floor, DungeonTile.Index.Wall, 10)) { modifications++; } } if (GetAdjacentIndex(dungeon, key, BuilderDirection.North) == DungeonTile.Index.Wall && GetAdjacentIndex(dungeon, key, BuilderDirection.South) == DungeonTile.Index.Floor) { if (TryConvertIndexAtoB(dungeon, key, BuilderDirection.South, DungeonTile.Index.Floor, DungeonTile.Index.Wall, 10)) { modifications++; } } else if (GetAdjacentIndex(dungeon, key, BuilderDirection.North) == DungeonTile.Index.Floor && GetAdjacentIndex(dungeon, key, BuilderDirection.South) == DungeonTile.Index.Wall) { if (TryConvertIndexAtoB(dungeon, key, BuilderDirection.North, DungeonTile.Index.Floor, DungeonTile.Index.Wall, 10)) { modifications++; } } } if (modifications >= maxModifications) { return; } } } }
public abstract void Tick(Dungeon.Dungeon dungeon);
private void TickCharacter(Dungeon.Dungeon dungeon) { if (Character == null || Character.IsDead) { return; } // Cheats if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Alpha1)) { Character.AddTimedStatus(CharacterStatusType.Stunned, 2); Debug.Log($"{Character.name} got stunned!"); return; } else if (Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Alpha2)) { Character.GodMode = !Character.GodMode; return; } // Logic if (Input.GetKeyDown(KeyCode.E)) { var item = dungeon.GetItemAt(Character.Position); if (item == null) { item = dungeon.GetItemAt(Character.Position + _lastMoveDir); if (item == null) { return; } } if (Character.TryInteract(item) == false) { return; } } else if (GetInventoryKeyDown(out var index)) { if (index >= Character.Inventory.Count) { return; } var item = Character.Inventory[index]; if (item.Meta.Type == ItemType.Weapon && Character.PrimaryWeapon != item) { Character.SetPrimaryWeapon(item); } else if (item.Meta.Type == ItemType.Spell) { if (Character.CanCastSpell(item) == false) { return; } _itemPendingUseFromTargetPosition = item; _mode = InputMode.TargetPosition; _targetPosition = Character.FindDefaultTargetPosition(item, _lastMoveDir); _targetGameObject = GameObject.Instantiate(_targetGameObjectPrefab); _targetGameObject.SetActive(false); _targetGameObject.transform.position = new Vector3(_targetPosition.x, _targetPosition.y, 0); var shape = item.GetAbilityShape(Character.Context); var radius = item.GetLocalImpactRadius(Character.Context); if (radius > 0) { var sqRad = radius * radius; for (var y = -radius; y <= radius; y++) { for (var x = -radius; x <= radius; x++) { if (x == 0 && y == 0) { continue; } var p = new int2(x, y); if (shape == AbilityShape.FilledCircle) { var sqDist = math.distancesq(p, int2.zero); if (sqDist > sqRad) { continue; } } var childTarget = new GameObject("T").AddComponent <SpriteRenderer>(); childTarget.sprite = _targetGameObject.GetComponent <SpriteRenderer>().sprite; childTarget.transform.SetParent(_targetGameObject.transform, false); childTarget.transform.localPosition = new Vector3(x, y, 0); } } } _targetGameObject?.SetActive(true); return; } else { return; } } else { MoveResult result = MoveResult.None; MoveDirection dir = CheckMoveInput(); if (dir != MoveDirection.None) { result = Move(dungeon, dir, true); _lastMoveDir = DirectionToVec(dir); } // We did not consume a turn if (result == MoveResult.None) { return; } if (result == MoveResult.Collided) { _forceKeyDown = true; return; } if (result == MoveResult.Bump) { if (Character.Context.CurrentBumpTarget != null) { if (Character.Context.CurrentBumpTarget is Character.Character c) { Character.Melee(c); } _forceKeyDown = true; } else { Debug.LogError("This should never happen"); } } } SpendTurn(dungeon); }