Object/Upgrade.cs

Defines an Upgrade game object type and a serializable FUpgrade record. FUpgrade holds upgrade metadata like object id, name, list of affected buildings and stat modifiers. Upgrade is an Obj-derived component that exposes Properties for Buildings, AttackModifyer and HealthModifyer, updates a world tooltip when local player is dragging it, builds a small description string, returns building ids and produces an FUpgrade instance.

File Access
using Forp.Game;
using Forp.Object;
using Sandbox.UI;
using System;
using System.Collections.Generic;
using System.Text;

namespace Forp.Object.Unit;

public record FUpgrade
{
	public string ObjectId { get; set; }
	public string Name { get; set; }

	public List<GameObject> BuildingIds { get; set; }
	public int AttackModifyer { get; set; }
	public int HealthModifyer { get; set; }
}

public class Upgrade : Obj
{
	[Property] public List<GameObject> Buildings { get; set; }
	[Property] public int AttackModifyer { get; set; }
	[Property] public int HealthModifyer { get; set; }

	protected override void OnUpdate()
	{
		ShowTooltip = GamePlayer.Local != null && GamePlayer.Local.DraggedObject == GameObject;
		base.OnUpdate();

		if (ShowTooltip)
		{
			WorldTooltip.SetScale(0.05f);
		}
	}

	public string GetDesciption()
	{
		return $"{Buildings.Count}b\n{AttackModifyer}a\n{HealthModifyer}hp";
	}

	public List<string> GetBuildingIds()
	{
		return Buildings.Select(Building => Building.GetComponent<TextBuilding>().ObjectId).ToList();
	}

	public FUpgrade GetUpgradeData()
	{
		FUpgrade UpgradeData = new()
		{
			ObjectId = ObjectId,
			Name = DisplayName,
			BuildingIds = Buildings,
			AttackModifyer = AttackModifyer,
			HealthModifyer = HealthModifyer,
		};

		return UpgradeData;
	}
}