123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798 |
- using LitJson;
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using System.Xml;
- using System.Collections;
- using System.Collections.Generic;
- public class ManaVisit
- {
- #region 变量
- #region 配置
- public static int Cost
- {
- get { return Cost_; }
- set
- {
- Cost_ = value;
- ManaReso.Get<Text>("C_CostLab").text = "<(金币)>" + Cost;
- }
- }
- public static int Cost_;
- public static int CoolTime;
- public static float FancyRate;
- public static float AwardRate;
- public static float CreateRate;
- public static string CostFml;
- public static string AwardMinFml;
- public static string AwardMaxFml;
- #endregion
- public static bool InVisit;
- public static bool Complete;
- public static bool LoadComplete;
- public static bool TweenComplete;
- public static string XmlStr;
- public static int Slot;
- public static int Level;
- public static XmlNode Node;
- public static XmlDocument Document;
- public static bool OriginBird;
- public static bool OriginTree;
- public static bool OriginRainbow;
- public static List<Slot> VisitPlantList;
- public static List<Slot> OriginPlantList;
- public static List<ElfType> OriginElfList;
- #endregion
- public static void Initialize()
- {
- XmlAttributeCollection attribute = ManaData.GetVisitConfig();
- CostFml = attribute[5].Value;
- Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
- AwardMinFml = attribute[2].Value;
- AwardMaxFml = attribute[3].Value;
- CoolTime = int.Parse(attribute[4].Value);
- FancyRate = float.Parse(attribute[7].Value);
- AwardRate = float.Parse(attribute[1].Value);
- CreateRate = float.Parse(attribute[6].Value);
- #region 倒计时
- if (CoolTime != 0)
- {
- Text text = ManaReso.Get<Text>("C_VisitLab");
- List<float> delayList = new List<float>();
- List<float> durationList = new List<float>();
- List<VecPair> pairList = new List<VecPair>();
- List<UnityAction> actionList = new List<UnityAction>();
- Vector3 v1 = new Vector3(0.75f, 0.75f, 0.75f);
- Vector3 v2 = new Vector3(0.4f, 0.4f, 0.4f);
- Vector3 v3 = new Vector3(0, 0, 0);
- for (int i = 0; i < CoolTime - 1; i++)
- {
- delayList.Add(0.5f);
- delayList.Add(0);
- }
- delayList.Add(0.5f);
- for (int i = 0; i < CoolTime; i++)
- {
- durationList.Add(0.25f);
- durationList.Add(0.25f);
- pairList.Add(new VecPair(v1, v2));
- pairList.Add(new VecPair(v2, v3));
- var tempInt = i;
- actionList.Add
- (
- () =>
- {
- text.text = (CoolTime - tempInt).ToString();
- ManaAudio.PlayClip(Clip.BtnClip);
- }
- );
- actionList.Add(null);
- }
- TweenRoot tween = ManaReso.Get("C_VisitLab").CreateStreamScale
- (
- delayList,
- durationList,
- pairList,
- true,
- false,
- Curve.EaseOutQuad,
- false,
- actionList
- );
- tween.OnForwardFinish += () =>
- {
- ManaAudio.PlayClip(Clip.BubbleClip);
- };
- }
- #endregion
- Complete = true;
- }
- public static void Exit()
- {
- TweenRoot tweenRoot = ManaReso.Get("I_BlackMask").TweenForCG();
- tweenRoot.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ManaPlayer.Player.SetAllCollider(true);
- }
- );
-
- HideTip ();
- ManaReso.SetActive("C_Visit", true);
- ManaReso.SetActive("C_Coin", true);
- ManaReso.SetActive("C_Group1", true);
- ManaReso.SetActive("C_Group2", true);
- ManaReso.SetActive("C_Return", false);
- ManaReso.SetActive("C_Garden", false);
- ManaGarden.MiniLock = true;
- #region Garden
- ManaGarden.RetriveFlowerAll();
- for (int i = 0; i < ManaGarden.PageList.Count; i++)
- {
- ManaReso.Save(ManaGarden.PageList[i]);
- }
- ManaGarden.PageList = new List<Transform>();
- Garden.CurPage = 0;
- ManaGarden.SlotList = new List<Slot>();
- ManaGarden.PageList = new List<Transform>();
- Garden.ResetPage();
- Garden.PagePos = new List<Vector3>();
- int pageAmt = 2;
- if (ManaGarden.Slot >= 7)
- {
- pageAmt = (ManaGarden.Slot - 7)/9 + 3;
- }
- for (int i = 0; i < pageAmt; i++)
- {
- ManaGarden.CreatePage();
- }
- for (int i = 0; i < ManaGarden.SlotList.Count; i++)
- {
- if (i < ManaGarden.Slot)
- {
- ManaGarden.SlotList[i].Lock = true;
- ManaGarden.SlotList[i].Available = true;
- }
- else
- {
- ManaGarden.SlotList[i].Lock = false;
- ManaGarden.SlotList[i].Available = false;
- }
- }
- List<KV<int, int>> plantList = ManaData.GetPlantList();
- for (int i = 0; i < plantList.Count; i++)
- {
- ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
- }
- #endregion
- #region Bird Tree Rainbow
- if (OriginBird)
- {
- ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
- }
- else
- {
- ManaReso.Get("Bird0").GetTweenSr().InOrigin = true;
- }
- if (OriginTree)
- {
- ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
- ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
- }
- else
- {
- ManaReso.Get("Tree1").GetTweenSr().InOrigin = true;
- ManaReso.Get("Tree2").GetTweenSr().InOrigin = true;
- }
- if (OriginRainbow)
- {
- ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
- }
- else
- {
- ManaReso.Get("Rainbow").GetTweenSr().InOrigin = true;
- }
- #endregion
- #region Player
- ManaReso.Save(ManaPlayer.Player);
- ManaReso.TraDic.Remove("Player");
- ManaPlayer.Instance.GetPlayer();
- Garden.PlayerPos = new List<Vector3>();
- Garden.Player = ManaReso.Get("Player");
- Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
- Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
- #endregion
- ManaGarden.ElfList = new List<ElfType>(OriginElfList);
- InVisit = false;
- }
- public static void Enter()
- {
- if (!LoadComplete || !TweenComplete)
- {
- return;
- }
- ManaReso.Get("I_BlackMask").TweenForCG();
- ShowTip ();
- Document = new XmlDocument();
- Document.LoadXml(XmlStr);
- Node = Document.SelectSingleNode("PlayerConfig");
- ManaReso.SetActive("C_Coin", false);
- ManaReso.SetActive("C_Group1", false);
- ManaReso.SetActive("C_Group2", false);
- ManaReso.SetActive("C_Garden", true);
- if (!InVisit)
- {
- for (int i = 0; i < ManaGarden.StarList.Count; i++)
- {
- ManaReso.Save(ManaGarden.StarList[i]);
- }
- ManaGarden.StarList = new List<Star>();
- }
- ManaReso.SetActive("C_Return", true);
- ManaGarden.MiniLock = false;
- #region Bird Tree Rainbow
- if (!InVisit)
- {
- if (ManaReso.Get("Bird0").gameObject.activeSelf)
- {
- OriginBird = true;
- }
- if (ManaReso.Get("Tree1").gameObject.activeSelf)
- {
- OriginTree = true;
- }
- if (ManaReso.Get("Rainbow").gameObject.activeSelf)
- {
- OriginRainbow = true;
- }
- }
- ManaReso.SetActive("Bird0", false);
- ManaReso.SetActive("Tree1", false);
- ManaReso.SetActive("Tree2", false);
- ManaReso.SetActive("Rainbow", false);
- #endregion
- #region Ability
- Slot = 1;
- if (!InVisit)
- {
- OriginElfList = new List<ElfType>(ManaGarden.ElfList);
- }
- ManaGarden.ElfList = new List<ElfType>();
- List<XmlAttributeCollection> attributeList = ManaData.GetSkillList(Node);
- for (int i = 0; i < attributeList.Count; i++)
- {
- if (!attributeList[i][0].Value.Contains("Ability"))
- {
- continue;
- }
- if (attributeList[i][0].Value == "Ability1")
- {
- Level = int.Parse(attributeList[i][3].Value);
- ManaReso.SetText("C_GardenLab", Language.GetStr("UI", "C_GardenLab") + Level);
- continue;
- }
- if (int.Parse(attributeList[i][3].Value) == 0)
- {
- continue;
- }
- if (attributeList[i][0].Value == "Ability2")
- {
- ManaReso.Get("Rainbow").GetTweenSr().InDestination = true;
- }
- else if (attributeList[i][0].Value == "Ability3")
- {
- ManaReso.Get("Tree1").GetTweenSr().InDestination = true;
- ManaReso.Get("Tree2").GetTweenSr().InDestination = true;
- }
- else if (attributeList[i][0].Value == "Ability4")
- {
- ManaReso.Get("Bird0").GetTweenSr().InDestination = true;
- }
- else if (attributeList[i][0].Value == "Ability5")
- {
- ManaGarden.ElfList.Add(ElfType.Bee_Yellow);
- }
- else if (attributeList[i][0].Value == "Ability6")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Bee_Purple);
- }
- else if (attributeList[i][0].Value == "Ability7")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Bee_Blue);
- }
- else if (attributeList[i][0].Value == "Ability8")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Bee_Red);
- }
- else if (attributeList[i][0].Value == "Ability9")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Bee_White);
- }
- else if (attributeList[i][0].Value == "Ability10")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Butterfly_Yellow);
- }
- else if (attributeList[i][0].Value == "Ability11")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Butterfly_Purple);
- }
- else if (attributeList[i][0].Value == "Ability12")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Butterfly_Blue);
- }
- else if (attributeList[i][0].Value == "Ability13")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Butterfly_Red);
- }
- else if (attributeList[i][0].Value == "Ability14")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Butterfly_White);
- }
- else if (attributeList[i][0].Value == "Ability15")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Dragonfly_Yellow);
- }
- else if (attributeList[i][0].Value == "Ability16")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Dragonfly_Purple);
- }
- else if (attributeList[i][0].Value == "Ability17")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Dragonfly_Blue);
- }
- else if (attributeList[i][0].Value == "Ability18")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Dragonfly_Red);
- }
- else if (attributeList[i][0].Value == "Ability19")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Dragonfly_White);
- }
- else if (attributeList[i][0].Value == "Ability20")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Beetle_Yellow);
- }
- else if (attributeList[i][0].Value == "Ability21")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Beetle_Purple);
- }
- else if (attributeList[i][0].Value == "Ability22")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Beetle_Blue);
- }
- else if (attributeList[i][0].Value == "Ability23")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Beetle_Red);
- }
- else if (attributeList[i][0].Value == "Ability24")
- {
- Slot++;
- ManaGarden.ElfList.Add(ElfType.Beetle_White);
- }
- }
-
- #endregion
- #region Garden
- if (!InVisit)
- {
- OriginPlantList = new List<Slot>(ManaGarden.PlantList);
- ManaData.SaveDress();
- ManaData.SavePlantList();
- }
- ManaGarden.RetriveFlowerAll();
- for (int i = 0; i < ManaGarden.PageList.Count; i++)
- {
- ManaReso.Save(ManaGarden.PageList[i]);
- }
- ManaGarden.PageList = new List<Transform>();
- Garden.CurPage = 0;
- ManaGarden.SlotList = new List<Slot>();
- ManaGarden.PageList = new List<Transform>();
- Garden.ResetPage();
- Garden.PagePos = new List<Vector3>();
- int pageAmt = 2;
- if (Slot >= 7)
- {
- pageAmt = (Slot - 7) / 9 + 3;
- }
- for (int i = 0; i < pageAmt; i++)
- {
- ManaGarden.CreatePage();
- }
-
- for (int i = 0; i < ManaGarden.SlotList.Count; i++)
- {
- if (i < Slot)
- {
- ManaGarden.SlotList[i].Lock = true;
- ManaGarden.SlotList[i].Available = true;
- }
- else
- {
- ManaGarden.SlotList[i].Lock = false;
- ManaGarden.SlotList[i].Available = false;
- }
- }
- List<KV<int, int>> plantList = ManaData.GetPlantList(Node);
- for (int i = 0; i < plantList.Count; i++)
- {
- ManaGarden.PlantFlower(plantList[i].Key, plantList[i].Value);
- }
- #endregion
- #region Player
- ManaReso.Save(ManaPlayer.Player);
- ManaReso.TraDic.Remove("Player");
- ManaPlayer.Instance.GetPlayer(Node).SetAllCollider(false);
- Garden.PlayerPos = new List<Vector3>();
- Garden.Player = ManaReso.Get("Player");
- Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos1"].position);
- Garden.PlayerPos.Add(ManaPlayer.Player.ChildDic["Pos2"].position);
- #endregion
- #region Award
-
- if (ManaTutorial.TutorialC || Random.Range(0f,1f) <= AwardRate)
- {
- if (ManaTutorial.TutorialC)
- {
- ManaTutorial.EndC();
- }
- if (ManaGarden.PlantList.Count > 0)
- {
- ManaGarden.PlantList.Random()[0].Flower.Award = true;
- }
- }
- #endregion
- InVisit = true;
- }
- public static void UpdateCost()
- {
- if (Complete)
- {
- Cost = Mathf.FloorToInt((float)Auxiliary.FmlParse(CostFml, "l", ManaCenter.Level.ToString()));
- }
- }
- public static void DataReverse()
- {
- if (InVisit)
- {
- VisitPlantList = new List<Slot>(ManaGarden.PlantList);
- ManaGarden.PlantList = OriginPlantList;
- }
- }
- public static void DataRecover()
- {
- if (InVisit)
- {
- ManaGarden.PlantList = VisitPlantList;
- }
- }
- public static void ShowTip()
- {
- ManaReso.SetActive ("C_Tip", true);
- ManaReso.Get<Text> ("C_TipLab").text = Language.GetStr ("Tip", "Tip" + Random.Range(1,10));
- }
- public static void HideTip()
- {
- ManaReso.SetActive ("C_Tip", false);
- }
- public static void GetArchive()
- {
- if (Random.Range(0f, 1f) <= CreateRate)
- {
- LoadComplete = true;
- XmlStr = WriteArchive();
- Enter();
- }
- else
- {
- ManaServer.RandomLoad
- (
- (jsonData) =>
- {
- LoadComplete = true;
-
- if (jsonData.Inst_Object.ContainsKey("l"))
- {
- XmlStr = jsonData["l"].ToString();
- }
- else
- {
- LoadComplete = true;
- XmlStr = WriteArchive();
- }
- Enter();
- }
- );
- }
- }
- public static string WriteArchive()
- {
- XmlDocument doc = new XmlDocument();
- doc.LoadXml(ManaData.PlayerDoc.OuterXml);
- bool fancy;
- if (Random.Range(0f, 1f) < FancyRate)
- {
- fancy = true;
- }
- else
- {
- fancy = false;
- }
- int slot = 1;
- int newLevel = Random.Range(1, 301);
-
- XmlNodeList nodeList = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("SkillList").ChildNodes;
- for (int i = 0; i < nodeList.Count; i++)
- {
- SkillType type = nodeList[i].Attributes[1].Value.ToEnum<SkillType>();
- if (type == SkillType.Ability)
- {
- Ability ability = (Ability) ManaCenter.SkillDic[nodeList[i].Attributes[0].Value];
- int unlockLevel = ability.UnlockLv;
- if (newLevel >= unlockLevel)
- {
- if (ability.ID_ >= 6)
- {
- slot++;
- }
- nodeList[i].Attributes[2].Value = "Upgrade";
- nodeList[i].Attributes[3].Value = newLevel.ToString();
- }
- else
- {
- nodeList[i].Attributes[2].Value = "Lock";
- nodeList[i].Attributes[3].Value = "0";
- }
- }
- }
- List<int> flowerList = new List<int>();
- for (int i = 2; i < 28; i++)
- {
- flowerList.Add(i);
- }
- int slotIndex = 0;
- string plantList = "";
- for (int i = 0; i < slot; i++)
- {
- if (fancy || Random.Range(0f, 1f) >= 0.35f)
- {
- int flowerID = slotIndex + 1;
- plantList += string.Format("{0},{1} ", flowerID, slotIndex);
- slotIndex++;
- }
- }
- plantList = plantList.TrimEnd(' ');
- doc.SelectSingleNode("PlayerConfig").SelectSingleNode("PlantList").Attributes[0].Value = plantList;
- XmlNode xmlNode = doc.SelectSingleNode("PlayerConfig").SelectSingleNode("DressData");
- xmlNode.Attributes[0].Value = "";
- xmlNode.Attributes[0].Value = ManaPlayer.CloseUnitDic[Random.Range(2, (int) Mathf.Lerp(2, 30, newLevel/300f)+1)].ArmatureName;
- xmlNode.Attributes[1].Value = ManaPlayer.CloseUnitDic[Random.Range(201, (int) Mathf.Lerp(201, 217, newLevel/300f)+1)].ArmatureName;
- xmlNode.Attributes[2].Value = ManaPlayer.CloseUnitDic[Random.Range(401, (int) Mathf.Lerp(401, 415, newLevel/300f)+1)].ArmatureName;
- xmlNode.Attributes[3].Value = ManaPlayer.CloseUnitDic[Random.Range(601, (int) Mathf.Lerp(601, 612, newLevel/300f)+1)].ArmatureName;
- xmlNode.Attributes[4].Value = ManaPlayer.CloseUnitDic[Random.Range(801, (int) Mathf.Lerp(801, 817, newLevel/300f)+1)].ArmatureName;
- xmlNode.Attributes[7].Value = ManaPlayer.CloseUnitDic[Random.Range(1001, (int) Mathf.Lerp(1001, 1003, newLevel/300f)+1)].ArmatureName;
- float eyeMouseRate = Random.Range(0f, 1f);
- if (eyeMouseRate <= 0.33f)
- {
- xmlNode.Attributes[5].Value = "眼睛1";
- xmlNode.Attributes[6].Value = "嘴巴1";
- }
- else if (eyeMouseRate <= 0.66f)
- {
- xmlNode.Attributes[5].Value = "眼睛2";
- xmlNode.Attributes[6].Value = "嘴巴2";
- }
- else
- {
- xmlNode.Attributes[5].Value = "眼睛3";
- xmlNode.Attributes[6].Value = "嘴巴3";
- }
- return doc.OuterXml;
- }
- }
|