Beispiel #1
0
    public bool BuyMetal(MetalCargo from, int amount)
    {
        if (Vector2.Distance(transform.position, from.transform.position) <= 2f)
        {
            if (!RelationshipManager.IsBlockading(gameObject.tag, from.tag))
            {
                if (GetCurrentFreeCargo() >= amount)
                {
                    CurrentMetal += amount;
                    from.RemoveMetal(amount);
                    return(true);
                }
            }
        }

        return(false);
    }
Beispiel #2
0
    public bool SellMetal(MetalCargo to, int amount)
    {
        if (Vector2.Distance(transform.position, to.transform.position) <= 2f)
        {
            if (!RelationshipManager.IsBlockading(gameObject.tag, to.tag))
            {
                if (CurrentMetal >= amount)
                {
                    if (to.GetCurrentFreeCargo() >= amount)
                    {
                        CurrentMetal -= amount;
                        to.AddMetal(amount);
                        return(true);
                    }
                }
            }
        }

        return(false);
    }
Beispiel #3
0
    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);
    }