BlueGit

blue-star tribegen

Files

tribegen / web / src / Classes / Injury.php

Injury.php

initial generation
timfa Tim · pushed by timfa · 9 months ago
0b655138 History
Injury.php 2.1 KiB Download Raw
1<?php
2
3namespace TribeGen\Classes;
4
5use TribeGen\Database\Database;
6
7class Injury
8{
9 private $id;
10 private $koboldId;
11 private $injuryType;
12 private $category;
13 private $severity;
14
15 private static $cureMap = [
16 'wound' => 'basic_medicine',
17 'fracture' => 'bone_setting',
18 'infection' => 'healing_herbs',
19 'poison' => 'antidote',
20 'burn' => 'burn_salve',
21 'malnourished' => 'food', // Cured by having enough food
22 'old-age' => null // Cannot be cured
23 ];
24
25 public function __construct($id, $koboldId, $injuryType, $category, $severity)
26 {
27 $this->id = $id;
28 $this->koboldId = $koboldId;
29 $this->injuryType = $injuryType;
30 $this->category = $category;
31 $this->severity = $severity;
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 function getDescription()
81 {
82 return ucfirst(str_replace('_', ' ', $this->injuryType));
83 }
84
85 public function delete()
86 {
87 $db = Database::getInstance();
88 $pdo = $db->getPDO();
89
90 $stmt = $pdo->prepare("DELETE FROM injuries WHERE id = ?");
91 $stmt->execute([$this->id]);
92 }
93}