From 065363480f14c88c5604ea97c692e65e21d82f83 Mon Sep 17 00:00:00 2001 From: KimLS Date: Wed, 17 Jun 2015 12:05:09 -0700 Subject: [PATCH] Added AA grant to quest system, fixed a bug here or there noticed incrementaa needs to be fixed or removed --- zone/aa.cpp | 55 ++++++++++++++++++++++++++--- zone/aa_ability.h | 1 - zone/aa_rank.h | 1 - zone/client.cpp | 4 +++ zone/lua_mob.cpp | 24 +++++++++++++ zone/lua_mob.h | 4 +++ zone/mob.h | 1 + zone/perl_mob.cpp | 90 +++++++++++++++++++++++++++++++++++++++++++++-- zone/spells.cpp | 2 +- 9 files changed, 171 insertions(+), 11 deletions(-) diff --git a/zone/aa.cpp b/zone/aa.cpp index 21e1de1b2..741a15aff 100644 --- a/zone/aa.cpp +++ b/zone/aa.cpp @@ -1015,6 +1015,7 @@ void Client::PurchaseAlternateAdvancementRank(int rank_id) { NotifyNewTitlesAvailable(); } +//need to rewrite this void Client::IncrementAlternateAdvancementRank(int rank_id) { AA::Rank *rank = zone->GetAlternateAdvancementRank(rank_id); if(!rank) { @@ -1139,8 +1140,6 @@ void Client::ActivateAlternateAdvancementAbility(int rank_id, int target_id) { if(!SpellFinished(rank->spell, entity_list.GetMob(target_id), 10, -1, -1, spells[rank->spell].ResistDiff, false)) { return; } - CastToClient()->GetPTimers().Start(rank->spell_type, cooldown); - SendAlternateAdvancementTimer(rank->spell_type, 0, 0); ExpendAlternateAdvancementCharge(ability->id); } else { if(!CastSpell(rank->spell, target_id, USE_ITEM_SPELL_SLOT, -1, -1, 0, -1, rank->spell_type + pTimerAAStart, cooldown, nullptr, rank->id)) { @@ -1312,6 +1311,8 @@ uint32 Mob::GetAAByAAID(uint32 aa_id, uint32 *charges) const { return iter->second.first; } } + + return 0; } bool Mob::SetAA(uint32 rank_id, uint32 new_value, uint32 charges) { @@ -1474,9 +1475,14 @@ void Zone::LoadAlternateAdvancement() { current->total_cost = current->cost + current->prev->total_cost; } else { + current->prev_id = -1; current->total_cost = current->cost; } + if(!current->next) { + current->next_id = -1; + } + i++; current = current->next; } @@ -1490,7 +1496,8 @@ bool ZoneDatabase::LoadAlternateAdvancementAbilities(std::unordered_mapprev_id = atoi(row[10]); rank->next_id = atoi(row[11]); rank->expansion = atoi(row[12]); - rank->account_time_required = atoul(row[13]); rank->base_ability = nullptr; rank->total_cost = 0; rank->next = nullptr; @@ -1606,3 +1612,42 @@ bool ZoneDatabase::LoadAlternateAdvancementAbilities(std::unordered_mapGetAlternateAdvancementAbilityAndRank(aa_id, points); + auto ability = ability_rank.first; + auto rank = ability_rank.second; + + if(!ability) { + return; + } + + if(ability->charges > 0) { + return; + } + + if(!ability->grant_only) { + return; + } + + if(!CanUseAlternateAdvancementRank(rank)) { + return; + } + + SetAA(ability->first_rank_id, rank->current_value, 0); + + if(IsClient()) { + Client *c = CastToClient(); + + if(rank->next) { + c->SendAlternateAdvancementRank(rank->base_ability->id, rank->next->current_value); + } + + c->SendAlternateAdvancementPoints(); + c->SendAlternateAdvancementStats(); + c->CalcBonuses(); + } +} \ No newline at end of file diff --git a/zone/aa_ability.h b/zone/aa_ability.h index ba152fb06..4a2d41f3e 100644 --- a/zone/aa_ability.h +++ b/zone/aa_ability.h @@ -39,7 +39,6 @@ public: ~Ability() { } Rank *GetMaxRank(); - Rank *GetRankByLevel(int level); Rank *GetRankByPointsSpent(int current_level); int GetMaxLevel(Mob *who); diff --git a/zone/aa_rank.h b/zone/aa_rank.h index a824f2c82..977a07680 100644 --- a/zone/aa_rank.h +++ b/zone/aa_rank.h @@ -45,7 +45,6 @@ public: Rank *next; int current_value; int expansion; - uint32 account_time_required; int total_cost; Ability *base_ability; std::vector effects; diff --git a/zone/client.cpp b/zone/client.cpp index 5ef3e84e5..0ce7292ef 100644 --- a/zone/client.cpp +++ b/zone/client.cpp @@ -533,6 +533,10 @@ bool Client::SaveAA() { if(!ability) continue; + if(ability->grant_only) { + continue; + } + if(rank.second.first > 0) { AA::Rank *r = ability->GetRankByPointsSpent(rank.second.first); diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index 11124d50f..31719d364 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -1195,6 +1195,26 @@ int Lua_Mob::GetAA(int id) { return self->GetAA(id); } +int Lua_Mob::GetAAByAAID(int id) { + Lua_Safe_Call_Int(); + return self->GetAAByAAID(id); +} + +bool Lua_Mob::SetAA(int rank_id, int new_value) { + Lua_Safe_Call_Bool(); + return self->SetAA(rank_id, new_value); +} + +bool Lua_Mob::SetAA(int rank_id, int new_value, int charges) { + Lua_Safe_Call_Bool(); + return self->SetAA(rank_id, new_value, charges); +} + +void Lua_Mob::GrantAlternateAdvancementAbility(int aa_id, int points) { + Lua_Safe_Call_Void(); + self->GrantAlternateAdvancementAbility(aa_id, points); +} + bool Lua_Mob::DivineAura() { Lua_Safe_Call_Bool(); return self->DivineAura(); @@ -2074,6 +2094,10 @@ luabind::scope lua_register_mob() { .def("CheckHealAggroAmount", (int(Lua_Mob::*)(int))&Lua_Mob::CheckHealAggroAmount) .def("CheckHealAggroAmount", (int(Lua_Mob::*)(int,uint32))&Lua_Mob::CheckHealAggroAmount) .def("GetAA", (int(Lua_Mob::*)(int))&Lua_Mob::GetAA) + .def("GetAAByAAID", (int(Lua_Mob::*)(int))&Lua_Mob::GetAAByAAID) + .def("SetAA", (bool(Lua_Mob::*)(int,int))&Lua_Mob::SetAA) + .def("SetAA", (bool(Lua_Mob::*)(int,int,int))&Lua_Mob::SetAA) + .def("GrantAlternateAdvancementAbility", (void(Lua_Mob::*)(int, int))&Lua_Mob::GrantAlternateAdvancementAbility) .def("DivineAura", (bool(Lua_Mob::*)(void))&Lua_Mob::DivineAura) .def("SetOOCRegen", (void(Lua_Mob::*)(int))&Lua_Mob::SetOOCRegen) .def("GetEntityVariable", (const char*(Lua_Mob::*)(const char*))&Lua_Mob::GetEntityVariable) diff --git a/zone/lua_mob.h b/zone/lua_mob.h index 023fedd2a..914f46c5d 100644 --- a/zone/lua_mob.h +++ b/zone/lua_mob.h @@ -249,6 +249,10 @@ public: int CheckHealAggroAmount(int spell_id); int CheckHealAggroAmount(int spell_id, uint32 heal_possible); int GetAA(int id); + int GetAAByAAID(int id); + bool SetAA(int rank_id, int new_value); + bool SetAA(int rank_id, int new_value, int charges); + void GrantAlternateAdvancementAbility(int aa_id, int points); bool DivineAura(); void SetOOCRegen(int regen); const char* GetEntityVariable(const char *name); diff --git a/zone/mob.h b/zone/mob.h index 20ec928e7..1c3d7ab15 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -969,6 +969,7 @@ public: void ExpendAlternateAdvancementCharge(uint32 aa_id); void CalcAABonuses(StatBonuses* newbon); void ApplyAABonuses(const AA::Rank &rank, StatBonuses* newbon); + void GrantAlternateAdvancementAbility(int aa_id, int points); protected: void CommonDamage(Mob* other, int32 &damage, const uint16 spell_id, const SkillUseTypes attack_skill, bool &avoidable, const int8 buffslot, const bool iBuffTic); diff --git a/zone/perl_mob.cpp b/zone/perl_mob.cpp index 80ca97484..612d9f868 100644 --- a/zone/perl_mob.cpp +++ b/zone/perl_mob.cpp @@ -6360,12 +6360,12 @@ XS(XS_Mob_GetAA) { dXSARGS; if (items != 2) - Perl_croak(aTHX_ "Usage: Mob::GetAA(THIS, aa_id)"); + Perl_croak(aTHX_ "Usage: Mob::GetAA(THIS, rank_id)"); { Mob * THIS; uint32 RETVAL; dXSTARG; - uint32 aa_id = (uint32)SvUV(ST(1)); + uint32 rank_id = (uint32)SvUV(ST(1)); if (sv_derived_from(ST(0), "Mob")) { IV tmp = SvIV((SV*)SvRV(ST(0))); @@ -6376,12 +6376,93 @@ XS(XS_Mob_GetAA) if(THIS == nullptr) Perl_croak(aTHX_ "THIS is nullptr, avoiding crash."); - RETVAL = THIS->GetAA(aa_id); + RETVAL = THIS->GetAA(rank_id); XSprePUSH; PUSHu((UV)RETVAL); } XSRETURN(1); } +XS(XS_Mob_GetAAByAAID); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Mob_GetAAByAAID) +{ + dXSARGS; + if(items != 2) + Perl_croak(aTHX_ "Usage: Mob::GetAAByAAID(THIS, aa_id)"); + { + Mob * THIS; + uint32 RETVAL; + dXSTARG; + uint32 aa_id = (uint32)SvUV(ST(1)); + + 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."); + + RETVAL = THIS->GetAAByAAID(aa_id); + XSprePUSH; PUSHu((UV)RETVAL); + } + XSRETURN(1); +} + +XS(XS_Mob_SetAA); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Mob_SetAA) +{ + dXSARGS; + if(items < 3 || items > 4) + Perl_croak(aTHX_ "Usage: Mob::SetAA(THIS, aa_id, points, [charges])"); + { + Mob * THIS; + bool RETVAL; + int aa_id = (int)SvIV(ST(1)); + int points = (int)SvIV(ST(2)); + int charges = (items == 4) ? (int)SvIV(ST(3)) : 0; + + 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."); + + RETVAL = THIS->SetAA(aa_id, points, charges); + ST(0) = boolSV(RETVAL); + sv_2mortal(ST(0)); + } + XSRETURN(1); +} + +XS(XS_Mob_GrantAlternateAdvancementAbility); /* prototype to pass -Wmissing-prototypes */ +XS(XS_Mob_GrantAlternateAdvancementAbility) +{ + dXSARGS; + if(items != 3) + Perl_croak(aTHX_ "Usage: Mob::GrantAlternateAdvancementAbility(THIS, aa_id, points)"); + { + Mob * THIS; + int aa_id = (int)SvIV(ST(1)); + int points = (int)SvIV(ST(2)); + + 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."); + + THIS->GrantAlternateAdvancementAbility(aa_id, points); + } + XSRETURN_EMPTY; +} + XS(XS_Mob_DivineAura); /* prototype to pass -Wmissing-prototypes */ XS(XS_Mob_DivineAura) { @@ -8625,6 +8706,9 @@ XS(boot_Mob) newXSproto(strcpy(buf, "CheckAggroAmount"), XS_Mob_CheckAggroAmount, file, "$$"); newXSproto(strcpy(buf, "CheckHealAggroAmount"), XS_Mob_CheckHealAggroAmount, file, "$$"); newXSproto(strcpy(buf, "GetAA"), XS_Mob_GetAA, file, "$$"); + newXSproto(strcpy(buf, "GetAAByAAID"), XS_Mob_GetAAByAAID, file, "$$"); + newXSproto(strcpy(buf, "SetAA"), XS_Mob_SetAA, file, "$$$;$"); + newXSproto(strcpy(buf, "GrantAlternateAdvancementAbility"), XS_Mob_GrantAlternateAdvancementAbility, file, "$$$"); newXSproto(strcpy(buf, "DivineAura"), XS_Mob_DivineAura, file, "$"); newXSproto(strcpy(buf, "AddFeignMemory"), XS_Mob_AddFeignMemory, file, "$$"); newXSproto(strcpy(buf, "RemoveFromFeignMemory"), XS_Mob_RemoveFromFeignMemory, file, "$$"); diff --git a/zone/spells.cpp b/zone/spells.cpp index 310e2bd01..ec872d1c9 100644 --- a/zone/spells.cpp +++ b/zone/spells.cpp @@ -820,8 +820,8 @@ void Mob::InterruptSpell(uint16 message, uint16 color, uint16 spellid) if(casting_spell_aa_id && IsClient()) { //Rest AA Timer on failed cast AA::Rank *rank = zone->GetAlternateAdvancementRank(casting_spell_aa_id); if(rank) { + CastToClient()->Message_StringID(MT_SpellFailure, ABILITY_FAILED); CastToClient()->SendAlternateAdvancementTimer(rank->spell_type, 0, 0x7fffffff); - CastToClient()->Message_StringID(15, ABILITY_FAILED); CastToClient()->GetPTimers().Clear(&database, rank->spell_type + pTimerAAStart); } }