Ejemplo n.º 1
0
    internal void ClientRequestFailed(ClientSlot clientSlot)
    {
        if (_finished)
        {
            return;
        }

        var reqData = _requestAllocations[clientSlot];
        int revenue = 0;

        foreach (var itemID in reqData.Items)
        {
            Item item = GetItem(itemID);
            revenue += item.BaseRevenue;
        }
        _revenue -= revenue;
        if (_revenue < 0)
        {
            _revenue = 0;
        }
        OnClientRevenueAction?.Invoke(clientSlot, -revenue, 0);
        OnEarningsChanged?.Invoke(_revenue);

        _numFailures++;
        _requestAllocations.Remove(clientSlot);
        if (_stalledRequests.Count > 0)
        {
            var data = _stalledRequests.Dequeue();
            clientSlot.InitClient(data);
        }
    }
Ejemplo n.º 2
0
    public void RequestFulfilled(ClientSlot clientSlot)
    {
        if (_finished)
        {
            return;
        }

        var   data            = _requestAllocations[clientSlot];
        float timeLeftPercent = 100 * (1 - clientSlot.TimeElapsed / data.Timeout);
        int   revenue         = 0;

        foreach (var itemID in data.Items)
        {
            Item itemData = GetItem(itemID);
            revenue += itemData.BaseRevenue;
        }

        int idx = 0;

        while (idx < EarningModifiers.Count && timeLeftPercent > EarningModifiers[idx].TimeLeftThresholdValue)
        {
            idx++;
        }
        float multiplier        = EarningModifiers[idx].ExtraPercent;
        int   additionalRevenue = Mathf.FloorToInt(revenue * multiplier);

        OnClientRevenueAction?.Invoke(clientSlot, revenue, additionalRevenue);

        _revenue += revenue + additionalRevenue;
        OnEarningsChanged?.Invoke(_revenue);
        _requestAllocations.Remove(clientSlot);

        if (_stalledRequests.Count > 0)
        {
            data = _stalledRequests.Dequeue();
            clientSlot.InitClient(data);
        }
    }