[2796] Applied MaNGOS coding style (see trunk/bcpp.cfg).
[mangos-git.git] / src / game / Level0.cpp
blobde7a945df9d3f2276d5aa5adf94beec033060074
1 /*
2 * Copyright (C) 2005,2006 MaNGOS <http://www.mangosproject.org/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "Player.h"
26 #include "Opcodes.h"
27 #include "Chat.h"
28 #include "MapManager.h"
29 #include "ObjectAccessor.h"
30 #include "Language.h"
32 bool ChatHandler::ShowHelpForCommand(ChatCommand *table, const char* cmd)
34 for(uint32 i = 0; table[i].Name != NULL; i++)
36 if(!hasStringAbbr(table[i].Name, cmd))
37 continue;
39 if(m_session->GetSecurity() < table[i].SecurityLevel)
40 continue;
42 if(table[i].ChildCommands != NULL)
44 cmd = strtok(NULL, " ");
45 if(cmd && ShowHelpForCommand(table[i].ChildCommands, cmd))
46 return true;
49 if(table[i].Help == "")
51 SendSysMessage(LANG_NO_HELP_CMD);
52 return true;
55 SendSysMultilineMessage(table[i].Help.c_str());
57 return true;
60 return false;
63 bool ChatHandler::HandleHelpCommand(const char* args)
65 if(!*args)
66 return false;
68 char* cmd = strtok((char*)args, " ");
69 if(!cmd)
70 return false;
72 if(!ShowHelpForCommand(getCommandTable(), cmd))
74 SendSysMessage(LANG_NO_CMD);
77 return true;
80 bool ChatHandler::HandleCommandsCommand(const char* args)
82 ChatCommand *table = getCommandTable();
84 SendSysMessage(LANG_AVIABLE_CMD);
86 for(uint32 i = 0; table[i].Name != NULL; i++)
88 if(*args && !hasStringAbbr(table[i].Name, (char*)args))
89 continue;
91 if(m_session->GetSecurity() < table[i].SecurityLevel)
92 continue;
94 SendSysMessage(table[i].Name);
97 return true;
100 bool ChatHandler::HandleAcctCommand(const char* args)
102 uint32 gmlevel = m_session->GetSecurity();
103 PSendSysMessage(LANG_ACCOUNT_LEVEL, gmlevel);
104 return true;
107 bool ChatHandler::HandleStartCommand(const char* args)
109 Player *chr = m_session->GetPlayer();
111 if(chr->isInFlight())
113 SendSysMessage(LANG_YOU_IN_FLIGHT);
114 return true;
117 if(chr->isInCombat())
119 SendSysMessage(LANG_YOU_IN_COMBAT);
120 return true;
123 // not let used .start command as free replacement for hearthstone
124 if(chr->HaveSpellCooldown(8690))
126 SendSysMessage(LANG_YOU_USED_IT_RECENTLY);
127 return true;
130 chr->SetUInt32Value(PLAYER_FARSIGHT, 0x01);
132 PlayerInfo const *info = objmgr.GetPlayerInfo(chr->getRace(), chr->getClass());
134 chr->TeleportTo(info->mapId, info->positionX, info->positionY,info->positionZ,chr->GetOrientation());
136 chr->SetUInt32Value(PLAYER_FARSIGHT, 0x00);
138 // set hearthstone cooldown
139 chr->AddSpellCooldown(8690,time(NULL)+3600);
141 return true;
144 bool ChatHandler::HandleInfoCommand(const char* args)
146 uint32 clientsNum = sWorld.GetSessionCount();
148 PSendSysMessage(LANG_CONNECTED_USERS, (int) clientsNum);
150 return true;
153 bool ChatHandler::HandleDismountCommand(const char* args)
156 //If player is not mounted, so go out :)
157 if (!m_session->GetPlayer( )->IsMounted())
159 SendSysMessage(LANG_CHAR_NON_MOUNTED);
160 return true;
163 if(m_session->GetPlayer( )->isInFlight())
165 SendSysMessage(LANG_YOU_IN_FLIGHT);
166 return true;
169 m_session->GetPlayer( )->Unmount();
170 m_session->GetPlayer( )->SetPlayerSpeed(MOVE_RUN, 7.5, true);
171 return true;
174 bool ChatHandler::HandleSaveCommand(const char* args)
176 m_session->GetPlayer()->SaveToDB();
177 SendSysMessage(LANG_PLAYER_SAVED);
178 return true;
181 bool ChatHandler::HandleGMListCommand(const char* args)
183 bool first = true;
185 ObjectAccessor::PlayersMapType &m(ObjectAccessor::Instance().GetPlayers());
186 for(ObjectAccessor::PlayersMapType::iterator itr = m.begin(); itr != m.end(); ++itr)
188 if(itr->second->GetSession()->GetSecurity() && itr->second->isVisibleFor(m_session->GetPlayer()))
190 if(first)
191 SendSysMessage(LANG_GMS_ON_SRV);
193 SendSysMessage(itr->second->GetName());
195 first = false;
199 if(first)
200 SendSysMessage(LANG_GMS_NOT_LOGGED);
202 return true;
205 bool ChatHandler::HandleShowHonor(const char* args)
207 uint32 dishonorable_kills = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LIFETIME_DISHONORABLE_KILLS);
208 uint32 honorable_kills = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LIFETIME_HONORABLE_KILLS);
209 uint32 highest_rank = (m_session->GetPlayer()->GetHonorHighestRank() < 16)? m_session->GetPlayer()->GetHonorHighestRank() : 0;
210 uint32 today_honorable_kills = (uint16)m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_SESSION_KILLS);
211 uint32 today_dishonorable_kills = (uint16)(m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_SESSION_KILLS)>>16);
212 uint32 yestarday_kills = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_YESTERDAY_KILLS);
213 uint32 yestarday_honor = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION);
214 uint32 this_week_kills = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_THIS_WEEK_KILLS);
215 uint32 this_week_honor = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_THIS_WEEK_CONTRIBUTION);
216 uint32 last_week_kills = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LAST_WEEK_KILLS);
217 uint32 last_week_honor = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LAST_WEEK_CONTRIBUTION);
218 uint32 last_week_standing = m_session->GetPlayer()->GetUInt32Value(PLAYER_FIELD_LAST_WEEK_RANK);
220 std::string alliance_ranks[] =
223 LANG_ALI_PRIVATE,
224 LANG_ALI_CORPORAL,
225 LANG_ALI_SERGEANT,
226 LANG_ALI_MASTER_SERGEANT,
227 LANG_ALI_SERGEANT_MAJOR,
228 LANG_ALI_KNIGHT,
229 LANG_ALI_KNIGHT_LIEUTENANT,
230 LANG_ALI_KNIGHT_CAPTAIN,
231 LANG_ALI_KNIGHT_CHAMPION,
232 LANG_ALI_LIEUTENANT_COMMANDER,
233 LANG_ALI_COMMANDER,
234 LANG_ALI_MARSHAL,
235 LANG_ALI_FIELD_MARSHAL,
236 LANG_ALI_GRAND_MARSHAL,
237 LANG_ALI_GAME_MASTER
239 std::string horde_ranks[] =
242 LANG_HRD_SCOUT,
243 LANG_HRD_GRUNT,
244 LANG_HRD_SERGEANT,
245 LANG_HRD_SENIOR_SERGEANT,
246 LANG_HRD_FIRST_SERGEANT,
247 LANG_HRD_STONE_GUARD,
248 LANG_HRD_BLOOD_GUARD,
249 LANG_HRD_LEGIONNARE,
250 LANG_HRD_CENTURION,
251 LANG_HRD_CHAMPION,
252 LANG_HRD_LIEUTENANT_GENERAL,
253 LANG_HRD_GENERAL,
254 LANG_HRD_WARLORD,
255 LANG_HRD_HIGH_WARLORD,
256 LANG_HRD_GAME_MASTER
258 std::string rank_name;
259 std::string hrank_name;
261 if ( m_session->GetPlayer()->GetTeam() == ALLIANCE )
263 rank_name = alliance_ranks[ m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) ];
264 hrank_name = alliance_ranks[ highest_rank ];
266 else
267 if ( m_session->GetPlayer()->GetTeam() == HORDE )
269 rank_name = horde_ranks[ m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ) ];
270 hrank_name = horde_ranks[ highest_rank ];
272 else
274 rank_name = LANG_NO_RANK;
277 PSendSysMessage(LANG_RANK, rank_name.c_str(), m_session->GetPlayer()->GetName(), m_session->GetPlayer()->CalculateHonorRank( m_session->GetPlayer()->GetTotalHonor() ));
278 PSendSysMessage(LANG_HONOR_TODAY, today_honorable_kills, today_dishonorable_kills);
279 PSendSysMessage(LANG_HONOR_YESTERDAY, yestarday_kills, yestarday_honor);
280 PSendSysMessage(LANG_HONOR_THIS_WEEK, this_week_kills, this_week_honor);
281 PSendSysMessage(LANG_HONOR_LAST_WEEK, last_week_kills, last_week_honor, last_week_standing);
282 PSendSysMessage(LANG_HONOR_LIFE, honorable_kills, dishonorable_kills, highest_rank, hrank_name.c_str());
284 return true;