babies
@@ -104,7 +104,7 @@
104
104
105
105
<div class="game-right">
106
106
<div class="panel">
107
<h3>Events</h3>
107
<h3>Activities</h3>
108
108
<div id="eventsList" class="events-list"></div>
109
109
</div>
110
110
@@ -104,7 +104,7 @@104
104
105
<div class="game-right">105
<div class="game-right">106
<div class="panel">106
<div class="panel">107
<h3>Events</h3>107
<h3>Activities</h3>108
<div id="eventsList" class="events-list"></div>108
<div id="eventsList" class="events-list"></div>109
</div>109
</div>110
110
@@ -558,6 +558,32 @@ class Kobold
558
558
return $this->spriteMorph;
559
559
}
560
560
561
public function setSpriteMorph($spriteMorph)
562
{
563
$this->spriteMorph = $spriteMorph;
564
}
565
566
public function getColours()
567
{
568
return [
569
'primary' => $this->colourPrimary,
570
'secondary' => $this->colourSecondary,
571
'tertiary' => $this->colourTertiary
572
];
573
}
574
575
public function setColours($primary, $secondary, $tertiary)
576
{
577
$this->colourPrimary = $primary;
578
$this->colourSecondary = $secondary;
579
$this->colourTertiary = $tertiary;
580
}
581
582
public function regenerateSprite()
583
{
584
$this->initializeSprite();
585
}
586
561
587
public function getStatLabel($statValue)
562
588
{
563
589
if ($statValue >= 90)
@@ -558,6 +558,32 @@ class Kobold558
return $this->spriteMorph;558
return $this->spriteMorph;559
}559
}560
560
561
public function setSpriteMorph($spriteMorph)562
{563
$this->spriteMorph = $spriteMorph;564
}565
566
public function getColours()567
{568
return [569
'primary' => $this->colourPrimary,570
'secondary' => $this->colourSecondary,571
'tertiary' => $this->colourTertiary572
];573
}574
575
public function setColours($primary, $secondary, $tertiary)576
{577
$this->colourPrimary = $primary;578
$this->colourSecondary = $secondary;579
$this->colourTertiary = $tertiary;580
}581
582
public function regenerateSprite()583
{584
$this->initializeSprite();585
}586
561
public function getStatLabel($statValue)587
public function getStatLabel($statValue)562
{588
{563
if ($statValue >= 90)589
if ($statValue >= 90)@@ -412,6 +412,135 @@ class Tribe
412
412
}
413
413
}
414
414
415
public function tryMate()
416
{
417
$kobolds = array_values($this->getKobolds());
418
$count = count($kobolds);
419
420
if ($count === 0) {
421
return '';
422
}
423
424
$roll = rand(1, 30);
425
if ($roll <= $count) {
426
return '';
427
}
428
429
$males = array_values(array_filter($kobolds, fn($k) => $k->getMale()));
430
$females = array_values(array_filter($kobolds, fn($k) => !$k->getMale()));
431
432
if (empty($males) || empty($females)) {
433
return '';
434
}
435
436
$pair = null;
437
$attempts = 20;
438
while ($attempts-- > 0) {
439
$male = $males[array_rand($males)];
440
$female = $females[array_rand($females)];
441
442
$maleParents = $male->getParents();
443
$femaleParents = $female->getParents();
444
445
$sharedFather = !empty($maleParents['father_id']) && $maleParents['father_id'] === ($femaleParents['father_id'] ?? null);
446
$sharedMother = !empty($maleParents['mother_id']) && $maleParents['mother_id'] === ($femaleParents['mother_id'] ?? null);
447
$isMaleParent = $male->getId() === ($femaleParents['father_id'] ?? null) || $male->getId() === ($femaleParents['mother_id'] ?? null);
448
$isFemaleParent = $female->getId() === ($maleParents['father_id'] ?? null) || $female->getId() === ($maleParents['mother_id'] ?? null);
449
450
if ($sharedFather || $sharedMother || $isMaleParent || $isFemaleParent) {
451
continue;
452
}
453
454
$pair = [$male, $female];
455
break;
456
}
457
458
if (!$pair) {
459
return '';
460
}
461
462
[$male, $female] = $pair;
463
464
if (!$male->checkStat('personality') || !$female->checkStat('personality')) {
465
return "{$male->getName()} and {$female->getName()} spent some of time together this month, but didn't quite hit it off.";
466
}
467
468
$child = Kobold::generate($this->userId, $this->saveId, -6);
469
470
$inheritRoll = rand(1, 100);
471
if ($inheritRoll <= 40) {
472
$child->setSpriteMorph($male->getSpriteMorph());
473
} elseif ($inheritRoll <= 80) {
474
$child->setSpriteMorph($female->getSpriteMorph());
475
}
476
477
$blendHex = function ($a, $b) {
478
$hexToRgb = function ($hex) {
479
$hex = ltrim($hex, '#');
480
return [
481
'r' => hexdec(substr($hex, 0, 2)),
482
'g' => hexdec(substr($hex, 2, 2)),
483
'b' => hexdec(substr($hex, 4, 2))
484
];
485
};
486
487
$rgbToHex = function ($rgb) {
488
return sprintf('#%02X%02X%02X', $rgb['r'], $rgb['g'], $rgb['b']);
489
};
490
491
$ra = $hexToRgb($a);
492
$rb = $hexToRgb($b);
493
$ratio = rand(0, 100) / 100;
494
495
$offset = function () {
496
return rand(-20, 20);
497
};
498
499
$mix = function ($c1, $c2) use ($ratio, $offset) {
500
$val = (int) round(($c1 * $ratio) + ($c2 * (1 - $ratio)) + $offset());
501
return max(0, min(255, $val));
502
};
503
504
$mixed = [
505
'r' => $mix($ra['r'], $rb['r']),
506
'g' => $mix($ra['g'], $rb['g']),
507
'b' => $mix($ra['b'], $rb['b'])
508
];
509
510
return $rgbToHex($mixed);
511
};
512
513
$maleColours = $male->getColours();
514
$femaleColours = $female->getColours();
515
516
$childPrimary = $blendHex($maleColours['primary'], $femaleColours['primary']);
517
$childSecondary = $blendHex($maleColours['secondary'], $femaleColours['secondary']);
518
$childTertiary = $blendHex($maleColours['tertiary'], $femaleColours['tertiary']);
519
520
$child->setColours($childPrimary, $childSecondary, $childTertiary);
521
$child->setParents($male->getId(), $female->getId());
522
$child->regenerateSprite();
523
524
$this->addKobold($child);
525
526
$pairName = $female->getName() . " and " . $male->getName();
527
$momName = $female->getName();
528
$variations = [
529
"{$pairName} spent a lot of time together this month. After a while, {$momName} laid an egg!",
530
"A quiet bond formed between {$pairName}, and soon {$momName} laid an egg.",
531
"The tribe whispers as {$pairName} draw close. By month's end, {$momName} laid an egg.",
532
"Under the clan's watchful eyes, {$pairName} grew inseparable, and {$momName} laid an egg.",
533
"After many shared moments, {$pairName} welcomed a new egg from {$momName}.",
534
"A spark passed between {$pairName}. Before the month ended, {$momName} laid an egg.",
535
"The camp celebrates softly as {$pairName} brought new life—{$momName} laid an egg.",
536
"Fortunate days came for {$pairName}; the month closes with {$momName} laying an egg.",
537
"The tribe smiles as {$pairName} found harmony, and {$momName} laid an egg.",
538
"Among the kobolds, {$pairName} share a rare warmth, and {$momName} laid an egg."
539
];
540
541
return $variations[array_rand($variations)];
542
}
543
415
544
public function endMonth()
416
545
{
417
546
$this->currentMonth++;
@@ -478,6 +607,7 @@ class Tribe
478
607
}
479
608
}
480
609
$foodStory .= "\nIt's {$this->currentSeason}.\n";
610
$foodStory .= $this->tryMate();
481
611
482
612
foreach ($this->kobolds as $kobold) {
483
613
if ($kobold->isDead()) {
@@ -412,6 +412,135 @@ class Tribe412
}412
}413
}413
}414
414
415
public function tryMate()416
{417
$kobolds = array_values($this->getKobolds());418
$count = count($kobolds);419
420
if ($count === 0) {421
return '';422
}423
424
$roll = rand(1, 30);425
if ($roll <= $count) {426
return '';427
}428
429
$males = array_values(array_filter($kobolds, fn($k) => $k->getMale()));430
$females = array_values(array_filter($kobolds, fn($k) => !$k->getMale()));431
432
if (empty($males) || empty($females)) {433
return '';434
}435
436
$pair = null;437
$attempts = 20;438
while ($attempts-- > 0) {439
$male = $males[array_rand($males)];440
$female = $females[array_rand($females)];441
442
$maleParents = $male->getParents();443
$femaleParents = $female->getParents();444
445
$sharedFather = !empty($maleParents['father_id']) && $maleParents['father_id'] === ($femaleParents['father_id'] ?? null);446
$sharedMother = !empty($maleParents['mother_id']) && $maleParents['mother_id'] === ($femaleParents['mother_id'] ?? null);447
$isMaleParent = $male->getId() === ($femaleParents['father_id'] ?? null) || $male->getId() === ($femaleParents['mother_id'] ?? null);448
$isFemaleParent = $female->getId() === ($maleParents['father_id'] ?? null) || $female->getId() === ($maleParents['mother_id'] ?? null);449
450
if ($sharedFather || $sharedMother || $isMaleParent || $isFemaleParent) {451
continue;452
}453
454
$pair = [$male, $female];455
break;456
}457
458
if (!$pair) {459
return '';460
}461
462
[$male, $female] = $pair;463
464
if (!$male->checkStat('personality') || !$female->checkStat('personality')) {465
return "{$male->getName()} and {$female->getName()} spent some of time together this month, but didn't quite hit it off.";466
}467
468
$child = Kobold::generate($this->userId, $this->saveId, -6);469
470
$inheritRoll = rand(1, 100);471
if ($inheritRoll <= 40) {472
$child->setSpriteMorph($male->getSpriteMorph());473
} elseif ($inheritRoll <= 80) {474
$child->setSpriteMorph($female->getSpriteMorph());475
}476
477
$blendHex = function ($a, $b) {478
$hexToRgb = function ($hex) {479
$hex = ltrim($hex, '#');480
return [481
'r' => hexdec(substr($hex, 0, 2)),482
'g' => hexdec(substr($hex, 2, 2)),483
'b' => hexdec(substr($hex, 4, 2))484
];485
};486
487
$rgbToHex = function ($rgb) {488
return sprintf('#%02X%02X%02X', $rgb['r'], $rgb['g'], $rgb['b']);489
};490
491
$ra = $hexToRgb($a);492
$rb = $hexToRgb($b);493
$ratio = rand(0, 100) / 100;494
495
$offset = function () {496
return rand(-20, 20);497
};498
499
$mix = function ($c1, $c2) use ($ratio, $offset) {500
$val = (int) round(($c1 * $ratio) + ($c2 * (1 - $ratio)) + $offset());501
return max(0, min(255, $val));502
};503
504
$mixed = [505
'r' => $mix($ra['r'], $rb['r']),506
'g' => $mix($ra['g'], $rb['g']),507
'b' => $mix($ra['b'], $rb['b'])508
];509
510
return $rgbToHex($mixed);511
};512
513
$maleColours = $male->getColours();514
$femaleColours = $female->getColours();515
516
$childPrimary = $blendHex($maleColours['primary'], $femaleColours['primary']);517
$childSecondary = $blendHex($maleColours['secondary'], $femaleColours['secondary']);518
$childTertiary = $blendHex($maleColours['tertiary'], $femaleColours['tertiary']);519
520
$child->setColours($childPrimary, $childSecondary, $childTertiary);521
$child->setParents($male->getId(), $female->getId());522
$child->regenerateSprite();523
524
$this->addKobold($child);525
526
$pairName = $female->getName() . " and " . $male->getName();527
$momName = $female->getName();528
$variations = [529
"{$pairName} spent a lot of time together this month. After a while, {$momName} laid an egg!",530
"A quiet bond formed between {$pairName}, and soon {$momName} laid an egg.",531
"The tribe whispers as {$pairName} draw close. By month's end, {$momName} laid an egg.",532
"Under the clan's watchful eyes, {$pairName} grew inseparable, and {$momName} laid an egg.",533
"After many shared moments, {$pairName} welcomed a new egg from {$momName}.",534
"A spark passed between {$pairName}. Before the month ended, {$momName} laid an egg.",535
"The camp celebrates softly as {$pairName} brought new life—{$momName} laid an egg.",536
"Fortunate days came for {$pairName}; the month closes with {$momName} laying an egg.",537
"The tribe smiles as {$pairName} found harmony, and {$momName} laid an egg.",538
"Among the kobolds, {$pairName} share a rare warmth, and {$momName} laid an egg."539
];540
541
return $variations[array_rand($variations)];542
}543
415
public function endMonth()544
public function endMonth()416
{545
{417
$this->currentMonth++;546
$this->currentMonth++;@@ -478,6 +607,7 @@ class Tribe478
}607
}479
}608
}480
$foodStory .= "\nIt's {$this->currentSeason}.\n";609
$foodStory .= "\nIt's {$this->currentSeason}.\n";610
$foodStory .= $this->tryMate();481
611
482
foreach ($this->kobolds as $kobold) {612
foreach ($this->kobolds as $kobold) {483
if ($kobold->isDead()) {613
if ($kobold->isDead()) {