public void onButtonPressed(int index) { if (player.GetPower() >= blueprint.items[index].cost && player.faction == vendor.GetFaction() && player.unitsCommanding.Count < player.GetTotalCommandLimit()) { BuyItem(player, index, vendor); if (GetActive()) { CloseUI(); } ClearVendor(); } else if (player as PlayerCore && player.GetUnitsCommanding().Count >= player.GetTotalCommandLimit()) { player.alerter.showMessage("Unit limit reached!", "clip_alert"); } }
public void onButtonPressed(int index) { // TODO: this is invalid for non ownable items, so must be changed later on if (player.GetPower() >= blueprint.items[index].cost && player.faction == vendor.GetFaction() && player.unitsCommanding.Count < player.GetTotalCommandLimit()) { GameObject creation = new GameObject(); switch (blueprint.items[index].entityBlueprint.intendedType) { case EntityBlueprint.IntendedType.Turret: Turret tur = creation.AddComponent <Turret>(); tur.blueprint = blueprint.items[index].entityBlueprint; tur.SetOwner(player); break; case EntityBlueprint.IntendedType.Tank: Tank tank = creation.AddComponent <Tank>(); tank.blueprint = blueprint.items[index].entityBlueprint; tank.enginePower = 250; tank.SetOwner(player); break; default: break; } creation.name = blueprint.items[index].entityBlueprint.name; player.sectorMngr.InsertPersistentObject(blueprint.items[index].entityBlueprint.name, creation); creation.transform.position = vendor.GetPosition(); creation.GetComponent <Entity>().spawnPoint = vendor.GetPosition(); if (blueprint.items[index].entityBlueprint.intendedType != EntityBlueprint.IntendedType.Tank) { player.SetTractorTarget(creation.GetComponent <Draggable>()); } player.AddPower(-blueprint.items[index].cost); if (GetActive()) { CloseUI(); } ClearVendor(); } else if (player as PlayerCore && player.GetUnitsCommanding().Count >= player.GetTotalCommandLimit()) { player.alerter.showMessage("Unit limit reached!", "clip_alert"); } }
public void InitializeSelectionPhase() { searcherString = ""; selectionPhaseParent.SetActive(true); buildPhaseParent.SetActive(false); //initialize window on screen if (initialized) { CloseUI(false); // prevent initializing twice by closing UI if already initialized } initialized = true; Activate(); cursorScript.gameObject.SetActive(false); cursorScript.SetBuilder(this); contentsArray = new Transform[] { smallContents, mediumContents, largeContents }; contentTexts = new GameObject[] { smallText, mediumText, largeText }; foreach (GameObject obj in contentTexts) { obj.SetActive(false); } GetComponentInChildren <ShipBuilderPartDisplay>().Initialize(this); player.SetIsInteracting(true); partDict = new Dictionary <DWInventoryButton, EntityBlueprint.PartInfo>(); // hide the buttons and yard tips if interacting with a trader List <EntityBlueprint.PartInfo> parts = player.GetInventory(); if (parts != null) { for (int i = 0; i < parts.Count; i++) { parts[i] = ShipBuilder.CullSpatialValues(parts[i]); } } foreach (EntityBlueprint.PartInfo part in parts) { if (part.abilityID == 10) { AddDronePart(part); } } foreach (EntityBlueprint.PartInfo part in player.blueprint.parts) { if (part.abilityID == 10) { AddDronePart(part); } } var partsToAdd = new List <ShellPart>(); foreach (Entity ent in player.GetUnitsCommanding()) { if (!((ent as Drone) && ent.GetComponentInChildren <TractorBeam>())) { continue; } var target = ent.GetComponentInChildren <TractorBeam>().GetTractorTarget(); if (target && target.GetComponent <ShellPart>()) { partsToAdd.Add(target.GetComponent <ShellPart>()); } } if (player.GetTractorTarget() && player.GetTractorTarget().GetComponent <ShellPart>()) { partsToAdd.Add(player.GetTractorTarget().GetComponent <ShellPart>()); } foreach (ShellPart part in partsToAdd) { var info = part.info; info = ShipBuilder.CullSpatialValues(info); if (info.abilityID == 10) { int size = ResourceManager.GetAsset <PartBlueprint>(info.partID).size; var button = Instantiate(displayButtonPrefab, contentsArray[size]).GetComponent <DWInventoryButton>(); button.handler = selectionDisplay; button.workshop = this; contentTexts[size].SetActive(true); button.part = info; partDict.Add(button, info); } player.cursave.partInventory.Add(info); Destroy(part.gameObject); } phase = DroneWorkshopPhase.SelectionPhase; // activate windows gameObject.SetActive(true); }