123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576 |
- 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>("Garden").ValidPage = Mathf.Clamp(Mathf.CeilToInt(_Slot/7f), 1, 2);
- }
- }
- public static int Level
- {
- get { return _Level; }
- set
- {
- _Level = value;
- Slot = 7 + Level / 20;
- for (int i = 0; i < Slot; i++)
- {
- ManaGarden.SlotList[i].Valid = true;
- }
- ManaDebug.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", _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("<color=red>游戏暂停</color>");
- }
- else
- {
- Time.timeScale = 1;
- ManaDebug.Log("<color=red>游戏继续</color>");
- }
- }
- }
- 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 _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<Skill> CoolList;
- public static List<SkillRoot> UseList;
- public static List<SkillRoot> SkillList;
- public static Dictionary<string, SkillRoot> SkillDic;
- #endregion
- private void Awake()
- {
- #region 生成技能条
- #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
- 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)
- {
- 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"), Color.red, 25, ManaReso.Get("C_HudTra"), ManaReso.Get("C_Main"), false);
- }
- ManaDebug.Log(string.Format("参观收益<color=red>{0:0}</color> = <color=red>{1}</color> * <color=red>{2}</color> * <color=red>{3}</color> * <color=red>{4}</color> (人次*金币*时间*加成)", 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 读花朵存档
- 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
- #region 读数据存档
- Sign = int.Parse(Data.PlayerNode.SelectSingleNode("Sign").Attributes[0].Value);
- CircleTimer = float.Parse(Data.PlayerNode.SelectSingleNode("CircleTimer").Attributes[0].Value);
- #endregion
- }
- public override void RegistValueC()
- {
- #region 读技能存档
- UseList = new List<SkillRoot>();
- CoolList = new List<Skill>();
- 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("离线时间<color=red>{0}</color>", elapse));
- XmlNodeList xmlNodeList = Data.PlayerNode.SelectSingleNode("SkillList").ChildNodes;
- List<SkillRoot> ffCoolList = new List<SkillRoot>();
- List<List<SkillRoot>> ffUseList = new List<List<SkillRoot>>();
- if (elapse > CircleTimer)
- {
- int ffCircle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
- ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", ffCircle));
- for (int i = 0; i < ffCircle; i++)
- {
- ffUseList.Add(new List<SkillRoot>());
- }
- }
- else
- {
- ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", 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);
- 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());
- }
- }
- }
|