示例#1
0
 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];
 }
示例#2
0
文件: index.php 项目: Epiphane/CoRPG
            $name = $params["self"]["name"];
            $region = $params["self"]["region"];
            $actor = \GameObject\Model\GameObjectModel::findByNameRegionGame($name, array($region));
            if ($params["other"]) {
                $name = $params["other"]["name"];
                $region = $params["other"]["region"];
                $victim = \GameObject\Model\GameObjectModel::findByNameRegionGame($name, array($region));
            }
            $action = $params["action"];
            $result = \GameObject\Controller\GameObjectController::act($actor, $victim, $action);
            if ($result["success"]) {
                sendResponse(["result" => $result, "self" => $actor->read(), "other" => $victim ? $victim->read() : "{}"]);
            } else {
                sendResponse($result);
            }
        }
    } else {
        if ($_SERVER["REQUEST_METHOD"] == "PUT") {
            _log("\t" . json_encode($params));
            $name = $params["name"];
            $region = $params["region"];
            $obj = \GameObject\Model\GameObjectModel::findByNameRegionGame($name, array($region));
            if ($obj) {
                sendResponse($obj->update($params)->read());
            } else {
                $obj = \GameObject\Model\GameObjectModel::build($params);
                sendResponse($obj->save()->read());
            }
        }
    }
}