Skip to content

Commit

Permalink
Added Prayer Beads (Karma) effect + some support for python item cond…
Browse files Browse the repository at this point in the history
…itions
  • Loading branch information
DMD authored and DMD committed Sep 3, 2016
1 parent 03317fe commit 20e3013
Show file tree
Hide file tree
Showing 13 changed files with 126 additions and 8 deletions.
31 changes: 30 additions & 1 deletion TemplePlus/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1879,6 +1879,35 @@ void ConditionSystem::InitCondFromCondStructAndArgs(Dispatcher* dispatcher, Cond
}
}

void ConditionSystem::InitItemCondFromCondStructAndArgs(Dispatcher * dispatcher, CondStruct * condStruct, int * condargs){
CondNode **node;
SubDispNode *subDispNode;
CondNode *condNode;

auto *condNodeNew = new CondNode(condStruct);
node = &dispatcher->itemConds;
while (*node)
{
node = &(*node)->nextCondNode;
}
*node = condNodeNew;

for (auto i = 0u; i < condStruct->numArgs; i++) {
condNodeNew->args[i] = condargs[i];
}

conds.CondNodeAddToSubDispNodeArray(dispatcher, condNodeNew);
for (subDispNode = dispatcher->subDispNodes[dispTypeConditionAddFromD20StatusInit]; subDispNode; subDispNode = subDispNode->next)
{
if (subDispNode->subDispDef->dispKey == 0)
{
condNode = subDispNode->condNode;
if (!(condNode->flags & 1) && condNode == condNodeNew)
subDispNode->subDispDef->dispCallback(subDispNode, dispatcher->objHnd, dispTypeConditionAddFromD20StatusInit, 0, nullptr);
}
}
}

void ConditionSystem::RegisterNewConditions()
{

Expand Down Expand Up @@ -4569,7 +4598,7 @@ int ClassAbilityCallbacks::SneakAttackDamage(DispatcherCallbackArgs args) {

auto sneakDmgDice = Dice(sneakAttackDice, 6, 0);
if (feats.HasFeatCountByClass(args.objHndCaller, FEAT_DEADLY_PRECISION)) {
sneakDmgDice = Dice(sneakAttackDice, 5, 1);
sneakDmgDice = Dice(sneakAttackDice, 5, 1*sneakAttackDice);
}
dispIo->damage.AddDamageDice(sneakDmgDice.ToPacked(), DamageType::Unspecified, 106);
floatSys.FloatCombatLine(args.objHndCaller, 90); // Sneak Attack!
Expand Down
2 changes: 2 additions & 0 deletions TemplePlus/condition.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ struct ConditionSystem : temple::AddressTable

void CondNodeAddToSubDispNodeArray(Dispatcher* dispatcher, CondNode* condNodeNew);
void InitCondFromCondStructAndArgs(Dispatcher* dispatcher, CondStruct* condStruct, int* condargs);
void InitItemCondFromCondStructAndArgs(Dispatcher* dispatcher, CondStruct* condStruct, int* condargs);


#pragma endregion
void RegisterNewConditions();
Expand Down
33 changes: 31 additions & 2 deletions TemplePlus/d20_status.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "temple_functions.h"
#include "d20_obj_registry.h"
#include "gamesystems/objects/objsystem.h"

#include <gamesystems/gamesystems.h>



Expand Down Expand Up @@ -289,14 +289,43 @@ void D20StatusSystem::initItemConditions(objHndl objHnd)
auto item = objSystem->GetObject(objHndItem);
uint32_t itemInvLocation = item->GetInt32(obj_f_item_inv_location);
if (inventory.IsItemEffectingConditions(objHndItem, itemInvLocation)) {
inventory.sub_100FF500(dispatcher, objHndItem, itemInvLocation);
//inventory.sub_100FF500(dispatcher, objHndItem, itemInvLocation);
InitFromItemConditionFields(dispatcher, objHndItem, itemInvLocation);
}
}
}

}
}

void D20StatusSystem::InitFromItemConditionFields(Dispatcher * dispatcher, objHndl item, int invIdx){

auto itemObj = gameSystems->GetObj().GetObject(item);
auto &itemConds = itemObj->GetInt32Array(obj_f_item_pad_wielder_condition_array);
auto itemArgs = itemObj->GetInt32Array(obj_f_item_pad_wielder_argument_array);
int condArgs[64];

auto argIdx = 0u;
for (auto i = 0u; i < itemConds.GetSize(); i++){
auto condId = itemConds[i];
auto condStruct = conds.GetById(condId);
if (!condStruct){
logger->warn("Item condition not found!");
continue;
}

for (auto j=0u; j<condStruct->numArgs; j++) {
condArgs[j] = itemArgs[argIdx++];
}
condArgs[2] = invIdx;

conds.InitItemCondFromCondStructAndArgs(dispatcher, condStruct, condArgs);

}


}

void D20StatusSystem::D20StatusInitFromInternalFields(objHndl objHnd, Dispatcher* dispatcher)
{
CondStruct *condStruct;
Expand Down
1 change: 1 addition & 0 deletions TemplePlus/d20_status.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class D20StatusSystem
void initDomains(objHndl objHnd);
void initFeats(objHndl objHnd);
void initItemConditions(objHndl objHnd);
void InitFromItemConditionFields(Dispatcher* dispatcher, objHndl item, int invIdx);
void D20StatusInitFromInternalFields(objHndl objHnd, Dispatcher *dispatcher);

std::map<Stat, std::string> classCondMap = {
Expand Down
30 changes: 27 additions & 3 deletions TemplePlus/python/python_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ PYBIND11_PLUGIN(tp_dispatcher){
condStr.Register();
}
})
;
.def("add_item_force_remove_callback", [](CondStructNew &condStr){
condStr.AddHook(dispTypeItemForceRemove, DK_NONE, temple::GetRef<int(__cdecl*)(DispatcherCallbackArgs)>(0x10104410));
})
;



Expand All @@ -119,6 +122,10 @@ PYBIND11_PLUGIN(tp_dispatcher){
.def("get_arg", &DispatcherCallbackArgs::GetCondArg)
.def("set_arg", &DispatcherCallbackArgs::SetCondArg)
.def_readwrite("evt_obj", &DispatcherCallbackArgs::dispIO)
.def("condition_remove", [](DispatcherCallbackArgs& args)
{
conds.ConditionRemove(args.objHndCaller, args.subDispNode->condNode);
})
;

#pragma region useful data types
Expand Down Expand Up @@ -242,6 +249,7 @@ PYBIND11_PLUGIN(tp_dispatcher){

py::class_<RadialMenuEntryAction>(m, "RadialMenuEntryAction", py::base<RadialMenuEntry>())
.def(py::init<int, int, int, const char[]>(), py::arg("combesMesLine"), py::arg("action_type"), py::arg("data1"), py::arg("helpTopic"))
.def(py::init<std::string&, int, int, std::string&>(), py::arg("radialText"), py::arg("action_type"), py::arg("data1"), py::arg("helpTopic"))
;
py::class_<RadialMenuEntryPythonAction>(m, "RadialMenuEntryPythonAction", py::base<RadialMenuEntryAction>())
.def(py::init<int, int, int, int, const char[]>(), py::arg("combatMesLine"), py::arg("action_type"), py::arg("action_id"), py::arg("data1"), py::arg("helpTopic"))
Expand Down Expand Up @@ -290,6 +298,16 @@ PYBIND11_PLUGIN(tp_dispatcher){
return spellSys.GetSpellLevelBySpellClass(spEntry.spellEnum, spellClass);
})
;

py::class_<SpellPacketBody>(m, "SpellPacket")
.def_readwrite("spell_enum", &SpellPacketBody::spellEnum)
.def_readwrite("inventory_idx", &SpellPacketBody::invIdx)
.def_readwrite("spell_entry", &SpellPacketBody::spellEntry)
.def_readwrite("spell_class", &SpellPacketBody::spellClass)
.def_readwrite("spell_id", &SpellPacketBody::spellId)
.def_readwrite("caster_level", &SpellPacketBody::casterLevel)
.def("is_divine_spell", &SpellPacketBody::IsDivine)
;
#pragma endregion


Expand Down Expand Up @@ -328,13 +346,19 @@ PYBIND11_PLUGIN(tp_dispatcher){
.def(py::init())
.def_readwrite("return_val", &DispIoD20Signal::return_val)
.def_readwrite("data1", &DispIoD20Signal::data1)
.def_readwrite("data2", &DispIoD20Signal::data2);
.def_readwrite("data2", &DispIoD20Signal::data2)
;

py::class_<DispIoD20Query>(m, "EventObjD20Query", py::base<DispIO>())
.def(py::init())
.def_readwrite("return_val", &DispIoD20Query::return_val)
.def_readwrite("data1", &DispIoD20Query::data1)
.def_readwrite("data2", &DispIoD20Query::data2);
.def_readwrite("data2", &DispIoD20Query::data2)
.def("get_spell_packet", [](DispIoD20Query& evtObj)->SpellPacketBody& {
SpellPacketBody* spPkt = (SpellPacketBody*)evtObj.data1;
return *spPkt;
}, "Used for CasterLevelMod callbacks to get a spellpacket from the data1 field")
;

py::class_<DispIOTurnBasedStatus>(m, "EventObjTurnBasedStatus", py::base<DispIO>())
.def(py::init())
Expand Down
15 changes: 15 additions & 0 deletions TemplePlus/radialmenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,21 @@ RadialMenuEntryAction::RadialMenuEntryAction(int combatMesLine, int d20aType, in
{
}

RadialMenuEntryAction::RadialMenuEntryAction(std::string & textArg, int d20aType, int data1, std::string & helpId) : RadialMenuEntry()
{
type = RadialMenuEntryType::Action;
auto textId = ElfHash::Hash(textArg);
auto textCache = radialMenus.radMenuStrings.find(textId);
if (textCache == radialMenus.radMenuStrings.end()){
radialMenus.radMenuStrings[textId] = textArg;
}

this->text = (char*)radialMenus.radMenuStrings[textId].c_str();
this->helpId = ElfHash::Hash(helpId);
d20ActionType = static_cast<D20ActionType>(d20aType);
d20ActionData1 = data1;
}

RadialMenuEntryToggle::RadialMenuEntryToggle(int combatMesLine, void* ActualArg, const char HelpId[]): RadialMenuEntry()
{
type = RadialMenuEntryType::Toggle;
Expand Down
4 changes: 4 additions & 0 deletions TemplePlus/radialmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#pragma once

#include "common.h"
#include <map>

/*
Data structures
Expand Down Expand Up @@ -106,6 +107,7 @@ struct RadialMenuEntryAction : RadialMenuEntry
RadialMenuEntryAction(int combatMesLine, D20ActionType d20aType, int data1, uint32_t helpId);
RadialMenuEntryAction(int combatMesLine, D20ActionType d20aType, int data1, const char helpId[]);
RadialMenuEntryAction(int combatMesLine, int d20aType, int data1, const char helpId[]);
RadialMenuEntryAction(std::string & text, int d20aType, int data1, std::string & helpId);
};

struct RadialMenuEntryPythonAction : RadialMenuEntryAction
Expand Down Expand Up @@ -202,6 +204,8 @@ class RadialMenus {
RadialMenu* GetActiveRadialMenu() const;
int GetActiveMenuChildrenCount(int activeNodeIdx) const;
BOOL PythonActionCallback(const objHndl& handle, RadialMenuEntry* entry);

std::map<int, std::string> radMenuStrings;
};

extern RadialMenus radialMenus;
11 changes: 11 additions & 0 deletions TemplePlus/spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,17 @@ bool SpellPacketBody::IsVancian(){
return false;
}

bool SpellPacketBody::IsDivine(){
if (spellSys.isDomainSpell(spellClass))
return true;
auto castingClass = spellSys.GetCastingClass(spellClass);

if (d20ClassSys.IsDivineCastingClass(castingClass))
return true;

return false;
}

void SpellPacketBody::Debit(){
// preamble
if (!caster){
Expand Down
1 change: 1 addition & 0 deletions TemplePlus/spell.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct SpellPacketBody{
bool SavingThrow(objHndl target, D20SavingThrowFlag flags);
const char* GetName(); // get the spell name
bool IsVancian();
bool IsDivine();
void Debit(); // debit from the caster's memorized / daily casted spells
void MemorizedUseUp(SpellStoreData &spellData); // mark memorized spell as used up
void Reset();
Expand Down
2 changes: 1 addition & 1 deletion TemplePlus/ui/ui_party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class UiPartyHooks : public TempleFix {
static char* (__cdecl* orgBuffDebuffGetBaseText)(BuffDebuffPacket*, int, int) =
replaceFunction<char*(__cdecl)(BuffDebuffPacket* , int , int )>(0x100F45A0, [](BuffDebuffPacket* bdb, int iconType, int iconIdx)->char*{
if (iconType == 0){ // buff
auto spEnum = bdb->buffs[bdb->buffCount - 1].spellEnum;
auto spEnum = bdb->buffs[iconIdx ].spellEnum;
if (spEnum == -2){
return "";
}
Expand Down
Binary file modified tpdata/co8fixes.dat
Binary file not shown.
4 changes: 3 additions & 1 deletion tpdata/templeplus/lib/templeplus/pymod.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ class PythonModifier(tpdp.ModifierSpec):
def AddHook(self, eventType, eventKey, callShit, argsTuple ):
self.add_hook(eventType, eventKey, callShit, argsTuple)
def ExtendExisting(self, condName):
self.extend_existing(condName)
self.extend_existing(condName)
def AddItemForceRemoveHandler(self): # in charge of backing up condition args
self.add_item_force_remove_callback()
Binary file modified tpdata/tpgamefiles.dat
Binary file not shown.

0 comments on commit 20e3013

Please sign in to comment.