196 lines
4.2 KiB
Markdown
196 lines
4.2 KiB
Markdown
---
|
|
title: Boutique
|
|
type: docs
|
|
weight: 5
|
|
---
|
|
|
|
Le systeme de boutique fournit le commerce via des boutiques NPC et des systemes de troc.
|
|
|
|
**Package:** `com.hypixel.hytale.builtin.adventure.shop`
|
|
|
|
## Architecture
|
|
|
|
```
|
|
ShopPlugin
|
|
├── Types de Boutique
|
|
│ ├── ShopAsset - Definitions boutique statiques
|
|
│ └── BarterShopAsset - Boutiques de troc dynamiques
|
|
├── Elements
|
|
│ ├── ShopElement - Entree item boutique
|
|
│ └── Integration ChoiceElement
|
|
├── Interactions
|
|
│ └── GiveItemInteraction
|
|
├── Pages
|
|
│ ├── ShopPage - Page UI boutique
|
|
│ ├── ShopPageSupplier
|
|
│ └── BarterPage - Page UI troc
|
|
└── Etat
|
|
└── BarterShopState - Etat troc persistant
|
|
```
|
|
|
|
## Types de Boutique
|
|
|
|
### ShopAsset
|
|
|
|
Boutiques statiques avec contenu fixe:
|
|
|
|
```java
|
|
public class ShopAsset implements JsonAssetWithMap<String, DefaultAssetMap<String, ShopAsset>> {
|
|
protected String id;
|
|
protected ChoiceElement[] elements; // Items boutique
|
|
|
|
public String getId();
|
|
public ChoiceElement[] getElements();
|
|
}
|
|
```
|
|
|
|
**Emplacement Asset:** `Shops/`
|
|
|
|
### BarterShopAsset
|
|
|
|
Boutiques dynamiques avec echanges rotatifs:
|
|
|
|
```java
|
|
public class BarterShopAsset implements JsonAssetWithMap<String, DefaultAssetMap<String, BarterShopAsset>> {
|
|
// Trading base sur le troc avec mecanique de rafraichissement
|
|
}
|
|
```
|
|
|
|
**Emplacement Asset:** `BarterShops/`
|
|
|
|
## Configuration de Boutique
|
|
|
|
### Exemple Boutique Statique
|
|
|
|
```yaml
|
|
# Shops/general_store.json
|
|
{
|
|
"Id": "general_store",
|
|
"Content": [
|
|
{
|
|
"Type": "ShopElement",
|
|
"Item": "bread",
|
|
"Price": 5,
|
|
"Currency": "gold_coin"
|
|
},
|
|
{
|
|
"Type": "ShopElement",
|
|
"Item": "torch",
|
|
"Price": 2,
|
|
"Currency": "gold_coin"
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### Composants Boutique Troc
|
|
|
|
```java
|
|
public class BarterShopState {
|
|
// Etat persistant pour boutiques de troc
|
|
public static void initialize(Path dataDirectory);
|
|
public static void shutdown();
|
|
}
|
|
|
|
public class TradeSlot { /* Slot d'echange de base */ }
|
|
public class FixedTradeSlot extends TradeSlot { /* Echange fixe */ }
|
|
public class PoolTradeSlot extends TradeSlot { /* Aleatoire depuis pool */ }
|
|
public class WeightedTrade { /* Echange aleatoire pondere */ }
|
|
|
|
public class BarterItemStack { /* Items pour troc */ }
|
|
public class BarterTrade { /* Definition complete d'echange */ }
|
|
public class RefreshInterval { /* Timing de rafraichissement */ }
|
|
```
|
|
|
|
## Elements de Boutique
|
|
|
|
### ShopElement
|
|
|
|
Enregistre comme type d'element de choix:
|
|
|
|
```java
|
|
getCodecRegistry(ChoiceElement.CODEC).register("ShopElement", ShopElement.class, ShopElement.CODEC);
|
|
```
|
|
|
|
## Interactions
|
|
|
|
### GiveItemInteraction
|
|
|
|
Interaction de choix qui donne des items au joueur:
|
|
|
|
```java
|
|
getCodecRegistry(ChoiceInteraction.CODEC).register("GiveItem", GiveItemInteraction.class, GiveItemInteraction.CODEC);
|
|
```
|
|
|
|
## Integration UI
|
|
|
|
### Page Boutique
|
|
|
|
Page UI personnalisee pour boutiques:
|
|
|
|
```java
|
|
getCodecRegistry(OpenCustomUIInteraction.PAGE_CODEC).register(
|
|
"Shop",
|
|
ShopPageSupplier.class,
|
|
ShopPageSupplier.CODEC
|
|
);
|
|
```
|
|
|
|
### Ouvrir une Boutique
|
|
|
|
```yaml
|
|
# Definition d'interaction
|
|
{
|
|
"Type": "OpenCustomUI",
|
|
"Page": {
|
|
"Type": "Shop",
|
|
"ShopId": "general_store"
|
|
}
|
|
}
|
|
```
|
|
|
|
## Utilisation de l'API
|
|
|
|
### Obtenir les Assets Boutique
|
|
|
|
```java
|
|
// Obtenir le store d'assets boutique
|
|
AssetStore<String, ShopAsset, DefaultAssetMap<String, ShopAsset>> store =
|
|
ShopAsset.getAssetStore();
|
|
|
|
// Obtenir boutique specifique
|
|
ShopAsset shop = ShopAsset.getAssetMap().getAsset("general_store");
|
|
|
|
// Obtenir boutique troc
|
|
BarterShopAsset barterShop = BarterShopAsset.getAssetMap().getAsset("traveling_merchant");
|
|
```
|
|
|
|
### Instance Plugin Boutique
|
|
|
|
```java
|
|
ShopPlugin shop = ShopPlugin.get();
|
|
```
|
|
|
|
## Persistance Etat Troc
|
|
|
|
L'etat des boutiques de troc est sauvegarde/charge automatiquement:
|
|
|
|
```java
|
|
// Appele dans start()
|
|
BarterShopState.initialize(this.getDataDirectory());
|
|
|
|
// Appele dans shutdown()
|
|
BarterShopState.shutdown();
|
|
```
|
|
|
|
## Dependances d'Assets
|
|
|
|
Les boutiques chargent apres les items:
|
|
|
|
```java
|
|
HytaleAssetStore.builder(ShopAsset.class, new DefaultAssetMap())
|
|
.setPath("Shops")
|
|
.loadsAfter(Item.class) // Assurer que items sont charges d'abord
|
|
.build();
|
|
```
|