Exemplo n.º 1
0
        public void ExecuteUserCmd(IPlayerUserCmdGetter getter, IUserCmd cmd)
        {
            if (cmd.IsUseAction && cmd.UseType == (int)EUseActionType.Door)
            {
                var entity =
                    _mapContext.GetEntityWithEntityKey(new EntityKey(cmd.UseEntityId, (int)EEntityType.MapObject));

                if (getter.OwnerEntity != null)
                {
                    var player = (PlayerEntity)getter.OwnerEntity;
                    if (player != null && player.hasGamePlay)
                    {
                        player.gamePlay.UseEntityId = cmd.UseEntityId;
                    }
                }

                if (entity == null && (SharedConfig.IsServer || SharedConfig.IsOffline))
                {
                    _listener.CreateMapObj(cmd.UseEntityId);
                    entity = _mapContext.GetEntityWithEntityKey(new EntityKey(cmd.UseEntityId, (int)EEntityType.MapObject));
                    if (entity == null)
                    {
                        _logger.ErrorFormat("Door Entity {0} does not exist!", cmd.UseEntityId);
                        return;
                    }
                }

                if (!SharedConfig.IsServer && !SharedConfig.IsOffline)
                {
                    var player = (PlayerEntity)getter.OwnerEntity;
                    player.autoMoveInterface.PlayerAutoMove.StopAutoMove();
                    player.StateInteractController().InterruptCharactor();
                    player.stateInterface.State.OpenDoor();
                    return;
                }

                var door = entity as MapObjectEntity;
                if (door == null)
                {
                    _logger.ErrorFormat("entity {0} is not door", cmd.UseEntityId);
                }

                if (!door.hasDoorRotate && door.doorData.IsOpenable())
                {
                    var player = (PlayerEntity)getter.OwnerEntity;
                    player.autoMoveInterface.PlayerAutoMove.StopAutoMove();
                    var go             = door.rawGameObject.Value;
                    var playerPosition = player.RootGo().transform.position;
                    var doorPosition   = go.transform.position;

                    var direction = (playerPosition - doorPosition);
                    var dot       = Vector3.Dot(direction, go.transform.forward);

                    var rot = go.transform.localEulerAngles.y;
                    rot = YawPitchUtility.Normalize(rot);
                    float from = rot, to = 0;
                    var   state    = door.doorData.State;
                    var   endState = state;
                    if (dot > 0)
                    {
                        switch (state)
                        {
                        case (int)DoorState.Closed:
                            to       = from + OpenMaxAngle;
                            endState = (int)DoorState.OpenMax;
                            break;

                        case (int)DoorState.OpenMin:
                            to       = from - OpenMinAngle;
                            endState = (int)DoorState.Closed;
                            break;

                        case (int)DoorState.OpenMax:
                            to       = from - OpenMaxAngle;
                            endState = (int)DoorState.Closed;
                            break;
                        }
                    }
                    else if (dot < 0)
                    {
                        switch (state)
                        {
                        case (int)DoorState.Closed:
                            to       = from + OpenMinAngle;
                            endState = (int)DoorState.OpenMin;
                            break;

                        case (int)DoorState.OpenMin:
                            to       = from - OpenMinAngle;
                            endState = (int)DoorState.Closed;
                            break;

                        case (int)DoorState.OpenMax:
                            to       = from - OpenMaxAngle;
                            endState = (int)DoorState.Closed;
                            break;
                        }
                    }

                    if (endState != state)
                    {
                        player.StateInteractController().InterruptCharactor();
                        player.stateInterface.State.OpenDoor();

                        var         audioId = endState == (int)DoorState.Closed ? EAudioUniqueId.CloseDoor : EAudioUniqueId.OpenDoor;
                        SimpleProto sp      = FreePool.Allocate();
                        sp.Key = FreeMessageConstant.PlaySound;
                        sp.Ks.Add(2);
                        sp.Ins.Add((int)audioId);
                        sp.Bs.Add(true);
                        FreeMessageSender.SendMessage(player, sp);

                        //player.AudioController().PlaySimpleAudio(audioId);
                        if (SharedConfig.IsServer || SharedConfig.IsOffline)
                        {
                            door.doorData.State = (int)DoorState.Rotating;
                            door.AddDoorRotate(from, from, to, endState);
                            _logger.DebugFormat("Trigger Door From {0} {1} To {2} {3}",
                                                state, from, endState, to);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void ExecuteUserCmd(IUserCmdOwner owner, IUserCmd cmd)
        {
            if (cmd.IsUseAction && cmd.UseType == (int)EUseActionType.Door)
            {
                var door = _context.GetEntityWithEntityKey(new Core.EntityComponent.EntityKey(cmd.UseEntityId, (short)EEntityType.MapObject));
                if (door == null)
                {
                    _logger.ErrorFormat("Door Entity {0} does not exist!", cmd.UseEntityId);
                    return;
                }

                if (!door.hasDoorRotate && door.doorData.IsOpenable())
                {
                    var player = (PlayerEntity)owner.OwnerEntity;
                    player.playerMove.InterruptAutoRun();
                    var go             = door.rawGameObject.Value;
                    var playerPosition = player.RootGo().transform.position;
                    var doorPosition   = go.transform.position;

                    var direction = (playerPosition - doorPosition);
                    var dot       = Vector3.Dot(direction, go.transform.forward);

                    var rot = go.transform.localEulerAngles.y;
                    rot = YawPitchUtility.Normalize(rot);
                    float from = rot, to = 0;
                    var   state    = door.doorData.State;
                    var   endState = state;
                    if (dot > 0)
                    {
                        switch (state)
                        {
                        case (int)DoorState.Closed:
                            to       = from + OpenMaxAngle;
                            endState = (int)DoorState.OpenMax;
                            break;

                        case (int)DoorState.OpenMin:
                            to       = from - OpenMinAngle;
                            endState = (int)DoorState.Closed;
                            break;

                        case (int)DoorState.OpenMax:
                            to       = from - OpenMaxAngle;
                            endState = (int)DoorState.Closed;
                            break;
                        }
                    }
                    else if (dot < 0)
                    {
                        switch (state)
                        {
                        case (int)DoorState.Closed:
                            to       = from + OpenMinAngle;
                            endState = (int)DoorState.OpenMin;
                            break;

                        case (int)DoorState.OpenMin:
                            to       = from - OpenMinAngle;
                            endState = (int)DoorState.Closed;
                            break;

                        case (int)DoorState.OpenMax:
                            to       = from - OpenMaxAngle;
                            endState = (int)DoorState.Closed;
                            break;
                        }
                    }

                    if (endState != state)
                    {
                        player.stateInterface.State.OpenDoor();
                        if (SharedConfig.IsServer || SharedConfig.IsOffline)
                        {
                            door.doorData.State = (int)DoorState.Rotating;
                            door.AddDoorRotate(from, from, to, endState);
                            _logger.DebugFormat("Trigger Door From {0} {1} To {2} {3}",
                                                state, from, endState, to);
                            switch ((DoorState)endState)
                            {
                            case DoorState.Closed:
                                player.soundManager.Value.PlayOnce(XmlConfig.EPlayerSoundType.CloseDoor);
                                break;

                            case DoorState.OpenMax:
                            case DoorState.OpenMin:
                                player.soundManager.Value.PlayOnce(XmlConfig.EPlayerSoundType.OpenDoor);
                                break;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        protected override void DoSetData(PointerData data)
        {
            _doorObjId = DoorCastData.EntityId(data.IdList);

            var doorObj = _triggerObjectManager.Get(ETriggerObjectType.Door, _doorObjId);

            if (doorObj == null)
            {
                Logger.Debug("Door trigger object is null.");
                return;
            }

            _enableAction = false;

            var player = _playerContext.flagSelfEntity;
            var go     = doorObj;

            if (IsUntouchableOffGround(player, data.Position, go))
            {
                Logger.Debug("Door is untouchable to player.");
                return;
            }

            //make sure player-door have a correct relative position
            var direction = player.RootGo().transform.position - go.transform.position;

            direction.y = 0;
            var dot = Vector3.Dot(direction, go.transform.forward);

            if (!dot.Equals(0))
            {
                var mapObj = _doorContext.GetEntityWithEntityKey(new EntityKey(_doorObjId, (int)EEntityType.MapObject));
                if (mapObj == null || !mapObj.hasDoorData)
                {
                    if (DetectObstacle(go, dot < 0))
                    {
                        SetObstacleTip();
                    }
                    else
                    {
                        Tip           = ScriptLocalization.client_actiontip.opendoor;
                        _enableAction = true;
                    }
                }
                else
                {
                    var state = mapObj.doorData.State;
                    if (state == (int)DoorState.Closed)
                    {
                        if (DetectObstacle(go, dot < 0))
                        {
                            SetObstacleTip();
                        }
                        else
                        {
                            Tip           = ScriptLocalization.client_actiontip.opendoor;
                            _enableAction = true;
                        }
                    }
                    else if (state == (int)DoorState.OpenMax || state == (int)DoorState.OpenMin)
                    {
                        if ((state == (int)DoorState.OpenMax && DetectObstacle(go, true)) ||
                            (state == (int)DoorState.OpenMin && DetectObstacle(go, false)))
                        {
                            SetObstacleTip();
                        }
                        else
                        {
                            Tip           = ScriptLocalization.client_actiontip.closedoor;
                            _enableAction = true;
                        }
                    }
                    else
                    {
                        Logger.Debug("Door state is wrong.");
                    }
                }
            }
            else
            {
                Logger.Debug("Door operation angle failed.");
            }
        }