Esempio n. 1
0
    private void CollectAvailableResources()
    {
        if (IsDisabled)
        {
            return;
        }

        foreach (Resource resource in nearbyResources)
        {
            float distance = Vector3.Distance(resource.transform.position, transform.position);
            if (distance <= collectionRange)
            {
                if (!cargoHold.IsFull)
                {
                    ResourceType collectedResource = resource.type;
                    int          collectedCount    = resource.Collect(cargoHold.AvailableCapacity) + tractorBeamCount;

                    if (collectedCount > 0)
                    {
                        EventLog.singleton.AddEvent(String.Format("Player {0}'s Trade Ship collected " + collectedCount + " {1}",
                                                                  EventLog.singleton.CreateColoredText(owner.seat.ToString(), owner.color),
                                                                  EventLog.singleton.CreateColoredText(resource.type.ToString(), Resource.GetColor(resource.type))));
                        GameObject item = (GameObject)Instantiate(resource.resourceItemPrefab, resource.sphere.transform.position, resource.sphere.transform.rotation);
                        item.GetComponent <ResourceItem>().FlyTo(netId);
                        NetworkServer.Spawn(item);
                    }

                    cargoHold.Add(collectedResource, collectedCount);
                }
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Process buying cargo from a merchant
    /// </summary>
    /// <param name="ship">The ship doing the buying</param>
    /// <param name="warehouse">The merchant doing the selling</param>
    /// <param name="assets">The player's wealth</param>
    /// <param name="id">The cargo to buy</param>
    /// <param name="count">The amount to buy</param>
    /// <returns>Successfulness</returns>
    public static bool ProcessBuy(CargoHold ship, Warehouse warehouse, PlayerAssets assets, Cargoes id, int count)
    {
        int price = warehouse.GetSellPrice(id, count);

        if (assets.cash < price)
        {
            return(false);
        }

        if (warehouse.GetWareQuantity(id) == 0)
        {
            return(false);
        }

        if (ship.availableSpace < count)
        {
            return(false);
        }

        assets.ModifyCash(-price);
        ship.Add(id, count);
        warehouse.ModifySellingWare(id, -count);
        warehouse.ModifyCash(price);

        return(true);
    }
Esempio n. 3
0
    public int Transfer(ResourceType resource, int quantity, CargoHold other)
    {
        int transferred = other.Add(resource, quantity);

        Dump(resource, transferred);

        return(transferred);
    }
Esempio n. 4
0
    // Use this for initialization
    void Start()
    {
        cargoHold.OnResourceAdded  += cargoHold_OnResourceAdded;
        cargoHold.OnResourceDumped += cargoHold_OnResourceDumped;
        camTarget = transform.FindChild("CameraTarget");

        if (isServer)
        {
            NetworkServer.FindLocalObject(owner).GetComponent <Player>().playerBase = this.netId;

            //seed with initial values, enough to buy one ship
            cargoHold.Add(ResourceType.Corium, 2);
            cargoHold.Add(ResourceType.Workers, 1);

            //testing values
            cargoHold.Add(ResourceType.Corium, 20);
            cargoHold.Add(ResourceType.Hydrazine, 20);
            cargoHold.Add(ResourceType.Supplies, 20);
            cargoHold.Add(ResourceType.Workers, 20);
        }
    }