fiks
@@ -2,7 +2,7 @@ var doneTyping = true;
2
2
// Main Game App
3
3
class TribeGenApp
4
4
{
5
constructor()
5
constructor ()
6
6
{
7
7
this.currentUser = null;
8
8
this.currentSave = null;
@@ -631,6 +631,7 @@ class TribeGenApp
631
631
{
632
632
this.currentSave = data.save;
633
633
this.currentTribe = data.tribe;
634
this.cleanupLikes();
634
635
await this.ensureEnvironmentsLoaded();
635
636
await this.fetchAvailableEvents();
636
637
this.showGameScreen();
@@ -1616,6 +1617,57 @@ class TribeGenApp
1616
1617
return { text: 'wonderful', color: '#27ae60' };
1617
1618
}
1618
1619
1620
cleanupLikes ()
1621
{
1622
if (!this.currentTribe || !Array.isArray(this.currentTribe.kobolds))
1623
{
1624
return;
1625
}
1626
1627
const koboldIds = new Set(
1628
this.currentTribe.kobolds
1629
.map(k => k?.id)
1630
.filter(id => typeof id === 'string' && id.length > 0)
1631
);
1632
1633
const rivalList = Array.isArray(this.currentSave?.rivals)
1634
? this.currentSave.rivals
1635
: Object.values(this.currentSave?.rivals || {});
1636
1637
const rivalIds = new Set(
1638
rivalList
1639
.map(r => r?.id)
1640
.filter(id => typeof id === 'string' && id.length > 0)
1641
);
1642
1643
this.currentTribe.kobolds.forEach(kobold =>
1644
{
1645
const likes = kobold?.likes;
1646
if (!likes || typeof likes !== 'object')
1647
{
1648
kobold.likes = {};
1649
return;
1650
}
1651
1652
if (Array.isArray(likes))
1653
{
1654
kobold.likes = {};
1655
return;
1656
}
1657
1658
const cleaned = {};
1659
Object.entries(likes).forEach(([targetId, value]) =>
1660
{
1661
if (koboldIds.has(targetId) || rivalIds.has(targetId))
1662
{
1663
cleaned[targetId] = value;
1664
}
1665
});
1666
1667
kobold.likes = cleaned;
1668
});
1669
}
1670
1619
1671
renderKoboldRelationships (kobold)
1620
1672
{
1621
1673
const container = document.getElementById('koboldRelationships');
@@ -1639,8 +1691,10 @@ class TribeGenApp
1639
1691
} else
1640
1692
{
1641
1693
// Check if it's a rival
1642
const rivalData = this.currentSave?.rivals || [];
1643
const rival = rivalData.find(r => r.id === targetId);
1694
const rivalData = Array.isArray(this.currentSave?.rivals)
1695
? this.currentSave.rivals
1696
: Object.values(this.currentSave?.rivals || {});
1697
const rival = rivalData.find(r => r?.id === targetId);
1644
1698
if (rival)
1645
1699
{
1646
1700
rivals.push({ id: targetId, name: rival.name, likeValue });
@@ -2,7 +2,7 @@ var doneTyping = true;2
// Main Game App2
// Main Game App3
class TribeGenApp3
class TribeGenApp4
{4
{5
constructor()5
constructor ()6
{6
{7
this.currentUser = null;7
this.currentUser = null;8
this.currentSave = null;8
this.currentSave = null;@@ -631,6 +631,7 @@ class TribeGenApp631
{631
{632
this.currentSave = data.save;632
this.currentSave = data.save;633
this.currentTribe = data.tribe;633
this.currentTribe = data.tribe;634
this.cleanupLikes();634
await this.ensureEnvironmentsLoaded();635
await this.ensureEnvironmentsLoaded();635
await this.fetchAvailableEvents();636
await this.fetchAvailableEvents();636
this.showGameScreen();637
this.showGameScreen();@@ -1616,6 +1617,57 @@ class TribeGenApp1616
return { text: 'wonderful', color: '#27ae60' };1617
return { text: 'wonderful', color: '#27ae60' };1617
}1618
}1618
1619
1620
cleanupLikes ()1621
{1622
if (!this.currentTribe || !Array.isArray(this.currentTribe.kobolds))1623
{1624
return;1625
}1626
1627
const koboldIds = new Set(1628
this.currentTribe.kobolds1629
.map(k => k?.id)1630
.filter(id => typeof id === 'string' && id.length > 0)1631
);1632
1633
const rivalList = Array.isArray(this.currentSave?.rivals)1634
? this.currentSave.rivals1635
: Object.values(this.currentSave?.rivals || {});1636
1637
const rivalIds = new Set(1638
rivalList1639
.map(r => r?.id)1640
.filter(id => typeof id === 'string' && id.length > 0)1641
);1642
1643
this.currentTribe.kobolds.forEach(kobold =>1644
{1645
const likes = kobold?.likes;1646
if (!likes || typeof likes !== 'object')1647
{1648
kobold.likes = {};1649
return;1650
}1651
1652
if (Array.isArray(likes))1653
{1654
kobold.likes = {};1655
return;1656
}1657
1658
const cleaned = {};1659
Object.entries(likes).forEach(([targetId, value]) =>1660
{1661
if (koboldIds.has(targetId) || rivalIds.has(targetId))1662
{1663
cleaned[targetId] = value;1664
}1665
});1666
1667
kobold.likes = cleaned;1668
});1669
}1670
1619
renderKoboldRelationships (kobold)1671
renderKoboldRelationships (kobold)1620
{1672
{1621
const container = document.getElementById('koboldRelationships');1673
const container = document.getElementById('koboldRelationships');@@ -1639,8 +1691,10 @@ class TribeGenApp1639
} else1691
} else1640
{1692
{1641
// Check if it's a rival1693
// Check if it's a rival1642
const rivalData = this.currentSave?.rivals || [];1694
const rivalData = Array.isArray(this.currentSave?.rivals)1643
const rival = rivalData.find(r => r.id === targetId);1695
? this.currentSave.rivals1696
: Object.values(this.currentSave?.rivals || {});1697
const rival = rivalData.find(r => r?.id === targetId);1644
if (rival)1698
if (rival)1645
{1699
{1646
rivals.push({ id: targetId, name: rival.name, likeValue });1700
rivals.push({ id: targetId, name: rival.name, likeValue });@@ -229,7 +229,7 @@ class Kobold
229
229
230
230
$kobold->isAlive = $data['is_alive'] ?? true;
231
231
$kobold->isExpelled = $data['is_expelled'] ?? false;
232
$kobold->injuries = $data['injuries'] ?? [];
232
$kobold->injuries = array_values($data['injuries'] ?? []);
233
233
$kobold->items = $data['items'] ?? [];
234
234
$kobold->fatigue = $data['fatigue'] ?? 0;
235
235
$kobold->fatherId = $data['father_id'] ?? null;
@@ -512,7 +512,7 @@ class Kobold
512
512
513
513
public function removeInjury($injuryId)
514
514
{
515
$this->injuries = array_filter($this->injuries, fn($inj) => $inj['id'] !== $injuryId);
515
$this->injuries = array_values(array_filter($this->injuries, fn($inj) => $inj['id'] !== $injuryId));
516
516
}
517
517
518
518
public function getInjuries()
@@ -229,7 +229,7 @@ class Kobold229
229
230
$kobold->isAlive = $data['is_alive'] ?? true;230
$kobold->isAlive = $data['is_alive'] ?? true;231
$kobold->isExpelled = $data['is_expelled'] ?? false;231
$kobold->isExpelled = $data['is_expelled'] ?? false;232
$kobold->injuries = $data['injuries'] ?? [];232
$kobold->injuries = array_values($data['injuries'] ?? []);233
$kobold->items = $data['items'] ?? [];233
$kobold->items = $data['items'] ?? [];234
$kobold->fatigue = $data['fatigue'] ?? 0;234
$kobold->fatigue = $data['fatigue'] ?? 0;235
$kobold->fatherId = $data['father_id'] ?? null;235
$kobold->fatherId = $data['father_id'] ?? null;@@ -512,7 +512,7 @@ class Kobold512
512
513
public function removeInjury($injuryId)513
public function removeInjury($injuryId)514
{514
{515
$this->injuries = array_filter($this->injuries, fn($inj) => $inj['id'] !== $injuryId);515
$this->injuries = array_values(array_filter($this->injuries, fn($inj) => $inj['id'] !== $injuryId));516
}516
}517
517
518
public function getInjuries()518
public function getInjuries()@@ -667,7 +667,7 @@ class Tribe
667
667
668
668
public function getEndOfMonthEvents(): array
669
669
{
670
$maxCost = 500;
670
$maxCost = 250;
671
671
$selectedEvents = [];
672
672
$totalCost = 0;
673
673
@@ -859,7 +859,6 @@ class Tribe
859
859
if ($monthEventStory) {
860
860
$foodStory = $monthEventStory . "\n" . $foodStory;
861
861
}
862
$foodStory .= "\n";
863
862
864
863
foreach ($this->kobolds as $kobold) {
865
864
if ($kobold->getAge() < 0) {
@@ -876,7 +875,7 @@ class Tribe
876
875
877
876
// Age all kobolds
878
877
if ($this->currentMonth % 12 === 0) {
879
$foodStory .= "\nA new year begins.\n";
878
$foodStory .= "A new year begins.\n";
880
879
881
880
foreach ($this->kobolds as $kobold) {
882
881
$foodStory .= $this->ageKobold($kobold);
@@ -667,7 +667,7 @@ class Tribe667
667
668
public function getEndOfMonthEvents(): array668
public function getEndOfMonthEvents(): array669
{669
{670
$maxCost = 500;670
$maxCost = 250;671
$selectedEvents = [];671
$selectedEvents = [];672
$totalCost = 0;672
$totalCost = 0;673
673
@@ -859,7 +859,6 @@ class Tribe859
if ($monthEventStory) {859
if ($monthEventStory) {860
$foodStory = $monthEventStory . "\n" . $foodStory;860
$foodStory = $monthEventStory . "\n" . $foodStory;861
}861
}862
$foodStory .= "\n";863
862
864
foreach ($this->kobolds as $kobold) {863
foreach ($this->kobolds as $kobold) {865
if ($kobold->getAge() < 0) {864
if ($kobold->getAge() < 0) {@@ -876,7 +875,7 @@ class Tribe876
875
877
// Age all kobolds876
// Age all kobolds878
if ($this->currentMonth % 12 === 0) {877
if ($this->currentMonth % 12 === 0) {879
$foodStory .= "\nA new year begins.\n";878
$foodStory .= "A new year begins.\n";880
879
881
foreach ($this->kobolds as $kobold) {880
foreach ($this->kobolds as $kobold) {882
$foodStory .= $this->ageKobold($kobold);881
$foodStory .= $this->ageKobold($kobold);@@ -597,41 +597,8 @@ if ($method === 'POST') {
597
597
$tribe = Tribe::load($userId, $saveId);
598
598
599
599
// Get kobolds with full stats, items and injuries
600
$kobolds = [];
601
foreach ($tribe->getKobolds() as $kobold) {
602
$kInjuries = $kobold->getInjuries() ?? [];
603
// enrich injuries with required medicine mapping
604
foreach ($kInjuries as &$inj) {
605
$req = null;
606
if (class_exists('Injury')) {
607
$req = Injury::getCureForCategory($inj['category'] ?? null);
608
}
609
$inj['required_medicine'] = $req;
610
}
611
612
$kobolds[] = [
613
'id' => $kobold->getId(),
614
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",
615
'age' => $kobold->getAge(),
616
'ageCategory' => $kobold->getAgeCategory(),
617
'stats' => [
618
'vitality' => $kobold->getStat('vitality'),
619
'intelligence' => $kobold->getStat('intelligence'),
620
'medicine' => $kobold->getStat('medicine'),
621
'crafting' => $kobold->getStat('crafting'),
622
'personality' => $kobold->getStat('personality'),
623
'will' => $kobold->getStat('will'),
624
'fighting' => $kobold->getStat('fighting')
625
],
626
'fatigue' => $kobold->getFatigue(),
627
'fatigue_label' => $kobold->getFatigueLabel(),
628
'items' => $kobold->getItems() ?? [],
629
'injuries' => $kInjuries,
630
'is_leader' => $kobold->isLeader(),
631
'male' => $kobold->getMale(),
632
'likes' => isset($kobold->likes) && is_array($kobold->likes) ? $kobold->likes : []
633
];
634
}
600
$kobolds = getKobolds($tribe, true);
601
$rivals = getKobolds($tribe, false);
635
602
636
603
// Get storage items
637
604
$storage = $tribe->getStorage();
@@ -648,7 +615,7 @@ if ($method === 'POST') {
648
615
'food_time_remaining' => $tribe->foodTimeStr($tribe->getFoodCount()),
649
616
'created_at' => $tribe->getCreatedAt(),
650
617
'last_played' => $tribe->getLastPlayed(),
651
'rivals' => isset($tribe->rivals) ? $tribe->rivals : []
618
'rivals' => $rivals
652
619
],
653
620
'tribe' => [
654
621
'kobolds' => $kobolds,
@@ -712,3 +679,46 @@ if ($method === 'POST') {
712
679
}
713
680
}
714
681
682
function getKobolds($tribe, $tribeMembers): array
683
{
684
$kobolds = [];
685
foreach ($tribe->getKobolds(!$tribeMembers) as $kobold) {
686
$kInjuries = $kobold->getInjuries() ?? [];
687
// enrich injuries with required medicine mapping
688
foreach ($kInjuries as &$inj) {
689
$req = null;
690
if (class_exists('Injury')) {
691
$req = Injury::getCureForCategory($inj['category'] ?? null);
692
}
693
$inj['required_medicine'] = $req;
694
}
695
696
$kobolds[] = [
697
'id' => $kobold->getId(),
698
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",
699
'age' => $kobold->getAge(),
700
'ageCategory' => $kobold->getAgeCategory(),
701
'stats' => [
702
'vitality' => $kobold->getStat('vitality'),
703
'intelligence' => $kobold->getStat('intelligence'),
704
'medicine' => $kobold->getStat('medicine'),
705
'crafting' => $kobold->getStat('crafting'),
706
'personality' => $kobold->getStat('personality'),
707
'will' => $kobold->getStat('will'),
708
'fighting' => $kobold->getStat('fighting')
709
],
710
'fatigue' => $kobold->getFatigue(),
711
'fatigue_label' => $kobold->getFatigueLabel(),
712
'items' => $kobold->getItems() ?? [],
713
'injuries' => $kInjuries,
714
'is_leader' => $kobold->isLeader(),
715
'male' => $kobold->getMale(),
716
'likes' => isset($kobold->dataStore) && $kobold->dataStore instanceof stdClass
717
&& isset($kobold->dataStore->likes) && is_array($kobold->dataStore->likes)
718
? $kobold->dataStore->likes
719
: []
720
];
721
}
722
723
return $kobolds;
724
}
@@ -597,41 +597,8 @@ if ($method === 'POST') {597
$tribe = Tribe::load($userId, $saveId);597
$tribe = Tribe::load($userId, $saveId);598
598
599
// Get kobolds with full stats, items and injuries599
// Get kobolds with full stats, items and injuries600
$kobolds = [];600
$kobolds = getKobolds($tribe, true);601
foreach ($tribe->getKobolds() as $kobold) {601
$rivals = getKobolds($tribe, false);602
$kInjuries = $kobold->getInjuries() ?? [];603
// enrich injuries with required medicine mapping604
foreach ($kInjuries as &$inj) {605
$req = null;606
if (class_exists('Injury')) {607
$req = Injury::getCureForCategory($inj['category'] ?? null);608
}609
$inj['required_medicine'] = $req;610
}611
612
$kobolds[] = [613
'id' => $kobold->getId(),614
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",615
'age' => $kobold->getAge(),616
'ageCategory' => $kobold->getAgeCategory(),617
'stats' => [618
'vitality' => $kobold->getStat('vitality'),619
'intelligence' => $kobold->getStat('intelligence'),620
'medicine' => $kobold->getStat('medicine'),621
'crafting' => $kobold->getStat('crafting'),622
'personality' => $kobold->getStat('personality'),623
'will' => $kobold->getStat('will'),624
'fighting' => $kobold->getStat('fighting')625
],626
'fatigue' => $kobold->getFatigue(),627
'fatigue_label' => $kobold->getFatigueLabel(),628
'items' => $kobold->getItems() ?? [],629
'injuries' => $kInjuries,630
'is_leader' => $kobold->isLeader(),631
'male' => $kobold->getMale(),632
'likes' => isset($kobold->likes) && is_array($kobold->likes) ? $kobold->likes : []633
];634
}635
602
636
// Get storage items603
// Get storage items637
$storage = $tribe->getStorage();604
$storage = $tribe->getStorage();@@ -648,7 +615,7 @@ if ($method === 'POST') {648
'food_time_remaining' => $tribe->foodTimeStr($tribe->getFoodCount()),615
'food_time_remaining' => $tribe->foodTimeStr($tribe->getFoodCount()),649
'created_at' => $tribe->getCreatedAt(),616
'created_at' => $tribe->getCreatedAt(),650
'last_played' => $tribe->getLastPlayed(),617
'last_played' => $tribe->getLastPlayed(),651
'rivals' => isset($tribe->rivals) ? $tribe->rivals : []618
'rivals' => $rivals652
],619
],653
'tribe' => [620
'tribe' => [654
'kobolds' => $kobolds,621
'kobolds' => $kobolds,@@ -712,3 +679,46 @@ if ($method === 'POST') {712
}679
}713
}680
}714
681
682
function getKobolds($tribe, $tribeMembers): array683
{684
$kobolds = [];685
foreach ($tribe->getKobolds(!$tribeMembers) as $kobold) {686
$kInjuries = $kobold->getInjuries() ?? [];687
// enrich injuries with required medicine mapping688
foreach ($kInjuries as &$inj) {689
$req = null;690
if (class_exists('Injury')) {691
$req = Injury::getCureForCategory($inj['category'] ?? null);692
}693
$inj['required_medicine'] = $req;694
}695
696
$kobolds[] = [697
'id' => $kobold->getId(),698
'name' => $kobold->getAgeCategory() !== "egg" ? $kobold->getName() : "Egg",699
'age' => $kobold->getAge(),700
'ageCategory' => $kobold->getAgeCategory(),701
'stats' => [702
'vitality' => $kobold->getStat('vitality'),703
'intelligence' => $kobold->getStat('intelligence'),704
'medicine' => $kobold->getStat('medicine'),705
'crafting' => $kobold->getStat('crafting'),706
'personality' => $kobold->getStat('personality'),707
'will' => $kobold->getStat('will'),708
'fighting' => $kobold->getStat('fighting')709
],710
'fatigue' => $kobold->getFatigue(),711
'fatigue_label' => $kobold->getFatigueLabel(),712
'items' => $kobold->getItems() ?? [],713
'injuries' => $kInjuries,714
'is_leader' => $kobold->isLeader(),715
'male' => $kobold->getMale(),716
'likes' => isset($kobold->dataStore) && $kobold->dataStore instanceof stdClass717
&& isset($kobold->dataStore->likes) && is_array($kobold->dataStore->likes)718
? $kobold->dataStore->likes719
: []720
];721
}722
723
return $kobolds;724
}