BlueGit

blue-star tribegen

Files

tribegen / web / src / Classes / Injury.php

Injury.php

injuries, cures, event edits
timfa Tim Falken · pushed by timfa · 9 months ago
146dd342 History
Injury.php 2.3 KiB Download Raw
1<?php
2
3require_once __DIR__ . '/../../src/Database/Database.php';
4
5class Injury
6{
7 private $id;
8 private $injuryType;
9 private $description;
10 private $category;
11 private $severity;
12 private $statModifications = [];
13
14 private static $cureMap = [
15 'wound' => 'basic_medicine',
16 'fracture' => 'bone_setting',
17 'infection' => 'healing_herbs',
18 'poison' => 'antidote',
19 'burn' => 'burn_salve',
20 'malnourished' => 'food', // Cured by having enough food
21 'old-age' => null // Cannot be cured
22 ];
23
24 public function __construct($id, $injuryType, $description, $category, $severity, $statModifications = [])
25 {
26 $this->id = $id;
27 $this->description = $description;
28 $this->injuryType = $injuryType;
29 $this->category = $category;
30 $this->severity = $severity;
31 $this->statModifications = $statModifications;
32 }
33
34 public static function load($id)
35 {
36 $db = Database::getInstance();
37 $pdo = $db->getPDO();
38
39 $stmt = $pdo->prepare("SELECT * FROM injuries WHERE id = ?");
40 $stmt->execute([$id]);
41 $row = $stmt->fetch();
42
43 if (!$row) {
44 return null;
45 }
46
47 return new self($row['id'], $row['kobold_id'], $row['injury_type'], $row['category'], $row['severity']);
48 }
49
50 public function getId()
51 {
52 return $this->id;
53 }
54
55 public function getInjuryType()
56 {
57 return $this->injuryType;
58 }
59
60 public function getCategory()
61 {
62 return $this->category;
63 }
64
65 public function getSeverity()
66 {
67 return $this->severity;
68 }
69
70 public function canBeCured()
71 {
72 return isset(self::$cureMap[$this->category]) && self::$cureMap[$this->category] !== null;
73 }
74
75 public function getRequiredMedicine()
76 {
77 return self::$cureMap[$this->category] ?? null;
78 }
79
80 public static function getCureForCategory($category)
81 {
82 return self::$cureMap[$category] ?? null;
83 }
84
85 public function getDescription()
86 {
87 return ucfirst(str_replace('_', ' ', $this->injuryType));
88 }
89
90 public function delete()
91 {
92 $db = Database::getInstance();
93 $pdo = $db->getPDO();
94
95 $stmt = $pdo->prepare("DELETE FROM injuries WHERE id = ?");
96 $stmt->execute([$this->id]);
97 }
98}