From 438b7e1b32240dc56c391ca97f883b93b28b8695 Mon Sep 17 00:00:00 2001 From: SaltyBay Date: Sat, 22 Feb 2020 15:07:05 +0100 Subject: [PATCH] auto unlock for kits and shop items after a given serverruntime --- ArkShop/ArkShop/Private/Kits.cpp | 13 ++++++++++ ArkShop/ArkShop/Private/Store.cpp | 13 ++++++++++ ArkShop/ArkShop/Private/Tools.h | 41 +++++++++++++++++++++++++++++++ ArkShop/Configs/config.json | 35 ++++++++++++++++++++++++-- 4 files changed, 100 insertions(+), 2 deletions(-) diff --git a/ArkShop/ArkShop/Private/Kits.cpp b/ArkShop/ArkShop/Private/Kits.cpp index 85e58afc..c6d2fdee 100644 --- a/ArkShop/ArkShop/Private/Kits.cpp +++ b/ArkShop/ArkShop/Private/Kits.cpp @@ -270,6 +270,19 @@ namespace ArkShop::Kits return; } + const unsigned time = kit_entry.value("Time", 0) * 3600; + auto currentServerTime = ArkApi::GetApiUtils().GetWorld()->TimeSecondsField(); + + if (time > currentServerTime) + { + Tools::Time_t timediff = Tools::GetAvailableTimeDiff(time, currentServerTime); + + ArkApi::GetApiUtils().SendChatMessage(player_controller, GetText("Sender"), + *GetText("BadTimeKit"), timediff.hours, timediff.minutes); + + return; + } + if (const int kit_amount = GetKitAmount(steam_id, kit_name); kit_amount > 0 && ChangeKitAmount(kit_name, -1, steam_id)) { diff --git a/ArkShop/ArkShop/Private/Store.cpp b/ArkShop/ArkShop/Private/Store.cpp index e72874d2..b86b7d01 100644 --- a/ArkShop/ArkShop/Private/Store.cpp +++ b/ArkShop/ArkShop/Private/Store.cpp @@ -293,6 +293,19 @@ namespace ArkShop::Store return false; } + const unsigned time = item_entry.value("Time", 0) * 3600; + auto currentServerTime = ArkApi::GetApiUtils().GetWorld()->TimeSecondsField(); + + if (time > currentServerTime) + { + Tools::Time_t timediff = Tools::GetAvailableTimeDiff(time, currentServerTime); + + ArkApi::GetApiUtils().SendChatMessage(player_controller, GetText("Sender"), + *GetText("BadTimeShop"), timediff.hours, timediff.minutes); + + return false; + } + if (type == "item") { success = BuyItem(player_controller, item_entry, steam_id, amount); diff --git a/ArkShop/ArkShop/Private/Tools.h b/ArkShop/ArkShop/Private/Tools.h index c6a0b932..a95fd7fb 100644 --- a/ArkShop/ArkShop/Private/Tools.h +++ b/ArkShop/ArkShop/Private/Tools.h @@ -4,6 +4,20 @@ namespace ArkShop::Tools { + /* ============================================ [type definitions] ============================================ */ + + /** + * \brief time struct + */ + typedef struct + { + int hours; /**< \brief value for hours */ + int minutes; /**< \brief value for minutes */ + int secounds; /**< \brief value for secounds */ + + }Time_t; + + inline int GetRandomNumber(int min, int max) { const int n = max - min + 1; @@ -18,4 +32,31 @@ namespace ArkShop::Tools return min + x % n; } + + /** + * \brief Gets a Time_t + * + * This functions returns a Time_t with difference of the time + * + * \param[in] AvailableTime the timer + * \param[in] ServerRunTime the current server runntime + * \return Time_t struct with the times + */ + inline Time_t GetAvailableTimeDiff(long double AvailableTime, long double ServerRunTime) + { + Time_t result = { 0 }; + + int timediff = int(AvailableTime - ServerRunTime); + + if (0 < timediff) + { + result.hours = (int)(timediff / 3600); + result.minutes = (int)(((float)(timediff % 3600)) / 60); + result.secounds = (int)((float)((timediff % 3600) % 60)); + } + + return result; + } + + } // namespace Tools // namespace ArkShop diff --git a/ArkShop/Configs/config.json b/ArkShop/Configs/config.json index ff278708..314aba44 100644 --- a/ArkShop/Configs/config.json +++ b/ArkShop/Configs/config.json @@ -71,9 +71,29 @@ "Blueprint":"Blueprint'/Game/PrimalEarth/CoreBlueprints/Weapons/PrimalItem_WeaponStoneClub.PrimalItem_WeaponStoneClub'" } ] - } + }, + "Startflyer": { + "DefaultAmount": 2, + "Description": "Ptera and saddle (useable 40 hours after wipe)", + "OnlyFromSpawn": false, + "Time": 40, + "Items": [ + { + "Amount": 1, + "Quality": 0, + "ForceBlueprint": false, + "Blueprint": "Blueprint'/Game/PrimalEarth/CoreBlueprints/Items/Armor/Saddles/PrimalItemArmor_PteroSaddle.PrimalItemArmor_PteroSaddle'" + } + ], + "Dinos": [ + { + "Level": 180, + "Blueprint": "Blueprint'/Game/PrimalEarth/Dinos/Ptero/Ptero_Character_BP.Ptero_Character_BP'" + } + ] + } }, - "ShopItems":{ + "ShopItems":{ "ingots100":{ "Type":"item", "Description":"Metal Ingot (100x)", @@ -115,6 +135,15 @@ "MaxLevel":15, "Blueprint":"Blueprint'/Game/PrimalEarth/Dinos/Para/Para_Character_BP.Para_Character_BP'" }, + "Pteranodon": { + "Type": "dino", + "Description": "Pteranodon (buyable 72 hours after wipe)", + "Level": 224, + "Price": 1200, + "Time": 72, + "Neutered": false, + "Blueprint": "Blueprint'/Game/PrimalEarth/Dinos/Ptero/Ptero_Character_BP.Ptero_Character_BP'" + }, "carno":{ "Type":"dino", "Description":"Carnotaurus", @@ -215,6 +244,8 @@ "NotEnoughItems":"You don't have enough items ({0}/{1})", "SoldItems":"You have successfully sold items", "BadLevel":"Required level: {0} - {1}", + "BadTimeShop": "Item available in: {0} hours, {1} minutes ", + "BadTimeKit": "Kit available in: {0} hours, {1} minutes ", "KitsListPrice":"Price: {0}", "KitsListFormat":"\"{0}\" - {1}. {2} left. {3}\n", "StoreListDino":"{0}) {1}. Level: {2}. Id: {3}. Price: {4}\n",