123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- using LitJson;
- using UnityEngine;
- using System;
- using System.Xml;
- using System.Collections;
- using System.Collections.Generic;
- public class ManaData : MonoBehaviour
- {
- #region 变量
- public static int Level
- {
- get { return _Level; }
- set
- {
- _Level = value;
- UpdateSkillStatus();
- ManaLog.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", _Level));
- }
- }
- public static float Person
- {
- get { return _Person; }
- set
- {
- _Person = value;
- ManaReso.SetText("F_PersonLab", _Person.ToString("0"));
- }
- }
- public static float CoinPerson
- {
- get { return _CoinPerson; }
- set
- {
- _CoinPerson = value;
- ManaReso.SetText("F_CoinPersonLab", _CoinPerson.ToString("0"));
- }
- }
- public static double Coin
- {
- get { return _Coin; }
- set
- {
- _Coin = value;
- ManaReso.SetText("F_CoinLab", _Coin.ToString("0"));
- ManaReso.SetText("C_CoinLab", _Coin.ToString("0"));
- }
- }
- public static double Diamond
- {
- get { return _Diamond; }
- set
- {
- _Diamond = value;
- ManaReso.SetText("F_DiamondLab", _Diamond.ToString("0"));
- }
- }
-
- private static int _Level;
- private static float _Person;
- private static float _CoinPerson;
- private static double _Coin;
- private static double _Diamond;
- public static bool SkillBar;
- public static bool Connect;
- public static float OpTimer;
- public static float NewPerson;
- public static float NewCoinPerson;
- public static double Circle;
- public static double OfflineCoin;
- public static double CircleTimer;
- public static List<Skill> CoolList;
- public static List<SkillRoot> SkillList;
- public static List<SkillRoot> UsingList;
- public static Dictionary<string, SkillRoot> SkillDic;
- public static float SkillPerson;
- public static float SkillPlusPerm;
- public static float SkillPlusTemp;
- public static float SkillPersonBuff;
- public static float SkillCoinPerson;
- #endregion
- private void Awake()
- {
- Initializer.RegistValue += RegistValue;
-
- #region 读取技能配置
- SkillDic = new Dictionary<string, SkillRoot>();
- SkillList = new List<SkillRoot>();
- List<XmlAttributeCollection> attributesList = Data.GetSkillConfig();
- for (int i = 0; i < attributesList.Count; i++)
- {
- SkillRoot skillRoot;
- #region MyRegion
- if (attributesList[i].Count == 17)
- {
- skillRoot = new Pack(attributesList[i]);
- }
- else if (attributesList[i].Count == 23)
- {
- skillRoot = new Ability(attributesList[i]);
- }
- else if (attributesList[i].Count == 33)
- {
- if (string.IsNullOrEmpty(attributesList[i][4].Value))
- {
- skillRoot = new Skill(attributesList[i]);
- }
- else
- {
- skillRoot = new BigSkill(attributesList[i]);
- }
- }
- else
- {
- throw new Exception(attributesList[i].Count.ToString());
- }
- #endregion
- SkillList.Add(skillRoot);
- SkillDic.Add(skillRoot.Name, skillRoot);
- }
- SkillList.Sort();
- #endregion
- #region 创建技能条
- for (int i = 0; i < SkillList.Count; i++)
- {
- if (SkillList[i].Class != SkillClass.Null)
- {
- ManaReso.GetSkillItem(SkillList[i]);
- }
- }
- #endregion
- }
- private void Update()
- {
- #region 计算参观收益
- CircleTimer -= Time.deltaTime;
- if (CircleTimer < 0)
- {
- CircleTimer = Circle;
- NewPerson = Person*(1 + SkillPersonBuff) + SkillPerson;
- NewCoinPerson = CoinPerson + SkillCoinPerson;
- Coin += (NewPerson*NewCoinPerson*Circle)*(1 + SkillPlusPerm);
- ManaLog.Log(string.Format("参观收益<color=red>{0:0}</color> = <color=red>{1}</color> * <color=red>{2}</color> * <color=red>{3}</color> * <color=red>{4}</color> (人次*金币*时间*加成)", (NewPerson * NewCoinPerson * Circle) * (1 + SkillPlusPerm), NewPerson, NewCoinPerson, Circle, 1 + SkillPlusPerm));
- }
- #endregion
- #region 使用中的技能
- for (int i = 0; i < UsingList.Count; i++)
- {
- if (UsingList[i].DoTiming())
- {
- i--;
- }
- }
- #endregion
- #region 冷却中的技能
- for (int i = 0; i < CoolList.Count; i++)
- {
- if (CoolList[i].DoCool())
- {
- i--;
- }
- }
- #endregion
- #region 检测是否有操作
- OpTimer += Time.deltaTime;
- if (OpTimer >= 60)
- {
- OpTimer = 0;
- }
- #endregion
- }
- private void RegistValue()
- {
- CoolList = new List<Skill>();
- UsingList = new List<SkillRoot>();
- #region 读取技能状态
- XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
- for (int i = 0; i < xmlNodeList.Count; i++)
- {
- if (xmlNodeList[i].Attributes[0].Value == SkillCato.Skill.ToString())
- {
- Skill skill = (Skill)SkillDic[xmlNodeList[i].Name];
- skill.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
- skill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[3].Value);
- skill.UsingTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
- skill.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
- }
- else if (xmlNodeList[i].Attributes[0].Value == SkillCato.BigSkill.ToString())
- {
- BigSkill bigSkill = (BigSkill)SkillDic[xmlNodeList[i].Name];
- bigSkill.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
- bigSkill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
- bigSkill.UsingTimer = float.Parse(xmlNodeList[i].Attributes[5].Value);
- bigSkill.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value); //Sa0
- bigSkill.BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value); //Sa1
- }
- else if (xmlNodeList[i].Attributes[0].Value == SkillCato.Pack.ToString())
- {
- Pack pack = (Pack)SkillDic[xmlNodeList[i].Attributes[1].Value];
- pack.Level = int.Parse(xmlNodeList[i].Attributes[3].Value);
- pack.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value);
- }
- else if (xmlNodeList[i].Attributes[0].Value == SkillCato.Ability.ToString())
- {
- Ability ability = (Ability)SkillDic[xmlNodeList[i].Name];
- ability.Level = int.Parse(xmlNodeList[i].Attributes[2].Value);
- ability.ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
- }
- else
- {
- throw new Exception();
- }
- }
- for (int i = 0; i < SkillList.Count; i++)
- {
- SkillList[i].Initialize();
- }
- #endregion
- #region 读取已解锁的花
- XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes;
- string[] strings = attributes[0].Value.Split(' ');
- for (int i = 0; i < strings.Length; i++)
- {
- int id = int.Parse(strings[i]);
- FlowerInfo flowerInfo = ManaGarden.FlowerDic[id];
- flowerInfo.Unlock = true;
- }
- #endregion
- #region 读取已种植的花
- attributes = Data.PlayerNode.SelectSingleNode("PlantList").Attributes;
- for (int i = 0; i < attributes.Count; i++)
- {
- int id = int.Parse(attributes[i].Value);
- ManaGarden.PlaceFlower(id, ManaReso.Get(attributes[i].Name));
- }
- #endregion
- Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value);
- Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value);
- Circle = 10;
- Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value);
- OfflineCoin = 0;
- #region 离线期间的收入
-
- double elapse = DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds; //离开时间
- if (elapse > CircleTimer)
- {
- elapse -= CircleTimer;
- int offlineCircle = 1 + Mathf.FloorToInt((float) (elapse/Circle)); //离线周期
-
- for (int i = 0; i < SkillList.Count; i++)
- {
- SkillList[i].CollectCoin(offlineCircle);
- }
- OfflineCoin += (Person * CoinPerson * Circle * offlineCircle) * (1 + SkillPlusPerm);
- }
- else
- {
- CircleTimer -= elapse;
- }
- Coin += OfflineCoin;
- ManaReso.SetText("A_IconLab", OfflineCoin.ToString("0"));
-
- #endregion
- }
- public static void UpdateSkillStatus()
- {
- for (int i = 0; i < SkillList.Count; i++)
- {
- SkillList[i].OnLevelChange();
- }
- }
- public static bool Pay(double amt, Current current)
- {
- amt = (int) amt;
- if (current == Current.Free)
- {
- return true;
- }
- else if (current == Current.AD)
- {
- return true;
- }
- else if (current == Current.Cash)
- {
- return true;
- }
- else if (current == Current.Coin)
- {
- #region MyRegion
- if (Coin >= amt)
- {
- Coin -= amt;
- return true;
- }
- else
- {
- ManaMessage.Show("您没有足够的金币", 1);
- return false;
- }
- #endregion
- }
- else if (current == Current.Diamond)
- {
- #region MyRegion
- if (Diamond >= amt)
- {
- Diamond -= amt;
- return true;
- }
- else
- {
- ManaMessage.Show("您没有足够的钻石", 1);
- return false;
- }
- #endregion
- }
- else
- {
- throw new Exception(current.ToString());
- }
- }
- }
|