KF2-Server-Extension/ServerExt/Classes/ExtAutoPurchaseHelper.uc

245 lines
6.4 KiB
Ucode
Raw Normal View History

2017-10-20 02:00:49 +00:00
class ExtAutoPurchaseHelper extends KFAutoPurchaseHelper within ExtPlayerController;
final function class<KFPerk> GetBasePerk()
{
return (ActivePerkManager!=None && ActivePerkManager.CurrentPerk!=None) ? ActivePerkManager.CurrentPerk.BasePerk : None;
}
2020-11-28 21:54:57 +00:00
2017-10-20 02:00:49 +00:00
final function Ext_PerkBase GetExtPerk()
{
return ActivePerkManager!=None ? ActivePerkManager.CurrentPerk : None;
}
function DoAutoPurchase()
{
local int PotentialDosh, i;
local Array <STraderItem> OnPerkWeapons;
local STraderItem TopTierWeapon;
local int ItemIndex;
local bool bSecondaryWeaponPurchased;
local bool bUpgradeSuccess;
local bool bAutoFillPurchasedItem;
local string AutoFillMessageString;
local Ext_PerkBase EP;
GetTraderItems();
EP = GetExtPerk();
2020-11-28 20:12:58 +00:00
if (EP==None || EP.AutoBuyLoadOutPath.length == 0)
2017-10-20 02:00:49 +00:00
return;
2020-11-28 20:12:58 +00:00
for (i = 0; i<EP.AutoBuyLoadOutPath.length; i++)
2017-10-20 02:00:49 +00:00
{
ItemIndex = TraderItems.SaleItems.Find('WeaponDef', EP.AutoBuyLoadOutPath[i]);
2020-11-28 20:12:58 +00:00
if (ItemIndex != INDEX_NONE)
2017-10-20 02:00:49 +00:00
OnPerkWeapons.AddItem(TraderItems.SaleItems[ItemIndex]);
}
SellOffPerkWeapons();
TopTierWeapon = GetTopTierWeapon(OnPerkWeapons);
//can I afford my top teir without selling my current weapon?
2020-11-28 20:12:58 +00:00
if (!DoIOwnThisWeapon(TopTierWeapon) && GetCanAfford(GetAdjustedBuyPricefor (TopTierWeapon) + DoshBuffer) && CanCarry(TopTierWeapon))
2017-10-20 02:00:49 +00:00
{
bUpgradeSuccess = AttemptUpgrade(TotalDosh, OnPerkWeapons, true);
}
else
{
PotentialDosh = GetPotentialDosh();
bUpgradeSuccess = AttemptUpgrade(PotentialDosh+TotalDosh, OnPerkWeapons);
}
bAutoFillPurchasedItem = StartAutoFill();
2020-11-28 20:12:58 +00:00
if (DoIOwnThisWeapon(TopTierWeapon))
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
while (AttemptToPurchaseNextLowerTier(TotalDosh, OnPerkWeapons))
2017-10-20 02:00:49 +00:00
{
bSecondaryWeaponPurchased = true;
AttemptToPurchaseNextLowerTier(TotalDosh, OnPerkWeapons);
}
}
MyKFIM.ServerCloseTraderMenu();
2020-11-28 20:12:58 +00:00
if (bUpgradeSuccess)
2017-10-20 02:00:49 +00:00
{
AutoFillMessageString = class'KFCommon_LocalizedStrings'.default.WeaponUpgradeComepleteString;
}
2020-11-28 20:12:58 +00:00
else if (bSecondaryWeaponPurchased)
2017-10-20 02:00:49 +00:00
{
AutoFillMessageString = class'KFCommon_LocalizedStrings'.default.SecondaryWeaponPurchasedString;
}
2020-11-28 20:12:58 +00:00
else if (bAutoFillPurchasedItem)
2017-10-20 02:00:49 +00:00
{
AutoFillMessageString = class'KFCommon_LocalizedStrings'.default.AutoFillCompleteString;
}
else
{
AutoFillMessageString = class'KFCommon_LocalizedStrings'.default.NoItemsPurchasedString;
}
2020-11-28 20:12:58 +00:00
if (MyGFxHUD != none)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:04:55 +00:00
MyGFxHUD.ShowNonCriticalMessage(class'KFCommon_LocalizedStrings'.default.AutoTradeCompleteString$AutoFillMessageString);
2017-10-20 02:00:49 +00:00
}
}
function SellOnPerkWeapons()
{
local int i;
local class<KFPerk> Perk;
Perk = GetBasePerk();
2020-11-28 20:12:58 +00:00
if (Perk!=None)
2017-10-20 02:00:49 +00:00
{
for (i = 0; i < OwnedItemList.length; i++)
{
2020-11-28 20:12:58 +00:00
if (OwnedItemList[i].DefaultItem.AssociatedPerkClasses.Find(Perk)!=INDEX_NONE && OwnedItemList[i].DefaultItem.BlocksRequired != -1)
2017-10-20 02:00:49 +00:00
{
SellWeapon(OwnedItemList[i], i);
i=-1;
}
}
}
}
function SellOffPerkWeapons()
{
local int i;
local Ext_PerkBase EP;
EP = GetExtPerk();
for (i = 0; i < OwnedItemList.length; i++)
{
2020-11-28 20:12:58 +00:00
if (OwnedItemList[i].DefaultItem.AssociatedPerkClasses.Find(EP.BasePerk)==INDEX_NONE && OwnedItemList[i].DefaultItem.BlocksRequired != -1 && OwnedItemList[i].SellPrice != 0)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (EP.AutoBuyLoadOutPath.Find(OwnedItemList[i].DefaultItem.WeaponDef) == INDEX_NONE)
2017-10-20 02:00:49 +00:00
{
SellWeapon(OwnedItemList[i], i);
i=-1;
}
}
}
}
function InitializeOwnedItemList()
{
local Inventory Inv;
local KFWeapon KFW;
local KFPawn_Human KFP;
local Ext_PerkBase EP;
EP = GetExtPerk();
2020-11-28 19:53:57 +00:00
OwnedItemList.length = 0;
2017-10-20 02:00:49 +00:00
2020-11-28 20:04:55 +00:00
TraderItems = KFGameReplicationInfo(WorldInfo.GRI).TraderItems;
2017-10-20 02:00:49 +00:00
2020-11-28 20:04:55 +00:00
KFP = KFPawn_Human(Pawn);
2020-11-28 20:12:58 +00:00
if (KFP != none)
2020-11-28 19:53:57 +00:00
{
2017-10-20 02:00:49 +00:00
// init armor purchase values
ArmorItem.SpareAmmoCount = KFP.Armor;
ArmorItem.MaxSpareAmmo = KFP.GetMaxArmor();
ArmorItem.AmmoPricePerMagazine = TraderItems.ArmorPrice * ActivePerkManager.GetArmorDiscountMod();
ArmorItem.DefaultItem.WeaponDef = TraderItems.ArmorDef;
// init grenade purchase values
GrenadeItem.SpareAmmoCount = MyKFIM.GrenadeCount;
GrenadeItem.MaxSpareAmmo = ActivePerkManager.MaxGrenadeCount;
GrenadeItem.AmmoPricePerMagazine = TraderItems.GrenadePrice;
GrenadeItem.DefaultItem.WeaponDef = EP.GrenadeWeaponDef;
// @temp: fill in stuff that is normally serialized in the archetype
GrenadeItem.DefaultItem.AssociatedPerkClasses[0] = CurrentPerk.Class;
2020-11-28 20:04:55 +00:00
for (Inv = MyKFIM.InventoryChain; Inv != none; Inv = Inv.Inventory)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:04:55 +00:00
KFW = KFWeapon(Inv);
2020-11-28 20:12:58 +00:00
if (KFW != none)
2017-10-20 02:00:49 +00:00
{
// Set the weapon information and add it to the OwnedItemList
2020-11-28 20:04:55 +00:00
SetWeaponInformation(KFW);
2020-11-28 19:53:57 +00:00
}
2017-10-20 02:00:49 +00:00
}
2020-11-28 20:12:58 +00:00
if (MyGfxManager != none && MyGfxManager.TraderMenu != none)
2017-10-20 02:00:49 +00:00
{
MyGfxManager.TraderMenu.OwnedItemList = OwnedItemList;
}
}
}
2020-11-28 20:04:55 +00:00
function int AddItemByPriority(out SItemInformation WeaponInfo)
2017-10-20 02:00:49 +00:00
{
local byte i;
local byte WeaponGroup, WeaponPriority;
local byte BestIndex;
local class<KFPerk> Perk;
Perk = GetBasePerk();
BestIndex = 0;
WeaponGroup = WeaponInfo.DefaultItem.InventoryGroup;
WeaponPriority = WeaponInfo.DefaultItem.GroupPriority;
2020-11-28 20:12:58 +00:00
for (i = 0; i < OwnedItemList.length; i++)
2017-10-20 02:00:49 +00:00
{
// If the weapon belongs in the group prior to the current weapon, we've found the spot
2020-11-28 20:12:58 +00:00
if (WeaponGroup < OwnedItemList[i].DefaultItem.InventoryGroup)
2017-10-20 02:00:49 +00:00
{
BestIndex = i;
break;
}
2020-11-28 20:12:58 +00:00
else if (WeaponGroup == OwnedItemList[i].DefaultItem.InventoryGroup)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (WeaponPriority > OwnedItemList[i].DefaultItem.GroupPriority)
2017-10-20 02:00:49 +00:00
{
// if the weapon is in the same group but has a higher priority, we've found the spot
BestIndex = i;
break;
}
2020-11-28 20:12:58 +00:00
else if (WeaponPriority == OwnedItemList[i].DefaultItem.GroupPriority && WeaponInfo.DefaultItem.AssociatedPerkClasses.Find(Perk)>=0)
2017-10-20 02:00:49 +00:00
{
// if the weapons have the same priority give the slot to the on perk weapon
BestIndex = i;
break;
}
}
else
{
// Covers the case if this weapon is the only item in the last group
BestIndex = i + 1;
}
}
2020-11-28 20:04:55 +00:00
OwnedItemList.InsertItem(BestIndex, WeaponInfo);
2017-10-20 02:00:49 +00:00
// Add secondary ammo immediately after the main weapon
2020-11-28 20:12:58 +00:00
if (WeaponInfo.DefaultItem.WeaponDef.static.UsesSecondaryAmmo())
2017-10-20 02:00:49 +00:00
{
WeaponInfo.bIsSecondaryAmmo = true;
WeaponInfo.SellPrice = 0;
2020-11-28 20:04:55 +00:00
OwnedItemList.InsertItem(BestIndex + 1, WeaponInfo);
2017-10-20 02:00:49 +00:00
}
2020-11-28 20:12:58 +00:00
if (MyGfxManager != none && MyGfxManager.TraderMenu != none)
2017-10-20 02:00:49 +00:00
{
MyGfxManager.TraderMenu.OwnedItemList = OwnedItemList;
}
return BestIndex;
}
2020-01-09 11:05:13 +00:00
function bool CanCarry(const out STraderItem Item, optional int OverrideLevelValue = INDEX_NONE)
{
local int Result;
2020-11-28 20:12:58 +00:00
Result = TotalBlocks + MyKFIM.GetDisplayedBlocksRequiredfor (Item);
if (Result > MaxBlocks)
{
2020-11-28 19:53:57 +00:00
return false;
}
return true;
}