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

263 lines
7.8 KiB
Ucode
Raw Normal View History

2017-10-20 02:00:49 +00:00
Class Ext_TraitBase extends Object
abstract
config(ServerExt)
DependsOn(ExtWebAdmin_UI);
var localized string MaxLevelText;
var localized string LevelCostText;
var localized string MinPerkLevelText;
2017-10-20 02:00:49 +00:00
var array<FWebAdminConfigInfo> WebConfigs;
var() class<Ext_TGroupBase> TraitGroup; // With groups you can prevent player from buying multiple traits of same group.
var() localized string TraitName,Description; // UI name.
2017-10-20 02:00:49 +00:00
var() byte NumLevels; // Maximum number of levels.
var config array<int> LevelCosts;
var() array<int> DefLevelCosts; // Point price tag for each level.
var() class<Ext_TraitDataStore> TraitData; // Optional additional data that this trait requires for each player.
var config int MinLevel; // Minimum perk level player needs to be in order to be allowed to get this trait.
var() int DefMinLevel;
var() const byte LoadPriority; // Order of loading the trait class, if for example one trait depends on progress of another trait.
var() class<Ext_PerkBase> SupportedPerk; // Only functions on this perk.
// Config init stuff.
var config int ConfigVersion;
var const int CurrentConfigVer;
var config bool bDisabled; // This trait is currently disabled on server.
var() bool bGroupLimitToOne, // TraitGroup should limit so you can only buy one of them.
bHighPriorityDeath, // Should receive PreventDeath call before any other trait.
bPostApplyEffect; // Apply effects on second pass (relies on that another trait is activated first).
// Check if trait is enabled and usable on this perk.
2020-11-28 20:04:55 +00:00
static function bool IsEnabled(Ext_PerkBase Perk)
2017-10-20 02:00:49 +00:00
{
return !Default.bDisabled && (Default.SupportedPerk==None || ClassIsChildOf(Perk.Class,Default.SupportedPerk));
}
// Check if player meets the requirements to buy this trait.
2020-11-28 20:04:55 +00:00
static function bool MeetsRequirements(byte Lvl, Ext_PerkBase Perk)
2017-10-20 02:00:49 +00:00
{
// First check level.
2020-11-28 20:12:58 +00:00
if (Perk.CurrentLevel<Default.MinLevel)
2017-10-20 02:00:49 +00:00
return false;
// Then check grouping.
2020-11-28 20:12:58 +00:00
if (Lvl==0 && Default.TraitGroup!=None && Default.TraitGroup.Static.GroupLimited(Perk,Default.Class))
2017-10-20 02:00:49 +00:00
return false;
return true;
}
// Return UI description player will see before bying this trait.
function string GetPerkDescription()
2017-10-20 02:00:49 +00:00
{
local string S;
local byte i;
2020-11-28 20:12:58 +00:00
for (i=0; i<Default.NumLevels; ++i)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (i==0)
2017-10-20 02:00:49 +00:00
S = string(GetTraitCost(i));
else S $= ", "$GetTraitCost(i);
}
S = MaxLevelText@"#{9FF781}"$Default.NumLevels$"#{DEF}|"$LevelCostText@"#{F3F781}"$S$"#{DEF}";
2020-11-28 20:12:58 +00:00
if (Default.MinLevel>0)
S = MinPerkLevelText@"#{FF4000}"$Default.MinLevel$"#{DEF}|"$S;
2017-10-20 02:00:49 +00:00
return Default.Description$"||"$S;
}
// Return tooltip description of this trait
static function string GetTooltipInfo()
{
return Default.TraitName$"|"$Default.Description;
}
// Return level specific trait prices.
2020-11-28 20:04:55 +00:00
static function int GetTraitCost(byte LevelNum)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Default.LevelCosts.Length>0)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (LevelNum<Default.LevelCosts.Length)
2017-10-20 02:00:49 +00:00
return Default.LevelCosts[LevelNum];
return Default.LevelCosts[Default.LevelCosts.Length-1];
}
return 5;
}
// Trait initialization/cleanup.
2020-11-28 20:12:58 +00:00
static function Ext_TraitDataStore Initializefor (Ext_PerkBase Perk, ExtPlayerController Player)
2017-10-20 02:00:49 +00:00
{
local Ext_TraitDataStore T;
T = None;
2020-11-28 20:12:58 +00:00
if (Default.TraitData!=None)
2017-10-20 02:00:49 +00:00
{
T = Player.Spawn(Default.TraitData,Player);
T.Perk = Perk;
T.PlayerOwner = Player;
T.TraitClass = Default.Class;
}
return T;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static function CleanupTrait(ExtPlayerController Player, Ext_PerkBase Perk, optional Ext_TraitDataStore Data)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (Data!=None)
2017-10-20 02:00:49 +00:00
Data.Destroy();
}
// Called when trait is first activated/deactivated (might even have a dead pawn).
2020-11-28 20:04:55 +00:00
static function TraitActivate(Ext_PerkBase Perk, byte Level, optional Ext_TraitDataStore Data);
static function TraitDeActivate(Ext_PerkBase Perk, byte Level, optional Ext_TraitDataStore Data);
2017-10-20 02:00:49 +00:00
// Called everytime player spawns in on the game (cancel effect is called on level up/level reset/perk change).
2020-11-28 20:04:55 +00:00
static function ApplyEffectOn(KFPawn_Human Player, Ext_PerkBase Perk, byte Level, optional Ext_TraitDataStore Data);
static function CancelEffectOn(KFPawn_Human Player, Ext_PerkBase Perk, byte Level, optional Ext_TraitDataStore Data);
2017-10-20 02:00:49 +00:00
// Owner died with this trait active.
2020-11-28 20:04:55 +00:00
static function PlayerDied(Ext_PerkBase Perk, byte Level, optional Ext_TraitDataStore Data);
2017-10-20 02:00:49 +00:00
// Prevent death.
2020-11-28 20:04:55 +00:00
static function bool PreventDeath(KFPawn_Human Player, Controller Instigator, Class<DamageType> DamType, Ext_PerkBase Perk, byte Level, optional Ext_TraitDataStore Data);
2017-10-20 02:00:49 +00:00
// Give/modify default inventory.
2020-11-28 20:04:55 +00:00
static function AddDefaultInventory(KFPawn Player, Ext_PerkBase Perk, byte Level, optional Ext_TraitDataStore Data);
2017-10-20 02:00:49 +00:00
// Data that server should replicate to client.
2020-11-28 20:04:55 +00:00
static final function string IntToStr(int Value, optional byte MaxVal) // Helper function to put integer into one character of string.
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
switch (MaxVal)
2017-10-20 02:00:49 +00:00
{
case 0: // 0-65535
return Chr(Max(Value,0)+1);
case 1: // 0-1073741823
return Chr((Value & 32767)+1) $ Chr(((Value >> 15) & 32767)+1);
}
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static final function string InlineString(string Str) // Helper function to append a string line to a text using a length char in front.
2017-10-20 02:00:49 +00:00
{
return IntToStr(Len(Str))$Str;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static final function int StrToInt(out string Value, optional byte MaxVal) // Reverse.
2017-10-20 02:00:49 +00:00
{
local int Res;
2020-11-28 20:12:58 +00:00
switch (MaxVal)
2017-10-20 02:00:49 +00:00
{
case 0: // 0-65535
Res = Asc(Left(Value,1))-1;
Value = Mid(Value,1);
break;
case 1: // 0-1073741823
Res =(Asc(Mid(Value,0,1))-1) | ((Asc(Mid(Value,1,1)) << 15)-1);
Value = Mid(Value,2);
break;
}
return Res;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static final function string GetInlineStr(out string S) // Reverse.
2017-10-20 02:00:49 +00:00
{
local int l;
local string Res;
l = StrToInt(S);
Res = Left(S,l);
S = Mid(S,l);
return Res;
}
static function string GetRepData()
{
local string S;
local int i;
S = IntToStr(Default.MinLevel)$IntToStr(Default.LevelCosts.Length);
2020-11-28 20:12:58 +00:00
for (i=0; i<Default.LevelCosts.Length; ++i)
2017-10-20 02:00:49 +00:00
S $= IntToStr(Default.LevelCosts[i]);
return S;
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static function string ClientSetRepData(string S)
2017-10-20 02:00:49 +00:00
{
local int i;
Default.MinLevel = StrToInt(S);
Default.LevelCosts.Length = StrToInt(S);
2020-11-28 20:12:58 +00:00
for (i=0; i<Default.LevelCosts.Length; ++i)
2017-10-20 02:00:49 +00:00
Default.LevelCosts[i] = StrToInt(S);
return S;
}
// Configure initialization.
static function CheckConfig()
{
2020-11-28 20:12:58 +00:00
if (Default.ConfigVersion!=Default.CurrentConfigVer)
2017-10-20 02:00:49 +00:00
{
UpdateConfigs(Default.ConfigVersion);
Default.ConfigVersion = Default.CurrentConfigVer;
StaticSaveConfig();
}
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static function UpdateConfigs(int OldVer)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
if (OldVer==0)
2017-10-20 02:00:49 +00:00
{
Default.LevelCosts = Default.DefLevelCosts;
Default.MinLevel = Default.DefMinLevel;
}
}
// WebAdmin UI
2020-11-28 20:04:55 +00:00
static function InitWebAdmin(ExtWebAdmin_UI UI)
2017-10-20 02:00:49 +00:00
{
UI.AddSettingsPage("Trait "$Default.TraitName,Default.Class,Default.WebConfigs,GetValue,ApplyValue);
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static function string GetValue(name PropName, int ElementIndex)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
switch (PropName)
2017-10-20 02:00:49 +00:00
{
case 'MinLevel':
return string(Default.MinLevel);
case 'LevelCosts':
return (ElementIndex==-1 ? string(Default.LevelCosts.Length) : string(Default.LevelCosts[ElementIndex]));
case 'bDisabled':
return string(Default.bDisabled);
}
}
2020-11-28 21:54:57 +00:00
2020-11-28 20:04:55 +00:00
static function ApplyValue(name PropName, int ElementIndex, string Value)
2017-10-20 02:00:49 +00:00
{
2020-11-28 20:12:58 +00:00
switch (PropName)
2017-10-20 02:00:49 +00:00
{
case 'MinLevel':
Default.MinLevel = int(Value); break;
case 'LevelCosts':
Default.LevelCosts.Length = Default.DefLevelCosts.Length;
2020-11-28 20:12:58 +00:00
if (Value!="#DELETE" && ElementIndex<Default.LevelCosts.Length)
2017-10-20 02:00:49 +00:00
Default.LevelCosts[ElementIndex] = int(Value);
break;
case 'bDisabled':
Default.bDisabled = bool(Value); break;
default:
return;
}
StaticSaveConfig();
}
defaultproperties
{
CurrentConfigVer=1
DefLevelCosts.Add(5)
NumLevels=1
DefMinLevel=0
WebConfigs.Add((PropType=1,PropName="bDisabled",UIName="Disabled",UIDesc="Disable this trait (hides from UI and makes it unusable)!"))
WebConfigs.Add((PropType=0,PropName="MinLevel",UIName="Minimum Level",UIDesc="Minimum Level required for this trait"))
WebConfigs.Add((PropType=0,PropName="LevelCosts",UIName="Level Costs",UIDesc="EXP cost for each trait level (array length is a constant)!",NumElements=-1))
}