private void Start() { nextRestockTime = Time.time + Random.Range(minTimeToRestock, maxTimeToRestock); Cargo = GetComponent <MetalCargo>(); SellingStructure = GetComponent <SellingStructure>(); }
public void GetRequiredComponentsFromSelectable() { selectedSpriteImage.sprite = attachedSelectable.gameObject.GetComponent <SpriteRenderer>().sprite; selectedAmountText.text = "" + SelectionManager.selected.Count; selectedNameText.text = attachedSelectable.selectableName; attachedHitpoints = attachedSelectable.gameObject.GetComponent <Hitpoints>(); attachedMetalCargo = attachedSelectable.gameObject.GetComponent <MetalCargo>(); attachedSellingStructure = attachedSelectable.gameObject.GetComponent <SellingStructure>(); }
private SellingStructure getBestDeal() { List <SellingStructure> allBuildings = BuildingsManager.sellingStructures; int currentBestPrice = int.MaxValue; SellingStructure best = null; foreach (SellingStructure current in allBuildings) { if (current != null) { // DistanceToBuilding is how much distance to current building affects outcome float distanceToBuilding = Vector2.Distance(aiAttributes.AttachedShip.transform.position, current.transform.position) * aiAttributes.distanceToBuildingModifier; // Calculate currentPrice by getting metal price in the building and modifying it by distanceToBuilding int currentPrice = Mathf.FloorToInt(current.MetalPrice + distanceToBuilding); // Add preference towards own faction if (!aiAttributes.AttachedShip.tag.Equals(current.tag)) { currentPrice = Mathf.FloorToInt(currentPrice * (1 + aiAttributes.ownFactionTradeBiasModifier)); } if ((best == null || currentBestPrice > currentPrice) && !RelationshipManager.IsBlockading(current.tag, aiAttributes.AttachedShip.tag) && current.Cargo.CurrentMetal >= aiAttributes.AttachedShip.Cargo.GetCurrentFreeCargo() / 2 && (FactionsManager.factions[aiAttributes.AttachedShip.tag].money >= aiAttributes.AttachedShip.Cargo.GetCurrentFreeCargo() * current.MetalPrice || current.tag.Equals(aiAttributes.AttachedShip.tag))) { if (best == null || Random.value > aiAttributes.randomness) { currentBestPrice = currentPrice; best = current; } } } } return(best); }
private void Start() { aiAttributes = GetComponent <AiAttributes>(); buyingFrom = getBestDeal(); }