feat: Implement item stack script routines
This commit is contained in:
parent
c72ef75b12
commit
ee45ac0262
5 changed files with 48 additions and 19 deletions
|
@ -171,6 +171,11 @@ const ExecutionContext &Routines::getAction(const VariablesList &args, int index
|
|||
return args[index].context;
|
||||
}
|
||||
|
||||
shared_ptr<Item> Routines::getItem(const VariablesList &args, int index) const {
|
||||
int argCount = static_cast<int>(args.size());
|
||||
return index < argCount ? dynamic_pointer_cast<Item>(args[index].object) : nullptr;
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
||||
|
|
|
@ -34,6 +34,7 @@ class Creature;
|
|||
class Door;
|
||||
class Event;
|
||||
class Game;
|
||||
class Item;
|
||||
class Location;
|
||||
class Object;
|
||||
class Sound;
|
||||
|
@ -73,24 +74,25 @@ private:
|
|||
void addTslRoutines();
|
||||
|
||||
bool getBool(const VariablesList &args, int index, bool defValue = false) const;
|
||||
int getInt(const VariablesList &args, int index, int defValue = 0) const;
|
||||
const script::ExecutionContext &getAction(const VariablesList &args, int index) const;
|
||||
float getFloat(const VariablesList &args, int index, float defValue = 0.0f) const;
|
||||
std::string getString(const VariablesList &args, int index, std::string defValue = "") const;
|
||||
glm::vec3 getVector(const VariablesList &args, int index, glm::vec3 defValue = glm::vec3(0.0f)) const;
|
||||
std::shared_ptr<Object> getCaller(script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<SpatialObject> getCallerAsSpatial(script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<Object> getTriggerrer(script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<Object> getObject(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Object> getObjectOrCaller(const VariablesList &args, int index, script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<SpatialObject> getSpatialObject(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<SpatialObject> getSpatialObjectOrCaller(const VariablesList &args, int index, script::ExecutionContext &ctx) const;
|
||||
int getInt(const VariablesList &args, int index, int defValue = 0) const;
|
||||
std::shared_ptr<Creature> getCreature(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Creature> getCreatureOrCaller(const VariablesList &args, int index, script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<Door> getDoor(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Sound> getSound(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Location> getLocationEngineType(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Event> getEvent(const VariablesList &args, int index) const;
|
||||
const script::ExecutionContext &getAction(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Item> getItem(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Location> getLocationEngineType(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Object> getCaller(script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<Object> getObject(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<Object> getObjectOrCaller(const VariablesList &args, int index, script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<Object> getTriggerrer(script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<Sound> getSound(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<SpatialObject> getCallerAsSpatial(script::ExecutionContext &ctx) const;
|
||||
std::shared_ptr<SpatialObject> getSpatialObject(const VariablesList &args, int index) const;
|
||||
std::shared_ptr<SpatialObject> getSpatialObjectOrCaller(const VariablesList &args, int index, script::ExecutionContext &ctx) const;
|
||||
std::string getString(const VariablesList &args, int index, std::string defValue = "") const;
|
||||
|
||||
// Common
|
||||
|
||||
|
@ -161,6 +163,7 @@ private:
|
|||
script::Variable getIsObjectValid(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getIsOpen(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getItemInSlot(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getItemStackSize(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getLocked(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getModule(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getNextItemInInventory(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
|
@ -168,6 +171,7 @@ private:
|
|||
script::Variable getPosition(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getTag(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable getWaypointByTag(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable setItemStackSize(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable setLocked(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable soundObjectPlay(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
script::Variable soundObjectStop(const VariablesList &args, script::ExecutionContext &ctx);
|
||||
|
|
|
@ -177,7 +177,7 @@ void Routines::addKotorRoutines() {
|
|||
add("ActionGiveItem", Void, { Object, Object });
|
||||
add("ActionTakeItem", Void, { Object, Object });
|
||||
add("VectorNormalize", TVector, { TVector }, bind(&Routines::vectorNormalize, this, _1, _2));
|
||||
add("GetItemStackSize", Int, { Object });
|
||||
add("GetItemStackSize", Int, { Object }, bind(&Routines::getItemStackSize, this, _1, _2));
|
||||
add("GetAbilityScore", Int, { Object, Int }, bind(&Routines::getAbilityScore, this, _1, _2));
|
||||
add("GetIsDead", Int, { Object }, bind(&Routines::getIsDead, this, _1, _2));
|
||||
add("PrintVector", Void, { TVector, Int }, bind(&Routines::printVector, this, _1, _2));
|
||||
|
@ -189,7 +189,7 @@ void Routines::addKotorRoutines() {
|
|||
add("TouchAttackRanged", Int, { Object, Int });
|
||||
add("EffectParalyze", Effect, { }, bind(&Routines::effectParalyze, this, _1, _2));
|
||||
add("EffectSpellImmunity", Effect, { Int }, bind(&Routines::effectSpellImmunity, this, _1, _2));
|
||||
add("SetItemStackSize", Void, { Object, Int });
|
||||
add("SetItemStackSize", Void, { Object, Int }, bind(&Routines::setItemStackSize, this, _1, _2));
|
||||
add("GetDistanceBetween", Float, { Object, Object }, bind(&Routines::getDistanceBetween, this, _1, _2));
|
||||
add("SetReturnStrref", Void, { Int, Int, Int });
|
||||
add("EffectForceJump", Effect, { Object, Int }, bind(&Routines::effectForceJump, this, _1, _2));
|
||||
|
@ -514,7 +514,7 @@ void Routines::addKotorRoutines() {
|
|||
add("EffectSpellLevelAbsorption", Effect, { Int, Int, Int }, bind(&Routines::effectSpellLevelAbsorption, this, _1, _2));
|
||||
add("EffectDispelMagicBest", Effect, { Int }, bind(&Routines::effectDispelMagicBest, this, _1, _2));
|
||||
add("GetCurrentStealthXP", Int, { });
|
||||
add("GetNumStackedItems", Int, { Object });
|
||||
add("GetNumStackedItems", Int, { Object }, bind(&Routines::getItemStackSize, this, _1, _2));
|
||||
add("SurrenderToEnemies", Void, { });
|
||||
add("EffectMissChance", Effect, { Int }, bind(&Routines::effectMissChance, this, _1, _2));
|
||||
add("SetCurrentStealthXP", Void, { Int });
|
||||
|
|
|
@ -302,7 +302,7 @@ Variable Routines::getIsInCombat(const VariablesList &args, ExecutionContext &ct
|
|||
return creature->isInCombat();
|
||||
}
|
||||
|
||||
Variable Routines::getIsOpen(const VariablesList & args, ExecutionContext & ctx) {
|
||||
Variable Routines::getIsOpen(const VariablesList &args, ExecutionContext &ctx) {
|
||||
auto object = getSpatialObject(args, 0);
|
||||
if (!object) {
|
||||
warn("Routines: getIsOpen: object is invalid");
|
||||
|
@ -311,6 +311,26 @@ Variable Routines::getIsOpen(const VariablesList & args, ExecutionContext & ctx)
|
|||
return object->isOpen();
|
||||
}
|
||||
|
||||
Variable Routines::getItemStackSize(const VariablesList &args, ExecutionContext &ctx) {
|
||||
auto item = getItem(args, 0);
|
||||
if (!item) {
|
||||
warn("Routines: getItemStackSize: item is invalid");
|
||||
return 0;
|
||||
}
|
||||
return item->stackSize();
|
||||
}
|
||||
|
||||
Variable Routines::setItemStackSize(const VariablesList &args, ExecutionContext &ctx) {
|
||||
auto item = getItem(args, 0);
|
||||
if (item) {
|
||||
int stackSize = getInt(args, 1);
|
||||
item->setStackSize(stackSize);
|
||||
} else {
|
||||
warn("Routines: setItemStackSize: item is invalid");
|
||||
}
|
||||
return Variable();
|
||||
}
|
||||
|
||||
} // namespace game
|
||||
|
||||
} // namespace reone
|
||||
|
|
|
@ -177,7 +177,7 @@ void Routines::addTslRoutines() {
|
|||
add("ActionGiveItem", Void, { Object, Object });
|
||||
add("ActionTakeItem", Void, { Object, Object });
|
||||
add("VectorNormalize", TVector, { TVector }, bind(&Routines::vectorNormalize, this, _1, _2));
|
||||
add("GetItemStackSize", Int, { Object });
|
||||
add("GetItemStackSize", Int, { Object }, bind(&Routines::getItemStackSize, this, _1, _2));
|
||||
add("GetAbilityScore", Int, { Object, Int }, bind(&Routines::getAbilityScore, this, _1, _2));
|
||||
add("GetIsDead", Int, { Object }, bind(&Routines::getIsDead, this, _1, _2));
|
||||
add("PrintVector", Void, { TVector, Int }, bind(&Routines::printVector, this, _1, _2));
|
||||
|
@ -189,7 +189,7 @@ void Routines::addTslRoutines() {
|
|||
add("TouchAttackRanged", Int, { Object, Int });
|
||||
add("EffectParalyze", Effect, { }, bind(&Routines::effectParalyze, this, _1, _2));
|
||||
add("EffectSpellImmunity", Effect, { Int }, bind(&Routines::effectSpellImmunity, this, _1, _2));
|
||||
add("SetItemStackSize", Void, { Object, Int });
|
||||
add("SetItemStackSize", Void, { Object, Int }, bind(&Routines::setItemStackSize, this, _1, _2));
|
||||
add("GetDistanceBetween", Float, { Object, Object }, bind(&Routines::getDistanceBetween, this, _1, _2));
|
||||
add("SetReturnStrref", Void, { Int, Int, Int });
|
||||
add("EffectForceJump", Effect, { Object, Int }, bind(&Routines::effectForceJump, this, _1, _2));
|
||||
|
@ -514,7 +514,7 @@ void Routines::addTslRoutines() {
|
|||
add("EffectSpellLevelAbsorption", Effect, { Int, Int, Int }, bind(&Routines::effectSpellLevelAbsorption, this, _1, _2));
|
||||
add("EffectDispelMagicBest", Effect, { Int }, bind(&Routines::effectDispelMagicBest, this, _1, _2));
|
||||
add("GetCurrentStealthXP", Int, { });
|
||||
add("GetNumStackedItems", Int, { Object });
|
||||
add("GetNumStackedItems", Int, { Object }, bind(&Routines::getItemStackSize, this, _1, _2));
|
||||
add("SurrenderToEnemies", Void, { });
|
||||
add("EffectMissChance", Effect, { Int }, bind(&Routines::effectMissChance, this, _1, _2));
|
||||
add("SetCurrentStealthXP", Void, { Int });
|
||||
|
|
Loading…
Reference in a new issue