BlueGit

blue-star tribegen

title data

timfa Tim Falken · pushed by timfa

Authored 2026-02-05 · 9 months ago

Hash
1ff1ef258a8cade69006f7deda256ac34513e883
Parent
5aa479ef
2 files changed +93 −0
web/src/Classes/Kobold.php +54 −0
@@ -41,6 +41,60 @@ class Kobold
41 41 'fighting'
42 42 ];
43 43
44 private static $statTitles = [
45 'vitality' => 'Pathfinder',
46 'intelligence' => 'Lorekeeper',
47 'medicine' => 'Healer',
48 'crafting' => 'Tinkerer',
49 'personality' => 'Speaker',
50 'will' => 'Warden',
51 'fighting' => 'Warrior'
52 ];
53
54 public function getTitle($hasSecondary = true)
55 {
56 $rankedStats = [];
57
58 foreach (self::$statNames as $statName) {
59 $rankedStats[$statName] = (int) ($this->stats[$statName] ?? 0);
60 }
61
62 arsort($rankedStats);
63 $statKeys = array_keys($rankedStats);
64
65 $topStat = $statKeys[0] ?? null;
66 if ($topStat === null) {
67 return '';
68 }
69
70 $topTitle = self::$statTitles[$topStat] ?? '';
71
72 if (($topTitle === 'Warrior' || $topTitle === 'Pathfinder') && $hasSecondary) {
73 $secondStat = $statKeys[1] ?? null;
74 $secondTitle = $secondStat !== null ? (self::$statTitles[$secondStat] ?? '') : '';
75
76 if ($secondTitle !== '') {
77 return trim($topTitle . ' ' . $secondTitle);
78 }
79 }
80
81 return $topTitle;
82 }
83
84 public function getHighestStatName()
85 {
86 $rankedStats = [];
87
88 foreach (self::$statNames as $statName) {
89 $rankedStats[$statName] = (int) ($this->stats[$statName] ?? 0);
90 }
91
92 arsort($rankedStats);
93 $statKeys = array_keys($rankedStats);
94
95 return $statKeys[0] ?? null;
96 }
97
44 98 public function __construct($id, $userId, $saveId, $name, $age, $spriteMorph, $isLeader = false)
45 99 {
46 100 $this->id = $id;
@@ -41,6 +41,60 @@ class Kobold
41 'fighting'
41 'fighting'
42 ];
42 ];
43
43
44 private static $statTitles = [
45 'vitality' => 'Pathfinder',
46 'intelligence' => 'Lorekeeper',
47 'medicine' => 'Healer',
48 'crafting' => 'Tinkerer',
49 'personality' => 'Speaker',
50 'will' => 'Warden',
51 'fighting' => 'Warrior'
52 ];
53
54 public function getTitle($hasSecondary = true)
55 {
56 $rankedStats = [];
57
58 foreach (self::$statNames as $statName) {
59 $rankedStats[$statName] = (int) ($this->stats[$statName] ?? 0);
60 }
61
62 arsort($rankedStats);
63 $statKeys = array_keys($rankedStats);
64
65 $topStat = $statKeys[0] ?? null;
66 if ($topStat === null) {
67 return '';
68 }
69
70 $topTitle = self::$statTitles[$topStat] ?? '';
71
72 if (($topTitle === 'Warrior' || $topTitle === 'Pathfinder') && $hasSecondary) {
73 $secondStat = $statKeys[1] ?? null;
74 $secondTitle = $secondStat !== null ? (self::$statTitles[$secondStat] ?? '') : '';
75
76 if ($secondTitle !== '') {
77 return trim($topTitle . ' ' . $secondTitle);
78 }
79 }
80
81 return $topTitle;
82 }
83
84 public function getHighestStatName()
85 {
86 $rankedStats = [];
87
88 foreach (self::$statNames as $statName) {
89 $rankedStats[$statName] = (int) ($this->stats[$statName] ?? 0);
90 }
91
92 arsort($rankedStats);
93 $statKeys = array_keys($rankedStats);
94
95 return $statKeys[0] ?? null;
96 }
97
44 public function __construct($id, $userId, $saveId, $name, $age, $spriteMorph, $isLeader = false)
98 public function __construct($id, $userId, $saveId, $name, $age, $spriteMorph, $isLeader = false)
45 {
99 {
46 $this->id = $id;
100 $this->id = $id;
web/src/Classes/Tribe.php +39 −0
@@ -108,6 +108,45 @@ class Tribe
108 108 }
109 109 }
110 110
111 public function isBestInTribeForStat($kobold, $statName)
112 {
113 if (!$kobold instanceof Kobold) {
114 return false;
115 }
116
117 $targetStat = $kobold->getStat($statName);
118 if ($targetStat === null) {
119 return false;
120 }
121
122 $bestStat = $targetStat;
123 foreach ($this->getKobolds() as $otherKobold) {
124 if ($otherKobold->getId() === $kobold->getId()) {
125 continue;
126 }
127
128 $otherStat = $otherKobold->getStat($statName);
129 if ($otherStat !== null && $otherStat > $bestStat) {
130 return false;
131 }
132 }
133
134 return true;
135 }
136
137 public function getKoboldTitle($kobold)
138 {
139 if (!$kobold instanceof Kobold) {
140 return false;
141 }
142
143 if ($this->isBestInTribeForStat($kobold, $kobold->getHighestStatName())) {
144 return "Chief " . $kobold->getTitle(false);
145 }
146
147 return $kobold->getTitle();
148 }
149
111 150 private function loadStorage()
112 151 {
113 152 $savePath = $this->saveManager->getSavePath($this->userId, $this->saveId);
@@ -108,6 +108,45 @@ class Tribe
108 }
108 }
109 }
109 }
110
110
111 public function isBestInTribeForStat($kobold, $statName)
112 {
113 if (!$kobold instanceof Kobold) {
114 return false;
115 }
116
117 $targetStat = $kobold->getStat($statName);
118 if ($targetStat === null) {
119 return false;
120 }
121
122 $bestStat = $targetStat;
123 foreach ($this->getKobolds() as $otherKobold) {
124 if ($otherKobold->getId() === $kobold->getId()) {
125 continue;
126 }
127
128 $otherStat = $otherKobold->getStat($statName);
129 if ($otherStat !== null && $otherStat > $bestStat) {
130 return false;
131 }
132 }
133
134 return true;
135 }
136
137 public function getKoboldTitle($kobold)
138 {
139 if (!$kobold instanceof Kobold) {
140 return false;
141 }
142
143 if ($this->isBestInTribeForStat($kobold, $kobold->getHighestStatName())) {
144 return "Chief " . $kobold->getTitle(false);
145 }
146
147 return $kobold->getTitle();
148 }
149
111 private function loadStorage()
150 private function loadStorage()
112 {
151 {
113 $savePath = $this->saveManager->getSavePath($this->userId, $this->saveId);
152 $savePath = $this->saveManager->getSavePath($this->userId, $this->saveId);