コード例 #1
0
 public void ChangeState(SActor actor, UpdateStateMachine updateStateMachine, ActorState state, float duration)
 {
     actor.ChangeStateServerSide(state, duration);
     actor.BeginState = Timing.sInstance.GetFrameStartTime();
     NetworkManagerServer.sInstance.SetStateDirty(actor.GetNetworkId(), actor.WorldId, (uint)Actor.ReplicationState.State);
     this.updateStateMachine = updateStateMachine;
 }
コード例 #2
0
        /// <summary>
        /// AI 컨트롤러로 위임.
        /// 최초 할당한 유저 값만 의미가 있고 이후 위임한 유저의 값은 의미가 없음
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="original_actor"></param>
        public void Possess(SActor actor, SActor original_actor)
        {
            // 기존 유저 정보를 바탕으로 ai컨트롤러 초기화
            if (original_actor.GetActorController() != null)
            {
                mSessionId         = original_actor.GetActorController().mSessionId;
                mSelectedCharacter = original_actor.GetActorController().mSelectedCharacter;
                UserId             = original_actor.GetActorController().UserId;
                mCharacterLevel    = original_actor.GetActorController().mCharacterLevel;
            }
            mNetworkId       = original_actor.GetNetworkId();
            mPlayerId        = original_actor.GetPlayerId();
            ControllPlayerId = actor.GetPlayerId();

            Log.Information($"ai Possess original player_id{mPlayerId}, attached player_id{actor.GetPlayerId()}");

            // ai 할당되었음을 동기화
            actor.AIPlayers.Add(mNetworkId);
            NetworkManagerServer.sInstance.SetStateDirty(actor.GetNetworkId(), actor.WorldId, (uint)Actor.ReplicationState.AI);

            original_actor.SetController(this);

            // 순환 참조 방지
            if (actor != original_actor)
            {
                actor.GetActorController().AIControllers.Add(this);
            }

            World.Instance(original_actor.WorldId).aiList[original_actor.GetPlayerId()] = original_actor;
        }
コード例 #3
0
        /// <summary>
        /// 해당 객체에서 컨트롤로를 때어냄
        /// </summary>
        /// <param name="actor"></param>
        public void Unpossess(SActor actor)
        {
            Log.Information($"ai Unpossess original player_id{mPlayerId}, network_id{mNetworkId}");

            actor.AIPlayers.Remove(this.mNetworkId);
            NetworkManagerServer.sInstance.SetStateDirty(actor.GetNetworkId(), actor.WorldId, (uint)Actor.ReplicationState.AI);

            //actor.SetController(null);

            World.Instance(actor.WorldId).aiList.Remove(mPlayerId);
        }
コード例 #4
0
        public void UpdateDash(SActor actor)
        {
            if (actor.EndState <= Timing.sInstance.GetFrameStartTime())
            {
                actor.mActorController?.GetUnprocessedMoveList().Clear();

                actor.SetLocation(actor.TargetPos);
                actor.SetVelocity(Vector3.zero);
                Log.Information($"end dash pos {actor.TargetPos.ToString()}");
                ChangeState(actor, UpdateIdle, ActorState.Idle, 0f);
                NetworkManagerServer.sInstance.SetStateDirty(actor.GetNetworkId(), actor.WorldId, (uint)Actor.ReplicationState.Pose);
            }
        }
コード例 #5
0
        public void UpdateGhost(SActor actor)
        {
            if (actor.EndState <= Timing.sInstance.GetFrameStartTime())
            {
                actor.mActorController?.GetUnprocessedMoveList().Clear();

                actor.SetLocation(actor.TargetPos);
                actor.SetVelocity(Vector3.zero);
                actor.degree = actor.SpawnAngle;
                actor.HiddenMapObjects.Clear();
                actor.killPlayerId = 0;

                LogHelper.LogInfo($"end ghost pos {actor.TargetPos.ToString()}");
                ChangeState(actor, UpdateIdle, ActorState.Idle, 0f);
                NetworkManagerServer.sInstance.SetStateDirty(actor.GetNetworkId(), actor.WorldId, (uint)Actor.ReplicationState.Spawn);

                actor.AddSpellMySelf(core.BuffType.Invincible);
                World.Instance(actor.WorldId).GameMode.game_mode.OnTrigger(actor.WorldId, actor.GetPlayerId(), PlayPointID.PlayerReborn);
            }
        }
コード例 #6
0
        public int HandleNewClient()
        {
            int  playerId = this.GetPlayerId();
            byte worldId  = this.GetWorldId();

            if (World.Instance(worldId).playerList.ContainsKey(playerId))
            {
                Log.Information($"already exist player {playerId}");
                return(0);
            }

            if (World.Instance(worldId).playerList.Count(x => ((SActor)x.Value).GetSessionId() == this.mSessionId) > 0)
            {
                Log.Information($"already exist player {playerId}, {this.mSessionId}");
                return(0);
            }

            SActor actor = null;

            if (EnableAiSwitch)
            {
                // 다른 플레이어가 AI로 제어중이라면 제어권을 다시 가져온다.
                actor = RestoreAI();
            }

            if (actor == null)
            {
                foreach (var entity in World.Instance(worldId).GameMode.GetEntries())
                {
                    if (entity.GetPlayerId() == playerId)
                    {
                        actor = (SActor)NetworkManagerServer.sInstance.GetGameObject(entity.mNetworkId, worldId);
                        Log.Information($"found reserved actor player id : {playerId}, session id : {this.mSessionId}, network id : {entity.mNetworkId}");
                        Possess(actor);
                        break;
                    }
                }
            }

            // AI 컨트롤러가 없었다면 새로운 객체 할당
            if (actor == null)
            {
                actor = SpawnActor(playerId, worldId, this.mTeam, this.mSpawnIndex);
                Possess(actor);
                //if (Possess(actor) == false)
                //{
                //    NetworkManagerServer.sInstance.UnregisterGameObject(actor);
                //    NetworkManagerServer.sInstance.CancelGameObject(actor);
                //    World.Instance(worldId).RemoveGameObject(actor);
                //    Log.Information($"SpawnActor error player_id{playerId}, network_id{actor.NetworkId}, world{worldId}, pos{actor.GetLocation()}");

                //    World.Instance(worldId).GameMode.LeaveEntry(playerId);
                //    Log.Information($"HandleNewClient error {playerId}, {this.mSessionId}");
                //    return 0;
                //}
            }

            World.Instance(worldId).playerList.Add(playerId, actor);

#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_IOS || UNITY_ANDROID
#else
            Cache.sInstance.AddUser(worldId);
#endif

            this.IsStartedPlay = true;

            return(actor.GetNetworkId());
        }
コード例 #7
0
        public SActor SpawnActor(int inPlayerId, byte worldId, int team, int spawn_index)
        {
            SActor actor = (SActor)GameObjectRegistry.sInstance.CreateGameObject((UInt32)GameObjectClassId.Actor, true, worldId);

            var entry = World.Instance(worldId).GameMode.AddEntry(inPlayerId, this.mSessionId.ToString(), (ushort)team, spawn_index, actor.GetNetworkId());

            actor.SpawnPoint = World.spawn_position[entry.seat].mapPos;
            actor.SpawnAngle = new Vector2(World.spawn_position[entry.seat].startVector.x, World.spawn_position[entry.seat].startVector.z).Angle();
            actor.degree     = actor.SpawnAngle;
            actor.SetWorldId(worldId);
            actor.SetLocation(actor.SpawnPoint);
            actor.SetPhysics();
            actor.Team = entry.GetTeam();
            actor.SetPlayerId(inPlayerId);

            //gotta pick a better spawn location than this...

            //actor.SetLocation(core.Utility.GetRandomVector(-10, 10, 0));
            actor.SetCharacter(mSelectedCharacter, mCharacterLevel, UserId);

            Log.Information($"SpawnActor player_id{inPlayerId}, UserID:{actor.UserId}, network_id{actor.NetworkId}, world{worldId}, idx{entry.seat}, pos{actor.GetLocation()}, angle{actor.degree}, direction({World.spawn_position[entry.seat].startVector.x},{World.spawn_position[entry.seat].startVector.z})");

            return(actor);
        }