From 02ada0e4969408eb4d403cd91f09e312ec65a855 Mon Sep 17 00:00:00 2001 From: Alex King <89047260+Kinglykrab@users.noreply.github.com> Date: Wed, 15 Mar 2023 20:37:37 -0400 Subject: [PATCH] [Quest API] Add SendIllusion overloads/parameters to Perl/Lua (#3059) * [Quest API] Add SendIllusion methods to Perl. # Perl - Add `$mob->SendIllusion(race, gender, texture, helmtexture, face, hairstyle, haircolor, beard, beardcolor, drakkin_heritage, drakkin_tattoo, drakkin_details, size, target)`. - Add `$mob->SendIllusionPacket(illusion_table_ref)`. * Change defaults. * Remove debug message * Cleanup. * Cleanup * Update perl_mob.cpp --- zone/lua_mob.cpp | 166 ++++++++++++++++++++++++++++------------------ zone/mob.cpp | 17 +++-- zone/mob.h | 3 +- zone/perl_mob.cpp | 52 +++++++++++++++ 4 files changed, 167 insertions(+), 71 deletions(-) diff --git a/zone/lua_mob.cpp b/zone/lua_mob.cpp index 1d0ba9716..4face4b8f 100644 --- a/zone/lua_mob.cpp +++ b/zone/lua_mob.cpp @@ -1567,153 +1567,189 @@ void Lua_Mob::SendIllusionPacket(luabind::adl::object illusion) { return; } - int race = RACE_DOUG_0; - int gender = 255; - int texture = 255; - int helmtexture = 255; - int haircolor = 255; - int beardcolor = 255; - int eyecolor1 = 255; - int eyecolor2 = 255; - int hairstyle = 255; - int luclinface = 255; - int beard = 255; - int aa_title = 255; - uint32 drakkin_heritage = 4294967295; - uint32 drakkin_tattoo = 4294967295; - uint32 drakkin_details = 4294967295; - float size = -1.0f; + uint16 race = self->GetRace(); + uint8 gender = self->GetGender(); + uint8 texture = self->GetTexture(); + uint8 helmtexture = self->GetHelmTexture(); + uint8 haircolor = self->GetHairColor(); + uint8 beardcolor = self->GetBeardColor(); + uint8 eyecolor1 = self->GetEyeColor1(); + uint8 eyecolor2 = self->GetEyeColor2(); + uint8 hairstyle = self->GetHairStyle(); + uint8 luclinface = self->GetLuclinFace(); + uint8 beard = self->GetBeard(); + uint8 aa_title = 255; + uint32 drakkin_heritage = self->GetDrakkinHeritage(); + uint32 drakkin_tattoo = self->GetDrakkinTattoo(); + uint32 drakkin_details = self->GetDrakkinDetails(); + float size = self->GetSize(); + bool send_appearance_effects = true; + Lua_Client target = Lua_Client(); auto cur = illusion["race"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - race = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + race = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["gender"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - gender = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + gender = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["texture"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - texture = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + texture = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["helmtexture"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - helmtexture = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + helmtexture = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["haircolor"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - haircolor = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + haircolor = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["beardcolor"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - beardcolor = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + beardcolor = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["eyecolor1"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - eyecolor1 = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + eyecolor1 = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["eyecolor2"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - eyecolor2 = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + eyecolor2 = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["hairstyle"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - hairstyle = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + hairstyle = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["luclinface"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - luclinface = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + luclinface = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["beard"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - beard = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + beard = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["aa_title"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - aa_title = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + aa_title = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["drakkin_heritage"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - drakkin_heritage = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + drakkin_heritage = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["drakkin_tattoo"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - drakkin_tattoo = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + drakkin_tattoo = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["drakkin_details"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { - drakkin_details = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + drakkin_details = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { } } cur = illusion["size"]; - if(luabind::type(cur) != LUA_TNIL) { + if (luabind::type(cur) != LUA_TNIL) { try { size = luabind::object_cast(cur); - } catch(luabind::cast_failed &) { + } catch (luabind::cast_failed &) { } } - self->SendIllusionPacket(race, gender, texture, helmtexture, haircolor, beardcolor, eyecolor1, eyecolor2, hairstyle, luclinface, - beard, aa_title, drakkin_heritage, drakkin_tattoo, drakkin_details, size); + cur = illusion["send_appearance_effects"]; + if (luabind::type(cur) != LUA_TNIL) { + try { + send_appearance_effects = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { + } + } + + cur = illusion["target"]; + if (luabind::type(cur) != LUA_TNIL) { + try { + target = luabind::object_cast(cur); + } catch (luabind::cast_failed &) { + } + } + + self->SendIllusionPacket( + race, + gender, + texture, + helmtexture, + haircolor, + beardcolor, + eyecolor1, + eyecolor2, + hairstyle, + luclinface, + beard, + aa_title, + drakkin_heritage, + drakkin_tattoo, + drakkin_details, + size, + send_appearance_effects, + target + ); } void Lua_Mob::ChangeRace(int in) { diff --git a/zone/mob.cpp b/zone/mob.cpp index f53891775..dca143cab 100644 --- a/zone/mob.cpp +++ b/zone/mob.cpp @@ -518,7 +518,7 @@ Mob::Mob( } Mob::~Mob() -{ +{ quest_manager.stopalltimers(this); mMovementManager->RemoveMob(this); @@ -2418,7 +2418,8 @@ void Mob::SendIllusionPacket( uint32 in_drakkin_tattoo, uint32 in_drakkin_details, float in_size, - bool send_appearance_effects + bool send_appearance_effects, + Client* target ) { uint8 new_texture = in_texture; @@ -2521,7 +2522,12 @@ void Mob::SendIllusionPacket( is->drakkin_details = new_drakkin_details; is->size = size; - entity_list.QueueClients(this, outapp); + if (!target) { + entity_list.QueueClients(this, outapp); + } else { + target->QueuePacket(outapp, false); + } + safe_delete(outapp); /* Refresh armor and tints after send illusion packet */ @@ -2532,7 +2538,7 @@ void Mob::SendIllusionPacket( } LogSpells( - "Illusion: Race [{}] Gender [{}] Texture [{}] HelmTexture [{}] HairColor [{}] BeardColor [{}] EyeColor1 [{}] EyeColor2 [{}] HairStyle [{}] Face [{}] DrakkinHeritage [{}] DrakkinTattoo [{}] DrakkinDetails [{}] Size [{}]", + "Illusion: Race [{}] Gender [{}] Texture [{}] HelmTexture [{}] HairColor [{}] BeardColor [{}] EyeColor1 [{}] EyeColor2 [{}] HairStyle [{}] Face [{}] DrakkinHeritage [{}] DrakkinTattoo [{}] DrakkinDetails [{}] Size [{}] Target [{}]", race, gender, new_texture, @@ -2546,7 +2552,8 @@ void Mob::SendIllusionPacket( new_drakkin_heritage, new_drakkin_tattoo, new_drakkin_details, - size + size, + target ? target->GetCleanName() : "No Target" ); } diff --git a/zone/mob.h b/zone/mob.h index 8682485c8..d01595a49 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -899,7 +899,8 @@ public: uint32 in_drakkin_tattoo = 0xFFFFFFFF, uint32 in_drakkin_details = 0xFFFFFFFF, float in_size = -1.0f, - bool send_appearance_effects = true + bool send_appearance_effects = true, + Client* target = nullptr ); void CloneAppearance(Mob* other, bool clone_name = false); void SetFaceAppearance(const FaceChange_Struct& face, bool skip_sender = false); diff --git a/zone/perl_mob.cpp b/zone/perl_mob.cpp index 81f807ec4..4ce5df213 100644 --- a/zone/perl_mob.cpp +++ b/zone/perl_mob.cpp @@ -1861,6 +1861,56 @@ void Perl_Mob_SendIllusion(Mob* self, uint16 race, uint8 gender, uint8 texture, self->SendIllusionPacket(race, gender, texture, helmtexture, haircolor, beardcolor, 0xFF, 0xFF, hairstyle, face, beard, 0xFF, drakkin_heritage, drakkin_tattoo, drakkin_details, size); } +void Perl_Mob_SendIllusion(Mob* self, uint16 race, uint8 gender, uint8 texture, uint8 helmtexture, uint8 face, uint8 hairstyle, uint8 haircolor, uint8 beard, uint8 beardcolor, uint32 drakkin_heritage, uint32 drakkin_tattoo, uint32 drakkin_details, float size, Client* target) // @categories Script Utility +{ + self->SendIllusionPacket(race, gender, texture, helmtexture, haircolor, beardcolor, 0xFF, 0xFF, hairstyle, face, beard, 0xFF, drakkin_heritage, drakkin_tattoo, drakkin_details, size, true, target); +} + +void Perl_Mob_SendIllusionPacket(Mob* self, perl::reference table_ref) +{ + perl::hash table = table_ref; + + uint16 race = table.exists("race") ? table["race"] : self->GetRace(); + uint8 gender = table.exists("gender") ? table["gender"] : self->GetGender(); + uint8 texture = table.exists("texture") ? table["texture"] : self->GetTexture(); + uint8 helmtexture = table.exists("helmtexture") ? table["helmtexture"] : self->GetHelmTexture(); + uint8 haircolor = table.exists("haircolor") ? table["haircolor"] : self->GetHairColor(); + uint8 beardcolor = table.exists("beardcolor") ? table["beardcolor"] : self->GetBeardColor(); + uint8 eyecolor1 = table.exists("eyecolor1") ? table["eyecolor1"] : self->GetEyeColor1(); + uint8 eyecolor2 = table.exists("eyecolor2") ? table["eyecolor2"] : self->GetEyeColor2(); + uint8 hairstyle = table.exists("hairstyle") ? table["hairstyle"] : self->GetHairStyle(); + uint8 luclinface = table.exists("luclinface") ? table["luclinface"] : self->GetLuclinFace(); + uint8 beard = table.exists("beard") ? table["beard"] : self->GetBeard(); + uint8 aa_title = table.exists("aa_title") ? table["aa_title"] : 255; + uint32 drakkin_heritage = table.exists("drakkin_heritage") ? table["drakkin_heritage"] : self->GetDrakkinHeritage(); + uint32 drakkin_tattoo = table.exists("drakkin_tattoo") ? table["drakkin_tattoo"] : self->GetDrakkinTattoo(); + uint32 drakkin_details = table.exists("drakkin_details") ? table["drakkin_details"] : self->GetDrakkinDetails(); + float size = table.exists("size") ? table["size"] : self->GetSize(); + bool send_appearance_effects = table.exists("send_appearance_effects") ? table["send_appearance_effects"] : true; + Client* target = table.exists("target") ? static_cast(table["target"]) : nullptr; + + self->SendIllusionPacket( + race, + gender, + texture, + helmtexture, + haircolor, + beardcolor, + eyecolor1, + eyecolor2, + hairstyle, + luclinface, + beard, + aa_title, + drakkin_heritage, + drakkin_tattoo, + drakkin_details, + size, + send_appearance_effects, + target + ); +} + void Perl_Mob_CameraEffect(Mob* self, uint32 duration) // @categories Script Utility { self->CameraEffect(duration, 0.03125f); @@ -3292,6 +3342,8 @@ void perl_register_mob() package.add("SendIllusion", (void(*)(Mob*, uint16, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint32, uint32))&Perl_Mob_SendIllusion); package.add("SendIllusion", (void(*)(Mob*, uint16, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint32, uint32, uint32))&Perl_Mob_SendIllusion); package.add("SendIllusion", (void(*)(Mob*, uint16, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint32, uint32, uint32, float))&Perl_Mob_SendIllusion); + package.add("SendIllusion", (void(*)(Mob*, uint16, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint8, uint32, uint32, uint32, float, Client*))&Perl_Mob_SendIllusion); + package.add("SendIllusionPacket", (void(*)(Mob*, perl::reference))&Perl_Mob_SendIllusionPacket); package.add("SendTo", &Perl_Mob_SendTo); package.add("SendToFixZ", &Perl_Mob_SendToFixZ); package.add("SendWearChange", &Perl_Mob_SendWearChange);