fanren/src/Model/NPC.php
2025-12-22 18:07:05 +08:00

32 lines
1018 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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对不起我不知道你在说什么。";
}
}