Init
This commit is contained in:
348
content/world/entities/npc/npc-components.fr.md
Normal file
348
content/world/entities/npc/npc-components.fr.md
Normal file
@@ -0,0 +1,348 @@
|
||||
---
|
||||
title: Composants NPC
|
||||
type: docs
|
||||
weight: 2
|
||||
---
|
||||
|
||||
Les composants NPC sont des composants ECS qui stockent les données et l'état des NPCs. Le système inclut plus de 300 composants de base pour diverses fonctionnalités NPC.
|
||||
|
||||
**Package:** `com.hypixel.hytale.server.npc.corecomponents`
|
||||
|
||||
## Vue d'Ensemble des Composants
|
||||
|
||||
Les composants NPC suivent le pattern ECS où les composants sont des conteneurs de données pures attachés aux entity stores.
|
||||
|
||||
```java
|
||||
// Accéder aux composants NPC
|
||||
EntityStore store = npc.getEntityStore();
|
||||
NPCBrainComponent brain = store.getComponent(NPCBrainComponent.class);
|
||||
```
|
||||
|
||||
## Composants Cerveau
|
||||
|
||||
### NPCBrainComponent
|
||||
|
||||
Le composant principal de traitement IA :
|
||||
|
||||
```java
|
||||
public class NPCBrainComponent {
|
||||
private DecisionMaker decisionMaker;
|
||||
private float thinkInterval;
|
||||
private float lastThinkTime;
|
||||
|
||||
public void setDecisionMaker(DecisionMaker maker);
|
||||
public DecisionMaker getDecisionMaker();
|
||||
public boolean shouldThink(float currentTime);
|
||||
}
|
||||
```
|
||||
|
||||
### NPCMemoryComponent
|
||||
|
||||
Stocke les mémoires et connaissances du NPC :
|
||||
|
||||
```java
|
||||
public class NPCMemoryComponent {
|
||||
private Map<String, Memory> memories;
|
||||
private float memoryDuration;
|
||||
|
||||
public void remember(String key, Object value, float duration);
|
||||
public <T> T recall(String key, Class<T> type);
|
||||
public boolean hasMemory(String key);
|
||||
public void forget(String key);
|
||||
}
|
||||
```
|
||||
|
||||
## Composants d'État
|
||||
|
||||
### NPCStateComponent
|
||||
|
||||
État comportemental actuel :
|
||||
|
||||
```java
|
||||
public class NPCStateComponent {
|
||||
private NPCState currentState;
|
||||
private NPCState previousState;
|
||||
private float stateEnterTime;
|
||||
|
||||
public enum NPCState {
|
||||
IDLE,
|
||||
WALKING,
|
||||
RUNNING,
|
||||
ATTACKING,
|
||||
FLEEING,
|
||||
INTERACTING,
|
||||
SLEEPING,
|
||||
DEAD
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### NPCAlertComponent
|
||||
|
||||
Niveau de vigilance et de conscience :
|
||||
|
||||
```java
|
||||
public class NPCAlertComponent {
|
||||
private AlertLevel alertLevel;
|
||||
private float alertDecayRate;
|
||||
private Entity alertSource;
|
||||
|
||||
public enum AlertLevel {
|
||||
RELAXED, // État normal
|
||||
CURIOUS, // Quelque chose a attiré l'attention
|
||||
ALERT, // Investigation active
|
||||
ALARMED, // Menace détectée
|
||||
COMBAT // En combat
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Composants de Cible
|
||||
|
||||
### NPCTargetComponent
|
||||
|
||||
Suivi de cible actuel :
|
||||
|
||||
```java
|
||||
public class NPCTargetComponent {
|
||||
private Ref<EntityStore> currentTarget;
|
||||
private TargetType targetType;
|
||||
private float targetAcquiredTime;
|
||||
private Vector3d lastKnownPosition;
|
||||
|
||||
public enum TargetType {
|
||||
HOSTILE,
|
||||
FRIENDLY,
|
||||
NEUTRAL,
|
||||
OBJECT
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### NPCFocusComponent
|
||||
|
||||
Point de focus visuel :
|
||||
|
||||
```java
|
||||
public class NPCFocusComponent {
|
||||
private Vector3d focusPoint;
|
||||
private Ref<EntityStore> focusEntity;
|
||||
private float focusStrength;
|
||||
private boolean shouldLookAt;
|
||||
}
|
||||
```
|
||||
|
||||
## Composants de Mouvement
|
||||
|
||||
### NPCMovementComponent
|
||||
|
||||
Configuration de mouvement :
|
||||
|
||||
```java
|
||||
public class NPCMovementComponent {
|
||||
private float walkSpeed;
|
||||
private float runSpeed;
|
||||
private float turnSpeed;
|
||||
private boolean canJump;
|
||||
private boolean canSwim;
|
||||
private boolean canClimb;
|
||||
}
|
||||
```
|
||||
|
||||
### NPCPathComponent
|
||||
|
||||
Données de suivi de chemin :
|
||||
|
||||
```java
|
||||
public class NPCPathComponent {
|
||||
private List<Vector3d> currentPath;
|
||||
private int currentWaypointIndex;
|
||||
private float pathRecalculateInterval;
|
||||
private float lastPathTime;
|
||||
|
||||
public Vector3d getCurrentWaypoint();
|
||||
public Vector3d getNextWaypoint();
|
||||
public boolean hasReachedWaypoint(Vector3d position, float threshold);
|
||||
}
|
||||
```
|
||||
|
||||
### NPCNavigationComponent
|
||||
|
||||
Paramètres de navigation :
|
||||
|
||||
```java
|
||||
public class NPCNavigationComponent {
|
||||
private float avoidanceRadius;
|
||||
private float pathfindingRange;
|
||||
private int maxPathLength;
|
||||
private NavigationFlags flags;
|
||||
|
||||
public static class NavigationFlags {
|
||||
public boolean avoidWater;
|
||||
public boolean avoidFire;
|
||||
public boolean canUseDoors;
|
||||
public boolean canBreakBlocks;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Composants de Combat
|
||||
|
||||
### NPCCombatComponent
|
||||
|
||||
Capacités de combat :
|
||||
|
||||
```java
|
||||
public class NPCCombatComponent {
|
||||
private float attackRange;
|
||||
private float attackCooldown;
|
||||
private float lastAttackTime;
|
||||
private DamageType preferredDamageType;
|
||||
private List<String> availableAttacks;
|
||||
}
|
||||
```
|
||||
|
||||
### NPCAggroComponent
|
||||
|
||||
Gestion de l'aggro :
|
||||
|
||||
```java
|
||||
public class NPCAggroComponent {
|
||||
private Map<Ref<EntityStore>, Float> aggroTable;
|
||||
private float aggroDecayRate;
|
||||
private float aggroRange;
|
||||
|
||||
public void addAggro(Ref<EntityStore> entity, float amount);
|
||||
public void removeAggro(Ref<EntityStore> entity);
|
||||
public Ref<EntityStore> getHighestAggroTarget();
|
||||
}
|
||||
```
|
||||
|
||||
## Composants Sociaux
|
||||
|
||||
### NPCFactionComponent
|
||||
|
||||
Affiliation de faction :
|
||||
|
||||
```java
|
||||
public class NPCFactionComponent {
|
||||
private String factionId;
|
||||
private Map<String, FactionRelation> relations;
|
||||
|
||||
public enum FactionRelation {
|
||||
ALLIED,
|
||||
FRIENDLY,
|
||||
NEUTRAL,
|
||||
UNFRIENDLY,
|
||||
HOSTILE
|
||||
}
|
||||
|
||||
public FactionRelation getRelation(String otherFaction);
|
||||
}
|
||||
```
|
||||
|
||||
### NPCDialogueComponent
|
||||
|
||||
Capacités de dialogue :
|
||||
|
||||
```java
|
||||
public class NPCDialogueComponent {
|
||||
private String dialogueTreeId;
|
||||
private Map<String, Boolean> dialogueFlags;
|
||||
private Ref<EntityStore> currentSpeaker;
|
||||
|
||||
public boolean hasDialogue();
|
||||
public void startDialogue(Player player);
|
||||
}
|
||||
```
|
||||
|
||||
## Composants Utilitaires
|
||||
|
||||
### NPCScheduleComponent
|
||||
|
||||
Programme journalier :
|
||||
|
||||
```java
|
||||
public class NPCScheduleComponent {
|
||||
private Map<Integer, ScheduleEntry> schedule;
|
||||
|
||||
public static class ScheduleEntry {
|
||||
public int startHour;
|
||||
public int endHour;
|
||||
public String activity;
|
||||
public Vector3d location;
|
||||
}
|
||||
|
||||
public ScheduleEntry getCurrentActivity(int worldHour);
|
||||
}
|
||||
```
|
||||
|
||||
### NPCInventoryComponent
|
||||
|
||||
Inventaire NPC :
|
||||
|
||||
```java
|
||||
public class NPCInventoryComponent {
|
||||
private ItemContainer inventory;
|
||||
private ItemStack equippedWeapon;
|
||||
private ItemStack equippedArmor;
|
||||
|
||||
public ItemStack getEquippedWeapon();
|
||||
public void equipItem(ItemStack item);
|
||||
}
|
||||
```
|
||||
|
||||
## Enregistrer des Composants Personnalisés
|
||||
|
||||
```java
|
||||
public class MyPlugin extends JavaPlugin {
|
||||
@Override
|
||||
public void start() {
|
||||
// Enregistrer un composant NPC personnalisé
|
||||
getEntityStoreRegistry().registerComponent(
|
||||
"custom_npc_data",
|
||||
CustomNPCComponent.class,
|
||||
CustomNPCComponent::new
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public class CustomNPCComponent {
|
||||
private String customData;
|
||||
private int customValue;
|
||||
|
||||
// Champs de données du composant
|
||||
}
|
||||
```
|
||||
|
||||
## Patterns d'Accès aux Composants
|
||||
|
||||
```java
|
||||
// Accès sécurisé aux composants
|
||||
public void processNPC(NPCEntity npc) {
|
||||
EntityStore store = npc.getEntityStore();
|
||||
|
||||
// Vérifier si le composant existe
|
||||
if (store.hasComponent(NPCCombatComponent.class)) {
|
||||
NPCCombatComponent combat = store.getComponent(NPCCombatComponent.class);
|
||||
// Traiter la logique de combat
|
||||
}
|
||||
|
||||
// Obtenir ou créer un composant
|
||||
NPCStateComponent state = store.getOrCreateComponent(
|
||||
NPCStateComponent.class,
|
||||
NPCStateComponent::new
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## Bonnes Pratiques
|
||||
|
||||
{{< callout type="info" >}}
|
||||
**Directives des Composants :**
|
||||
- Les composants doivent être des données pures - pas de logique complexe
|
||||
- Utilisez les composants pour l'état qui doit persister
|
||||
- Accédez aux composants via EntityStore, pas directement
|
||||
- Vérifiez l'existence du composant avant l'accès
|
||||
- Utilisez le composant approprié pour chaque type de données
|
||||
{{< /callout >}}
|
||||
Reference in New Issue
Block a user