Пример #1
0
 /**
  * @param ItemId $id
  * @param StringLiteral $name
  * @param Uri $icon
  */
 public function __construct(ItemId $id, StringLiteral $name, Uri $icon)
 {
     $this->id = $id;
     $this->name = $name;
     $this->icon = $icon;
     $this->bindingType = BindingType::NONE();
     $this->value = new Integer(0);
     $this->stackCount = new Integer(0);
     $this->minimumLevel = new Integer(0);
     $this->modifications = new ModificationCollection();
 }
Пример #2
0
 /**
  * @param array $data
  * @param string $class
  * @param string|null $format
  * @param array $context
  * @return Item
  */
 public function denormalize($data, $class, $format = null, array $context = array())
 {
     $data = $this->prepareForDenormalization($data);
     $id = new ItemId((string) $data[self::ID]);
     $name = new StringLiteral((string) $data[self::NAME]);
     $icon = new Uri((string) $data[self::ICON]);
     /* @var Item $item */
     $item = new $class($id, $name, $icon);
     if (isset($data[self::DESCRIPTION])) {
         $item = $item->withDescription(new StringLiteral((string) $data[self::DESCRIPTION]));
     }
     if (isset($data[self::VALUE])) {
         $item = $item->withValue(new Integer((int) $data[self::VALUE]));
     }
     if (isset($data[self::STACK_COUNT])) {
         $item = $item->withStackCount(new Integer((int) $data[self::STACK_COUNT]));
     }
     if (!empty($data[self::BINDING_TYPE])) {
         $item = $item->withBindingType(BindingType::fromNative((string) $data[self::BINDING_TYPE]));
     }
     if (isset($data[self::MINIMUM_LEVEL])) {
         $item = $item->withMinimumLevel(new Integer((int) $data[self::MINIMUM_LEVEL]));
     }
     if (isset($data[self::DURABILITY])) {
         $item = $item->withDurability(new Integer((int) $data[self::DURABILITY]));
     }
     if (!empty($data[self::STATS])) {
         if (!$this->serializer instanceof DenormalizerInterface) {
             throw new \LogicException('Cannot denormalize attribute "Stats" because injected serializer is not a denormalizer.');
         }
         /* @var Stats $stats */
         $stats = $this->serializer->denormalize($data[self::STATS], Stats::class, $format, $context);
         $item = $item->withStats($stats);
     }
     $modifications = new ModificationCollection();
     if (!empty($data[self::MODS])) {
         if (!$this->serializer instanceof DenormalizerInterface) {
             throw new \LogicException('Cannot denormalize attribute "Mods" because injected serializer is not a denormalizer.');
         }
         foreach ($data[self::MODS] as $key => $modification) {
             $modification = $this->serializer->denormalize($modification, Modification::class, $format, $context);
             $modifications = $modifications->withKey($key, $modification);
         }
     }
     if ($modifications->length() > 0) {
         $item = $item->withModifications($modifications);
     }
     return $item;
 }
 /**
  * @return ModificationCollection
  */
 public function getItemModifications()
 {
     $harness = (new Modification(new ItemId('20187'), new StringLiteral('Might Armoring 20'), new Uri('http://foo.bar/icon.harness.png')))->withValue(new Integer(1710))->withBindingType(BindingType::EQUIP())->withMinimumLevel(new Integer(45))->withDescription(new StringLiteral('This Armoring can be used to upgrade your armor.'));
     $overlay = (new Modification(new ItemId('73112'), new StringLiteral('Deft Mod 20A'), new Uri('http://foo.bar/icon.overlay.png')))->withValue(new Integer(455))->withBindingType(BindingType::EQUIP())->withMinimumLevel(new Integer(45))->withDescription(new StringLiteral('This Mod can be used to upgrade your weapons and armor.'));
     $support = (new Modification(new ItemId('55597'), new StringLiteral('Studious Enhancement 20'), new Uri('http://foo.bar/icon.support.png')))->withValue(new Integer(455))->withBindingType(BindingType::EQUIP())->withMinimumLevel(new Integer(45))->withDescription(new StringLiteral('This Enhancement can be used to upgrade your weapons and armor.'));
     return (new ModificationCollection())->withKey('Harness', $harness)->withKey('Overlay', $overlay)->withKey('Support', $support);
 }
Пример #4
0
 public function testBindingType()
 {
     $this->assertEquals(BindingType::NONE(), $this->item->getBindingType());
     $this->item = $this->item->withBindingType(BindingType::EQUIP());
     $this->assertEquals(BindingType::EQUIP(), $this->item->getBindingType());
 }