public TechNodeViewModel() { Width = 40; Height = 40; TechNode = new TechNode(); }
public string Execute(TechNode node, [CurrentCharacterIfNull] ICharacter player = null) { var technologies = player.SharedGetTechnologies(); technologies.ServerAddNode(node); return($"{player} tech node {node.Name} added."); }
public void AddNode(TechNode node) { Nodes.Add(node); if (Nodes.Count >= TechCount) foreach (TechNode tnode in Nodes) tnode.InitializeNode(); }
public ViewModelTechRequiredItemsControl( IReadOnlyList <IProtoItem> requiredProtoItems, [CanBeNull] TechNode techNode) { var count = requiredProtoItems.Count; this.Visibility = count > 0 ? Visibility.Visible : Visibility.Collapsed; if (count == 0) { return; } var array = new DataEntryRequiredItemProto[count]; for (var index = 0; index < count; index++) { var protoItem = requiredProtoItems[index]; array[index] = new DataEntryRequiredItemProto(protoItem, techNode, hasNextEntry: index < count - 1); } this.RequiredProtoItems = array; }
//randomly chose a node as parent node private TechNode RandomChoseOneParentNodeFromList(List <TechNode> techNodeList) { int i = 0; if (techNodeList.Count == 0) { return(null); } if (techNodeList.Count > 1) { i = Random.Range(0, techNodeList.Count); if (techNodeList [i] != null) { TechNode node = techNodeList[i]; techNodeList.RemoveAt(i); return(node); } else { return(null); } } else { return(techNodeList[0]); } }
private void ServerAddNodeNoCheckGroup(TechNode techNode) { if (!techNode.IsAvailable) { return; } if (this.Nodes.Contains(techNode)) { return; } this.Nodes.Add(techNode); var character = this.Character; Api.Logger.Info("Tech node added: " + techNode.ShortId, character); Api.SafeInvoke(() => CharacterTechNodeAddedOrRemoved?.Invoke(character, techNode, isAdded: true)); // add all required nodes recursively var currentNode = techNode; do { this.ServerAddNodeNoCheckGroup(currentNode); currentNode = currentNode.RequiredNode; }while (currentNode != null); character.SharedSetFinalStatsCacheDirty(); }
private void ComputeNodesByDepth() { m_nodes = m_rootNode.tree; List <TechNode> fix = new List <TechNode>(m_nodes); fix.Add(m_rootNode); m_nodes = fix.ToArray(); m_nodesByDepth = new TechNode[m_rootNode.depth + 1][]; List <TechNode>[] resultList = new List <TechNode> [m_nodesByDepth.Length]; for (int i = 0; i < resultList.Length; i++) { resultList[i] = new List <TechNode>(); } for (int i = 0; i < m_nodes.Length; i++) { int nodeDepth = m_nodes[i].depth; resultList[nodeDepth].Add(m_nodes[i]); } for (int i = 0; i < resultList.Length; i++) { m_nodesByDepth[i] = resultList[i].ToArray(); } TechNode[] tmp = new TechNode[1]; tmp[0] = m_rootNode; m_nodesByDepth[m_nodesByDepth.Length - 1] = tmp; }
public static void ServerUnlockNode(ICharacter character, TechNode techNode) { techNode.SharedValidateCanUnlock(character); var technologies = character.SharedGetTechnologies(); technologies.ServerRemoveLearningPoints(techNode.LearningPointsPrice); technologies.ServerAddNode(techNode); }
public DataEntryRequiredItemProto( IProtoItem protoItem, [CanBeNull] TechNode techNode, bool hasNextEntry) { this.protoItem = protoItem; this.techNode = techNode; this.hasNextEntry = hasNextEntry; }
public void PrepareProtoSetLinkWithTechNode(TechNode techNode) { if (this.listedInTechNodes == null) { this.listedInTechNodes = new List <TechNode>(); } this.listedInTechNodes.AddIfNotContains(techNode); }
public void ServerAddNode(TechNode techNode) { if (!this.Groups.Contains(techNode.Group)) { throw new Exception("Cannot add node - the group is locked"); } this.ServerAddNodeNoCheckGroup(techNode); }
private void Awake() { m_previousNode = transform.parent.GetComponent <TechNode>(); m_root = GetComponentInParent <TechTree>(); m_material = GetComponent <Renderer>().material; if (m_previousNode == null) { InitDepth(); } }
private void CharacterTechNodeAddedOrRemovedHandler(ICharacter character, TechNode techNode, bool isAdded) { if (techNode != this.TechNode) { return; } var context = this.GetActiveContext(character, out _); context?.Refresh(); }
public void AddNode(TechNode node) { Nodes.Add(node); if (Nodes.Count >= TechCount) { foreach (TechNode tnode in Nodes) { tnode.InitializeNode(); } } }
public static void ClientUnlockNode(TechNode techNode) { if (!techNode.SharedCanUnlock(Client.Characters.CurrentPlayerCharacter, out var error)) { NotificationSystem.ClientShowNotification(NotificationCannotUnlockTech, error, NotificationColor.Bad); return; } Instance.CallServer(_ => _.ServerRemote_UnlockNode(techNode)); }
void Start(){ node = new TechNode (); //get the tower01 button UIEventListener.Get (tower01.gameObject).onClick += OnCreateTower01; UIEventListener.Get (stop.gameObject).onClick += OnStop; UIEventListener.Get (start.gameObject).onClick += OnStart; UIEventListener.Get (techTree.gameObject).onClick += OnShowTechTree; UIEventListener.Get (closeBtn.gameObject).onClick += OnHideTechTree; UIEventListener.Get (wiki.gameObject).onClick += OnShowWiki; Time.timeScale = 0; }
public TechNodeViewModel AddNode(Point pos) { var node = new TechNode(GenerateNodeName()) { Pos = pos }; var nodeViewModel = new TechNodeViewModel { TechNode = node }; TechTree.Add(nodeViewModel); return(nodeViewModel); }
/// <summary> /// Remove node and all dependent nodes. /// </summary> public void ServerRemoveNode(TechNode techNode) { if (!this.Nodes.Remove(techNode)) { return; } Api.SafeInvoke(() => CharacterTechNodeAddedOrRemoved?.Invoke(this.Character, techNode, isAdded: false)); // remove all the dependent nodes foreach (var dependentNode in techNode.DependentNodes) { this.ServerRemoveNode(dependentNode); } }
public ViewModelTechNode( TechNode techNode, ViewModelTechTreeControl viewModelTechTree, BaseCommand commandOnNodeSelect) { this.viewModelTechTree = viewModelTechTree; this.CommandOnNodeSelect = commandOnNodeSelect; this.TechNode = techNode; this.HierarchyLevel = techNode.HierarchyLevel; ClientComponentTechnologiesWatcher.TechNodesChanged += this.TechNodesOrLearningPointsChanged; ClientComponentTechnologiesWatcher.LearningPointsChanged += this.TechNodesOrLearningPointsChanged; this.RefreshIsUnlocked(); }
public void DrawLine(TechNode from, TechNode to, float width) { Vector3 diff = to.transform.position - from.transform.position; Image new_line = Instantiate(LinePrefab); new_line.rectTransform.SetParent(from.transform.parent); new_line.rectTransform.SetAsFirstSibling(); new_line.rectTransform.sizeDelta = new Vector2(diff.magnitude, width); new_line.rectTransform.pivot = new Vector2(0.0f, 0.5f); new_line.rectTransform.position = from.transform.position; float angle = Mathf.Atan2(diff.y, diff.x) * Mathf.Rad2Deg; new_line.transform.rotation = Quaternion.Euler(0, 0, angle); new_line.name = string.Format("{0}to{1}", from.NodeCode, to.NodeCode); }
void Start(){ node = new TechNode (); //get the tower01 button UIEventListener.Get (tower01.gameObject).onClick += OnCreateTower01; UIEventListener.Get (stop.gameObject).onClick += OnStop; UIEventListener.Get (start.gameObject).onClick += OnStart; UIEventListener.Get (techTree.gameObject).onClick += OnShowTechTree; UIEventListener.Get (techTree2.gameObject).onClick += OnShowTechTree2; UIEventListener.Get (techTree3.gameObject).onClick += OnShowTechTree3; UIEventListener.Get (closeBtn.gameObject).onClick += OnHideTechTree; UIEventListener.Get (closeBtn2.gameObject).onClick += OnHideTechTree2; UIEventListener.Get (closeBtn3.gameObject).onClick += OnHideTechTree3; UIEventListener.Get (wiki.gameObject).onClick += OnShowWiki; UIEventListener.Get (closewiki.gameObject).onClick += OnHideWiki; Time.timeScale = 0; //EnemySpawnManager._instance.isContinue = false; }
//chose the first node as the parent node private TechNode ChoseFirstOneParentFromList(List <TechNode> techNodeList) { if (techNodeList.Count > 1) { TechNode node = techNodeList [0]; techNodeList.RemoveAt(0); return(node); } else if (techNodeList.Count == 1) { return(techNodeList[0]); } else { Debug.Log("Not enough node in parent list"); return(null); } }
void Start() { node = new TechNode(); //get the tower01 button UIEventListener.Get(tower01.gameObject).onClick += OnCreateTower01; UIEventListener.Get(stop.gameObject).onClick += OnStop; UIEventListener.Get(start.gameObject).onClick += OnStart; UIEventListener.Get(techTree.gameObject).onClick += OnShowTechTree; UIEventListener.Get(techTree2.gameObject).onClick += OnShowTechTree2; UIEventListener.Get(techTree3.gameObject).onClick += OnShowTechTree3; UIEventListener.Get(closeBtn.gameObject).onClick += OnHideTechTree; UIEventListener.Get(closeBtn2.gameObject).onClick += OnHideTechTree2; UIEventListener.Get(closeBtn3.gameObject).onClick += OnHideTechTree3; UIEventListener.Get(wiki.gameObject).onClick += OnShowWiki; UIEventListener.Get(closewiki.gameObject).onClick += OnHideWiki; Time.timeScale = 0; //EnemySpawnManager._instance.isContinue = false; }
public void PrepareProtoSetLinkWithTechNode(TechNode techNode) { if (this.listedInTechNodes == null) { if (this.IsAutoUnlocked) { Logger.Error( this + " is marked as " + nameof(this.IsAutoUnlocked) + " but the technology is set as the prerequisite: " + techNode); } this.listedInTechNodes = new List <TechNode>(); } this.listedInTechNodes.AddIfNotContains(techNode); }
private void InitDepth() { List <TechNode> children = new List <TechNode>(); foreach (Transform child in transform) { TechNode node = child.GetComponent <TechNode>(); if (node) { node.InitDepth(); children.Add(node); } } m_children = children.ToArray(); m_depth = 0; for (int i = 0; i < m_children.Length; i++) { m_depth = Mathf.Max(m_depth, m_children[i].depth + 1); } }
public TechNodeViewModel([NotNull] TechNode techNode) : base(techNode) { Description = techNode.Description; }
// Use this for initialization void Start() { cManager = new CharacterManager(); node = new TechNode(); }
public override TechNode PopulateFromSource(KerbalNode sourceNode) { TechNode newNode = new TechNode(); var v = sourceNode.Values; newNode.NodePart = v.ContainsKey("nodeName") ? v["nodeName"].First() : ""; double x; double y; newNode.Id = v.ContainsKey("id") ? v["id"].First() : ""; if (v.ContainsKey("pos")) { var posString = v["pos"].First(); var coordinates = posString.Split(','); if (coordinates.Length >= 2) { if (!Double.TryParse(coordinates[0], out x)) { x = 0; } if (!Double.TryParse(coordinates[1], out y)) { y = 0; } newNode.Pos = new Point(x, y); decimal z; if (!Decimal.TryParse(coordinates[2], out z)) { newNode.Zlayer = -1; } newNode.Zlayer = (int)z; } } if (v.ContainsKey("icon")) { newNode.Icon = v["icon"].First(); } if (v.ContainsKey("scale")) { var s = v["scale"].First(); newNode.Scale = Double.Parse(s); } newNode.Title = v.ContainsKey("title") ? v["title"].First() : ""; newNode.Description = v.ContainsKey("description") ? v["description"].First() : ""; newNode.AnyToUnlock = false; newNode.HideEmpty = false; newNode.HideIfNoBranchParts = false; if (v.ContainsKey("cost")) { int c; if (!Int32.TryParse(v["cost"].First(), out c)) { newNode.Cost = 0; } newNode.Cost = c; } if (v.ContainsKey("anyToUnlock")) { switch (v["anyToUnlock"].First().Trim().ToLower()) { case "true": newNode.AnyToUnlock = true; break; } } if (v.ContainsKey("hideEmpty")) { switch (v["hideEmpty"].First().Trim().ToLower()) { case "true": newNode.HideEmpty = true; break; } } if (v.ContainsKey("hideIfNoBranchParts")) { switch (v["hideIfNoBranchParts"].First().Trim().ToLower()) { case "true": newNode.HideIfNoBranchParts = true; break; } } // Create an empty parents collection, populated during linking newNode.Parents = new List <TechNode>(); newNode.Parts = new List <string>(); return(newNode); }
void Awake(){ _instance = this; node = new TechNode (); }
public bool SharedIsNodeUnlocked(TechNode techNode) { return(this.Nodes.Contains(techNode)); }
private RequirementHaveTechNode(TechNode techNode) : base(description: null) { this.TechNode = techNode; }
public override TechNode PopulateFromSource(KerbalNode sourceNode) { TechNode newNode = new TechNode(); var v = sourceNode.Values; newNode.NodePart = v.ContainsKey("nodepart") ? v["nodepart"].First() : ""; double x; double y; newNode.Id = v.ContainsKey("id") ? v["id"].First() : ""; if (v.ContainsKey("pos")) { var posString = v["pos"].First(); var coordinates = posString.Split(','); if (coordinates.Length >= 2) { if (!Double.TryParse(coordinates[0], out x)) { x = 0; } if (!Double.TryParse(coordinates[1], out y)) { y = 0; } newNode.Pos = new Point(x, y); decimal z; if (!Decimal.TryParse(coordinates[2], out z)) { newNode.Zlayer = -1; } newNode.Zlayer = (int)z; } } if (v.ContainsKey("icon")) { String iconString = v["icon"].First(); int id = Array.FindIndex(IconStringConverter.IconString, row => row == iconString); if (id != -1) { newNode.Icon = (IconsEnum)id; } else { newNode.Icon = IconsEnum.RDicon_generic; } } if (v.ContainsKey("scale")) { var s = v["scale"].First(); newNode.Scale = Double.Parse(s); } newNode.Title = v.ContainsKey("title") ? v["title"].First() : ""; newNode.Description = v.ContainsKey("description") ? v["description"].First() : ""; newNode.AnyToUnlock = false; newNode.HideEmpty = false; newNode.HideIfNoBranchParts = false; if (v.ContainsKey("cost")) { int c; if (!Int32.TryParse(v["cost"].First(), out c)) { newNode.Cost = 0; } newNode.Cost = c; } if (v.ContainsKey("anyParent")) { switch (v["anyParent"].First().Trim().ToLower()) { case "true": newNode.AnyToUnlock = true; break; } } if (v.ContainsKey("hideEmpty")) { switch (v["hideEmpty"].First().Trim().ToLower()) { case "true": newNode.HideEmpty = true; break; } } if (v.ContainsKey("hideIfNoBranchParts")) { switch (v["hideIfNoBranchParts"].First().Trim().ToLower()) { case "true": newNode.HideIfNoBranchParts = true; break; } } // Create an empty parents collection, populated during linking newNode.Parents = new List <TechNode>(); var tmpParts = new List <string>(); foreach (var child in sourceNode.Children.Where(child => child.Name == "Unlocks").Where(child => child.Values.ContainsKey("part"))) { tmpParts.AddRange(child.Values["part"]); } newNode.Parts = new List <string>(tmpParts); return(newNode); }
void Start(){ node = new TechNode (); }
private TaskHaveTechNode(TechNode techNode) : base(description: null) { this.TechNode = techNode; }
// Use this for initialization void Start () { node = new TechNode (); cManager = new CharacterManager (); gManager = new GameManager (); //add the diamond resource to the game manager. Vector3 obstaclePos = new Vector3 (17.15f, 1.0f, 23.8f); DiamondResource diamond = (DiamondResource)cManager.SpawnCharacter (CharacterData.CharacterClassType.BUILDING, (int)CharacterData.buildingMode.DIAMOND, 1, 1, obstaclePos, new Vector3 (0, 0, 0), CharacterStatus.Pose.Idle); diamond.SetPosition (obstaclePos); gManager.diamondList.Add (diamond); //tower2 Vector3 obstacle1Pos = new Vector3 (21.15f, 1.0f, 17.8f); diamond = (DiamondResource)cManager.SpawnCharacter (CharacterData.CharacterClassType.BUILDING, (int)CharacterData.buildingMode.DIAMOND, 1, 1, obstacle1Pos, new Vector3 (0, 0, 0), CharacterStatus.Pose.Idle); diamond.SetPosition (obstacle1Pos); gManager.diamondList.Add (diamond); //tower3 Vector3 obstacle2Pos = new Vector3 (15.15f, 1.0f, 17.3f); diamond = (DiamondResource)cManager.SpawnCharacter(CharacterData.CharacterClassType.BUILDING, (int)CharacterData.buildingMode.DIAMOND, 1, 1, obstacle2Pos, new Vector3 (0, 0, 0), CharacterStatus.Pose.Idle); diamond.SetPosition (obstacle2Pos); gManager.diamondList.Add (diamond); }
// Use this for initialization void Start () { cManager = new CharacterManager (); node = new TechNode (); }
private void ServerCharacterTechNodeAddedOrRemovedHandler(ICharacter character, TechNode techNode, bool isAdded) { if (!ReferenceEquals(techNode.Group, this.TechGroup)) { return; } var context = this.GetActiveContext(character, out _); context?.Refresh(); }