From 6e474f22a20717dcf951b1e316c9a0a4e3d18b33 Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Tue, 18 Feb 2014 16:52:51 -0500 Subject: [PATCH] Added single target HalveAggro and DoubleAggro Both exported to perl/lua pass the target you wish to change their hate. --- zone/lua_mob.cpp | 12 +++++++++ zone/lua_mob.h | 4 ++- zone/mob.h | 2 ++ zone/perl_mob.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index 851c1293a..673fb63ab 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -908,6 +908,16 @@ void Lua_Mob::SetHate(Lua_Mob other, int hate, int damage) { self->SetHate(other, hate, damage); } +void Lua_Mob::HalveAggro(Lua_Mob other) { + Lua_Safe_Call_Void(); + self->HalveAggro(other); +} + +void Lua_Mob::DoubleAggro(Lua_Mob other) { + Lua_Safe_Call_Void(); + self->DoubleAggro(other); +} + uint32 Lua_Mob::GetHateAmount(Lua_Mob target) { Lua_Safe_Call_Int(); return self->GetHateAmount(target); @@ -1962,6 +1972,8 @@ luabind::scope lua_register_mob() { .def("SetHate", (void(Lua_Mob::*)(Lua_Mob))&Lua_Mob::SetHate) .def("SetHate", (void(Lua_Mob::*)(Lua_Mob,int))&Lua_Mob::SetHate) .def("SetHate", (void(Lua_Mob::*)(Lua_Mob,int,int))&Lua_Mob::SetHate) + .def("HalveAggro", &Lua_Mob::HalveAggro) + .def("DoubleAggro", &Lua_Mob::DoubleAggro) .def("GetHateAmount", (uint32(Lua_Mob::*)(Lua_Mob))&Lua_Mob::GetHateAmount) .def("GetHateAmount", (uint32(Lua_Mob::*)(Lua_Mob,bool))&Lua_Mob::GetHateAmount) .def("GetDamageAmount", (uint32(Lua_Mob::*)(Lua_Mob))&Lua_Mob::GetDamageAmount) diff --git a/zone/lua_mob.h b/zone/lua_mob.h index 160fae5ad..b0ad150fd 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -192,6 +192,8 @@ public: void SetHate(Lua_Mob other); void SetHate(Lua_Mob other, int hate); void SetHate(Lua_Mob other, int hate, int damage); + void HalveAggro(Lua_Mob other); + void DoubleAggro(Lua_Mob other); uint32 GetHateAmount(Lua_Mob target); uint32 GetHateAmount(Lua_Mob target, bool is_damage); uint32 GetDamageAmount(Lua_Mob target); @@ -345,4 +347,4 @@ public: }; #endif -#endif \ No newline at end of file +#endif diff --git a/zone/mob.h b/zone/mob.h index 9220844e2..7f64fbd90 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -427,6 +427,8 @@ public: bool bFrenzy = false, bool iBuffTic = false); bool RemoveFromHateList(Mob* mob); void SetHate(Mob* other, int32 hate = 0, int32 damage = 0) { hate_list.Set(other,hate,damage);} + void HalveAggro(Mob *other) { uint32 in_hate = GetHateAmount(other); SetHate(other, (in_hate > 1 ? in_hate / 2 : 1)); } + void DoubleAggro(Mob *other) { uint32 in_hate = GetHateAmount(other); SetHate(other, (in_hate ? in_hate * 2 : 1)); } uint32 GetHateAmount(Mob* tmob, bool is_dam = false) { return hate_list.GetEntHate(tmob,is_dam);} uint32 GetDamageAmount(Mob* tmob) { return hate_list.GetEntHate(tmob, true);} Mob* GetHateTop() { return hate_list.GetTop(this);} diff --git a/zone/perl_mob.cpp b/zone/perl_mob.cpp index 13698cea9..a2958db27 100644 --- a/zone/perl_mob.cpp +++ b/zone/perl_mob.cpp @@ -5341,6 +5341,72 @@ XS(XS_Mob_SetHate) XSRETURN_EMPTY; } +XS(XS_Mob_HalveAggro); +XS(XS_Mob_HalveAggro) +{ + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Mob::HalveAggro(THIS, other)"); + { + Mob * THIS; + Mob * other; + + if (sv_derived_from(ST(0), "Mob")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Mob *,tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Mob"); + if(THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + if (sv_derived_from(ST(1), "Mob")) { + IV tmp = SvIV((SV*)SvRV(ST(1))); + other = INT2PTR(Mob *,tmp); + } + else + Perl_croak(aTHX_ "other is not of type Mob"); + if(other == nullptr) + Perl_croak(aTHX_ "other is nullptr, avoiding crash."); + + THIS->HalveAggro(other); + } + XSRETURN_EMPTY; +} + +XS(XS_Mob_DoubleAggro); +XS(XS_Mob_DoubleAggro) +{ + dXSARGS; + if (items != 2) + Perl_croak(aTHX_ "Usage: Mob::DoubleAggro(THIS, other)"); + { + Mob * THIS; + Mob * other; + + if (sv_derived_from(ST(0), "Mob")) { + IV tmp = SvIV((SV*)SvRV(ST(0))); + THIS = INT2PTR(Mob *,tmp); + } + else + Perl_croak(aTHX_ "THIS is not of type Mob"); + if(THIS == nullptr) + Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); + + if (sv_derived_from(ST(1), "Mob")) { + IV tmp = SvIV((SV*)SvRV(ST(1))); + other = INT2PTR(Mob *,tmp); + } + else + Perl_croak(aTHX_ "other is not of type Mob"); + if(other == nullptr) + Perl_croak(aTHX_ "other is nullptr, avoiding crash."); + + THIS->DoubleAggro(other); + } + XSRETURN_EMPTY; +} + XS(XS_Mob_GetHateAmount); /* prototype to pass -Wmissing-prototypes */ XS(XS_Mob_GetHateAmount) { @@ -8274,6 +8340,8 @@ XS(boot_Mob) newXSproto(strcpy(buf, "IsRooted"), XS_Mob_IsRooted, file, "$"); newXSproto(strcpy(buf, "AddToHateList"), XS_Mob_AddToHateList, file, "$$;$$$$$"); newXSproto(strcpy(buf, "SetHate"), XS_Mob_SetHate, file, "$$;$$"); + newXSproto(strcpy(buf, "HalveAggro"), XS_Mob_HalveAggro, file, "$$"); + newXSproto(strcpy(buf, "DoubleAggro"), XS_Mob_DoubleAggro, file, "$$"); newXSproto(strcpy(buf, "GetHateAmount"), XS_Mob_GetHateAmount, file, "$$;$"); newXSproto(strcpy(buf, "GetDamageAmount"), XS_Mob_GetDamageAmount, file, "$$"); newXSproto(strcpy(buf, "GetHateTop"), XS_Mob_GetHateTop, file, "$");