using LitJson;
using UnityEngine;
using UnityEngine.EventSystems;
using System;
using System.Xml;
using System.Collections;
using System.Collections.Generic;
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("已升级 花园等级 : {0}", _Level));
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("游戏暂停");
}
else
{
Time.timeScale = 1;
ManaDebug.Log("游戏继续");
}
}
}
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 SkillList
{
get
{
if (_SkillList == null)
{
_SkillList = new List();
}
return _SkillList;
}
set { _SkillList = value; }
}
public static Dictionary SkillDic
{
get
{
if (_SkillDic == null)
{
_SkillDic = new Dictionary();
}
return _SkillDic;
}
set { _SkillDic = value; }
}
public static List _SkillList;
public static Dictionary _SkillDic;
public static int SignIndex;
public static int MainDepth;
public static bool Mini;
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 CoolList = new List();
public static List UseList = new List();
#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("参观收益{0:0} = {1} * {2} * {3} * {4} (人次*金币*时间*加成)", temp, NewPerson, NewCoinPerson, CircleTime, 1 + SkillPlus));
}
#endregion
}
public override void Instantiate()
{
#region 生成技能条
#region 读技能配置
List 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.PlayerInt("SignIndex");
CircleTimer = Data.PlayerFloat("CircleTimer");
for (int i = 0; i < Data.PlayerInt("Slot"); i++)
{
ManaGarden.UnlockSlot();
}
List dataList = Data.GetAchieveData();
AD = dataList[0];
Skill = dataList[1];
Sign = dataList[2];
Share = dataList[3];
MiniGame = dataList[4];
FlowerCoin = dataList[5];
#endregion
#region 读花朵存档
List flowerList = Data.GetFlowerList();
for (int i = 0; i < flowerList.Count; i++)
{
ManaGarden.FlowerInfoList[flowerList[i]].Unlock = true;
}
List> plantList = Data.GetPlantList();
for (int i = 0; i < plantList.Count; i++)
{
ManaGarden.PlantFlower(plantList[i].Key, 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("离线时间{0}", elapse));
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));
}
List 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 读数据存档
Coin = Data.PlayerDouble("Coin");
Level = Data.PlayerInt("Level");
Diamond = Data.PlayerDouble("Diamond");
MiniTimer = Data.PlayerFloat("MiniTimer");
ManaDebug.Log(string.Format("{0:0}秒后激活小游戏", 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 override void TutorialRegistValue()
{
for (int i = 0; i < Data.PlayerInt("Slot"); i++)
{
ManaGarden.UnlockSlot();
}
}
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());
}
}
}