BlueGit

blue-star tribegen

Files

tribegen / web / src / Classes / Item.php

Item.php

injuries, cures, event edits
timfa Tim Falken · pushed by timfa · 9 months ago
146dd342 History
Item.php 1.7 KiB Download Raw
1<?php
2
3class Item
4{
5 private $id;
6 private $saveId;
7 private $name;
8 private $description;
9 private $itemType;
10 private $statModifications = [];
11
12 public function __construct($id, $name, $description, $itemType, $statModifications = [])
13 {
14 $this->id = $id;
15 $this->name = $name;
16 $this->description = $description;
17 $this->itemType = $itemType;
18 $this->statModifications = $statModifications;
19 }
20
21 public static function fromArray($data)
22 {
23 return new self(
24 $data['id'] ?? uniqid('itm_'),
25 $data['name'] ?? '',
26 $data['description'] ?? '',
27 $data['item_type'] ?? 'generic',
28 $data['stat_modifications'] ?? []
29 );
30 }
31
32 public function toArray()
33 {
34 return [
35 'id' => $this->id,
36 'name' => $this->name,
37 'description' => $this->description,
38 'item_type' => $this->itemType,
39 'stat_modifications' => $this->statModifications
40 ];
41 }
42
43 public function getId()
44 {
45 return $this->id;
46 }
47
48 public function getName()
49 {
50 return $this->name;
51 }
52
53 public function getDescription()
54 {
55 return $this->description;
56 }
57
58 public function getItemType()
59 {
60 return $this->itemType;
61 }
62
63 public function checkStat($statName, $baseValue)
64 {
65 // Returns modified stat value
66 $modified = $baseValue;
67
68 if (isset($this->statModifications[$statName])) {
69 $modified += $this->statModifications[$statName];
70 }
71
72 return max(0, min(100, $modified));
73 }
74
75 public function getStatModifications()
76 {
77 return $this->statModifications;
78 }
79}