示例#1
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        // Gets reference to the original turret (before the upgrade)
        BaseTurret originalTurret = null;

        if (buildingSlot != null)
        {
            if (buildingSlot.GetBuildingOnSlot() != null)
            {
                originalTurret = buildingSlot.GetBuildingOnSlot().GetComponent <BaseTurret>();
            }
        }

        // Remove old healthbar (if valid)
        float hitpoints = MaxHitPoints;

        if (originalTurret != null)
        {
            hitpoints = originalTurret.GetHitPoints();
            if (originalTurret._HealthBar != null)
            {
                ObjectPooling.Despawn(originalTurret._HealthBar.gameObject);
            }
        }

        // Create weapon
        if (_TowerWeapon != null)
        {
            _TowerWeapon = ObjectPooling.Spawn(_TowerWeapon.gameObject).GetComponent <Weapon>();
        }

        // Start building process
        base.OnWheelSelect(buildingSlot);
        if (_ClonedWorldObject != null)
        {
            // Only proceed if there was a previous building & we're upgrading from that
            if (originalTurret != null)
            {
                // Update player ref
                _ClonedWorldObject.SetPlayer(originalTurret._Player);

                // Set the new base's building state object to be the currently active object
                _ClonedWorldObject.BuildingState = originalTurret.gameObject;
            }

            // Update attached building slot turret reference
            if (buildingSlot != null)
            {
                buildingSlot.SetBuildingOnSlot(_ClonedWorldObject.GetComponent <BaseTurret>());
            }

            // Reset turret's health
            _ClonedWorldObject.SetHitPoints(_ClonedWorldObject.MaxHitPoints);
        }
    }
示例#2
0
    //******************************************************************************************************************************
    //
    //      FUNCTIONS
    //
    //******************************************************************************************************************************

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        // Gets reference to the original generator (before the upgrade)
        Generator originalGenerator = null;

        if (buildingSlot != null)
        {
            if (buildingSlot.GetBuildingOnSlot() != null)
            {
                originalGenerator = buildingSlot.GetBuildingOnSlot().GetComponent <Generator>();
            }
        }

        // Remove old healthbar (if valid)
        float hitpoints = MaxHitPoints;

        if (originalGenerator != null)
        {
            hitpoints = originalGenerator.GetHitPoints();
            if (originalGenerator._HealthBar != null)
            {
                ObjectPooling.Despawn(originalGenerator._HealthBar.gameObject);
            }
        }

        // Start building process
        base.OnWheelSelect(buildingSlot);
        if (_ClonedWorldObject != null)
        {
            // Only proceed if there was a previous building and we are upgrading from that
            if (originalGenerator != null)
            {
                // Update player ref
                _ClonedWorldObject.SetPlayer(originalGenerator._Player);

                // Set the new bases building state object to be the currently active object
                _ClonedWorldObject.BuildingState = originalGenerator.gameObject;
            }

            // Update attached buildingSlot generator reference
            if (buildingSlot != null)
            {
                buildingSlot.SetBuildingOnSlot(_ClonedWorldObject.GetComponent <Generator>());
            }

            // Reset building's health
            _ClonedWorldObject.SetHitPoints(_ClonedWorldObject.MaxHitPoints);
        }
    }
示例#3
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Destroys the building & returns some resources back to the player who owns the building.
    /// </summary>
    public void RecycleBuilding()
    {
        // Deselect all objects
        foreach (var selectable in GameManager.Instance.Selectables)
        {
            selectable.SetIsSelected(false);
        }

        // Add resources back to player
        if (_Player != null)
        {
            _Player.SuppliesCount += GetRecycleSuppliesAmount();
            _Player.PowerCount    += GetRecyclePowerAmount();
        }

        // Destroy building
        if (_RecycleOption)
        {
            // Deselect self
            SetIsSelected(false);

            // Destroy Widgets
            if (AttachedBuildingSlot.GetBuildingOnSlot()._HealthBar)
            {
                ObjectPooling.Despawn(AttachedBuildingSlot.GetBuildingOnSlot()._HealthBar.gameObject);
            }
            if (AttachedBuildingSlot.GetBuildingOnSlot()._BuildingProgressCounter)
            {
                ObjectPooling.Despawn(AttachedBuildingSlot.GetBuildingOnSlot()._BuildingProgressCounter.gameObject);
            }

            // Remove from queues/lists
            // Bases
            if (AttachedBuildingSlot.AttachedBase != null)
            {
                AttachedBuildingSlot.AttachedBase.RemoveFromQueue(AttachedBuildingSlot.GetBuildingOnSlot());
                AttachedBuildingSlot.AttachedBase.RemoveFromList(AttachedBuildingSlot.GetBuildingOnSlot());

                if (UI_BuildingQueueWrapper.Instance.ContainsQueue(_BuildingQueueUI))
                {
                    UI_BuildingQueueWrapper.Instance.RemoveFromQueue(_BuildingQueueUI);
                    Destroy(_BuildingQueueUI);
                }
            }
            // Buildings
            if (AttachedBuildingSlot.AttachedBuilding != null && AttachedBuildingSlot.AttachedBase == null)
            {
                AttachedBuildingSlot.AttachedBuilding.RemoveFromQueue(AttachedBuildingSlot.GetBuildingOnSlot());

                if (UI_BuildingQueueWrapper.Instance.ContainsQueue(_BuildingQueueUI))
                {
                    UI_BuildingQueueWrapper.Instance.RemoveFromQueue(_BuildingQueueUI);
                    Destroy(_BuildingQueueUI);
                }
            }

            // Destroy Building
            if (_BuildingQueueUI != null)
            {
                UI_BuildingQueueWrapper.Instance.RemoveFromQueue(_BuildingQueueUI);
            }
            OnDeath(null);

            // Send message to match feed
            MatchFeed.Instance.AddMessage(string.Concat(ObjectName, " recycled."));
        }

        // Make building slot available again
        AttachedBuildingSlot.SetBuildingOnSlot(null);
        AttachedBuildingSlot.gameObject.SetActive(true);

        // Update building queue UI
        if (AttachedBuildingSlot.AttachedBase != null)
        {
            AttachedBuildingSlot.AttachedBase._BuildingQueueUI.UpdateQueueItemList();
        }
    }
示例#4
0
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    /// <summary>
    //  Called when the player presses a button on the selection wheel with this world object
    //  linked to the button.
    /// </summary>
    /// <param name="buildingSlot">
    //  The building slot that instigated the selection wheel.
    //  (EG: If you're making a building, this is the building slot thats being used.)
    /// </param>
    public override void OnWheelSelect(BuildingSlot buildingSlot)
    {
        base.OnWheelSelect(buildingSlot);

        // Get reference to the newly cloned building
        if (_ClonedWorldObject != null)
        {
            // Reset building time
            if (SceneManager.GetSceneByName("TutorialScene") == SceneManager.GetActiveScene())
            {
                _CurrentBuildTime = BuildingTimeTutorial;
            }
            else
            {
                _CurrentBuildTime = BuildingTime;
            }

            // Update building slot team for the outline colouring
            Building building = _ClonedWorldObject.GetComponent <Building>();
            building.AttachedBuildingSlot      = buildingSlot;
            building.AttachedBuildingSlot.Team = _ClonedWorldObject.Team;

            // Update building slot ref with building
            buildingSlot.SetBuildingOnSlot(building);
            buildingSlot.SetIsSelected(false);
            buildingSlot.SetOutlineVisibility(false);

            Base     attachedBase     = buildingSlot.AttachedBase;
            Building attachedBuilding = buildingSlot.AttachedBuilding;

            // Add the building to the buildingslot's building's queue (i know, confusing right?)
            if (buildingSlot.ObjectsCreatedAreQueued)
            {
                // Add to attached base list (if valid)
                if (attachedBase != null)
                {
                    attachedBase.AddBuildingToList(building);
                    ///attachedBase.AddToQueue(building);

                    // Get rally point reference
                    if (attachedBase.GetRallyPoint() == null)
                    {
                        attachedBase.CreateRallyPoint();
                    }
                    building._Rallypoint = attachedBase.GetRallyPoint();

                    // Add to queue wrapper
                    if (building._BuildingQueueUI != null)
                    {
                        if (!UI_BuildingQueueWrapper.Instance.ContainsQueue(building._BuildingQueueUI))
                        {
                            UI_BuildingQueueWrapper.Instance.AddNewQueue(building._BuildingQueueUI);
                        }
                        building._BuildingQueueUI.transform.SetParent(UI_BuildingQueueWrapper.Instance.QueueListTransform);
                        building._BuildingQueueUI.gameObject.SetActive(true);
                    }
                    else
                    {
                        building.CreateQueueWidget();
                    }
                }

                // Add to attached building list (if valid)
                if (attachedBuilding != null && attachedBase == null)
                {
                    if (!attachedBuilding.RemoveFromQueue(building))
                    {
                        attachedBuilding.AddToQueue(building);
                    }

                    // Add to queue wrapper
                    if (building._BuildingQueueUI != null)
                    {
                        if (!UI_BuildingQueueWrapper.Instance.ContainsQueue(building._BuildingQueueUI))
                        {
                            UI_BuildingQueueWrapper.Instance.AddNewQueue(building._BuildingQueueUI);
                        }
                        building._BuildingQueueUI.transform.SetParent(UI_BuildingQueueWrapper.Instance.QueueListTransform);
                        building._BuildingQueueUI.gameObject.SetActive(true);
                    }
                    else
                    {
                        building.CreateQueueWidget();
                    }
                }

                // Send message to match feed
                MatchFeed.Instance.AddMessage(string.Concat(ObjectName, " added to queue."));
            }

            // Skip the queue process and start building the object immediately
            else   /// (!buildingSlot.ObjectsCreatedAreQueued)

            // Remove it from the base/building's queue (WorldObject class adds it at the start!)
            {
                if (attachedBase != null)
                {
                    attachedBase.RemoveFromQueue(building);
                }
                if (attachedBuilding != null)
                {
                    attachedBuilding.RemoveFromQueue(building);
                }

                // Start building the object
                building.StartBuildingObject();
            }

            // Set rally point
            if (buildingSlot.AttachedBase != null)
            {
                _Rallypoint = buildingSlot.AttachedBase.GetRallyPoint();
            }
        }

        // Play building started sound
        SoundManager.Instance.PlaySound("SFX/_SFX_Building", 1f, 1f);
    }