Skip to main content

Rules

EnemyMovingOntoDifferentEnemyRule

This rule is part of the game's movement system and applies specifically to entities of type Enemy.

What the Rule Does

In the context of the IsValid method, this rule checks whether an enemy entity is trying to move into a grid position that is already occupied by another enemy entity. If the grid position is indeed occupied, the rule goes further to examine if the enemy at the destination grid position is of the same character type as the moving enemy.

  • If yes: The rule returns true, allowing the movement.
  • If no: The rule logs an error and returns false, preventing the enemy from moving onto that position.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity trying to move.
  • Vector2 gridNewPosition: The new grid position to which the entity is trying to move.
  • HashSet<Vector2> obstaclePositions: A list of positions occupied by obstacles.
  • HashSet<Vector2> enemyPositions: A list of positions occupied by enemies.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position.

Flow of Logic

  1. The method first checks if the entity in question is of type Enemy and if the grid position it aims to move to (gridNewPosition) is already occupied by another enemy entity (enemyPositions.Contains(gridNewPosition)).
  2. If both conditions are met, it gathers a list of entities at that grid position (getEntitiesAtPosition(gridNewPosition)).
  3. If the list of entities is empty, it returns false.
  4. Then, the method checks the character type of the first entity in that position. If it's different from the moving enemy's character type, the method logs an error and returns false.

By enforcing this rule, the game prevents enemies of different types from stacking on top of each other in the same grid cell.

EnemyMovingOntoMaxStackRule

This rule is part of the game's movement system and is specific to entities of type Enemy.

What the Rule Does

The rule checks whether an enemy entity is trying to move into a grid position that is already occupied by another enemy entity of the same character type. If this is the case, it then checks if moving onto that grid cell would exceed the maximum stacking limit for that character type.

  • If yes: The rule logs an error and returns false, disallowing the movement.
  • If no: The rule returns true, allowing the movement.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity that is trying to move.
  • Vector2 gridNewPosition: The new grid position the entity is attempting to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions occupied by obstacles.
  • HashSet<Vector2> enemyPositions: A list of positions occupied by enemies.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position.

Flow of Logic

  1. Initially, the method checks if the entity in question is of type Enemy and if its desired grid position (gridNewPosition) is already occupied by another enemy (enemyPositions.Contains(gridNewPosition)).
  2. If both conditions are met, it fetches a list of entities at that grid position (getEntitiesAtPosition(gridNewPosition)).
  3. If the list of entities is empty, it returns false.
  4. Next, the method checks if the character type of the first entity at that position is the same as the moving entity's character type (entitesAtPos[0].Character == entity.Character).
  5. If this is true, it then checks if the number of entities already at the position has reached or exceeded the maximum stacking limit (entitesAtPos.Count >= entity.MaxStacking).
  6. If the maximum stacking limit is reached or exceeded, the method logs an error and returns false.

By employing this rule, the game prevents excessive stacking of enemies of the same type in the same grid cell, adhering to each character's MaxStacking property.

EnemyMovingOntoPlayerRule

This rule is a part of the game's movement system and specifically targets entities of type Enemy.

What the Rule Does

The rule checks whether an enemy entity is attempting to move onto the grid position currently occupied by the player. If so, it triggers actions to:

  1. Inflict damage to the player character based on the enemy's Damage attribute.
  2. Notify the enemy entity that it has successfully damaged the player.
  3. Disallow the enemy entity's movement to that specific grid position.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity (in this case, an enemy) that is trying to move.
  • Vector2 gridNewPosition: The new grid position the entity is attempting to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions occupied by obstacles.
  • HashSet<Vector2> enemyPositions: A list of positions occupied by enemies.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position.

Constructor

The rule class is initialized with an instance of the GameManager, allowing it to interact with the game state and specifically the player.

csharpCopy code

public EnemyMovingOntoPlayerRule(GameManager gameManagerInstance) { this.gameManagerInstance = gameManagerInstance; }

Flow of Logic

  1. The method checks if the entity in question is of type Enemy.
  2. It then checks if the enemy's desired new grid position (gridNewPosition) is the same as the current position of the player (GridManager.Instance.playerPosition).
  3. If both conditions are met, the enemy will inflict damage on the player (gameManagerInstance.Player.TakeDamage(entity.Damage, entity)).
  4. The enemy entity is then notified that it has successfully damaged the player (entity.ThisEntityDamagedPlayer()).
  5. The method returns false to indicate that the enemy's move to the player's position is not valid.

By enforcing this rule, the game handles interactions between enemy entities and the player when they try to occupy the same grid position.

ObstacleRule

This rule is part of the game's movement validation system and it specifically targets the Player entity when an obstacle is involved.

What the Rule Does

The rule checks if the entity's new intended grid position contains an obstacle. If so, the movement is blocked for player entities.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity that is attempting to move.
  • Vector2 gridNewPosition: The new grid position that the entity aims to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions that are currently occupied by obstacles.
  • HashSet<Vector2> enemyPositions: A list of positions that are currently occupied by enemies.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position.

Flow of Logic

  1. The method checks whether the new grid position (gridNewPosition) that the entity aims to move to is in the list of obstacle positions (obstaclePositions).
  2. If an obstacle is indeed at that position, it further checks if the entity is a Player.
  3. If both conditions are met, a debug log is generated stating that the player can't move onto an obstacle (DebugLogger.Log($"{entity.Name} can't move onto an obstacle")).
  4. The method then returns false to indicate that the move is not valid for the player entity.

This rule ensures that player characters cannot move into positions containing obstacles, providing an additional layer of challenge and complexity in navigating the game world.

PlayerMovingOntoAPortal

This rule handles the player entity's interaction with a specific type of obstacle called a "Doodad," which may act as a portal.

What the Rule Does

When a player moves onto a grid position that contains an obstacle, the rule checks if the obstacle is a portal (a specific type of Doodad). If it is, the player's movement is halted, and certain game events may be triggered, such as initiating dialogue or marking the portal as investigated.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity that is attempting to move.
  • Vector2 gridNewPosition: The new grid position that the entity aims to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions that are currently occupied by obstacles.
  • HashSet<Vector2> enemyPositions: A list of positions that are currently occupied by enemies.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position.

Flow of Logic

  1. Initial Check: The rule starts by checking if the player's intended movement is to a grid position that contains an obstacle.
  2. Identify Obstacle: If so, it identifies the specific obstacle at that position using GridManager.Instance.GetObstacleAtPosition().
  3. Is it a Doodad?: The rule uses pattern matching to check if the obstacle is of type "Doodad."
  4. Portal Check: If it is a Doodad, it checks if the Doodad has a PortalLocation.
    • If so, a log is generated to indicate the player has moved onto a portal.
  5. Event Trigger and Dialogue: If the Doodad has a dialogue attached, and the portal hasn't been investigated before, it triggers a new event ("PortalInvestigated: PortalLocation") and starts the dialogue.
  6. Movement Halt: Finally, the movement is halted by returning false.

This rule enhances gameplay by introducing portals that can trigger events or dialogue when a player moves onto them. It effectively turns certain obstacles into interactive elements that can engage the player in new ways.

PlayerMovingOntoEnemyRule

This rule governs the behavior when a player character tries to move into a grid position currently occupied by an enemy.

What the Rule Does

The rule prevents a player from moving onto a grid space that is currently occupied by an enemy. Essentially, it blocks the player from overlapping with enemy characters on the grid.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity that is attempting to move. In this context, it's the player.
  • Vector2 gridNewPosition: The new grid position the entity aims to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions that are currently occupied by obstacles. Not directly used in this rule but required by the interface.
  • HashSet<Vector2> enemyPositions: A list of positions that are currently occupied by enemies.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position. Not directly used in this rule but required by the interface.

Flow of Logic

  1. Initial Check: The rule starts by checking if the entity attempting to move is a player and if their intended new grid position is currently occupied by an enemy.
  2. Block Movement: If both conditions are met, the movement is halted by returning false.

This rule ensures that players and enemies maintain their separate spaces on the grid, contributing to the strategic elements of the game. It's a simple but essential rule for maintaining game integrity.

PlayerMovingOntoTreasureChestRule

This rule handles the player's interaction with treasure chests on the game grid. Specifically, it triggers an action when the player moves onto a grid cell containing a treasure chest.

What the Rule Does

The rule checks if a player is moving onto a grid cell that contains a treasure chest. If so, it triggers an event for picking up the treasure chest.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity that is attempting to move. In this context, it's the player.
  • Vector2 gridNewPosition: The new grid position that the entity aims to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions currently occupied by obstacles. Not directly used in this rule but required by the interface.
  • HashSet<Vector2> enemyPositions: A list of positions currently occupied by enemies. Not directly used in this rule but required by the interface.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position. Not directly used in this rule but required by the interface.

Flow of Logic

  1. Initial Check: The rule checks if the entity attempting to move is a player and if their intended new grid position contains a treasure chest.
  2. Trigger Pickup: If both conditions are met, the code logs that the player has moved onto a treasure chest and then calls the PickupChest method on the corresponding treasure chest.
  3. Block Further Movement: The method then returns false, which should prevent the player from moving onto the treasure chest (assuming that picking up the chest removes it from the grid).

This rule adds an interaction layer between the player and the environment, enriching the gameplay by allowing treasure chests to be collected when a player moves over them.

PlayerMovingOntoXpCrystalRule

This rule handles how the player interacts with XP (Experience Points) Crystals in the game grid. The rule gets triggered when a player entity moves onto a grid cell that contains one or more XP Crystals.

What the Rule Does

The rule performs a special rubber band animation on each XP Crystal present at the grid cell the player is moving onto.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity attempting to move; in this context, it's the player.
  • Vector2 gridNewPosition: The new grid position the entity aims to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions currently occupied by obstacles. Not directly used in this rule but required by the interface.
  • HashSet<Vector2> enemyPositions: A list of positions currently occupied by enemies. Not directly used in this rule but required by the interface.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position. Not directly used in this rule but required by the interface.

Flow of Logic

  1. Initial Check: The rule first checks if the entity attempting to move is a player and if their intended grid cell contains any XP Crystals.

  2. Trigger Animation: If both conditions are met, the rule iterates through all the XP Crystals in that particular grid cell and triggers a DoRubberBandAnimation method on each of them.

  3. Prevent Movement: Lastly, the method returns false, effectively stopping the player from moving onto the cell. This is based on the assumption that triggering the rubber band animation also results in the XP Crystals being collected, thus changing the state of the cell.

By implementing this rule, you create an interaction layer between the player and XP Crystals, adding an animated visual element to the gameplay when XP Crystals are collected.

SteamPoweredTreantRule

This rule manages the behavior of a special type of enemy, the Steam Powered Treant, when it tries to move onto a grid cell that already contains other entities, possibly enemies.

What the Rule Does

The rule enforces a unique attack logic for Steam Powered Treant, causing it to deal damage to other entities it moves onto if those entities are not also Steam Powered Treants.

Method Signature

csharpCopy code

public bool IsValid(Entity entity, Vector2 gridNewPosition, HashSet<Vector2> obstaclePositions, HashSet<Vector2> enemyPositions, GetEntitiesAtPositionDelegate getEntitiesAtPosition)

Parameters:

  • Entity entity: The entity attempting to move; in this context, it's the Steam Powered Treant.
  • Vector2 gridNewPosition: The new grid position the entity aims to move to.
  • HashSet<Vector2> obstaclePositions: A list of positions currently occupied by obstacles. Not directly used in this rule but required by the interface.
  • HashSet<Vector2> enemyPositions: A list of positions currently occupied by enemies.
  • GetEntitiesAtPositionDelegate getEntitiesAtPosition: A delegate to get entities at a specific grid position.

Flow of Logic

  1. Identify Entity: The rule first checks whether the entity that wants to move is a Steam Powered Treant and if it is moving onto a cell containing enemy entities.

  2. Check for Entities: Retrieves the list of entities at the target position using getEntitiesAtPosition.

  3. Damage Logic: If the target cell has entities that are not Steam Powered Treants, the Treant will inflict damage on all of them. This is executed by calling the TakeDamage method on each entity in the target cell.

  4. Prevent Movement: Finally, the method returns false, stopping the Steam Powered Treant from moving onto the cell after dealing the damage.

This rule adds a unique gameplay mechanic for the Steam Powered Treant character, making it particularly dangerous to other entities it might move onto. This can add another layer of strategic complexity to your game.