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>();
        attachedBuyingStructure = attachedSelectable.gameObject.GetComponent <BuyingStructure>();
    }
示例#2
0
    private BuyingStructure getBestDeal()
    {
        List <BuyingStructure> allBuildings = BuildingsManager.buyingStructures;
        int             currentBestPrice    = int.MaxValue;
        BuyingStructure best = null;

        foreach (BuyingStructure 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) &&
                    (FactionsManager.factions[current.tag].money >= current.MetalPrice * aiAttributes.AttachedShip.Cargo.CurrentMetal || current.tag.Equals(aiAttributes.AttachedShip.tag)) &&
                    current.Cargo.GetCurrentFreeCargo() >= aiAttributes.AttachedShip.Cargo.CurrentMetal)
                {
                    if (best == null || Random.value > aiAttributes.randomness)
                    {
                        currentBestPrice = currentPrice;
                        best             = current;
                    }
                }
            }
        }

        return(best);
    }
示例#3
0
    private void Start()
    {
        aiAttributes = GetComponent <AiAttributes>();

        sellingTo = getBestDeal();
    }