32 lines
1018 B
PHP
32 lines
1018 B
PHP
<?php
|
||
namespace Game\Model;
|
||
|
||
// NPC 可以继承 Character,但如果它不参与战斗,可以简化为独立模型。
|
||
// 为了简化,我们让它独立存在,只关注对话。
|
||
|
||
class NPC {
|
||
public string $id;
|
||
public string $name;
|
||
public array $dialogue; // 存储对话行或对话树结构
|
||
public bool $hasShop; // ⭐ 是否有商店
|
||
public ?array $shopInventory; // ⭐ 商店库存
|
||
|
||
public function __construct(string $id, string $name, array $dialogue, bool $hasShop = false, ?array $shopInventory = null) {
|
||
$this->id = $id;
|
||
$this->name = $name;
|
||
$this->dialogue = $dialogue;
|
||
$this->hasShop = $hasShop;
|
||
$this->shopInventory = $shopInventory ?? [];
|
||
}
|
||
|
||
public function getName(): string {
|
||
return $this->name;
|
||
}
|
||
|
||
/**
|
||
* 获取指定对话ID的文本
|
||
*/
|
||
public function getDialogueText(string $key): string {
|
||
return $this->dialogue[$key] ?? "NPC:对不起,我不知道你在说什么。";
|
||
}
|
||
} |