public TreeInfo(K h, char d, char n, bool a = true) { headName = h; onDuplicate = For(d); onNullKey = For(n); asc = a; }
public void SpawnTrees() { if (isServer && treePrefab) { for (int i = 0; i < numberOfTrees; i++) { float x = areaTransform.position.x + imageTargetScale * Random.Range(-areaTransform.localScale.x * 0.5f, areaTransform.localScale.x * 0.5f); float z = areaTransform.position.z + imageTargetScale * Random.Range(-areaTransform.localScale.z * 0.5f, areaTransform.localScale.z * 0.5f); GameObject tree = Instantiate(treePrefab, new Vector3(x, 0, z), Quaternion.identity); TreeBehaviour tb = tree.GetComponent <TreeBehaviour>(); tb.parentNetId = netId; tb.atc = this; team = tb.team; NetworkServer.Spawn(tree); } if (team >= 0) { registerTeamArea(team); } else { Debug.LogError("No team found for area!"); } } }
public static NodeResult TagExecute(SOTree node, object ISOtagNode) { TreeBehaviour source = SOTree.source as TreeBehaviour; if (source == null) { UnityEngine.Debug.LogError("A tagged node under tagged node is not supported, because tagged nodes assign non-TreeBehaviour sources." + "Sources can currently be accessed only by root, not by child AiTargetrs."); } // Execute node n times on every source, with a copy of a node. // Performance: Create copy of the tree only once, then replace that node with reference node to the library which contains 1 subtree for every targeter. AITargeter[] sources = TreeBehaviour.GetAiSourcesByTagUnderRoot(source, ((ISOTagNode)ISOtagNode).tag); if (sources.Length == 0) { UnityEngine.Debug.Log("No sources with tag(" + ((ISOTagNode)ISOtagNode).tag); } for (int i = 0; i < sources.Length; i++) { SOTree.source = sources[i]; //SOTree.DeepCopyTree(node).Execute(); node.Execute(); } SOTree.source = source; return(NodeResult.None); }
public void OnTreePositionFound(object treePlacementObject) { Random random = new Random(135); ThreadsafePlaceable threadsafePlaceable = (ThreadsafePlaceable)treePlacementObject; Vector2 position = _terrainGenerator.GetTerrainChunkPosition(threadsafePlaceable.Position.x, threadsafePlaceable.Position.z); Debug.Log("Tree Position Terrain Chunk: " + position); TerrainChunk terrainChunk = _terrainGenerator.GetTerrainChunk(position); TreeBehaviour treeBehaviour = (TreeBehaviour)threadsafePlaceable.MapPlaceable; treeBehaviour.transform.position = threadsafePlaceable.Position; treeBehaviour.gameObject.name = "Tree: " + threadsafePlaceable.Position; foreach (NeededSpace neededSpace in threadsafePlaceable.NeededSpaces) { ProceduralNeededSpace proceduralNeededSpace = (ProceduralNeededSpace)neededSpace; GameObject prefab = null; if (neededSpace.TerrainType == TerrainGenerator.TerrainType.Coast) { prefab = _coastModel; } else if (neededSpace.TerrainType == TerrainGenerator.TerrainType.Flatland) { prefab = _flatlandModel; } else if (neededSpace.TerrainType == TerrainGenerator.TerrainType.Hill) { prefab = _hillModel; } else if (neededSpace.TerrainType == TerrainGenerator.TerrainType.Mountain) { prefab = _mountainModel; } else { continue; } Vector3 absolutePosition = neededSpace.UsedCoordinate + threadsafePlaceable.Position; Vector2Int pos = new Vector2Int((int)absolutePosition.x, (int)absolutePosition.z); if (terrainChunk.EnvDictionary.ContainsKey(pos)) { continue; } float proceduralScalar = Mathf.Clamp(((proceduralNeededSpace.NoiseValue * 100f) % 10) / 7, 0.8f, 2f); GameObject go = GameObject.Instantiate(prefab, absolutePosition, Quaternion.Euler(0f, proceduralScalar * 360f, 0f), treeBehaviour.transform); // Debug.Log(proceduralNeededSpace.NoiseValue + " _ " + proceduralScalar); for (int i = 0; i < go.transform.childCount; i++) { go.transform.GetChild(i).localScale *= proceduralScalar; } terrainChunk.EnvDictionary.Add(pos, go); } if (!_placementController.PlaceObject(treeBehaviour)) { GameObject.Destroy(treeBehaviour.gameObject); } }
void Start() { treeBehaviour = GetComponent <TreeBehaviour>(); treeBehaviour.trunkSize += Vector3.up * Random.Range(trunkVar.x, trunkVar.y); treeBehaviour.leavesSize += Vector3.up * Random.Range(leavesVar.x, leavesVar.y); treeBehaviour.ApplySizes(); Destroy(treeBehaviour, 0f); Destroy(this, 0f); }
void Start() { m_spriteRenderer = GetComponent <SpriteRenderer>(); m_rigidbody = GetComponent <Rigidbody2D>(); behaviourBoss = GetComponent <TreeBehaviour>(); if (this.healthUI) { this.healthUISystem = this.healthUI.GetComponent <HeartSystem>(); } }
public TreeBehaviour GetRandomTree() { GameObject gameObject = new GameObject("Tree"); TreeBehaviour treeBehaviour = gameObject.AddComponent <TreeBehaviour>(); treeBehaviour.UsedCoordinates = new List <NeededSpace>(); treeBehaviour.UsedCoordinates.Add(new NeededSpace(Vector3Int.zero, TerrainGenerator.TerrainType.Flatland)); treeBehaviour.UsedCoordinates.Add(new NeededSpace(Vector3Int.left, TerrainGenerator.TerrainType.Flatland)); treeBehaviour.UsedCoordinates.Add(new NeededSpace(Vector3Int.right, TerrainGenerator.TerrainType.Flatland)); return(treeBehaviour); }
void RpcDestroyTree(GameObject tree) { TreeBehaviour tb = tree.GetComponent <TreeBehaviour>(); tb.DestroyTree(); if (isLocalPlayer) { score += scorePerTree; } }
public Tree(Node root, int maxSize, TreeBehaviour mode = TreeBehaviour.Cyclic) { MaxSize = maxSize; Nodes.Add(root); Root = root; AddBuffer.Enqueue(root); Model = new TreeModel(this); Mode = mode; }
void CmdDestroyTree(GameObject tree) { if (!isServer) { return; } TreeBehaviour tb = tree.GetComponent <TreeBehaviour>(); RpcDebugTree(tb.team, team); if (tb.team == team) { RpcDestroyTree(tree); } }
public void HarvestFood(TreeBehaviour aTree) { // resNeed:每次想吃appetite数量的粮食live,如果快饱了,则仅吃饱为止,不多吃 var hungry = attrsWriter.Data.MaxFood - attrsWriter.Data.CurrentFood; var resNeed = ScriptableAnimalStats.appetite; if (hungry < ScriptableAnimalStats.appetite) { resNeed = hungry; } var request = new HarvestRequest() { Harvester = _entityId, ResourcesNeed = resNeed }; aTree.Harvest(request, OnHarvestFood); }
public SMTree <K> Add(SCList <Variant> k, long v, out TreeBehaviour tb) { if (k == null) { if (_info.element.onNullKey != TreeBehaviour.Allow) { tb = _info.element.onNullKey; return(this); } k = SCList <Variant> .Empty; } if (Contains(k) && _info.element.onDuplicate != TreeBehaviour.Allow) { tb = _info.element.onDuplicate; return(this); } if (_impl == null) { tb = TreeBehaviour.Allow; return(new SMTree <K>(_info, k, v)); } Variant nv; SITree st = _impl; if (st.Contains(k.element)) { Variant tv = st.Lookup(k.element); switch (tv.variant) { case Variants.Compound: nv = new Variant(Variants.Compound, (SMTree <K>)tv.ob + ((SCList <Variant>)k.next, v)); // care: immutable break; case Variants.Partial: nv = new Variant(Variants.Partial, (SDict <long, bool>)tv.ob + (v, true)); // care: immutable break; default: throw new Exception("internal error"); } st = _impl.Update(k.element, nv) ?? throw new Exception("Impossible"); } else { switch (st.variant) { case Variants.Compound: nv = new Variant(Variants.Compound, new SMTree <K>(_info.next, (SCList <Variant>)k.next, v)); // these are not null); break; case Variants.Partial: nv = new Variant(Variants.Partial, new SDict <long, bool>(v, true)); break; case Variants.Ascending: case Variants.Descending: if (_info.element.onDuplicate == TreeBehaviour.Allow) { goto case Variants.Partial; } nv = new Variant(v); break; default: // assure VS that nv has been assigned! nv = new Variant(0); break; } st = (SITree)(_impl + (k.element, nv)); } tb = TreeBehaviour.Allow; return(new SMTree <K>(_info, st, (Length ?? 0) + 1)); }
private bool LookforFood() { if (stateMachine.CurrentState == DinoAiFSMState.StateEnum.LOOK_FOR_FOOD) { return(true); } _curFood = attrsWriter.Data.CurrentFood; if (_curFood / attrsWriter.Data.MaxFood >= ScriptableAnimalStats.HungryRate) { // 不饿 return(false); } if (ScriptableAnimalStats.vegetarian) // 素食主义者,吃树 { List <TreeBehaviour> treeList = new List <TreeBehaviour>(); foreach (var iter in TreeBehaviour.AllTrees) { var tree = iter.Value; float dist = Vector3.Distance(transform.position, tree.transform.position); if (dist > ScriptableAnimalStats.scent) { continue; } if (!tree.IsHavestable()) { continue; } treeList.Add(tree); } // 收集范围内的所有目标,随机找一个作为最终目标 TreeBehaviour aTree = null; if (treeList.Count > 0) { int rand = Random.Range(0, treeList.Count); aTree = treeList[rand]; } if (aTree != null) { var targetPosition = aTree.transform.position; if (aTree._entityId.Id == 0) { Debug.LogError("Look For Food EntityId is ZERO!!!"); } stateMachine.TriggerTransition(DinoAiFSMState.StateEnum.LOOK_FOR_FOOD, aTree._entityId, targetPosition); return(true); } } else // 肉食主义者,吃尸体 { List <DinoBehaviour> corpseList = new List <DinoBehaviour>(); foreach (var iter in allAnimals) { var animal = iter.Value; if (!(animal.Dead && !animal.IsVanish)) { continue; } float dist = Vector3.Distance(transform.position, animal.transform.position); if (dist > ScriptableAnimalStats.scent) { continue; } corpseList.Add(animal); } // 收集范围内的所有目标,随机找一个作为最终目标 DinoBehaviour corpse = null; if (corpseList.Count > 0) { int rand = Random.Range(0, corpseList.Count); corpse = corpseList[rand]; } if (corpse != null) { var targetPosition = corpse.transform.position; if (!corpse.Dead) { Debug.LogError("DinoBehaviour - Cannot eat live animals!"); } stateMachine.TriggerTransition(DinoAiFSMState.StateEnum.LOOK_FOR_FOOD, corpse._entityId, targetPosition); return(true); } } return(false); }