/// <summary> /// Calculates the value. /// </summary> /// <param name="context">The context.</param> public override void CalculateValue(IBehaviorContext context) { PlayerBehaviorContext playerContext = context as PlayerBehaviorContext; if (playerContext == null) { IsNodeValid = false; Debug.Assert(false, "Player Context null"); return; } BaseUnit unit = playerContext.Unit; if (unit == null) { IsNodeValid = false; Debug.Assert(false, "Unit null"); return; } if (!playerContext.Player.AvailUnitUpgrades.Contains(UpgradeId)) { IsNodeValid = false; return; } BaseUnitUpgrade upgrade = playerContext.Player.GameSession.EnvironmentConfig.UpgradesConfig.Upgrades.FirstOrDefault(u => u.Id == UpgradeId); if (upgrade == null) { IsNodeValid = false; return; } if (!upgrade.IsValidUpgrade(unit)) { IsNodeValid = false; return; } int usedCount = unit.Upgrades.Count(u => u == upgrade); IsNodeValid = true; Value = usedCount; }
/// <summary> /// Makes the decision. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override bool MakeDecision(IBehaviorContext context) { PlayerBehaviorContext playerContext = context as PlayerBehaviorContext; if (playerContext == null) { return(false); } BaseUnitUpgrade upgrade = playerContext.Player.GameSession.EnvironmentConfig.UpgradesConfig.Upgrades.FirstOrDefault(u => u.Id == UpgradeId); if (upgrade == null) { return(false); } playerContext.UnitUpgrade = upgrade; return(true); }