Skip to content

Commit

Permalink
Blackguard
Browse files Browse the repository at this point in the history
  • Loading branch information
DMD authored and DMD committed Sep 30, 2016
1 parent e20ac42 commit 1b3dea2
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
63 changes: 63 additions & 0 deletions TemplePlus/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class GenericCallbacks
static int __cdecl PowerAttackDamageBonus(DispatcherCallbackArgs args);
static int __cdecl GlobalWieldedTwoHandedQuery(DispatcherCallbackArgs args);

static int __cdecl GlobalHpChanged(DispatcherCallbackArgs args);


static int __cdecl HasCondition(DispatcherCallbackArgs args);

Expand Down Expand Up @@ -1026,6 +1028,67 @@ int GenericCallbacks::GlobalWieldedTwoHandedQuery(DispatcherCallbackArgs args)
return 0;
}

int GenericCallbacks::GlobalHpChanged(DispatcherCallbackArgs args){
GET_DISPIO(dispIoTypeSendSignal, DispIoD20Signal);

auto handle = args.objHndCaller;
auto obj = objSystem->GetObject(handle);

auto hpCur = objects.StatLevelGet(handle, stat_hp_current);
auto subdualDam = obj->GetInt32(obj_f_critter_subdual_damage);
auto lastHitBy = obj->GetObjHndl(obj_f_last_hit_by);
auto hpChange = dispIo->data2;

// Kill
if (hpCur <= -10){
critterSys.Kill(handle);
return 0;
}

auto isUncon = critterSys.IsDeadOrUnconscious(handle);


auto addDisabled = false;
auto knockedOut = false;
auto isDying = false;
auto hasDiehard = feats.HasFeatCountByClass(args.objHndCaller, FEAT_DIEHARD);

if (hpCur < 0 && !hasDiehard){
knockedOut = true;
if (hpChange < 0){
isDying = true;
}
}
if (subdualDam >= hpCur){
if (!hasDiehard)
knockedOut = true;
else
knockedOut = subdualDam >= hpCur + 10;
}

// Knock Unconscious
if (knockedOut){
d20Sys.D20SignalPython(handle, "Knocked Unconscious");
if (!isUncon){
auto animId = Dice::Roll(1, 3, 72); // roll number between 73-75
animationGoals.PushFallDown(handle, animId);
}
if (isDying){
conds.AddTo(handle, "Dying", {});
return 0;
}
conds.AddTo(handle, "Unconscious", {});
return 0;
}
// Mark Disabled
else if (hpCur <= 0 ) {
conds.AddTo(args.objHndCaller, "Disabled", {});
return 0;
}

return 0;
}

int GenericCallbacks::HasCondition(DispatcherCallbackArgs args){
args.dispIO->AssertType(dispIOTypeQuery);
auto dispIo = static_cast<DispIoD20Query*>(args.dispIO);
Expand Down
7 changes: 4 additions & 3 deletions TemplePlus/python/python_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ PYBIND11_PLUGIN(tp_dispatcher){
#pragma region useful data types


#pragma region Bonuslist etc
#pragma region Bonuslist etc
py::class_<BonusList>(m, "BonusList")
.def(py::init())
.def("add", [](BonusList & bonlist, int value, int bonType, int mesline) {
Expand Down Expand Up @@ -271,9 +271,9 @@ PYBIND11_PLUGIN(tp_dispatcher){
.def_readwrite("flags", &TurnBasedStatus::tbsFlags)
.def_readwrite("attack_mode_code", &TurnBasedStatus::attackModeCode, "0 - normal main hand, 99 - dual wielding, 999 - natural attack")
;
#pragma endregion

#pragma endregion

#pragma region Radial Menu Enums
py::enum_<RadialMenuStandardNode>(m, "RadialMenuStandardNode")
.value("Root", Root)
.value("Spells", Spells)
Expand Down Expand Up @@ -311,6 +311,7 @@ PYBIND11_PLUGIN(tp_dispatcher){
.value("EndEarlyMulti", UiPickerType::EndEarlyMulti)
.value("LocIsClear", UiPickerType::LocIsClear)
;
#pragma endregion

py::class_<RadialMenuEntry>(m, "RadialMenuEntry")
.def(py::init())
Expand Down
7 changes: 6 additions & 1 deletion TemplePlus/python/python_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,9 +1126,14 @@ static bool ParseCondNameAndArgs(PyObject* args, CondStruct*& condStructOut, vec
for (unsigned int i = 0; i < cond->numArgs; ++i) {
if ((uint32_t) PyTuple_GET_SIZE(args) > i + 1) {
auto item = PyTuple_GET_ITEM(args, i + 1);
if (PyLong_Check(item)){
condArgs[i] = PyLong_AsLong(item);
continue;
}

if (!PyInt_Check(item)) {
auto itemRepr = PyObject_Repr(item);
PyErr_Format(PyExc_ValueError, "Argument %d for condition %s (requires %d args) is not of type int: %s",
PyErr_Format(PyExc_ValueError, "Argument %d for condition %s (requires %d args) is not of type int or long: %s",
i + 1, condName, cond->numArgs, PyString_AsString(itemRepr));
Py_DECREF(itemRepr);
return false;
Expand Down
Binary file modified tpdata/tpgamefiles.dat
Binary file not shown.

0 comments on commit 1b3dea2

Please sign in to comment.