using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using UnityEngine; using DG.Tweening; using TMPro; using UnityEngine.UI; public enum OpenWeaponStatType { Base, Forge, Inventory, Exchange } public class WeaponStatsManager : MonoBehaviour { public void HideCall() { GetCanvasGroup().DOFade(0, 0.15f); } [SerializeField] private CanvasGroup weaponStatsCanvasGroup; [SerializeField] private TMP_Text forgeWeaponName; [SerializeField] private WeaponStats[] allWeaponStats; [SerializeField] private Image itemSprite; private RectTransform rect => transform as RectTransform; [SerializeField] private Vector2 forgePosition; [SerializeField] private Vector2 storePosition; [SerializeField] private Vector2 inventoryPosition; private readonly Vector2 storePivotPoint = new Vector2(0.5f, 0.5f); private readonly Vector2 inventoryPivotPoint = new Vector2(-0.600000024f,-0.930000007f); private readonly Vector2 forgePivotPoint = new Vector2(0f, 0f); public CanvasGroup GetCanvasGroup() => weaponStatsCanvasGroup; public void SetWeaponStatData(OpenWeaponStatType weaponStatType, int currentWeaponID) { var dataPivot = storePivotPoint; var dataAnchoredPosition = storePivotPoint; Weapon currentWeaponData = OnDemandLoader.Load("config/" + currentWeaponID); switch (weaponStatType) { case OpenWeaponStatType.Base: dataPivot = storePivotPoint; dataAnchoredPosition = storePosition; itemSprite.gameObject.SetActive(false); break; case OpenWeaponStatType.Forge: dataPivot = forgePivotPoint; dataAnchoredPosition = forgePosition; itemSprite.gameObject.SetActive(false); break; case OpenWeaponStatType.Inventory: dataPivot = inventoryPivotPoint; dataAnchoredPosition = inventoryPosition; Rect rec = new Rect(0, 0, currentWeaponData.assetIcon.width, currentWeaponData.assetIcon.height); itemSprite.sprite = Sprite.Create( currentWeaponData.assetIcon, rec, new Vector2(0,0), 1); itemSprite.gameObject.SetActive(true); break; case OpenWeaponStatType.Exchange: dataPivot = inventoryPivotPoint; dataAnchoredPosition = inventoryPosition; itemSprite.gameObject.SetActive(false); break; } rect.pivot = dataPivot; rect.anchoredPosition = dataAnchoredPosition; int currentLevel = (int)currentWeaponData.WeaponLevel; bool isMaxLevel = currentLevel == currentWeaponData.WeaponLevels.Length - 1; int nextLevel = Mathf.Clamp(currentLevel + 1, 0, currentWeaponData.WeaponLevels.Length - 1); Weapon nextWeaponData = currentWeaponData.WeaponLevels[nextLevel]; if (!currentWeaponData.Forgeable) { weaponStatsCanvasGroup.DOFade(0, 0.15f); return; } weaponStatsCanvasGroup.DOFade(1, 0.25f); PacketManager.sendForgeWeaponTrackers(currentWeaponID); foreach (WeaponStats weaponStat in allWeaponStats) { weaponStat.GetUpgradedValue().fillAmount = 0; weaponStat.SetMaxLevelLineColour(isMaxLevel); float maxValue = 0; float visualActualValue = 0; float baseValue = 0; float upgradedValue = 0; foreach (WeaponStats stat in allWeaponStats) { stat.gameObject.SetActive(true); if (!currentWeaponData.isShotgun) { if (stat.StatDataType == WeaponStats.DataType.BULLET_COUNT) { stat.gameObject.SetActive(false); } } if (!currentWeaponData.isRocketLauncher) { if (stat.StatDataType == WeaponStats.DataType.EXPLOSION_RADIUS) { stat.gameObject.SetActive(false); } } } switch (weaponStat.StatDataType) { case WeaponStats.DataType.DAMAGE: maxValue = currentWeaponData.isRocketLauncher ? 2000 : 500; bool isShotgun = currentWeaponData.isShotgun; int damage = isShotgun ? currentWeaponData.maxDamage * currentWeaponData.bulletsPerTap : currentWeaponData.maxDamage; visualActualValue = damage; baseValue = damage / maxValue; upgradedValue = damage / maxValue; break; case WeaponStats.DataType.FIRE_RATE: float bulletsPerSecond = 1f / currentWeaponData.shootCooldown; visualActualValue = bulletsPerSecond; baseValue = 1 - currentWeaponData.shootCooldown; upgradedValue = 1 - nextWeaponData.shootCooldown; break; case WeaponStats.DataType.MAG_SIZE: maxValue = 100; visualActualValue = currentWeaponData.ammoClipAmount; baseValue = 1 - currentWeaponData.ammoClipAmount / maxValue; upgradedValue = 1 - nextWeaponData.ammoClipAmount / maxValue; break; case WeaponStats.DataType.CRIT_DAMAGE: maxValue = 500; visualActualValue = currentWeaponData.maxDamage * 1.1f; baseValue = (currentWeaponData.maxDamage * 1.1f) / maxValue; upgradedValue = (nextWeaponData.maxDamage * 1.1f) / maxValue; break; case WeaponStats.DataType.RANGE: maxValue = (currentWeaponData.isRocketLauncher || currentWeaponData.isSniper) ? 2000 : 250; visualActualValue = currentWeaponData.effectiveRange; baseValue = currentWeaponData.effectiveRange / maxValue; upgradedValue = nextWeaponData.effectiveRange / maxValue; break; case WeaponStats.DataType.EXPLOSION_RADIUS: maxValue = 15; visualActualValue = currentWeaponData.explosionRadius; baseValue = currentWeaponData.explosionRadius / maxValue; upgradedValue = nextWeaponData.explosionRadius / maxValue; break; case WeaponStats.DataType.ADS_SPEED: maxValue = 15; visualActualValue = currentWeaponData.effectiveRange; baseValue = 1f - currentWeaponData.zoomSpeed / maxValue; upgradedValue = 1f - nextWeaponData.zoomSpeed / maxValue; break; case WeaponStats.DataType.BULLET_COUNT: maxValue = 10; visualActualValue = currentWeaponData.bulletsPerTap; baseValue = currentWeaponData.bulletsPerTap / maxValue; upgradedValue = nextWeaponData.bulletsPerTap / maxValue; break; } forgeWeaponName.text = $"[Level {(isMaxLevel ? "Max" : (currentLevel + 1).ToString())}] {currentWeaponData.name} Stats"; weaponStat.GetMaxValue().text = visualActualValue.ToString("F1"); if (isMaxLevel) upgradedValue = 0; DOTween.To(() => weaponStat.GetBaseValue().fillAmount, x => weaponStat.GetBaseValue().fillAmount = x, baseValue, 0.2f ).SetEase(Ease.InSine); DOTween.To(() => weaponStat.GetUpgradedValue().fillAmount, x => weaponStat.GetUpgradedValue().fillAmount = x, upgradedValue, 0.2f ).SetEase(Ease.InSine); } } }