feat: Implement CreateItemOnObject
This commit is contained in:
parent
9a24364115
commit
7cc49a7a6e
6 changed files with 42 additions and 2 deletions
|
@ -36,6 +36,10 @@ SpatialObject::SpatialObject(uint32_t id, ObjectType type, SceneGraph *sceneGrap
|
|||
Object(id, type), _sceneGraph(sceneGraph) {
|
||||
}
|
||||
|
||||
void SpatialObject::addItem(const shared_ptr<Item> &item) {
|
||||
_items.push_back(item);
|
||||
}
|
||||
|
||||
float SpatialObject::distanceTo(const glm::vec2 &point) const {
|
||||
return glm::distance2(glm::vec2(_position), point);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ public:
|
|||
|
||||
virtual void playAnimation(const std::string &name, int flags = 0, float speed = 1.0f);
|
||||
|
||||
void addItem(const std::shared_ptr<Item> &item);
|
||||
|
||||
float distanceTo(const glm::vec2 &point) const;
|
||||
float distanceTo(const glm::vec3 &point) const;
|
||||
bool contains(const glm::vec3 &point) const;
|
||||
|
|
|
@ -87,6 +87,7 @@ private:
|
|||
|
||||
// Objects
|
||||
|
||||
script::Variable createItemOnObject(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
|
||||
script::Variable destroyObject(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
|
||||
script::Variable getArea(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
|
||||
script::Variable getEnteringObject(const std::vector<script::Variable> &args, script::ExecutionContext &ctx);
|
||||
|
|
|
@ -70,7 +70,7 @@ void Routines::addKotorRoutines() {
|
|||
add("GetFacing", Float, { Object });
|
||||
add("GetItemPossessor", Object, { Object });
|
||||
add("GetItemPossessedBy", Object, { Object, String });
|
||||
add("CreateItemOnObject", Object, { String, Object, Int });
|
||||
add("CreateItemOnObject", Object, { String, Object, Int }, bind(&Routines::createItemOnObject, this, _1, _2));
|
||||
add("ActionEquipItem", Void, { Object, Int, Int });
|
||||
add("ActionUnequipItem", Void, { Object, Int });
|
||||
add("ActionPickUpItem", Void, { Object });
|
||||
|
|
|
@ -17,8 +17,11 @@
|
|||
|
||||
#include "routines.h"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "../../common/log.h"
|
||||
|
||||
#include "../blueprint/blueprints.h"
|
||||
#include "../game.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -134,6 +137,36 @@ Variable Routines::getLocked(const vector<Variable> &args, ExecutionContext &ctx
|
|||
return move(result);
|
||||
}
|
||||
|
||||
Variable Routines::createItemOnObject(const vector<Variable> &args, ExecutionContext &ctx) {
|
||||
Variable result(VariableType::Object);
|
||||
result.objectId = kObjectInvalid;
|
||||
|
||||
string itemBlueprint(args[0].strValue);
|
||||
if (!itemBlueprint.empty()) {
|
||||
boost::to_lower(itemBlueprint);
|
||||
|
||||
int targetId = args.size() >= 2 ? args[1].objectId : kObjectSelf;
|
||||
int count = args.size() >= 3 ? args[2].intValue : 1;
|
||||
|
||||
shared_ptr<Object> target(getObjectById(targetId, ctx));
|
||||
if (target) {
|
||||
shared_ptr<ItemBlueprint> blueprint(Blueprints::instance().getItem(itemBlueprint));
|
||||
shared_ptr<Item> item(_game->objectFactory().newItem());
|
||||
item->load(blueprint);
|
||||
|
||||
shared_ptr<SpatialObject> spatialTarget(dynamic_pointer_cast<SpatialObject>(target));
|
||||
spatialTarget->addItem(item);
|
||||
|
||||
result.objectId = item->id();
|
||||
|
||||
} else {
|
||||
warn("Routine: object not found: " + to_string(targetId));
|
||||
}
|
||||
}
|
||||
|
||||
return move(result);
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
||||
|
|
|
@ -70,7 +70,7 @@ void Routines::addTslRoutines() {
|
|||
add("GetFacing", Float, { Object });
|
||||
add("GetItemPossessor", Object, { Object });
|
||||
add("GetItemPossessedBy", Object, { Object, String });
|
||||
add("CreateItemOnObject", Object, { String, Object, Int, Int });
|
||||
add("CreateItemOnObject", Object, { String, Object, Int, Int }, bind(&Routines::createItemOnObject, this, _1, _2));
|
||||
add("ActionEquipItem", Void, { Object, Int, Int });
|
||||
add("ActionUnequipItem", Void, { Object, Int });
|
||||
add("ActionPickUpItem", Void, { Object });
|
||||
|
|
Loading…
Reference in a new issue