public function buy($action) { $this->check($this->victim, "victim"); $this->check($action["price"]["amount"], "price amount"); $this->check($action["price"]["type"], "price type"); $price = $action["price"]["amount"]; $type = $action["price"]["type"]; $request = new \Data\Request(); $request->Filter[] = new \Data\Filter("subject_id", $this->victim->object_id); $ownership = \GameObject\Model\GameObjectOwnershipModel::findOne($request); if ($ownership) { if ($ownership->object_id !== $this->actor->object_id) { $owner = \GameObject\Model\GameObjectModel::findById($ownership->object_id); $funds = $owner->getProperty($type); $owner->setProperty($type, $funds + $price); $ownership->update(["object_id" => $this->actor->object_id]); $funds = $this->actor->getProperty($type); $this->actor->setProperty($type, $funds - $price); } } else { $ownership = \GameObject\Model\GameObjectOwnershipModel::build(["object_id" => $this->actor->object_id, "subject_id" => $this->victim->object_id]); $ownership->save(); } return ["success" => true]; }
$name = $path[0]; // Just the name } elseif (count($path) == 2) { // Region and name! array_push($deps, $path[0]); $name = $path[1]; } $obj = \GameObject\Model\GameObjectModel::findById($name); if (!$obj) { $obj = \GameObject\Model\GameObjectModel::findByNameRegionGame($name, $deps, $game); } if ($fetch_possessions) { if ($obj) { $possessions = array(); foreach ($obj->ownerships as $object) { $possession = \GameObject\Model\GameObjectModel::findById($object->subject_id); $possessions[] = $possession->read(); } sendResponse($possessions); } else { header('Content-Type: application/json'); echo "[]"; } } elseif ($obj) { sendResponse($obj->read()); } else { header('Content-Type: application/json'); echo "{}"; } } } else {