123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 |
- using LitJson;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using System;
- using System.Xml;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine.UI;
- public class ManaData : Regist
- {
- #region 变量
- #region 成就
- public static double AD
- {
- get { return _AD; }
- set
- {
- _AD = value;
- ManaAchieve.UpdateStatus(AchieveType.AD, _AD);
- }
- }
- public static double Skill
- {
- get { return _Skill; }
- set
- {
- _Skill = value;
- ManaAchieve.UpdateStatus(AchieveType.Skill, _Skill);
- }
- }
- public static double Sign
- {
- get { return _Sign; }
- set
- {
- _Sign = value;
- ManaAchieve.UpdateStatus(AchieveType.Sign, _Sign);
- }
- }
- public static double Share
- {
- get { return _Share; }
- set
- {
- _Share = value;
- ManaAchieve.UpdateStatus(AchieveType.Share, _Share);
- }
- }
- public static double ElfLevel
- {
- get { return _ElfLevel; }
- set
- {
- _ElfLevel = value;
- ManaAchieve.UpdateStatus(AchieveType.ElfLevel, _ElfLevel);
- }
- }
- public static double TotalCoin
- {
- get { return _TotalCoin; }
- set
- {
- _TotalCoin = value;
- ManaAchieve.UpdateStatus(AchieveType.TotalCoin, _TotalCoin);
- }
- }
- public static double MiniGame
- {
- get { return _MiniGame; }
- set
- {
- _MiniGame = value;
- ManaAchieve.UpdateStatus(AchieveType.MiniGame, _MiniGame);
- }
- }
- public static double FlowerCoin
- {
- get { return _FlowerCoin; }
- set
- {
- _FlowerCoin = value;
-
- ManaAchieve.UpdateStatus(AchieveType.FlowerCoin, _FlowerCoin);
- }
- }
- private static double _AD;
- private static double _Skill;
- private static double _Sign;
- private static double _Share;
- private static double _ElfLevel;
- private static double _TotalCoin;
- private static double _MiniGame;
- private static double _FlowerCoin;
- #endregion
- public static int Slot
- {
- get { return _Slot; }
- set
- {
- _Slot = value;
- Garden.ValidPage = Mathf.Clamp(Mathf.CeilToInt(_Slot/7f), 1, 2);
- }
- }
- public static int Level
- {
- get { return _Level; }
- set
- {
- _Level = value;
- ManaDebug.Log(string.Format("已升级 花园等级 : <color=red>{0}</color>", _Level));
- if (TabBtn == false)
- {
- if (_Level >= 20)
- {
- TabBtn = true;
- ManaReso.Get<Graphic>("F_Elf").material = null;
- ManaReso.Get<Graphic>("F_Store").material = null;
- ManaReso.Get<Graphic>("F_Magic").material = null;
- ManaReso.Get<Graphic>("F_ElfLab").material = null;
- ManaReso.Get<Graphic>("F_StoreLab").material = null;
- ManaReso.Get<Graphic>("F_MagicLab").material = null;
- ManaReso.Get<Button>("F_Elf").interactable = true;
- ManaReso.Get<Button>("F_Store").interactable = true;
- ManaReso.Get<Button>("F_Magic").interactable = true;
- }
- }
- for (int i = 0; i < SkillList.Count; i++)
- {
- SkillList[i].UpdateStatus();
- }
- ManaAchieve.UpdateStatus(AchieveType.Garden, _Level);
- }
- }
- 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.0"));
- ManaAchieve.UpdateStatus(AchieveType.Person, _Person);
- }
- }
- 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
- {
- if (value - _Coin > 0)
- {
- TotalCoin += value - _Coin;
- }
- _Coin = value;
- ManaReso.SetText("F_CoinLab", _Coin.ToString("0"));
- ManaReso.SetText("C_CoinLab", _Coin.ToString("0"));
-
- ManaAchieve.UpdateStatus(AchieveType.CurrentCoin, _Coin);
- }
- }
- 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 List<SkillRoot> SkillList
- {
- get
- {
- if (_SkillList == null)
- {
- _SkillList = new List<SkillRoot>();
- }
- return _SkillList;
- }
- set { _SkillList = value; }
- }
- public static Dictionary<string, SkillRoot> SkillDic
- {
- get
- {
- if (_SkillDic == null)
- {
- _SkillDic = new Dictionary<string, SkillRoot>();
- }
- return _SkillDic;
- }
- set { _SkillDic = value; }
- }
- public static List<SkillRoot> _SkillList;
- public static Dictionary<string, SkillRoot> _SkillDic;
- public static int SignIndex;
- public static int MainDepth;
- public static bool Mini;
- public static bool TabBtn;
- public static bool SkillBar;
- public static bool Connect;
- public static float OpTime = 90;
- public static float OpTimer;
- public static float MiniTimer;
- public static float CircleTime = 10;
- public static float CircleTimer;
- public static float NewPerson;
- public static float NewCoinPerson;
- public static float SkillPlus;
- public static float SkillPerson;
- public static float SkillPersonBuff;
- public static float SkillCoinPerson;
- public static List<Skill> CoolList = new List<Skill>();
- public static List<SkillRoot> UseList = new List<SkillRoot>();
- #endregion
- private void Update()
- {
- if (Initializer.Tutorial)
- {
- TutorialUpdate();
- }
- else
- {
- RegularUpdate();
- }
- }
- private void TutorialUpdate()
- {
- }
- private void RegularUpdate()
- {
- 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 (MainDepth == 0)
- {
- ManaReso.Get("C_Main").TweenForCG();
- }
- }
- else
- {
- OpTimer += Time.deltaTime;
- if (OpTimer >= OpTime)
- {
- OpTimer = 0;
- if (MainDepth == -1)
- {
- ManaReso.Get("C_Main").TweenBacCG();
- }
- }
- }
- }
- private void FixedUpdate()
- {
- if (Initializer.Tutorial)
- {
- TutorialFixedUpdate();
- }
- else
- {
- RegularFixedUpdate();
- }
- }
-
- private void TutorialFixedUpdate()
- {
-
- }
- private void RegularFixedUpdate()
- {
- #region 技能
- for (int i = 0; i < UseList.Count; i++)
- {
- if (UseList[i].DoUse())
- {
- i--;
- }
- }
- 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 (MainDepth == -1)
- {
- ManaReso.GetHudText("+" + temp.ToString("0"), Color.white, 25, ManaReso.Get("C_PosTra"), 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 Instantiate()
- {
- #region 生成技能条
- #region 读技能配置
- List<XmlAttributeCollection> attributeList = Data.GetSkillConfig();
- for (int i = 0; i < attributeList.Count; i++)
- {
- SkillRoot skillRoot;
- #region MyRegion
- if (attributeList[i].Count == 17)
- {
- skillRoot = new Pack(attributeList[i]);
- }
- else if (attributeList[i].Count == 23)
- {
- skillRoot = new Ability(attributeList[i]);
- }
- else if (attributeList[i].Count == 33)
- {
- if (string.IsNullOrEmpty(attributeList[i][4].Value))
- {
- skillRoot = new Skill(attributeList[i]);
- }
- else
- {
- skillRoot = new BigSkill(attributeList[i]);
- }
- }
- else
- {
- throw new Exception(attributeList[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
- }
- public override void RegistValueA()
- {
- if (ManaReso.Get("B_SignIn").gameObject.activeSelf)
- {
- MainDepth = 1;
- }
- else
- {
- MainDepth = 0;
- }
- #region 读数据存档
- SignIndex = Data.GetPlayerInt("SignIndex");
- CircleTimer = Data.GetPlayerFloat("CircleTimer");
- List<double> dataList = Data.GetAchieveData();
- AD = dataList[0];
- Skill = dataList[1];
- Sign = dataList[2];
- Share = dataList[3];
- MiniGame = dataList[4];
- FlowerCoin = dataList[5];
- #endregion
- #region 读花朵存档
- List<int> flowerList = Data.GetFlowerList();
- for (int i = 0; i < flowerList.Count; i++)
- {
- ManaGarden.FlowerInfoList[flowerList[i]-1].Unlock = true;
- }
- List<KV<int, string>> plantList = Data.GetPlantList();
- for (int i = 0; i < plantList.Count; i++)
- {
- ManaGarden.PlantFlower(plantList[i].Key-1, plantList[i].Value);
- }
- #endregion
- }
- public override void RegistValueC()
- {
- #region 读技能存档
- 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));
- 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));
- }
- List<XmlAttributeCollection> attributeList = Data.GetSkillList();
- for (int i = 0; i < attributeList.Count; i++)
- {
- SkillRoot skillRoot = SkillDic[attributeList[i][0].Value];
- skillRoot.RegistReference();
- skillRoot.RegistValue(elapse, ffUseList, attributeList[i]);
- }
- #endregion
- #region 读数据存档
- for (int i = 0; i < Data.GetPlayerInt("Slot"); i++)
- {
- ManaGarden.UnlockSlot();
- }
- Coin = Data.GetPlayerDouble("Coin");
- Level = Data.GetPlayerInt("Level");
- Diamond = Data.GetPlayerDouble("Diamond");
- MiniTimer = Data.GetPlayerFloat("MiniTimer");
- ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
- #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());
- }
- }
- }
|