Skip to content

Commit

Permalink
Add CharacterGetPermanentBoost and CharacterSetPermanentBoost APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbyte committed Oct 16, 2019
1 parent c6030b1 commit 30fc0f1
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 2 deletions.
35 changes: 33 additions & 2 deletions APIDocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,37 @@ Updates the total lifetime of the specified game action.
** TODO Documentation **
# Character functions
## Permanent Boosts
Permanent Boosts are stat bonuses or stat reductions that are applied to an item. They are permanent, i.e. are stored in the savegame.
The following stats are supported: SummonLifelinkModifier, Strength, Memory, Intelligence, Movement, MovementSpeedBoost, Finesse, Wits, Constitution, FireResistance, EarthResistance, WaterResistance, AirResistance, PoisonResistance, ShadowResistance, Willpower, Bodybuilding, PiercingResistance, PhysicalResistance, CorrosiveResistance, MagicResistance, CustomResistance, Sight, Hearing, FOV, APMaximum, APStart, APRecovery, CriticalChance, Initiative, Vitality, VitalityBoost, MagicPoints, Level, Gain, Armor, MagicArmor, ArmorBoost, MagicArmorBoost, ArmorBoostGrowthPerLevel, MagicArmorBoostGrowthPerLevel, DamageBoost, DamageBoostGrowthPerLevel, Accuracy, Dodge, MaxResistance, LifeSteal, Weight, ChanceToHitBoost, RangeBoost, APCostBoost, SPCostBoost, MaxSummons, BonusWeaponDamageMultiplier.
**Limitations:**
Permanent boosts don't show up immediately because of how client-server communication works in the game. To ensure that boosts are visible on the client boosts must be synced by performing a no-op call to `CharacterAddAttribute`. Example:
```c
...
NRD_CharacterGetPermanentBoostInt(_Character, "PoisonResistance", _Resistance)
AND
IntegerSum(_Resistance, 10, _NewResistance)
THEN
NRD_CharacterSetPermanentBoostInt(_Character, "PoisonResistance", _NewResistance);
CharacterAddAttribute(_Character, "Dummy", 0); // Force boost sync
```


### CharacterGetPermanentBoost
`query NRD_CharacterGetPermanentBoostInt([in](CHARACTERGUID)_Character, [in](STRING)_Stat, [out](INTEGER)_Value)`

Returns the permanent boost value applied to the specified character. `_Stat` must be one of the values listed above.


### CharacterSetPermanentBoost
`call NRD_CharacterSetPermanentBoostInt((CHARACTERGUID)_Character, (STRING)_Stat, (INTEGER)_Value)`

Updates the permanent boost value of `_Stat` to the specified value . `_Stat` must be one of the values listed above. Both positive and negative boost values are supported.


# Item functions
Expand Down Expand Up @@ -604,8 +635,8 @@ Returns the permanent boost value applied to the specified item. `_Stat` must be


### ItemSetPermanentBoost
`query NRD_ItemGetPermanentBoostInt([in](ITEMGUID)_Item, [in](STRING)_Stat, [out](INTEGER)_Value)`
`query NRD_ItemGetPermanentBoostReal([in](ITEMGUID)_Item, [in](STRING)_Stat, [out](REAL)_Value)`
`call NRD_ItemSetPermanentBoostInt((GUIDSTRING)_Item, (STRING)_Stat, (INTEGER)_Value)`
`call NRD_ItemSetPermanentBoostReal((GUIDSTRING)_Item, (STRING)_Stat, (REAL)_Value)`

Updates the permanent boost value of `_Stat` to the specified value . `_Stat` must be one of the values listed above. Both positive and negative boost values are supported.

Expand Down
73 changes: 73 additions & 0 deletions OsiInterface/Functions/CharacterFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <stdafx.h>
#include "FunctionLibrary.h"
#include <OsirisProxy.h>
#include "PropertyMaps.h"

namespace osidbg
{
namespace func
{
template <OsiPropertyMapType Type>
bool CharacterGetPermanentBoost(OsiArgumentDesc & args)
{
auto character = FindCharacterByNameGuid(args.Get(0).String);
if (character == nullptr) return false;

if (character->Stats == nullptr
|| character->Stats->DynamicStats == nullptr
|| character->Stats->DynamicStatsEnd - character->Stats->DynamicStats < 2) {
OsiError("Character has no permanent boost stats!");
return false;
}

auto permanentBoosts = character->Stats->DynamicStats[1];
return OsirisPropertyMapGet(gCharacterDynamicStatPropertyMap, permanentBoosts, args, 1, Type);
}

template <OsiPropertyMapType Type>
void CharacterSetPermanentBoost(OsiArgumentDesc const & args)
{
auto character = FindCharacterByNameGuid(args.Get(0).String);
if (character == nullptr) return;

if (character->Stats == nullptr
|| character->Stats->DynamicStats == nullptr
|| character->Stats->DynamicStatsEnd - character->Stats->DynamicStats < 2) {
OsiError("Character has no permanent boost stats!");
return;
}

auto permanentBoosts = character->Stats->DynamicStats[1];
OsirisPropertyMapSet(gCharacterDynamicStatPropertyMap, permanentBoosts, args, 1, Type);
}
}

void CustomFunctionLibrary::RegisterCharacterFunctions()
{
auto & functionMgr = osiris_.GetCustomFunctionManager();

auto characterGetPermanentBoostInt = std::make_unique<CustomQuery>(
"NRD_CharacterGetPermanentBoostInt",
std::vector<CustomFunctionParam>{
{ "Character", ValueType::CharacterGuid, FunctionArgumentDirection::In },
{ "Stat", ValueType::String, FunctionArgumentDirection::In },
{ "Value", ValueType::Integer, FunctionArgumentDirection::Out },
},
&func::CharacterGetPermanentBoost<OsiPropertyMapType::Integer>
);
functionMgr.Register(std::move(characterGetPermanentBoostInt));


auto characterSetPermanentBoostInt = std::make_unique<CustomCall>(
"NRD_CharacterSetPermanentBoostInt",
std::vector<CustomFunctionParam>{
{ "Character", ValueType::CharacterGuid, FunctionArgumentDirection::In },
{ "Stat", ValueType::String, FunctionArgumentDirection::In },
{ "Value", ValueType::Integer, FunctionArgumentDirection::In },
},
&func::CharacterSetPermanentBoost<OsiPropertyMapType::Integer>
);
functionMgr.Register(std::move(characterSetPermanentBoostInt));
}

}
1 change: 1 addition & 0 deletions OsiInterface/Functions/FunctionLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ namespace osidbg
RegisterHitFunctions();
RegisterPlayerFunctions();
RegisterItemFunctions();
RegisterCharacterFunctions();

auto & functionMgr = osiris_.GetCustomFunctionManager();

Expand Down
1 change: 1 addition & 0 deletions OsiInterface/Functions/FunctionLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace osidbg
void RegisterHitFunctions();
void RegisterPlayerFunctions();
void RegisterItemFunctions();
void RegisterCharacterFunctions();

void PostStartup();

Expand Down
1 change: 1 addition & 0 deletions OsiInterface/OsiInterface.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ copy /Y "$(TargetPath)" "C:\Program Files (x86)\Steam\steamapps\common\Divinity
</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DxgiWrapper.cpp" />
<ClCompile Include="Functions\CharacterFunctions.cpp" />
<ClCompile Include="Functions\DamageFunctions.cpp" />
<ClCompile Include="Functions\FunctionLibrary.cpp" />
<ClCompile Include="Functions\FunctionUtilities.cpp" />
Expand Down
3 changes: 3 additions & 0 deletions OsiInterface/OsiInterface.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
<ClCompile Include="PropertyMaps.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Functions\CharacterFunctions.cpp">
<Filter>Source Files\Functions</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="Exports.def">
Expand Down

0 comments on commit 30fc0f1

Please sign in to comment.