FantasyFrontiers / FantasyFrontiers/FantasyFrontiers

🧑‍🤝‍🧑 NPC RelationSystem

Open
#5 0 comments 0 reactions 0 assignees View on GitHub
enhancement hacktoberfest
Dominant language
Kotlin
Stars
3
Forks
2
PR merge metrics
No merged PRs in 30d

Description

A relationship system could be very useful for shaping interactions and conversations between the player and the NPCs. It can track the development of the relationship between the player and the NPCs over time, making the game world more reactive and dynamic. Here are some considerations for what such a system might look like:

1. **Relationship Status**:
- Define different levels of relationships, e.g., Unknown, Acquaintance, Friend, Close Friend, Enemy, etc.

```kotlin
enum class RelationshipStatus {
UNKNOWN,
ACQUAINTANCE,
FRIEND,
CLOSE_FRIEND,
ENEMY
}
```

2. **Relationship Object**:
- Create an object that represents the relationship between the player and an NPC, including the current relationship status and other relevant information.

```kotlin
data class Relationship(
val npcId: Long,
val status: RelationshipStatus,
val points: Int
)
```

3. **Relationship Manager**:
- Create a manager that manages all of the player's relationships with NPCs and provides functions to earn or lose relationship points and update the relationship status.

```kotlin
class RelationshipManager(
val relationships: MutableMap = mutableMapOf()
) {
fun gainPoints(npcId: Long, points: Int) {
val relationship = relationships[npcId] ?: Relationship(npcId, RelationshipStatus.UNKNOWN, 0)
val updatedPoints = relationship.points + points
val updatedStatus = determineStatus(updatedPoints)
relationships[npcId] = relationship.copy(status = updatedStatus, points = updatedPoints)
}

fun losePoints(npcId: Long, points: Int) {
gainPoints(npcId, -points)
}

private fun determineStatus(points: Int): RelationshipStatus {
return when {
points >= 100 -> RelationshipStatus.CLOSE_FRIEND
points >= 50 -> RelationshipStatus.FRIEND
points >= 10 -> RelationshipStatus.ACQUAINTANCE
points < 0 -> RelationshipStatus.ENEMY
else -> RelationshipStatus.UNKNOWN
}
}
}
```

4. **Integration into the ConversationContext**:
- Use the current relationship status to influence the `ConversationContext`, e.g., by choosing a formal context for unknown NPCs and a friendly context for NPC friends.

```kotlin
fun determineConversationContext(relationshipManager: RelationshipManager, npcId: Long): ConversationContext {
val relationship = relationshipManager.relationships[npcId]
return when (relationship?.status) {
RelationshipStatus.FRIEND, RelationshipStatus.CLOSE_FRIEND -> ConversationContext.FRIENDSHIP
else -> ConversationContext.FORMAL
}
}
```

With such a system, you can manage relationships between the player and NPCs in a structured manner while also having the ability to develop and change these relationships over the course of the game.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.