BlueGit

blue-star tribegen

Files

tribegen / web / src / Events / SocialEvent.php

SocialEvent.php

upd
timfa Tim Falken · pushed by timfa · 9 months ago
3298ef22 History
SocialEvent.php 9.9 KiB Download Raw
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 {$koboldB->his()} 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 {$koboldA->him()}self 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 {$koboldA->his()} 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 {$koboldA->his()} 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 {$koboldA->his()} 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 {$koboldA->him()}self 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 {$koboldB->his()} 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 {$koboldB->his()} 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 {$koboldB->his()} 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}