コード例 #1
0
        protected void OnVisitorGetRandomLittleZooApply(Message msg)
        {
            var _msg   = msg as VisitorGetRandomLittleZooApply;
            var entity = EntityManager.GetInstance().GetEntityMovable(_msg.entityID) as EntityVisitor;

            int groupID = entity.stayGroupID;

            if (_msg.isFirstApply)
            {
                //groupID = GlobalDataManager.GetInstance().logicTableGroup.sortedGroupID[0];
                var playerData = GlobalDataManager.GetInstance().playerData;
                groupID = GlobalDataManager.GetInstance().logicTableGroup.GetSortedGroupIDs(sceneID)[0];
            }

            openedLittleZooIDs.Clear();

            bool retCode     = false;
            int  nextGroupID = Const.Invalid_Int;

            while (true)
            {
                retCode = GetOpenedLittleZooIDs(groupID, openedLittleZooIDs);
                if (!retCode)
                {
                    //失败
                    VisitorGetRandomLittleZooReply.Send(_msg.entityID, false, Const.Invalid_Int, Const.Invalid_Int, false, null);
                    return;
                }

                //wouldGotoLittleZooIDs = //从开放的动物栏中 剔除 去过的
                retCode = GetWouldGotoLittleZooIDs(entity, groupID, openedLittleZooIDs, wouldGotoLittleZooIDs);
                if (!retCode)
                {
                    //retCode = GlobalDataManager.GetInstance().logicTableGroup.GetNextGroupID(groupID, ref nextGroupID);
                    retCode = GlobalDataManager.GetInstance().logicTableGroup.GetNextGroupID(sceneID, groupID, ref nextGroupID);
                    if (!retCode)
                    {
                        //找下一组失败
                        VisitorGetRandomLittleZooReply.Send(_msg.entityID, false, Const.Invalid_Int, Const.Invalid_Int, false, null);
                        return;
                    }
                    groupID = nextGroupID;
                }
                else
                {
                    break;
                }
            }

            //构建 wouldGotoLittleZooIDs 对应的权重
            retCode = GetWouldGotoWeights(groupID, wouldGotoLittleZooIDs, wouldGotoWeights);
            if (!retCode)
            {
                //失败
                VisitorGetRandomLittleZooReply.Send(_msg.entityID, false, Const.Invalid_Int, Const.Invalid_Int, false, null);
                return;
            }

            int idx = Const.Invalid_Int;

            Math_F.TableProbability(wouldGotoWeights, ref idx);

            int littleZooID = wouldGotoLittleZooIDs[idx];

            EntityVisitor.RecordVisitedLittleZoo(entity, groupID, littleZooID);

            VisitorGetRandomLittleZooReply.Send(_msg.entityID, true, groupID, littleZooID, false, null);
        }