Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- public class TankUpgrades
- {
- public const int MaxLevel = 40;
- public const int MaxPurchasableTier = 7;
- private const int DefaultLevelValue = 1;
- private const int DefaultShopValue = 0;
- private const float NextUpgradePricePercent = 0.01f;
- private int firePowerLevel;
- private int protectionLevel;
- private int mobilityLevel;
- private int viewRangeLevel;
- private int crewLevel;
- private int shopBullet;
- private DaoManagerEncrypted daoManager;
- private string daoKeyPrefix;
- private int tier;
- public int TankPriceCoins
- {
- get
- {
- int num = 1000;
- switch (this.tier)
- {
- case 1:
- return 30 * num;
- case 2:
- return 80 * num;
- case 3:
- return 120 * num;
- case 4:
- return 180 * num;
- case 5:
- return 330 * num;
- case 6:
- return 390 * num;
- default:
- return 700 * num;
- }
- }
- }
- public int BaseUpgradePrice
- {
- get
- {
- int num = 100;
- switch (this.tier)
- {
- case 1:
- return 10 * num;
- case 2:
- return 20 * num;
- case 3:
- return 30 * num;
- case 4:
- return 40 * num;
- case 5:
- return 50 * num;
- case 6:
- return 45 * num;
- default:
- return 60 * num;
- }
- }
- }
- public int TankPriceXp
- {
- get
- {
- int num = 100;
- switch (this.tier)
- {
- case 1:
- return 5 * num;
- case 2:
- return 14 * num;
- case 3:
- return 21 * num;
- case 4:
- return 32 * num;
- case 5:
- return 48 * num;
- case 6:
- return 62 * num;
- default:
- return 100 * num;
- }
- }
- }
- public int FirePowerLevel
- {
- get
- {
- return this.ValidateLevel(this.firePowerLevel);
- }
- set
- {
- this.firePowerLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.FirePower, value);
- }
- }
- public int ProtectionLevel
- {
- get
- {
- return this.ValidateLevel(this.protectionLevel);
- }
- set
- {
- this.protectionLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.Protection, value);
- }
- }
- public int MobilityLevel
- {
- get
- {
- return this.ValidateLevel(this.mobilityLevel);
- }
- set
- {
- this.mobilityLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.Mobility, value);
- }
- }
- public int ViewRangeLevel
- {
- get
- {
- return this.ValidateLevel(this.viewRangeLevel);
- }
- set
- {
- this.viewRangeLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.ViewRange, value);
- }
- }
- public int CrewLevel
- {
- get
- {
- return this.ValidateLevel(this.crewLevel);
- }
- set
- {
- this.crewLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.Crew, value);
- }
- }
- public int ShopBullet
- {
- get
- {
- return this.shopBullet;
- }
- set
- {
- this.shopBullet = this.daoWriteShop(TankUpgrades.DaoKeyEnum.ShopBullet, value);
- }
- }
- public bool IsMaxFirePowerLevel
- {
- get
- {
- return this.FirePowerLevel >= 40;
- }
- }
- public bool IsMaxProtectionLevel
- {
- get
- {
- return this.ProtectionLevel >= 40;
- }
- }
- public bool IsMaxMobilityLevel
- {
- get
- {
- return this.MobilityLevel >= 40;
- }
- }
- public bool IsMaxViewRangeLevel
- {
- get
- {
- return this.ViewRangeLevel >= 40;
- }
- }
- public bool IsMaxCrewLevel
- {
- get
- {
- return this.CrewLevel >= 40;
- }
- }
- public float NormalizedFirePowerLevel
- {
- get
- {
- return this.GetNormalizedLevel(this.FirePowerLevel);
- }
- }
- public float NormalizedProtectionLevel
- {
- get
- {
- return this.GetNormalizedLevel(this.ProtectionLevel);
- }
- }
- public float NormalizedMobilityLevel
- {
- get
- {
- return this.GetNormalizedLevel(this.MobilityLevel);
- }
- }
- public float NormalizedViewRangeLevel
- {
- get
- {
- return this.GetNormalizedLevel(this.ViewRangeLevel);
- }
- }
- public float NormalizedCrewLevel
- {
- get
- {
- return this.GetNormalizedLevel(this.CrewLevel);
- }
- }
- public int FirePowerCost
- {
- get
- {
- return this.GetUpgradePrice(this.FirePowerLevel);
- }
- }
- public int ProtectionCost
- {
- get
- {
- return this.GetUpgradePrice(this.ProtectionLevel);
- }
- }
- public int MobilityCost
- {
- get
- {
- return this.GetUpgradePrice(this.MobilityLevel);
- }
- }
- public int ViewRangeCost
- {
- get
- {
- return this.GetUpgradePrice(this.ViewRangeLevel);
- }
- }
- public int CrewCost
- {
- get
- {
- return this.GetUpgradePrice(this.CrewLevel);
- }
- }
- public string DaoPurchasedKey { get; private set; }
- public List<string> DaoUpgradesKeyList
- {
- get
- {
- return new List<string>()
- {
- this.daoLevelKey(TankUpgrades.DaoKeyEnum.FirePower),
- this.daoLevelKey(TankUpgrades.DaoKeyEnum.Protection),
- this.daoLevelKey(TankUpgrades.DaoKeyEnum.Mobility),
- this.daoLevelKey(TankUpgrades.DaoKeyEnum.ViewRange),
- this.daoLevelKey(TankUpgrades.DaoKeyEnum.Crew),
- this.daoLevelKey(TankUpgrades.DaoKeyEnum.ShopBullet)
- };
- }
- }
- private int TankId { get; set; }
- public TankUpgrades(int tankId)
- {
- this.TankId = tankId;
- this.daoManager = new DaoManagerEncrypted();
- this.daoKeyPrefix = tankId.ToString() + "u";
- this.DaoPurchasedKey = this.daoKeyPrefix + "iP";
- this.tier = Tank.ResolveTier(tankId);
- this.daoReadLevels();
- }
- public float TotalUpgradesNormalized()
- {
- return (this.NormalizedFirePowerLevel + this.NormalizedCrewLevel + this.NormalizedMobilityLevel + this.NormalizedProtectionLevel + this.NormalizedViewRangeLevel) / 5f;
- }
- public bool IsAtLeastMidUpgraded()
- {
- return (double) this.TotalUpgradesNormalized() >= 0.5;
- }
- public bool IsTankPurchased()
- {
- if (!this.IsTankPurchasable())
- return false;
- else
- return this.daoManager.ReadBool(this.DaoPurchasedKey, false);
- }
- public bool IsTankPurchasable()
- {
- return this.tier <= 7;
- }
- public void PurchaseTank()
- {
- this.daoManager.WriteBool(this.DaoPurchasedKey, true);
- }
- public void SellTank()
- {
- this.daoManager.WriteBool(this.DaoPurchasedKey, false);
- }
- private int GetUpgradePrice(int level)
- {
- if (level >= 40)
- return 0;
- else
- return this.BaseUpgradePrice + (level - 1) * (int) Math.Round((double) this.BaseUpgradePrice * 0.00999999977648258, 0);
- }
- private void daoReadLevels()
- {
- this.FirePowerLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.FirePower), 1);
- this.ProtectionLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Protection), 1);
- this.MobilityLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Mobility), 1);
- this.ViewRangeLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.ViewRange), 1);
- this.CrewLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Crew), 1);
- this.ShopBullet = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.ShopBullet), 0);
- }
- public bool HasAnyDaoRecord()
- {
- return this.daoManager.IsSet(this.DaoPurchasedKey) || this.daoManager.IsSet(this.daoLevelKey(TankUpgrades.DaoKeyEnum.FirePower)) || (this.daoManager.IsSet(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Protection)) || this.daoManager.IsSet(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Mobility))) || (this.daoManager.IsSet(this.daoLevelKey(TankUpgrades.DaoKeyEnum.ViewRange)) || this.daoManager.IsSet(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Crew)));
- }
- private int daoWriteLevel(TankUpgrades.DaoKeyEnum daoKey, int level)
- {
- level = this.ValidateLevel(level);
- this.daoManager.WriteInt(this.daoLevelKey(daoKey), level);
- return level;
- }
- private int daoWriteShop(TankUpgrades.DaoKeyEnum daoKey, int item)
- {
- this.daoManager.WriteInt(this.daoLevelKey(daoKey), item);
- return item;
- }
- private string daoLevelKey(TankUpgrades.DaoKeyEnum daoKey)
- {
- return this.daoKeyPrefix + Convert.ToInt16((object) daoKey).ToString();
- }
- private int ValidateLevel(int level)
- {
- return Mathf.Clamp(level, 1, 40);
- }
- private float GetNormalizedLevel(int level)
- {
- if (level <= 1)
- return 0.0f;
- else
- return Mathf.Clamp01((float) level / 40f);
- }
- private enum DaoKeyEnum
- {
- FirePower,
- Protection,
- Mobility,
- ViewRange,
- Crew,
- ShopBullet,
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement