Advertisement
6jarjar6

TankUpgrades.cs Armored Aces

Jun 9th, 2014
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TankUpgrades
  6. {
  7.   public const int MaxLevel = 40;
  8.   public const int MaxPurchasableTier = 7;
  9.   private const int DefaultLevelValue = 1;
  10.   private const int DefaultShopValue = 0;
  11.   private const float NextUpgradePricePercent = 0.01f;
  12.   private int firePowerLevel;
  13.   private int protectionLevel;
  14.   private int mobilityLevel;
  15.   private int viewRangeLevel;
  16.   private int crewLevel;
  17.   private int shopBullet;
  18.   private DaoManagerEncrypted daoManager;
  19.   private string daoKeyPrefix;
  20.   private int tier;
  21.  
  22.   public int TankPriceCoins
  23.   {
  24.     get
  25.     {
  26.       int num = 1000;
  27.       switch (this.tier)
  28.       {
  29.         case 1:
  30.           return 30 * num;
  31.         case 2:
  32.           return 80 * num;
  33.         case 3:
  34.           return 120 * num;
  35.         case 4:
  36.           return 180 * num;
  37.         case 5:
  38.           return 330 * num;
  39.         case 6:
  40.           return 390 * num;
  41.         default:
  42.           return 700 * num;
  43.       }
  44.     }
  45.   }
  46.  
  47.   public int BaseUpgradePrice
  48.   {
  49.     get
  50.     {
  51.       int num = 100;
  52.       switch (this.tier)
  53.       {
  54.         case 1:
  55.           return 10 * num;
  56.         case 2:
  57.           return 20 * num;
  58.         case 3:
  59.           return 30 * num;
  60.         case 4:
  61.           return 40 * num;
  62.         case 5:
  63.           return 50 * num;
  64.         case 6:
  65.           return 45 * num;
  66.         default:
  67.           return 60 * num;
  68.       }
  69.     }
  70.   }
  71.  
  72.   public int TankPriceXp
  73.   {
  74.     get
  75.     {
  76.       int num = 100;
  77.       switch (this.tier)
  78.       {
  79.         case 1:
  80.           return 5 * num;
  81.         case 2:
  82.           return 14 * num;
  83.         case 3:
  84.           return 21 * num;
  85.         case 4:
  86.           return 32 * num;
  87.         case 5:
  88.           return 48 * num;
  89.         case 6:
  90.           return 62 * num;
  91.         default:
  92.           return 100 * num;
  93.       }
  94.     }
  95.   }
  96.  
  97.   public int FirePowerLevel
  98.   {
  99.     get
  100.     {
  101.       return this.ValidateLevel(this.firePowerLevel);
  102.     }
  103.     set
  104.     {
  105.       this.firePowerLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.FirePower, value);
  106.     }
  107.   }
  108.  
  109.   public int ProtectionLevel
  110.   {
  111.     get
  112.     {
  113.       return this.ValidateLevel(this.protectionLevel);
  114.     }
  115.     set
  116.     {
  117.       this.protectionLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.Protection, value);
  118.     }
  119.   }
  120.  
  121.   public int MobilityLevel
  122.   {
  123.     get
  124.     {
  125.       return this.ValidateLevel(this.mobilityLevel);
  126.     }
  127.     set
  128.     {
  129.       this.mobilityLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.Mobility, value);
  130.     }
  131.   }
  132.  
  133.   public int ViewRangeLevel
  134.   {
  135.     get
  136.     {
  137.       return this.ValidateLevel(this.viewRangeLevel);
  138.     }
  139.     set
  140.     {
  141.       this.viewRangeLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.ViewRange, value);
  142.     }
  143.   }
  144.  
  145.   public int CrewLevel
  146.   {
  147.     get
  148.     {
  149.       return this.ValidateLevel(this.crewLevel);
  150.     }
  151.     set
  152.     {
  153.       this.crewLevel = this.daoWriteLevel(TankUpgrades.DaoKeyEnum.Crew, value);
  154.     }
  155.   }
  156.  
  157.   public int ShopBullet
  158.   {
  159.     get
  160.     {
  161.       return this.shopBullet;
  162.     }
  163.     set
  164.     {
  165.       this.shopBullet = this.daoWriteShop(TankUpgrades.DaoKeyEnum.ShopBullet, value);
  166.     }
  167.   }
  168.  
  169.   public bool IsMaxFirePowerLevel
  170.   {
  171.     get
  172.     {
  173.       return this.FirePowerLevel >= 40;
  174.     }
  175.   }
  176.  
  177.   public bool IsMaxProtectionLevel
  178.   {
  179.     get
  180.     {
  181.       return this.ProtectionLevel >= 40;
  182.     }
  183.   }
  184.  
  185.   public bool IsMaxMobilityLevel
  186.   {
  187.     get
  188.     {
  189.       return this.MobilityLevel >= 40;
  190.     }
  191.   }
  192.  
  193.   public bool IsMaxViewRangeLevel
  194.   {
  195.     get
  196.     {
  197.       return this.ViewRangeLevel >= 40;
  198.     }
  199.   }
  200.  
  201.   public bool IsMaxCrewLevel
  202.   {
  203.     get
  204.     {
  205.       return this.CrewLevel >= 40;
  206.     }
  207.   }
  208.  
  209.   public float NormalizedFirePowerLevel
  210.   {
  211.     get
  212.     {
  213.       return this.GetNormalizedLevel(this.FirePowerLevel);
  214.     }
  215.   }
  216.  
  217.   public float NormalizedProtectionLevel
  218.   {
  219.     get
  220.     {
  221.       return this.GetNormalizedLevel(this.ProtectionLevel);
  222.     }
  223.   }
  224.  
  225.   public float NormalizedMobilityLevel
  226.   {
  227.     get
  228.     {
  229.       return this.GetNormalizedLevel(this.MobilityLevel);
  230.     }
  231.   }
  232.  
  233.   public float NormalizedViewRangeLevel
  234.   {
  235.     get
  236.     {
  237.       return this.GetNormalizedLevel(this.ViewRangeLevel);
  238.     }
  239.   }
  240.  
  241.   public float NormalizedCrewLevel
  242.   {
  243.     get
  244.     {
  245.       return this.GetNormalizedLevel(this.CrewLevel);
  246.     }
  247.   }
  248.  
  249.   public int FirePowerCost
  250.   {
  251.     get
  252.     {
  253.       return this.GetUpgradePrice(this.FirePowerLevel);
  254.     }
  255.   }
  256.  
  257.   public int ProtectionCost
  258.   {
  259.     get
  260.     {
  261.       return this.GetUpgradePrice(this.ProtectionLevel);
  262.     }
  263.   }
  264.  
  265.   public int MobilityCost
  266.   {
  267.     get
  268.     {
  269.       return this.GetUpgradePrice(this.MobilityLevel);
  270.     }
  271.   }
  272.  
  273.   public int ViewRangeCost
  274.   {
  275.     get
  276.     {
  277.       return this.GetUpgradePrice(this.ViewRangeLevel);
  278.     }
  279.   }
  280.  
  281.   public int CrewCost
  282.   {
  283.     get
  284.     {
  285.       return this.GetUpgradePrice(this.CrewLevel);
  286.     }
  287.   }
  288.  
  289.   public string DaoPurchasedKey { get; private set; }
  290.  
  291.   public List<string> DaoUpgradesKeyList
  292.   {
  293.     get
  294.     {
  295.       return new List<string>()
  296.       {
  297.         this.daoLevelKey(TankUpgrades.DaoKeyEnum.FirePower),
  298.         this.daoLevelKey(TankUpgrades.DaoKeyEnum.Protection),
  299.         this.daoLevelKey(TankUpgrades.DaoKeyEnum.Mobility),
  300.         this.daoLevelKey(TankUpgrades.DaoKeyEnum.ViewRange),
  301.         this.daoLevelKey(TankUpgrades.DaoKeyEnum.Crew),
  302.         this.daoLevelKey(TankUpgrades.DaoKeyEnum.ShopBullet)
  303.       };
  304.     }
  305.   }
  306.  
  307.   private int TankId { get; set; }
  308.  
  309.   public TankUpgrades(int tankId)
  310.   {
  311.     this.TankId = tankId;
  312.     this.daoManager = new DaoManagerEncrypted();
  313.     this.daoKeyPrefix = tankId.ToString() + "u";
  314.     this.DaoPurchasedKey = this.daoKeyPrefix + "iP";
  315.     this.tier = Tank.ResolveTier(tankId);
  316.     this.daoReadLevels();
  317.   }
  318.  
  319.   public float TotalUpgradesNormalized()
  320.   {
  321.     return (this.NormalizedFirePowerLevel + this.NormalizedCrewLevel + this.NormalizedMobilityLevel + this.NormalizedProtectionLevel + this.NormalizedViewRangeLevel) / 5f;
  322.   }
  323.  
  324.   public bool IsAtLeastMidUpgraded()
  325.   {
  326.     return (double) this.TotalUpgradesNormalized() >= 0.5;
  327.   }
  328.  
  329.   public bool IsTankPurchased()
  330.   {
  331.     if (!this.IsTankPurchasable())
  332.       return false;
  333.     else
  334.       return this.daoManager.ReadBool(this.DaoPurchasedKey, false);
  335.   }
  336.  
  337.   public bool IsTankPurchasable()
  338.   {
  339.     return this.tier <= 7;
  340.   }
  341.  
  342.   public void PurchaseTank()
  343.   {
  344.     this.daoManager.WriteBool(this.DaoPurchasedKey, true);
  345.   }
  346.  
  347.   public void SellTank()
  348.   {
  349.     this.daoManager.WriteBool(this.DaoPurchasedKey, false);
  350.   }
  351.  
  352.   private int GetUpgradePrice(int level)
  353.   {
  354.     if (level >= 40)
  355.       return 0;
  356.     else
  357.       return this.BaseUpgradePrice + (level - 1) * (int) Math.Round((double) this.BaseUpgradePrice * 0.00999999977648258, 0);
  358.   }
  359.  
  360.   private void daoReadLevels()
  361.   {
  362.     this.FirePowerLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.FirePower), 1);
  363.     this.ProtectionLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Protection), 1);
  364.     this.MobilityLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Mobility), 1);
  365.     this.ViewRangeLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.ViewRange), 1);
  366.     this.CrewLevel = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.Crew), 1);
  367.     this.ShopBullet = this.daoManager.ReadInt(this.daoLevelKey(TankUpgrades.DaoKeyEnum.ShopBullet), 0);
  368.   }
  369.  
  370.   public bool HasAnyDaoRecord()
  371.   {
  372.     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)));
  373.   }
  374.  
  375.   private int daoWriteLevel(TankUpgrades.DaoKeyEnum daoKey, int level)
  376.   {
  377.     level = this.ValidateLevel(level);
  378.     this.daoManager.WriteInt(this.daoLevelKey(daoKey), level);
  379.     return level;
  380.   }
  381.  
  382.   private int daoWriteShop(TankUpgrades.DaoKeyEnum daoKey, int item)
  383.   {
  384.     this.daoManager.WriteInt(this.daoLevelKey(daoKey), item);
  385.     return item;
  386.   }
  387.  
  388.   private string daoLevelKey(TankUpgrades.DaoKeyEnum daoKey)
  389.   {
  390.     return this.daoKeyPrefix + Convert.ToInt16((object) daoKey).ToString();
  391.   }
  392.  
  393.   private int ValidateLevel(int level)
  394.   {
  395.     return Mathf.Clamp(level, 1, 40);
  396.   }
  397.  
  398.   private float GetNormalizedLevel(int level)
  399.   {
  400.     if (level <= 1)
  401.       return 0.0f;
  402.     else
  403.       return Mathf.Clamp01((float) level / 40f);
  404.   }
  405.  
  406.   private enum DaoKeyEnum
  407.   {
  408.     FirePower,
  409.     Protection,
  410.     Mobility,
  411.     ViewRange,
  412.     Crew,
  413.     ShopBullet,
  414.   }
  415. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement