TrinityCore
Loading...
Searching...
No Matches
PlayerTaxi.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "PlayerTaxi.h"
19#include "DBCStores.h"
20#include "ObjectMgr.h"
21#include "Player.h"
22#include "StringConvert.h"
23#include <sstream>
24
26{
27 // class specific initial known nodes
28 switch (chrClass)
29 {
31 {
32 for (std::size_t i = 0; i < m_taximask.size(); ++i)
34 break;
35 }
36 }
37
38 // race specific initial known nodes: capital and taxi hub masks
39 switch (race)
40 {
41 case RACE_HUMAN: SetTaximaskNode(2); break; // Human
42 case RACE_ORC: SetTaximaskNode(23); break; // Orc
43 case RACE_DWARF: SetTaximaskNode(6); break; // Dwarf
45 SetTaximaskNode(27); break; // Night Elf
46 case RACE_UNDEAD_PLAYER: SetTaximaskNode(11); break;// Undead
47 case RACE_TAUREN: SetTaximaskNode(22); break; // Tauren
48 case RACE_GNOME: SetTaximaskNode(6); break; // Gnome
49 case RACE_TROLL: SetTaximaskNode(23); break; // Troll
50 case RACE_BLOODELF: SetTaximaskNode(82); break; // Blood Elf
51 case RACE_DRAENEI: SetTaximaskNode(94); break; // Draenei
52 }
53
54 // new continent starting masks (It will be accessible only at new map)
55 switch (Player::TeamForRace(race))
56 {
57 case ALLIANCE: SetTaximaskNode(100); break;
58 case HORDE: SetTaximaskNode(99); break;
59 }
60 // level dependent taxi hubs
61 if (level >= 68)
62 SetTaximaskNode(213); //Shattered Sun Staging Area
63}
64
65bool PlayerTaxi::LoadTaxiMask(std::string const& data)
66{
67 bool warn = false;
68 std::vector<std::string_view> tokens = Trinity::Tokenize(data, ' ', false);
69 for (size_t index = 0; (index < m_taximask.size()) && (index < tokens.size()); ++index)
70 {
71 if (Optional<uint32> mask = Trinity::StringTo<uint32>(tokens[index]))
72 {
73 // load and set bits only for existing taxi nodes
74 m_taximask[index] = sTaxiNodesMask[index] & *mask;
75 if (m_taximask[index] != *mask)
76 warn = true;
77 }
78 else
79 {
80 m_taximask[index] = 0;
81 warn = true;
82 }
83 }
84 return !warn;
85}
86
88{
89 if (all)
90 data.append(sTaxiNodesMask.data(), sTaxiNodesMask.size()); // all existing nodes
91 else
92 data.append(m_taximask.data(), m_taximask.size()); // known nodes
93}
94
95bool PlayerTaxi::LoadTaxiDestinationsFromString(const std::string& values, uint32 team)
96{
98
99 std::vector<std::string_view> tokens = Trinity::Tokenize(values, ' ', false);
100 auto itr = tokens.begin();
101 if (itr != tokens.end())
102 {
103 if (Optional<uint32> faction = Trinity::StringTo<uint32>(*itr))
104 m_flightMasterFactionId = *faction;
105 else
106 return false;
107 }
108 else
109 return false;
110
111 while ((++itr) != tokens.end())
112 {
113 if (Optional<uint32> node = Trinity::StringTo<uint32>(*itr))
114 AddTaxiDestination(*node);
115 else
116 return false;
117 }
118
119 if (m_TaxiDestinations.empty())
120 return true;
121
122 // Check integrity
123 if (m_TaxiDestinations.size() < 2)
124 return false;
125
126 for (size_t i = 1; i < m_TaxiDestinations.size(); ++i)
127 {
128 uint32 cost;
129 uint32 path;
130 sObjectMgr->GetTaxiPath(m_TaxiDestinations[i - 1], m_TaxiDestinations[i], path, cost);
131 if (!path)
132 return false;
133 }
134
135 // can't load taxi path without mount set (quest taxi path?)
136 if (!sObjectMgr->GetTaxiMountDisplayId(GetTaxiSource(), team, true))
137 return false;
138
139 return true;
140}
141
143{
144 if (m_TaxiDestinations.empty())
145 return "";
146
147 ASSERT(m_TaxiDestinations.size() >= 2);
148
149 std::ostringstream ss;
150 ss << m_flightMasterFactionId << ' ';
151
152 for (size_t i = 0; i < m_TaxiDestinations.size(); ++i)
153 ss << m_TaxiDestinations[i] << ' ';
154
155 return ss.str();
156}
157
159{
160 if (m_TaxiDestinations.size() < 2)
161 return 0;
162
163 uint32 path;
164 uint32 cost;
165
166 sObjectMgr->GetTaxiPath(m_TaxiDestinations[0], m_TaxiDestinations[1], path, cost);
167
168 return path;
169}
170
171std::ostringstream& operator<<(std::ostringstream& ss, PlayerTaxi const& taxi)
172{
173 for (std::size_t i = 0; i < taxi.m_taximask.size(); ++i)
174 ss << uint32(taxi.m_taximask[i]) << ' ';
175 return ss;
176}
177
TaxiMask sTaxiNodesMask
TaxiMask sOldContinentsNodesMask
DBCStorage< FactionTemplateEntry > sFactionTemplateStore(FactionTemplateEntryfmt)
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
#define ASSERT
Definition Errors.h:68
#define sObjectMgr
Definition ObjectMgr.h:1721
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
std::ostringstream & operator<<(std::ostringstream &ss, PlayerTaxi const &taxi)
@ CLASS_DEATH_KNIGHT
@ ALLIANCE
@ HORDE
@ RACE_TROLL
@ RACE_UNDEAD_PLAYER
@ RACE_ORC
@ RACE_DRAENEI
@ RACE_NIGHTELF
@ RACE_BLOODELF
@ RACE_DWARF
@ RACE_GNOME
@ RACE_HUMAN
@ RACE_TAUREN
void append(T value)
Definition ByteBuffer.h:129
std::string SaveTaxiDestinationsToString()
void AddTaxiDestination(uint32 dest)
Definition PlayerTaxi.h:64
bool SetTaximaskNode(uint32 nodeidx)
Definition PlayerTaxi.h:45
std::deque< uint32 > m_TaxiDestinations
Definition PlayerTaxi.h:82
uint32 GetTaxiSource() const
Definition PlayerTaxi.h:65
FactionTemplateEntry const * GetFlightMasterFactionTemplate() const
uint32 m_flightMasterFactionId
Definition PlayerTaxi.h:83
bool LoadTaxiDestinationsFromString(std::string const &values, uint32 team)
bool LoadTaxiMask(std::string const &data)
void AppendTaximaskTo(ByteBuffer &data, bool all)
void ClearTaxiDestinations()
Definition PlayerTaxi.h:63
TaxiMask m_taximask
Definition PlayerTaxi.h:81
uint32 GetCurrentTaxiPath() const
void InitTaxiNodesForLevel(uint32 race, uint32 chrClass, uint8 level)
static uint32 TeamForRace(uint8 race)
Definition Player.cpp:6269
size_t size() const
Definition DBCEnums.h:446
value_type const * data() const
Definition DBCEnums.h:447
TC_COMMON_API std::vector< std::string_view > Tokenize(std::string_view str, char sep, bool keepEmpty)
Definition Util.cpp:56