예제 #1
0
    /// <summary>
    /// 播放使用动画
    /// </summary>
    public virtual void UseForAnim(GameObject user, ItemsBean itemsData)
    {
        //播放使用动画
        ItemsInfoBean   itemsInfo = GetItemsInfo(itemsData.itemId);
        CreatureCptBase creature  = user.GetComponentInChildren <CreatureCptBase>();

        if (itemsInfo.anim_use.IsNull())
        {
            //如果没有动画 则播放默认的使用动画
            creature.creatureAnim.PlayUse(true);
        }
        else
        {
            //如果可以转换成int 说明是use的另外一种类型
            if (int.TryParse(itemsInfo.anim_use, out int reslut))
            {
                creature.creatureAnim.PlayUse(true, reslut);
            }
            else
            {
                //如果该道具指定播放指定动画
                creature.creatureAnim.PlayAnim(itemsInfo.anim_use);
            }
        }
    }
예제 #2
0
    /// <summary>
    /// 使用物品
    /// </summary>
    /// <param name="user"></param>
    /// <param name="itemsData"></param>
    /// <param name="type">0 左键 1右键 2F建</param>
    public void UseItem(GameObject user, ItemsBean itemsData, ItemUseTypeEnum useType)
    {
        Item item;

        if (itemsData == null || itemsData.itemId == 0)
        {
            //如果手上没有东西
            item = manager.GetRegisterItem(itemsData.itemId, ItemsTypeEnum.Block);
        }
        else
        {
            //如果手上有东西
            ItemsInfoBean itemsInfo = manager.GetItemsInfoById(itemsData.itemId);
            //获取对应得处理类
            item = manager.GetRegisterItem(itemsInfo.id, (ItemsTypeEnum)itemsInfo.items_type);
        }
        item.Use(user, itemsData, useType);
        if (useType == ItemUseTypeEnum.E)
        {
            //如果是交互 则不播放动画
        }
        else
        {
            item.UseForAnim(user, itemsData);
        }
    }
예제 #3
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);

                Vector3Int localPosition = targetPosition - chunkForHit.chunk.chunkData.positionForWorld;

                //放置位置
                Vector3Int upLocalPosition = localPosition + Vector3Int.up;

                //获取上方方块
                Block upBlock = chunkForHit.chunk.chunkData.GetBlockForLocal(upLocalPosition);

                //如果上方有方块 则无法放置
                if (upBlock != null && upBlock.blockType != BlockTypeEnum.None)
                {
                    return;
                }

                ItemsInfoBean itemsInfo = GetItemsInfo(itemData.itemId);
                CreatureHandler.Instance.CreateCreature(itemsInfo.type_id, targetPosition + Vector3Int.up);
            }
        }
    }
예제 #4
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));
                }
            }
        }
    }
예제 #5
0
    /// <summary>
    /// 伤害目标
    /// </summary>
    public virtual void DamageTarget(GameObject user, ItemsBean itemsData, Collider[] targetArray)
    {
        if (targetArray.IsNull())
        {
            return;
        }
        //获取武器伤害
        ItemsInfoBean itemsInfo = GetItemsInfo(itemsData.itemId);

        CreatureCptBase selfCreature = user.GetComponent <CreatureCptBase>();

        for (int i = 0; i < targetArray.Length; i++)
        {
            Collider itemCollider = targetArray[i];
            //获取目标生物
            CreatureCptBase creatureCpt = itemCollider.GetComponent <CreatureCptBase>();
            if (creatureCpt == null)
            {
                continue;
            }
            if (creatureCpt == selfCreature)
            {
                continue;
            }
            creatureCpt.creatureBattle.UnderAttack(user, itemsInfo.atk);
        }
    }
예제 #6
0
    public void SetData(ItemsBean itemData, Vector3 position, Vector3 dropdirection)
    {
        this.itemData      = itemData;
        itemsInfo          = ItemsHandler.Instance.manager.GetItemsInfoById(itemData.itemId);
        transform.position = position;
        //设置头像
        SetIcon(itemData.itemId);
        //增加一个跳动的力
        //随机方向
        if (dropdirection == Vector3.zero)
        {
            System.Random random = new System.Random();
            rbItem.AddForce(random.Next(-100, 100), random.Next(-100, 100), random.Next(-100, 100));
        }
        //指定方向
        else
        {
            rbItem.AddForce(dropdirection.x * 100, dropdirection.y * 100, dropdirection.z * 100);
        }
        //初始化数据
        SOGameInitBean gameInitData = GameHandler.Instance.manager.gameInitData;

        timeForItemsDestory = gameInitData.timeForItemsDestory;
        disForItemsDestory  = gameInitData.disForItemsDestory;
        disForDropNoPick    = gameInitData.disForDropNoPick;
        timeForCreate       = 0;
    }
예제 #7
0
 /// <summary>
 /// 移除道具
 /// </summary>
 /// <param name="itemsId"></param>
 /// <param name="itemsNum"></param>
 public int RemoveItem(long itemsId, int itemsNum)
 {
     ItemsBean[] allItems = GetAllItems();
     for (int i = 0; i < allItems.Length; i++)
     {
         ItemsBean itemData = allItems[i];
         if (itemData == null || itemData.itemId == 0)
         {
             continue;
         }
         if (itemData.itemId == itemsId)
         {
             if (itemData.number > itemsNum)
             {
                 itemData.number -= itemsNum;
                 itemsNum         = 0;
             }
             else
             {
                 itemsNum       -= itemData.number;
                 itemData.number = 0;
                 itemData.meta   = null;
                 itemData.itemId = 0;
             }
             if (itemsNum <= 0)
             {
                 //如果都扣除完了
                 break;
             }
         }
     }
     return(itemsNum);
 }
예제 #8
0
    /// <summary>
    /// 单个数据回调
    /// </summary>
    /// <param name="itemCell"></param>
    public void OnCellForItem(ScrollGridCell itemCell)
    {
        UIViewItemContainer viewItemContainer = itemCell.GetComponent <UIViewItemContainer>();
        ItemsBean           itemsData         = blockBoxData.items[itemCell.index];

        viewItemContainer.SetData(UIViewItemContainer.ContainerType.Box, itemsData, itemCell.index);
    }
예제 #9
0
    public override List <ItemsBean> GetDropItems(BlockBean blockData)
    {
        List <ItemsBean> listData  = base.GetDropItems(blockData);
        ItemsInfoBean    itemsInfo = ItemsHandler.Instance.manager.GetItemsInfoByBlockType(blockData.GetBlockType());

        //加一个自己
        listData.Add(new ItemsBean(itemsInfo.id, 1, null));
        //添加箱子里的物品
        if (blockData == null)
        {
            return(listData);
        }
        BlockMetaBox blockBoxData = FromMetaData <BlockMetaBox>(blockData.meta);

        if (blockBoxData == null)
        {
            return(listData);
        }
        for (int i = 0; i < blockBoxData.items.Length; i++)
        {
            ItemsBean itemData = blockBoxData.items[i];
            listData.Add(itemData);
        }
        return(listData);
    }
예제 #10
0
    /// <summary>
    /// 是否有足够数量的指定道具
    /// </summary>
    /// <param name="itemsId"></param>
    /// <param name="itemsNum"></param>
    /// <returns></returns>
    public bool HasEnoughItem(long itemsId, long itemsNum)
    {
        ItemsBean[] allItems    = GetAllItems();
        int         totalNumber = 0;

        for (int i = 0; i < allItems.Length; i++)
        {
            ItemsBean itemData = allItems[i];
            if (itemData == null || itemData.itemId == 0)
            {
                continue;
            }
            if (itemData.itemId == itemsId)
            {
                totalNumber += itemData.number;
            }
        }
        if (totalNumber >= itemsNum)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
예제 #11
0
    /// <summary>
    /// 增加道具
    /// </summary>
    /// <param name="uiViewItem"></param>
    public bool AddItems(UIViewItem uiViewItem)
    {
        //首先直接在显示的list中搜索空位
        List <GameObject> listCellObj = ui_ItemList.GetAllCellObj();

        for (int i = 0; i < listCellObj.Count; i++)
        {
            GameObject          itemObj       = listCellObj[i];
            UIViewItemContainer itemContainer = itemObj.GetComponent <UIViewItemContainer>();
            //如果有容器VIEW 并且里面没有东西
            if (itemContainer != null && itemContainer.GetViewItem() == null)
            {
                uiViewItem.ExchangeItemForContainer(itemContainer);
                return(true);
            }
        }
        //如果不成功则直接查询整个listBackpack
        for (int i = 0; i < listBackpack.Length; i++)
        {
            ItemsBean itemData = listBackpack[i];
            if (itemData == null || itemData.itemId == 0)
            {
                itemData.itemId = uiViewItem.itemId;
                itemData.number = uiViewItem.itemNumber;
                itemData.meta   = uiViewItem.meta;
                Destroy(uiViewItem.gameObject);
                return(true);
            }
        }
        return(false);
    }
예제 #12
0
        public void InitializeObject(string itemCode, string baseItemCode)
        {
            string xml = string.Empty;

            B1Base.DAO.ItemDI itemBaseDI = new B1Base.DAO.ItemDI();
            itemBaseDI.InitializeObject(baseItemCode);
            try
            {
                xml = itemBaseDI.GetXmlForDI();
            }
            finally
            {
                itemBaseDI.FinalizeObject();
            }

            xml = xml.Replace(baseItemCode, itemCode);

            _businessObject = (Items)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oItems);

            _bean = new ItemsBean();

            if (!_businessObject.GetByKey(itemCode))
            {
                _newObject = true;
                _businessObject.ItemCode = itemCode;
            }

            _businessObject.UpdateFromXML(xml);

            _businessObject.Series = 3;
        }
예제 #13
0
    /// <summary>
    /// 在容器中增加新的itemdata
    /// </summary>
    /// <param name="arrayContainer"></param>
    /// <param name="itemId"></param>
    /// <param name="itemNumber"></param>
    /// <returns></returns>
    protected int AddNewItems(ItemsBean[] arrayContainer, long itemId, int itemNumber, string meta)
    {
        ItemsInfoBean itemsInfo = ItemsHandler.Instance.manager.GetItemsInfoById(itemId);

        for (int i = 0; i < arrayContainer.Length; i++)
        {
            ItemsBean itemData = arrayContainer[i];
            if (itemData == null || itemData.itemId == 0)
            {
                ItemsBean newItemData = new ItemsBean(itemId);
                arrayContainer[i] = newItemData;
                int subNumber = itemsInfo.max_number;
                newItemData.meta = meta;
                //如果增加的数量在该道具的上限之内
                if (subNumber >= itemNumber)
                {
                    newItemData.number += itemNumber;
                    itemNumber          = 0;
                    return(itemNumber);
                }
                //如果增加的数量在该道具的上限之外
                else
                {
                    newItemData.number = itemsInfo.max_number;
                    itemNumber        -= subNumber;
                }
            }
        }
        return(itemNumber);
    }
예제 #14
0
    /// <summary>
    /// 设置容器道具 用于初始化
    /// </summary>
    /// <param name="itemsData"></param>
    public void SetViewItem(ItemsBean itemsData)
    {
        //设置展示信息
        ui_ViewItemContainer.SetItemId(itemsData.itemId);

        //如果没有东西,则删除原来存在的
        if (itemsData == null || itemsData.itemId == 0)
        {
            if (currentViewItem != null)
            {
                Destroy(currentViewItem.gameObject);
            }
            currentViewItem = null;
            return;
        }
        //如果有东西,则先实例化再设置数据
        if (currentViewItem == null)
        {
            GameObject obj = Instantiate(gameObject, ui_ViewItemModel.gameObject);
            obj.name        = "ViewItem";
            currentViewItem = obj.GetComponent <UIViewItem>();
            currentViewItem.originalParent       = this;
            currentViewItem.transform.position   = ui_ViewItemModel.transform.position;
            currentViewItem.transform.localScale = ui_ViewItemModel.transform.localScale;
            currentViewItem.transform.rotation   = ui_ViewItemModel.transform.rotation;
        }
        currentViewItem.SetData(itemsData.itemId, itemsData.number, itemsData.meta);

        callBackForSetViewItem?.Invoke(this, itemsData.itemId);
        this.TriggerEvent(EventsInfo.UIViewItemContainer_ItemChange, this, itemsData.itemId);
    }
예제 #15
0
 /// <summary>
 /// 设置数据
 /// </summary>
 /// <param name="itemsData"></param>
 /// <param name="viewIndex"></param>
 public void SetData(ContainerType containerType, ItemsBean itemsData, int viewIndex = 0)
 {
     this.containerType = containerType;
     this.itemsData     = itemsData;
     this.viewIndex     = viewIndex;
     SetViewItem(itemsData);
 }
예제 #16
0
 public override void Use(GameObject user, ItemsBean itemsData, ItemUseTypeEnum useType)
 {
     base.Use(user, itemsData, useType);
     //获取打中的目标
     Collider[] targetArray = TargetCheck(user, itemsData);
     //伤害打中的目标
     DamageTarget(user, itemsData, targetArray);
 }
예제 #17
0
    /// <summary>
    /// 单个数据回调
    /// </summary>
    /// <param name="itemCell"></param>
    public void OnCellForItem(ScrollGridCell itemCell)
    {
        UserDataBean        userData          = GameDataHandler.Instance.manager.GetUserData();
        UIViewItemContainer viewItemContainer = itemCell.GetComponent <UIViewItemContainer>();
        ItemsBean           itemsData         = userData.GetItemsFromBackpack(itemCell.index);

        viewItemContainer.SetData(UIViewItemContainer.ContainerType.Backpack, itemsData, itemCell.index);
    }
예제 #18
0
 public BlockMetaBox(int number)
 {
     items = new ItemsBean[number];
     for (int i = 0; i < items.Length; i++)
     {
         items[i] = new ItemsBean();
     }
 }
예제 #19
0
    /// <summary>
    /// 单个数据回调
    /// </summary>
    /// <param name="itemCell"></param>
    public void OnCellForItem(ScrollGridCell itemCell)
    {
        UIViewItemContainer viewItemContainer = itemCell.GetComponent <UIViewItemContainer>();
        ItemsInfoBean       itemsInfo         = listItemsInfo[itemCell.index];
        ItemsBean           itemsData         = new ItemsBean();

        itemsData.itemId = itemsInfo.id;
        itemsData.number = int.MaxValue;
        viewItemContainer.SetData(UIViewItemContainer.ContainerType.God, itemsData, itemCell.index);
    }
예제 #20
0
    /// <summary>
    /// 获取快捷栏道具
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    public ItemsBean GetItemsFromShortcut(int index)
    {
        ItemsBean itemsData = listShortcutsItems[index];

        if (itemsData == null)
        {
            itemsData = new ItemsBean();
            listShortcutsItems[index] = itemsData;
        }
        return(itemsData);
    }
예제 #21
0
    /// <summary>
    /// 获取背包道具
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    public ItemsBean GetItemsFromBackpack(int index)
    {
        ItemsBean itemsData = listBackpack[index];

        if (itemsData == null)
        {
            itemsData           = new ItemsBean();
            listBackpack[index] = itemsData;
        }
        return(itemsData);
    }
예제 #22
0
    /// <summary>
    /// 处理-瞄准使用道具的目标
    /// </summary>
    public void HandlerForUseItemSightTarget()
    {
        if (!isActiveAndEnabled)
        {
            return;
        }
        //获取道具栏上的物品
        UserDataBean userData  = GameDataHandler.Instance.manager.GetUserData();
        ItemsBean    itemsData = userData.GetItemsFromShortcut();

        ItemsHandler.Instance.UseItemForSightTarget(itemsData);
    }
예제 #23
0
 /// <summary>
 /// 道具数据发生改变的回调
 /// </summary>
 public void CallBackForItemsDataMetaChange(ItemsBean itemsData)
 {
     if (itemsData != this.itemsData)
     {
         return;
     }
     if (currentViewItem == null)
     {
         return;
     }
     currentViewItem.SetData(itemsData.itemId, itemsData.number, itemsData.meta);
 }
예제 #24
0
        public void InitializeObject(string itemCode)
        {
            _businessObject = (Items)Controller.ConnectionController.Instance.Company.GetBusinessObject(BoObjectTypes.oItems);

            _bean = new ItemsBean();

            if (!_businessObject.GetByKey(itemCode))
            {
                _newObject = true;
                _businessObject.ItemCode = itemCode;
            }
        }
예제 #25
0
    /// <summary>
    /// 改变快捷栏
    /// </summary>
    /// <param name="indexForShortcuts"></param>
    public void SetShortcuts(int indexForShortcuts)
    {
        this.indexForShortcuts = indexForShortcuts;
        //改变手中的物品
        Player player = GameHandler.Instance.manager.player;

        if (player != null)
        {
            CreatureCptCharacter character = player.GetCharacter();
            ItemsBean            itemsData = GetItemsFromShortcut();
            character.CharacterItems.ChangeRightHandItem(itemsData.itemId);
        }
    }
예제 #26
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);

                Vector3Int localPosition = targetPosition - chunkForHit.chunk.chunkData.positionForWorld;
                //获取原位置方块
                Block tagetBlock = chunkForHit.chunk.chunkData.GetBlockForLocal(localPosition);

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

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

                //如果上方有方块 则无法种植
                if (upBlock != null && upBlock.blockType != BlockTypeEnum.None)
                {
                    return;
                }

                //种植的方块
                ItemsInfoBean itemsInfo      = GetItemsInfo(itemData.itemId);
                BlockTypeEnum plantBlockType = (BlockTypeEnum)itemsInfo.type_id;
                //初始化meta数据
                BlockMetaCrop blockCropData = new BlockMetaCrop();
                blockCropData.isStartGrow = false;
                blockCropData.growPro     = 0;
                string metaData = BlockBaseCrop.ToMetaData(blockCropData);
                //替换为种植
                chunkForHit.chunk.SetBlockForLocal(upLocalPosition, plantBlockType, BlockDirectionEnum.UpForward, metaData);

                //扣除道具
                UserDataBean userData = GameDataHandler.Instance.manager.GetUserData();
                userData.AddItems(itemData, -1);
                //刷新UI
                UIHandler.Instance.RefreshUI();
            }
        }
    }
예제 #27
0
    /// <summary>
    /// 获取道具破坏的伤害
    /// </summary>
    public virtual int GetBreakDamage(ItemsBean itemsData, Block breakBlock)
    {
        //检测是否能造成伤害
        bool canBreak = breakBlock.blockInfo.CheckCanBreak(itemsData.itemId);

        if (canBreak)
        {
            return(1);
        }
        else
        {
            return(0);
        }
    }
예제 #28
0
 /// <summary>
 ///  创建掉落道具实例
 /// </summary>
 public void CreateItemCptDrop(ItemsBean itemData, Vector3 position, ItemDropStateEnum ItemCptDropState, Vector3 dropDirection)
 {
     if (itemData.itemId == 0)
     {
         return;
     }
     manager.GetItemsObjById(-1, (objModel) =>
     {
         GameObject objCommon    = Instantiate(gameObject, objModel);
         ItemCptDrop ItemCptDrop = objCommon.GetComponent <ItemCptDrop>();
         ItemCptDrop.SetData(itemData, position, dropDirection);
         ItemCptDrop.SetItemDropState(ItemCptDropState);
     });
 }
예제 #29
0
 /// <summary>
 /// 增加道具
 /// </summary>
 public bool AddViewItem(ItemsBean itemsData, Vector3 createPosition)
 {
     //如果已经有一个了 则不能添加
     if (GetViewItem() != null)
     {
         return(false);
     }
     SetData(containerType, itemsData, viewIndex);
     currentViewItem.rectTransform
     .DOAnchorPos(createPosition, timeForAddViewItem)
     .From()
     .SetEase(Ease.OutCubic);
     return(true);
 }
예제 #30
0
 /// <summary>
 /// 使用道具 (默认是破坏)
 /// </summary>
 public virtual void TargetUse(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;
     }
     ItemUseHandle(itemsData, targetPosition, oldBlock, oldBlockDirection, targetChunk);
 }