public static string ConvertToString(ItemSkillTree skilltree) { string save = ""; for (int i = 0; i < skilltree.GetSize; i++) { if (i > 0) { save += ";"; } save += ItemNodeAtlas.GetID(skilltree.GetNode(i).GetType().Name) + "|"; for (int j = 0; j < skilltree.GetNode(i).GetNeighboor.Count; j++) { save += skilltree.GetNode(i).GetNeighboor[j]; if (j < skilltree.GetNode(i).GetNeighboor.Count - 1) { save += ':'; } } save += "|" + skilltree.GetNode(i).GetState + "|" + skilltree.GetNode(i).GetLevel + "|" + skilltree.GetNode(i).GetMaxLevel + "|" + skilltree.GetNode(i).GetRequiredPoints + "|" + skilltree.GetNode(i).GetPos.X + ":" + skilltree.GetNode(i).GetPos.Y + "|"; save += skilltree.GetNode(i).GetSaveValue(); } return(save); }
public static ItemSkillTree ConvertToTree(string save, ItemUpdate source) { string[] nodeListSave; string[] nodeDetails; ItemSkillTree tree = new ItemSkillTree(); nodeListSave = save.Split(';'); tree.m_ItemSource = source; string[] a; ItemNode bufferNode; foreach (string nodeSave in nodeListSave) { bufferNode = null; nodeDetails = nodeSave.Split(','); if (nodeDetails.Length != 8) { AnotherRpgMod.Instance.Logger.Warn("Item tree corrupted, reseting tree"); tree = new ItemSkillTree(); tree.Init(source); return(tree); } bufferNode = (ItemNode)ItemNodeAtlas.GetCorrectNode(int.Parse(nodeDetails[0])); a = nodeDetails[6].Split(':'); bufferNode.Init(tree, tree.GetSize, int.Parse(nodeDetails[4]), int.Parse(nodeDetails[5]), new Vector2(int.Parse(a[0]), int.Parse(a[1]))); //Ignore it if there is no neighboor if (nodeDetails[1] != "") { a = nodeDetails[1].Split(':'); foreach (string neightboor in a) { bufferNode.AddNeightboor(int.Parse(neightboor)); } } bufferNode.ForceLockNode(int.Parse(nodeDetails[2])); bufferNode.SetLevel = int.Parse(nodeDetails[3]); if (nodeDetails[7] != "") { bufferNode.LoadValue(nodeDetails[7]); } tree.AddNode(bufferNode); } return(tree); }
public int AddNewRandomNode(int Source, Vector2 position, List <int> IDList, bool Ascend = false) { int ID = IDList.Count; ItemNode Node = (ItemNode)ItemNodeAtlas.GetCorrectNode(IDList[Mathf.RandomInt(0, ID)]); if (!Ascend) { float power = Mathf.Clamp((position.Y / 250) + (Math.Abs(position.X) / 300) + Mathf.Random(-0.35f, 0.35f), 0, 45); int level = 3 + (int)power; int requirement = Mathf.FloorInt(1 + power * 0.75f); Node.Init(this, m_nodeList.Count, level, requirement, position); Node.SetPower(1 + power); if (Source != -1) { Node.AddNeightboor(Source); } m_nodeList.Add(Node); } return(m_nodeList.Count - 1); }
private void GenerateTree() { int NodeGoal = Mathf.CeilInt(Mathf.Pow(m_ItemSource.baseCap / 3f, 0.95) * 1.25f); List <int> IDS = ItemNodeAtlas.GetAvailibleNodeList(m_ItemSource, false); int yPos = 0; //skilltree will allways goes down int minbranche = MINBRANCH; minbranche = Mathf.Clamp(Mathf.FloorInt(MINBRANCH + m_ItemSource.GetCapLevel() * 0.02f), MINBRANCH, MAXBRANCH); int brancheAmm = Mathf.RandomInt(minbranche, MAXBRANCH); List <Branch> Branches = new List <Branch> { new Branch(), new Branch(), new Branch() }; //branches placement : // 3 1 0 2 4 int brancheID = 0; bool emptyLevel = true; int connectionBranch; Vector2 pos; for (int i = 0; i < NodeGoal; i++) { //20% chance to add a new branches if (Mathf.RandomInt(0, 5) >= 4 && Branches.Count < brancheAmm) { Branches.Add(new Branch()); } //Used to init the first node if (i == 0) { Branches[0].Add(AddNewRandomNode(-1, new Vector2(0, 0), IDS, false)); yPos++; emptyLevel = true; } else { //if we reached all branches, then we goes to the layer if (brancheID >= Branches.Count) { emptyLevel = true; brancheID = 0; yPos++; } if (Mathf.RandomInt(0, 5) < 4 || (brancheID == Branches.Count - 1 && emptyLevel)) { emptyLevel = false; connectionBranch = brancheID; if (Branches[brancheID].IsEmpty()) { connectionBranch = Branch.GetRandomNearbyBranches(brancheID, Branches.Count, Branches, true); } else if (Mathf.RandomInt(0, 5) >= 4) { connectionBranch = Branch.GetRandomNearbyBranches(brancheID, Branches.Count, Branches, true); } pos = new Vector2(Branch.GetPosition(brancheID), yPos * 100); int a = HaveNodeAtPos(pos); if (a > 0) { m_nodeList[a].AddNeightboor(Branches[brancheID].GetLastandBefore()); } else { Branches[brancheID].Add(AddNewRandomNode(Branches[connectionBranch].GetLastandBefore(), pos, IDS, false)); } //add neightboor if (Mathf.RandomInt(0, 5) >= 4) { connectionBranch = Branch.GetRandomNearbyBranches(brancheID, Branches.Count, Branches, true); int id = Branches[connectionBranch].GetLastandBefore(); if (!m_nodeList[Branches[brancheID].GetLast()].GetNeighboor.Contains(id)) { m_nodeList[Branches[brancheID].GetLast()].AddNeightboor(id); } } } //Go through all the node one by one brancheID += 1; } } BuildConnection(); m_nodeList[0].UnlockStep(3); }
public void ExtendTree(int Node) { //Init all value to continue building the tree int yPos = GetYPos(); List <int> IDS = ItemNodeAtlas.GetAvailibleNodeList(m_ItemSource); int brancheAmm = Mathf.RandomInt( Mathf.Clamp(GetBranchesCount(), Mathf.RoundInt(MINBRANCH + m_ItemSource.GetCapLevel() * 0.02f), MAXBRANCH) , MAXBRANCH ); List <Branch> Branches = new List <Branch>(); for (int i = 0; i < brancheAmm; i++) { Branches.Add(GetEntireBranch(i)); } bool emptyLevel = false; int brancheID = GetLowestBranch(Branches, yPos); if (brancheID == -1) { brancheID++; emptyLevel = true; } int connectionBranch; Vector2 pos; AnotherRpgMod.Instance.Logger.Info(m_nodeList.Count); for (int i = 0; i < Node; i++) { //20% chance to add a new branches if (Mathf.RandomInt(0, 5) >= 4 && Branches.Count < brancheAmm) { Branches.Add(new Branch()); } //if we reached all branches, then we goes to the layer if (brancheID >= Branches.Count) { emptyLevel = true; brancheID = 0; yPos++; } if (Mathf.RandomInt(0, 5) < 4 || (brancheID == Branches.Count - 1 && emptyLevel)) { emptyLevel = false; connectionBranch = brancheID; if (Branches[brancheID].IsEmpty()) { connectionBranch = Branch.GetRandomNearbyBranches(brancheID, Branches.Count, Branches, true); } else if (Mathf.RandomInt(0, 5) >= 4) { connectionBranch = Branch.GetRandomNearbyBranches(brancheID, Branches.Count, Branches, true); } pos = new Vector2(Branch.GetPosition(brancheID), yPos * 100); int a = HaveNodeAtPos(pos); if (a > 0) { m_nodeList[a].AddNeightboor(Branches[brancheID].GetLastandBefore()); } else { Branches[brancheID].Add(AddNewRandomNode(Branches[connectionBranch].GetLastandBefore(), pos, IDS, false)); } //add neightboor if (Mathf.RandomInt(0, 5) >= 4) { connectionBranch = Branch.GetRandomNearbyBranches(brancheID, Branches.Count, Branches, true); int id = Branches[connectionBranch].GetLastandBefore(); if (!m_nodeList[Branches[brancheID].GetLast()].GetNeighboor.Contains(id)) { m_nodeList[Branches[brancheID].GetLast()].AddNeightboor(id); } } } brancheID += 1; } UpdateConnection(); }
public static ItemSkillTree ConvertToTree(string save, ItemUpdate source, int evoPoint, int AscPoint) { string[] nodeListSave; string[] nodeDetails; ItemSkillTree tree = new ItemSkillTree(); nodeListSave = save.Split(';'); tree.m_ItemSource = source; string[] a; ItemNode bufferNode; foreach (string nodeSave in nodeListSave) { bufferNode = null; nodeDetails = nodeSave.Split('|'); if (nodeDetails.Length != 8) { AnotherRpgMod.Instance.Logger.Error(source.ItemName); AnotherRpgMod.Instance.Logger.Error("Item tree corrupted, reseting tree"); AnotherRpgMod.Instance.Logger.Error(nodeSave); tree = new ItemSkillTree(); tree.MaxEvolutionPoints = evoPoint; tree.MaxAscendPoints = AscPoint; tree.Init(source); tree.Reset(true); tree.EvolutionPoints = tree.MaxEvolutionPoints; tree.AscendPoints = tree.MaxAscendPoints; if (tree.AscendPoints > 0) { tree.ExtendTree(Mathf.Clamp(Mathf.CeilInt(Mathf.Pow(source.baseCap / 3f, 0.95)), 5, 99) * tree.AscendPoints); } return(tree); } bufferNode = (ItemNode)ItemNodeAtlas.GetCorrectNode(int.Parse(nodeDetails[0])); a = nodeDetails[6].Split(':'); bufferNode.Init(tree, tree.GetSize, int.Parse(nodeDetails[4]), int.Parse(nodeDetails[5]), new Vector2(int.Parse(a[0]), int.Parse(a[1]))); //Ignore it if there is no neighboor if (nodeDetails[1] != "") { a = nodeDetails[1].Split(':'); foreach (string neightboor in a) { bufferNode.AddNeightboor(int.Parse(neightboor)); } } bufferNode.ForceLockNode(int.Parse(nodeDetails[2])); bufferNode.SetLevel = int.Parse(nodeDetails[3]); if (nodeDetails[7] != "") { bufferNode.LoadValue(nodeDetails[7]); } tree.AddNode(bufferNode); } return(tree); }