DarkflameServer/dGame/TeamManager.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

69 lines
1.3 KiB
C++
Raw Permalink Normal View History

#include "TeamManager.h"
#include "EntityManager.h"
#include "Game.h"
#include "dConfig.h"
TeamManager* TeamManager::m_Address = nullptr; //For singleton method
Team::Team() {
lootOption = Game::config->GetValue("default_team_loot") == "0" ? 0 : 1;
}
TeamManager::TeamManager() {
}
Team* TeamManager::GetTeam(LWOOBJID member) const {
for (const auto& pair : m_Teams) {
for (const auto memberId : pair.second->members) {
if (memberId == member) {
return pair.second;
2022-07-28 13:39:57 +00:00
}
}
}
2022-07-28 13:39:57 +00:00
return nullptr;
}
LWOOBJID TeamManager::GetNextLootOwner(Team* team) const {
team->lootRound++;
if (team->lootRound >= team->members.size()) {
team->lootRound = 0;
}
return team->members[team->lootRound];
}
void TeamManager::UpdateTeam(LWOOBJID teamId, char lootOption, const std::vector<LWOOBJID>& members) {
const auto& pair = m_Teams.find(teamId);
2022-07-28 13:39:57 +00:00
Team* team;
2022-07-28 13:39:57 +00:00
if (pair == m_Teams.end()) {
if (members.size() <= 1) {
return;
}
2022-07-28 13:39:57 +00:00
team = new Team();
m_Teams[teamId] = team;
} else {
team = pair->second;
}
2022-07-28 13:39:57 +00:00
team->members = members;
team->lootOption = lootOption;
}
void TeamManager::DeleteTeam(LWOOBJID teamId) {
const auto& pair = m_Teams.find(teamId);
if (pair == m_Teams.end()) return;
delete pair->second;
m_Teams.erase(teamId);
}
TeamManager::~TeamManager() {
}