BlueGit

blue-star tribegen

Files

tribegen / web / src / Classes / Injury.php

Injury.php

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