Merge branch 'DarkflameUniverse:main' into main

This commit is contained in:
Nils Bergmann 2021-12-14 20:05:31 +01:00 committed by GitHub
commit 2b92bbc45f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 445 additions and 160 deletions

View File

@ -123,6 +123,9 @@ make_directory(${CMAKE_BINARY_DIR}/res)
# Create a /locale directory # Create a /locale directory
make_directory(${CMAKE_BINARY_DIR}/locale) make_directory(${CMAKE_BINARY_DIR}/locale)
# Create a /logs directory
make_directory(${CMAKE_BINARY_DIR}/logs)
# Copy ini files on first build # Copy ini files on first build
if (NOT EXISTS ${PROJECT_BINARY_DIR}/authconfig.ini) if (NOT EXISTS ${PROJECT_BINARY_DIR}/authconfig.ini)
configure_file( configure_file(

View File

@ -236,6 +236,8 @@ The client script for the survival minigame has a bug in it which can cause the
* Change `PlayerReady(self)` to `onPlayerReady(self)` * Change `PlayerReady(self)` to `onPlayerReady(self)`
* Save the file, overriding readonly mode if required * Save the file, overriding readonly mode if required
If you still experience the bug, try deleting/renaming `res/pack/scripts.pak`.
### Brick-By-Brick building ### Brick-By-Brick building
Brick-By-Brick building requires `PATCHSERVERIP=0:` in the `boot.cfg` to point to a HTTP server which always returns `HTTP 404 - Not Found` for all requests. This can be achieved by pointing it to `localhost` while having `sudo python -m http.server 80` running in the background. Brick-By-Brick building requires `PATCHSERVERIP=0:` in the `boot.cfg` to point to a HTTP server which always returns `HTTP 404 - Not Found` for all requests. This can be achieved by pointing it to `localhost` while having `sudo python -m http.server 80` running in the background.

View File

@ -45,6 +45,7 @@ int main(int argc, char** argv) {
dConfig config("authconfig.ini"); dConfig config("authconfig.ini");
Game::config = &config; Game::config = &config;
Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console"))));
Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1");
//Connect to the MySQL Database //Connect to the MySQL Database
std::string mysql_host = config.GetValue("mysql_host"); std::string mysql_host = config.GetValue("mysql_host");
@ -152,11 +153,13 @@ int main(int argc, char** argv) {
dLogger * SetupLogger() { dLogger * SetupLogger() {
std::string logPath = "./logs/AuthServer_" + std::to_string(time(nullptr)) + ".log"; std::string logPath = "./logs/AuthServer_" + std::to_string(time(nullptr)) + ".log";
bool logToConsole = false; bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG #ifdef _DEBUG
logToConsole = true; logToConsole = true;
logDebugStatements = true;
#endif #endif
return new dLogger(logPath, logToConsole); return new dLogger(logPath, logToConsole, logDebugStatements);
} }
void HandlePacket(Packet* packet) { void HandlePacket(Packet* packet) {

View File

@ -48,6 +48,7 @@ int main(int argc, char** argv) {
dConfig config("chatconfig.ini"); dConfig config("chatconfig.ini");
Game::config = &config; Game::config = &config;
Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console"))));
Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1");
//Connect to the MySQL Database //Connect to the MySQL Database
std::string mysql_host = config.GetValue("mysql_host"); std::string mysql_host = config.GetValue("mysql_host");
@ -159,11 +160,13 @@ int main(int argc, char** argv) {
dLogger * SetupLogger() { dLogger * SetupLogger() {
std::string logPath = "./logs/ChatServer_" + std::to_string(time(nullptr)) + ".log"; std::string logPath = "./logs/ChatServer_" + std::to_string(time(nullptr)) + ".log";
bool logToConsole = false; bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG #ifdef _DEBUG
logToConsole = true; logToConsole = true;
logDebugStatements = true;
#endif #endif
return new dLogger(logPath, logToConsole); return new dLogger(logPath, logToConsole, logDebugStatements);
} }
void HandlePacket(Packet* packet) { void HandlePacket(Packet* packet) {

View File

@ -1,7 +1,8 @@
#include "dLogger.h" #include "dLogger.h"
dLogger::dLogger(const std::string& outpath, bool logToConsole) { dLogger::dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements) {
m_logToConsole = logToConsole; m_logToConsole = logToConsole;
m_logDebugStatements = logDebugStatements;
m_outpath = outpath; m_outpath = outpath;
#ifdef _WIN32 #ifdef _WIN32
@ -24,39 +25,25 @@ dLogger::~dLogger() {
#endif #endif
} }
void dLogger::LogBasic(const std::string & message) { void dLogger::vLog(const char* format, va_list args) {
LogBasic(message.c_str());
}
void dLogger::LogBasic(const char * format, ...) {
#ifdef _WIN32 #ifdef _WIN32
time_t t = time(NULL); time_t t = time(NULL);
struct tm time; struct tm time;
localtime_s(&time, &t); localtime_s(&time, &t);
char timeStr[70]; char timeStr[70];
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time); strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time);
char message[2048]; char message[2048];
va_list args;
va_start(args, format);
vsprintf_s(message, format, args); vsprintf_s(message, format, args);
va_end(args);
if (m_logToConsole) std::cout << "[" << "time machine broke" << "] " << message; if (m_logToConsole) std::cout << "[" << timeStr << "] " << message;
mFile << "[" << "time" << "] " << message; mFile << "[" << timeStr << "] " << message;
#else #else
time_t t = time(NULL); time_t t = time(NULL);
struct tm * time = localtime(&t); struct tm * time = localtime(&t);
char timeStr[70]; char timeStr[70];
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time); strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time);
char message[2048]; char message[2048];
va_list args;
va_start(args, format);
vsprintf(message, format, args); vsprintf(message, format, args);
va_end(args);
if (m_logToConsole) { if (m_logToConsole) {
fputs("[", stdout); fputs("[", stdout);
@ -76,62 +63,42 @@ void dLogger::LogBasic(const char * format, ...) {
#endif #endif
} }
void dLogger::LogBasic(const char * format, ...) {
va_list args;
va_start(args, format);
vLog(format, args);
va_end(args);
}
void dLogger::LogBasic(const std::string & message) {
LogBasic(message.c_str());
}
void dLogger::Log(const char * className, const char * format, ...) { void dLogger::Log(const char * className, const char * format, ...) {
#ifdef _WIN32
time_t t = time(NULL);
struct tm time;
localtime_s(&time, &t);
char timeStr[70];
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", &time);
char message[2048];
va_list args; va_list args;
std::string log = "[" + std::string(className) + "] " + std::string(format);
va_start(args, format); va_start(args, format);
vsprintf_s(message, format, args); vLog(log.c_str(), args);
va_end(args); va_end(args);
if (m_logToConsole) std::cout << "[" << timeStr << "] [" << className << "]: " << message;
mFile << "[" << timeStr << "] [" << className << "]: " << message;
#else
time_t t = time(NULL);
struct tm * time = localtime(&t);
char timeStr[70];
strftime(timeStr, sizeof(timeStr), "%d-%m-%y %H:%M:%S", time);
char message[2048];
va_list args;
va_start(args, format);
vsprintf(message, format, args);
va_end(args);
if (m_logToConsole) {
fputs("[", stdout);
fputs(timeStr, stdout);
fputs("] ", stdout);
fputs("[", stdout);
fputs(className, stdout);
fputs("]: ", stdout);
fputs(message, stdout);
}
if (fp != NULL) {
fputs("[", fp);
fputs(timeStr, fp);
fputs("] ", fp);
fputs("[", fp);
fputs(className, fp);
fputs("]: ", fp);
fputs(message, fp);
}
#endif
} }
void dLogger::Log(const std::string & className, const std::string & message) { void dLogger::Log(const std::string & className, const std::string & message) {
Log(className.c_str(), message.c_str()); Log(className.c_str(), message.c_str());
} }
void dLogger::LogDebug(const char * className, const char * format, ...) {
if (!m_logDebugStatements) return;
va_list args;
std::string log = "[" + std::string(className) + "] " + std::string(format);
va_start(args, format);
vLog(log.c_str(), args);
va_end(args);
}
void dLogger::LogDebug(const std::string & className, const std::string & message) {
LogDebug(className.c_str(), message.c_str());
}
void dLogger::Flush() { void dLogger::Flush() {
#ifdef _WIN32 #ifdef _WIN32
mFile.flush(); mFile.flush();

View File

@ -7,21 +7,26 @@
class dLogger { class dLogger {
public: public:
dLogger(const std::string& outpath, bool logToConsole); dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements);
~dLogger(); ~dLogger();
void SetLogToConsole(bool logToConsole) { m_logToConsole = logToConsole; } void SetLogToConsole(bool logToConsole) { m_logToConsole = logToConsole; }
void SetLogDebugStatements(bool logDebugStatements) { m_logDebugStatements = logDebugStatements; }
void vLog(const char* format, va_list args);
void LogBasic(const std::string& message); void LogBasic(const std::string& message);
void LogBasic(const char* format, ...); void LogBasic(const char* format, ...);
void Log(const char* className, const char* format, ...); void Log(const char* className, const char* format, ...);
void Log(const std::string& className, const std::string& message); void Log(const std::string& className, const std::string& message);
void LogDebug(const std::string& className, const std::string& message);
void LogDebug(const char* className, const char* format, ...);
void Flush(); void Flush();
const bool GetIsLoggingToConsole() const { return m_logToConsole; } const bool GetIsLoggingToConsole() const { return m_logToConsole; }
private: private:
bool m_logDebugStatements;
bool m_logToConsole; bool m_logToConsole;
std::string m_outpath; std::string m_outpath;
std::ofstream mFile; std::ofstream mFile;

View File

@ -74,6 +74,7 @@ public:
*/ */
uint64_t GetLastLogin() const { return m_LastLogin; } uint64_t GetLastLogin() const { return m_LastLogin; }
/** /**
* Gets the default shirt color for this character * Gets the default shirt color for this character
* @return the default shirt color ID * @return the default shirt color ID
@ -134,6 +135,67 @@ public:
*/ */
uint32_t GetRightHand() const { return m_RightHand; } uint32_t GetRightHand() const { return m_RightHand; }
/**
* Sets the default shirt color for this character
* @param color the shirt color ID to set
*/
void SetShirtColor(uint32_t color) { m_ShirtColor = color; }
/**
* Sets the default shirt style for this character
* @param style the shirt style ID to set
*/
void SetShirtStyle(uint32_t style) { m_ShirtStyle = style; }
/**
* Sets the default pants color for this character
* @param color the pants color ID to set
*/
void SetPantsColor(uint32_t color) { m_PantsColor = color; }
/**
* Sets the default hair color for this character
* @param color the hair color ID to set
*/
void SetHairColor(uint32_t color) { m_HairColor = color; }
/**
* Sets the default hair style for this character
* @param style the hair style ID to set
*/
void SetHairStyle(uint32_t style) { m_HairStyle = style; }
/**
* Sets the eyes config for this character
* @param eyes the eyes config ID to set
*/
void SetEyes(uint32_t eyes) { m_Eyes = eyes; }
/**
* Sets the eyebrows config for this character
* @param eyebrows the eyebrows config ID to set
*/
void SetEyebrows(uint32_t eyebrows) { m_Eyebrows = eyebrows; }
/**
* Sets the mouth config for this character
* @param mouth the mouth config ID to set
*/
void SetMouth(uint32_t mouth) { m_Mouth = mouth; }
/**
* Sets the left hand color for this character
* @param color the left hand color ID to set
*/
void SetLeftHand(uint32_t leftHand) { m_LeftHand = leftHand; }
/**
* Sets the right hand color for this character
* @param color the right hand color ID to set
*/
void SetRightHand(uint32_t rightHand) { m_RightHand = rightHand; }
/** /**
* Whether this character has visited a certain zone * Whether this character has visited a certain zone
* @param mapID the ID of the zone to check for * @param mapID the ID of the zone to check for

View File

@ -1644,6 +1644,26 @@ void Entity::PickupItem(const LWOOBJID& objectID) {
droppedLoot.erase(objectID); droppedLoot.erase(objectID);
} }
bool Entity::CanPickupCoins(uint64_t count) {
if (!IsPlayer()) return false;
auto* player = static_cast<Player*>(this);
auto droppedCoins = player->GetDroppedCoins();
if (count > droppedCoins) {
return false;
} else {
player->SetDroppedCoins(droppedCoins - count);
return true;
}
}
void Entity::RegisterCoinDrop(uint64_t count) {
if (!IsPlayer()) return;
auto* player = static_cast<Player*>(this);
auto droppedCoins = player->GetDroppedCoins();
droppedCoins += count;
player->SetDroppedCoins(droppedCoins);
}
void Entity::AddChild(Entity* child) { void Entity::AddChild(Entity* child) {
m_ChildEntities.push_back(child); m_ChildEntities.push_back(child);
} }
@ -1768,6 +1788,7 @@ void Entity::HandleTriggerCommand(std::string id, std::string target, std::strin
else if (argArray[0] == "repulse") effectType = 2; else if (argArray[0] == "repulse") effectType = 2;
else if (argArray[0] == "gravity") effectType = 3; else if (argArray[0] == "gravity") effectType = 3;
else if (argArray[0] == "friction") effectType = 4; else if (argArray[0] == "friction") effectType = 4;
phanPhys->SetEffectType(effectType); phanPhys->SetEffectType(effectType);
phanPhys->SetDirectionalMultiplier(std::stof(argArray[1])); phanPhys->SetDirectionalMultiplier(std::stof(argArray[1]));
if (argArray.size() > 4) { if (argArray.size() > 4) {
@ -1781,6 +1802,10 @@ void Entity::HandleTriggerCommand(std::string id, std::string target, std::strin
phanPhys->SetMin(std::stoi(argArray[6])); phanPhys->SetMin(std::stoi(argArray[6]));
phanPhys->SetMax(std::stoi(argArray[7])); phanPhys->SetMax(std::stoi(argArray[7]));
} }
if (target == "self") {
EntityManager::Instance()->ConstructEntity(this);
}
} }
else if (id == "updateMission") { else if (id == "updateMission") {
CDMissionTasksTable* missionTasksTable = CDClientManager::Instance()->GetTable<CDMissionTasksTable>("MissionTasks"); CDMissionTasksTable* missionTasksTable = CDClientManager::Instance()->GetTable<CDMissionTasksTable>("MissionTasks");

View File

@ -202,6 +202,9 @@ public:
void AddLootItem(const Loot::Info& info); void AddLootItem(const Loot::Info& info);
void PickupItem(const LWOOBJID& objectID); void PickupItem(const LWOOBJID& objectID);
bool CanPickupCoins(uint64_t count);
void RegisterCoinDrop(uint64_t count);
void ScheduleKillAfterUpdate(Entity* murderer = nullptr); void ScheduleKillAfterUpdate(Entity* murderer = nullptr);
void TriggerEvent(std::string eveneventtID, Entity* optionalTarget = nullptr); void TriggerEvent(std::string eveneventtID, Entity* optionalTarget = nullptr);
void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; } void ScheduleDestructionAfterUpdate() { m_ShouldDestroyAfterUpdate = true; }

View File

@ -24,6 +24,7 @@ Player::Player(const LWOOBJID& objectID, const EntityInfo info, User* user, Enti
m_GMLevel = m_Character->GetGMLevel(); m_GMLevel = m_Character->GetGMLevel();
m_SystemAddress = m_ParentUser->GetSystemAddress(); m_SystemAddress = m_ParentUser->GetSystemAddress();
m_DroppedLoot = {}; m_DroppedLoot = {};
m_DroppedCoins = 0;
m_GhostReferencePoint = NiPoint3::ZERO; m_GhostReferencePoint = NiPoint3::ZERO;
m_GhostOverridePoint = NiPoint3::ZERO; m_GhostOverridePoint = NiPoint3::ZERO;
@ -290,6 +291,14 @@ const std::vector<Player*>& Player::GetAllPlayers()
return m_Players; return m_Players;
} }
uint64_t Player::GetDroppedCoins() {
return m_DroppedCoins;
}
void Player::SetDroppedCoins(uint64_t value) {
m_DroppedCoins = value;
}
Player::~Player() Player::~Player()
{ {
Game::logger->Log("Player", "Deleted player\n"); Game::logger->Log("Player", "Deleted player\n");

View File

@ -36,6 +36,8 @@ public:
std::map<LWOOBJID, Loot::Info>& GetDroppedLoot(); std::map<LWOOBJID, Loot::Info>& GetDroppedLoot();
uint64_t GetDroppedCoins();
/** /**
* Setters * Setters
*/ */
@ -52,6 +54,8 @@ public:
void SetGhostOverride(bool value); void SetGhostOverride(bool value);
void SetDroppedCoins(uint64_t value);
/** /**
* Wrapper for sending an in-game mail. * Wrapper for sending an in-game mail.
* *
@ -126,5 +130,7 @@ private:
std::map<LWOOBJID, Loot::Info> m_DroppedLoot; std::map<LWOOBJID, Loot::Info> m_DroppedLoot;
uint64_t m_DroppedCoins;
static std::vector<Player*> m_Players; static std::vector<Player*> m_Players;
}; };

View File

@ -74,7 +74,7 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
includeFaction = 1; includeFaction = 1;
} }
for (auto validTarget : context->GetValidTargets(m_ignoreFaction , includeFaction)) for (auto validTarget : context->GetValidTargets(m_ignoreFaction , includeFaction, m_TargetSelf == 1))
{ {
auto* entity = EntityManager::Instance()->GetEntity(validTarget); auto* entity = EntityManager::Instance()->GetEntity(validTarget);
@ -155,4 +155,6 @@ void AreaOfEffectBehavior::Load()
this->m_ignoreFaction = GetInt("ignore_faction"); this->m_ignoreFaction = GetInt("ignore_faction");
this->m_includeFaction = GetInt("include_faction"); this->m_includeFaction = GetInt("include_faction");
this->m_TargetSelf = GetInt("target_self");
} }

View File

@ -14,6 +14,8 @@ public:
int32_t m_includeFaction; int32_t m_includeFaction;
int32_t m_TargetSelf;
/* /*
* Inherited * Inherited
*/ */

View File

@ -325,7 +325,7 @@ void BehaviorContext::Reset()
this->scheduledUpdates.clear(); this->scheduledUpdates.clear();
} }
std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction) const std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, int32_t includeFaction, bool targetSelf) const
{ {
auto* entity = EntityManager::Instance()->GetEntity(this->caster); auto* entity = EntityManager::Instance()->GetEntity(this->caster);
@ -353,7 +353,7 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
} }
} }
if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && !entity->HasComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS) && targets.empty())) if (ignoreFaction || includeFaction || (!entity->HasComponent(COMPONENT_TYPE_PHANTOM_PHYSICS) && targets.empty()))
{ {
DestroyableComponent* destroyableComponent; DestroyableComponent* destroyableComponent;
if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent)) if (!entity->TryGetComponent(COMPONENT_TYPE_DESTROYABLE, destroyableComponent))
@ -362,12 +362,11 @@ std::vector<LWOOBJID> BehaviorContext::GetValidTargets(int32_t ignoreFaction, in
} }
auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS); auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS);
for (auto* candidate : entities) for (auto* candidate : entities)
{ {
const auto id = candidate->GetObjectID(); const auto id = candidate->GetObjectID();
if (destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction)) if ((id != entity->GetObjectID() || targetSelf) && destroyableComponent->CheckValidity(id, ignoreFaction || includeFaction))
{ {
targets.push_back(id); targets.push_back(id);
} }

View File

@ -102,7 +102,7 @@ struct BehaviorContext
void Reset(); void Reset();
std::vector<LWOOBJID> GetValidTargets(int32_t ignoreFaction = 0, int32_t includeFaction = 0) const; std::vector<LWOOBJID> GetValidTargets(int32_t ignoreFaction = 0, int32_t includeFaction = 0, const bool targetSelf = false) const;
explicit BehaviorContext(LWOOBJID originator, bool calculation = false); explicit BehaviorContext(LWOOBJID originator, bool calculation = false);

View File

@ -1,44 +1,81 @@
#include "ForceMovementBehavior.h" #include "ForceMovementBehavior.h"
#include "BehaviorBranchContext.h" #include "BehaviorBranchContext.h"
#include "BehaviorContext.h" #include "BehaviorContext.h"
#include "ControllablePhysicsComponent.h"
#include "EntityManager.h"
void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) void ForceMovementBehavior::Handle(BehaviorContext* context, RakNet::BitStream* bitStream, const BehaviorBranchContext branch) {
{ if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY)
{
return; return;
} }
uint32_t handle; uint32_t handle;
bitStream->Read(handle); bitStream->Read(handle);
context->RegisterSyncBehavior(handle, this, branch); context->RegisterSyncBehavior(handle, this, branch);
} }
void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) void ForceMovementBehavior::Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch)
{ {
uint32_t next; uint32_t next;
bitStream->Read(next); bitStream->Read(next);
LWOOBJID target; LWOOBJID target;
bitStream->Read(target); bitStream->Read(target);
auto* behavior = CreateBehavior(next);
branch.target = target; branch.target = target;
auto* behavior = CreateBehavior(next);
behavior->Handle(context, bitStream, branch); behavior->Handle(context, bitStream, branch);
} }
void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
if (this->m_hitAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitEnemyAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY && this->m_hitFactionAction->m_templateId == BehaviorTemplates::BEHAVIOR_EMPTY) {
return;
}
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
if (casterEntity != nullptr) {
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr) {
if (m_Forward == 1) {
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
}
EntityManager::Instance()->SerializeEntity(casterEntity);
}
}
const auto skillHandle = context->GetUniqueSkillId();
bitStream->Write(skillHandle);
context->SyncCalculation(skillHandle, this->m_Duration, this, branch);
}
void ForceMovementBehavior::Load() void ForceMovementBehavior::Load()
{ {
this->m_hitAction = GetAction("hit_action"); this->m_hitAction = GetAction("hit_action");
this->m_hitEnemyAction = GetAction("hit_action_enemy"); this->m_hitEnemyAction = GetAction("hit_action_enemy");
this->m_hitFactionAction = GetAction("hit_action_faction"); this->m_hitFactionAction = GetAction("hit_action_faction");
this->m_Duration = GetFloat("duration");
this->m_Forward = GetFloat("forward");
this->m_Left = GetFloat("left");
this->m_Yaw = GetFloat("yaw");
}
void ForceMovementBehavior::SyncCalculation(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) {
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
if (casterEntity != nullptr) {
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr) {
controllablePhysicsComponent->SetPosition(controllablePhysicsComponent->GetPosition() + controllablePhysicsComponent->GetVelocity() * m_Duration);
controllablePhysicsComponent->SetVelocity({});
EntityManager::Instance()->SerializeEntity(casterEntity);
}
}
this->m_hitAction->Calculate(context, bitStream, branch);
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
this->m_hitEnemyAction->Calculate(context, bitStream, branch);
} }

View File

@ -10,6 +10,11 @@ public:
Behavior* m_hitFactionAction; Behavior* m_hitFactionAction;
float_t m_Duration;
float_t m_Forward;
float_t m_Left;
float_t m_Yaw;
/* /*
* Inherited * Inherited
*/ */
@ -18,8 +23,12 @@ public:
{ {
} }
void Calculate(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Handle(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void SyncCalculation(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override; void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override; void Load() override;

View File

@ -129,6 +129,9 @@ BaseCombatAIComponent::BaseCombatAIComponent(Entity* parent, const uint32_t id)
BaseCombatAIComponent::~BaseCombatAIComponent() { BaseCombatAIComponent::~BaseCombatAIComponent() {
if (m_dpEntity) if (m_dpEntity)
dpWorld::Instance().RemoveEntity(m_dpEntity); dpWorld::Instance().RemoveEntity(m_dpEntity);
if (m_dpEntityEnemy)
dpWorld::Instance().RemoveEntity(m_dpEntityEnemy);
} }
void BaseCombatAIComponent::Update(const float deltaTime) { void BaseCombatAIComponent::Update(const float deltaTime) {

View File

@ -352,6 +352,26 @@ void CharacterComponent::LoadFromXML() {
} }
void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) { void CharacterComponent::UpdateXml(tinyxml2::XMLDocument* doc) {
tinyxml2::XMLElement* minifig = doc->FirstChildElement("obj")->FirstChildElement("mf");
if (!minifig) {
Game::logger->Log("CharacterComponent", "Failed to find mf tag while updating XML!\n");
return;
}
// write minifig information that might have been changed by commands
minifig->SetAttribute("es", m_Character->GetEyebrows());
minifig->SetAttribute("ess", m_Character->GetEyes());
minifig->SetAttribute("hc", m_Character->GetHairColor());
minifig->SetAttribute("hs", m_Character->GetHairStyle());
minifig->SetAttribute("l", m_Character->GetPantsColor());
minifig->SetAttribute("lh", m_Character->GetLeftHand());
minifig->SetAttribute("ms", m_Character->GetMouth());
minifig->SetAttribute("rh", m_Character->GetRightHand());
minifig->SetAttribute("t", m_Character->GetShirtColor());
// done with minifig
tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char"); tinyxml2::XMLElement* character = doc->FirstChildElement("obj")->FirstChildElement("char");
if (!character) { if (!character) {
Game::logger->Log("CharacterComponent", "Failed to find char tag while updating XML!\n"); Game::logger->Log("CharacterComponent", "Failed to find char tag while updating XML!\n");

View File

@ -259,11 +259,12 @@ public:
*/ */
void UpdatePlayerStatistic(StatisticID updateID, uint64_t updateValue = 1); void UpdatePlayerStatistic(StatisticID updateID, uint64_t updateValue = 1);
private:
/** /**
* Character info regarding this character, including clothing styles, etc. * Character info regarding this character, including clothing styles, etc.
*/ */
Character* m_Character; Character* m_Character;
private:
/** /**
* Whether this character is racing * Whether this character is racing

View File

@ -7,6 +7,8 @@
#include "NiQuaternion.h" #include "NiQuaternion.h"
#include "tinyxml2.h" #include "tinyxml2.h"
#include "Component.h" #include "Component.h"
#include "dpCollisionChecks.h"
#include "PhantomPhysicsComponent.h"
class Entity; class Entity;
class dpEntity; class dpEntity;
@ -218,6 +220,13 @@ public:
*/ */
bool GetStatic() const { return m_Static; } bool GetStatic() const { return m_Static; }
/**
* Returns the Physics entity for the component
* @return Physics entity for the component
*/
dpEntity* GetdpEntity() const { return m_dpEntity; }
private: private:
/** /**
* The entity that owns this component * The entity that owns this component

View File

@ -110,6 +110,13 @@ public:
*/ */
void SetEffectType(uint32_t type); void SetEffectType(uint32_t type);
/**
* Returns the Physics entity for the component
* @return Physics entity for the component
*/
dpEntity* GetdpEntity() const { return m_dpEntity; }
/** /**
* Spawns an object at each of the vertices for debugging purposes * Spawns an object at each of the vertices for debugging purposes
*/ */

View File

@ -1031,6 +1031,10 @@ void GameMessages::SendDropClientLoot(Entity* entity, const LWOOBJID& sourceID,
entity->AddLootItem(info); entity->AddLootItem(info);
} }
if (item == LOT_NULL && currency != 0) {
entity->RegisterCoinDrop(currency);
}
if (spawnPos != NiPoint3::ZERO) { if (spawnPos != NiPoint3::ZERO) {
bUsePosition = true; bUsePosition = true;
@ -5232,9 +5236,13 @@ void GameMessages::HandlePickupCurrency(RakNet::BitStream* inStream, Entity* ent
unsigned int currency; unsigned int currency;
inStream->Read(currency); inStream->Read(currency);
if (currency == 0) return;
auto* ch = entity->GetCharacter(); auto* ch = entity->GetCharacter();
if (entity->CanPickupCoins(currency)) {
ch->SetCoins(ch->GetCoins() + currency); ch->SetCoins(ch->GetCoins() + currency);
} }
}
void GameMessages::HandleRequestDie(RakNet::BitStream* inStream, Entity* entity) { void GameMessages::HandleRequestDie(RakNet::BitStream* inStream, Entity* entity) {
LWOOBJID killerID; LWOOBJID killerID;

View File

@ -407,6 +407,50 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
stmt->execute(); stmt->execute();
delete stmt; delete stmt;
if (chatCommand == "setMinifig" && args.size() == 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { // could break characters so only allow if GM > 0
int32_t minifigItemId;
if (!GeneralUtils::TryParse(args[1], minifigItemId)) {
ChatPackets::SendSystemMessage(sysAddr, u"Invalid Minifig Item Id ID.");
return;
}
EntityManager::Instance()->DestructEntity(entity, sysAddr);
auto* charComp = entity->GetComponent<CharacterComponent>();
std::string lowerName = args[0];
if (lowerName.empty()) return;
std::transform(lowerName.begin(), lowerName.end(), lowerName.begin(), ::tolower);
if (lowerName == "eyebrows") {
charComp->m_Character->SetEyebrows(minifigItemId);
} else if (lowerName == "eyes") {
charComp->m_Character->SetEyes(minifigItemId);
} else if (lowerName == "haircolor") {
charComp->m_Character->SetHairColor(minifigItemId);
} else if (lowerName == "hairstyle") {
charComp->m_Character->SetHairStyle(minifigItemId);
} else if (lowerName == "pants") {
charComp->m_Character->SetPantsColor(minifigItemId);
} else if (lowerName == "lefthand") {
charComp->m_Character->SetLeftHand(minifigItemId);
} else if (lowerName == "mouth") {
charComp->m_Character->SetMouth(minifigItemId);
} else if (lowerName == "righthand") {
charComp->m_Character->SetRightHand(minifigItemId);
} else if (lowerName == "shirt") {
charComp->m_Character->SetShirtColor(minifigItemId);
} else if (lowerName == "hands") {
charComp->m_Character->SetLeftHand(minifigItemId);
charComp->m_Character->SetRightHand(minifigItemId);
} else {
EntityManager::Instance()->ConstructEntity(entity);
ChatPackets::SendSystemMessage(sysAddr, u"Invalid Minifig item to change, try one of the following: Eyebrows, Eyes, HairColor, HairStyle, Pants, LeftHand, Mouth, RightHand, Shirt, Hands");
return;
}
EntityManager::Instance()->ConstructEntity(entity);
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(lowerName) + u" set to " + (GeneralUtils::to_u16string(minifigItemId)));
GameMessages::SendToggleGMInvis(entity->GetObjectID(), false, UNASSIGNED_SYSTEM_ADDRESS); // need to retoggle because it gets reenabled on creation of new character
}
if (chatCommand == "list-spawns" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { if (chatCommand == "list-spawns" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
for (const auto& pair : EntityManager::Instance()->GetSpawnPointEntities()) { for (const auto& pair : EntityManager::Instance()->GetSpawnPointEntities()) {
ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(pair.first)); ChatPackets::SendSystemMessage(sysAddr, GeneralUtils::ASCIIToUTF16(pair.first));
@ -429,6 +473,10 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
entity->GetCharacter()->UnlockEmote(emoteID); entity->GetCharacter()->UnlockEmote(emoteID);
} }
if (chatCommand == "force-save" && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
entity->GetCharacter()->SaveXMLToDatabase();
}
if (chatCommand == "kill" && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) { if (chatCommand == "kill" && args.size() == 1 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_DEVELOPER) {
ChatPackets::SendSystemMessage(sysAddr, u"Brutally murdering that player, if online on this server."); ChatPackets::SendSystemMessage(sysAddr, u"Brutally murdering that player, if online on this server.");

View File

@ -72,6 +72,7 @@ int main(int argc, char** argv) {
dConfig config("masterconfig.ini"); dConfig config("masterconfig.ini");
Game::config = &config; Game::config = &config;
Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console"))));
Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1");
//Connect to CDClient //Connect to CDClient
try { try {
@ -326,11 +327,13 @@ dLogger* SetupLogger() {
std::string logPath = std::string logPath =
"./logs/MasterServer_" + std::to_string(time(nullptr)) + ".log"; "./logs/MasterServer_" + std::to_string(time(nullptr)) + ".log";
bool logToConsole = false; bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG #ifdef _DEBUG
logToConsole = true; logToConsole = true;
logDebugStatements = true;
#endif #endif
return new dLogger(logPath, logToConsole); return new dLogger(logPath, logToConsole, logDebugStatements);
} }
void HandlePacket(Packet* packet) { void HandlePacket(Packet* packet) {

View File

@ -0,0 +1,24 @@
#include "BuccaneerValiantShip.h"
#include "SkillComponent.h"
#include "dLogger.h"
void BuccaneerValiantShip::OnStartup(Entity* self) {
const auto skill = 982;
const auto behavior = 20577;
const auto skillCastTimer = 1.0F;
self->AddCallbackTimer(skillCastTimer, [self]() {
auto* skillComponent = self->GetComponent<SkillComponent>();
auto* owner = self->GetOwner();
if (skillComponent != nullptr && owner != nullptr) {
skillComponent->CalculateBehavior(skill, behavior, LWOOBJID_EMPTY, true, false, owner->GetObjectID());
// Kill self if missed
const auto selfSmashTimer = 1.1F;
self->AddCallbackTimer(selfSmashTimer, [self]() {
self->Kill();
});
}
});
}

View File

@ -0,0 +1,6 @@
#pragma once
#include "CppScripts.h"
class BuccaneerValiantShip : public CppScripts::Script {
void OnStartup(Entity *self) override;
};

View File

@ -261,6 +261,7 @@
#include "PersonalFortress.h" #include "PersonalFortress.h"
#include "PropertyDevice.h" #include "PropertyDevice.h"
#include "ImaginationBackpackHealServer.h" #include "ImaginationBackpackHealServer.h"
#include "BuccaneerValiantShip.h"
// Survival scripts // Survival scripts
#include "AgSurvivalStromling.h" #include "AgSurvivalStromling.h"
@ -774,6 +775,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
script = new PropertyDevice(); script = new PropertyDevice();
else if (scriptName == "scripts\\02_server\\Map\\General\\L_IMAG_BACKPACK_HEALS_SERVER.lua") else if (scriptName == "scripts\\02_server\\Map\\General\\L_IMAG_BACKPACK_HEALS_SERVER.lua")
script = new ImaginationBackpackHealServer(); script = new ImaginationBackpackHealServer();
else if (scriptName == "scripts\\EquipmentScripts\\BuccaneerValiantShip.lua")
script = new BuccaneerValiantShip();
//Ignore these scripts: //Ignore these scripts:
else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua")
@ -782,7 +785,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
script = invalidToReturn; script = invalidToReturn;
else if (script == invalidToReturn) { else if (script == invalidToReturn) {
if (scriptName.length() > 0) if (scriptName.length() > 0)
Game::logger->Log("CppScripts", "Attempted to load CppScript for '" + scriptName + "', but returned InvalidScript.\n"); Game::logger->LogDebug("CppScripts", "Attempted to load CppScript for '" + scriptName + "', but returned InvalidScript.\n");
// information not really needed for sys admins but is for developers
script = invalidToReturn; script = invalidToReturn;
} }

View File

@ -50,19 +50,19 @@ void NsTokenConsoleServer::OnUse(Entity* self, Entity* user)
if (character->GetPlayerFlag(46)) if (character->GetPlayerFlag(46))
{ {
inventoryComponent->AddItem(8321, 1); inventoryComponent->AddItem(8321, 5);
} }
else if (character->GetPlayerFlag(47)) else if (character->GetPlayerFlag(47))
{ {
inventoryComponent->AddItem(8318, 1); inventoryComponent->AddItem(8318, 5);
} }
else if (character->GetPlayerFlag(48)) else if (character->GetPlayerFlag(48))
{ {
inventoryComponent->AddItem(8320, 1); inventoryComponent->AddItem(8320, 5);
} }
else if (character->GetPlayerFlag(49)) else if (character->GetPlayerFlag(49))
{ {
inventoryComponent->AddItem(8319, 1); inventoryComponent->AddItem(8319, 5);
} }
missionComponent->ForceProgressTaskType(863, 1, 1, false); missionComponent->ForceProgressTaskType(863, 1, 1, false);

View File

@ -136,6 +136,7 @@ int main(int argc, char** argv) {
dConfig config("worldconfig.ini"); dConfig config("worldconfig.ini");
Game::config = &config; Game::config = &config;
Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console")))); Game::logger->SetLogToConsole(bool(std::stoi(config.GetValue("log_to_console"))));
Game::logger->SetLogDebugStatements(config.GetValue("log_debug_statements") == "1");
if (config.GetValue("disable_chat") == "1") chatDisabled = true; if (config.GetValue("disable_chat") == "1") chatDisabled = true;
// Connect to CDClient // Connect to CDClient
@ -503,11 +504,13 @@ int main(int argc, char** argv) {
dLogger * SetupLogger(int zoneID, int instanceID) { dLogger * SetupLogger(int zoneID, int instanceID) {
std::string logPath = "./logs/WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(instanceID) + "_" + std::to_string(time(nullptr)) + ".log"; std::string logPath = "./logs/WorldServer_" + std::to_string(zoneID) + "_" + std::to_string(instanceID) + "_" + std::to_string(time(nullptr)) + ".log";
bool logToConsole = false; bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG #ifdef _DEBUG
logToConsole = true; logToConsole = true;
logDebugStatements = true;
#endif #endif
return new dLogger(logPath, logToConsole); return new dLogger(logPath, logToConsole, logDebugStatements);
} }
void HandlePacketChat(Packet* packet) { void HandlePacketChat(Packet* packet) {

View File

@ -19,6 +19,9 @@ max_clients=999
# 0 or 1, should log to console # 0 or 1, should log to console
log_to_console=1 log_to_console=1
# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation
log_debug_statements=0
# 0 or 1, should ignore playkeys # 0 or 1, should ignore playkeys
# If 1 everyone with an account will be able to login, regardless of if they have a key or not # If 1 everyone with an account will be able to login, regardless of if they have a key or not
dont_use_keys=0 dont_use_keys=0

View File

@ -19,5 +19,8 @@ max_clients=999
# 0 or 1, should log to console # 0 or 1, should log to console
log_to_console=1 log_to_console=1
# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation
log_debug_statements=0
# 0 or 1, should not compile chat hash map to file # 0 or 1, should not compile chat hash map to file
dont_generate_dcf=0 dont_generate_dcf=0

View File

@ -35,5 +35,8 @@ max_clients=999
# 0 or 1, should log to console # 0 or 1, should log to console
log_to_console=1 log_to_console=1
# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation
log_debug_statements=0
# 0 or 1, should autostart auth, chat, and char servers # 0 or 1, should autostart auth, chat, and char servers
prestart_servers=1 prestart_servers=1

View File

@ -20,6 +20,9 @@ max_clients=999
# 0 or 1, should log to console # 0 or 1, should log to console
log_to_console=1 log_to_console=1
# 0 or 1, should log debug (developer only) statements to console for debugging, not needed for normal operation
log_debug_statements=0
# 0 or 1, should not compile chat hash map to file # 0 or 1, should not compile chat hash map to file
dont_generate_dcf=0 dont_generate_dcf=0