public void HandleCollision(IPlayer link, IBlock block, Constants.Direction side)
        {
            if (link.State.GetType() == typeof(LinkPickingUpItemState))
            {
                return;
            }
            Vector2 correctDirection;

            switch (side)
            {
            case Constants.Direction.Up:
                correctDirection = new Vector2(0, -1);
                link.Move(linkMoveDistance, correctDirection);
                break;

            case Constants.Direction.Down:
                correctDirection = new Vector2(0, 1);
                link.Move(linkMoveDistance, correctDirection);
                break;

            case Constants.Direction.Left:
                correctDirection = new Vector2(-1, 0);
                link.Move(linkMoveDistance, correctDirection);
                break;

            case Constants.Direction.Right:
                correctDirection = new Vector2(1, 0);
                link.Move(linkMoveDistance, correctDirection);
                break;

            default:
                break;
            }
        }
Example #2
0
        private void UpdatePlayersPositions(Constants.Direction doorLocation)
        {
            foreach (IPlayer player in RoomGameState.PlayerList)
            {
                player.StopMoving();
                switch (doorLocation)
                {
                case Constants.Direction.Right:
                    player.Position = LinkConstants.DoorRightSpawnPosition;
                    break;

                case Constants.Direction.Left:
                    player.Position = LinkConstants.DoorLeftSpawnPosition;
                    break;

                case Constants.Direction.Up:
                    player.Position = LinkConstants.DoorUpSpawnPosition;
                    break;

                case Constants.Direction.Down:
                    player.Position = LinkConstants.DoorDownSpawnPosition;
                    break;
                }
            }
        }
        public BlockMovement(Constants.Direction direction, string door)
        {
            this.door = door;
            switch (direction)
            {
            case Constants.Direction.UP:
                motion = new Vector2(0, -1);
                break;

            case Constants.Direction.DOWN:
                motion = new Vector2(0, 1);
                break;

            case Constants.Direction.LEFT:
                motion = new Vector2(-1, 0);
                break;

            case Constants.Direction.RIGHT:
                motion = new Vector2(1, 0);
                break;

            default:
                motion = new Vector2();
                break;
            }
        }
        // Helper function that reverses current direction (used in EXTENDING -> RETRACTING transition)
        public void ReverseDirection()
        {
            // Console.WriteLine("Reversing direction.");
            if (state == State.RETRACTING)
            {
                state = State.EXTENDING;
            }
            else
            {
                state = State.RETRACTING;
            }

            switch (direction)
            {
            case Constants.Direction.UP:
                direction = Constants.Direction.DOWN;
                break;

            case Constants.Direction.RIGHT:
                direction = Constants.Direction.LEFT;
                break;

            case Constants.Direction.DOWN:
                direction = Constants.Direction.UP;
                break;

            case Constants.Direction.LEFT:
                direction = Constants.Direction.RIGHT;
                break;

            default:
                //Console.WriteLine("BladeTrapMovement: Unrecognized direction transition!");
                break;
            }
        }
Example #5
0
 public LinkKnockback(Constants.Direction direction, float distance, int numFrames)
 {
     this.direction = direction;
     this.distance  = distance;
     this.numFrames = numFrames;
     this.frame     = 0;
 }
        public void HandleCollision(INpc enemy, IBlock block, Constants.Direction side)
        {
            Vector2 correctDirection;

            enemy.SetKnockBack(false, Constants.Direction.None);
            switch (side)
            {
            case Constants.Direction.Up:
                correctDirection = new Vector2(Constants.EnemyNoMove, Constants.EnemyMoveUp);
                enemy.Move(correctDirection);
                break;

            case Constants.Direction.Down:
                correctDirection = new Vector2(Constants.EnemyNoMove, Constants.EnemyMoveDown);
                enemy.Move(correctDirection);
                break;

            case Constants.Direction.Left:
                correctDirection = new Vector2(Constants.EnemyMoveLeft, Constants.EnemyNoMove);
                enemy.Move(correctDirection);
                break;

            case Constants.Direction.Right:
                correctDirection = new Vector2(Constants.EnemyMoveRight, Constants.EnemyNoMove);
                enemy.Move(correctDirection);
                break;

            default:
                break;
            }
        }
Example #7
0
        public void HandleCollision(INpc enemy, IBlock block, Constants.Direction side)
        {
            if (CheckCollision(block.GetType()))
            {
                Vector2 direction = new Vector2();
                switch (side)
                {
                case Constants.Direction.Up:
                    direction = new Vector2(Constants.EnemyNoMove, Constants.EnemyMoveUp);
                    break;

                case Constants.Direction.Down:
                    direction = new Vector2(Constants.EnemyNoMove, Constants.EnemyMoveDown);
                    break;

                case Constants.Direction.Right:
                    direction = new Vector2(Constants.EnemyMoveRight, Constants.EnemyNoMove);
                    break;

                case Constants.Direction.Left:
                    direction = new Vector2(Constants.EnemyMoveLeft, Constants.EnemyNoMove);
                    break;
                }
                ((Bat)enemy).ChooseDirection();
                ((Bat)enemy).Move(direction);
            }
        }
Example #8
0
        public override void Enter(Actor owner, ActorAIController ownerAI)
        {
            base.Enter(owner, ownerAI);

            ownerAI.ChaseTarget   = GameSystem.Instance.ActorManager.GetRandomPlayer();
            this.currentDirection = this.GetTargetDirection(owner, ownerAI);

            this.GetObserver(owner)
            .SubscribeWithState3(this, owner, ownerAI, (_, _this, _owner, _ownerAI) =>
            {
                _owner.StatusController.SetMoveSpeedRate(_this.moveSpeedRate);
                _owner.Broker.Publish(RequestMove.Get(_this.currentDirection.ToVector2()));

                if (_this.IsReverse(_owner, _ownerAI))
                {
                    _this.changeDirectionDuration += Time.deltaTime;
                }
                else
                {
                    _this.changeDirectionDuration = 0.0f;
                }

                if (_this.changeDirectionDuration > _this.changeDirectionDelay)
                {
                    _this.changeDirectionDuration = 0.0f;
                    _this.currentDirection        = _this.GetTargetDirection(_owner, _ownerAI);
                }
            })
            .AddTo(this.events);
        }
        public Boomerang(Constants.Direction direction, Entity entity)
        {
            var entityTransform = entity.GetComponent <Transform>();

            GetComponent <Transform>().position = entityTransform.position;

            Constants.SetLayerDepth(this, Constants.LayerDepth.Item);

            Sprite s = new Sprite(EnemySpriteFactory.Instance.CreateGoriyaBoomerang());

            AddComponent(s);
            s.SetAnimate(true);

            BehaviorScript b = new BoomerangMovement(entity, direction);

            AddComponent(b);

            var coll = new Collider();

            coll.response = new BoomerangCollisionResponse(this, entity, 1); // Half a heart of damage, we'll say
            AddComponent(coll);

            // Play sound
            Sound.PlaySound(Sound.SoundEffects.Arrow_Boomerang, entity, !Sound.SOUND_LOOPS);
        }
        public void Move(Constants.Direction direction)
        {
            moving = true;

            goal = entity.GetComponent <Transform>().position;
            switch (direction)
            {
            case Constants.Direction.UP:
                goal.Y += Level.screen_height;
                break;

            case Constants.Direction.LEFT:
                goal.X += Level.screen_width;
                break;

            case Constants.Direction.RIGHT:
                goal.X -= Level.screen_width;
                break;

            case Constants.Direction.DOWN:
                goal.Y -= Level.screen_height;
                break;
            }
            start = entity.GetComponent <Transform>().position;
        }
Example #11
0
        public void HandleCollision(INpc enemy, IProjectile swordBeam, Constants.Direction side)
        {
            SwordBeamFlyingProjectile swordBeamCast = (SwordBeamFlyingProjectile)swordBeam;

            enemy.TakeDamage(swordBeamCast.DamageAmount());
            swordBeamCast.ExplodeSword();
        }
Example #12
0
        public MovePacket(Objects.Client c, Constants.Direction direction)
            : base(c)
        {
            Direction = direction;

            switch (direction)
            {
                case Tibia.Constants.Direction.Down:
                    Type = OutgoingPacketType.MoveDown;
                    break;
                case Tibia.Constants.Direction.Up:
                    Type = OutgoingPacketType.MoveUp;
                    break;
                case Tibia.Constants.Direction.Right:
                    Type = OutgoingPacketType.MoveRight;
                    break;
                case Tibia.Constants.Direction.Left:
                    Type = OutgoingPacketType.MoveLeft;
                    break;
                case Tibia.Constants.Direction.DownLeft:
                    Type = OutgoingPacketType.MoveDownLeft;
                    break;
                case Tibia.Constants.Direction.DownRight:
                    Type = OutgoingPacketType.MoveDownRight;
                    break;
                case Tibia.Constants.Direction.UpLeft:
                    Type = OutgoingPacketType.MoveUpLeft;
                    break;
                case Tibia.Constants.Direction.UpRight:
                    Type = OutgoingPacketType.MoveUpRight;
                    break;
            }

            Destination = PacketDestination.Server;
        }
Example #13
0
 /// <summary>
 /// constructor of a servershare
 /// </summary>
 /// <param name="location">location appreviation</param>
 /// <param name="shortloc">location appreviation</param>
 /// <param name="repr">HPC copy cluster head name</param>
 /// <param name="legacy">legacy share for backward compatibility</param>
 public ServerShare(string location, string shortloc, string repr, Constants.Direction dir)
 {
     _location  = location;
     _shortloc  = shortloc;
     _repr      = repr;
     _direction = dir;
 }
Example #14
0
    /// <summary>
    /// Called when the end of a branch is reached.
    /// </summary>
    /// <param name="branchIndex"></param>
    private void EndReached(int branchIndex)
    {
        lastDirection = attackDirection;
        CancelGrid();

        balance.TriggerEnd(endPoints[branchIndex].typeID);
    }
        public static async void PlayerMove(Constants.Direction dir, string uid, string sessionKey = "")
        {
            var player = LobbyService.Sessions[sessionKey]?.Players?.FirstOrDefault(n => n.UID == uid);

            if (player != null)
            {
                // Don't reverse into yourself.
                if (player.Direction == Constants.Direction.Left && dir == Constants.Direction.Right)
                {
                    return;
                }
                if (player.Direction == Constants.Direction.Right && dir == Constants.Direction.Left)
                {
                    return;
                }
                if (player.Direction == Constants.Direction.Up && dir == Constants.Direction.Down)
                {
                    return;
                }
                if (player.Direction == Constants.Direction.Down && dir == Constants.Direction.Up)
                {
                    return;
                }

                player.Direction = dir;
            }
        }
Example #16
0
        public void HandleCollision(IPlayer link, INpc enemy, Constants.Direction side)
        {
            link.BeDamaged(enemy.GetDamageAmount());

            Vector2 velocity = Vector2.Zero;

            switch (side)
            {
            case Constants.Direction.Up:
                velocity = new Vector2(0, -1 * knockbackVelocityScalar);
                break;

            case Constants.Direction.Down:
                velocity = new Vector2(0, knockbackVelocityScalar);
                break;

            case Constants.Direction.Left:
                velocity = new Vector2(-1 * knockbackVelocityScalar, 0);
                break;

            case Constants.Direction.Right:
                velocity = new Vector2(knockbackVelocityScalar, 0);
                break;
            }

            link.Move(knockbackDistance, velocity);
        }
Example #17
0
        public TurnPacket(Objects.Client c, Constants.Direction direction)
            : base(c)
        {
            Direction = direction;

            switch (direction)
            {
                case Tibia.Constants.Direction.Down:
                    Type = OutgoingPacketType.TurnDown;
                    break;
                case Tibia.Constants.Direction.Up:
                    Type = OutgoingPacketType.TurnUp;
                    break;
                case Tibia.Constants.Direction.Right:
                    Type = OutgoingPacketType.TurnRight;
                    break;
                case Tibia.Constants.Direction.Left:
                    Type = OutgoingPacketType.TurnLeft;
                    break;
                default:
                    throw new ArgumentOutOfRangeException(
                        "direction",
                        "Valid directions for turning are Up, Right, Down, and Left.");
            }

            Destination = PacketDestination.Server;
        }
        // If Link is within a small distance of either vertical or horizontal axis from us, move in that direction.
        private void Waiting()
        {
            // TODO: Convert all the rectangles to floating point. Only noticeable on the subpixel layer so it's not super important though.
            // Have to reconstruct a rectangle here because if we just grab the rectangle from the Sprite class it isn't the transform we expect (is instead on the spritesheet I think)

            // Grab a rectangle representing each entity at this point in time
            Entity    link           = Scene.Find("Link");
            Rectangle linkSpriteRect = link.GetComponent <Sprite>().sprite.frames[0];
            Vector2   linkTransform  = link.GetComponent <Transform>().WorldPosition; // link.
            Rectangle linkRect       = new Rectangle((int)linkTransform.X, (int)linkTransform.Y, linkSpriteRect.Width, linkSpriteRect.Height);

            Rectangle bladeSpriteRect = entity.GetComponent <Sprite>().sprite.frames[0];
            Vector2   bladeTransform  = entity.GetComponent <Transform>().position;
            Rectangle bladeRect       = new Rectangle((int)bladeTransform.X, (int)bladeTransform.Y, bladeSpriteRect.Width, bladeSpriteRect.Height);

            // Check if Link is horizontal
            if (HorizontallyAligned(linkRect, bladeRect))
            {
                // Console.WriteLine("BladeTrap at pos " + entity.GetComponent<Transform>().position + " detected link horiziontally!");
                state = State.EXTENDING;

                // If blade trap is to the left of Link right now
                if (linkRect.X >= bladeRect.X)
                {
                    // Console.WriteLine("BladeTrap going right.");
                    direction = Constants.Direction.RIGHT;
                }

                else
                {
                    // Console.WriteLine("BladeTrap going left.");
                    direction = Constants.Direction.LEFT;
                }
            }

            // Check if Link is vertical
            else if (VerticallyAligned(linkRect, bladeRect))
            {
                // Console.WriteLine("BladeTrap at pos " + entity.GetComponent<Transform>().position + " detected link vertically!");
                state = State.EXTENDING;

                // If Blade trap is above Link right now
                if (linkRect.Y >= bladeRect.Y)
                {
                    // Console.WriteLine("BladeTrap going down.");
                    direction = Constants.Direction.DOWN;
                }

                else
                {
                    // Console.WriteLine("BladeTrap going up.");
                    direction = Constants.Direction.UP;
                }
            }

            else
            {
                // Console.WriteLine("BladeTrap at pos " + entity.GetComponent<Transform>().position + " detected nothing!");
            }
        }
Example #19
0
        public TurnPacket(Objects.Client c, Constants.Direction direction)
            : base(c)
        {
            Direction = direction;

            switch (direction)
            {
            case Tibia.Constants.Direction.Down:
                Type = OutgoingPacketType.TurnDown;
                break;

            case Tibia.Constants.Direction.Up:
                Type = OutgoingPacketType.TurnUp;
                break;

            case Tibia.Constants.Direction.Right:
                Type = OutgoingPacketType.TurnRight;
                break;

            case Tibia.Constants.Direction.Left:
                Type = OutgoingPacketType.TurnLeft;
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          "direction",
                          "Valid directions for turning are Up, Right, Down, and Left.");
            }

            Destination = PacketDestination.Server;
        }
 public override void Move(Constants.Direction direction)
 {
     if (direction == link.FacingDirection)
     {
         stillMoving = true;
     }
 }
        public GoriyaBehavior(string color)
        {
            // Initial State
            state                = State.MOVING;
            direction            = Constants.Direction.RIGHT;
            framesSinceTurn      = 0;
            framesSinceThrow     = 0;
            framesBeforeLastFlip = 0;

            framesUntilThrow = Constants.GetRandomIntMinMax(50, 90);

            // sprites
            if (color.Equals("red"))
            {
                GoriyaLeft        = EnemySpriteFactory.Instance.CreateRedGoriyaLeft();
                GoriyaRight       = EnemySpriteFactory.Instance.CreateRedGoriyaRight();
                GoriyaUp          = EnemySpriteFactory.Instance.CreateRedGoriyaUp();
                GoriyaUpFlipped   = EnemySpriteFactory.Instance.CreateRedGoriyaUpFlipped();
                GoriyaDown        = EnemySpriteFactory.Instance.CreateRedGoriyaDown();
                GoriyaDownFlipped = EnemySpriteFactory.Instance.CreateRedGoriyaDownFlipped();
            }
            else
            {
                GoriyaLeft        = EnemySpriteFactory.Instance.CreateBlueGoriyaLeft();
                GoriyaRight       = EnemySpriteFactory.Instance.CreateBlueGoriyaRight();
                GoriyaUp          = EnemySpriteFactory.Instance.CreateBlueGoriyaUp();
                GoriyaUpFlipped   = EnemySpriteFactory.Instance.CreateBlueGoriyaUpFlipped();
                GoriyaDown        = EnemySpriteFactory.Instance.CreateBlueGoriyaDown();
                GoriyaDownFlipped = EnemySpriteFactory.Instance.CreateBlueGoriyaDownFlipped();
            }
        }
        // Helper function to choose a new direction
        private void NewDirection(Sprite sprite)
        {
            direction = Constants.RandomEnumValue <Constants.Direction>();
            switch (direction)
            {
            case Constants.Direction.UP:
                direction = Constants.Direction.RIGHT;
                sprite.SetSprite(GoriyaRight);
                break;

            case Constants.Direction.RIGHT:
                direction = Constants.Direction.DOWN;
                sprite.SetSprite(GoriyaDown);
                break;

            case Constants.Direction.DOWN:
                direction = Constants.Direction.LEFT;
                sprite.SetSprite(GoriyaLeft);
                break;

            case Constants.Direction.LEFT:
                direction = Constants.Direction.UP;
                sprite.SetSprite(GoriyaUp);
                break;

            default:
                Console.WriteLine("RedGoriyaBehavior @ TurnRight(): Unrecognized direction!");
                break;
            }
        }
Example #23
0
        public void Move(Constants.Direction direction)
        {
            moving = true;

            goal = entity.GetComponent <Transform>().position;
            int offsetUpDown    = -270;
            int offsetLeftRight = -310;

            switch (direction)
            {
            case Constants.Direction.UP:
                goal.Y += offsetUpDown;
                break;

            case Constants.Direction.LEFT:
                goal.X += offsetLeftRight;
                break;

            case Constants.Direction.RIGHT:
                goal.X -= offsetLeftRight;
                break;

            case Constants.Direction.DOWN:
                goal.Y -= offsetUpDown;
                break;
            }
            start = entity.GetComponent <Transform>().position;
        }
 public void HandleCollision(INpc enemy, IProjectile sword, Constants.Direction side)
 {
     enemy.TakeDamage(sword.DamageAmount());
     if (enemy.GetType() == typeof(Skeleton) || enemy.GetType() == typeof(Goriya))
     {
         enemy.SetKnockBack(true, side);
     }
 }
Example #25
0
 public override IRoom GetRoom(Constants.Direction direction)
 {
     if (direction == Constants.Direction.Stairs)
     {
         UpdatePlayerPositions();
     }
     return(base.GetRoom(direction));
 }
Example #26
0
 /// <summary>
 /// Walk in the specified direction
 /// </summary>
 /// <param name="direction"></param>
 /// <returns></returns>
 public bool Walk(Constants.Direction direction)
 {
     byte[] packet = new byte[3];
     packet[0] = 0x01;
     packet[1] = 0x00;
     packet[2] = Convert.ToByte(0x65 + direction);
     return(client.Send(packet));
 }
 public virtual void Move(Constants.Direction direction)
 {
     if (link.BlockStateChange)
     {
         return;
     }
     link.State = new LinkWalkingState(link, direction, damaged, healthyDateTime);
 }
Example #28
0
        public WallMasterMovement(Constants.Direction startingDirection)
        {
            // initial state
            state     = State.ROAMING;
            direction = startingDirection;

            // initial values
            directionSwitchCurrent = 0;
        }
Example #29
0
        public ItemMovement(bool moving, bool disappearing, int framesToDraw, Constants.Direction directionThrown)
        {
            this.moving          = moving;
            this.disappearing    = disappearing;
            this.framesToDraw    = framesToDraw;
            this.directionThrown = directionThrown;

            this.framesDrawn = 0;
        }
 public void HandleCollision(INpc enemy, IProjectile boomerang, Constants.Direction side)
 {
     if (boomerang.Owner == Constants.ProjectileOwner.Link)
     {
         BoomerangFlyingProjectile boomerangCast = (BoomerangFlyingProjectile)boomerang;
         enemy.TakeDamage(boomerangCast.DamageAmount());
         boomerangCast.ReturnToOwner();
     }
 }
Example #31
0
        public void HandleCollision(INpc enemy, IProjectile bomb, Constants.Direction side)
        {
            BombExplodingProjectile bombCast = (BombExplodingProjectile)bomb;

            if (bombCast.IsExploded())
            {
                enemy.TakeDamage(bombCast.DamageAmount());
            }
        }
Example #32
0
 /// <summary>
 /// Turn to the specified direction.
 /// </summary>
 /// <param name="direction"></param>
 /// <returns></returns>
 public bool Turn(Constants.Direction direction)
 {
     byte[] packet = new byte[3];
     packet[0] = 0x01;
     packet[1] = 0x00;
     packet[2] = Convert.ToByte(0x6F + direction);
     return(client.Player.Turn(direction));
     //return client.Player.Turn(direction);
 }