Пример #1
0
        public void AddFriendByName(string name, RELATION_GROUP nGroup)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }
            int group  = -1;
            int nIndex = -1;

            if (CDataPool.Instance.GetRelation().GetRelationByName(name, ref group, ref nIndex)
                != RELATION_TYPE.RELATION_TYPE_STRANGER)
            {
                return;
            }

            CObject_Character pTargetObj = CObjectManager.Instance.FindCharacterByName(name);

            if (pTargetObj == CObjectManager.Instance.getPlayerMySelf())
            {
                return;
            }
            if (pTargetObj is CObject_PlayerOther)
            {
                ENUM_RELATION sCamp = Interface.GameInterface.Instance.GetCampType(pTargetObj, CObjectManager.Instance.getPlayerMySelf());
                if (sCamp != ENUM_RELATION.RELATION_FRIEND)
                {// 如果不是同一阵营的
                    GameProcedure.s_pEventSystem.PushEvent(GAME_EVENT_ID.GE_INFO_SELF, "不能添加不同阵营的人到好友");
                    return;
                }
            }
            CGRelation Msg = new CGRelation();

            Msg.GetRelation().CleanUp();
            Msg.GetRelation().m_Type = (byte)RELATION_REQUEST_TYPE.REQ_ADDFRIEND;
            REQUEST_ADD_RELATION_WITH_GROUP pFriend = new REQUEST_ADD_RELATION_WITH_GROUP();

            Msg.GetRelation().mRelation = pFriend;
            pFriend.CleanUp();
            pFriend.SetTargetName(EncodeUtility.Instance.GetGbBytes(name));
            pFriend.SetGroup((byte)nGroup);
            pFriend.SetRelationType((byte)RELATION_TYPE.RELATION_TYPE_FRIEND);

            NetManager.GetNetManager().SendPacket(Msg);
        }
Пример #2
0
        //加入好友功能(包括好友、临时好友、黑名单)
        public void addFriend(RELATION_GROUP nGroup, string name)
        {
            string            strva    = name;
            CGRelation        Msg      = new CGRelation();
            CObject_Character pCharObj = null;

            Msg.GetRelation().m_Type = (byte)RELATION_REQUEST_TYPE.REQ_ADDFRIEND;
            REQUEST_ADD_RELATION_WITH_GROUP pFriend = new REQUEST_ADD_RELATION_WITH_GROUP();

            Msg.GetRelation().mRelation = pFriend;
            pFriend.CleanUp();

            bool valueIsNum = false;                                /*Ogre::StringConverter::isNumber(strva.c_str());*/

            if (nGroup == RELATION_GROUP.RELATION_GROUP_FRIEND_ALL) // 如果直接一个名字,就自动往所有的列表里加,
            {
                nGroup = RELATION_GROUP.RELATION_GROUP_F1;
            }
            else if (nGroup == RELATION_GROUP.RELATION_GROUP_TEMPFRIEND) //临时好友
            {
                SDATA_RELATION_MEMBER pMember = new SDATA_RELATION_MEMBER();

                if (!valueIsNum)
                {
                    pCharObj = (CObject_Character)CObjectManager.Instance.FindCharacterByName(strva);
                    if (pCharObj == null)
                    {
                        return;
                    }
                    pMember.m_szName = strva;
                }
                else
                {
                    pCharObj = (CObject_Character)CObjectManager.Instance.GetMainTarget();
                    if (pCharObj == null)
                    {
                        return;
                    }
                    pMember.m_szName = pCharObj.GetCharacterData().Get_Name();
                }
                // 如果是玩家并且是统一阵营的才会添加
                ENUM_RELATION sCamp = Interface.GameInterface.Instance.GetCampType(pCharObj, CObjectManager.Instance.getPlayerMySelf());
                if ((pCharObj is CObject_PlayerOther) == false)
                {
                    return;
                }
                if (sCamp != ENUM_RELATION.RELATION_FRIEND)
                {
                    return;
                }

                int nTmpGroup = -1, nIndex = -1;
                CDataPool.Instance.GetRelation().GetRelationByName(pMember.m_szName, ref nTmpGroup, ref nIndex);
                if (nTmpGroup >= 0)
                {
                    return;
                }

                pMember.m_RelationType = RELATION_TYPE.RELATION_TYPE_TEMPFRIEND;
                if (CDataPool.Instance.GetRelation().AddRelation(RELATION_GROUP.RELATION_GROUP_TEMPFRIEND, pMember))
                {
                    string szText = "你将" + pMember.m_szName + " 添加为临时好友";
                    GameProcedure.s_pEventSystem.PushEvent(GAME_EVENT_ID.GE_INFO_SELF, szText);
                }
                CEventSystem.Instance.PushEvent(GAME_EVENT_ID.GE_UPDATE_FRIEND);
                return;
            }
            else if (nGroup == RELATION_GROUP.RELATION_GROUP_BLACK)
            { // 增加黑名单的添加
                CGRelation Msg1                 = new CGRelation();
                Msg1.GetRelation().m_Type       = (byte)RELATION_REQUEST_TYPE.REQ_ADDTOBLACKLIST;
                REQUEST_ADD_RELATION pBlackName = new REQUEST_ADD_RELATION();
                Msg1.GetRelation().mRelation    = pBlackName;
                pBlackName.CleanUp();

                if (strva == "")
                {
                    pCharObj = (CObject_Character)CObjectManager.Instance.GetMainTarget();
                    if (pCharObj == null)
                    {
                        return;
                    }
                    pBlackName.SetTargetName(EncodeUtility.Instance.GetGbBytes(pCharObj.GetCharacterData().Get_Name()));
                }
                else if (valueIsNum)
                {
//                      pCharObj = (CObject_Character)CObjectManager.Instance.FindCharacterByRaceID(int.Parse(strva));
//                      if( pCharObj == null ) pCharObj = (CObject_Character*)CObjectManager::GetMe()->FindCharacterByName(strva.c_str());
//                      if( pCharObj == null ) return ;
//                      pBlackName->SetTargetGUID( Ogre::StringConverter::parseInt(strva.c_str()) );
                }
                else
                {
                    pCharObj = (CObject_Character)CObjectManager.Instance.FindCharacterByName(strva);
                    if (pCharObj == null)
                    {
                        return;
                    }
                    pBlackName.SetTargetName(EncodeUtility.Instance.GetGbBytes(strva));
                }

                if (pCharObj == CObjectManager.Instance.getPlayerMySelf())
                {
                    return;
                }

                if (pCharObj is CObject_PlayerOther)        // 如果是玩家
                {
                    ENUM_RELATION sCamp = Interface.GameInterface.Instance.GetCampType(pCharObj, CObjectManager.Instance.getPlayerMySelf());
                    if (sCamp != ENUM_RELATION.RELATION_FRIEND)
                    {
                        GameProcedure.s_pEventSystem.PushEvent(GAME_EVENT_ID.GE_INFO_SELF, "不能添加不同阵营的人到黑名单");
                        return;
                    }
                }
                else
                {
                    GameProcedure.s_pEventSystem.PushEvent(GAME_EVENT_ID.GE_INFO_SELF, "不能添加非玩家到黑名单");
                    return;
                }

                pBlackName.SetRelationType((byte)RELATION_TYPE.RELATION_TYPE_BLACKNAME);
                NetManager.GetNetManager().SendPacket(Msg1);
                return;
            }

            if (strva == "")
            {
                pCharObj = (CObject_Character)CObjectManager.Instance.GetMainTarget();
                if (pCharObj == null)
                {
                    return;
                }
                pFriend.SetTargetName(EncodeUtility.Instance.GetGbBytes(pCharObj.GetCharacterData().Get_Name()));
            }
            else if (valueIsNum)
            {
//              pCharObj = (CObject_Character)CObjectManager::GetMe()->FindCharacterByRaceID(Ogre::StringConverter::parseInt(strva.c_str()));
//              if( pCharObj == NULL ) pCharObj = (CObject_Character*)CObjectManager::GetMe()->FindCharacterByName(strva.c_str());
//              if( pCharObj == NULL ) return 0;
//              pFriend->SetTargetGUID( Ogre::StringConverter::parseInt(strva.c_str()) );
            }
            else
            {
                pFriend.SetTargetName(EncodeUtility.Instance.GetGbBytes(strva));
                pCharObj = (CObject_Character)CObjectManager.Instance.FindCharacterByName(strva);
                if (pCharObj == null)
                {
                    return;
                }
            }
            if (pCharObj == CObjectManager.Instance.getPlayerMySelf())      // 如果是自己,就不加
            {
                return;
            }

            if (pCharObj is CObject_PlayerOther)       // 如果是玩家
            {
                ENUM_RELATION sCamp = Interface.GameInterface.Instance.GetCampType(pCharObj, CObjectManager.Instance.getPlayerMySelf());
                if (sCamp != ENUM_RELATION.RELATION_FRIEND)             // 如果不是同一阵营的
                {
                    GameProcedure.s_pEventSystem.PushEvent(GAME_EVENT_ID.GE_INFO_SELF, "不能添加不同阵营的人到好友");
                    return;
                }
//              // 改为势力判断 [9/26/2011 Ivan edit]
//              if (pCharObj.GetCharacterData().GetShiLi() !=
//                  CObjectManager::GetMe()->GetMySelf()->GetCharacterData()->GetShiLi())
//              {
//                  CGameProcedure::s_pEventSystem->PushEvent( GE_INFO_SELF, "不能添加不同势力的人到好友" );
//                  return 0;
//              }
            }
            else
            {
                GameProcedure.s_pEventSystem.PushEvent(GAME_EVENT_ID.GE_INFO_SELF, "不能添加非玩家到好友");
                return;
            }

            pFriend.SetGroup((byte)nGroup);
            pFriend.SetRelationType((byte)RELATION_TYPE.RELATION_TYPE_FRIEND);

            NetManager.GetNetManager().SendPacket(Msg);

            return;
        }