示例#1
0
        public override int use(PlayerBase user, WorldBase world, Vector2 location, GameTime time, BinaryInputManager inputManager)
        {
            int consumed = 0;

            if (inputManager.isDown())
            {
                TileType selectedBlock = user.world.getBlock(user.location);
                if (selectedBlock != null && (selectedBlock.TILEID == TileTypeReferencer.REACTIVE_TRUNK_0.TILEID || selectedBlock.TILEID == TileTypeReferencer.REACTIVE_TRUNK_1.TILEID))
                {
                    if (!inputManager.wasDown() || !user.world.worldLocToTileLoc(user.location).Equals(harvestLocation))
                    {
                        harvestLocation        = user.world.worldLocToTileLoc(user.location);
                        ticksHarvesting        = 0;
                        maxTicksHarvestingTime = selectedBlock.harvestTicks;
                    }

                    if (ticksHarvesting == 0)
                    {
                        SoundManager.getSound(selectedBlock.blockBreakSound).playWithVariance(0, .05f, 0, SoundType.MONSTER);
                    }


                    ticksHarvesting++;
                    if (ticksHarvesting > selectedBlock.harvestTicks)
                    {
                        //user.world.useBlock(user.location, user, this);
                        ticksHarvesting = 0;
                        consumed        = 1;
                        for (int x = -3; x <= 3; x++)
                        {
                            for (int y = -7; y <= 0; y++)
                            {
                                Vector2  potentialTrunkLoc = user.location + new Vector2(x * Chunk.tileDrawWidth, y * Chunk.tileDrawWidth);
                                TileType potentialTrunk    = user.world.getBlock(potentialTrunkLoc);
                                if (potentialTrunk != null && (potentialTrunk.Equals(TileTypeReferencer.REACTIVE_TRUNK_0) || potentialTrunk.Equals(TileTypeReferencer.REACTIVE_TRUNK_1)))
                                {
                                    world.useBlock(potentialTrunkLoc, user, this);
                                }
                            }
                        }
                    }

                    /*else
                     * {
                     *  world.useBlock(user.location, user, this);
                     * }*/
                }
                else
                {
                    if (!inputManager.wasDown())
                    {
                        base.use(user, world, location, time, inputManager);

                        if (user is Player)
                        {
                            Player player = (Player)user;
                            if (player.state.actionPermitted(STATE_ACTIONS.THROW))
                            {
                                Entities.Projectiles.EntityAxe axe = new Entities.Projectiles.EntityAxe(user.location + new Vector2(0, -15), world, user);
                                axe.velocity += Vector2.Normalize(location - user.location) * 15;
                                world.addEntity(axe);

                                SoundManager.getSound("spear-throw").playWithVariance(0, .2f, 0, SoundType.MONSTER);
                                consumed = 1;

                                player.state.decorate(axe);
                                player.state.submitStateAction(STATE_ACTIONS.THROW);
                            }
                        }
                        else
                        {
                            Entities.Projectiles.EntityAxe axe = new Entities.Projectiles.EntityAxe(user.location + new Vector2(0, -15), world, user);
                            axe.velocity += Vector2.Normalize(location - user.location) * 15;
                            world.addEntity(axe);
                            SoundManager.getSound("spear-throw").playWithVariance(0, .2f, 0, SoundType.MONSTER);
                            consumed = 1;
                        }



                        /*Entities.Projectiles.EntityAxe axe = new Entities.Projectiles.EntityAxe(user.location + new Vector2(0, -15), world, user);
                         * axe.velocity += Vector2.Normalize(location - user.location) * 15;
                         * world.addEntity(axe);
                         *
                         * SoundManager.getSound("spear-throw").playWithVariance(0, .2f, 0, SoundType.MONSTER);
                         * consumed = 1;*/
                    }
                }
            }
            else
            {
                ticksHarvesting = 0;
            }

            return(consumed);
        }