//使用道具
 private IEnumerator PlayUseItemAction(BattleUnitUseItemAction action)
 {
     if (action.attributeUpdate != null)
     {
         if (action.attributeUpdate.hpChanged != 0)
         {
             PlayDamageLabel(action.attributeUpdate.hpChanged, BattleSkillDamageType.Heal);
         }
         RefreshAttribute(action.attributeUpdate);
     }
     yield break;
 }
Example #2
0
        //使用道具
        public bool UseItem(int itemID, int itemCount)
        {
            if (package != null)
            {
                var item = PackageItemManager.Instance.GetItem(itemID);
                if (item == null)
                {
                    return(false);
                }

                int finalCount = 0;
                int usedCount  = package.TryUseItem(itemID, itemCount, ref finalCount);
                if (usedCount > 0)
                {
                    BattleUnitUseItemAction action = BattleUnitActionEvent.CreateEvent <BattleUnitUseItemAction>(BattleUnitActionType.UseItem, this);
                    action.itemID      = itemID;
                    action.useCount    = usedCount;
                    action.remainCount = finalCount;
                    switch (item.itemType)
                    {
                    case PackageItemType.Recover:
                        action.attributeUpdate               = new BattleUnitSyncAttribute();
                        action.attributeUpdate.hpChanged     = Mathf.Min(battleUnitAttribute.maxHp - battleUnitAttribute.hp, item.hpRecovery);
                        action.attributeUpdate.energyChanged = Mathf.Min(battleUnitAttribute.maxEnergy - battleUnitAttribute.energy, item.energyRecovery);
                        action.attributeUpdate.currentHP     = battleUnitAttribute.hp + action.attributeUpdate.hpChanged;
                        action.attributeUpdate.currentEnergy = battleUnitAttribute.energy + action.attributeUpdate.energyChanged;

                        //自身属性更新
                        battleUnitAttribute.hp     = action.attributeUpdate.currentHP;
                        battleUnitAttribute.energy = action.attributeUpdate.currentEnergy;

                        break;

                    default:
                        break;
                    }
                    battleField.AppendBattleAction(action);
                }

                return(usedCount > 0);
            }
            else
            {
                UtilityHelper.LogError(string.Format("Use item failed, no package : {0} -> {1}", battleUnitAttribute.battleUnitName, itemID));
                return(false);
            }
        }