Exemplo n.º 1
0
    protected override void Update()
    {
        base.Update();

        if (resourceToHarvest != null)
        {
            float distToResource = Vector2Int.Distance(tile.pos, resourceToHarvest.tile.pos);
            if (distToResource <= 1 && movement.hasReachedDestination && resourceToHarvest.resourceAmount > 0)
            {
                movement.LookAtTile(resourceToHarvest.tile);

                harvestAmount += Time.deltaTime * harvestSpeed;
                if (harvestAmount >= harvestAmountPerResource)
                {
                    harvestAmount = 0;
                    resourceToHarvest.Harvest(harvestAmountPerResource);
                    if (resourceToHarvest.type == ResourceType.Gem)
                    {
                        if (ownerId == 0)
                        {
                            PlayerController.instance.AddGems(5);
                        }
                        if (ownerId == 1)
                        {
                            EnemyController.instance.AddGems(5);
                        }
                    }
                    if (resourceToHarvest.type == ResourceType.Mineral)
                    {
                        if (ownerId == 0)
                        {
                            PlayerController.instance.AddMinerals(20);
                        }
                        if (ownerId == 1)
                        {
                            EnemyController.instance.AddMinerals(20);
                        }
                    }
                    if ((ownerId == 0 && PlayerController.instance.IsAtMaxResource(resourceToHarvest.type)))
                    {
                        cancelHarvesting();
                        return;
                    }
                    if (ownerId == 1 && EnemyController.instance.IsAtMaxResource(resourceToHarvest.type))
                    {
                        cancelHarvesting();
                        return;
                    }
                }
                isHarvesting = true;
                if (!resourceToHarvest.unitsHarvesting.Contains(this))
                {
                    resourceToHarvest.unitsHarvesting.Add(this);
                }
            }
            else if (isHarvesting)
            {
                cancelHarvesting();
            }
        }
    }