示例#1
0
    protected override void UseForPlayer(Player player, ItemsBean itemData, ItemUseTypeEnum useType)
    {
        //检测玩家前方是否有方块
        if (player.playerRay.RayToChunkBlock(out RaycastHit hit, out Vector3Int targetBlockPosition))
        {
            ChunkComponent chunkForHit = hit.collider.GetComponentInParent <ChunkComponent>();
            if (chunkForHit != null)
            {
                //获取位置和方向
                player.playerRay.GetHitPositionAndDirection(hit, out Vector3Int targetPosition, out Vector3Int closePosition, out BlockDirectionEnum direction);
                if (useType == ItemUseTypeEnum.Left)
                {
                    TargetBreak(itemData, targetPosition);
                }
                else
                {
                    Vector3Int localPosition = targetPosition - chunkForHit.chunk.chunkData.positionForWorld;
                    //获取原位置方块
                    Block tagetBlock = chunkForHit.chunk.chunkData.GetBlockForLocal(localPosition);

                    //如果不能锄地
                    if (tagetBlock.blockInfo.plough_state == 0)
                    {
                        return;
                    }

                    //获取上方方块
                    Block upBlock = chunkForHit.chunk.chunkData.GetBlockForLocal(localPosition + Vector3Int.up);

                    //如果上方有方块 则无法使用锄头
                    if (upBlock != null && upBlock.blockType != BlockTypeEnum.None)
                    {
                        return;
                    }
                    //扣除道具耐久
                    if (this is ItemBaseTool itemTool)
                    {
                        ItemsDetailsToolBean itemsDetailsTool = itemData.GetMetaData <ItemsDetailsToolBean>();
                        //如果没有耐久 不能锄地
                        if (itemsDetailsTool.life <= 0)
                        {
                            return;
                        }
                        itemsDetailsTool.AddLife(-1);
                        //保存数据
                        itemData.SetMetaData(itemsDetailsTool);
                        //回调
                        EventHandler.Instance.TriggerEvent(EventsInfo.ItemsBean_MetaChange, itemData);
                    }

                    BlockTypeEnum ploughBlockType = (BlockTypeEnum)tagetBlock.blockInfo.remark_int;
                    //替换为耕地方块
                    chunkForHit.chunk.SetBlockForLocal(localPosition, ploughBlockType, direction);

                    //播放粒子特效
                    BlockCptBreak.PlayBlockCptBreakEffect(ploughBlockType, targetPosition + new Vector3(0.5f, 0.5f, 0.5f));
                }
            }
        }
    }
示例#2
0
    public override ItemsDetailsBean GetItemsDetailsBean(long itemId)
    {
        ItemsInfoBean        itemsInfo        = GetItemsInfo(itemId);
        ItemsDetailsToolBean itemsDetailsTool = new ItemsDetailsToolBean();

        itemsDetailsTool.life    = itemsInfo.life;
        itemsDetailsTool.lifeMax = itemsInfo.life;
        return(itemsDetailsTool);
    }
示例#3
0
    /// <summary>
    /// 破碎目标
    /// </summary>
    public virtual void TargetBreak(ItemsBean itemsData, Vector3Int targetPosition)
    {
        //获取原位置方块
        WorldCreateHandler.Instance.manager.GetBlockForWorldPosition(targetPosition, out Block oldBlock, out BlockDirectionEnum oldBlockDirection, out Chunk targetChunk);
        if (targetChunk == null)
        {
            return;
        }
        //如果原位置是空则不做处理
        if (oldBlock == null || oldBlock.blockType == BlockTypeEnum.None)
        {
            return;
        }
        //获取破坏值
        int breakDamage = GetBreakDamage(itemsData, oldBlock);

        //扣除道具耐久
        if (breakDamage > 0 && this is ItemBaseTool itemTool)
        {
            ItemsDetailsToolBean itemsDetailsTool = itemsData.GetMetaData <ItemsDetailsToolBean>();
            //如果已经没有耐久了 则不造成伤害
            if (itemsDetailsTool.life <= 0)
            {
                breakDamage = 0;
            }
            itemsDetailsTool.AddLife(-1);
            //保存数据
            itemsData.SetMetaData(itemsDetailsTool);
            //回调
            EventHandler.Instance.TriggerEvent(EventsInfo.ItemsBean_MetaChange, itemsData);
        }

        BlockCptBreak BlockCptBreak = BlockHandler.Instance.BreakBlock(targetPosition, oldBlock, breakDamage);

        if (BlockCptBreak.blockLife <= 0)
        {
            //移除破碎效果
            BlockHandler.Instance.DestroyBreakBlock(targetPosition);
            //创建掉落
            ItemsHandler.Instance.CreateItemCptDrop(oldBlock, targetChunk, targetPosition);
            //移除该方块
            targetChunk.RemoveBlockForWorld(targetPosition);
        }
    }
示例#4
0
 /// <summary>
 /// 设置耐久
 /// </summary>
 public void SetLife()
 {
     if (itemsInfo.life == 0)
     {
         //如果没有生命值 则没有耐久
         ui_Life.ShowObj(false);
     }
     else
     {
         if (!meta.IsNull())
         {
             ItemsDetailsToolBean itemsDetails = ItemsBean.GetMetaData <ItemsDetailsToolBean>(meta);
             ui_Life.value = (float)itemsDetails.life / itemsInfo.life;
             ui_Life.ShowObj(true);
         }
         else
         {
             ui_Life.ShowObj(false);
         }
     }
 }
    public override void ItemUseHandle(ItemsBean itemsData, Vector3Int targetPosition, Block targetBlock, BlockDirectionEnum targetBlockDirection, Chunk targetChunk)
    {
        if (targetBlock == null)
        {
            return;
        }
        if (targetBlock.blockInfo.GetBlockShape() != BlockShapeEnum.Plough)
        {
            return;
        }
        ItemsDetailsToolBean itemsDetailsTool = itemsData.GetMetaData <ItemsDetailsToolBean>();

        //如果没有耐久了 则不执行
        if (itemsDetailsTool.life <= 0)
        {
            return;
        }
        //扣除耐久
        itemsDetailsTool.AddLife(-1);
        //保存数据 道具数据
        itemsData.SetMetaData(itemsDetailsTool);
        //回调
        EventHandler.Instance.TriggerEvent(EventsInfo.ItemsBean_MetaChange, itemsData);

        //修改耕地的状态
        BlockBean       blockData       = targetChunk.GetBlockData(targetPosition - targetChunk.chunkData.positionForWorld);
        BlockMetaPlough blockMetaPlough = Block.FromMetaData <BlockMetaPlough>(blockData.meta);

        if (blockMetaPlough == null)
        {
            blockMetaPlough = new BlockMetaPlough();
        }
        blockMetaPlough.waterState = 1;
        blockData.meta             = Block.ToMetaData(blockMetaPlough);
        targetChunk.SetBlockData(blockData);
        //更新区块
        WorldCreateHandler.Instance.manager.AddUpdateChunk(targetChunk, 1);
    }