123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483 |
- using LitJson;
- using UnityEngine;
- using UnityEngine.EventSystems;
- 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;
- for (int i = 0; i < SkillList.Count; i++)
- {
- SkillList[i].OnLevelChange();
- }
- 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 float SkillPlus;
- public static float SkillPerson;
- public static float SkillPersonBuff;
- public static float SkillCoinPerson;
- public static bool SkillBar;
- public static bool Connect;
- public static float OpTime;
- public static float CircleTime;
- public static float OpTimer;
- public static float CircleTimer;
- public static float NewPerson;
- public static float NewCoinPerson;
- public static List<Skill> CoolList;
- public static List<SkillRoot> SkillList;
- public static List<SkillRoot> UsingList;
- public static Dictionary<string, SkillRoot> SkillDic;
- #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(SkillRoot.SortByClassID);
- #endregion
- #region 创建技能条
- for (int i = 0; i < SkillList.Count; i++)
- {
- if (SkillList[i].Tab != SkillTab.Null)
- {
- ManaReso.GetSkillItem(SkillList[i]);
- }
- }
- #endregion
- }
- private void Update()
- {
- if (Math.Abs(Time.timeScale) < 0.0005f)
- {
- return;
- }
- if (Input.anyKeyDown)
- {
- OpTimer = 0;
- if (ManaReso.Get("GardenMini").gameObject.activeSelf || ManaReso.Get("F_Manage").gameObject.activeSelf)
- {
- return;
- }
- GameObject go = ManaReso.Get("C_Main").gameObject;
- if (go.activeSelf == false)
- {
- go.transform.TweenForCG();
- }
- }
- else
- {
- OpTimer += Time.deltaTime;
- if (OpTimer >= OpTime)
- {
- OpTimer = 0;
- GameObject go = ManaReso.Get("C_Main").gameObject;
- if (go.activeSelf)
- {
- go.transform.TweenBacCG();
- }
- }
- }
- }
- private void FixedUpdate()
- {
- #region 使用技能
- for (int i = 0; i < UsingList.Count; i++)
- {
- if (UsingList[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;
- Coin += (NewPerson*NewCoinPerson*CircleTime)*(1 + SkillPlus);
- 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 * CircleTime) * (1 + SkillPlus), NewPerson, NewCoinPerson, CircleTime, 1 + SkillPlus));
- }
- #endregion
- }
- private void RegistValue()
- {
- OpTime = 5;
- CircleTime = 10;
- CircleTimer = 10;
- CoolList = new List<Skill>();
- UsingList = new List<SkillRoot>();
- #region 读技能存档
- double elapse = DateTime.Now.Subtract(DateTime.Parse(Data.PlayerNode.SelectSingleNode("QuitTime").Attributes[0].Value)).TotalSeconds;
- XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
- List<SkillRoot> ffCoolList = new List<SkillRoot>();
- List<List<SkillRoot>> ffList = new List<List<SkillRoot>>();
- if (elapse > CircleTimer)
- {
- int ffCircle = 1 + Mathf.FloorToInt((float)((elapse - CircleTimer) / CircleTime));
- for (int i = 0; i < ffCircle; i++)
- {
- ffList.Add(new List<SkillRoot>());
- }
- }
- 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.UsingTimer = float.Parse(xmlNodeList[i].Attributes[4].Value);
- skill._ItemStatus = (SkillStatus)Enum.Parse(typeof(SkillStatus), xmlNodeList[i].Attributes[1].Value);
- skill.RegistValue(elapse, ffList);
- }
- 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.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
- bigSkill.RegistValue(elapse, ffList);
- }
- 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, ffList);
- }
- 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, ffList);
- }
- else
- {
- throw new Exception();
- }
- }
- #endregion
- #region 读花朵存档
- XmlAttributeCollection attributes = Data.PlayerNode.SelectSingleNode("FlowerList").Attributes;
- if (string.IsNullOrEmpty(attributes[0].Value) == false)
- {
- string[] strings = attributes[0].Value.Split(' ');
- for (int i = 0; i < strings.Length; i++)
- {
- if (string.IsNullOrEmpty(strings[i]))
- {
- continue;
- }
- int id = int.Parse(strings[i]);
- ManaGarden.FlowerDic[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.PlaceFlower(id, ManaReso.Get(attributes[i].Name));
- }
- #endregion
- #region 读数据存档
- Level = int.Parse(Data.PlayerNode.SelectSingleNode("Level").Attributes[0].Value);
- Coin = double.Parse(Data.PlayerNode.SelectSingleNode("Coin").Attributes[0].Value);
- Diamond = double.Parse(Data.PlayerNode.SelectSingleNode("Diamond").Attributes[0].Value);
- #endregion
- #region 计算离线收入
- double collectCoin = 0;
- if (ffList.Count > 0)
- {
- for (int i = 0; i < ffList.Count; i++)
- {
- for (int j = 0; j < ffCoolList.Count; j++)
- {
- if (ffCoolList[j].SkillType == SkillType.Skill || ffCoolList[j].SkillType == SkillType.BigSkill)
- {
- if (i == 0)
- {
- ((Skill) ffCoolList[j]).CoolTimer -= CircleTimer;
- }
- else
- {
- ((Skill)ffCoolList[j]).CoolTimer -= CircleTime;
- }
- }
- }
-
- for (int j = 0; j < ffList[i].Count; j++)
- {
- ffList[i][j].Annul();
- ffCoolList.Add(ffList[i][j]);
- }
- NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
- NewCoinPerson = CoinPerson + SkillCoinPerson;
- collectCoin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
- }
- Coin += collectCoin;
-
- ManaReso.SetText("A_IconLab", collectCoin.ToString("0"));
- CircleTimer = (float)((elapse - CircleTimer) % CircleTime);
- }
- else
- {
- CircleTimer = (float)(CircleTimer - elapse);
- ManaReso.SetText("A_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
- {
- ManaLog.Log("您没有足够的金币");
- return false;
- }
- }
- else if (current == Current.Diamond)
- {
- if (Diamond >= amt)
- {
- Diamond -= amt;
- return true;
- }
- else
- {
- ManaLog.Log("您没有足够的钻石");
- return false;
- }
- }
- else
- {
- throw new Exception(current.ToString());
- }
- }
- }
|