UI tweaks
@@ -455,7 +455,7 @@ button {
455
455
border: 1px solid #ddd;
456
456
border-radius: 5px;
457
457
padding: 15px;
458
overflow-y: auto;
458
overflow-y: clip;
459
459
min-height: 200px;
460
460
}
461
461
@@ -479,6 +479,7 @@ button {
479
479
padding: 10px;
480
480
cursor: pointer;
481
481
transition: all 0.3s;
482
max-height: 50px;
482
483
}
483
484
484
485
.event-item:hover,
@@ -513,6 +514,10 @@ button {
513
514
border-color: #ff6666;
514
515
}
515
516
517
.kobold-list-sprite {
518
max-height: 45px;
519
}
520
516
521
/* Modal */
517
522
.modal {
518
523
position: fixed;
@@ -582,13 +587,12 @@ button {
582
587
display: flex;
583
588
flex-direction: column;
584
589
gap: 8px;
585
max-height: 200px;
590
max-height: 100px;
586
591
overflow-y: auto;
587
592
overflow-x: hidden;
588
593
}
589
594
590
595
.storage-item {
591
padding: 10px;
592
596
background: #f9f9f9;
593
597
border-radius: 5px;
594
598
cursor: pointer;
@@ -455,7 +455,7 @@ button {455
border: 1px solid #ddd;455
border: 1px solid #ddd;456
border-radius: 5px;456
border-radius: 5px;457
padding: 15px;457
padding: 15px;458
overflow-y: auto;458
overflow-y: clip;459
min-height: 200px;459
min-height: 200px;460
}460
}461
461
@@ -479,6 +479,7 @@ button {479
padding: 10px;479
padding: 10px;480
cursor: pointer;480
cursor: pointer;481
transition: all 0.3s;481
transition: all 0.3s;482
max-height: 50px;482
}483
}483
484
484
.event-item:hover,485
.event-item:hover,@@ -513,6 +514,10 @@ button {513
border-color: #ff6666;514
border-color: #ff6666;514
}515
}515
516
517
.kobold-list-sprite {518
max-height: 45px;519
}520
516
/* Modal */521
/* Modal */517
.modal {522
.modal {518
position: fixed;523
position: fixed;@@ -582,13 +587,12 @@ button {582
display: flex;587
display: flex;583
flex-direction: column;588
flex-direction: column;584
gap: 8px;589
gap: 8px;585
max-height: 200px;590
max-height: 100px;586
overflow-y: auto;591
overflow-y: auto;587
overflow-x: hidden;592
overflow-x: hidden;588
}593
}589
594
590
.storage-item {595
.storage-item {591
padding: 10px;592
background: #f9f9f9;596
background: #f9f9f9;593
border-radius: 5px;597
border-radius: 5px;594
cursor: pointer;598
cursor: pointer;@@ -103,7 +103,7 @@ class TribeGenApp
103
103
e.preventDefault();
104
104
const email = document.querySelector('#loginForm input[name="email"]').value;
105
105
const password = document.querySelector('#loginForm input[name="password"]').value;
106
106
let dataText = "Request failed altogether";
107
107
try
108
108
{
109
109
const response = await fetch('api/auth/login', {
@@ -113,7 +113,7 @@ class TribeGenApp
113
113
});
114
114
115
115
const dataJson = await response;
116
const dataText = await dataJson.text();
116
dataText = await dataJson.text();
117
117
const data = JSON.parse(dataText);
118
118
119
119
if (data.success)
@@ -129,6 +129,7 @@ class TribeGenApp
129
129
{
130
130
this.showAuthError('Login failed');
131
131
console.error(error);
132
console.error('Response data:', dataText);
132
133
}
133
134
}
134
135
@@ -145,6 +146,7 @@ class TribeGenApp
145
146
return;
146
147
}
147
148
149
let dataText = "Request failed altogether";
148
150
try
149
151
{
150
152
const response = await fetch('api/auth/register', {
@@ -154,7 +156,7 @@ class TribeGenApp
154
156
});
155
157
156
158
const dataRaw = await response;
157
const dataText = await dataRaw.text();
159
dataText = await dataRaw.text();
158
160
const data = JSON.parse(dataText);
159
161
160
162
if (data.success)
@@ -170,6 +172,7 @@ class TribeGenApp
170
172
{
171
173
this.showAuthError('Registration failed');
172
174
console.error(error);
175
console.error('Response data:', dataText);
173
176
}
174
177
}
175
178
@@ -204,6 +207,7 @@ class TribeGenApp
204
207
205
208
async loadSaves ()
206
209
{
210
let dataText = "Request failed altogether";
207
211
try
208
212
{
209
213
const response = await fetch(`api/game/list?userId=${this.currentUser.email}`, {
@@ -211,7 +215,7 @@ class TribeGenApp
211
215
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }
212
216
});
213
217
214
const dataText = await response.text();
218
dataText = await response.text();
215
219
const data = JSON.parse(dataText);
216
220
217
221
if (!data.success && data.error == "Not authenticated")
@@ -241,6 +245,7 @@ class TribeGenApp
241
245
} catch (error)
242
246
{
243
247
console.error('Failed to load saves:', error);
248
console.error('Response data:', dataText);
244
249
}
245
250
}
246
251
@@ -266,6 +271,7 @@ class TribeGenApp
266
271
return;
267
272
}
268
273
274
let dataText = "Request failed altogether";
269
275
try
270
276
{
271
277
const response = await fetch('api/game/generation', {
@@ -280,7 +286,7 @@ class TribeGenApp
280
286
})
281
287
});
282
288
283
const dataText = await response.text();
289
dataText = await response.text();
284
290
const data = JSON.parse(dataText);
285
291
286
292
if (data.success)
@@ -296,6 +302,7 @@ class TribeGenApp
296
302
{
297
303
alert('Failed to generate kobolds');
298
304
console.error(error);
305
console.error('Response data:', dataText);
299
306
}
300
307
}
301
308
@@ -456,13 +463,14 @@ class TribeGenApp
456
463
457
464
async loadEnvironments ()
458
465
{
466
let dataText = "Request failed altogether";
459
467
try
460
468
{
461
469
const response = await fetch('api/game/environments', {
462
470
method: 'GET'
463
471
});
464
472
465
const dataText = await response.text();
473
dataText = await response.text();
466
474
const data = JSON.parse(dataText);
467
475
468
476
if (data.success)
@@ -480,6 +488,7 @@ class TribeGenApp
480
488
} catch (error)
481
489
{
482
490
console.error('Failed to load environments', error);
491
console.error('Response data:', dataText);
483
492
}
484
493
}
485
494
@@ -570,6 +579,7 @@ class TribeGenApp
570
579
return;
571
580
}
572
581
582
let dataText = "Request failed altogether";
573
583
try
574
584
{
575
585
const response = await fetch('api/game/save', {
@@ -588,7 +598,7 @@ class TribeGenApp
588
598
})
589
599
});
590
600
591
const dataText = await response.text();
601
dataText = await response.text();
592
602
const data = JSON.parse(dataText);
593
603
594
604
if (data.success)
@@ -600,11 +610,13 @@ class TribeGenApp
600
610
{
601
611
alert('Failed to finish tribe setup');
602
612
console.error(error);
613
console.error('Response data:', dataText);
603
614
}
604
615
}
605
616
606
617
async loadGame (saveId)
607
618
{
619
let dataText = "Request failed altogether";
608
620
try
609
621
{
610
622
const response = await fetch(`api/game/load?saveId=${saveId}&userId=${this.currentUser.email}`, {
@@ -612,7 +624,7 @@ class TribeGenApp
612
624
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }
613
625
});
614
626
615
const dataText = await response.text();
627
dataText = await response.text();
616
628
const data = JSON.parse(dataText);
617
629
618
630
if (data.success)
@@ -627,6 +639,7 @@ class TribeGenApp
627
639
{
628
640
alert('Failed to load game');
629
641
console.error(error);
642
console.error('Response data:', dataText);
630
643
}
631
644
}
632
645
@@ -842,7 +855,7 @@ class TribeGenApp
842
855
item.innerHTML = `
843
856
<table style="width:100%">
844
857
<td>
845
<img src="${spriteUrl}"/>
858
<img class="kobold-list-sprite" src="${spriteUrl}"/>
846
859
</td>
847
860
<td>
848
861
<div>
@@ -911,6 +924,7 @@ class TribeGenApp
911
924
if (!this.currentUser || !this.currentSave)
912
925
return;
913
926
927
let dataText = "Request failed altogether";
914
928
try
915
929
{
916
930
const response = await fetch(`api/game/events?saveId=${this.currentSave.id}&userId=${this.currentUser.email}`, {
@@ -918,7 +932,7 @@ class TribeGenApp
918
932
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }
919
933
});
920
934
921
const dataText = await response.text();
935
dataText = await response.text();
922
936
const data = JSON.parse(dataText);
923
937
924
938
if (data.success && Array.isArray(data.events))
@@ -933,6 +947,7 @@ class TribeGenApp
933
947
} catch (error)
934
948
{
935
949
console.error('Failed to load events:', error);
950
console.error('Response data:', dataText);
936
951
}
937
952
}
938
953
@@ -1070,6 +1085,7 @@ class TribeGenApp
1070
1085
1071
1086
if (!selected || selected.length === 0) return;
1072
1087
1088
let dataText = "Request failed altogether";
1073
1089
try
1074
1090
{
1075
1091
const resp = await fetch('api/game/event', {
@@ -1078,7 +1094,7 @@ class TribeGenApp
1078
1094
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, eventType: this.currentEventType, participants: selected })
1079
1095
});
1080
1096
1081
const dataText = await resp.text();
1097
dataText = await resp.text();
1082
1098
const data = JSON.parse(dataText);
1083
1099
1084
1100
if (data.success)
@@ -1090,16 +1106,18 @@ class TribeGenApp
1090
1106
} else
1091
1107
{
1092
1108
alert(data.error || 'Failed to start event');
1109
console.error('Event error:', data);
1093
1110
}
1094
1111
} catch (err)
1095
1112
{
1096
1113
console.error(err);
1097
alert('Failed to start event');
1114
console.error('Response data:', dataText);
1098
1115
}
1099
1116
}
1100
1117
1101
1118
async endMonth ()
1102
1119
{
1120
let dataT = "Request failed altogether";
1103
1121
try
1104
1122
{
1105
1123
const response = await fetch('api/game/endMonth', {
@@ -1113,7 +1131,7 @@ class TribeGenApp
1113
1131
})
1114
1132
});
1115
1133
1116
const dataT = await response.text();
1134
dataT = await response.text();
1117
1135
const data = JSON.parse(dataT);
1118
1136
1119
1137
if (data.success)
@@ -1127,6 +1145,7 @@ class TribeGenApp
1127
1145
{
1128
1146
alert('Failed to end month');
1129
1147
console.error(error);
1148
console.error('Response data:', dataT);
1130
1149
}
1131
1150
}
1132
1151
@@ -1239,6 +1258,7 @@ class TribeGenApp
1239
1258
1240
1259
async giveItemToKobold (item, koboldId)
1241
1260
{
1261
let dataText = "Request failed altogether";
1242
1262
try
1243
1263
{
1244
1264
const resp = await fetch('api/game/giveItem', {
@@ -1247,7 +1267,7 @@ class TribeGenApp
1247
1267
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: koboldId, itemId: item.id })
1248
1268
});
1249
1269
1250
const dataText = await resp.text();
1270
dataText = await resp.text();
1251
1271
const data = JSON.parse(dataText);
1252
1272
if (data.success)
1253
1273
{
@@ -1259,11 +1279,13 @@ class TribeGenApp
1259
1279
} else
1260
1280
{
1261
1281
alert(data.error || 'Failed to give item');
1282
console.error('Give item error:', data);
1262
1283
}
1263
1284
} catch (err)
1264
1285
{
1265
1286
console.error(err);
1266
1287
alert('Failed to give item');
1288
console.error('Response data:', dataText);
1267
1289
} finally
1268
1290
{
1269
1291
this.hideItemModal();
@@ -1432,6 +1454,7 @@ class TribeGenApp
1432
1454
btn.textContent = `Cure using ${required}`;
1433
1455
btn.addEventListener('click', async () =>
1434
1456
{
1457
let dataText = "Request failed altogether";
1435
1458
try
1436
1459
{
1437
1460
const resp = await fetch('api/game/cureInjury', {
@@ -1439,7 +1462,7 @@ class TribeGenApp
1439
1462
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },
1440
1463
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, injuryId: injury.id, itemId: required })
1441
1464
});
1442
const dataText = await resp.text();
1465
dataText = await resp.text();
1443
1466
const data = JSON.parse(dataText);
1444
1467
if (data.success)
1445
1468
{
@@ -1454,11 +1477,13 @@ class TribeGenApp
1454
1477
} else
1455
1478
{
1456
1479
alert(data.error || 'Failed to cure injury');
1480
console.error('Cure injury error:', data);
1457
1481
}
1458
1482
} catch (err)
1459
1483
{
1460
1484
console.error(err);
1461
1485
alert('Failed to cure injury');
1486
console.error('Response data:', dataText);
1462
1487
}
1463
1488
});
1464
1489
actions.appendChild(btn);
@@ -1527,6 +1552,7 @@ class TribeGenApp
1527
1552
1528
1553
async returnItemToStorage (item, kobold)
1529
1554
{
1555
let dataText = "Request failed altogether";
1530
1556
try
1531
1557
{
1532
1558
const resp = await fetch('api/game/returnItem', {
@@ -1535,7 +1561,7 @@ class TribeGenApp
1535
1561
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, itemId: item.id })
1536
1562
});
1537
1563
1538
const dataText = await resp.text();
1564
dataText = await resp.text();
1539
1565
const data = JSON.parse(dataText);
1540
1566
if (data.success)
1541
1567
{
@@ -1547,11 +1573,13 @@ class TribeGenApp
1547
1573
} else
1548
1574
{
1549
1575
alert(data.error || 'Failed to return item');
1576
console.error('Return item error:', data);
1550
1577
}
1551
1578
} catch (err)
1552
1579
{
1553
1580
console.error(err);
1554
1581
alert('Failed to return item');
1582
console.error('Response data:', dataText);
1555
1583
} finally
1556
1584
{
1557
1585
this.hideItemModal();
@@ -103,7 +103,7 @@ class TribeGenApp103
e.preventDefault();103
e.preventDefault();104
const email = document.querySelector('#loginForm input[name="email"]').value;104
const email = document.querySelector('#loginForm input[name="email"]').value;105
const password = document.querySelector('#loginForm input[name="password"]').value;105
const password = document.querySelector('#loginForm input[name="password"]').value;106
106
let dataText = "Request failed altogether";107
try107
try108
{108
{109
const response = await fetch('api/auth/login', {109
const response = await fetch('api/auth/login', {@@ -113,7 +113,7 @@ class TribeGenApp113
});113
});114
114
115
const dataJson = await response;115
const dataJson = await response;116
const dataText = await dataJson.text();116
dataText = await dataJson.text();117
const data = JSON.parse(dataText);117
const data = JSON.parse(dataText);118
118
119
if (data.success)119
if (data.success)@@ -129,6 +129,7 @@ class TribeGenApp129
{129
{130
this.showAuthError('Login failed');130
this.showAuthError('Login failed');131
console.error(error);131
console.error(error);132
console.error('Response data:', dataText);132
}133
}133
}134
}134
135
@@ -145,6 +146,7 @@ class TribeGenApp145
return;146
return;146
}147
}147
148
149
let dataText = "Request failed altogether";148
try150
try149
{151
{150
const response = await fetch('api/auth/register', {152
const response = await fetch('api/auth/register', {@@ -154,7 +156,7 @@ class TribeGenApp154
});156
});155
157
156
const dataRaw = await response;158
const dataRaw = await response;157
const dataText = await dataRaw.text();159
dataText = await dataRaw.text();158
const data = JSON.parse(dataText);160
const data = JSON.parse(dataText);159
161
160
if (data.success)162
if (data.success)@@ -170,6 +172,7 @@ class TribeGenApp170
{172
{171
this.showAuthError('Registration failed');173
this.showAuthError('Registration failed');172
console.error(error);174
console.error(error);175
console.error('Response data:', dataText);173
}176
}174
}177
}175
178
@@ -204,6 +207,7 @@ class TribeGenApp204
207
205
async loadSaves ()208
async loadSaves ()206
{209
{210
let dataText = "Request failed altogether";207
try211
try208
{212
{209
const response = await fetch(`api/game/list?userId=${this.currentUser.email}`, {213
const response = await fetch(`api/game/list?userId=${this.currentUser.email}`, {@@ -211,7 +215,7 @@ class TribeGenApp211
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }215
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }212
});216
});213
217
214
const dataText = await response.text();218
dataText = await response.text();215
const data = JSON.parse(dataText);219
const data = JSON.parse(dataText);216
220
217
if (!data.success && data.error == "Not authenticated")221
if (!data.success && data.error == "Not authenticated")@@ -241,6 +245,7 @@ class TribeGenApp241
} catch (error)245
} catch (error)242
{246
{243
console.error('Failed to load saves:', error);247
console.error('Failed to load saves:', error);248
console.error('Response data:', dataText);244
}249
}245
}250
}246
251
@@ -266,6 +271,7 @@ class TribeGenApp266
return;271
return;267
}272
}268
273
274
let dataText = "Request failed altogether";269
try275
try270
{276
{271
const response = await fetch('api/game/generation', {277
const response = await fetch('api/game/generation', {@@ -280,7 +286,7 @@ class TribeGenApp280
})286
})281
});287
});282
288
283
const dataText = await response.text();289
dataText = await response.text();284
const data = JSON.parse(dataText);290
const data = JSON.parse(dataText);285
291
286
if (data.success)292
if (data.success)@@ -296,6 +302,7 @@ class TribeGenApp296
{302
{297
alert('Failed to generate kobolds');303
alert('Failed to generate kobolds');298
console.error(error);304
console.error(error);305
console.error('Response data:', dataText);299
}306
}300
}307
}301
308
@@ -456,13 +463,14 @@ class TribeGenApp456
463
457
async loadEnvironments ()464
async loadEnvironments ()458
{465
{466
let dataText = "Request failed altogether";459
try467
try460
{468
{461
const response = await fetch('api/game/environments', {469
const response = await fetch('api/game/environments', {462
method: 'GET'470
method: 'GET'463
});471
});464
472
465
const dataText = await response.text();473
dataText = await response.text();466
const data = JSON.parse(dataText);474
const data = JSON.parse(dataText);467
475
468
if (data.success)476
if (data.success)@@ -480,6 +488,7 @@ class TribeGenApp480
} catch (error)488
} catch (error)481
{489
{482
console.error('Failed to load environments', error);490
console.error('Failed to load environments', error);491
console.error('Response data:', dataText);483
}492
}484
}493
}485
494
@@ -570,6 +579,7 @@ class TribeGenApp570
return;579
return;571
}580
}572
581
582
let dataText = "Request failed altogether";573
try583
try574
{584
{575
const response = await fetch('api/game/save', {585
const response = await fetch('api/game/save', {@@ -588,7 +598,7 @@ class TribeGenApp588
})598
})589
});599
});590
600
591
const dataText = await response.text();601
dataText = await response.text();592
const data = JSON.parse(dataText);602
const data = JSON.parse(dataText);593
603
594
if (data.success)604
if (data.success)@@ -600,11 +610,13 @@ class TribeGenApp600
{610
{601
alert('Failed to finish tribe setup');611
alert('Failed to finish tribe setup');602
console.error(error);612
console.error(error);613
console.error('Response data:', dataText);603
}614
}604
}615
}605
616
606
async loadGame (saveId)617
async loadGame (saveId)607
{618
{619
let dataText = "Request failed altogether";608
try620
try609
{621
{610
const response = await fetch(`api/game/load?saveId=${saveId}&userId=${this.currentUser.email}`, {622
const response = await fetch(`api/game/load?saveId=${saveId}&userId=${this.currentUser.email}`, {@@ -612,7 +624,7 @@ class TribeGenApp612
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }624
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }613
});625
});614
626
615
const dataText = await response.text();627
dataText = await response.text();616
const data = JSON.parse(dataText);628
const data = JSON.parse(dataText);617
629
618
if (data.success)630
if (data.success)@@ -627,6 +639,7 @@ class TribeGenApp627
{639
{628
alert('Failed to load game');640
alert('Failed to load game');629
console.error(error);641
console.error(error);642
console.error('Response data:', dataText);630
}643
}631
}644
}632
645
@@ -842,7 +855,7 @@ class TribeGenApp842
item.innerHTML = `855
item.innerHTML = `843
<table style="width:100%">856
<table style="width:100%">844
<td>857
<td>845
<img src="${spriteUrl}"/>858
<img class="kobold-list-sprite" src="${spriteUrl}"/>846
</td>859
</td>847
<td>860
<td>848
<div>861
<div>@@ -911,6 +924,7 @@ class TribeGenApp911
if (!this.currentUser || !this.currentSave)924
if (!this.currentUser || !this.currentSave)912
return;925
return;913
926
927
let dataText = "Request failed altogether";914
try928
try915
{929
{916
const response = await fetch(`api/game/events?saveId=${this.currentSave.id}&userId=${this.currentUser.email}`, {930
const response = await fetch(`api/game/events?saveId=${this.currentSave.id}&userId=${this.currentUser.email}`, {@@ -918,7 +932,7 @@ class TribeGenApp918
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }932
headers: { 'Authorization': `Bearer ${this.currentUser.token}` }919
});933
});920
934
921
const dataText = await response.text();935
dataText = await response.text();922
const data = JSON.parse(dataText);936
const data = JSON.parse(dataText);923
937
924
if (data.success && Array.isArray(data.events))938
if (data.success && Array.isArray(data.events))@@ -933,6 +947,7 @@ class TribeGenApp933
} catch (error)947
} catch (error)934
{948
{935
console.error('Failed to load events:', error);949
console.error('Failed to load events:', error);950
console.error('Response data:', dataText);936
}951
}937
}952
}938
953
@@ -1070,6 +1085,7 @@ class TribeGenApp1070
1085
1071
if (!selected || selected.length === 0) return;1086
if (!selected || selected.length === 0) return;1072
1087
1088
let dataText = "Request failed altogether";1073
try1089
try1074
{1090
{1075
const resp = await fetch('api/game/event', {1091
const resp = await fetch('api/game/event', {@@ -1078,7 +1094,7 @@ class TribeGenApp1078
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, eventType: this.currentEventType, participants: selected })1094
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, eventType: this.currentEventType, participants: selected })1079
});1095
});1080
1096
1081
const dataText = await resp.text();1097
dataText = await resp.text();1082
const data = JSON.parse(dataText);1098
const data = JSON.parse(dataText);1083
1099
1084
if (data.success)1100
if (data.success)@@ -1090,16 +1106,18 @@ class TribeGenApp1090
} else1106
} else1091
{1107
{1092
alert(data.error || 'Failed to start event');1108
alert(data.error || 'Failed to start event');1109
console.error('Event error:', data);1093
}1110
}1094
} catch (err)1111
} catch (err)1095
{1112
{1096
console.error(err);1113
console.error(err);1097
alert('Failed to start event');1114
console.error('Response data:', dataText);1098
}1115
}1099
}1116
}1100
1117
1101
async endMonth ()1118
async endMonth ()1102
{1119
{1120
let dataT = "Request failed altogether";1103
try1121
try1104
{1122
{1105
const response = await fetch('api/game/endMonth', {1123
const response = await fetch('api/game/endMonth', {@@ -1113,7 +1131,7 @@ class TribeGenApp1113
})1131
})1114
});1132
});1115
1133
1116
const dataT = await response.text();1134
dataT = await response.text();1117
const data = JSON.parse(dataT);1135
const data = JSON.parse(dataT);1118
1136
1119
if (data.success)1137
if (data.success)@@ -1127,6 +1145,7 @@ class TribeGenApp1127
{1145
{1128
alert('Failed to end month');1146
alert('Failed to end month');1129
console.error(error);1147
console.error(error);1148
console.error('Response data:', dataT);1130
}1149
}1131
}1150
}1132
1151
@@ -1239,6 +1258,7 @@ class TribeGenApp1239
1258
1240
async giveItemToKobold (item, koboldId)1259
async giveItemToKobold (item, koboldId)1241
{1260
{1261
let dataText = "Request failed altogether";1242
try1262
try1243
{1263
{1244
const resp = await fetch('api/game/giveItem', {1264
const resp = await fetch('api/game/giveItem', {@@ -1247,7 +1267,7 @@ class TribeGenApp1247
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: koboldId, itemId: item.id })1267
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: koboldId, itemId: item.id })1248
});1268
});1249
1269
1250
const dataText = await resp.text();1270
dataText = await resp.text();1251
const data = JSON.parse(dataText);1271
const data = JSON.parse(dataText);1252
if (data.success)1272
if (data.success)1253
{1273
{@@ -1259,11 +1279,13 @@ class TribeGenApp1259
} else1279
} else1260
{1280
{1261
alert(data.error || 'Failed to give item');1281
alert(data.error || 'Failed to give item');1282
console.error('Give item error:', data);1262
}1283
}1263
} catch (err)1284
} catch (err)1264
{1285
{1265
console.error(err);1286
console.error(err);1266
alert('Failed to give item');1287
alert('Failed to give item');1288
console.error('Response data:', dataText);1267
} finally1289
} finally1268
{1290
{1269
this.hideItemModal();1291
this.hideItemModal();@@ -1432,6 +1454,7 @@ class TribeGenApp1432
btn.textContent = `Cure using ${required}`;1454
btn.textContent = `Cure using ${required}`;1433
btn.addEventListener('click', async () =>1455
btn.addEventListener('click', async () =>1434
{1456
{1457
let dataText = "Request failed altogether";1435
try1458
try1436
{1459
{1437
const resp = await fetch('api/game/cureInjury', {1460
const resp = await fetch('api/game/cureInjury', {@@ -1439,7 +1462,7 @@ class TribeGenApp1439
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1462
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.currentUser?.token}` },1440
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, injuryId: injury.id, itemId: required })1463
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, injuryId: injury.id, itemId: required })1441
});1464
});1442
const dataText = await resp.text();1465
dataText = await resp.text();1443
const data = JSON.parse(dataText);1466
const data = JSON.parse(dataText);1444
if (data.success)1467
if (data.success)1445
{1468
{@@ -1454,11 +1477,13 @@ class TribeGenApp1454
} else1477
} else1455
{1478
{1456
alert(data.error || 'Failed to cure injury');1479
alert(data.error || 'Failed to cure injury');1480
console.error('Cure injury error:', data);1457
}1481
}1458
} catch (err)1482
} catch (err)1459
{1483
{1460
console.error(err);1484
console.error(err);1461
alert('Failed to cure injury');1485
alert('Failed to cure injury');1486
console.error('Response data:', dataText);1462
}1487
}1463
});1488
});1464
actions.appendChild(btn);1489
actions.appendChild(btn);@@ -1527,6 +1552,7 @@ class TribeGenApp1527
1552
1528
async returnItemToStorage (item, kobold)1553
async returnItemToStorage (item, kobold)1529
{1554
{1555
let dataText = "Request failed altogether";1530
try1556
try1531
{1557
{1532
const resp = await fetch('api/game/returnItem', {1558
const resp = await fetch('api/game/returnItem', {@@ -1535,7 +1561,7 @@ class TribeGenApp1535
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, itemId: item.id })1561
body: JSON.stringify({ userId: this.currentUser.email, saveId: this.currentSave.id, koboldId: kobold.id, itemId: item.id })1536
});1562
});1537
1563
1538
const dataText = await resp.text();1564
dataText = await resp.text();1539
const data = JSON.parse(dataText);1565
const data = JSON.parse(dataText);1540
if (data.success)1566
if (data.success)1541
{1567
{@@ -1547,11 +1573,13 @@ class TribeGenApp1547
} else1573
} else1548
{1574
{1549
alert(data.error || 'Failed to return item');1575
alert(data.error || 'Failed to return item');1576
console.error('Return item error:', data);1550
}1577
}1551
} catch (err)1578
} catch (err)1552
{1579
{1553
console.error(err);1580
console.error(err);1554
alert('Failed to return item');1581
alert('Failed to return item');1582
console.error('Response data:', dataText);1555
} finally1583
} finally1556
{1584
{1557
this.hideItemModal();1585
this.hideItemModal();@@ -17,7 +17,7 @@ class FarmingEvent extends Event
17
17
18
18
public function getMaxParticipants()
19
19
{
20
return 10;
20
return 6;
21
21
}
22
22
23
23
public function getCost()
@@ -142,6 +142,7 @@ class FarmingEvent extends Event
142
142
143
143
public function autumn(array $all, Kobold $bestInt, Kobold $bestVit)
144
144
{
145
$harvestBaseMultiplier = 3.0;
145
146
$this->tribe->dataStore->wasTendedInSummer = false;
146
147
147
148
$multiplier = $this->tribe->dataStore->farmYieldMultiplier ?? 1.0;
@@ -158,7 +159,7 @@ class FarmingEvent extends Event
158
159
for ($i = 0; $i < count($all); $i++) {
159
160
$farmer = $all[$i];
160
161
161
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * 3) * $multiplier;
162
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * $harvestBaseMultiplier) * $multiplier;
162
163
$totalFood += $farmed;
163
164
164
165
if ($farmed > $mostFood) {
@@ -176,6 +177,24 @@ class FarmingEvent extends Event
176
177
$months = $this->tribe->foodMonthsLeft($totalFood);
177
178
$this->tribe->addFood($totalFood);
178
179
180
$max = $this->tribe->foodRequirements[GameHelper::getAgeCategory("adult")] * $harvestBaseMultiplier * $multiplier * $this->getMaxParticipants();
181
182
$word = "terribly";
183
$perc = ($totalFood / $max);
184
185
if ($perc >= 0.95)
186
$word = "perfectly";
187
else if ($perc >= 0.75)
188
$word = "great";
189
else if ($perc >= 0.5)
190
$word = "well";
191
else if ($perc >= 0.25)
192
$word = "okay";
193
else if ($perc >= 0.1)
194
$word = "badly";
195
196
$this->story .= "Tending to the crops went {$word}.\n";
197
179
198
if ($months < 1)
180
199
$this->story .= "The tribe gained only {$this->tribe->foodTimeStr($totalFood)} worth of food from the harvest.\n";
181
200
else {
@@ -17,7 +17,7 @@ class FarmingEvent extends Event17
17
18
public function getMaxParticipants()18
public function getMaxParticipants()19
{19
{20
return 10;20
return 6;21
}21
}22
22
23
public function getCost()23
public function getCost()@@ -142,6 +142,7 @@ class FarmingEvent extends Event142
142
143
public function autumn(array $all, Kobold $bestInt, Kobold $bestVit)143
public function autumn(array $all, Kobold $bestInt, Kobold $bestVit)144
{144
{145
$harvestBaseMultiplier = 3.0;145
$this->tribe->dataStore->wasTendedInSummer = false;146
$this->tribe->dataStore->wasTendedInSummer = false;146
147
147
$multiplier = $this->tribe->dataStore->farmYieldMultiplier ?? 1.0;148
$multiplier = $this->tribe->dataStore->farmYieldMultiplier ?? 1.0;@@ -158,7 +159,7 @@ class FarmingEvent extends Event158
for ($i = 0; $i < count($all); $i++) {159
for ($i = 0; $i < count($all); $i++) {159
$farmer = $all[$i];160
$farmer = $all[$i];160
161
161
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * 3) * $multiplier;162
$farmed = rand(0, $this->tribe->foodRequirements[$farmer->getAgeCategory()] * $harvestBaseMultiplier) * $multiplier;162
$totalFood += $farmed;163
$totalFood += $farmed;163
164
164
if ($farmed > $mostFood) {165
if ($farmed > $mostFood) {@@ -176,6 +177,24 @@ class FarmingEvent extends Event176
$months = $this->tribe->foodMonthsLeft($totalFood);177
$months = $this->tribe->foodMonthsLeft($totalFood);177
$this->tribe->addFood($totalFood);178
$this->tribe->addFood($totalFood);178
179
180
$max = $this->tribe->foodRequirements[GameHelper::getAgeCategory("adult")] * $harvestBaseMultiplier * $multiplier * $this->getMaxParticipants();181
182
$word = "terribly";183
$perc = ($totalFood / $max);184
185
if ($perc >= 0.95)186
$word = "perfectly";187
else if ($perc >= 0.75)188
$word = "great";189
else if ($perc >= 0.5)190
$word = "well";191
else if ($perc >= 0.25)192
$word = "okay";193
else if ($perc >= 0.1)194
$word = "badly";195
196
$this->story .= "Tending to the crops went {$word}.\n";197
179
if ($months < 1)198
if ($months < 1)180
$this->story .= "The tribe gained only {$this->tribe->foodTimeStr($totalFood)} worth of food from the harvest.\n";199
$this->story .= "The tribe gained only {$this->tribe->foodTimeStr($totalFood)} worth of food from the harvest.\n";181
else {200
else {@@ -162,7 +162,7 @@ if ($method === 'POST') {
162
162
$koboldName = $target->getName();
163
163
$injuryName = $injury['injury_type'] ?? ($injury['injuryType'] ?? 'injury');
164
164
165
$story = "{$koboldName} used the {$itemName} to cure their {$injuryName}.";
165
$story = "{$koboldName} used the {$itemName} to cure the {$injuryName}.";
166
166
167
167
echo json_encode(['success' => true, 'story' => $story]);
168
168
} catch (\Exception $e) {
@@ -162,7 +162,7 @@ if ($method === 'POST') {162
$koboldName = $target->getName();162
$koboldName = $target->getName();163
$injuryName = $injury['injury_type'] ?? ($injury['injuryType'] ?? 'injury');163
$injuryName = $injury['injury_type'] ?? ($injury['injuryType'] ?? 'injury');164
164
165
$story = "{$koboldName} used the {$itemName} to cure their {$injuryName}.";165
$story = "{$koboldName} used the {$itemName} to cure the {$injuryName}.";166
166
167
echo json_encode(['success' => true, 'story' => $story]);167
echo json_encode(['success' => true, 'story' => $story]);168
} catch (\Exception $e) {168
} catch (\Exception $e) {