Esempio n. 1
0
        public void Update()
        {
            if (Game.Instance.AllSystemInited == false)
            {
                return;
            }

            // 自动吃药
            if (mIsUsingHPDrug == false && mUseHPDrugHPRatio > 0f && LocalPlayerManager.Instance.LocalActorAttribute != null)
            {
                long hp    = LocalPlayerManager.Instance.LocalActorAttribute.HP;
                long hpMax = LocalPlayerManager.Instance.LocalActorAttribute.HPMax;
                if (hp > 0 && ((double)hp / (double)hpMax) < mUseHPDrugHPRatio)
                {
                    foreach (uint useHPDrugGoodsId in mUseHPDrugGoodsIds)
                    {
                        if (SceneHelp.Instance.ForbidUseGoods(useHPDrugGoodsId) == false && GoodsHelper.CheckGoodsCanUse(useHPDrugGoodsId) == true && ItemManager.Instance.GetGoodsNumForBagByTypeId(useHPDrugGoodsId) > 0)
                        {
                            if (GoodsHelper.CheckUseGoodsIsInCD(useHPDrugGoodsId) == false)
                            {
                                ItemManager.Instance.UseGoods(useHPDrugGoodsId, 1);
                                mIsUsingHPDrug = true;
                                return;
                            }

                            break;
                        }
                    }
                }
            }
            if (mIsUsingMPDrug == false && mUseMPDrugMPRatio > 0f && LocalPlayerManager.Instance.LocalActorAttribute != null)
            {
                long mp    = LocalPlayerManager.Instance.LocalActorAttribute.MP;
                long mpMax = LocalPlayerManager.Instance.LocalActorAttribute.MPMax;
                if (mp > 0 && ((double)mp / (double)mpMax) < mUseMPDrugMPRatio)
                {
                    foreach (uint useMPDrugGoodsId in mUseMPDrugGoodsIds)
                    {
                        if (SceneHelp.Instance.ForbidUseGoods(useMPDrugGoodsId) == false && GoodsHelper.CheckGoodsCanUse(useMPDrugGoodsId) == true && ItemManager.Instance.GetGoodsNumForBagByTypeId(useMPDrugGoodsId) > 0)
                        {
                            if (GoodsHelper.CheckUseGoodsIsInCD(useMPDrugGoodsId) == false)
                            {
                                ItemManager.Instance.UseGoods(useMPDrugGoodsId, 1);
                                mIsUsingMPDrug = true;
                                return;
                            }

                            break;
                        }
                    }
                }
            }

            // 自动买药
            if (mAutoBuyDrug == true && mIsBuyingDrug == false)
            {
                if (mAutoBuyHPDrugGoodsId > 0)
                {
                    ulong hpDrugNum = ItemManager.Instance.GetGoodsNumForBagByTypeId(mAutoBuyHPDrugGoodsId);
                    if (hpDrugNum < 3)
                    {
                        if (LocalPlayerManager.Instance.GetMoneyByConst((ushort)mAutoBuyHPDrugMoneyType) >= mAutoBuyHPDrugPrice * mAutoBuyHPDrugNum)
                        {
                            BuyGoods(DBMallType.BagShop, mAutoBuyHPDrugGoodsId, mAutoBuyHPDrugNum);
                        }
                    }
                }

                if (mAutoBuyMPDrugGoodsId > 0)
                {
                    ulong mpDrugNum = ItemManager.Instance.GetGoodsNumForBagByTypeId(mAutoBuyMPDrugGoodsId);
                    if (mpDrugNum < 3)
                    {
                        if (LocalPlayerManager.Instance.GetMoneyByConst((ushort)mAutoBuyMPDrugMoneyType) >= mAutoBuyMPDrugPrice * mAutoBuyMPDrugNum)
                        {
                            BuyGoods(DBMallType.BagShop, mAutoBuyMPDrugGoodsId, mAutoBuyMPDrugNum);
                        }
                    }
                }
            }
        }