Spaces:
Running
Running
Add experience points and levels for main character. Every level gain adds + 20 to maximum troop size and +1 ability gain to main character - Follow Up Deployment
Browse files- index.html +70 -2
index.html
CHANGED
@@ -186,6 +186,12 @@
|
|
186 |
<div>
|
187 |
<span class="font-semibold">Renown:</span> <span id="player-renown">0</span>
|
188 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
<div>
|
190 |
<span class="font-semibold">Troops:</span> <span id="player-troops">0/50</span>
|
191 |
</div>
|
@@ -230,6 +236,9 @@
|
|
230 |
<button class="action-btn w-full px-4 py-2 bg-green-700 hover:bg-green-800 rounded disabled:opacity-50 disabled:cursor-not-allowed" disabled>
|
231 |
<i class="fas fa-leaf mr-2"></i> Gather Food
|
232 |
</button>
|
|
|
|
|
|
|
233 |
<button class="action-btn w-full px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded disabled:opacity-50 disabled:cursor-not-allowed" disabled>
|
234 |
<i class="fas fa-route mr-2"></i> Travel
|
235 |
</button>
|
@@ -360,6 +369,15 @@
|
|
360 |
maxHealth: 100,
|
361 |
location: null,
|
362 |
background: "noble",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
relations: {
|
364 |
bavaria: 50,
|
365 |
swabia: 0,
|
@@ -668,7 +686,10 @@
|
|
668 |
case 4: // Gather Food
|
669 |
gatherFood();
|
670 |
break;
|
671 |
-
case 5: //
|
|
|
|
|
|
|
672 |
travelTo(settlement);
|
673 |
break;
|
674 |
}
|
@@ -790,10 +811,14 @@
|
|
790 |
gameState.inCombat = false;
|
791 |
|
792 |
if (victory) {
|
793 |
-
// Calculate loot
|
794 |
const loot = Math.floor(gameState.selectedSettlement.wealth * 0.3);
|
|
|
795 |
gameState.player.gold += loot;
|
796 |
gameState.player.renown += 5;
|
|
|
|
|
|
|
797 |
|
798 |
// Update settlement
|
799 |
gameState.selectedSettlement.garrison = Math.floor(gameState.selectedSettlement.garrison * 0.5);
|
@@ -938,6 +963,20 @@
|
|
938 |
updatePlayerInfo();
|
939 |
}
|
940 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
941 |
// Travel to a settlement
|
942 |
function travelTo(settlement) {
|
943 |
if (settlement.id === gameState.player.location) {
|
@@ -1058,11 +1097,37 @@
|
|
1058 |
addGameLog(event.message);
|
1059 |
}
|
1060 |
|
|
|
|
|
|
|
|
|
1061 |
// Update UI
|
1062 |
updatePlayerInfo();
|
1063 |
addGameLog(`Turn ${gameState.currentTurn} completed. You paid ${wages} gold in wages and consumed ${foodConsumed} food.`);
|
1064 |
}
|
1065 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1066 |
// Update player info display
|
1067 |
function updatePlayerInfo() {
|
1068 |
playerNameEl.textContent = gameState.player.name;
|
@@ -1071,6 +1136,9 @@
|
|
1071 |
playerRenownEl.textContent = gameState.player.renown;
|
1072 |
playerTroopsEl.textContent = `${gameState.player.currentTroops}/${gameState.player.maxTroops}`;
|
1073 |
document.getElementById('player-food').textContent = gameState.player.inventory.food;
|
|
|
|
|
|
|
1074 |
healthTextEl.textContent = `${gameState.player.health}`;
|
1075 |
healthBarEl.style.width = `${gameState.player.health}%`;
|
1076 |
}
|
|
|
186 |
<div>
|
187 |
<span class="font-semibold">Renown:</span> <span id="player-renown">0</span>
|
188 |
</div>
|
189 |
+
<div>
|
190 |
+
<span class="font-semibold">Level:</span> <span id="player-level">1</span>
|
191 |
+
</div>
|
192 |
+
<div>
|
193 |
+
<span class="font-semibold">XP:</span> <span id="player-xp">0</span>/<span id="player-next-xp">100</span>
|
194 |
+
</div>
|
195 |
<div>
|
196 |
<span class="font-semibold">Troops:</span> <span id="player-troops">0/50</span>
|
197 |
</div>
|
|
|
236 |
<button class="action-btn w-full px-4 py-2 bg-green-700 hover:bg-green-800 rounded disabled:opacity-50 disabled:cursor-not-allowed" disabled>
|
237 |
<i class="fas fa-leaf mr-2"></i> Gather Food
|
238 |
</button>
|
239 |
+
<button class="action-btn w-full px-4 py-2 bg-blue-700 hover:bg-blue-800 rounded disabled:opacity-50 disabled:cursor-not-allowed" disabled>
|
240 |
+
<i class="fas fa-bed mr-2"></i> Rest
|
241 |
+
</button>
|
242 |
<button class="action-btn w-full px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded disabled:opacity-50 disabled:cursor-not-allowed" disabled>
|
243 |
<i class="fas fa-route mr-2"></i> Travel
|
244 |
</button>
|
|
|
369 |
maxHealth: 100,
|
370 |
location: null,
|
371 |
background: "noble",
|
372 |
+
experience: 0,
|
373 |
+
level: 1,
|
374 |
+
experienceToNextLevel: 100,
|
375 |
+
abilities: {
|
376 |
+
leadership: 1,
|
377 |
+
combat: 1,
|
378 |
+
charisma: 1,
|
379 |
+
tactics: 1
|
380 |
+
},
|
381 |
relations: {
|
382 |
bavaria: 50,
|
383 |
swabia: 0,
|
|
|
686 |
case 4: // Gather Food
|
687 |
gatherFood();
|
688 |
break;
|
689 |
+
case 5: // Rest
|
690 |
+
rest();
|
691 |
+
break;
|
692 |
+
case 6: // Travel
|
693 |
travelTo(settlement);
|
694 |
break;
|
695 |
}
|
|
|
811 |
gameState.inCombat = false;
|
812 |
|
813 |
if (victory) {
|
814 |
+
// Calculate loot and experience
|
815 |
const loot = Math.floor(gameState.selectedSettlement.wealth * 0.3);
|
816 |
+
const expGain = Math.floor(gameState.combatEnemy.troops * 2);
|
817 |
gameState.player.gold += loot;
|
818 |
gameState.player.renown += 5;
|
819 |
+
gameState.player.experience += expGain;
|
820 |
+
addCombatLog(`You gained ${expGain} experience points!`, 'victory');
|
821 |
+
checkLevelUp();
|
822 |
|
823 |
// Update settlement
|
824 |
gameState.selectedSettlement.garrison = Math.floor(gameState.selectedSettlement.garrison * 0.5);
|
|
|
963 |
updatePlayerInfo();
|
964 |
}
|
965 |
|
966 |
+
// Rest and recover health
|
967 |
+
function rest() {
|
968 |
+
if (gameState.player.health >= gameState.player.maxHealth) {
|
969 |
+
addGameLog("You are already at full health.");
|
970 |
+
return;
|
971 |
+
}
|
972 |
+
|
973 |
+
const healthRecovered = Math.min(20, gameState.player.maxHealth - gameState.player.health);
|
974 |
+
gameState.player.health += healthRecovered;
|
975 |
+
|
976 |
+
addGameLog(`You rest and recover ${healthRecovered} health.`);
|
977 |
+
updatePlayerInfo();
|
978 |
+
}
|
979 |
+
|
980 |
// Travel to a settlement
|
981 |
function travelTo(settlement) {
|
982 |
if (settlement.id === gameState.player.location) {
|
|
|
1097 |
addGameLog(event.message);
|
1098 |
}
|
1099 |
|
1100 |
+
// Add 5 health (can exceed max)
|
1101 |
+
gameState.player.health += 5;
|
1102 |
+
addGameLog(`You recover 5 health from resting.`);
|
1103 |
+
|
1104 |
// Update UI
|
1105 |
updatePlayerInfo();
|
1106 |
addGameLog(`Turn ${gameState.currentTurn} completed. You paid ${wages} gold in wages and consumed ${foodConsumed} food.`);
|
1107 |
}
|
1108 |
|
1109 |
+
// Handle level up
|
1110 |
+
function checkLevelUp() {
|
1111 |
+
if (gameState.player.experience >= gameState.player.experienceToNextLevel) {
|
1112 |
+
gameState.player.level++;
|
1113 |
+
gameState.player.experience -= gameState.player.experienceToNextLevel;
|
1114 |
+
gameState.player.experienceToNextLevel = Math.floor(gameState.player.experienceToNextLevel * 1.5);
|
1115 |
+
gameState.player.maxTroops += 20;
|
1116 |
+
|
1117 |
+
// Let player choose an ability to increase
|
1118 |
+
const ability = prompt(`Level Up! You reached level ${gameState.player.level}. Choose an ability to increase:\n1. Leadership (+troop effectiveness)\n2. Combat (+personal combat)\n3. Charisma (+negotiation)\n4. Tactics (+battle advantage)`);
|
1119 |
+
|
1120 |
+
if (ability === "1") gameState.player.abilities.leadership++;
|
1121 |
+
else if (ability === "2") gameState.player.abilities.combat++;
|
1122 |
+
else if (ability === "3") gameState.player.abilities.charisma++;
|
1123 |
+
else if (ability === "4") gameState.player.abilities.tactics++;
|
1124 |
+
|
1125 |
+
addGameLog(`You reached level ${gameState.player.level}! Max troops increased to ${gameState.player.maxTroops}.`);
|
1126 |
+
return true;
|
1127 |
+
}
|
1128 |
+
return false;
|
1129 |
+
}
|
1130 |
+
|
1131 |
// Update player info display
|
1132 |
function updatePlayerInfo() {
|
1133 |
playerNameEl.textContent = gameState.player.name;
|
|
|
1136 |
playerRenownEl.textContent = gameState.player.renown;
|
1137 |
playerTroopsEl.textContent = `${gameState.player.currentTroops}/${gameState.player.maxTroops}`;
|
1138 |
document.getElementById('player-food').textContent = gameState.player.inventory.food;
|
1139 |
+
document.getElementById('player-level').textContent = gameState.player.level;
|
1140 |
+
document.getElementById('player-xp').textContent = gameState.player.experience;
|
1141 |
+
document.getElementById('player-next-xp').textContent = gameState.player.experienceToNextLevel;
|
1142 |
healthTextEl.textContent = `${gameState.player.health}`;
|
1143 |
healthBarEl.style.width = `${gameState.player.health}%`;
|
1144 |
}
|