Exemplo n.º 1
0
 public void Update()
 {
     if (Status != TreeStatus.Dead && Status == TreeStatus.Live)
     {
         Status = TreeStatus.Burned;
     }
 }
Exemplo n.º 2
0
    // void SetNewTarget()
    // {
    //     float shortestDistance = Mathf.Infinity;
    //     Transform potentialTarget;
    //     print($"Number of treeSockets: {treeSockets.Length}");
    //     foreach (GameObject treeSocket in treeSockets)
    //     {
    //         print($"Treesocket: {treeSocket}");
    //         TreeStatus treeStatus = treeSocket.transform.GetComponentInChildren<TreeStatus>();
    //         if (treeStatus == null)
    //             continue;
    //         navMeshAgent.SetDestination(treeSocket.transform.position);
    //         shortestDistance = Math.Min(navMeshAgent.remainingDistance, shortestDistance);
    //         print($"Distance: {shortestDistance}");
    //     }
    // }

    private void OnCollisionEnter(Collision other)
    {
        // if not dead tree, keep going
        if (!other.transform.CompareTag("TreeEncapsulator"))
        {
            return;
        }

        attackingTarget = other.transform.parent.GetComponentInChildren <TreeStatus>();
        if (attackingTarget == null)
        {
            return;
        }
        TreeSocketIndex treeSocketIndex = other.transform.GetComponentInParent <TreeSocketIndex>();

        if (treeSocketIndex == null)
        {
            Debug.LogError("no index found");
            return;
        }

        if (treeSocketIndex.socketIndex == targetTreeSocketIndex)
        {
            currentTreeSocketIndex        = targetTreeSocketIndex;
            navMeshAgent.isStopped        = true;
            attackingTarget.AttackWeight += enemyWeight;
            StartCoroutine(Attack());
        }
    }
Exemplo n.º 3
0
        public void DownHealth()
        {
            if (Healthness == 0)
            {
                Status = TreeStatus.Dead;
            }

            else if (Status == TreeStatus.Burned)
            {
                Healthness--;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// The tree is canceled.
        /// </summary>
        public void Cencel()
        {
            Root = null;

            foreach (var level in Levels)
            {
                level.Clear();
            }

            Levels.Clear();

            Status = TreeStatus.Cencel;
        }
Exemplo n.º 5
0
    void SetNewTarget()
    {
        // if not yet, initialised return.
        if (enemySpawner == null || enemySpawner.treeSockets == null)
        {
            return;
        }
        Dictionary <int, GameObject> ordinalTreeDistanceDict = new Dictionary <int, GameObject>();
        int lowestIndex = Int32.MaxValue;

        // print($"Number of treeSockets: {treeSockets.Length}");
        foreach (GameObject treeSocket in enemySpawner.treeSockets)
        {
            //print($"Treesocket: {treeSocket}");
            TreeStatus treeStatus = treeSocket.transform.GetComponentInChildren <TreeStatus>();
            if (treeStatus == null)
            {
                continue;
            }

            int index = treeSocket.GetComponent <TreeSocketIndex>().socketIndex;

            // if (index <= currentTreeSocketIndex)
            //     continue;

            ordinalTreeDistanceDict.Add(index, treeSocket);
            // print($"Adding {treeSocket} {index}");
            // print(index + " " + lowestIndex);
            lowestIndex = Mathf.Min(index, lowestIndex);
        }

        if (lowestIndex == Int32.MaxValue)
        {
            Debug.LogWarning("No new target found");
            inPersuit = false;
        }
        else
        {
            targetTreeSocketIndex = lowestIndex;
            // print("setting new destination" + lowestIndex);
            navMeshAgent.SetDestination(ordinalTreeDistanceDict[lowestIndex].transform.position);
            peekIndex = lowestIndex;
            inPersuit = true;
            navMeshAgent.isStopped = false;
        }
    }
    private void AssignTree(GameObject treePrefab)
    {
        GameObject spawnedTree = Instantiate(treePrefab, currentDeadTree.transform);

        if (spawnedTree == null)
        {
            Debug.LogError("Tree failed to spawn");
        }
        spawnedTree.transform.SetParent(currentDeadTree.transform.parent);
        TreeStatus treeStatus = spawnedTree.GetComponent <TreeStatus>();

        if (treeStatus == null)
        {
            Debug.LogError("No treeStatus found");
        }
        treeStatus.deadTree         = currentDeadTree;
        treeStatus.treeEncapsulator = currentTreeEncapsulator;
    }
Exemplo n.º 7
0
 public bool Add(Node currentNode, UTF8DecodeContext context, TreeStatus t)
 {
     if (t == TreeStatus.Valid)
     {
         currentNode.center = new Node();
         currentNode.center.value = context;
         currentNode.left = null;
         currentNode.right = null;
     }
     else if (t == TreeStatus.InvalidByte)
     {
         currentNode.right = new Node();
         currentNode.right.value = context;
     }
     else if (t == TreeStatus.InvalidSequence)
     {
         currentNode.left = new Node();
         currentNode.left.value = context;
     }
     return true;
 }
Exemplo n.º 8
0
 public bool Add(Node currentNode, UTF8DecodeContext context, TreeStatus t)
 {
     if (t == TreeStatus.Valid)
     {
         currentNode.center       = new Node();
         currentNode.center.value = context;
         currentNode.left         = null;
         currentNode.right        = null;
     }
     else if (t == TreeStatus.InvalidByte)
     {
         currentNode.right       = new Node();
         currentNode.right.value = context;
     }
     else if (t == TreeStatus.InvalidSequence)
     {
         currentNode.left       = new Node();
         currentNode.left.value = context;
     }
     return(true);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Tree built.
 /// </summary>
 public void Built()
 {
     Status = TreeStatus.Built;
 }
Exemplo n.º 10
0
        public void Update(GameTime gameTime)
        {
            switch (status)
            {
                case TreeStatus.SEED:
                    fallSpeed += 25f * (float)gameTime.ElapsedGameTime.TotalSeconds;
                    position.Y -= (float)(gameTime.ElapsedGameTime.TotalSeconds) * fallSpeed;
                    this.glowRange = 0.8f + 0.2f * (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds * 0.35);
                    if (position.Y < groundHeight)
                    {
                        status = TreeStatus.PLANTED;
                        position.Y = groundHeight;
                    }
                    break;
                case TreeStatus.PLANTED:
                    this.glowStrength = 0.4f + 0.15f * (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds * 0.5);
                    this.glowRange = 1f + 0.2f * (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds * 0.35);
                    growth += (gameTime.ElapsedGameTime.Milliseconds / 1000.0f) / growthTime;
                    if (growth > 1.0f)
                    {
                        status = TreeStatus.MATURE;
                        growth = 1.0f;
                        nextSeedPosition = GetNextSeedPosition();
                    }
                    break;
                case TreeStatus.MATURE:
                    this.glowStrength = 0.4f + 0.15f * (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds * 0.5);
                    this.glowRange = 1f + 0.2f * (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds * 0.35);
                    // grow fruit
                    currentFruitTime += gameTime.ElapsedGameTime.TotalSeconds;
                    if (currentFruitTime > fruitTime)
                    {
                        parentCollection.game.seedCollection.SpawnSeed(nextSeedPosition);
                        nextSeedPosition = GetNextSeedPosition();
                        currentFruitTime = 0;
                    }
                    // decrease life span of tree
                    if (treeType != TreeType.BASE)
                    {
                        lifeSpan -= gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
                        if (lifeSpan < 0.0f)
                            status = TreeStatus.DIED;
                    }
                    break;
                case TreeStatus.DIED:

                    glowStrength -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                    glowStrength = Math.Max(glowStrength, 0);
                    lifeSpan -= gameTime.ElapsedGameTime.Milliseconds / 1000.0f;
                    if (lifeSpan < -3.0f)
                        status = TreeStatus.KILLED;
                    break;
                case TreeStatus.KILLED:
                    glowStrength -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                    glowStrength = Math.Max(glowStrength, 0);

                    growth -= (gameTime.ElapsedGameTime.Milliseconds / 1000.0f) / growthTime;
                    if (growth < 0.0f)
                    {
                        RemoveOnNextUpdate = true;
                        growth = 0.0f;
                    }
                    break;
                case TreeStatus.BLUEPRINT:
                    growth = 1.0f;
                    break;
            }
        }
Exemplo n.º 11
0
        public Tree(TreeCollection coll, Vector3 pos, TreeType type, bool isBlueprint, String preferredName)
        {
            position = pos;
            treeType = type;
            parentCollection = coll;
            fruitSize = new Vector2(parentCollection.fruitTexture.Width, parentCollection.fruitTexture.Height);
            texture = parentCollection.textures[(int)treeType];
            if (treeType != TreeType.BASE)
            {
                deadTexture = parentCollection.textures[(int)treeType + 4];
                xrayTexture = parentCollection.textures[(int)treeType + 8];
            }
            else
            {
                deadTexture = xrayTexture = texture;
            }

            screenSize = new Vector2(texture.Width, texture.Height);
            if (preferredName == "")
                name = names[random.Next(names.Length - 1)];
            else
                name = preferredName;

            if (treeType == TreeType.BASE)
            {
                offset = new Vector2(-0.5f * screenSize.X - 20, -screenSize.Y + 210.0f);
            }
            else
            {
                offset = new Vector2(-0.5f * screenSize.X, -screenSize.Y + 64.0f);
            }
            growth = 0.1f;
            status = TreeStatus.SEED;
            groundHeight = parentCollection.game.world.getHeigth(position.X);

            if (isBlueprint)
            {
                status = TreeStatus.BLUEPRINT;
                position.Y = groundHeight;
            }

            switch (treeType)
            {
                case TreeType.BASE:
                    position.Y = groundHeight;
                    status = TreeStatus.MATURE;
                    growth = 1.0f;
                    fruitTime = 15.0f;
                    resistance = 1.0f;
                    lifeSpan = 0.0f;
                    price = 0;
                    descriptionLines[0] = "The Tree of Light";
                    descriptionLines[1] = "Protect it at any cost.";
                    break;
                case TreeType.FIGHTER:
                    growthTime = 8.0f;
                    fruitTime = 20.0f;
                    resistance = 0.4f;
                    lifeSpan = 60.0f;
                    price = 3;
                    descriptionLines[0] = "Soldier Tree";
                    descriptionLines[1] = "Light but defensive tree.";
                    break;
                case TreeType.MOTHER:
                    growthTime = 15.0f;
                    fruitTime = 5.0f;
                    resistance = 0.6f;
                    lifeSpan = 80.0f;
                    price = 8;
                    descriptionLines[0] = "Producer Tree";
                    descriptionLines[1] = "Spawns many Souls.";
                    break;
                case TreeType.PAWN:
                    growthTime = 5.0f;
                    fruitTime = 7.0f;
                    resistance = 0.6f;
                    lifeSpan = 25.0f;
                    price = 2;
                    descriptionLines[0] = "Common Tree";
                    descriptionLines[1] = "Cheap jack of all trades.";
                    break;
                case TreeType.TANK:
                    growthTime = 25.0f;
                    fruitTime = 25.0f;
                    resistance = 0.3f;
                    lifeSpan = 130.0f;
                    price = 10;
                    descriptionLines[0] = "Defender Tree";
                    descriptionLines[1] = "Slow-growing heavy defender.";
                    break;
            }

            descriptionLines[2] = "Price: " + price.ToString() + " souls";

            // create first seed position
            if (!isBlueprint && status == TreeStatus.MATURE)
            {
                nextSeedPosition = GetNextSeedPosition();
            }
        }
Exemplo n.º 12
0
 public Tree()
 {
     Healthness = 2;
     Status     = TreeStatus.Live;
 }