Browse Source

Add `GetTrader()` command to trading component

pull/8/head
Anton Tarasenko 2 years ago
parent
commit
b74f927f1b
  1. 10
      sources/Gameplay/BaseClasses/KillingFloor/Frontend/Trading/ATradingComponent.uc
  2. 20
      sources/Gameplay/KF1Frontend/Trading/KF1_TradingComponent.uc

10
sources/Gameplay/BaseClasses/KillingFloor/Frontend/Trading/ATradingComponent.uc

@ -92,6 +92,16 @@ public final function Trading_OnSelect_Slot OnTraderSelected(
*/
public function array<ETrader> 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.
*

20
sources/Gameplay/KF1Frontend/Trading/KF1_TradingComponent.uc

@ -84,6 +84,26 @@ public function array<ETrader> 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;

Loading…
Cancel
Save