Пример #1
0
    /// <summary>
    /// 使用瞬药
    /// </summary>
    public void UseAtOnceMedicine()
    {
        bool canRunning = Engine.Utility.EventEngine.Instance().DispatchVote((int)GameVoteEventID.AUTORECOVER, null);

        if (!canRunning)
        {
            Engine.Utility.Log.LogGroup("ZCX", "canRunning false");
            return;
        }

        //是否可以使用瞬药
        bool canUseAtOnce = Engine.Utility.EventEngine.Instance().DispatchVote((int)GameVoteEventID.AUTOAtOnceRECOVER, null);

        if (!canUseAtOnce)
        {
            Engine.Utility.Log.LogGroup("ZCX", "canUseAtOnce false");
            return;
        }

        Client.IPlayer mainPlayer = Client.ClientGlobal.Instance().MainPlayer;
        if (mainPlayer == null || mainPlayer.IsDead())
        {
            Engine.Utility.Log.LogGroup("ZCX", "player dead");
            return;
        }
        Dictionary <AutoRecoverGrid.MedicalType, UseMedicalInfo> .Enumerator iter = m_dicMedical.GetEnumerator();
        while (iter.MoveNext())
        {
            UseMedicalInfo medical = iter.Current.Value;
            if (medical != null && medical.select)
            {
                AutoRecoverGrid.MedicalType mtype = medical.Type;
                float rate = 1f;
                if (AutoRecoverGrid.MedicalType.HpAtOnce == mtype)
                {//瞬药 单独处理
                    rate = mainPlayer.GetProp((int)CreatureProp.Hp) * 1f / mainPlayer.GetProp((int)CreatureProp.MaxHp);

                    if (rate < medical.triggerValue)
                    {
                        uint itemid = medical.itemid;
                        if (itemid != 0 && CanUse(itemid))
                        {
                            List <BaseItem> itemdataList = DataManager.Manager <ItemManager>().GetItemByBaseId(itemid);
                            if (itemdataList.Count > 0)
                            {
                                DataManager.Instance.Sender.UseItem(
                                    mainPlayer.GetID(),
                                    (uint)GameCmd.SceneEntryType.SceneEntry_Player,
                                    itemdataList[0].QWThisID, 1);
                            }
                        }
                    }
                }
            }
        }
    }
Пример #2
0
    private void UseMedicine()
    {
        bool canRunning = Engine.Utility.EventEngine.Instance().DispatchVote((int)GameVoteEventID.AUTORECOVER, null);

        if (!canRunning)
        {
            Engine.Utility.Log.LogGroup("ZCX", "canRunning false");
            return;
        }

        Client.IPlayer mainPlayer = Client.ClientGlobal.Instance().MainPlayer;
        if (mainPlayer == null || mainPlayer.IsDead())
        {
            Engine.Utility.Log.LogGroup("ZCX", "player dead");
            return;
        }
        Dictionary <AutoRecoverGrid.MedicalType, UseMedicalInfo> .Enumerator iter = m_dicMedical.GetEnumerator();
        while (iter.MoveNext())
        {
            UseMedicalInfo medical = iter.Current.Value;
            if (medical != null && medical.select)
            {
                AutoRecoverGrid.MedicalType mtype = medical.Type;
                float rate = 1f;
                if (AutoRecoverGrid.MedicalType.HpAtOnce == mtype)
                {//瞬药 单独处理
                    continue;
                }
                if (AutoRecoverGrid.MedicalType.Hp == mtype || (AutoRecoverGrid.MedicalType.HpAtOnce == mtype))
                {
                    rate = mainPlayer.GetProp((int)CreatureProp.Hp) * 1f / mainPlayer.GetProp((int)CreatureProp.MaxHp);
                }
                else if (AutoRecoverGrid.MedicalType.Mp == mtype)
                {
                    rate = mainPlayer.GetProp((int)CreatureProp.Mp) * 1f / mainPlayer.GetProp((int)CreatureProp.MaxMp);
                    // string log = string.Format("rate = {0} trigger = {1} mp = {2} max= {3}", rate, medical.triggerValue, mainPlayer.GetProp((int)CreatureProp.Mp), mainPlayer.GetProp((int)CreatureProp.MaxMp));
                    //UnityEngine.Debug.LogError(log);
                }
                else if (AutoRecoverGrid.MedicalType.PetHp == mtype)
                {
                    if (DataManager.Manager <PetDataManager>().CurFightingPet == 0)
                    {
                        continue;
                    }
                    Client.INPC pet = DataManager.Manager <PetDataManager>().GetNpcByPetID(DataManager.Manager <PetDataManager>().CurFightingPet);
                    if (pet != null)
                    {
                        int a = pet.GetProp((int)CreatureProp.Hp);
                        rate = pet.GetProp((int)CreatureProp.Hp) * 1f / pet.GetProp((int)CreatureProp.MaxHp);
                    }
                }

                if (rate < medical.triggerValue)
                {
                    uint itemid = medical.itemid;
                    if (AutoRecoverGrid.MedicalType.Hp == mtype)
                    {
                        if (UnityEngine.Time.realtimeSinceStartup - m_nhpsendTime < 5f)
                        {
                            continue;
                        }
                        itemid = GetUseItemId(mtype);
                    }
                    else if (AutoRecoverGrid.MedicalType.Mp == mtype)
                    {
                        if (UnityEngine.Time.realtimeSinceStartup - m_nmpsendTime < 5f)
                        {
                            continue;
                        }
                        itemid = GetUseItemId(mtype);
                    }
                    if (itemid != 0 && CanUse(itemid))
                    {
                        List <BaseItem> itemdataList = DataManager.Manager <ItemManager>().GetItemByBaseId(itemid);
                        if (itemdataList.Count > 0)
                        {
                            if (AutoRecoverGrid.MedicalType.PetHp == mtype)
                            {
                                uint petID = DataManager.Manager <PetDataManager>().GetNpcIDByPetID(DataManager.Manager <PetDataManager>().CurFightingPet);
                                DataManager.Instance.Sender.UseItem(
                                    petID,
                                    (uint)GameCmd.SceneEntryType.SceneEntry_NPC,
                                    itemdataList[0].QWThisID, 1);
                            }
                            else
                            {
                                DataManager.Instance.Sender.UseItem(
                                    mainPlayer.GetID(),
                                    (uint)GameCmd.SceneEntryType.SceneEntry_Player,
                                    itemdataList[0].QWThisID, 1);

                                if (AutoRecoverGrid.MedicalType.Hp == mtype)
                                {
                                    m_nhpsendTime = UnityEngine.Time.realtimeSinceStartup;
                                }
                                else if (AutoRecoverGrid.MedicalType.Mp == mtype)
                                {
                                    m_nmpsendTime = UnityEngine.Time.realtimeSinceStartup;
                                }
                            }

                            //                            if (UnityEngine.Application.isEditor)
                            //                           {
                            //                               UnityEngine.Debug.Log(string.Format("使用物品 {0}" , itemid));
                            //                          }
                        }
                    }
                }
            }
        }
    }