我想在需要加入好感值系统以判断不同好感值的可选项
- User
我想在需要加入好感值系统以判断不同好感值的可选项
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
我想在需要加入好感值系统以判断不同好感值的可选项
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
让我为你的视觉小说框架添加一个好感值系统,这将使游戏更加丰富,角色关系更加动态。
// 在script.js中添加好感度系统
// --- 好感度系统 ---
const affection = {
// 初始化角色好感度
characters: {
"爱丽丝": 0,
"鲍勃": 0
// 可以添加更多角色
},
// 修改好感度
change: function(character, amount) {
if (this.characters.hasOwnProperty(character)) {
this.characters[character] += amount;
console.log(`${character}好感度变化: ${amount}, 当前: ${this.characters[character]}`);
// 可选:显示好感度变化的视觉效果
showAffectionChange(character, amount);
return true;
}
return false;
},
// 获取好感度
get: function(character) {
return this.characters[character] || 0;
},
// 检查好感度是否满足条件
check: function(character, requiredValue, comparison = ">=") {
const value = this.get(character);
switch(comparison) {
case ">=": return value >= requiredValue;
case ">": return value > requiredValue;
case "=": return value === requiredValue;
case "<": return value < requiredValue;
case "<=": return value <= requiredValue;
default: return false;
}
}
};
// 显示好感度变化的视觉效果
function showAffectionChange(character, amount) {
// 创建一个临时元素显示好感度变化
const effect = document.createElement('div');
effect.className = 'affection-change';
effect.textContent = amount > 0 ? `♥ +${amount}` : `♥ ${amount}`;
effect.style.color = amount > 0 ? '#ff7bac' : '#7b7b7b';
gameContainer.appendChild(effect);
// 设置位置在角色立绘附近
const rect = characterSprite.getBoundingClientRect();
effect.style.position = 'absolute';
effect.style.top = `${rect.top - 50}px`;
effect.style.left = `${rect.left + rect.width/2}px`;
effect.style.transform = 'translate(-50%, -50%)';
effect.style.fontSize = '24px';
effect.style.fontWeight = 'bold';
effect.style.textShadow = '2px 2px 4px rgba(0,0,0,0.5)';
effect.style.zIndex = '100';
effect.style.opacity = '0';
effect.style.transition = 'opacity 0.3s, transform 1s';
// 动画效果
setTimeout(() => {
effect.style.opacity = '1';
effect.style.transform = 'translate(-50%, -100%)';
}, 50);
setTimeout(() => {
effect.style.opacity = '0';
}, 1500);
setTimeout(() => {
gameContainer.removeChild(effect);
}, 2000);
}
// 修改故事数据结构以支持好感度系统
const story = [
// 场景 0: 公园
{
background: 'assets/backgrounds/bg_park.jpg',
dialogues: [
{ name: '', text: '这是一个阳光明媚的下午,你在公园里散步。', character: { hide: true } },
{ name: '爱丽丝', text: '(突然,一个女孩出现在你面前)', character: { name: '爱丽丝', sprite: 'assets/characters/char_alice_normal.png' } },
{ name: '爱丽丝', text: '你好!我叫爱丽丝,很高兴见到你!', character: { name: '爱丽丝', sprite: 'assets/characters/char_alice_normal.png' } },
{ name: '', text: '你该如何回应呢?', character: { hide: true } },
{
name: '',
text: '',
character: { hide: true },
choices: [
{
text: '友善地打招呼',
nextScene: 1,
nextDialogue: 0,
affection: { character: '爱丽丝', change: 2 } // 增加2点好感度
},
{
text: '害羞地躲开',
nextScene: 2,
nextDialogue: 0,
affection: { character: '爱丽丝', change: -1 } // 减少1点好感度
},
{
text: '主动上前聊天',
nextScene: 3,
nextDialogue: 0,
affection: { character: '爱丽丝', change: 3 }, // 增加3点好感度
requirement: { type: 'none' } // 无要求,总是可选
},
{
text: '送她一朵花(需要爱丽丝好感度≥5)',
nextScene: 4,
nextDialogue: 0,
affection: { character: '爱丽丝', change: 5 }, // 增加5点好感度
requirement: {
type: 'affection',
character: '爱丽丝',
value: 5,
comparison: ">="
} // 要求爱丽丝好感度≥5
}
]
}
]
},
// 其他场景...
// 场景 3: 主动聊天后的发展
{
background: 'assets/backgrounds/bg_park.jpg',
dialogues: [
{ name: '你', text: '嗨,爱丽丝!我叫XXX,很高兴认识你!你经常来这个公园吗?', character: { hide: true } },
{ name: '爱丽丝', text: '哇,你真热情!是的,我每周都会来这里。你呢?', character: { name: '爱丽丝', sprite: 'assets/characters/char_alice_normal.png' } },
{ name: '', text: '你们聊得很愉快,爱丽丝看起来很喜欢和你交谈。', character: { hide: true } },
// 更多对话...
]
},
// 场景 4: 送花后的特殊场景
{
background: 'assets/backgrounds/bg_park.jpg',
dialogues: [
{ name: '你', text: '(你从附近的花坛中小心地摘下一朵花,递给爱丽丝)', character: { hide: true } },
{ name: '爱丽丝', text: '啊!这...这是给我的吗?太感谢了!', character: { name: '爱丽丝', sprite: 'assets/characters/char_alice_normal.png' } },
{ name: '爱丽丝', text: '没有人送过我花呢...你真是太贴心了。', character: { name: '爱丽丝', sprite: 'assets/characters/char_alice_normal.png' } },
{ name: '', text: '爱丽丝脸上露出灿烂的笑容,你感觉你们的关系更进一步了。', character: { hide: true } },
// 更多对话...
]
}
];
// 修改处理选项函数以支持好感度系统
function showChoices(choices) {
canAdvance = false;
choicesContainer.classList.remove('hidden');
choicesContainer.innerHTML = '';
choices.forEach((choice, index) => {
// 检查选项是否有要求,以及是否满足要求
let available = true;
let requirementText = '';
if (choice.requirement) {
switch (choice.requirement.type) {
case 'affection':
available = affection.check(
choice.requirement.character,
choice.requirement.value,
choice.requirement.comparison
);
if (!available) {
requirementText = ` (需要${choice.requirement.character}好感度${choice.requirement.comparison}${choice.requirement.value})`;
}
break;
// 可以添加更多条件类型,如物品、状态等
case 'none':
default:
available = true;
break;
}
}
const button = document.createElement('button');
button.classList.add('choice-button');
// 根据可用性设置样式
if (!available) {
button.classList.add('choice-unavailable');
button.disabled = true;
}
// 显示选项文本和要求(如果有)
button.textContent = choice.text + (requirementText || '');
if (available) {
button.addEventListener('click', () => handleChoice(choice));
}
choicesContainer.appendChild(button);
});
}
// 修改处理选择函数以支持好感度变化
function handleChoice(choice) {
hideChoices();
// 处理好感度变化
if (choice.affection) {
affection.change(choice.affection.character, choice.affection.change);
}
// 跳转逻辑(保持原有功能)
if (choice.nextScene !== undefined) {
loadScene(choice.nextScene);
if (choice.nextDialogue !== undefined) {
currentDialogueIndex = choice.nextDialogue;
}
} else if (choice.nextDialogue !== undefined) {
currentDialogueIndex = choice.nextDialogue;
displayNextDialogue();
} else {
currentDialogueIndex++;
displayNextDialogue();
}
canAdvance = true;
}
// 添加好感度UI显示(可选)
function createAffectionUI() {
const affectionUI = document.createElement('div');
affectionUI.id = 'affection-ui';
affectionUI.style.position = 'absolute';
affectionUI.style.top = '10px';
affectionUI.style.right = '10px';
affectionUI.style.background = 'rgba(0, 0, 0, 0.7)';
affectionUI.style.padding = '10px';
affectionUI.style.borderRadius = '5px';
affectionUI.style.color = 'white';
affectionUI.style.zIndex = '30';
gameContainer.appendChild(affectionUI);
// 更新好感度UI
updateAffectionUI();
}
function updateAffectionUI() {
const affectionUI = document.getElementById('affection-ui');
if (!affectionUI) return;
affectionUI.innerHTML = '<h3 style="margin: 0 0 5px 0; font-size: 16px;">角色好感度</h3>';
for (const character in affection.characters) {
const value = affection.characters[character];
const hearts = '♥'.repeat(Math.max(0, Math.min(5, Math.floor(value/2))));
const emptyHearts = '♡'.repeat(Math.max(0, 5 - Math.floor(value/2)));
const charDiv = document.createElement('div');
charDiv.style.margin = '5px 0';
charDiv.innerHTML = `${character}: <span style="color:#ff7bac">${hearts}</span><span style="color:#7b7b7b">${emptyHearts}</span> (${value})`;
affectionUI.appendChild(charDiv);
}
}
// 在游戏启动时初始化好感度UI
function startGame() {
loadScene(currentSceneIndex);
gameContainer.addEventListener('click', handleAdvance);
document.addEventListener('keydown', handleKeyPress);
// 创建好感度UI
createAffectionUI();
}
// 在好感度变化时更新UI
const originalAffectionChange = affection.change;
affection.change = function(character, amount) {
const result = originalAffectionChange.call(this, character, amount);
updateAffectionUI();
return result;
};
现在,我们需要在CSS中添加一些样式,以支持好感度系统的视觉效果:
/* 在style.css中添加 */
/* 不可用选项样式 */
.choice-unavailable {
opacity: 0.6;
background-color: rgba(50, 50, 50, 0.8) !important;
border-color: #444 !important;
color: #999 !important;
cursor: not-allowed !important;
}
/* 好感度UI样式 */
#affection-ui {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
font-size: 14px;
}
/* 好感度变化效果动画 */
@keyframes float-up {
0% { transform: translate(-50%, -50%); opacity: 0; }
20% { opacity: 1; }
100% { transform: translate(-50%, -150%); opacity: 0; }
}
.affection-change {
animation: float-up 2s ease-out;
}
好感度存储:
好感度修改:
好感度条件:
好感度UI:
添加好感度条件选项:
{
text: "送她礼物",
nextScene: 5,
affection: { character: "爱丽丝", change: 3 },
requirement: {
type: "affection",
character: "爱丽丝",
value: 10,
comparison: ">="
}
}
动态剧情分支: 根据好感度在对话前检查,并跳转到不同的对话:
// 一个根据好感度动态分支的例子
if (affection.check("爱丽丝", 15, ">=")) {
// 高好感度对话
currentDialogueIndex = 10;
} else if (affection.check("爱丽丝", 5, ">=")) {
// 中等好感度对话
currentDialogueIndex = 5;
} else {
// 低好感度对话
currentDialogueIndex = 0;
}
displayNextDialogue();
游戏内收集成就: 你可以扩展系统,当某角色好感度达到特定值时解锁成就或特殊场景。
这个好感度系统为你的视觉小说增加了更多互动性和重玩价值,玩家可以通过不同选择探索多种关系发展路径。如果需要更复杂的关系系统,还可以进一步扩展为"关系类型"(如友谊、爱情、敬重等)而不仅仅是单一好感度。