BlueGit

blue-star tribegen

statcheck for personality that factors likes/dislikes.

also simple social event that'll repeat a bunch of times because it's the only one we have

timfa Tim Falken · pushed by timfa

Authored 2026-02-03 · 9 months ago

Hash
e2c972c8145a3f094df656cdda0e5a2e88cdcdfe
Parent
edf7d060
6 files changed +380 −6
web/src/Classes/Kobold.php +25 −3
@@ -27,6 +27,7 @@ class Kobold
27 27 private $colourTertiary;
28 28
29 29 private $male;
30 public $dataStore;
30 31
31 32 private static $statNames = [
32 33 'vitality',
@@ -234,6 +235,11 @@ class Kobold
234 235 $kobold->colourPrimary = $data['colour_primary'] ?? '#FFFFFF';
235 236 $kobold->colourSecondary = $data['colour_secondary'] ?? '#FFFFFF';
236 237 $kobold->colourTertiary = $data['colour_tertiary'] ?? '#FFFFFF';
238 $kobold->dataStore = $data['data_store'] ?? new stdClass();
239
240 if (is_array($kobold->dataStore)) {
241 $kobold->dataStore = (object) $kobold->dataStore;
242 }
237 243
238 244 return $kobold;
239 245 }
@@ -259,7 +265,8 @@ class Kobold
259 265 'colour_primary' => $this->colourPrimary,
260 266 'colour_secondary' => $this->colourSecondary,
261 267 'colour_tertiary' => $this->colourTertiary,
262 'male' => $this->male
268 'male' => $this->male,
269 'data_store' => $this->dataStore ?? new stdClass()
263 270 ];
264 271 }
265 272
@@ -410,7 +417,7 @@ class Kobold
410 417 }
411 418 }
412 419
413 public function checkStat($statName)
420 public function checkStat($statName, $bonus = 0)
414 421 {
415 422 $stat = $this->getStat($statName);
416 423
@@ -454,10 +461,25 @@ class Kobold
454 461 $stat = max(0, min(100, $stat));
455 462
456 463 // Roll under 1d100
457 $roll = rand(1, 100);
464 $roll = min(100, rand(1, 100) + $bonus);
458 465 return $roll <= $stat;
459 466 }
460 467
468 public function checkPersonality(Kobold $otherKobold)
469 {
470 // Get the like value that otherKobold has for this kobold
471 $bonus = 0;
472
473 if (isset($otherKobold->dataStore) && $otherKobold->dataStore instanceof stdClass) {
474 if (isset($otherKobold->dataStore->likes) && is_array($otherKobold->dataStore->likes)) {
475 $bonus = $otherKobold->dataStore->likes[$this->getId()] ?? 0;
476 }
477 }
478
479 // Call checkStat with the like value as bonus
480 return $this->checkStat('personality', $bonus);
481 }
482
461 483 public function addInjury($injuryType)
462 484 {
463 485 // Reject duplicates
@@ -27,6 +27,7 @@ class Kobold
27 private $colourTertiary;
27 private $colourTertiary;
28
28
29 private $male;
29 private $male;
30 public $dataStore;
30
31
31 private static $statNames = [
32 private static $statNames = [
32 'vitality',
33 'vitality',
@@ -234,6 +235,11 @@ class Kobold
234 $kobold->colourPrimary = $data['colour_primary'] ?? '#FFFFFF';
235 $kobold->colourPrimary = $data['colour_primary'] ?? '#FFFFFF';
235 $kobold->colourSecondary = $data['colour_secondary'] ?? '#FFFFFF';
236 $kobold->colourSecondary = $data['colour_secondary'] ?? '#FFFFFF';
236 $kobold->colourTertiary = $data['colour_tertiary'] ?? '#FFFFFF';
237 $kobold->colourTertiary = $data['colour_tertiary'] ?? '#FFFFFF';
238 $kobold->dataStore = $data['data_store'] ?? new stdClass();
239
240 if (is_array($kobold->dataStore)) {
241 $kobold->dataStore = (object) $kobold->dataStore;
242 }
237
243
238 return $kobold;
244 return $kobold;
239 }
245 }
@@ -259,7 +265,8 @@ class Kobold
259 'colour_primary' => $this->colourPrimary,
265 'colour_primary' => $this->colourPrimary,
260 'colour_secondary' => $this->colourSecondary,
266 'colour_secondary' => $this->colourSecondary,
261 'colour_tertiary' => $this->colourTertiary,
267 'colour_tertiary' => $this->colourTertiary,
262 'male' => $this->male
268 'male' => $this->male,
269 'data_store' => $this->dataStore ?? new stdClass()
263 ];
270 ];
264 }
271 }
265
272
@@ -410,7 +417,7 @@ class Kobold
410 }
417 }
411 }
418 }
412
419
413 public function checkStat($statName)
420 public function checkStat($statName, $bonus = 0)
414 {
421 {
415 $stat = $this->getStat($statName);
422 $stat = $this->getStat($statName);
416
423
@@ -454,10 +461,25 @@ class Kobold
454 $stat = max(0, min(100, $stat));
461 $stat = max(0, min(100, $stat));
455
462
456 // Roll under 1d100
463 // Roll under 1d100
457 $roll = rand(1, 100);
464 $roll = min(100, rand(1, 100) + $bonus);
458 return $roll <= $stat;
465 return $roll <= $stat;
459 }
466 }
460
467
468 public function checkPersonality(Kobold $otherKobold)
469 {
470 // Get the like value that otherKobold has for this kobold
471 $bonus = 0;
472
473 if (isset($otherKobold->dataStore) && $otherKobold->dataStore instanceof stdClass) {
474 if (isset($otherKobold->dataStore->likes) && is_array($otherKobold->dataStore->likes)) {
475 $bonus = $otherKobold->dataStore->likes[$this->getId()] ?? 0;
476 }
477 }
478
479 // Call checkStat with the like value as bonus
480 return $this->checkStat('personality', $bonus);
481 }
482
461 public function addInjury($injuryType)
483 public function addInjury($injuryType)
462 {
484 {
463 // Reject duplicates
485 // Reject duplicates
web/src/Classes/Tribe.php +152 −3
@@ -529,12 +529,42 @@ class Tribe
529 529
530 530 [$male, $female] = $pair;
531 531
532 if (!$male->checkStat('personality') || !$female->checkStat('personality')) {
532 if (!$male->checkPersonality($female) || !$female->checkPersonality($male)) {
533 533 return "{$male->getName()} and {$female->getName()} spent some time together this month, but didn't quite hit it off.";
534 534 }
535 535
536 536 $child = Kobold::generate($this->userId, $this->saveId, -6);
537 537
538 if (!isset($child->dataStore)) {
539 $child->dataStore = new stdClass();
540 }
541 if (!isset($child->dataStore->likes)) {
542 $child->dataStore->likes = [];
543 }
544
545 // Child likes parents by default
546 $child->dataStore->likes[$male->getId()] = 10;
547 $child->dataStore->likes[$female->getId()] = 10;
548
549 // Initialize parents' dataStore if needed
550 if (!isset($male->dataStore)) {
551 $male->dataStore = new stdClass();
552 }
553 if (!isset($male->dataStore->likes)) {
554 $male->dataStore->likes = [];
555 }
556
557 if (!isset($female->dataStore)) {
558 $female->dataStore = new stdClass();
559 }
560 if (!isset($female->dataStore->likes)) {
561 $female->dataStore->likes = [];
562 }
563
564 // Parents like the child by default
565 $male->dataStore->likes[$child->getId()] = 20;
566 $female->dataStore->likes[$child->getId()] = 20;
567
538 568 $inheritRoll = rand(1, 100);
539 569 if ($inheritRoll <= 40) {
540 570 $child->setSpriteMorph($male->getSpriteMorph());
@@ -609,6 +639,83 @@ class Tribe
609 639 return $variations[array_rand($variations)];
610 640 }
611 641
642 public function getEndOfMonthEvents(): array
643 {
644 $maxCost = 500;
645 $selectedEvents = [];
646 $totalCost = 0;
647
648 // Scan src/Events directory for event classes
649 $eventsDir = __DIR__ . '/../../src/Events/';
650 $eventFiles = glob($eventsDir . '*.php');
651 $availableEventClasses = [];
652
653 foreach ($eventFiles as $file) {
654 $className = basename($file, '.php');
655
656 // Skip base classes
657 if ($className === 'Event' || $className === 'MonthEndEvent') {
658 continue;
659 }
660
661 require_once $file;
662
663 // Check if class exists and extends MonthEndEvent
664 if (!class_exists($className)) {
665 continue;
666 }
667
668 // Create temporary instance to check conditions
669 $tempEvent = new $className($this);
670
671 // Check if it's an end-of-month event
672 if (!$tempEvent->isEndOfMonth()) {
673 continue;
674 }
675
676 // Check if event is available
677 if (!$tempEvent->isAvailable()) {
678 continue;
679 }
680
681 // Check if tribe has enough eligible kobolds
682 $minAge = $tempEvent->getMinAge();
683 $minParticipants = $tempEvent->getMinParticipants();
684
685 $eligibleKobolds = array_filter($this->getAliveKobolds(), function ($kobold) use ($minAge) {
686 return $kobold->getAge() >= $minAge;
687 });
688
689 if (count($eligibleKobolds) < $minParticipants) {
690 continue;
691 }
692
693 // This event is available
694 $availableEventClasses[] = $className;
695 }
696
697 // If no events available, return empty array
698 if (empty($availableEventClasses)) {
699 return [];
700 }
701
702 // Select events randomly until cost exceeds maxCost
703 while ($totalCost <= $maxCost && !empty($availableEventClasses)) {
704 // Pick a random event class
705 $randomClass = $availableEventClasses[array_rand($availableEventClasses)];
706
707 // Create new instance
708 $event = new $randomClass($this);
709 $eventCost = $event->getCost();
710
711 // Add to selection
712 $selectedEvents[] = $event;
713 $totalCost += $eventCost;
714 }
715
716 return $selectedEvents;
717 }
718
612 719 public function endMonth()
613 720 {
614 721 $this->currentMonth++;
@@ -679,11 +786,53 @@ class Tribe
679 786 $foodStory = $cropLossVariations[array_rand($cropLossVariations)];
680 787 }
681 788
682 // Random month events happen here
789 // Execute end-of-month events
790 $monthEventStory = '';
791 $endOfMonthEvents = $this->getEndOfMonthEvents();
792
793 foreach ($endOfMonthEvents as $event) {
794 // Select eligible participants
795 $eligible = array_filter($this->getAliveKobolds(), function ($kobold) use ($event) {
796 return $kobold->getAge() >= $event->getMinAge();
797 });
798
799 if (count($eligible) < $event->getMinParticipants()) {
800 continue;
801 }
802
803 // Randomly select participants (between min and max)
804 $eligible = array_values($eligible);
805 shuffle($eligible);
806 $participantCount = rand($event->getMinParticipants(), min($event->getMaxParticipants(), count($eligible)));
807 $participants = array_slice($eligible, 0, $participantCount);
808 $participantIds = array_map(fn($k) => $k->getId(), $participants);
809
810 // Set participants and execute event
811 $event->setParticipants($participantIds);
812 $event->execute();
813
814 // Add fatigue to participants
815 foreach ($participants as $participant) {
816 $participant->addFatigue($event->getCost());
817 if ($participant->isDead()) {
818 $monthEventStory .= $participant->getName() . " has died.\n";
819 }
820 $participant->save();
821 }
822
823 // Add event story
824 if ($event->getStory()) {
825 $monthEventStory .= $event->getStory() . "\n";
826 }
827 }
828
683 829 // After events, consume food
684 830
685 831 // age eggs
686 832 $foodStory = "A month passes...\n" . $this->consumeFood();
833 if ($monthEventStory) {
834 $foodStory = $monthEventStory . "\n" . $foodStory;
835 }
687 836 $foodStory .= "\n";
688 837
689 838 foreach ($this->kobolds as $kobold) {
@@ -733,7 +882,7 @@ class Tribe
733 882
734 883 foreach ($this->kobolds as $kobold) {
735 884 if ($kobold->isDead()) {
736 $foodStory = $foodStory . "\n" . $kobold->getName() . " has died.";
885 $foodStory = $foodStory . "\n" . $kobold->getName() . " has been buried.";
737 886 }
738 887 }
739 888
@@ -529,12 +529,42 @@ class Tribe
529
529
530 [$male, $female] = $pair;
530 [$male, $female] = $pair;
531
531
532 if (!$male->checkStat('personality') || !$female->checkStat('personality')) {
532 if (!$male->checkPersonality($female) || !$female->checkPersonality($male)) {
533 return "{$male->getName()} and {$female->getName()} spent some time together this month, but didn't quite hit it off.";
533 return "{$male->getName()} and {$female->getName()} spent some time together this month, but didn't quite hit it off.";
534 }
534 }
535
535
536 $child = Kobold::generate($this->userId, $this->saveId, -6);
536 $child = Kobold::generate($this->userId, $this->saveId, -6);
537
537
538 if (!isset($child->dataStore)) {
539 $child->dataStore = new stdClass();
540 }
541 if (!isset($child->dataStore->likes)) {
542 $child->dataStore->likes = [];
543 }
544
545 // Child likes parents by default
546 $child->dataStore->likes[$male->getId()] = 10;
547 $child->dataStore->likes[$female->getId()] = 10;
548
549 // Initialize parents' dataStore if needed
550 if (!isset($male->dataStore)) {
551 $male->dataStore = new stdClass();
552 }
553 if (!isset($male->dataStore->likes)) {
554 $male->dataStore->likes = [];
555 }
556
557 if (!isset($female->dataStore)) {
558 $female->dataStore = new stdClass();
559 }
560 if (!isset($female->dataStore->likes)) {
561 $female->dataStore->likes = [];
562 }
563
564 // Parents like the child by default
565 $male->dataStore->likes[$child->getId()] = 20;
566 $female->dataStore->likes[$child->getId()] = 20;
567
538 $inheritRoll = rand(1, 100);
568 $inheritRoll = rand(1, 100);
539 if ($inheritRoll <= 40) {
569 if ($inheritRoll <= 40) {
540 $child->setSpriteMorph($male->getSpriteMorph());
570 $child->setSpriteMorph($male->getSpriteMorph());
@@ -609,6 +639,83 @@ class Tribe
609 return $variations[array_rand($variations)];
639 return $variations[array_rand($variations)];
610 }
640 }
611
641
642 public function getEndOfMonthEvents(): array
643 {
644 $maxCost = 500;
645 $selectedEvents = [];
646 $totalCost = 0;
647
648 // Scan src/Events directory for event classes
649 $eventsDir = __DIR__ . '/../../src/Events/';
650 $eventFiles = glob($eventsDir . '*.php');
651 $availableEventClasses = [];
652
653 foreach ($eventFiles as $file) {
654 $className = basename($file, '.php');
655
656 // Skip base classes
657 if ($className === 'Event' || $className === 'MonthEndEvent') {
658 continue;
659 }
660
661 require_once $file;
662
663 // Check if class exists and extends MonthEndEvent
664 if (!class_exists($className)) {
665 continue;
666 }
667
668 // Create temporary instance to check conditions
669 $tempEvent = new $className($this);
670
671 // Check if it's an end-of-month event
672 if (!$tempEvent->isEndOfMonth()) {
673 continue;
674 }
675
676 // Check if event is available
677 if (!$tempEvent->isAvailable()) {
678 continue;
679 }
680
681 // Check if tribe has enough eligible kobolds
682 $minAge = $tempEvent->getMinAge();
683 $minParticipants = $tempEvent->getMinParticipants();
684
685 $eligibleKobolds = array_filter($this->getAliveKobolds(), function ($kobold) use ($minAge) {
686 return $kobold->getAge() >= $minAge;
687 });
688
689 if (count($eligibleKobolds) < $minParticipants) {
690 continue;
691 }
692
693 // This event is available
694 $availableEventClasses[] = $className;
695 }
696
697 // If no events available, return empty array
698 if (empty($availableEventClasses)) {
699 return [];
700 }
701
702 // Select events randomly until cost exceeds maxCost
703 while ($totalCost <= $maxCost && !empty($availableEventClasses)) {
704 // Pick a random event class
705 $randomClass = $availableEventClasses[array_rand($availableEventClasses)];
706
707 // Create new instance
708 $event = new $randomClass($this);
709 $eventCost = $event->getCost();
710
711 // Add to selection
712 $selectedEvents[] = $event;
713 $totalCost += $eventCost;
714 }
715
716 return $selectedEvents;
717 }
718
612 public function endMonth()
719 public function endMonth()
613 {
720 {
614 $this->currentMonth++;
721 $this->currentMonth++;
@@ -679,11 +786,53 @@ class Tribe
679 $foodStory = $cropLossVariations[array_rand($cropLossVariations)];
786 $foodStory = $cropLossVariations[array_rand($cropLossVariations)];
680 }
787 }
681
788
682 // Random month events happen here
789 // Execute end-of-month events
790 $monthEventStory = '';
791 $endOfMonthEvents = $this->getEndOfMonthEvents();
792
793 foreach ($endOfMonthEvents as $event) {
794 // Select eligible participants
795 $eligible = array_filter($this->getAliveKobolds(), function ($kobold) use ($event) {
796 return $kobold->getAge() >= $event->getMinAge();
797 });
798
799 if (count($eligible) < $event->getMinParticipants()) {
800 continue;
801 }
802
803 // Randomly select participants (between min and max)
804 $eligible = array_values($eligible);
805 shuffle($eligible);
806 $participantCount = rand($event->getMinParticipants(), min($event->getMaxParticipants(), count($eligible)));
807 $participants = array_slice($eligible, 0, $participantCount);
808 $participantIds = array_map(fn($k) => $k->getId(), $participants);
809
810 // Set participants and execute event
811 $event->setParticipants($participantIds);
812 $event->execute();
813
814 // Add fatigue to participants
815 foreach ($participants as $participant) {
816 $participant->addFatigue($event->getCost());
817 if ($participant->isDead()) {
818 $monthEventStory .= $participant->getName() . " has died.\n";
819 }
820 $participant->save();
821 }
822
823 // Add event story
824 if ($event->getStory()) {
825 $monthEventStory .= $event->getStory() . "\n";
826 }
827 }
828
683 // After events, consume food
829 // After events, consume food
684
830
685 // age eggs
831 // age eggs
686 $foodStory = "A month passes...\n" . $this->consumeFood();
832 $foodStory = "A month passes...\n" . $this->consumeFood();
833 if ($monthEventStory) {
834 $foodStory = $monthEventStory . "\n" . $foodStory;
835 }
687 $foodStory .= "\n";
836 $foodStory .= "\n";
688
837
689 foreach ($this->kobolds as $kobold) {
838 foreach ($this->kobolds as $kobold) {
@@ -733,7 +882,7 @@ class Tribe
733
882
734 foreach ($this->kobolds as $kobold) {
883 foreach ($this->kobolds as $kobold) {
735 if ($kobold->isDead()) {
884 if ($kobold->isDead()) {
736 $foodStory = $foodStory . "\n" . $kobold->getName() . " has died.";
885 $foodStory = $foodStory . "\n" . $kobold->getName() . " has been buried.";
737 }
886 }
738 }
887 }
739
888
web/src/Events/Event.php +5 −0
@@ -8,6 +8,11 @@ abstract class Event
8 8 protected $story = '';
9 9 protected $participants = []; // array of kobold ids
10 10
11 public function isEndOfMonth()
12 {
13 return false;
14 }
15
11 16 public function __construct(Tribe $tribe)
12 17 {
13 18 $this->tribe = $tribe;
@@ -8,6 +8,11 @@ abstract class Event
8 protected $story = '';
8 protected $story = '';
9 protected $participants = []; // array of kobold ids
9 protected $participants = []; // array of kobold ids
10
10
11 public function isEndOfMonth()
12 {
13 return false;
14 }
15
11 public function __construct(Tribe $tribe)
16 public function __construct(Tribe $tribe)
12 {
17 {
13 $this->tribe = $tribe;
18 $this->tribe = $tribe;
web/src/Events/MonthEndEvent.php added +26 −0
@@ -0,0 +1,26 @@
1 <?php
2 require_once __DIR__ . '/../../src/Events/Event.php';
3 require_once __DIR__ . '/../../src/Classes/Tribe.php';
4
5 abstract class MonthEndEvent extends Event
6 {
7 public function isEndOfMonth()
8 {
9 return true;
10 }
11
12 public function __construct(Tribe $tribe)
13 {
14 $this->tribe = $tribe;
15 }
16
17 abstract public function execute();
18
19 abstract public function getCost();
20
21 abstract function getMinParticipants();
22
23 abstract function getMaxParticipants();
24
25 abstract function getMinAge();
26 }
@@ -0,0 +1,26 @@
1<?php
2require_once __DIR__ . '/../../src/Events/Event.php';
3require_once __DIR__ . '/../../src/Classes/Tribe.php';
4
5abstract class MonthEndEvent extends Event
6{
7 public function isEndOfMonth()
8 {
9 return true;
10 }
11
12 public function __construct(Tribe $tribe)
13 {
14 $this->tribe = $tribe;
15 }
16
17 abstract public function execute();
18
19 abstract public function getCost();
20
21 abstract function getMinParticipants();
22
23 abstract function getMaxParticipants();
24
25 abstract function getMinAge();
26}
web/src/Events/SocialEvent.php added +168 −0
@@ -0,0 +1,168 @@
1 <?php
2
3 require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4 require_once __DIR__ . '/../../src/Classes/Kobold.php';
5 require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
6
7 class SocialEvent extends MonthEndEvent
8 {
9 public function getMinAge()
10 {
11 return 5;
12 }
13
14 public function getMinParticipants()
15 {
16 return 2;
17 }
18
19 public function getMaxParticipants()
20 {
21 return 2;
22 }
23
24 public function getCost()
25 {
26 return 50;
27 }
28
29 public function isAvailable()
30 {
31 return true;
32 }
33
34 public function execute()
35 {
36 $this->story = '';
37
38 // Get eligible kobolds
39 $eligibleKobolds = array_values(array_filter(
40 $this->tribe->getAliveKobolds(),
41 fn($k) => $k->getAge() >= $this->getMinAge()
42 ));
43
44 if (count($eligibleKobolds) < 2) {
45 return;
46 }
47
48 // Select two random kobolds
49 $shuffled = $eligibleKobolds;
50 shuffle($shuffled);
51 $koboldA = $shuffled[0];
52 $koboldB = $shuffled[1];
53
54 // Initialize dataStore->likes if not present
55 if (!isset($koboldA->dataStore)) {
56 $koboldA->dataStore = new stdClass();
57 }
58 if (!isset($koboldA->dataStore->likes)) {
59 $koboldA->dataStore->likes = [];
60 }
61
62 if (!isset($koboldB->dataStore)) {
63 $koboldB->dataStore = new stdClass();
64 }
65 if (!isset($koboldB->dataStore->likes)) {
66 $koboldB->dataStore->likes = [];
67 }
68
69 // Get current likes values (default to 0)
70 $aLikesB = $koboldA->dataStore->likes[$koboldB->getId()] ?? 0;
71 $bLikesA = $koboldB->dataStore->likes[$koboldA->getId()] ?? 0;
72
73 // Roll personality checks (factoring in their feelings toward each other)
74 $aSuccess = $koboldA->checkPersonality($koboldB);
75 $bSuccess = $koboldB->checkPersonality($koboldA);
76
77 $nameA = $koboldA->getName();
78 $nameB = $koboldB->getName();
79
80 if ($aSuccess && $bSuccess) {
81 // Both succeed - mutual fondness grows
82 $koboldA->dataStore->likes[$koboldB->getId()] = $aLikesB + 1;
83 $koboldB->dataStore->likes[$koboldA->getId()] = $bLikesA + 1;
84
85 $bothSuccessVariations = [
86 "{$nameA} and {$nameB} spent a pleasant afternoon sharing stories by the fire, their bond deepening with each tale.",
87 "Under the shade of an old tree, {$nameA} and {$nameB} found themselves laughing together, discovering a growing fondness for one another.",
88 "{$nameA} and {$nameB} worked side by side this month, their companionship blossoming as they learned to trust each other more.",
89 "A quiet understanding passed between {$nameA} and {$nameB} as they watched the sunset together, their friendship strengthening in the peaceful silence.",
90 "{$nameA} and {$nameB} explored the nearby stream, skipping stones and sharing dreams, growing closer with every moment.",
91 "Through shared hardship and triumph, {$nameA} and {$nameB} found their connection deepening, each grateful for the other's presence.",
92 "{$nameA} taught {$nameB} a new skill this month, and in return {$nameB} shared wisdom of their own—their mutual respect blossomed.",
93 "A chance encounter led {$nameA} and {$nameB} to spend the day together, discovering common interests and kindred spirits.",
94 "{$nameA} and {$nameB} found comfort in each other's company during a stormy night, their bond growing stronger through the shared experience.",
95 "The tribe noticed {$nameA} and {$nameB} seeking each other out more often, their friendship becoming a source of joy for both.",
96 "{$nameA} and {$nameB} collaborated on a small project, their easy cooperation revealing a deepening affection between them.",
97 "During a quiet moment in the bustling camp, {$nameA} and {$nameB} exchanged knowing glances, their understanding of each other growing ever richer."
98 ];
99
100 $this->story = $bothSuccessVariations[array_rand($bothSuccessVariations)];
101
102 } elseif ($aSuccess || $bSuccess) {
103 // One succeeds - one-sided fondness grows
104 if ($aSuccess) {
105 $koboldA->dataStore->likes[$koboldB->getId()] = $aLikesB + 1;
106
107 $aSuccessVariations = [
108 "{$nameA} found themselves drawn to {$nameB}'s company this month, though {$nameB} seemed somewhat distracted and distant.",
109 "While {$nameB} was preoccupied with other matters, {$nameA} grew more appreciative of {$nameB}'s qualities and presence in the tribe.",
110 "{$nameA} made several attempts to connect with {$nameB}, and though the responses were lukewarm, {$nameA}'s fondness only grew.",
111 "As {$nameA} watched {$nameB} from afar, admiration bloomed—though {$nameB} remained largely unaware of the attention.",
112 "{$nameA} went out of their way to help {$nameB} with various tasks, developing a quiet affection despite {$nameB}'s apparent indifference.",
113 "Through patient observation, {$nameA} came to appreciate {$nameB}'s unique strengths, even as {$nameB} barely noticed the growing admiration.",
114 "{$nameA} found {$nameB}'s quirks increasingly endearing this month, though their interactions remained somewhat one-sided.",
115 "A series of small gestures from {$nameA} toward {$nameB} went largely unacknowledged, yet {$nameA}'s regard only deepened.",
116 "{$nameA} discovered a growing respect for how {$nameB} handled challenges, even if {$nameB} didn't reciprocate the sentiment.",
117 "Despite {$nameB}'s cool demeanor, {$nameA} saw glimpses of something admirable beneath the surface, and their fondness grew."
118 ];
119
120 $this->story = $aSuccessVariations[array_rand($aSuccessVariations)];
121
122 } else {
123 $koboldB->dataStore->likes[$koboldA->getId()] = $bLikesA + 1;
124
125 $bSuccessVariations = [
126 "{$nameB} found themselves drawn to {$nameA}'s company this month, though {$nameA} seemed somewhat distracted and distant.",
127 "While {$nameA} was preoccupied with other matters, {$nameB} grew more appreciative of {$nameA}'s qualities and presence in the tribe.",
128 "{$nameB} made several attempts to connect with {$nameA}, and though the responses were lukewarm, {$nameB}'s fondness only grew.",
129 "As {$nameB} watched {$nameA} from afar, admiration bloomed—though {$nameA} remained largely unaware of the attention.",
130 "{$nameB} went out of their way to help {$nameA} with various tasks, developing a quiet affection despite {$nameA}'s apparent indifference.",
131 "Through patient observation, {$nameB} came to appreciate {$nameA}'s unique strengths, even as {$nameA} barely noticed the growing admiration.",
132 "{$nameB} found {$nameA}'s quirks increasingly endearing this month, though their interactions remained somewhat one-sided.",
133 "A series of small gestures from {$nameB} toward {$nameA} went largely unacknowledged, yet {$nameB}'s regard only deepened.",
134 "{$nameB} discovered a growing respect for how {$nameA} handled challenges, even if {$nameA} didn't reciprocate the sentiment.",
135 "Despite {$nameA}'s cool demeanor, {$nameB} saw glimpses of something admirable beneath the surface, and their fondness grew."
136 ];
137
138 $this->story = $bSuccessVariations[array_rand($bSuccessVariations)];
139 }
140
141 } else {
142 // Both fail - mutual dislike grows
143 $koboldA->dataStore->likes[$koboldB->getId()] = $aLikesB - 1;
144 $koboldB->dataStore->likes[$koboldA->getId()] = $bLikesA - 1;
145
146 $bothFailVariations = [
147 "{$nameA} and {$nameB} had a heated disagreement this month, each walking away with a worse opinion of the other.",
148 "Tensions flared between {$nameA} and {$nameB} over a trivial matter, leaving both feeling resentful and bitter.",
149 "What began as a simple conversation between {$nameA} and {$nameB} devolved into harsh words and hurt feelings on both sides.",
150 "{$nameA} and {$nameB} clashed over different approaches to a problem, each convinced the other was being unreasonable.",
151 "A misunderstanding between {$nameA} and {$nameB} escalated into mutual accusations, souring their relationship further.",
152 "{$nameA} and {$nameB} found themselves grating on each other's nerves this month, each finding fault in the other's behavior.",
153 "During a shared task, {$nameA} and {$nameB} bickered constantly, their frustration with each other reaching new heights.",
154 "The tribe watched uncomfortably as {$nameA} and {$nameB} exchanged cutting remarks, their animosity plain for all to see.",
155 "{$nameA} and {$nameB} discovered they had fundamentally opposing views on an important matter, and neither was willing to compromise.",
156 "An unfortunate incident left both {$nameA} and {$nameB} blaming each other, their already strained relationship deteriorating further.",
157 "{$nameA} and {$nameB} spent an awkward afternoon together, each irritated by the other's presence and manner of speaking.",
158 "What should have been a pleasant collaboration turned sour as {$nameA} and {$nameB} butted heads at every turn, their mutual dislike intensifying."
159 ];
160
161 $this->story = $bothFailVariations[array_rand($bothFailVariations)];
162 }
163
164 // Save the kobolds with updated dataStore
165 $koboldA->save();
166 $koboldB->save();
167 }
168 }
@@ -0,0 +1,168 @@
1<?php
2
3require_once __DIR__ . '/../../src/Events/MonthEndEvent.php';
4require_once __DIR__ . '/../../src/Classes/Kobold.php';
5require_once __DIR__ . '/../../src/Utilities/GameHelper.php';
6
7class SocialEvent extends MonthEndEvent
8{
9 public function getMinAge()
10 {
11 return 5;
12 }
13
14 public function getMinParticipants()
15 {
16 return 2;
17 }
18
19 public function getMaxParticipants()
20 {
21 return 2;
22 }
23
24 public function getCost()
25 {
26 return 50;
27 }
28
29 public function isAvailable()
30 {
31 return true;
32 }
33
34 public function execute()
35 {
36 $this->story = '';
37
38 // Get eligible kobolds
39 $eligibleKobolds = array_values(array_filter(
40 $this->tribe->getAliveKobolds(),
41 fn($k) => $k->getAge() >= $this->getMinAge()
42 ));
43
44 if (count($eligibleKobolds) < 2) {
45 return;
46 }
47
48 // Select two random kobolds
49 $shuffled = $eligibleKobolds;
50 shuffle($shuffled);
51 $koboldA = $shuffled[0];
52 $koboldB = $shuffled[1];
53
54 // Initialize dataStore->likes if not present
55 if (!isset($koboldA->dataStore)) {
56 $koboldA->dataStore = new stdClass();
57 }
58 if (!isset($koboldA->dataStore->likes)) {
59 $koboldA->dataStore->likes = [];
60 }
61
62 if (!isset($koboldB->dataStore)) {
63 $koboldB->dataStore = new stdClass();
64 }
65 if (!isset($koboldB->dataStore->likes)) {
66 $koboldB->dataStore->likes = [];
67 }
68
69 // Get current likes values (default to 0)
70 $aLikesB = $koboldA->dataStore->likes[$koboldB->getId()] ?? 0;
71 $bLikesA = $koboldB->dataStore->likes[$koboldA->getId()] ?? 0;
72
73 // Roll personality checks (factoring in their feelings toward each other)
74 $aSuccess = $koboldA->checkPersonality($koboldB);
75 $bSuccess = $koboldB->checkPersonality($koboldA);
76
77 $nameA = $koboldA->getName();
78 $nameB = $koboldB->getName();
79
80 if ($aSuccess && $bSuccess) {
81 // Both succeed - mutual fondness grows
82 $koboldA->dataStore->likes[$koboldB->getId()] = $aLikesB + 1;
83 $koboldB->dataStore->likes[$koboldA->getId()] = $bLikesA + 1;
84
85 $bothSuccessVariations = [
86 "{$nameA} and {$nameB} spent a pleasant afternoon sharing stories by the fire, their bond deepening with each tale.",
87 "Under the shade of an old tree, {$nameA} and {$nameB} found themselves laughing together, discovering a growing fondness for one another.",
88 "{$nameA} and {$nameB} worked side by side this month, their companionship blossoming as they learned to trust each other more.",
89 "A quiet understanding passed between {$nameA} and {$nameB} as they watched the sunset together, their friendship strengthening in the peaceful silence.",
90 "{$nameA} and {$nameB} explored the nearby stream, skipping stones and sharing dreams, growing closer with every moment.",
91 "Through shared hardship and triumph, {$nameA} and {$nameB} found their connection deepening, each grateful for the other's presence.",
92 "{$nameA} taught {$nameB} a new skill this month, and in return {$nameB} shared wisdom of their own—their mutual respect blossomed.",
93 "A chance encounter led {$nameA} and {$nameB} to spend the day together, discovering common interests and kindred spirits.",
94 "{$nameA} and {$nameB} found comfort in each other's company during a stormy night, their bond growing stronger through the shared experience.",
95 "The tribe noticed {$nameA} and {$nameB} seeking each other out more often, their friendship becoming a source of joy for both.",
96 "{$nameA} and {$nameB} collaborated on a small project, their easy cooperation revealing a deepening affection between them.",
97 "During a quiet moment in the bustling camp, {$nameA} and {$nameB} exchanged knowing glances, their understanding of each other growing ever richer."
98 ];
99
100 $this->story = $bothSuccessVariations[array_rand($bothSuccessVariations)];
101
102 } elseif ($aSuccess || $bSuccess) {
103 // One succeeds - one-sided fondness grows
104 if ($aSuccess) {
105 $koboldA->dataStore->likes[$koboldB->getId()] = $aLikesB + 1;
106
107 $aSuccessVariations = [
108 "{$nameA} found themselves drawn to {$nameB}'s company this month, though {$nameB} seemed somewhat distracted and distant.",
109 "While {$nameB} was preoccupied with other matters, {$nameA} grew more appreciative of {$nameB}'s qualities and presence in the tribe.",
110 "{$nameA} made several attempts to connect with {$nameB}, and though the responses were lukewarm, {$nameA}'s fondness only grew.",
111 "As {$nameA} watched {$nameB} from afar, admiration bloomed—though {$nameB} remained largely unaware of the attention.",
112 "{$nameA} went out of their way to help {$nameB} with various tasks, developing a quiet affection despite {$nameB}'s apparent indifference.",
113 "Through patient observation, {$nameA} came to appreciate {$nameB}'s unique strengths, even as {$nameB} barely noticed the growing admiration.",
114 "{$nameA} found {$nameB}'s quirks increasingly endearing this month, though their interactions remained somewhat one-sided.",
115 "A series of small gestures from {$nameA} toward {$nameB} went largely unacknowledged, yet {$nameA}'s regard only deepened.",
116 "{$nameA} discovered a growing respect for how {$nameB} handled challenges, even if {$nameB} didn't reciprocate the sentiment.",
117 "Despite {$nameB}'s cool demeanor, {$nameA} saw glimpses of something admirable beneath the surface, and their fondness grew."
118 ];
119
120 $this->story = $aSuccessVariations[array_rand($aSuccessVariations)];
121
122 } else {
123 $koboldB->dataStore->likes[$koboldA->getId()] = $bLikesA + 1;
124
125 $bSuccessVariations = [
126 "{$nameB} found themselves drawn to {$nameA}'s company this month, though {$nameA} seemed somewhat distracted and distant.",
127 "While {$nameA} was preoccupied with other matters, {$nameB} grew more appreciative of {$nameA}'s qualities and presence in the tribe.",
128 "{$nameB} made several attempts to connect with {$nameA}, and though the responses were lukewarm, {$nameB}'s fondness only grew.",
129 "As {$nameB} watched {$nameA} from afar, admiration bloomed—though {$nameA} remained largely unaware of the attention.",
130 "{$nameB} went out of their way to help {$nameA} with various tasks, developing a quiet affection despite {$nameA}'s apparent indifference.",
131 "Through patient observation, {$nameB} came to appreciate {$nameA}'s unique strengths, even as {$nameA} barely noticed the growing admiration.",
132 "{$nameB} found {$nameA}'s quirks increasingly endearing this month, though their interactions remained somewhat one-sided.",
133 "A series of small gestures from {$nameB} toward {$nameA} went largely unacknowledged, yet {$nameB}'s regard only deepened.",
134 "{$nameB} discovered a growing respect for how {$nameA} handled challenges, even if {$nameA} didn't reciprocate the sentiment.",
135 "Despite {$nameA}'s cool demeanor, {$nameB} saw glimpses of something admirable beneath the surface, and their fondness grew."
136 ];
137
138 $this->story = $bSuccessVariations[array_rand($bSuccessVariations)];
139 }
140
141 } else {
142 // Both fail - mutual dislike grows
143 $koboldA->dataStore->likes[$koboldB->getId()] = $aLikesB - 1;
144 $koboldB->dataStore->likes[$koboldA->getId()] = $bLikesA - 1;
145
146 $bothFailVariations = [
147 "{$nameA} and {$nameB} had a heated disagreement this month, each walking away with a worse opinion of the other.",
148 "Tensions flared between {$nameA} and {$nameB} over a trivial matter, leaving both feeling resentful and bitter.",
149 "What began as a simple conversation between {$nameA} and {$nameB} devolved into harsh words and hurt feelings on both sides.",
150 "{$nameA} and {$nameB} clashed over different approaches to a problem, each convinced the other was being unreasonable.",
151 "A misunderstanding between {$nameA} and {$nameB} escalated into mutual accusations, souring their relationship further.",
152 "{$nameA} and {$nameB} found themselves grating on each other's nerves this month, each finding fault in the other's behavior.",
153 "During a shared task, {$nameA} and {$nameB} bickered constantly, their frustration with each other reaching new heights.",
154 "The tribe watched uncomfortably as {$nameA} and {$nameB} exchanged cutting remarks, their animosity plain for all to see.",
155 "{$nameA} and {$nameB} discovered they had fundamentally opposing views on an important matter, and neither was willing to compromise.",
156 "An unfortunate incident left both {$nameA} and {$nameB} blaming each other, their already strained relationship deteriorating further.",
157 "{$nameA} and {$nameB} spent an awkward afternoon together, each irritated by the other's presence and manner of speaking.",
158 "What should have been a pleasant collaboration turned sour as {$nameA} and {$nameB} butted heads at every turn, their mutual dislike intensifying."
159 ];
160
161 $this->story = $bothFailVariations[array_rand($bothFailVariations)];
162 }
163
164 // Save the kobolds with updated dataStore
165 $koboldA->save();
166 $koboldB->save();
167 }
168}
web/src/api/game.php +4 −0
@@ -679,6 +679,10 @@ if ($method === 'POST') {
679 679 }
680 680
681 681 $event = new $className($tribe);
682
683 if ($event->isEndOfMonth())
684 continue;
685
682 686 $type = preg_replace('/Event$/', '', $className);
683 687
684 688 $events[] = [
@@ -679,6 +679,10 @@ if ($method === 'POST') {
679 }
679 }
680
680
681 $event = new $className($tribe);
681 $event = new $className($tribe);
682
683 if ($event->isEndOfMonth())
684 continue;
685
682 $type = preg_replace('/Event$/', '', $className);
686 $type = preg_replace('/Event$/', '', $className);
683
687
684 $events[] = [
688 $events[] = [