eg
The contents of this binary file are not shown.
@@ -325,7 +325,13 @@ class TribeGenApp
325
325
const leaderIndex = document.getElementById('selectLeaderBtn').dataset.leaderIndex;
326
326
if (force || leaderIndex != index)
327
327
{
328
document.querySelectorAll('#memberSelectionGrid .kobold-card')[index].classList.toggle('selected');
328
const selectedCard = document.querySelectorAll('#memberSelectionGrid .kobold-card')[index];
329
selectedCard.classList.toggle('selected');
330
331
if (force)
332
{
333
selectedCard.id = "tribeLeader";
334
}
329
335
330
336
const selected = document.querySelectorAll('#memberSelectionGrid .kobold-card.selected').length;
331
337
document.getElementById('memberCount').textContent = `${selected} / 5 selected`;
@@ -342,7 +348,6 @@ class TribeGenApp
342
348
343
349
async selectLeader ()
344
350
{
345
const leaderIndex = document.getElementById('selectLeaderBtn').dataset.leaderIndex;
346
351
const leaderName = document.getElementById('leaderName').value;
347
352
348
353
if (!leaderName)
@@ -360,7 +365,9 @@ class TribeGenApp
360
365
361
366
async finishTribe ()
362
367
{
368
const leaderIndex = document.getElementById('selectLeaderBtn').dataset.leaderIndex;
363
369
const selectedMembers = document.querySelectorAll('#memberSelectionGrid .kobold-card.selected');
370
364
371
const memberIndices = Array.from(selectedMembers).map(card =>
365
372
{
366
373
return Array.from(card.parentElement.children).indexOf(card);
@@ -379,7 +386,8 @@ class TribeGenApp
379
386
userId: this.currentUser.id,
380
387
saveId: this.currentSave.id,
381
388
leaderName: document.getElementById('leaderName').value,
382
memberIndices: memberIndices
389
memberIndices: memberIndices,
390
leaderId: leaderIndex
383
391
})
384
392
});
385
393
@@ -459,7 +467,7 @@ class TribeGenApp
459
467
<td>
460
468
<div>
461
469
<div class="tribe-item-name">${kobold.name}</div>
462
<div class="tribe-item-age">${kobold.age} years</div>
470
<div class="tribe-item-age">${(kobold.age > 0 ? kobold.age : 0)} years</div>
463
471
</div>
464
472
</td>
465
473
</table>
@@ -806,8 +814,19 @@ class TribeGenApp
806
814
{
807
815
const modal = document.getElementById('koboldModal');
808
816
document.getElementById('koboldModalName').textContent = kobold.name;
809
document.getElementById('koboldModalAge').textContent = `${(kobold.male ? "male" : "female")}, ${kobold.age} years old`;
810
document.getElementById('koboldModalDescription').textContent = `A ${kobold.ageCategory} Kobold`;
817
818
const a = (kobold.ageCategory == "old" || kobold.ageCategory == "adult") ? "An" : "A";
819
820
if (kobold.ageCategory == "egg")
821
{
822
document.getElementById('koboldModalAge').textContent = `Not yet hatched`;
823
document.getElementById('koboldModalDescription').textContent = `An egg.`;
824
}
825
else
826
{
827
document.getElementById('koboldModalAge').textContent = `${kobold.age} years old`;
828
document.getElementById('koboldModalDescription').textContent = `${a} ${kobold.ageCategory} ${(kobold.male ? "male" : "female")} Kobold.`;
829
}
811
830
812
831
this.renderKoboldStats(kobold);
813
832
this.renderKoboldInventory(kobold);
@@ -325,7 +325,13 @@ class TribeGenApp325
const leaderIndex = document.getElementById('selectLeaderBtn').dataset.leaderIndex;325
const leaderIndex = document.getElementById('selectLeaderBtn').dataset.leaderIndex;326
if (force || leaderIndex != index)326
if (force || leaderIndex != index)327
{327
{328
document.querySelectorAll('#memberSelectionGrid .kobold-card')[index].classList.toggle('selected');328
const selectedCard = document.querySelectorAll('#memberSelectionGrid .kobold-card')[index];329
selectedCard.classList.toggle('selected');330
331
if (force)332
{333
selectedCard.id = "tribeLeader";334
}329
335
330
const selected = document.querySelectorAll('#memberSelectionGrid .kobold-card.selected').length;336
const selected = document.querySelectorAll('#memberSelectionGrid .kobold-card.selected').length;331
document.getElementById('memberCount').textContent = `${selected} / 5 selected`;337
document.getElementById('memberCount').textContent = `${selected} / 5 selected`;@@ -342,7 +348,6 @@ class TribeGenApp342
348
343
async selectLeader ()349
async selectLeader ()344
{350
{345
const leaderIndex = document.getElementById('selectLeaderBtn').dataset.leaderIndex;346
const leaderName = document.getElementById('leaderName').value;351
const leaderName = document.getElementById('leaderName').value;347
352
348
if (!leaderName)353
if (!leaderName)@@ -360,7 +365,9 @@ class TribeGenApp360
365
361
async finishTribe ()366
async finishTribe ()362
{367
{368
const leaderIndex = document.getElementById('selectLeaderBtn').dataset.leaderIndex;363
const selectedMembers = document.querySelectorAll('#memberSelectionGrid .kobold-card.selected');369
const selectedMembers = document.querySelectorAll('#memberSelectionGrid .kobold-card.selected');370
364
const memberIndices = Array.from(selectedMembers).map(card =>371
const memberIndices = Array.from(selectedMembers).map(card =>365
{372
{366
return Array.from(card.parentElement.children).indexOf(card);373
return Array.from(card.parentElement.children).indexOf(card);@@ -379,7 +386,8 @@ class TribeGenApp379
userId: this.currentUser.id,386
userId: this.currentUser.id,380
saveId: this.currentSave.id,387
saveId: this.currentSave.id,381
leaderName: document.getElementById('leaderName').value,388
leaderName: document.getElementById('leaderName').value,382
memberIndices: memberIndices389
memberIndices: memberIndices,390
leaderId: leaderIndex383
})391
})384
});392
});385
393
@@ -459,7 +467,7 @@ class TribeGenApp459
<td>467
<td>460
<div>468
<div>461
<div class="tribe-item-name">${kobold.name}</div>469
<div class="tribe-item-name">${kobold.name}</div>462
<div class="tribe-item-age">${kobold.age} years</div>470
<div class="tribe-item-age">${(kobold.age > 0 ? kobold.age : 0)} years</div>463
</div>471
</div>464
</td>472
</td>465
</table>473
</table>@@ -806,8 +814,19 @@ class TribeGenApp806
{814
{807
const modal = document.getElementById('koboldModal');815
const modal = document.getElementById('koboldModal');808
document.getElementById('koboldModalName').textContent = kobold.name;816
document.getElementById('koboldModalName').textContent = kobold.name;809
document.getElementById('koboldModalAge').textContent = `${(kobold.male ? "male" : "female")}, ${kobold.age} years old`;817
810
document.getElementById('koboldModalDescription').textContent = `A ${kobold.ageCategory} Kobold`;818
const a = (kobold.ageCategory == "old" || kobold.ageCategory == "adult") ? "An" : "A";819
820
if (kobold.ageCategory == "egg")821
{822
document.getElementById('koboldModalAge').textContent = `Not yet hatched`;823
document.getElementById('koboldModalDescription').textContent = `An egg.`;824
}825
else826
{827
document.getElementById('koboldModalAge').textContent = `${kobold.age} years old`;828
document.getElementById('koboldModalDescription').textContent = `${a} ${kobold.ageCategory} ${(kobold.male ? "male" : "female")} Kobold.`;829
}811
830
812
this.renderKoboldStats(kobold);831
this.renderKoboldStats(kobold);813
this.renderKoboldInventory(kobold);832
this.renderKoboldInventory(kobold);@@ -96,10 +96,15 @@ class Kobold
96
96
return $this->male ? "his" : "her";
97
97
}
98
98
99
public function setLeader()
100
{
101
$this->isLeader = true;
102
}
103
99
104
public static function generate($userId, $saveId, $age = null)
100
105
{
101
106
if ($age === null) {
102
$age = rand(5, 20);
107
$age = rand(5, 50);
103
108
}
104
109
105
110
$spriteMorph = self::getRandomSpriteMorph();
@@ -232,13 +237,13 @@ class Kobold
232
237
{
233
238
return [
234
239
'id' => $this->id,
235
'name' => $this->name,
240
'name' => $this->getAgeCategory() !== "egg" ? $this->name : "Egg",
236
241
'age' => $this->age,
237
242
'ageCategory' => $this->getAgeCategory(),
238
243
'stats' => $this->stats,
239
244
'sprite_morph' => $this->spriteMorph,
240
245
'is_leader' => $this->isLeader,
241
'is_alive' => $this->isAlive,
246
'is_alive' => !$this->isDead(),
242
247
'is_expelled' => $this->isExpelled,
243
248
'injuries' => $this->injuries,
244
249
'items' => $this->items,
@@ -370,9 +375,9 @@ class Kobold
370
375
public function getAgeProgress()
371
376
{
372
377
if ($this->age < 17) {
373
return $this->age / 17;
378
return max(1, $this->age / 17);
374
379
} else if ($this->age > 40) {
375
return 1 - (40 / $this->age);
380
return max(1, 1 - (40 / $this->age));
376
381
}
377
382
378
383
return 1;
@@ -96,10 +96,15 @@ class Kobold96
return $this->male ? "his" : "her";96
return $this->male ? "his" : "her";97
}97
}98
98
99
public function setLeader()100
{101
$this->isLeader = true;102
}103
99
public static function generate($userId, $saveId, $age = null)104
public static function generate($userId, $saveId, $age = null)100
{105
{101
if ($age === null) {106
if ($age === null) {102
$age = rand(5, 20);107
$age = rand(5, 50);103
}108
}104
109
105
$spriteMorph = self::getRandomSpriteMorph();110
$spriteMorph = self::getRandomSpriteMorph();@@ -232,13 +237,13 @@ class Kobold232
{237
{233
return [238
return [234
'id' => $this->id,239
'id' => $this->id,235
'name' => $this->name,240
'name' => $this->getAgeCategory() !== "egg" ? $this->name : "Egg",236
'age' => $this->age,241
'age' => $this->age,237
'ageCategory' => $this->getAgeCategory(),242
'ageCategory' => $this->getAgeCategory(),238
'stats' => $this->stats,243
'stats' => $this->stats,239
'sprite_morph' => $this->spriteMorph,244
'sprite_morph' => $this->spriteMorph,240
'is_leader' => $this->isLeader,245
'is_leader' => $this->isLeader,241
'is_alive' => $this->isAlive,246
'is_alive' => !$this->isDead(),242
'is_expelled' => $this->isExpelled,247
'is_expelled' => $this->isExpelled,243
'injuries' => $this->injuries,248
'injuries' => $this->injuries,244
'items' => $this->items,249
'items' => $this->items,@@ -370,9 +375,9 @@ class Kobold370
public function getAgeProgress()375
public function getAgeProgress()371
{376
{372
if ($this->age < 17) {377
if ($this->age < 17) {373
return $this->age / 17;378
return max(1, $this->age / 17);374
} else if ($this->age > 40) {379
} else if ($this->age > 40) {375
return 1 - (40 / $this->age);380
return max(1, 1 - (40 / $this->age));376
}381
}377
382
378
return 1;383
return 1;@@ -340,14 +340,14 @@ class Tribe
340
340
341
341
// Add malnourished injury if not already present
342
342
if (!$this->hasInjuryCategory($kobold, 'malnourished')) {
343
$kobold->addInjury('malnourished', 'malnourished', 1);
343
$kobold->addInjury('malnourished');
344
344
$story .= "{$kobold->getName()} went hungry and became malnourished.\n";
345
345
} else {
346
346
// Already malnourished - becomes more severe
347
347
$injuries = $kobold->getInjuries();
348
348
foreach ($injuries as $injury) {
349
349
if ($injury['category'] === 'malnourished') {
350
// Could increase severity or add another injury
350
$injury['severity']++;
351
351
$story .= "{$kobold->getName()} remained hungry and suffered.\n";
352
352
break;
353
353
}
@@ -403,15 +403,21 @@ class Tribe
403
403
$this->currentSeason = $seasons[$index];
404
404
// Random month events happen here (handled by EventManager in API)
405
405
// After events, consume food
406
$foodStory = $this->consumeFood();
407
406
408
// Age all kobolds
409
if ($this->currentMonth % 12 === 0) {
410
$foodStory .= "\nA new year begins.\n";
411
407
412
foreach ($this->kobolds as $kobold) {
408
409
// age eggs
410
$foodStory = "A month passes...\n" . $this->consumeFood();
411
$foodStory .= "\n";
412
413
foreach ($this->kobolds as $kobold) {
414
if ($kobold->getAge() < 0) {
413
415
$kobold->incrementAge();
414
416
417
if ($kobold->getAge() >= 0) {
418
$foodStory .= "An egg hatched! {$kobold->getName()} was born.\n";
419
}
420
415
421
// Check for old-age injuries
416
422
if ($kobold->getAge() >= 35 && $this->shouldAddOldAgeInjury($kobold)) {
417
423
$oldAgeInjuries = ['bad_back', 'bad_liver', 'poor_eyesight', 'dementia'];
@@ -431,6 +437,35 @@ class Tribe
431
437
$kobold->save();
432
438
}
433
439
}
440
441
// Age all kobolds
442
if ($this->currentMonth % 12 === 0) {
443
$foodStory .= "\nA new year begins.\n";
444
445
foreach ($this->kobolds as $kobold) {
446
if ($kobold->getAge() >= 0) {
447
$kobold->incrementAge();
448
449
// Check for old-age injuries
450
if ($kobold->getAge() >= 35 && $this->shouldAddOldAgeInjury($kobold)) {
451
$oldAgeInjuries = ['bad_back', 'bad_liver', 'poor_eyesight', 'dementia'];
452
$injury = $oldAgeInjuries[array_rand($oldAgeInjuries)];
453
$kobold->addInjury($injury, 'old-age', 1);
454
}
455
456
// Old-age death roll: if roll < (age + total injury severity), kobold dies
457
if ($kobold->getAge() >= 35) {
458
$roll = rand(1, 100);
459
$totalSeverity = $kobold->getTotalInjurySeverity();
460
if ($roll < ($kobold->getAge() + $totalSeverity)) {
461
$kobold->die();
462
}
463
}
464
465
$kobold->save();
466
}
467
}
468
}
434
469
$foodStory .= "\nIt's {$this->currentSeason}.\n";
435
470
436
471
$this->save();
@@ -340,14 +340,14 @@ class Tribe340
340
341
// Add malnourished injury if not already present341
// Add malnourished injury if not already present342
if (!$this->hasInjuryCategory($kobold, 'malnourished')) {342
if (!$this->hasInjuryCategory($kobold, 'malnourished')) {343
$kobold->addInjury('malnourished', 'malnourished', 1);343
$kobold->addInjury('malnourished');344
$story .= "{$kobold->getName()} went hungry and became malnourished.\n";344
$story .= "{$kobold->getName()} went hungry and became malnourished.\n";345
} else {345
} else {346
// Already malnourished - becomes more severe346
// Already malnourished - becomes more severe347
$injuries = $kobold->getInjuries();347
$injuries = $kobold->getInjuries();348
foreach ($injuries as $injury) {348
foreach ($injuries as $injury) {349
if ($injury['category'] === 'malnourished') {349
if ($injury['category'] === 'malnourished') {350
// Could increase severity or add another injury350
$injury['severity']++;351
$story .= "{$kobold->getName()} remained hungry and suffered.\n";351
$story .= "{$kobold->getName()} remained hungry and suffered.\n";352
break;352
break;353
}353
}@@ -403,15 +403,21 @@ class Tribe403
$this->currentSeason = $seasons[$index];403
$this->currentSeason = $seasons[$index];404
// Random month events happen here (handled by EventManager in API)404
// Random month events happen here (handled by EventManager in API)405
// After events, consume food405
// After events, consume food406
$foodStory = $this->consumeFood();407
406
408
// Age all kobolds409
if ($this->currentMonth % 12 === 0) {410
$foodStory .= "\nA new year begins.\n";411
407
412
foreach ($this->kobolds as $kobold) {408
409
// age eggs410
$foodStory = "A month passes...\n" . $this->consumeFood();411
$foodStory .= "\n";412
413
foreach ($this->kobolds as $kobold) {414
if ($kobold->getAge() < 0) {413
$kobold->incrementAge();415
$kobold->incrementAge();414
416
417
if ($kobold->getAge() >= 0) {418
$foodStory .= "An egg hatched! {$kobold->getName()} was born.\n";419
}420
415
// Check for old-age injuries421
// Check for old-age injuries416
if ($kobold->getAge() >= 35 && $this->shouldAddOldAgeInjury($kobold)) {422
if ($kobold->getAge() >= 35 && $this->shouldAddOldAgeInjury($kobold)) {417
$oldAgeInjuries = ['bad_back', 'bad_liver', 'poor_eyesight', 'dementia'];423
$oldAgeInjuries = ['bad_back', 'bad_liver', 'poor_eyesight', 'dementia'];@@ -431,6 +437,35 @@ class Tribe431
$kobold->save();437
$kobold->save();432
}438
}433
}439
}440
441
// Age all kobolds442
if ($this->currentMonth % 12 === 0) {443
$foodStory .= "\nA new year begins.\n";444
445
foreach ($this->kobolds as $kobold) {446
if ($kobold->getAge() >= 0) {447
$kobold->incrementAge();448
449
// Check for old-age injuries450
if ($kobold->getAge() >= 35 && $this->shouldAddOldAgeInjury($kobold)) {451
$oldAgeInjuries = ['bad_back', 'bad_liver', 'poor_eyesight', 'dementia'];452
$injury = $oldAgeInjuries[array_rand($oldAgeInjuries)];453
$kobold->addInjury($injury, 'old-age', 1);454
}455
456
// Old-age death roll: if roll < (age + total injury severity), kobold dies457
if ($kobold->getAge() >= 35) {458
$roll = rand(1, 100);459
$totalSeverity = $kobold->getTotalInjurySeverity();460
if ($roll < ($kobold->getAge() + $totalSeverity)) {461
$kobold->die();462
}463
}464
465
$kobold->save();466
}467
}468
}434
$foodStory .= "\nIt's {$this->currentSeason}.\n";469
$foodStory .= "\nIt's {$this->currentSeason}.\n";435
470
436
$this->save();471
$this->save();@@ -2,6 +2,7 @@
2
2
3
3
require_once __DIR__ . '/../../src/Events/Event.php';
4
4
require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
5
require_once __DIR__ . '/../../src/Classes/Kobold.php';
5
6
6
7
class ExplorationEvent extends Event
7
8
{
@@ -92,6 +93,13 @@ class ExplorationEvent extends Event
92
93
$this->story .= "{$bestKobold->getName()} finds a stick suitable to be a splint, but it breaks as {$bestKobold->he()} tries to craft it.\n";
93
94
}
94
95
}
96
97
$eggFound = rand(1, 100) <= 3;
98
if ($eggFound) {
99
$this->tribe->addKobold(Kobold::generate($this->tribe->getUserId(), $this->tribe->getSaveId(), rand(-6, -1)));
100
$this->story .= "The party finds a lost Kobold egg... What might be inside?\n";
101
}
102
95
103
$this->story .= "\nThe exploration party returned to the tribe with their findings.";
96
104
97
105
return $this->story;
@@ -2,6 +2,7 @@2
2
3
require_once __DIR__ . '/../../src/Events/Event.php';3
require_once __DIR__ . '/../../src/Events/Event.php';4
require_once __DIR__ . '/../../src/Utilities/GameHelper.php';4
require_once __DIR__ . '/../../src/Utilities/GameHelper.php';5
require_once __DIR__ . '/../../src/Classes/Kobold.php';5
6
6
class ExplorationEvent extends Event7
class ExplorationEvent extends Event7
{8
{@@ -92,6 +93,13 @@ class ExplorationEvent extends Event92
$this->story .= "{$bestKobold->getName()} finds a stick suitable to be a splint, but it breaks as {$bestKobold->he()} tries to craft it.\n";93
$this->story .= "{$bestKobold->getName()} finds a stick suitable to be a splint, but it breaks as {$bestKobold->he()} tries to craft it.\n";93
}94
}94
}95
}96
97
$eggFound = rand(1, 100) <= 3;98
if ($eggFound) {99
$this->tribe->addKobold(Kobold::generate($this->tribe->getUserId(), $this->tribe->getSaveId(), rand(-6, -1)));100
$this->story .= "The party finds a lost Kobold egg... What might be inside?\n";101
}102
95
$this->story .= "\nThe exploration party returned to the tribe with their findings.";103
$this->story .= "\nThe exploration party returned to the tribe with their findings.";96
104
97
return $this->story;105
return $this->story;@@ -37,7 +37,7 @@ if ($method === 'POST') {
37
37
38
38
$kobolds[] = [
39
39
'id' => $kobold->getId(),
40
'name' => $kobold->getName(),
40
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",
41
41
'ageCategory' => $kobold->getAgeCategory(),
42
42
'age' => $kobold->getAge(),
43
43
'stats' => [
@@ -329,8 +329,12 @@ if ($method === 'POST') {
329
329
330
330
$tribe = Tribe::load($userId, $saveId);
331
331
332
$i = array_keys($tribe->kobolds)[$input['memberIndices'][0]];
332
$leaderI = intval($input['leaderId']) ?? 0;
333
334
$keys = array_keys($tribe->kobolds);
335
$i = $keys[$leaderI];
333
336
$tribe->kobolds[$i]->setName($input['leaderName']);
337
$tribe->kobolds[$i]->setLeader();
334
338
335
339
for ($i = 0; $i < count($input['memberIndices']); $i++) {
336
340
$input['memberIndices'][$i] = array_keys($tribe->kobolds)[$input['memberIndices'][$i]];
@@ -519,7 +523,7 @@ if ($method === 'POST') {
519
523
520
524
$kobolds[] = [
521
525
'id' => $kobold->getId(),
522
'name' => $kobold->getName(),
526
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",
523
527
'age' => $kobold->getAge(),
524
528
'ageCategory' => $kobold->getAgeCategory(),
525
529
'stats' => [
@@ -37,7 +37,7 @@ if ($method === 'POST') {37
37
38
$kobolds[] = [38
$kobolds[] = [39
'id' => $kobold->getId(),39
'id' => $kobold->getId(),40
'name' => $kobold->getName(),40
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",41
'ageCategory' => $kobold->getAgeCategory(),41
'ageCategory' => $kobold->getAgeCategory(),42
'age' => $kobold->getAge(),42
'age' => $kobold->getAge(),43
'stats' => [43
'stats' => [@@ -329,8 +329,12 @@ if ($method === 'POST') {329
329
330
$tribe = Tribe::load($userId, $saveId);330
$tribe = Tribe::load($userId, $saveId);331
331
332
$i = array_keys($tribe->kobolds)[$input['memberIndices'][0]];332
$leaderI = intval($input['leaderId']) ?? 0;333
334
$keys = array_keys($tribe->kobolds);335
$i = $keys[$leaderI];333
$tribe->kobolds[$i]->setName($input['leaderName']);336
$tribe->kobolds[$i]->setName($input['leaderName']);337
$tribe->kobolds[$i]->setLeader();334
338
335
for ($i = 0; $i < count($input['memberIndices']); $i++) {339
for ($i = 0; $i < count($input['memberIndices']); $i++) {336
$input['memberIndices'][$i] = array_keys($tribe->kobolds)[$input['memberIndices'][$i]];340
$input['memberIndices'][$i] = array_keys($tribe->kobolds)[$input['memberIndices'][$i]];@@ -519,7 +523,7 @@ if ($method === 'POST') {519
523
520
$kobolds[] = [524
$kobolds[] = [521
'id' => $kobold->getId(),525
'id' => $kobold->getId(),522
'name' => $kobold->getName(),526
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",523
'age' => $kobold->getAge(),527
'age' => $kobold->getAge(),524
'ageCategory' => $kobold->getAgeCategory(),528
'ageCategory' => $kobold->getAgeCategory(),525
'stats' => [529
'stats' => [