using LitJson; using UnityEngine; using UnityEngine.EventSystems; using System; using System.Xml; using System.Collections; using System.Collections.Generic; public class ManaData : Regist { #region 变量 public static int Slot { get { return _Slot; } set { _Slot = value; ManaReso.Get("Garden").ValidPage = Mathf.Clamp(Mathf.CeilToInt(_Slot/7f), 1, 2); } } public static int Level { get { return _Level; } set { _Level = value; ManaDebug.Log(string.Format("已升级 花园等级 : {0}", _Level)); for (int i = 0; i < SkillList.Count; i++) { SkillList[i].UpdateStatus(); } } } public static bool Pause { get { return _Pause; } set { _Pause = value; if (_Pause) { Time.timeScale = 0; ManaDebug.Log("游戏暂停"); } else { Time.timeScale = 1; ManaDebug.Log("游戏继续"); } } } public static float Person { get { return _Person; } set { _Person = value; ManaReso.SetText("F_PersonLab", _Person.ToString("0.0")); } } public static float CoinPerson { get { return _CoinPerson; } set { _CoinPerson = value; ManaReso.SetText("F_CoinPersonLab", _CoinPerson.ToString("0.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 _Slot; private static int _Level; private static bool _Pause; private static float _Person; private static float _CoinPerson; private static double _Coin; private static double _Diamond; public static float SkillPlus; public static float SkillPerson; public static float SkillPersonBuff; public static float SkillCoinPerson; public static int Sign; public static int Main; public static bool Mini; public static bool SkillBar; public static bool Connect; public static float OpTime; public static float OpTimer; public static float MiniTimer; public static float CircleTime; public static float CircleTimer; public static float NewPerson; public static float NewCoinPerson; public static List CoolList; public static List UseList; public static List SkillList; public static Dictionary SkillDic; #endregion public override void Instantiate() { #region 生成技能条 #region 读技能配置 SkillDic = new Dictionary(); SkillList = new List(); List 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 SkillDic.Add(skillRoot.Name, skillRoot); SkillList.Add(skillRoot); } SkillList.Sort(SkillRoot.Sort); #endregion for (int i = 0; i < SkillList.Count; i++) { if (SkillList[i].SkillTab != SkillTab.Null) { ManaReso.GetSkillItem(SkillList[i]); } } #endregion } private void Update() { if (Pause) { return; } if (Mini == false) { MiniTimer -= Time.deltaTime; if (MiniTimer < 0) { Mini = true; ManaReso.Get("C_MiniGame").TweenForCG(); } } if (Auxiliary.AnyKeyUp) { OpTimer = 0; if (Main == 0) { ManaReso.Get("C_Main").TweenForCG(); } } else { OpTimer += Time.deltaTime; if (OpTimer >= OpTime) { OpTimer = 0; if (Main == -1) { ManaReso.Get("C_Main").TweenBacCG(); } } } } private void FixedUpdate() { #region 使用技能 for (int i = 0; i < UseList.Count; i++) { if (UseList[i].DoUse()) { i--; } } #endregion #region 冷却技能 for (int i = 0; i < CoolList.Count; i++) { if (CoolList[i].DoCool()) { i--; } } #endregion #region 计算参观收入 CircleTimer -= Time.deltaTime; if (CircleTimer < 0) { CircleTimer = CircleTime; NewPerson = Person*(1 + SkillPersonBuff) + SkillPerson; NewCoinPerson = CoinPerson + SkillCoinPerson; float temp = (NewPerson*NewCoinPerson*CircleTime)*(1 + SkillPlus); Coin += temp; if (Main == -1) { ManaReso.GetHudText("+" + temp.ToString("0"), ManaColor.HudText, 25, ManaReso.Get("C_HudTra"), ManaReso.Get("C_Main"), false); } ManaDebug.Log(string.Format("参观收益{0:0} = {1} * {2} * {3} * {4} (人次*金币*时间*加成)", temp, NewPerson, NewCoinPerson, CircleTime, 1 + SkillPlus)); } #endregion } public override void RegistValueA() { OpTime = 90; MiniTimer = 0; CircleTime = 10; #region 调试 if (ManaReso.Get("B_SignIn").gameObject.activeSelf) { Main = 1; } else { Main = 0; } #endregion #region 读数据存档 Sign = int.Parse(Data.PlayerNode.SelectSingleNode("Sign").Attributes[0].Value); ManaMiniGame.MiniGameAmt = int.Parse(Data.PlayerNode.SelectSingleNode("MiniGameAmt").Attributes[0].Value); CircleTimer = float.Parse(Data.PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value); int slot = int.Parse(Data.PlayerNode.SelectSingleNode("Slot").Attributes[0].Value); for (int i = 0; i < slot; i++) { ManaGarden.UnlockSlot(); } #endregion #region 读花朵存档 XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes; if (!string.IsNullOrEmpty(attributes[0].Value)) { string[] strings = attributes[0].Value.Split(' '); for (int i = 0; i < strings.Length; i++) { int id = int.Parse(strings[i]); ManaGarden.FlowerInfoList[id].Unlock = true; } } attributes = Data.PlayerNode.SelectSingleNode("PlantList").Attributes; for (int i = 0; i < attributes.Count; i++) { int id = int.Parse(attributes[i].Value); ManaGarden.PlantFlower(id, attributes[i].Name); } #endregion } public override void RegistValueC() { #region 读技能存档 UseList = new List(); CoolList = new List(); float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds; if (elapse > 43200) { elapse = 43200; } ManaDebug.Log(string.Format("离线时间{0}", elapse)); XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes; List ffCoolList = new List(); List> ffUseList = new List>(); if (elapse > CircleTimer) { int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime); ManaDebug.Log(string.Format("离线周期{0}", ffCircle)); for (int i = 0; i < ffCircle; i++) { ffUseList.Add(new List()); } } else { ManaDebug.Log(string.Format("离线周期{0}", 0)); } for (int i = 0; i < xmlNodeList.Count; i++) { if (xmlNodeList[i].Attributes[0].Value == SkillType.Skill.ToString()) { Skill skill = (Skill)SkillDic[xmlNodeList[i].Name]; skill.RegistReference(); skill.Level = int.Parse(xmlNodeList[i].Attributes[2].Value); skill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[3].Value); skill.UseTimer = float.Parse(xmlNodeList[i].Attributes[4].Value); skill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value); skill.RegistValue(elapse, ffUseList); } else if (xmlNodeList[i].Attributes[0].Value == SkillType.BigSkill.ToString()) { BigSkill bigSkill = (BigSkill)SkillDic[xmlNodeList[i].Name]; bigSkill.RegistReference(); bigSkill.Level = int.Parse(xmlNodeList[i].Attributes[3].Value); bigSkill.CoolTimer = float.Parse(xmlNodeList[i].Attributes[4].Value); bigSkill.UseTimer = float.Parse(xmlNodeList[i].Attributes[5].Value); bigSkill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value); bigSkill._BarStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value); bigSkill.RegistValue(elapse, ffUseList); } else if (xmlNodeList[i].Attributes[0].Value == SkillType.Pack.ToString()) { Pack pack = (Pack)SkillDic[xmlNodeList[i].Attributes[1].Value]; pack.RegistReference(); pack.Level = int.Parse(xmlNodeList[i].Attributes[3].Value); pack._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[2].Value); pack.RegistValue(elapse, ffUseList); } else if (xmlNodeList[i].Attributes[0].Value == SkillType.Ability.ToString()) { Ability ability = (Ability)SkillDic[xmlNodeList[i].Name]; ability.RegistReference(); ability.Level = int.Parse(xmlNodeList[i].Attributes[2].Value); ability._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value); ability.RegistValue(elapse, ffUseList); } else { throw new Exception(); } } #endregion #region 读数据存档 Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value); MiniTimer = float.Parse(Data.PlayerNode.SelectSingleNode("MiniTimer").Attributes[0].Value); ManaDebug.Log(string.Format("{0:0}秒后激活小游戏", MiniTimer)); Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value); Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value); #endregion #region 计算离线收入 float collectCoin = 0; if (ffUseList.Count > 0) { for (int i = 0; i < ffUseList.Count; i++) { for (int j = 0; j < ffCoolList.Count; j++) { if (ffCoolList[j] is Skill) { if (i == 0) { ((Skill)ffCoolList[j]).CoolTimer -= CircleTimer; } else { ((Skill)ffCoolList[j]).CoolTimer -= CircleTime; } } } for (int j = 0; j < ffUseList[i].Count; j++) { ffUseList[i][j].Annul(); ffCoolList.Add(ffUseList[i][j]); } NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson; NewCoinPerson = CoinPerson + SkillCoinPerson; collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus); } CircleTimer = (elapse - CircleTimer)%CircleTime; for (int j = 0; j < ffCoolList.Count; j++) { if (ffCoolList[j] is Skill) { ((Skill) ffCoolList[j]).CoolTimer -= CircleTime - CircleTimer; } } Coin += collectCoin; ManaReso.SetText("Ba_IconLab", collectCoin.ToString("0")); } else { CircleTimer = CircleTimer - elapse; ManaReso.SetText("Ba_IconLab", "0"); } #endregion } public static bool Pay(double amt, Current current) { amt = (long) 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) { if (Coin >= amt) { Coin -= amt; return true; } else { ManaDebug.Log("您没有足够的金币"); return false; } } else if (current == Current.Diamond) { if (Diamond >= amt) { Diamond -= amt; return true; } else { ManaDebug.Log("您没有足够的钻石"); return false; } } else { throw new Exception(current.ToString()); } } }