Skip to content

Commit

Permalink
Updated for 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebring committed Jan 31, 2018
1 parent eaa2d18 commit 6b0df0e
Show file tree
Hide file tree
Showing 29 changed files with 1,463 additions and 15,438 deletions.
1,289 changes: 68 additions & 1,221 deletions ArkGameTestingCommands/ArkGameTestingCommands.cpp

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions ArkGameTestingCommands/ArkGameTestingCommands.h

This file was deleted.

29 changes: 17 additions & 12 deletions ArkGameTestingCommands/ArkGameTestingCommands.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<VCProjectVersion>15.0</VCProjectVersion>
<ProjectGuid>{1DCA1C38-37D0-4F80-BB0B-3B433E64222F}</ProjectGuid>
<RootNamespace>ArkGameTestingCommands</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
<WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down Expand Up @@ -70,8 +70,8 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<IncludePath>C:\ArkApi\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\ArkApi\lib;$(LibraryPath)</LibraryPath>
<IncludePath>C:\ArkApi2\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\ArkApi2\lib;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
Expand Down Expand Up @@ -107,6 +107,8 @@
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<LanguageStandard>stdcpp17</LanguageStandard>
<PreprocessorDefinitions>_SILENCE_ALL_CXX17_DEPRECATION_WARNINGS;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
Expand All @@ -115,17 +117,20 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="ArkGameTestingCommands.cpp" />
<ClCompile Include="GiveCustomItems.cpp" />
<ClCompile Include="SpawnCustomDino.cpp" />
<ClCompile Include="Tools.cpp" />
<ClCompile Include="Commands\HealthCommand.cpp" />
<ClCompile Include="Commands\ItemTemplateCommand.cpp" />
<ClCompile Include="Commands\SpawnTemplateCommand.cpp" />
<ClCompile Include="Commands\TeleportToCommand.cpp" />
<ClCompile Include="Plugin.cpp" />
<ClCompile Include="Utils.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="ArkGameTestingCommands.h" />
<ClInclude Include="GiveCustomItems.h" />
<ClInclude Include="GiveItemsTemplate.h" />
<ClInclude Include="json.hpp" />
<ClInclude Include="SpawnCustomDino.h" />
<ClInclude Include="Tools.h" />
<ClInclude Include="Commands\HealthCommand.h" />
<ClInclude Include="Commands\ItemTemplateCommand.h" />
<ClInclude Include="Commands\SpawnTemplateCommand.h" />
<ClInclude Include="Commands\TeleportToCommand.h" />
<ClInclude Include="Plugin.h" />
<ClInclude Include="Utils.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
43 changes: 29 additions & 14 deletions ArkGameTestingCommands/ArkGameTestingCommands.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,54 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Header Files\Commands">
<UniqueIdentifier>{077fb3e3-f44f-4490-ae71-65a1f8a90468}</UniqueIdentifier>
</Filter>
<Filter Include="Source Files\Commands">
<UniqueIdentifier>{0cb2b033-1b39-4fde-813c-8f262890551b}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="ArkGameTestingCommands.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SpawnCustomDino.cpp">
<ClCompile Include="Utils.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Tools.cpp">
<Filter>Source Files</Filter>
<ClCompile Include="Commands\SpawnTemplateCommand.cpp">
<Filter>Source Files\Commands</Filter>
</ClCompile>
<ClCompile Include="GiveCustomItems.cpp">
<ClCompile Include="Plugin.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Commands\HealthCommand.cpp">
<Filter>Source Files\Commands</Filter>
</ClCompile>
<ClCompile Include="Commands\ItemTemplateCommand.cpp">
<Filter>Source Files\Commands</Filter>
</ClCompile>
<ClCompile Include="Commands\TeleportToCommand.cpp">
<Filter>Source Files\Commands</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ArkGameTestingCommands.h">
<ClInclude Include="Utils.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SpawnCustomDino.h">
<Filter>Header Files</Filter>
<ClInclude Include="Commands\SpawnTemplateCommand.h">
<Filter>Header Files\Commands</Filter>
</ClInclude>
<ClInclude Include="Tools.h">
<ClInclude Include="Plugin.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="json.hpp">
<Filter>Header Files</Filter>
<ClInclude Include="Commands\HealthCommand.h">
<Filter>Header Files\Commands</Filter>
</ClInclude>
<ClInclude Include="GiveItemsTemplate.h">
<Filter>Header Files</Filter>
<ClInclude Include="Commands\ItemTemplateCommand.h">
<Filter>Header Files\Commands</Filter>
</ClInclude>
<ClInclude Include="GiveCustomItems.h">
<Filter>Header Files</Filter>
<ClInclude Include="Commands\TeleportToCommand.h">
<Filter>Header Files\Commands</Filter>
</ClInclude>
</ItemGroup>
</Project>
133 changes: 133 additions & 0 deletions ArkGameTestingCommands/Commands/HealthCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
#include "HealthCommand.h"

void HealthChatCommand(AShooterPlayerController* aShooterPlayerController, FString* msg, EChatSendMode::Type mode)
{
auto result = HealthInternal(aShooterPlayerController, ArkLibrary::GetCommand(CommandName_Health_Chat));
if (result.size() == 0) return;

for (auto str : result) ArkApi::GetApiUtils().SendChatMessage(aShooterPlayerController, L"[system]", str.c_str());
}

void HealthConsoleCommand(APlayerController* aPlayerController, FString* msg, bool bWriteToLog)
{
auto aShooterPlayerController = static_cast<AShooterPlayerController*>(aPlayerController);

auto result = HealthInternal(aShooterPlayerController, ArkLibrary::GetCommand(CommandName_Health_Console));
if (result.size() == 0) return;

std::wstringstream ss;
for (auto str : result) ss << ArkApi::Tools::ConvertToWideStr(str) << std::endl;

ArkApi::GetApiUtils().SendNotification(aShooterPlayerController, { 1, 0, 1, 1 }, 0.8f, 30.0f, nullptr, ss.str().c_str());
}

std::list<std::string> HealthInternal(AShooterPlayerController* aShooterPlayerController, ArkLibrary::CommandDefinition *cmd)
{
std::list<std::string> result;

UWorld* world = ArkApi::GetApiUtils().GetWorld();
if (!world) return result;
if (!aShooterPlayerController) return result;

ACharacter* character = aShooterPlayerController->CharacterField()();
if (!character || !character->IsA(APrimalCharacter::GetPrivateStaticClass())) return result;

APrimalCharacter* primalCharacter = static_cast<APrimalCharacter*>(character);

std::map<std::string, std::list<std::tuple<float, float>>> statuses;
FVector* pos = new FVector();
int teamId = aShooterPlayerController->TargetingTeamField()();
FVector playerPos = aShooterPlayerController->DefaultActorLocationField()();

TArray<AActor*>* FoundActors = new TArray<AActor*>();
UGameplayStatics::GetAllActorsOfClass(reinterpret_cast<UObject *>(world), APrimalDinoCharacter::GetPrivateStaticClass(), FoundActors);

for (uint32_t i = 0; i < FoundActors->Num(); i++)
{
AActor* actor = (*FoundActors)[i];

APrimalDinoCharacter* dino = static_cast<APrimalDinoCharacter*>(actor);

int dinoTeam = dino->TargetingTeamField()();

dino->RootComponentField()()->GetCustomLocation(pos);
if (dinoTeam == teamId && ArkLibrary::IsPointInside2dCircle(*pos, playerPos.X, playerPos.Y, 5000))
{
FString className;
dino->DinoNameTagField()().ToString(&className); //species name
//std::string name = dino->GetTamedNameField().ToString(); //tamed name

UPrimalCharacterStatusComponent* status = dino->MyCharacterStatusComponentField()();
if (status)
{
float* currentStatValues = status->CurrentStatusValuesField()();
float* maxStatsValues = status->MaxStatusValuesField()();

std::string classNameStr = className.ToString();

if (statuses.find(classNameStr) == statuses.end())
{
auto list = std::list<std::tuple<float, float>>();
list.push_back(std::make_tuple(currentStatValues[0], maxStatsValues[0]));
statuses[classNameStr] = list;
}
else
{
statuses[classNameStr].push_back(std::make_tuple(currentStatValues[0], maxStatsValues[0]));
}
}
}
}
delete FoundActors;
delete pos;

for (std::map<std::string, std::list<std::tuple<float, float>>>::const_iterator it = statuses.begin(), end = statuses.end(); it != end; ++it)
{
std::string name = it->first;
std::list<float> percentages;
double totalHealth = 0.0;
double totalRemaining = 0.0;
double totalDiff = 0.0;

for (std::list<std::tuple<float, float>>::const_iterator it2 = it->second.begin(), end2 = it->second.end(); it2 != end2; ++it2)
{
float currentHealth = std::get<0>(*it2);
float maxHealth = std::get<1>(*it2);
float healthPercentage = currentHealth / maxHealth;
float healthDiff = maxHealth - currentHealth;

totalHealth += maxHealth;
totalRemaining += currentHealth;
totalDiff += healthDiff;

percentages.push_back(healthPercentage);
}

percentages.sort([](const float & a, const float & b) { return a < b; });

std::stringstream ss;
ss << name << " (" << percentages.size() << "): ";

int n = 0;
for (std::list<float>::const_iterator it2 = percentages.begin(), end2 = percentages.end(); it2 != end2; ++it2)
{
if (n > 0) ss << ", ";
ss << std::round(*it2 * 100.0);

n++;
}

result.push_back(ss.str());
ss.str(std::string());

//avoid divide-by-zero exception
if (totalHealth > 0.0)
{
ss << "Remaining: " << std::round((totalRemaining / totalHealth) * 100.0) << "%, Diff: " << std::round(-totalDiff);
}

result.push_back(ss.str());
}

return result;
}
9 changes: 9 additions & 0 deletions ArkGameTestingCommands/Commands/HealthCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once
#include "../Plugin.h"

DECLARE_COMMAND(Health_Chat);
DECLARE_COMMAND(Health_Console);

void HealthChatCommand(AShooterPlayerController* aShooterPlayerController, FString* msg, EChatSendMode::Type mode);
void HealthConsoleCommand(APlayerController* aPlayerController, FString* msg, bool bWriteToLog);
std::list<std::string> HealthInternal(AShooterPlayerController* aShooterPlayerController, ArkLibrary::CommandDefinition *cmd);
76 changes: 76 additions & 0 deletions ArkGameTestingCommands/Commands/ItemTemplateCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "ItemTemplateCommand.h"

void ItemTemplateConsoleCommand(APlayerController* aPlayerController, FString* msg, bool bWriteToLog)
{
auto aShooterPlayerController = static_cast<AShooterPlayerController*>(aPlayerController);

auto &plugin = Plugin::Get();
auto cmd = ArkLibrary::GetCommand(CommandName_ItemTemplate_Console);

TArray<FString> Parsed;
msg->ParseIntoArray(Parsed, L" ", true);

if (Parsed.IsValidIndex(1))
{
std::string templateName = Parsed[1].ToString();

auto templatesList = cmd->Json["Templates"];

auto templateEntryIter = templatesList.find(templateName);
if (templateEntryIter == templatesList.end())
{
ArkApi::GetApiUtils().SendChatMessage(aShooterPlayerController, L"[system]", L"The template does not exist! Maybe you forgot to reload..?");
return;
}

auto templateEntry = templateEntryIter.value();

__int64 steamId = ArkApi::GetApiUtils().GetSteamIdFromController(aShooterPlayerController);

int count;
std::list<ArkLibrary::GiveItemDefinition> items;

try
{
count = templateEntry.value("count", 1);

auto itemsMap = templateEntry.value("items", nlohmann::json::array());
for (auto iter = itemsMap.begin(); iter != itemsMap.end(); ++iter)
{
auto item = iter.value();

std::string blueprint = item.value("blueprint", "");
std::list<std::string> blueprints = item.find("blueprints") != item.end() ? item["blueprints"] : std::list<std::string>();
int quantity = item.value("quantity", 0);
int count = item.value("count", 1);
float quality = item.value("quality", 0.0);

ArkLibrary::GiveItemDefinition giveItemDef;
giveItemDef.blueprint = blueprint;
giveItemDef.blueprints = blueprints;
giveItemDef.quantity = quantity;
giveItemDef.count = count;
giveItemDef.quality = quality;

items.push_back(giveItemDef);
}
}
catch (const std::exception&)
{
ArkApi::GetApiUtils().SendChatMessage(aShooterPlayerController, L"[system]", L"Failed to read template...");
return;
}

bool success = true;
for (int i = 0; i < count; i++)
{
bool innerSuccess = GiveCustomItems(steamId, items);

if (!innerSuccess)
{
success = false;
break;
}
}
}
}
7 changes: 7 additions & 0 deletions ArkGameTestingCommands/Commands/ItemTemplateCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#pragma once
#include "../Plugin.h"
#include <ArkPluginLibrary/GiveCustomItems.h>

DECLARE_COMMAND(ItemTemplate_Console);

void ItemTemplateConsoleCommand(APlayerController* aPlayerController, FString* msg, bool bWriteToLog);
Loading

0 comments on commit 6b0df0e

Please sign in to comment.