예제 #1
0
    public override void onAtDestination()
    {
        this.timeMining += (Time.deltaTime * this.owner.info.personality.workSpeedMultiplyer);

        int hardness = this.owner.world.getHardness(this.stonePos);

        if (this.timeMining >= this._mineSpeeds[hardness])
        {
            // Pickup the dropped item from the stone.
            CellData data = this.owner.world.getCellState(this.stonePos).data;
            if (data is CellDataMineable)
            {
                CellDataMineable dataMineable = (CellDataMineable)data;

                this.minerData.heldItem = dataMineable.droppedItem;

                if (dataMineable.showParticles)
                {
                    // Play particle (and color it)
                    Particle particle = this.owner.world.particles.spawn(this.stonePos.center, this.owner.depth, this.mineParticlePrefab);
                    if (particle != null)
                    {
                        LayerData layerData            = this.owner.world.mapGenerator.getLayerFromDepth(this.owner.depth);
                        ParticleSystem.MainModule main = particle.ps.main;
                        main.startColor = layerData.getGroundTint(this.owner.world, this.stonePos.x, this.stonePos.y);
                    }
                }

                // Add to mined stat.
                StatisticInt stat = this.owner.world.statManager.getCellMinedStat(data);
                if (stat != null)
                {
                    stat.increase(1);
                }
            }

            // Reduce hunger and energy.
            this.owner.hunger.decrease(this._hungerCost);
            this.owner.energy.decrease(this._energyCost);

            // Remove the stone.
            this.owner.world.setCell(this.stonePos, null);
            this.owner.world.targetedSquares.stopTargeting(this.stonePos);
            this.owner.world.liftFog(this.stonePos);
            this.owner.world.tryCollapse(this.stonePos);

            // Add to global mined count
            this.owner.world.stoneExcavated++;
        }
    }
예제 #2
0
    protected override void onClick(Position pos, bool isValid)
    {
        if (isValid)
        {
            int  cost       = this.popup.getDemoCost();
            bool inCreative = CameraController.instance.inCreativeMode;
            if ((inCreative || (this.money.value >= this.popup.getDemoCost()) && this.world.plotManager.isOwned(pos)))
            {
                if (!inCreative)
                {
                    this.money.value -= cost;
                }

                Vector2 particlePos;
                if (this.destroyableEntity != null)
                {
                    particlePos = this.destroyableEntity.worldPos;
                    this.world.entities.remove(this.destroyableEntity);
                }
                else
                {
                    // Add to the destroyed stat.
                    CellData     cell = this.world.getCellState(pos).data;
                    StatisticInt stat = this.world.statManager.getCellDestroyedStat(cell);
                    if (stat != null)
                    {
                        stat.increase(1);
                    }
                    else
                    {
                        print("error");
                    }

                    particlePos = pos.center;

                    // Remove the Cell.
                    this.world.setCell(pos, null);
                    this.world.tryCollapse(pos);
                }

                this.world.particles.spawn(particlePos, pos.depth, particlePrefab);
            }
        }
    }