Advertisement
Rochet2

Race Change - Trinitycore

Aug 9th, 2012
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Race change
  2. // By Eatos
  3. // Convert to trinitycore by Rochet2
  4. // Original release thread: http://www.ac-web.org/forums/showthread.php?t=151878
  5.  
  6. #include "ScriptPCH.h"
  7. #include "GuildMgr.h"
  8. #include "Chat.h"
  9.  
  10. class RaceChanger : public CreatureScript
  11. {
  12. public:
  13.     RaceChanger() : CreatureScript("RaceChanger") { }
  14.  
  15.     bool OnGossipHello(Player* Plr, Creature* pObject)
  16.     {
  17.         if(Plr->GetSession()->GetSecurity() != SEC_PLAYER)
  18.         {
  19.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Human", 0, 1 );
  20.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into NightElf", 0, 4 );
  21.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Dwarf", 0, 3 );
  22.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Gnome", 0, 7 );
  23.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Draenei", 0, 11 );
  24.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Orc", 0, 2 );
  25.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Undead", 0, 5 );
  26.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Tauren", 0, 6 );
  27.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into Troll", 0, 8 );
  28.             Plr->ADD_GOSSIP_ITEM( 0, "Change me Into BloodElf", 0, 10 );
  29.         }
  30.         else
  31.         {
  32.             Plr->GetSession()->SendNotification("You can not use this right now");
  33.             return false;
  34.         }
  35.         Plr->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, pObject->GetGUID());
  36.         return true;
  37.     }
  38.  
  39.     bool OnGossipSelect(Player* Plr, Creature* pObject, uint32 Id, uint32 IntId)
  40.     {
  41.         // ChatHandler(Plr).PSendSysMessage("MUHAHAHA ...");
  42.  
  43.         uint8 race, race_old, class_, gender;
  44.         Powers powertype;
  45.         // TeamId team;
  46.         race_old = race = IntId; // what are these for? Shouldnt they be different?
  47.  
  48.         Plr->setFactionForRace(race);
  49.         class_ = Plr->getClass();
  50.         gender = Plr->getGender();
  51.         powertype = Plr->getPowerType();
  52.         // team = Plr->GetTeamId();
  53.  
  54.         const PlayerInfo* info = sObjectMgr->GetPlayerInfo(race, class_);
  55.         if (!info)
  56.             return true;
  57.  
  58.         Plr->SetFloatValue(OBJECT_FIELD_SCALE_X, ((race==RACE_TAUREN)?1.3f:1.0f));
  59.         // Plr->SetUInt32Value(UNIT_FIELD_FACTIONTEMPLATE, info->factiontemplate ); // handled by setFactionForRace
  60.         Plr->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( race ) | ( class_ << 8 ) | ( gender << 16 ) | ( powertype << 24 ) ) );
  61.         Plr->SetUInt32Value(UNIT_FIELD_DISPLAYID, gender ? info->displayId_f : info->displayId_f );
  62.         Plr->SetUInt32Value(UNIT_FIELD_NATIVEDISPLAYID, gender ? info->displayId_f : info->displayId_f );
  63.  
  64.         // Different races have different number of visuals
  65.         Plr->SetUInt32Value(PLAYER_BYTES, ((urand(0,5))|(urand(0,5)<<8)|(urand(0,5)<<16)|(urand(0,5)<<24))); // urand were RandomUInt. Might not exist in Trinitycore. Not sure what it does either.
  66.         Plr->SetUInt32Value(PLAYER_BYTES_2, (( !gender ? 0 : urand(0,3) ) | (0x02 << 24))); // gender right?
  67.         //Plr->SetUInt32Value(PLAYER_BYTES, ((skin) | (face << 8) | (hairStyle << 16) | (hairColor << 24)));
  68.         //Plr->SetUInt32Value(PLAYER_BYTES_2, (facialHair | (0x02 << 24)));
  69.  
  70.         Plr->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, 0xEEEEEEEE);
  71.         //dump reputation data
  72.         FactionStateList m_tempRepMap;
  73.         //store neutral
  74.         for(uint32 i = 0; i < sFactionStore.GetNumRows(); ++i)
  75.         {
  76.             const FactionEntry * f = sFactionStore.LookupEntry(i);
  77.             if(f == 0) continue;
  78.             if( Plr->GetReputation(f->ID) &&
  79.                 f->team != 67 && f->team != 469 && // ream = parentFaction ?
  80.                 f->team != 892 && f->team != 891 &&
  81.                 f->ID != 947 && f->ID != 946 &&
  82.                 f->ID != 892 && f->ID != 891 &&
  83.                 f->ID != 941 && f->ID != 978 &&
  84.                 f->ID != 922
  85.                 )
  86.             {
  87.                 const ReputationMgr & repMgr = Plr->GetReputationMgr();
  88.                 FactionState * rep = new FactionState;
  89.                 /*
  90.                 rep->Flags = 0;
  91.                 rep->Standing = repMgr.GetReputation(f->ID);
  92.                 rep->base = repMgr.GetBaseReputation(f->ID);
  93.                 */
  94.                 FactionState newFaction;
  95.                 newFaction.ID = f->ID;
  96.                 newFaction.ReputationListID = f->reputationListID;
  97.                 newFaction.Standing = repMgr.GetReputation(f->ID);
  98.                 newFaction.Flags = 0;
  99.                 newFaction.needSend = true;
  100.                 newFaction.needSave = true;
  101.  
  102.                 m_tempRepMap[f->ID] = newFaction; // newFaction.ReputationListID or f->ID?
  103.             }
  104.         }
  105.  
  106.         Plr->GetReputationMgr().SendInitialReputations(); // does this initialize the rep values?
  107.  
  108.         for(FactionStateList::iterator itr = m_tempRepMap.begin(); itr != m_tempRepMap.end(); ++itr)
  109.         {
  110.             Plr->SetReputation(itr->first, itr->second.Standing );
  111.             //delete itr->second;
  112.         }
  113.  
  114.         // Plr->(); // _RemoveLanguages See CharacterHandler.cpp 1736 line ?
  115.         // Seems like languages are handled automatically.
  116.  
  117.         //remove racial spells along with all starting spells then add them for new race
  118.         const PlayerInfo* old_info = sObjectMgr->GetPlayerInfo(race_old, class_);
  119.         if (!old_info)
  120.             return true;
  121.  
  122.         for(PlayerCreateInfoSpells::const_iterator sp = old_info->spell.begin(); sp != old_info->spell.end(); sp++) // spell_list
  123.             if (Plr->HasSpell(*sp)) Plr->removeSpell((*sp), false, false);
  124.  
  125.         for(PlayerCreateInfoSpells::const_iterator sp = info->spell.begin(); sp != info->spell.end(); sp++)
  126.             Plr->addSpell((*sp), true, true, true, false);
  127.  
  128.         // Shouldnt we also take into account if the faction changes?
  129.         if (Plr->GetGuildId())
  130.         {
  131.             Guild *pGuild = sGuildMgr->GetGuildById( Plr->GetGuildId() );
  132.  
  133.             if(pGuild && pGuild->GetLeaderGUID() != Plr->GetGUID() )
  134.             {
  135.                 pGuild->DeleteMember(Plr->GetGUID());
  136.                 /*Plr->L SetGuildId(0);
  137.                 Plr->SetGuildRank(0);
  138.                 pGuild->RemoveGuildMember(Plr->m_playerInfo, NULL);
  139.  
  140.                 WorldPacket data(100);
  141.                 data.Initialize(SMSG_GUILD_EVENT);
  142.                 data << uint8(GUILD_EVENT_LEFT);
  143.                 data << uint8(1);
  144.                 data << Plr->GetName();
  145.                 pGuild->SendPacket(&data);
  146.                 */
  147.             }
  148.         }
  149.  
  150.         Plr->SaveToDB(false);
  151.         // ChatHandler(Plr).PSendSysMessage("Signed in blood. There is no going back now ...");
  152.         // ChatHandler(Plr).PSendSysMessage("Relog ...");
  153.         //force relog
  154.         Plr->GetSession()->KickPlayer(); // instant kick, cant be bothered to make it delayed.
  155.         Plr->CLOSE_GOSSIP_MENU();
  156.         return true;
  157.     }
  158. };
  159.  
  160. void AddSC_RaceChanger()
  161. {
  162.     new RaceChanger();
  163. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement