A perk class for the game that hands out starter items to the player. When leveled up it seeds a shuffled list of handout items and, during Update, spawns those items near the player over time while playing sound and a dodge animation.
[Perk( Rarity.Uncommon, alwaysOfferDebug: false )]
public class PerkHandoutsCommon : Perk
{
private TimeSince _timeSinceItem;
public enum HandoutType { Reroll, Banish, HealthPack, Armor } // Lock
public List<HandoutType> _items;
public override float ImportanceMultiplier => 0.25f;
static PerkHandoutsCommon()
{
Register<PerkHandoutsCommon>(
name: "Starter Pack",
imagePath: "textures/icons/vector/starter_pack.png",
description: level => $"+2 reroll-item ___ +1 banish-item\n+1 healthpack ___ +30 armor-item",
upgradeDescription: level => $"+2 reroll-item ___ +1 banish-item\n+1 healthpack ___ +30 armor-item"
);
}
public override void Start()
{
base.Start();
}
public override void IncreaseLevel()
{
base.IncreaseLevel();
ShouldUpdate = true;
_timeSinceItem = 0f;
//var type = Player.GetRandomPerkType( Rarity.Common );
//Manager.Instance.Chat.AddLocalChatMessage( "Got a random perk:", from: "", startPerk: TypeLibrary.GetType( this.GetType() ), endPerks: new List<TypeDescription>() { type } );
//_perkTypes.Add( type );
var newItems = new List<HandoutType>() { HandoutType.Reroll, HandoutType.Reroll, HandoutType.Banish, HandoutType.HealthPack, HandoutType.Armor, HandoutType.Armor, HandoutType.Armor }; // HandoutType.Lock, HandoutType.Lock
newItems.Shuffle();
_items ??= new List<HandoutType>();
_items.AddRange( newItems );
}
public override void Refresh()
{
base.Refresh();
}
public override void Update( float dt )
{
base.Update( dt );
if ( _items.Count > 0 && _timeSinceItem > 0.2f )
{
var dir = Utils.GetRandomVectorInCone( -Player.FacingDir );
Manager.Instance.SpawnItemRpc( GetItemName( _items[0] ), Player.Position2D, dir );
Player.DodgeDuckRpc( dir, time: Game.Random.Float( 0.04f, 0.06f ) );
_items.RemoveAt( 0 );
if ( _items.Count <= 0 )
ShouldUpdate = false;
_timeSinceItem = 0f;
Manager.Instance.PlaySfxNearbyRpc( "scuffle", Player.Position2D, pitch: Utils.Map( _items.Count, 9, 0, 0.8f, 0.95f ), volume: 0.85f, maxDist: 300f );
}
}
string GetItemName( HandoutType itemType )
{
switch ( itemType )
{
case HandoutType.Reroll:
default:
return "reroll_item";
case HandoutType.Banish:
return "banish_item";
case HandoutType.HealthPack:
return "health_pack";
case HandoutType.Armor:
return "armor_item";
}
}
}