//****************************************************************************************************************************** // // FUNCTIONS // //****************************************************************************************************************************** //////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void ConfirmRecycle() { if (_BuildingToRecycle != null && _BuildingSlotInFocus != null) { _BuildingToRecycle.SetIsSelected(false); // Remove the building from any queues it is currently in if (_BuildingSlotInFocus.AttachedBase != null) { _BuildingSlotInFocus.AttachedBase.RemoveFromQueue(_BuildingToRecycle); } if (_BuildingSlotInFocus.GetBuildingOnSlot() != null) { _BuildingSlotInFocus.GetBuildingOnSlot().RemoveFromQueue(_BuildingToRecycle); } // Recycle building _BuildingToRecycle.RecycleBuilding(); // Free resources by destroying this instance (if needed) if (_RecycleBuildingClass.GetToBeDestroyed()) { Destroy(_RecycleBuildingClass.gameObject); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <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); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> public void UpdateButtonStates() { if (_BuildingSlotInstigator != null) { if (_BuildingSlotInstigator.GetBuildingOnSlot() != null) { RefreshButtons(_BuildingSlotInstigator.GetBuildingOnSlot().Selectables); } else { RefreshButtons(_BuildingSlotInstigator.GetBuildingsAsAbstraction()); } } }
//****************************************************************************************************************************** // // 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); } }
//****************************************************************************************************************************** // // 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) { // Update building reference _BuildingToRecycle = buildingSlot.GetBuildingOnSlot(); // Valid building check if (_BuildingToRecycle != null) { // Show the confirm screen popup GameObject confirmScreen = GameManager.Instance.ConfirmRecycleScreen; if (confirmScreen != null) { UI_RecycleScreenConfirmation recycleScreen = confirmScreen.GetComponent <UI_RecycleScreenConfirmation>(); if (recycleScreen != null) { recycleScreen.SetBuildingSlotInFocus(buildingSlot); recycleScreen.SetBuildingToRecycle(_BuildingToRecycle); recycleScreen.SetRecycleClass(this); recycleScreen.gameObject.SetActive(true); } } } else { Debug.Log("_BuildingToRecycle == null"); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Starts the construction process of this abstraction. /// </summary> public virtual void StartBuildingObject(BuildingSlot buildingSlot = null) { _ObjectState = WorldObjectStates.Building; if (buildingSlot != null) { buildingSlot.GetBuildingOnSlot().SetBuildingStarted(true); } // Send message to match feed MatchFeed.Instance.AddMessage(string.Concat(ObjectName, " started construction.")); }
//****************************************************************************************************************************** // // 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) { base.OnWheelSelect(buildingSlot); // Detonate all known mines on the attached minefield MineField mineField = buildingSlot.GetBuildingOnSlot() as MineField; for (int i = 0; i < mineField.GetUndetonatedMines().Count; i++) { Mine mine = mineField.GetUndetonatedMines()[i]; mine.DetonateMine(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called when the player presses a button on the selection wheel with this 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) { // Set building attached reference _BuildingAttached = buildingSlot.GetBuildingOnSlot(); // Not reached the maximum upgrade yet if (!_HasMaxUpgrade) { // If the method exists for the next upgrade, then call it if (UpgradeEvents.Count >= _CurrentUpgradeLevel + 1 && UpgradeProperties.Count >= _CurrentUpgradeLevel + 1) { UpgradeEvents[_CurrentUpgradeLevel].Invoke(); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <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(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <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) { // Deselect buildingSlot._IsCurrentlySelected = false; this._IsCurrentlySelected = false; // Get player reference Player plyr; if (_Player) { plyr = _Player; } else { plyr = GameManager.Instance.Players[0]; } // Check if the player has enough resources to build the object if ((plyr.SuppliesCount >= this.CostSupplies) && (plyr.PowerCount >= this.CostPower)) { // Add to building queue on the selected building slot _ClonedWorldObject = ObjectPooling.Spawn(gameObject, Vector3.zero, Quaternion.identity).GetComponent <WorldObject>(); _ClonedWorldObject.SetBuildingPosition(buildingSlot); _ClonedWorldObject.gameObject.SetActive(true); _ClonedWorldObject.Init(); // Create healthbar CreateHealthBar(_ClonedWorldObject, plyr.PlayerCamera); // Create building progress panel & allocate it to the unit GameObject buildProgressObj = ObjectPooling.Spawn(GameManager.Instance.BuildingInProgressPanel.gameObject); _BuildingProgressCounter = buildProgressObj.GetComponent <UnitBuildingCounter>(); _BuildingProgressCounter.SetObjectAttached(_ClonedWorldObject); _BuildingProgressCounter.SetCameraAttached(plyr.PlayerCamera); buildProgressObj.gameObject.SetActive(true); buildProgressObj.transform.SetParent(GameManager.Instance.WorldSpaceCanvas.gameObject.transform, false); // Add to building queue _ClonedWorldObject._ObjectState = WorldObjectStates.InQueue; if (buildingSlot.GetBuildingOnSlot() != null) { buildingSlot.GetBuildingOnSlot().AddToQueue(_ClonedWorldObject); } else { // Add to base queue if (buildingSlot.AttachedBase != null) { buildingSlot.AttachedBase.AddToQueue(_ClonedWorldObject); } } // Update queue widget UI_BuildingQueueWrapper.Instance.UpdateQueuePositions(); // Deduct resources from player _ClonedWorldObject.SetPlayer(plyr); plyr.SuppliesCount -= _ClonedWorldObject.CostSupplies; plyr.PowerCount -= _ClonedWorldObject.CostPower; // Set object's properties _ClonedWorldObject.Team = plyr.Team; _ClonedWorldObject._IsCurrentlySelected = false; _CurrentBuildTime = BuildingTime; } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> /// <param name="other"></param> private void OnTriggerEnter(Collider other) { if (other.gameObject.tag != "Ground" && other.gameObject.layer != LayerMask.NameToLayer("Ignore Raycast")) { // Not holding LEFT CONTROL and LEFT SHIFT if (!Input.GetKey(KeyCode.LeftControl)) { if (!Input.GetKey(KeyCode.LeftShift)) { // Deselect any objects that are currently selected foreach (var obj in _Player.SelectedWorldObjects) { obj.SetIsSelected(false); } _Player.SelectedWorldObjects.Clear(); foreach (var obj in _Player.SelectedUnits) { obj.SetIsSelected(false); } _Player.SelectedUnits.Clear(); if (_Player.SelectedBuildingSlot != null) { _Player.SelectedBuildingSlot.SetIsSelected(false); _Player.SelectedBuildingSlot = null; } } } // Cast hit object to selectable objects Base baseObj = null; Building buildingObj = null; BuildingSlot buildingSlot = null; Unit unit = null; WorldObject worldObj = null; baseObj = other.gameObject.GetComponentInParent <Base>(); buildingSlot = other.gameObject.GetComponent <BuildingSlot>(); worldObj = other.gameObject.GetComponentInParent <WorldObject>(); // Left clicking on something attached to a base if (baseObj != null) { buildingObj = other.gameObject.GetComponent <Building>(); // Left clicking on a base if (buildingObj == null && buildingSlot == null) { // Matching team if (baseObj.Team == _Player.Team) { // Add selection to list _Player.SelectedWorldObjects.Add(baseObj); baseObj.SetPlayer(_Player); baseObj.SetIsSelected(true); baseObj.OnSelectionWheel(); } } // Left clicking on a building if (buildingObj != null) { if (buildingSlot == null) { // Matching team if (buildingObj.Team == _Player.Team) { // Add selection to list _Player.SelectedWorldObjects.Add(buildingObj); buildingObj.SetPlayer(_Player); buildingObj.SetIsSelected(true); buildingObj.OnSelectionWheel(); } } } // Left clicking on a building slot if (buildingSlot != null) { // Empty building slot if (buildingSlot.GetBuildingOnSlot() == null) { // Matching team if (buildingSlot.AttachedBase.Team == _Player.Team) { _Player.SelectedBuildingSlot = buildingSlot; buildingSlot.SetPlayer(_Player); buildingSlot.SetIsSelected(true); } } // Builded slot else { // Matching team if (buildingSlot.GetBuildingOnSlot().Team == _Player.Team) { // Add selection to list _Player.SelectedWorldObjects.Add(buildingSlot.GetBuildingOnSlot()); buildingSlot.GetBuildingOnSlot().SetPlayer(_Player); buildingSlot.GetBuildingOnSlot().SetIsSelected(true); buildingSlot.GetBuildingOnSlot().OnSelectionWheel(); } } } } // Left clicking on something NOT attached to a base else { buildingObj = other.gameObject.GetComponentInParent <Building>(); // Left clicking on a building if (buildingObj != null) { if (baseObj == null && buildingSlot == null) { // Matching team if (buildingObj.Team == _Player.Team) { // Add selection to list _Player.SelectedWorldObjects.Add(buildingObj); buildingObj.SetPlayer(_Player); buildingObj.SetIsSelected(true); buildingObj.OnSelectionWheel(); } } } // Hit an AI object? unit = other.gameObject.GetComponentInParent <Unit>(); // Left clicking on a unit if (unit != null) { // Unit is active in the world if (unit.GetObjectState() == Abstraction.WorldObjectStates.Active) { // Matching team if (unit.Team == _Player.Team) { // Add selection to list _Player.SelectedWorldObjects.Add(unit); _Player.SelectedUnits.Add(unit); unit.SetPlayer(_Player); unit.SetIsSelected(true); } } } // Left clicking on a world object if (worldObj != null) { if (buildingSlot == null && buildingObj == null && baseObj == null && unit == null) { // Add selection to list _Player.SelectedWorldObjects.Add(worldObj); worldObj.SetPlayer(_Player); worldObj.SetIsSelected(true); } } // Left clicking on a building slot if (buildingSlot != null) { // Empty building slot if (buildingSlot.GetBuildingOnSlot() == null) { _Player.SelectedBuildingSlot = buildingSlot; buildingSlot.SetPlayer(_Player); buildingSlot.SetIsSelected(true); } // Builded slot else { // Matching team if (buildingSlot.GetBuildingOnSlot().Team == _Player.Team) { // Add selection to list _Player.SelectedWorldObjects.Add(buildingSlot.GetBuildingOnSlot()); buildingSlot.GetBuildingOnSlot().SetPlayer(_Player); buildingSlot.GetBuildingOnSlot().SetIsSelected(true); buildingSlot.GetBuildingOnSlot().OnSelectionWheel(); } } } } } // Just clicked on the ground so deselect all objects else { _Player.DeselectAllObjects(); } }
//****************************************************************************************************************************** // // 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) { // Update building reference _BuildingAttached = buildingSlot.GetBuildingOnSlot(); }
/// <summary> /// Prevents tutorial event from continuing until /// the required action is met. /// </summary> /// <param name="md"></param> private void ActionRequired(MessageData md) { switch (md.Action) { case RequiredAction.BUILD_BARRICADE: if (BarricadeSlot.GetBuildingOnSlot() != null) { if ((BarricadeSlot.GetBuildingOnSlot().ObjectName == BarricadeSlot.Buildings[1].ObjectName && (BarricadeSlot.GetBuildingOnSlot()._ObjectState == WorldObject.WorldObjectStates.Building || BarricadeSlot.GetBuildingOnSlot()._ObjectState == WorldObject.WorldObjectStates.InQueue)) || (BarricadeSlot.GetBuildingOnSlot().ObjectName == BarricadeSlot.Buildings[2].ObjectName && (BarricadeSlot.GetBuildingOnSlot()._ObjectState == WorldObject.WorldObjectStates.Building || BarricadeSlot.GetBuildingOnSlot()._ObjectState == WorldObject.WorldObjectStates.InQueue))) { ObjectiveText.text = "Build Barricade: 1/1"; ActionBool = true; } else { ObjectiveText.text = "Build Barricade: 0/1"; } } else { ObjectiveText.text = "Build Barricade: 0/1"; } break; case RequiredAction.BUILD_BASIC_UNIT: if (_PopulationCount == 1) { ActionBool = true; ObjectiveText.text = "Build Dwarf Soldier 1/1"; } else { ObjectiveText.text = "Build Dwarf Soldier 0/1"; } break; case RequiredAction.BUILD_POWER_GENERATOR: ObjectiveText.text = "Power Station: " + _ResourceManager.GetPowerGeneratorCount() + "/1"; for (int i = 0; i < BaseBuildingSlots.Count; ++i) { if (BaseBuildingSlots[i].GetBuildingOnSlot() != null) { if (BaseBuildingSlots[i].GetBuildingOnSlot().ObjectName == BaseBuildingSlots[i].Buildings[2].ObjectName && BaseBuildingSlots[i].GetBuildingOnSlot()._ObjectState == Abstraction.WorldObjectStates.Building) { ActionBool = true; } } } break; case RequiredAction.BUILD_SUPPLY_GENERATOR: ObjectiveText.text = "Supply Generator: " + _ResourceManager.GetSupplyGeneratorCount() + "/1"; for (int i = 0; i < BaseBuildingSlots.Count; ++i) { if (BaseBuildingSlots[i].GetBuildingOnSlot() != null) { if (BaseBuildingSlots[i].GetBuildingOnSlot().ObjectName == BaseBuildingSlots[i].Buildings[1].ObjectName && BaseBuildingSlots[i].GetBuildingOnSlot()._ObjectState == Abstraction.WorldObjectStates.Building) { ActionBool = true; } } } break; case RequiredAction.BUILD_TOWER: if (TurretSlot.GetBuildingOnSlot() != null) { if ((TurretSlot.GetBuildingOnSlot().ObjectName == TurretSlot.Buildings[1].ObjectName && TurretSlot.GetBuildingOnSlot()._ObjectState == Abstraction.WorldObjectStates.Building) || (TurretSlot.GetBuildingOnSlot().ObjectName == TurretSlot.Buildings[2].ObjectName && TurretSlot.GetBuildingOnSlot()._ObjectState == Abstraction.WorldObjectStates.Building) || (TurretSlot.GetBuildingOnSlot().ObjectName == TurretSlot.Buildings[3].ObjectName && TurretSlot.GetBuildingOnSlot()._ObjectState == Abstraction.WorldObjectStates.Building)) { ObjectiveText.text = "Build Tower: 1/1"; ActionBool = true; } else { ObjectiveText.text = "Build Tower: 0/1"; } } else { ObjectiveText.text = "Build Tower: 0/1"; } break; case RequiredAction.BUILD_VEHICLE: break; case RequiredAction.KILL_ENEMIES: break; case RequiredAction.UPGRADE_TOWNHALL: if (!StartBase.activeInHierarchy) { ActionBool = true; ObjectiveText.text = "Town Hall Tier II 1/1"; } else { ObjectiveText.text = "Town Hall Tier II 0/1"; } break; case RequiredAction.BUILD_BARRACKS: for (int i = 0; i < BaseBuildingSlots.Count; ++i) { if (BaseBuildingSlots[i].GetBuildingOnSlot() != null) { if (BaseBuildingSlots[i].GetBuildingOnSlot().ObjectName == BaseBuildingSlots[i].Buildings[9].ObjectName && BaseBuildingSlots[i].GetBuildingOnSlot()._ObjectState == Abstraction.WorldObjectStates.Building) { ObjectiveText.text = "Build Barracks 1/1"; ActionBool = true; } else { ObjectiveText.text = "Build Barracks 0/1"; } } else { ObjectiveText.text = "Build Barracks 0/1"; } } break; case RequiredAction.BUILD_BARRACK_UNIT: if (_PopulationCount == 1) { ActionBool = true; ObjectiveText.text = "Build Barracks Unit 1/1"; } else { ObjectiveText.text = "Build Barracks Unit 0/1"; } break; case RequiredAction.FINISH_TUTORIAL: ActionBool = true; break; default: break; } }