Example #1
0
    public IEnumerator goFish()
    {
        ResourceTile mostTile = grid.resourceTiles.ElementAt(UnityEngine.Random.Range(0, grid.resourceTiles.Count)).Value;

        int stagger = UnityEngine.Random.Range(5, 30);

        for (int i = 0; i < stagger; i++)
        {
            yield return(null);
        }

        yield return(StartCoroutine(moveBoat(mostTile.tileIndex())));

        mostTile.isHere(gameObject);
        //fish(mostTile.tileIndex());
        mostTile.fishingHere(gameObject);

        yield return(null);

        mostTile.getFish(gameObject);

        currentGrossProfit = currentCatch * fishPrice;
        currentProfit      = currentCatch * fishPrice - costs;

        yield return(null);

        mostTile.leftHere(gameObject);
    }
Example #2
0
    public IEnumerator goFish()
    {
        Debug.Log("Grid " + grid);
        Debug.Log("ResourceTiles " + grid.resourceTiles.Count);

        ResourceTile mostTile = grid.resourceTiles.ElementAt(UnityEngine.Random.Range(0, grid.resourceTiles.Count)).Value;

        int stagger = UnityEngine.Random.Range(5, 30);

        for (int i = 0; i < stagger; i++)
        {
            yield return(null);
        }

        yield return(StartCoroutine(moveBoat(mostTile.tileIndex())));

        mostTile.isHere(gameObject);
        //fish(mostTile.tileIndex());
        mostTile.fishingHere(gameObject);

        yield return(null);

        entCatch = mostTile.getFish(gameObject);


        yield return(null);

        mostTile.leftHere(gameObject);
    }
Example #3
0
    IEnumerator GetFish()
    {
        if (tile is null)
        {
            tile = cachedInFilter.getEntity <Destination>().getComponent <Destination>().destination;
        }
        tile.isHere(owner.gameObject);
        //fish(mostTile.tileIndex());
        tile.fishingHere(owner.gameObject);

        yield return(null);

        currentCatch = tile.getFish(owner.gameObject);


        yield return(null);

        tile.leftHere(owner.gameObject);
    }
    IEnumerator toRandomDest()
    {
        if (grid != null)
        {
            ResourceTile mostTile = grid.resourceTiles.ElementAt(Random.Range(0, grid.resourceTiles.Count)).Value;

            moveBoat(mostTile.tileIndex());
            mostTile.isHere(gameObject);
            //fish(mostTile.tileIndex());
            mostTile.fishingHere(gameObject);
            yield return(null);

            mostTile.getFish(gameObject);

            currentGrossProfit = currentCatch * fishPrice;
            currentProfit      = currentCatch * fishPrice - costs;

            yield return(new WaitForSeconds(1f));

            mostTile.leftHere(gameObject);

            keepFishing(mostTile.tileIndex());
        }
    }
    IEnumerator toBestNeighborDestQuota(Vector3Int tileIndex)
    {
        float             totalTime = sim.weektime;
        List <Vector3Int> neighbors = getNeighbors(tileIndex);
        //float mostResource = 0;
        ResourceTile mostTile = grid.getTileAt(tileIndex.x, tileIndex.y);

        //stagger
        int framerate = (int)(1f / Time.unscaledDeltaTime);
        int stagger   = 0;

        if (timer.month == 1)
        {
            yearCatch  = 0;
            yearProfit = 0;
        }

        else
        {
            stagger = Random.Range(0, (int)(framerate - framerate * .1f));

            for (int i = 0; i < stagger; i++)
            {
                totalTime -= Time.deltaTime;
                yield return(null);
            }
        }

        totalTime -= Time.deltaTime;

        //bit of an exploration chance, the less profit the more likely the exploration;
        float exploration          = Random.Range(0f, 1f);
        float explorationThreshold = currentGrossProfit / (fishPrice * capacity * efficiency);

        if (exploration > explorationThreshold)
        {
            mostTile = bestNeighbor(grid.resourceTiles.ElementAt(Random.Range(0, grid.resourceTiles.Count)).Value);
        }

        else
        {
            mostTile = bestNeighbor(grid.getTileAt(tileIndex));
        }

        //Debug.Log("Most resource: " + mostResource);
        //Debug.Log("Most tile: [" + mostTile.tileIndex().x + ", " + mostTile.tileIndex().y + "]");
        moveBoat(mostTile.tileIndex());

        mostTile.isHere(gameObject);
        //fish(mostTile.tileIndex());

        mostTile.fishingHere(gameObject);
        yield return(null);

        mostTile.getFish(gameObject, quota);
        quota -= currentCatch;
        //Debug.Log("Quota : " + quota);
        yearCatch += currentCatch;

        currentGrossProfit = currentCatch * fishPrice;
        currentProfit      = currentCatch * fishPrice - costs;
        yearProfit        += currentProfit;
        totalProfit       += currentProfit;

        yield return(new WaitForSeconds(totalTime));

        mostTile.leftHere(gameObject);

        //yearly reckoning

        if (timer.month == 12)
        {
            if (yearProfit < 250)
            {
                die();
            }
            // else keepFishingQuota(mostTile.tileIndex());
        }

        if (quota > 0)
        {
            keepFishingQuota(mostTile.tileIndex());
        }
        else
        {
            moveBoat(homeTileIndex);
            stayHomeAndWait();
        }
    }