public AIController CreateAI(byte character_id, string user_id, byte world_id, Guid session_id, int team, int player_id, int spawn_index, int characterLevel)
        {
            AIController aiController = new AIController();

            aiController.mSelectedCharacter = character_id;
            aiController.UserId             = user_id;
            aiController.mSessionId         = session_id;
            aiController.mPlayerId          = player_id != 0 ? player_id : GetNewPlayerId(world_id);
            aiController.mWorldId           = world_id;
            aiController.mCharacterLevel    = characterLevel;
            Log.Information($"Create AI playerId:{aiController.mPlayerId}, character:{aiController.mSelectedCharacter}, userId:{aiController.UserId}, session:{aiController.mSessionId}");
            var actor = aiController.SpawnActor(aiController.mPlayerId, world_id, team, spawn_index);

            aiController.Possess(actor, actor);

            return(aiController);
        }
Example #2
0
        public void Unpossess(SActor actor, PlayerController newPlayerController, AIController aiController)
        {
            Log.Information($"player Unpossess player_id{actor.GetPlayerId()}, network_id{actor.NetworkId}, world{actor.WorldId}");

            // 새로운 플레이어컨트롤로 교체인 경우
            if (newPlayerController != null)
            {
                actor.SetController(newPlayerController);
                return;
            }

            World.Instance(actor.WorldId).GameMode.LeaveEntry(mPlayerId);

            if (EnableAiSwitch)
            {
                // 남은 플레이어중에서 ai가 가장 적게 할당된 유저에게 할당
                var otherActor = GetAppropriateActorAIPossess(mWorldId, GetPlayerId());
                if (otherActor != null)
                {
                    if (aiController == null)
                    {
                        // 최초 AI컨트롤러로 위임
                        aiController = new AIController();
                        aiController.Possess(otherActor, actor);
                    }
                    else
                    {
                        // 새로운 곳에 붙임
                        aiController.Possess(otherActor, actor);
                    }

                    // AI 교체 완료
                    return;
                }
            }

            // 기본적으로 해당 객체에 컨트롤러를 널로 초기화
            actor.SetController(null);
        }