Merge branch 'main' into die-roll-anims-ckawell

This commit is contained in:
Christopher Kawell 2021-12-15 13:27:11 -06:00 committed by GitHub
commit 34050f641d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 190 additions and 105 deletions

View File

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

View File

@ -45,6 +45,7 @@ int main(int argc, char** argv) {
dConfig config("authconfig.ini");
Game::config = &config;
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
std::string mysql_host = config.GetValue("mysql_host");
@ -152,11 +153,13 @@ int main(int argc, char** argv) {
dLogger * SetupLogger() {
std::string logPath = "./logs/AuthServer_" + std::to_string(time(nullptr)) + ".log";
bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG
logToConsole = true;
logDebugStatements = true;
#endif
return new dLogger(logPath, logToConsole);
return new dLogger(logPath, logToConsole, logDebugStatements);
}
void HandlePacket(Packet* packet) {

View File

@ -48,6 +48,7 @@ int main(int argc, char** argv) {
dConfig config("chatconfig.ini");
Game::config = &config;
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
std::string mysql_host = config.GetValue("mysql_host");
@ -156,14 +157,16 @@ int main(int argc, char** argv) {
return 0;
}
dLogger* SetupLogger() {
dLogger * SetupLogger() {
std::string logPath = "./logs/ChatServer_" + std::to_string(time(nullptr)) + ".log";
bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG
logToConsole = true;
logDebugStatements = true;
#endif
return new dLogger(logPath, logToConsole);
return new dLogger(logPath, logToConsole, logDebugStatements);
}
void HandlePacket(Packet* packet) {

View File

@ -1,7 +1,8 @@
#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_logDebugStatements = logDebugStatements;
m_outpath = outpath;
#ifdef _WIN32
@ -24,39 +25,25 @@ dLogger::~dLogger() {
#endif
}
void dLogger::LogBasic(const std::string & message) {
LogBasic(message.c_str());
}
void dLogger::LogBasic(const char * format, ...) {
void dLogger::vLog(const char* format, va_list args) {
#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_start(args, format);
vsprintf_s(message, format, args);
va_end(args);
if (m_logToConsole) std::cout << "[" << "time machine broke" << "] " << message;
mFile << "[" << "time" << "] " << message;
if (m_logToConsole) std::cout << "[" << timeStr << "] " << message;
mFile << "[" << timeStr << "] " << 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);
@ -76,62 +63,42 @@ void dLogger::LogBasic(const char * format, ...) {
#endif
}
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];
void dLogger::LogBasic(const char * format, ...) {
va_list args;
va_start(args, format);
vsprintf_s(message, format, args);
vLog(format, 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);
void dLogger::LogBasic(const std::string & message) {
LogBasic(message.c_str());
}
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 char * className, const char * format, ...) {
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::Log(const std::string & className, const std::string & message) {
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() {
#ifdef _WIN32
mFile.flush();

View File

@ -7,21 +7,26 @@
class dLogger {
public:
dLogger(const std::string& outpath, bool logToConsole);
dLogger(const std::string& outpath, bool logToConsole, bool logDebugStatements);
~dLogger();
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 char* format, ...);
void Log(const char* className, const char* format, ...);
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();
const bool GetIsLoggingToConsole() const { return m_logToConsole; }
private:
bool m_logDebugStatements;
bool m_logToConsole;
std::string m_outpath;
std::ofstream mFile;

View File

@ -74,7 +74,7 @@ void AreaOfEffectBehavior::Calculate(BehaviorContext* context, RakNet::BitStream
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);
@ -155,4 +155,6 @@ void AreaOfEffectBehavior::Load()
this->m_ignoreFaction = GetInt("ignore_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_TargetSelf;
/*
* Inherited
*/

View File

@ -325,7 +325,7 @@ void BehaviorContext::Reset()
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);
@ -353,21 +353,20 @@ 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))
{
return targets;
}
auto entities = EntityManager::Instance()->GetEntitiesByComponent(COMPONENT_TYPE_CONTROLLABLE_PHYSICS);
for (auto* candidate : entities)
{
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);
}

View File

@ -102,7 +102,7 @@ struct BehaviorContext
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);

View File

@ -1,44 +1,81 @@
#include "ForceMovementBehavior.h"
#include "BehaviorBranchContext.h"
#include "BehaviorContext.h"
#include "ControllablePhysicsComponent.h"
#include "EntityManager.h"
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)
{
return;
}
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) {
return;
}
uint32_t handle;
bitStream->Read(handle);
context->RegisterSyncBehavior(handle, this, branch);
uint32_t handle;
bitStream->Read(handle);
context->RegisterSyncBehavior(handle, this, 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;
bitStream->Read(target);
LWOOBJID target;
branch.target = target;
auto* behavior = CreateBehavior(next);
behavior->Handle(context, bitStream, branch);
}
bitStream->Read(target);
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* behavior = CreateBehavior(next);
auto* casterEntity = EntityManager::Instance()->GetEntity(context->caster);
if (casterEntity != nullptr) {
auto* controllablePhysicsComponent = casterEntity->GetComponent<ControllablePhysicsComponent>();
if (controllablePhysicsComponent != nullptr) {
branch.target = target;
if (m_Forward == 1) {
controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25);
}
behavior->Handle(context, bitStream, branch);
EntityManager::Instance()->SerializeEntity(casterEntity);
}
}
const auto skillHandle = context->GetUniqueSkillId();
bitStream->Write(skillHandle);
context->SyncCalculation(skillHandle, this->m_Duration, this, branch);
}
void ForceMovementBehavior::Load()
{
this->m_hitAction = GetAction("hit_action");
this->m_hitEnemyAction = GetAction("hit_action_enemy");
this->m_hitFactionAction = GetAction("hit_action_faction");
this->m_hitAction = GetAction("hit_action");
this->m_hitEnemyAction = GetAction("hit_action_enemy");
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;
float_t m_Duration;
float_t m_Forward;
float_t m_Left;
float_t m_Yaw;
/*
* 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 SyncCalculation(BehaviorContext *context, RakNet::BitStream *bitStream, BehaviorBranchContext branch) override;
void Sync(BehaviorContext* context, RakNet::BitStream* bitStream, BehaviorBranchContext branch) override;
void Load() override;

View File

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

View File

@ -407,7 +407,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
stmt->execute();
delete stmt;
if (chatCommand == "setMinifig" && args.size() == 2 && entity->GetGMLevel() >= GAME_MASTER_LEVEL_FORUM_MODERATOR) { // could break characters so only allow if GM > 0
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.");
@ -434,7 +434,7 @@ void SlashCommandHandler::HandleChatCommand(const std::u16string& command, Entit
charComp->m_Character->SetMouth(minifigItemId);
} else if (lowerName == "righthand") {
charComp->m_Character->SetRightHand(minifigItemId);
} else if (lowerName == "shirt") {
} else if (lowerName == "shirtcolor") {
charComp->m_Character->SetShirtColor(minifigItemId);
} else if (lowerName == "hands") {
charComp->m_Character->SetLeftHand(minifigItemId);

View File

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

@ -262,6 +262,7 @@
#include "PropertyDevice.h"
#include "ImaginationBackpackHealServer.h"
#include "LegoDieRoll.h"
#include "BuccaneerValiantShip.h"
// Survival scripts
#include "AgSurvivalStromling.h"
@ -777,6 +778,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
script = new ImaginationBackpackHealServer();
else if (scriptName == "scripts\\ai\\GENERAL\\L_LEGO_DIE_ROLL.lua")
script = new LegoDieRoll();
else if (scriptName == "scripts\\EquipmentScripts\\BuccaneerValiantShip.lua")
script = new BuccaneerValiantShip();
//Ignore these scripts:
else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua")
@ -785,7 +788,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr
script = invalidToReturn;
else if (script == invalidToReturn) {
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;
}

View File

@ -136,6 +136,7 @@ int main(int argc, char** argv) {
dConfig config("worldconfig.ini");
Game::config = &config;
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;
// Connect to CDClient
@ -503,11 +504,13 @@ int main(int argc, char** argv) {
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";
bool logToConsole = false;
bool logDebugStatements = false;
#ifdef _DEBUG
logToConsole = true;
logDebugStatements = true;
#endif
return new dLogger(logPath, logToConsole);
return new dLogger(logPath, logToConsole, logDebugStatements);
}
void HandlePacketChat(Packet* packet) {

View File

@ -19,6 +19,9 @@ max_clients=999
# 0 or 1, should log to console
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
# If 1 everyone with an account will be able to login, regardless of if they have a key or not
dont_use_keys=0

View File

@ -19,5 +19,8 @@ max_clients=999
# 0 or 1, should log to console
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
dont_generate_dcf=0

View File

@ -32,5 +32,8 @@ max_clients=999
# 0 or 1, should log to console
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
prestart_servers=1

View File

@ -20,6 +20,9 @@ max_clients=999
# 0 or 1, should log to console
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
dont_generate_dcf=0