Unity3D自学笔记——UGUI背包系统(九)装备对HP影响的逻辑及使用药品

装备对HP影响的逻辑及使用药品

装备对HP影响的逻辑

这里写图片描述
背包中有加血属性的装备穿戴在身上后,应该只影响角色最大血量,不影响当前血量
这里写图片描述

使用药品

对当前属性的变更,切变更后的属性不能超过最大值。Status更改后,同样发起事件,通知监控对象,如头像面板进行值的改变,背包物品减少。

 /// <summary>
    /// 使用药水
    /// </summary>
    /// <param name="item"></param>
    public void DrinkPotion(ItemStatus item)
    {
        this.status.HpCur = this.status.HpCur + item.status.Hp > this.status.HpMax ? this.status.HpMax : this.status.HpCur + item.status.Hp;
        this.status.MpCur = this.status.MpCur + item.status.Mp > this.status.MpMax ? this.status.MpMax : this.status.MpCur + item.status.Mp;
        this.status.AtkCur = this.status.AtkCur + item.status.Atk > this.status.AtkMax ? this.status.AtkMax : this.status.AtkCur + item.status.Atk;
        this.status.DefCur = this.status.DefCur + item.status.Def > this.status.DefMax ? this.status.DefMax : this.status.DefCur + item.status.Def;
        this.status.SpdCur = this.status.SpdCur + item.status.Spd > this.status.SpdMax ? this.status.SpdMax : this.status.SpdCur + item.status.Spd;
        this.status.CriticalRateCur = this.status.CriticalRateCur + this.status.CriticalRateMax > this.status.CriticalRateMax ? this.status.CriticalRateMax : this.status.CriticalRateCur + item.status.CriticalRate;
        this.status.AtkSpdCur = this.status.AtkSpdCur + item.status.AtkSpd > this.status.AtkSpdMax ? this.status.AtkSpdMax : this.status.AtkSpdCur + item.status.AtkSpd;
        this.status.AtkRangeCur = this.status.AtkRangeCur + item.status.AtkRange > this.status.AtkRangeMax ? this.status.AtkRangeMax : this.status.AtkRangeCur + item.status.AtkRange;
        this.status.HitCur = this.status.HitCur + item.status.Hit > this.status.HitMax ? this.status.HitMax : this.status.HitCur + item.status.Hit;

        if (this.DrinkedPotion != null)
            this.DrinkedPotion(item);
    }

喝+150的药
这里写图片描述
血量补满, 血瓶数量减少
这里写图片描述

PlayerInfo
发生装备更改,喝药水,都刷新属性

 private void PlayerDrinkedPotion(ItemStatus obj)
    {
        RefreshStatus();
    }

    private void PlayerChangedEquip()
    {
        RefreshStatus();
    }

    private void RefreshStatus()
    {
        this.m_TxtLv.text = "." + this.m_PlayerStatus.Lv.ToString();
        this.m_TxtHp.text = string.Format("{0}/{1}", this.m_PlayerStatus.status.HpCur, this.m_PlayerStatus.status.HpMax);
        this.m_TxtMp.text = string.Format("{0}/{1}", this.m_PlayerStatus.status.MpCur, this.m_PlayerStatus.status.MpMax);
        this.m_SldHp.value = this.m_PlayerStatus.status.HpCur / this.m_PlayerStatus.status.HpMax;
        this.m_SldMp.value = this.m_PlayerStatus.status.MpCur / this.m_PlayerStatus.status.MpMax;
        this.m_SldExp.value = (float)(this.m_PlayerStatus.Exp / this.m_PlayerStatus.ExpMax);
    }

UIInventory
移除物品
移除物品逻辑是先减数量,数量为0则销毁,否则更新显示

 private void PlayerDrinkedPotion(ItemStatus item)
    {
        RemoveItem(item);
    }

public void RemoveItem(ItemStatus itemStatus)
    {
        itemStatus.Count -= 1;

        if (itemStatus.Count == 0)
        {//销毁物品
            this.m_ItemList.Remove(itemStatus.ItemID);
            DestroyImmediate(itemStatus.gameObject);
        }
        else
        {//更新数量显示
            itemStatus.gameObject.GetComponent<UIItem>().UpdateCount();
        }

        RefreshPartGrid();
    } 
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值