From b74f927f1b88beb3f9612636024c4959510a9707 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Wed, 8 Jun 2022 02:57:09 +0700 Subject: [PATCH] Add `GetTrader()` command to trading component --- .../Frontend/Trading/ATradingComponent.uc | 10 ++++++++++ .../Trading/KF1_TradingComponent.uc | 20 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/sources/Gameplay/BaseClasses/KillingFloor/Frontend/Trading/ATradingComponent.uc b/sources/Gameplay/BaseClasses/KillingFloor/Frontend/Trading/ATradingComponent.uc index 2fe9a2a..9622bac 100644 --- a/sources/Gameplay/BaseClasses/KillingFloor/Frontend/Trading/ATradingComponent.uc +++ b/sources/Gameplay/BaseClasses/KillingFloor/Frontend/Trading/ATradingComponent.uc @@ -92,6 +92,16 @@ public final function Trading_OnSelect_Slot OnTraderSelected( */ public function array GetTraders(); +/** + * Returns a trader with a given name `traderName`. + * If several traders are assigned the same name - returns any arbitrary one. + * + * @param traderName Name of the trader to return. Case-sensitive. + * @return `ETrader` with a given `traderName`. `none` if either `traderName` + * is `none` or there is no trader with such a name. + */ +public function ETrader GetTrader(Text traderName); + /** * Checks whether trading is currently active. * diff --git a/sources/Gameplay/KF1Frontend/Trading/KF1_TradingComponent.uc b/sources/Gameplay/KF1Frontend/Trading/KF1_TradingComponent.uc index a3ec4d0..d636f10 100644 --- a/sources/Gameplay/KF1Frontend/Trading/KF1_TradingComponent.uc +++ b/sources/Gameplay/KF1Frontend/Trading/KF1_TradingComponent.uc @@ -84,6 +84,26 @@ public function array GetTraders() return result; } +public function ETrader GetTrader(Text traderName) +{ + local int i; + local Text nextTraderName; + if (traderName == none) { + return none; + } + for (i = 0; i < registeredTraders.length; i += 1) + { + nextTraderName = registeredTraders[i].GetName(); + if (traderName.Compare(nextTraderName)) + { + _.memory.Free(nextTraderName); + return ETrader(registeredTraders[i].Copy()); + } + _.memory.Free(nextTraderName); + } + return none; +} + public function bool IsTradingActive() { local KFGameType kfGame;