123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666 |
- using LitJson;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.EventSystems;
- using System;
- using System.Xml;
- using System.Collections;
- using System.Collections.Generic;
- public class ManaData : Regist
- {
- #region 变量
- #region 成就
- public static double Elf
- {
- get { return Elf_; }
- set
- {
- Elf_ = value;
- ManaAchieve.UpdateStatus(AchieveType.ElfLevel, Elf_);
- }
- }
- public static double AD
- {
- get { return AD_; }
- set
- {
- AD_ = value;
- ManaAchieve.UpdateStatus(AchieveType.AdAmt, AD_);
- }
- }
- public static double Skill
- {
- get { return Skill_; }
- set
- {
- Skill_ = value;
- ManaAchieve.UpdateStatus(AchieveType.SkillAmt, Skill_);
- }
- }
- public static double SignAmt
- {
- get { return SignAmt_; }
- set
- {
- SignAmt_ = value;
- ManaAchieve.UpdateStatus(AchieveType.SignAmt, SignAmt_);
- }
- }
- public static double Share
- {
- get { return Share_; }
- set
- {
- Share_ = value;
- ManaAchieve.UpdateStatus(AchieveType.ShareAmt, Share_);
- }
- }
- public static double TotalCoin
- {
- get { return TotalCoin_; }
- set
- {
- TotalCoin_ = value;
- ManaAchieve.UpdateStatus(AchieveType.TotalCoin, TotalCoin_);
- }
- }
- public static double MiniGameAmt
- {
- get { return MiniGameAmt_; }
- set
- {
- MiniGameAmt_ = value;
- ManaAchieve.UpdateStatus(AchieveType.MiniGameAmt, MiniGameAmt_);
- }
- }
- public static double FlowerCoin
- {
- get { return FlowerCoin_; }
- set
- {
- FlowerCoin_ = value;
-
- ManaAchieve.UpdateStatus(AchieveType.FlowerCoin, FlowerCoin_);
- }
- }
- public static double TotalPerson
- {
- get { return TotalPerson_; }
- set
- {
- TotalPerson_ = value;
- ManaAchieve.UpdateStatus(AchieveType.TotalPerson, FlowerCoin_);
- }
- }
- private static double Elf_;
- private static double AD_;
- private static double Skill_;
- private static double SignAmt_;
- private static double Share_;
- private static double TotalCoin_;
- private static double MiniGameAmt_;
- private static double FlowerCoin_;
- private static double TotalPerson_;
- #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_));
- ManaAchieve.UpdateStatus(AchieveType.GardenLevel, Level_);
- if (TabBtnValid == false)
- {
- if (Level_ >= 20)
- {
- TabBtnValid = 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();
- }
- if (ManaTutorial.TutorialB_ && !ManaTutorial.TutorialB)
- {
- if (Level_ >= 200)
- {
- ManaTutorial.TutorialB = true;
- ManaTutorial.PrepareStep10();
- }
- }
- }
- }
- 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
- {
- 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 bool MiniValid;
- public static bool TabBtnValid;
- public static bool SkillBarValid;
- public static int MainDepth;
- 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<Skill> UseList = new List<Skill>();
- public static List<SkillRoot> SkillList = new List<SkillRoot>();
- public static Dictionary<string, SkillRoot> SkillDic = new Dictionary<string, SkillRoot>();
- #endregion
- private void Update()
- {
- if (ManaTutorial.TutorialA)
- {
- return;
- }
- MiniThread();
- MainThread();
- }
- private void MiniThread()
- {
- if (Pause)
- {
- return;
- }
- if (MiniValid == false)
- {
- MiniTimer -= Time.deltaTime;
- if (MiniTimer < 0)
- {
- MiniValid = true;
-
- ManaReso.Get("C_MiniGame").TweenForCG();
- }
- }
- }
- private void MainThread()
- {
- if (Pause)
- {
- return;
- }
- MiniThread();
- 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 (ManaTutorial.TutorialA)
- {
- return;
- }
- #region 技能
- for (int i = 0; i < UseList.Count; i++)
- {
- if (UseList[i].DoUse())
- {
- UseList.RemoveAt(i--);
- }
- }
- for (int i = 0; i < CoolList.Count; i++)
- {
- if (CoolList[i].DoCool())
- {
- CoolList.RemoveAt(i--);
- }
- }
- #endregion
- #region 参观收入
- CircleTimer -= Time.deltaTime;
- if (CircleTimer < 0)
- {
- CircleTimer = CircleTime;
- NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
- NewCoinPerson = CoinPerson + SkillCoinPerson;
- TotalPerson += NewPerson;
- float temp = (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
- Coin += temp;
- ManaReso.Get("C_IncomeLab").TweenForGra();
- ManaReso.Get("C_IncomeLab").TweenForVec();
- ManaReso.SetText("C_IncomeLab", "+" + temp.ToString("0"));
- ManaDebug.Log(string.Format("参观收益<color=red>{0: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.ID, 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 读数据存档
- CircleTimer = Data.GetPlayerFloat("CircleTimer");
- List<double> dataList = Data.GetAchieveData();
- AD = dataList[0];
- Skill = dataList[1];
- SignAmt = dataList[2];
- Share = dataList[3];
- MiniGameAmt = dataList[4];
- FlowerCoin = dataList[5];
- TotalPerson = dataList[6];
- #endregion
- }
- public override void RegistValueC()
- {
- #region 读技能存档
- float elapse = (float) DateTime.Now.Subtract(DateTime.Parse(Data.GetPlayerString("QuitTime"))).TotalSeconds;
- if (elapse > 43200)
- {
- elapse = 43200;
- }
-
- ManaDebug.Log(string.Format("离线时间<color=red>{0}</color>", elapse));
- List<Skill> coolList = new List<Skill>();
- List<List<Skill>> useList = new List<List<Skill>>();
- if (elapse > CircleTimer)
- {
- int circle = 1 + Mathf.FloorToInt((elapse - CircleTimer)/CircleTime);
-
- for (int i = 0; i < circle; i++)
- {
- useList.Add(new List<Skill>());
- }
- ManaDebug.Log(string.Format("离线周期<color=red>{0}</color>", circle));
- }
- 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, useList, 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");
- if (MiniTimer <= 0)
- {
- MiniValid = true;
- }
- else
- {
- MiniValid = false;
- }
- ManaDebug.Log(string.Format("<color=red>{0:0}</color>秒后激活小游戏", MiniTimer));
- #endregion
- #region 计算离线收入
- float coin = 0;
- if (useList.Count > 0)
- {
- for (int i = 0; i < useList.Count; i++)
- {
- for (int j = 0; j < coolList.Count; j++)
- {
- coolList[j].CoolTimer -= CircleTime;
- }
- for (int j = 0; j < useList[i].Count; j++)
- {
- useList[i][j].Annul();
- coolList.Add(useList[i][j]);
- }
- }
- NewPerson = Person * (1 + SkillPersonBuff) + SkillPerson;
- NewCoinPerson = CoinPerson + SkillCoinPerson;
- coin += (NewPerson * NewCoinPerson * CircleTime) * (1 + SkillPlus);
- CircleTimer = (elapse - CircleTimer)%CircleTime;
- for (int j = 0; j < coolList.Count; j++)
- {
- coolList[j].CoolTimer -= CircleTime - CircleTimer;
- }
- Coin += coin;
- ManaReso.SetText("Ba_IconLab", coin.ToString("0"));
- }
- else
- {
- CircleTimer = CircleTimer - elapse;
-
- ManaReso.SetText("Ba_IconLab", "0");
- }
- #endregion
- }
- public static bool Pay(double amt, Current current)
- {
- if (ManaTutorial.PayExempt)
- {
- return true;
- }
- amt = Auxiliary.ShrinkNumber(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
- {
- Toast.Show(1.5f, Language.GetStr("Common", "ShortCoin"));
- return false;
- }
- }
- else if (current == Current.Diamond)
- {
- if (Diamond >= amt)
- {
- Diamond -= amt;
- return true;
- }
- else
- {
- Toast.Show(1.5f, Language.GetStr("Common", "ShortDiamond"));
- return false;
- }
- }
- else
- {
- throw new Exception(current.ToString());
- }
- }
- }
|