Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Irateredkite/daily task tweaks #408

Merged
merged 8 commits into from
Mar 6, 2024
Merged
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 4.0.23
- Fixed some major issues with daily_tasks.

## 4.0.22
- Add call to Release() after a CObject::Find that was causing poor performance.

Expand Down
48 changes: 31 additions & 17 deletions plugins/daily_tasks/DailyTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,13 @@ namespace Plugins::DailyTasks
}

Hk::Player::AddCash(client, creditReward + surplusCreditReward);
if (itemQuantity > 0)
if (itemQuantity)
{
// Hk::Player::AddCargo causes a kick here, so we have to do this with the pub function
pub::Player::AddCargo(client, itemReward, itemQuantity, 1, false);
Hk::Player::AddCargo(client, itemReward, itemQuantity, false);
if (const auto& equip = Players[client].equipDescList.equip; &equip != &Players[client].lShadowEquipDescList.equip)
{
Players[client].lShadowEquipDescList.equip = equip;
}
}
PrintUserCmdText(client,
std::format(L"Task completed! You have been awarded {} credits and {} units of {}.",
Expand Down Expand Up @@ -274,11 +277,13 @@ namespace Plugins::DailyTasks
}
if (task.quantityCompleted == task.quantity && task.taskType == TaskType::KillPlayer && task.isCompleted == false)
{
auto remainingHoldSize = 0.f;
pub::Player::GetRemainingHoldSize(killerId.value(), remainingHoldSize);
task.isCompleted = true;
SaveTaskStatusToJson(Hk::Client::GetAccountByClientID(killerId.value()));
PrintUserCmdText(client, std::format(L"You have completed {}", stows(task.taskDescription)));
Hk::Client::PlaySoundEffect(client, CreateID("ui_gain_level"));
GenerateReward(client);
PrintUserCmdText(killerId.value(), std::format(L"You have completed {}", stows(task.taskDescription)));
Hk::Client::PlaySoundEffect(killerId.value(), CreateID("ui_gain_level"));
GenerateReward(killerId.value(), remainingHoldSize);
}
}
}
Expand All @@ -301,11 +306,13 @@ namespace Plugins::DailyTasks
if (task.quantityCompleted == task.quantity && task.taskType == TaskType::KillNpc && !task.isCompleted &&
task.npcFactionTarget == affiliation)
{
auto remainingHoldSize = 0.f;
pub::Player::GetRemainingHoldSize(killerId.value(), remainingHoldSize);
task.isCompleted = true;
SaveTaskStatusToJson(Hk::Client::GetAccountByClientID(killerId.value()));
PrintUserCmdText(client, std::format(L"You have completed {}", stows(task.taskDescription)));
Hk::Client::PlaySoundEffect(client, CreateID("ui_gain_level"));
GenerateReward(client);
PrintUserCmdText(killerId.value(), std::format(L"You have completed {}", stows(task.taskDescription)));
Hk::Client::PlaySoundEffect(killerId.value(), CreateID("ui_gain_level"));
GenerateReward(killerId.value(), remainingHoldSize);
}
}
}
Expand Down Expand Up @@ -416,7 +423,7 @@ namespace Plugins::DailyTasks
pub::Reputation::GetGroupName(npcFactionTarget, npcFactionIds);

task.taskType = KillNpc;
task.taskDescription = std::format("Destroy {} ships belonging to the {}.", npcQuantity, wstos(Hk::Message::GetWStringFromIdS(npcFactionIds)));
oliverpechey marked this conversation as resolved.
Show resolved Hide resolved
task.taskDescription = std::format("Destroy {} ships belonging to {}", npcQuantity, wstos(Hk::Message::GetWStringFromIdS(npcFactionIds)));
task.npcFactionTarget = npcFactionTarget;
task.quantity = npcQuantity;
AddLog(LogType::Normal, LogLevel::Debug, std::format("Creating a 'Kill NPCs' task to '{}'", task.taskDescription));
Expand Down Expand Up @@ -506,22 +513,29 @@ namespace Plugins::DailyTasks
if (!task.isCompleted)
{
PrintUserCmdText(client,
std::format(L"{} Expires in {} hours. {}/{} remaining.", stows(task.taskDescription), taskExpiry, task.quantityCompleted, task.quantity));
std::format(L"{} | Expires in {} hours | {}/{} remaining.",
stows(task.taskDescription),
taskExpiry,
task.quantity - task.quantityCompleted,
task.quantity));
}
else
{
PrintUserCmdText(client, stows(task.taskDescription + " TASK COMPLETED"));
PrintUserCmdText(client, stows(task.taskDescription + " | Task Completed"));
}
}
}

/** @ingroup DailyTasks
* @brief Hook on PlayerLaunch to display the task list when the player undocks.
*/
void DisplayTasksOnLaunch([[maybe_unused]] const uint& ship, ClientId& client)
void DisplayTasksOnLaunch([[maybe_unused]] const std::string_view& charFilename, ClientId& client)
{
PrintTasks(client);
PrintUserCmdText(client, L"To view this list again, type /showtasks in chat.");
if (global->config->displayMessage)
{
PrintTasks(client);
PrintUserCmdText(client, L"To view this list again, type /showtasks in chat.");
}
}

/** @ingroup DailyTasks
Expand Down Expand Up @@ -666,7 +680,7 @@ using namespace Plugins::DailyTasks;

REFL_AUTO(type(Config), field(taskQuantity), field(minCreditsReward), field(maxCreditsReward), field(itemRewardPool), field(taskTradeBaseTargets),
field(taskTradeItemTargets), field(taskItemAcquisitionTargets), field(taskNpcKillTargets), field(taskPlayerKillTargets), field(taskDuration),
field(resetTime));
field(resetTime), field(displayMessage));

REFL_AUTO(type(Tasks), field(tasks));

Expand All @@ -692,5 +706,5 @@ extern "C" EXPORT void ExportPluginInfo(PluginInfo* pi)
pi->emplaceHook(HookedCall::IEngine__ShipDestroyed, &ShipDestroyed);
pi->emplaceHook(HookedCall::IServerImpl__GFGoodSell, &ItemSold, HookStep::After);
pi->emplaceHook(HookedCall::IServerImpl__BaseEnter, &SaveTaskStatusOnBaseEnter, HookStep::After);
pi->emplaceHook(HookedCall::IServerImpl__PlayerLaunch, &DisplayTasksOnLaunch);
pi->emplaceHook(HookedCall::IServerImpl__CharacterSelect, &DisplayTasksOnLaunch);
}
2 changes: 2 additions & 0 deletions plugins/daily_tasks/DailyTasks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ namespace Plugins::DailyTasks
int resetTime = 12;
//! The amount of time in seconds a player has to complete a set of assigned tasks before they get cleaned up during the hourly check or at login.
int taskDuration = 86400;
//! Whether or not to display a message with daily task data when a player logs in.
bool displayMessage = true;
};

enum class TaskType
Expand Down
1 change: 1 addition & 0 deletions plugins/daily_tasks/DailyTasks.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<RootNamespace>$projectname$</RootNamespace>
<Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>Daily Tasks</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
Expand Down
Loading