jihaitang commited on
Commit
6927a3a
·
verified ·
1 Parent(s): e71c3ea

Update richang - lihuiban.html

Browse files
Files changed (1) hide show
  1. richang - lihuiban.html +566 -43
richang - lihuiban.html CHANGED
@@ -935,13 +935,13 @@
935
  }
936
  }
937
 
938
- /* 随机事件框样式 */
939
  .random-event-container {
940
  background: rgba(44, 44, 44, 0.95);
941
  border: 2px solid #4ecdc4;
942
  border-radius: 10px;
943
- padding: 20px;
944
- margin-top: 20px;
945
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
946
  display: none;
947
  }
@@ -950,6 +950,128 @@
950
  display: block;
951
  }
952
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
953
  .event-title {
954
  font-size: 20px;
955
  font-weight: bold;
@@ -1021,6 +1143,159 @@
1021
  }
1022
  }
1023
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1024
  </style>
1025
  </head>
1026
  <body>
@@ -1258,6 +1533,32 @@
1258
  <div class="event-description" id="event-description"></div>
1259
  <div class="event-options" id="event-options"></div>
1260
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1261
  </div>
1262
  </div>
1263
 
@@ -1278,6 +1579,13 @@
1278
  </div>
1279
  </div>
1280
 
 
 
 
 
 
 
 
1281
  <script>
1282
  // 用户当前所在位置
1283
  let userLocation = 'nandizi';
@@ -1399,26 +1707,22 @@
1399
  "正文": "烽烟斜晚照,山上的死战,终于趋近尾声。唐门伤亡惨重,武林盟群侠亦将死伤殆尽,忽有白衣晃眼,武林盟主瑞笙翩然而至,划一道剑痕在地,绝你追击之路。师兄弟们杀红了眼,哪管他是谁,话不多说,便掷暗器贸然上前抢攻。瑞笙武功之高,以臻绝世领域,心神凝敛之际,瓢泼的大雨在他眼里都似静止,你师弟们人数虽多,但暗器轨迹与步法都进线笔直,还未近身便被看穿破绽,内力到处,剑身鸣颤,接镖反击、错步揉身一气喝成。一道惊雷乍现,晃得人剎那睁不开眼,只一瞬间便决出了胜负。那瞬间太短,不容你细想,只能见招拆招,使出浑身解数瓦解攻势,堪堪救了几位师弟的性命,最致命的一剑,却有意想不到的人来替你接。",
1400
  "剩余行动点": 3,
1401
  "当前地点": "男弟子房",
1402
- "主要NPC": "姬姒",
1403
- "好感变化": "大幅上升",
1404
  "其他NPC": "无",
1405
  "随机事件": {
1406
- "事件类型": "选项事件",
1407
- "事件描述": "姬姒想要和探讨昨天心得",
1408
- "选项一": {
1409
- "描述": "你欣然接受邀请,和姬姒一起讨论",
1410
- "奖励": "悟性+3",
1411
- "成功率": "25%"
 
1412
  },
1413
- "选项二": {
1414
- "描述": "你急不可耐,跳过探讨环节,直接和姬姒过招",
1415
- "奖励": "根骨+1",
1416
- "成功率": "60%"
1417
- },
1418
- "选项三": {
1419
- "描述": "你婉拒姬姒,专注于眼前的工作",
1420
- "奖励": "心性+2",
1421
- "成功率": "40%"
1422
  }
1423
  }
1424
  };
@@ -1547,6 +1851,9 @@
1547
  };
1548
 
1549
  let currentRandomEvent = null;
 
 
 
1550
 
1551
  // 计算剩余分配点数 - 修改为永不为负
1552
  function calculateRemainingPoints() {
@@ -1718,23 +2025,101 @@
1718
  modal.style.display = 'block';
1719
  }
1720
 
1721
- // 监听来自iframe的消息 - 新增
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1722
  window.addEventListener('message', function(event) {
1723
- // 检查消息来源,确保安全
1724
  if (event.data.type === 'blackjack-exit') {
1725
- // 更新金钱
1726
- playerStats.金钱 = event.data.money;
1727
- updateStatsDisplay();
 
 
 
 
 
 
1728
 
1729
- // 关闭弹窗
1730
- document.getElementById('blackjack-modal').style.display = 'none';
1731
- document.getElementById('blackjack-iframe').src = '';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1732
 
1733
- // 显示结果
1734
- showModal(`赌场游戏结束<br>当前金钱:${playerStats.金钱}`);
 
1735
  }
1736
  });
1737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1738
  // 点击弹窗背景关闭(可选)- 新增
1739
  document.getElementById('blackjack-modal').addEventListener('click', function(e) {
1740
  if (e.target === this) {
@@ -1750,6 +2135,24 @@
1750
  }
1751
  });
1752
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1753
  // 显示互动输入弹窗
1754
  function showInteractionInput(npcId, location) {
1755
  currentInteractionNpc = npcId;
@@ -2080,7 +2483,7 @@
2080
  document.getElementById('modal').style.display = 'none';
2081
  }
2082
 
2083
- // 修改parseLLMResponse函数,添加随机事件的解析
2084
  function parseLLMResponse(response) {
2085
  if (response.正文) {
2086
  currentStoryText = response.正文;
@@ -2123,13 +2526,124 @@
2123
  }
2124
  }
2125
 
2126
- // 处理随机事件 - 新增
2127
  if (response.随机事件) {
2128
  currentRandomEvent = response.随机事件;
2129
- displayRandomEvent(currentRandomEvent);
 
 
 
 
 
 
 
 
 
 
2130
  } else {
2131
  hideRandomEvent();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2132
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2133
  }
2134
 
2135
  // 显示随机事件 - 新增
@@ -2429,7 +2943,7 @@
2429
  }
2430
  }
2431
 
2432
- // NPC互动(修改后)
2433
  function npcAction(npcId, action) {
2434
  // 先关闭信息弹窗
2435
  const popup = document.getElementById('npc-info-popup');
@@ -2442,15 +2956,24 @@
2442
  showInteractionInput(npcId, location);
2443
  } else if (action === '切磋') {
2444
  const npc = npcs[npcId];
2445
- // 显示战斗信息
2446
- const battleMessage = `<battle><br>` +
2447
- `发起战斗,敌方信息如下<br>` +
2448
- `name: ${npc.name}<br>` +
2449
- `&nbsp;&nbsp;maxHealth: 中<br>` +
2450
- `&nbsp;&nbsp;basicDamage: 中<br>` +
2451
- `<battle>`;
 
 
 
 
 
 
 
 
2452
 
2453
- showModal(battleMessage);
 
2454
  }
2455
  }
2456
 
@@ -2631,7 +3154,7 @@
2631
  window.onload = function() {
2632
  updateAllDisplays();
2633
  setupLocationEvents();
2634
- //refreshNpcLocations();
2635
  // 解析示例LLM响应
2636
  parseLLMResponse(llmResponse);
2637
  };
 
935
  }
936
  }
937
 
938
+ /* 随机事件框样式 - 响应式优化 */
939
  .random-event-container {
940
  background: rgba(44, 44, 44, 0.95);
941
  border: 2px solid #4ecdc4;
942
  border-radius: 10px;
943
+ padding: clamp(12px, 3vw, 20px);
944
+ margin-top: clamp(12px, 3vw, 20px);
945
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
946
  display: none;
947
  }
 
950
  display: block;
951
  }
952
 
953
+ .event-title {
954
+ font-size: clamp(1rem, 2.5vw, 1.25rem);
955
+ font-weight: bold;
956
+ color: #4ecdc4;
957
+ margin-bottom: clamp(6px, 1.5vw, 10px);
958
+ text-align: center;
959
+ }
960
+
961
+ .event-description {
962
+ font-size: clamp(0.875rem, 2vw, 1rem);
963
+ color: #fff;
964
+ margin-bottom: clamp(12px, 3vw, 20px);
965
+ line-height: 1.5;
966
+ text-align: center;
967
+ }
968
+
969
+ .event-options {
970
+ display: flex;
971
+ flex-direction: column;
972
+ gap: clamp(8px, 2vw, 15px);
973
+ }
974
+
975
+ .event-option-btn {
976
+ background: #2c2c2c;
977
+ border: 2px solid #4ecdc4;
978
+ border-radius: 8px;
979
+ padding: clamp(10px, 2.5vw, 15px);
980
+ cursor: pointer;
981
+ transition: all 0.3s ease;
982
+ text-align: left;
983
+ }
984
+
985
+ .event-option-btn:hover {
986
+ background: #3c3c3c;
987
+ transform: translateY(-2px);
988
+ box-shadow: 0 5px 15px rgba(78, 205, 196, 0.3);
989
+ }
990
+
991
+ .option-desc {
992
+ font-size: clamp(0.875rem, 2vw, 1rem);
993
+ color: #fff;
994
+ margin-bottom: clamp(5px, 1vw, 8px);
995
+ line-height: 1.4;
996
+ }
997
+
998
+ .option-reward {
999
+ font-size: clamp(0.75rem, 1.8vw, 0.875rem);
1000
+ color: #4ecdc4;
1001
+ margin-bottom: clamp(3px, 0.8vw, 5px);
1002
+ }
1003
+
1004
+ .option-success-rate {
1005
+ font-size: clamp(0.75rem, 1.8vw, 0.875rem);
1006
+ color: #aaa;
1007
+ }
1008
+
1009
+ /* 小屏幕优化 */
1010
+ @media (max-width: 600px) {
1011
+ .random-event-container {
1012
+ margin-top: 10px;
1013
+ padding: 10px;
1014
+ }
1015
+
1016
+ .event-options {
1017
+ gap: 6px;
1018
+ }
1019
+
1020
+ .event-option-btn {
1021
+ padding: 8px 10px;
1022
+ border-radius: 6px;
1023
+ }
1024
+
1025
+ /* 在非常小的屏幕上,减少行间距 */
1026
+ .option-desc {
1027
+ margin-bottom: 3px;
1028
+ }
1029
+
1030
+ .option-reward {
1031
+ margin-bottom: 2px;
1032
+ }
1033
+ }
1034
+
1035
+ /* 横屏手机优化 */
1036
+ @media (max-height: 500px) and (orientation: landscape) {
1037
+ .random-event-container {
1038
+ padding: 8px 12px;
1039
+ margin-top: 8px;
1040
+ }
1041
+
1042
+ .event-title {
1043
+ margin-bottom: 5px;
1044
+ }
1045
+
1046
+ .event-description {
1047
+ margin-bottom: 8px;
1048
+ }
1049
+
1050
+ .event-options {
1051
+ gap: 5px;
1052
+ }
1053
+
1054
+ .event-option-btn {
1055
+ padding: 6px 10px;
1056
+ }
1057
+ }
1058
+
1059
+ /* 平板和小窗口优化 */
1060
+ @media (min-width: 600px) and (max-width: 840px) {
1061
+ .random-event-container {
1062
+ padding: 15px;
1063
+ margin-top: 15px;
1064
+ }
1065
+
1066
+ .event-options {
1067
+ gap: 10px;
1068
+ }
1069
+
1070
+ .event-option-btn {
1071
+ padding: 12px;
1072
+ }
1073
+ }
1074
+
1075
  .event-title {
1076
  font-size: 20px;
1077
  font-weight: bold;
 
1143
  }
1144
  }
1145
 
1146
+ /* //回合制系统集成更新 - 战斗iframe弹窗 */
1147
+ .battle-modal {
1148
+ display: none;
1149
+ position: fixed;
1150
+ z-index: 3000;
1151
+ left: 0;
1152
+ top: 0;
1153
+ width: 100%;
1154
+ height: 100%;
1155
+ background-color: rgba(0,0,0,0.7);
1156
+ }
1157
+
1158
+ .battle-container {
1159
+ width: 90%;
1160
+ max-width: 900px;
1161
+ height: 90%;
1162
+ margin: 5% auto;
1163
+ position: relative;
1164
+ }
1165
+
1166
+ .battle-iframe {
1167
+ width: 100%;
1168
+ height: 100%;
1169
+ border: none;
1170
+ border-radius: 10px;
1171
+ }
1172
+ /* 战斗信息框样式 */
1173
+ .battle-event-container {
1174
+ background: rgba(44, 44, 44, 0.95);
1175
+ border: 2px solid #ff4d6d;
1176
+ border-radius: 10px;
1177
+ padding: clamp(12px, 3vw, 20px);
1178
+ margin-top: clamp(12px, 3vw, 20px);
1179
+ box-shadow: 0 5px 15px rgba(0,0,0,0.3);
1180
+ display: none;
1181
+ }
1182
+
1183
+ .battle-event-container.show {
1184
+ display: block;
1185
+ }
1186
+
1187
+ .battle-event-title {
1188
+ font-size: clamp(1rem, 2.5vw, 1.25rem);
1189
+ font-weight: bold;
1190
+ color: #ff4d6d;
1191
+ margin-bottom: clamp(6px, 1.5vw, 10px);
1192
+ text-align: center;
1193
+ }
1194
+
1195
+ .battle-event-description {
1196
+ font-size: clamp(0.875rem, 2vw, 1rem);
1197
+ color: #fff;
1198
+ margin-bottom: clamp(12px, 3vw, 20px);
1199
+ line-height: 1.5;
1200
+ text-align: center;
1201
+ }
1202
+
1203
+ .battle-enemy-info {
1204
+ background: rgba(0, 0, 0, 0.5);
1205
+ padding: clamp(10px, 2vw, 15px);
1206
+ border-radius: 8px;
1207
+ margin-bottom: clamp(10px, 2vw, 15px);
1208
+ }
1209
+
1210
+ .enemy-info-item {
1211
+ font-size: clamp(0.8rem, 1.8vw, 0.9rem);
1212
+ color: #ccc;
1213
+ margin: clamp(3px, 0.8vw, 5px) 0;
1214
+ }
1215
+
1216
+ .enemy-info-label {
1217
+ color: #ff4d6d;
1218
+ font-weight: bold;
1219
+ }
1220
+
1221
+ .battle-reward {
1222
+ background: rgba(78, 205, 196, 0.2);
1223
+ padding: clamp(8px, 2vw, 12px);
1224
+ border-radius: 6px;
1225
+ margin-bottom: clamp(12px, 3vw, 20px);
1226
+ text-align: center;
1227
+ }
1228
+
1229
+ .battle-reward-text {
1230
+ font-size: clamp(0.875rem, 2vw, 1rem);
1231
+ color: #4ecdc4;
1232
+ }
1233
+
1234
+ .battle-actions {
1235
+ display: flex;
1236
+ gap: clamp(10px, 2vw, 15px);
1237
+ justify-content: center;
1238
+ }
1239
+
1240
+ .battle-action-btn {
1241
+ flex: 1;
1242
+ padding: clamp(8px, 2vw, 12px) clamp(20px, 4vw, 30px);
1243
+ border: 2px solid #ff4d6d;
1244
+ border-radius: 8px;
1245
+ cursor: pointer;
1246
+ font-size: clamp(0.875rem, 2vw, 1rem);
1247
+ font-weight: bold;
1248
+ transition: all 0.3s ease;
1249
+ }
1250
+
1251
+ .battle-action-btn.fight {
1252
+ background: #ff4d6d;
1253
+ color: #fff;
1254
+ }
1255
+
1256
+ .battle-action-btn.fight:hover {
1257
+ background: #ff6b87;
1258
+ transform: translateY(-2px);
1259
+ }
1260
+
1261
+ .battle-action-btn.flee {
1262
+ background: #2c2c2c;
1263
+ color: #fff;
1264
+ border-color: #666;
1265
+ }
1266
+
1267
+ .battle-action-btn.flee:hover {
1268
+ background: #3c3c3c;
1269
+ transform: translateY(-2px);
1270
+ }
1271
+
1272
+ /* 战斗iframe弹窗 */
1273
+ .battle-modal {
1274
+ display: none;
1275
+ position: fixed;
1276
+ z-index: 3000;
1277
+ left: 0;
1278
+ top: 0;
1279
+ width: 100%;
1280
+ height: 100%;
1281
+ background-color: rgba(0,0,0,0.7);
1282
+ }
1283
+
1284
+ .battle-container {
1285
+ width: 90%;
1286
+ max-width: 900px;
1287
+ height: 90%;
1288
+ margin: 5% auto;
1289
+ position: relative;
1290
+ }
1291
+
1292
+ .battle-iframe {
1293
+ width: 100%;
1294
+ height: 100%;
1295
+ border: none;
1296
+ border-radius: 10px;
1297
+ }
1298
+
1299
  </style>
1300
  </head>
1301
  <body>
 
1533
  <div class="event-description" id="event-description"></div>
1534
  <div class="event-options" id="event-options"></div>
1535
  </div>
1536
+ <!-- 在random-event-container后添加战斗事件容器 -->
1537
+ <div class="battle-event-container" id="battle-event-container">
1538
+ <div class="battle-event-title">战斗事件</div>
1539
+ <div class="battle-event-description" id="battle-event-description"></div>
1540
+ <div class="battle-enemy-info">
1541
+ <div class="enemy-info-item">
1542
+ <span class="enemy-info-label">敌人:</span>
1543
+ <span id="enemy-name-display"></span>
1544
+ </div>
1545
+ <div class="enemy-info-item">
1546
+ <span class="enemy-info-label">攻击力:</span>
1547
+ <span id="enemy-attack-display"></span>
1548
+ </div>
1549
+ <div class="enemy-info-item">
1550
+ <span class="enemy-info-label">生命力:</span>
1551
+ <span id="enemy-health-display"></span>
1552
+ </div>
1553
+ </div>
1554
+ <div class="battle-reward">
1555
+ <div class="battle-reward-text" id="battle-reward-text"></div>
1556
+ </div>
1557
+ <div class="battle-actions">
1558
+ <button class="battle-action-btn fight" onclick="startBattle()">发起战斗</button>
1559
+ <button class="battle-action-btn flee" onclick="fleeBattle()">放弃战斗</button>
1560
+ </div>
1561
+ </div>
1562
  </div>
1563
  </div>
1564
 
 
1579
  </div>
1580
  </div>
1581
 
1582
+ <!-- //回合制系统集成更新 - 战斗iframe弹窗 -->
1583
+ <div id="battle-modal" class="battle-modal">
1584
+ <div class="battle-container">
1585
+ <iframe id="battle-iframe" class="battle-iframe"></iframe>
1586
+ </div>
1587
+ </div>
1588
+
1589
  <script>
1590
  // 用户当前所在位置
1591
  let userLocation = 'nandizi';
 
1707
  "正文": "烽烟斜晚照,山上的死战,终于趋近尾声。唐门伤亡惨重,武林盟群侠亦将死伤殆尽,忽有白衣晃眼,武林盟主瑞笙翩然而至,划一道剑痕在地,绝你追击之路。师兄弟们杀红了眼,哪管他是谁,话不多说,便掷暗器贸然上前抢攻。瑞笙武功之高,以臻绝世领域,心神凝敛之际,瓢泼的大雨在他眼里都似静止,你师弟们人数虽多,但暗器轨迹与步法都进线笔直,还未近身便被看穿破绽,内力到处,剑身鸣颤,接镖反击、错步揉身一气喝成。一道惊雷乍现,晃得人剎那睁不开眼,只一瞬间便决出了胜负。那瞬间太短,不容你细想,只能见招拆招,使出浑身解数瓦解攻势,堪堪救了几位师弟的性命,最致命的一剑,却有意想不到的人来替你接。",
1708
  "剩余行动点": 3,
1709
  "当前地点": "男弟子房",
1710
+ "主要NPC": "F",
1711
+ "好感变化": "不变",
1712
  "其他NPC": "无",
1713
  "随机事件": {
1714
+ "事件类型": "战斗事件",
1715
+ "事件描述": "你在山门附近训,发现一人形迹可疑,你上前盘查,对方居然是吐蕃细作!",
1716
+ "敌方信息": {
1717
+ "名称": "吐蕃探子",
1718
+ "属性": {
1719
+ "攻击力": "",
1720
+ "生命力": "中"
1721
  },
1722
+ "战斗报酬": {
1723
+ "类型": "金钱",
1724
+ "数值": 500
1725
+ }
 
 
 
 
 
1726
  }
1727
  }
1728
  };
 
1851
  };
1852
 
1853
  let currentRandomEvent = null;
1854
+ let currentBattleEvent = null; // 保存当前战斗事件信息
1855
+ let currentBattleType = null; // 'npc' 或 'event' 标识战斗类型
1856
+ let currentBattleReward = null; // 保存战斗奖励信息
1857
 
1858
  // 计算剩余分配点数 - 修改为永不为负
1859
  function calculateRemainingPoints() {
 
2025
  modal.style.display = 'block';
2026
  }
2027
 
2028
+ // // //回合制系统集成更新 - 显示战斗游戏
2029
+ // function showBattleGame(battleData) {
2030
+ // const modal = document.getElementById('battle-modal');
2031
+ // const iframe = document.getElementById('battle-iframe');
2032
+
2033
+ // // 构建URL参数
2034
+ // const params = new URLSearchParams({
2035
+ // playerName: battleData.player.name,
2036
+ // playerAttack: battleData.player.attack,
2037
+ // playerHealth: battleData.player.health,
2038
+ // enemyName: battleData.enemy.name,
2039
+ // enemyMaxHealth: battleData.enemy.maxHealth,
2040
+ // enemyBasicDamage: battleData.enemy.basicDamage
2041
+ // });
2042
+
2043
+ // // 设置iframe的src
2044
+
2045
+ // const gameUrl = `https://Ji-Haitang.github.io/char_card_1/turn-based-battle.html?${params.toString()}`;
2046
+ // iframe.src = gameUrl;
2047
+
2048
+ // modal.style.display = 'block';
2049
+ // }
2050
+
2051
+ // 修改window.addEventListener部分,添加战斗系统的消息处理
2052
  window.addEventListener('message', function(event) {
 
2053
  if (event.data.type === 'blackjack-exit') {
2054
+ // 21点游戏的处理...
2055
+ }
2056
+ else if (event.data.type === 'battle-exit') {
2057
+ // 关闭战斗弹窗
2058
+ document.getElementById('battle-modal').style.display = 'none';
2059
+ document.getElementById('battle-iframe').src = '';
2060
+
2061
+ // 获取战斗结果
2062
+ const result = event.data.result; // 'victory', 'defeat', 'quit'
2063
 
2064
+ if (currentBattleType === 'npc') {
2065
+ // NPC切磋结果
2066
+ const resultText = result === 'victory' ? '获得胜利了' : '不幸失败了';
2067
+ showModal(`你和对手切磋,${resultText}`);
2068
+
2069
+ // 如果胜利,增加声望
2070
+ if (result === 'victory') {
2071
+ playerStats.声望 += 1;
2072
+ updateStatsDisplay();
2073
+ }
2074
+ } else if (currentBattleType === 'event') {
2075
+ // 战斗事件结果
2076
+ if (result === 'victory') {
2077
+ let rewardMessage = '';
2078
+ // 应用战斗奖励
2079
+ if (currentBattleReward) {
2080
+ applyBattleReward(currentBattleReward);
2081
+ rewardMessage = `<br>获得奖励:${currentBattleReward.类型}+${currentBattleReward.数值}`;
2082
+ }
2083
+ showModal(currentBattleEvent.事件描述 +
2084
+ `<br><br>你迎战${currentBattleEvent.敌方信息.名称}并获得了胜利!` +
2085
+ rewardMessage);
2086
+ } else if (result === 'defeat') {
2087
+ showModal(currentBattleEvent.事件描述 +
2088
+ `<br><br>你迎战${currentBattleEvent.敌方信息.名称}但是不幸败北。`);
2089
+ }
2090
+
2091
+ // 隐藏战斗事件容器
2092
+ hideBattleEvent();
2093
+ }
2094
 
2095
+ // 重置战斗类型
2096
+ currentBattleType = null;
2097
+ currentBattleReward = null;
2098
  }
2099
  });
2100
 
2101
+ // 应用战斗奖励
2102
+ function applyBattleReward(reward) {
2103
+ if (!reward) return;
2104
+
2105
+ switch (reward.类型) {
2106
+ case '金钱':
2107
+ playerStats.金钱 += reward.数值;
2108
+ break;
2109
+ case '声望':
2110
+ playerStats.声望 += reward.数值;
2111
+ break;
2112
+ case '武学':
2113
+ playerStats.武学 += reward.数值;
2114
+ break;
2115
+ case '学识':
2116
+ playerStats.学识 += reward.数值;
2117
+ break;
2118
+ }
2119
+
2120
+ updateStatsDisplay();
2121
+ }
2122
+
2123
  // 点击弹窗背景关闭(可选)- 新增
2124
  document.getElementById('blackjack-modal').addEventListener('click', function(e) {
2125
  if (e.target === this) {
 
2135
  }
2136
  });
2137
 
2138
+ // 点击战斗弹窗背景关闭
2139
+ document.getElementById('battle-modal').addEventListener('click', function(e) {
2140
+ if (e.target === this) {
2141
+ if (confirm('确定要退出战斗吗?')) {
2142
+ this.style.display = 'none';
2143
+ document.getElementById('battle-iframe').src = '';
2144
+
2145
+ // 如果是战斗事件,隐藏容器
2146
+ if (currentBattleType === 'event') {
2147
+ hideBattleEvent();
2148
+ }
2149
+
2150
+ currentBattleType = null;
2151
+ currentBattleReward = null;
2152
+ }
2153
+ }
2154
+ });
2155
+
2156
  // 显示互动输入弹窗
2157
  function showInteractionInput(npcId, location) {
2158
  currentInteractionNpc = npcId;
 
2483
  document.getElementById('modal').style.display = 'none';
2484
  }
2485
 
2486
+ // 修改parseLLMResponse函数,处理战斗事件
2487
  function parseLLMResponse(response) {
2488
  if (response.正文) {
2489
  currentStoryText = response.正文;
 
2526
  }
2527
  }
2528
 
2529
+ // 处理随机事件
2530
  if (response.随机事件) {
2531
  currentRandomEvent = response.随机事件;
2532
+
2533
+ // 判断事件类型
2534
+ if (currentRandomEvent.事件类型 === '战斗事件') {
2535
+ // 处理战斗事件
2536
+ displayBattleEvent(currentRandomEvent);
2537
+ hideRandomEvent(); // 隐藏普通随机事件容器
2538
+ } else {
2539
+ // 处理普通随机事件
2540
+ displayRandomEvent(currentRandomEvent);
2541
+ hideBattleEvent(); // 隐藏战斗事件容器
2542
+ }
2543
  } else {
2544
  hideRandomEvent();
2545
+ hideBattleEvent();
2546
+ }
2547
+ }
2548
+
2549
+ // 显示战斗事件
2550
+ function displayBattleEvent(event) {
2551
+ const container = document.getElementById('battle-event-container');
2552
+ const description = document.getElementById('battle-event-description');
2553
+ const enemyName = document.getElementById('enemy-name-display');
2554
+ const enemyAttack = document.getElementById('enemy-attack-display');
2555
+ const enemyHealth = document.getElementById('enemy-health-display');
2556
+ const rewardText = document.getElementById('battle-reward-text');
2557
+
2558
+ // 保存当前战斗事件
2559
+ currentBattleEvent = event;
2560
+
2561
+ // 设置事件描述
2562
+ description.textContent = event.事件描述;
2563
+
2564
+ // 设置敌人信息
2565
+ if (event.敌方信息) {
2566
+ enemyName.textContent = event.敌方信息.名称 || '未知敌人';
2567
+ enemyAttack.textContent = event.敌方信息.属性?.攻击力 || '中';
2568
+ enemyHealth.textContent = event.敌方信息.属性?.生命力 || '中';
2569
+
2570
+ // 设置奖励信息
2571
+ if (event.敌方信息.战斗报酬) {
2572
+ const reward = event.敌方信息.战斗报酬;
2573
+ rewardText.textContent = `战斗胜利奖励:${reward.类型}+${reward.数值}`;
2574
+ currentBattleReward = reward;
2575
+ }
2576
  }
2577
+
2578
+ // 显示容器
2579
+ container.classList.add('show');
2580
+ }
2581
+
2582
+ // 隐藏战斗事件
2583
+ function hideBattleEvent() {
2584
+ const container = document.getElementById('battle-event-container');
2585
+ container.classList.remove('show');
2586
+ currentBattleEvent = null;
2587
+ }
2588
+
2589
+ // 发起战斗
2590
+ function startBattle() {
2591
+ if (!currentBattleEvent || !currentBattleEvent.敌方信息) return;
2592
+
2593
+ const enemyInfo = currentBattleEvent.敌方信息;
2594
+ currentBattleType = 'event';
2595
+
2596
+ // 准备战斗数据
2597
+ const battleData = {
2598
+ player: {
2599
+ name: '小虾米',
2600
+ attack: combatStats.攻击力,
2601
+ health: combatStats.生命值
2602
+ },
2603
+ enemy: {
2604
+ name: enemyInfo.名称,
2605
+ maxHealth: enemyInfo.属性?.生命力 || '中',
2606
+ basicDamage: enemyInfo.属性?.攻击力 || '中'
2607
+ }
2608
+ };
2609
+
2610
+ // 显示战斗iframe
2611
+ showBattleGame(battleData);
2612
+ }
2613
+
2614
+ // 放弃战斗
2615
+ function fleeBattle() {
2616
+ if (!currentBattleEvent) return;
2617
+
2618
+ const resultMessage = currentBattleEvent.事件描述 + '<br><br>你选择避开了战斗';
2619
+
2620
+ // 隐藏战斗事件
2621
+ hideBattleEvent();
2622
+
2623
+ // 显示结果
2624
+ showModal(resultMessage);
2625
+ }
2626
+
2627
+ // 显示战斗游戏(统一的战斗接口)
2628
+ function showBattleGame(battleData) {
2629
+ const modal = document.getElementById('battle-modal');
2630
+ const iframe = document.getElementById('battle-iframe');
2631
+
2632
+ // 构建URL参数
2633
+ const params = new URLSearchParams({
2634
+ playerName: battleData.player.name,
2635
+ playerAttack: battleData.player.attack,
2636
+ playerHealth: battleData.player.health,
2637
+ enemyName: battleData.enemy.name,
2638
+ enemyMaxHealth: battleData.enemy.maxHealth,
2639
+ enemyBasicDamage: battleData.enemy.basicDamage
2640
+ });
2641
+
2642
+ // 设置iframe的src
2643
+ const gameUrl = `turn-based-battle.html?${params.toString()}`;
2644
+ iframe.src = gameUrl;
2645
+
2646
+ modal.style.display = 'block';
2647
  }
2648
 
2649
  // 显示随机事件 - 新增
 
2943
  }
2944
  }
2945
 
2946
+ // 修改npcAction函数
2947
  function npcAction(npcId, action) {
2948
  // 先关闭信息弹窗
2949
  const popup = document.getElementById('npc-info-popup');
 
2956
  showInteractionInput(npcId, location);
2957
  } else if (action === '切磋') {
2958
  const npc = npcs[npcId];
2959
+ currentBattleType = 'npc';
2960
+
2961
+ // 准备战斗数据
2962
+ const battleData = {
2963
+ player: {
2964
+ name: '小虾米',
2965
+ attack: combatStats.攻击力,
2966
+ health: combatStats.生命值
2967
+ },
2968
+ enemy: {
2969
+ name: npc.name,
2970
+ maxHealth: '中', // NPC统一设置为中等难度
2971
+ basicDamage: '中'
2972
+ }
2973
+ };
2974
 
2975
+ // 显示战斗iframe
2976
+ showBattleGame(battleData);
2977
  }
2978
  }
2979
 
 
3154
  window.onload = function() {
3155
  updateAllDisplays();
3156
  setupLocationEvents();
3157
+ refreshNpcLocations();
3158
  // 解析示例LLM响应
3159
  parseLLMResponse(llmResponse);
3160
  };