Exemplo n.º 1
0
        protected override void OnHandle(IPacket packet, ClientWorldState worldState)
        {
            MoveItemServerPacket incomingPacket = (MoveItemServerPacket)packet;
            ClientCharacter      mobileToUpdate = (ClientCharacter)worldState.GetCharacter(incomingPacket.CharacterID);
            Item item = (Item)worldState.GetItem(incomingPacket.ItemID);

            if (mobileToUpdate == null)
            {
                worldState.MissingCharacters.Add(incomingPacket.CharacterID);
            }
            else if (item != null)
            {
                if (incomingPacket.MoveToID.HasValue) //(item.Data.IsWorldItem)
                {
                    ContainerItem moveToContainer = (ContainerItem)worldState.GetItem(incomingPacket.MoveToID.Value);
                    if (!mobileToUpdate.MoveItem(item, moveToContainer))
                    {
                        //ToDo: Simulation missmatch, Force server Authority
                    }
                }
                else if (incomingPacket.MoveToPosition.HasValue)
                {
                    if (!mobileToUpdate.MoveItem(item, incomingPacket.MoveToPosition.Value))
                    {
                        //ToDo: Simulation missmatch, Force server Authority
                    }
                }
            }
        }
        protected override void OnHandle(IPacket packet, ClientWorldState worldState)
        {
            MoveToPacket    incomingPacket = (MoveToPacket)packet;
            ClientCharacter mobileToUpdate = (ClientCharacter)worldState.GetCharacter(incomingPacket.MobileId);

            if (mobileToUpdate == null)
            {
                worldState.MissingCharacters.Add(incomingPacket.MobileId);
                return;
            }

            mobileToUpdate.ServerMoveToRecived(new Point(incomingPacket.X, incomingPacket.Y));
        }
        protected override void OnHandle(IPacket packet, ClientWorldState worldState)
        {
            StatsChangedPacket incomingPacket = (StatsChangedPacket)packet;
            ClientCharacter    mobileToUpdate = (ClientCharacter)worldState.GetCharacter(incomingPacket.MobileId);

            if (mobileToUpdate == null)
            {
                worldState.MissingCharacters.Add(incomingPacket.MobileId);
                return;
            }

            mobileToUpdate.ServerStatsRecived(incomingPacket.Health, incomingPacket.Energy);
        }
Exemplo n.º 4
0
        protected override void OnHandle(IPacket packet, ClientWorldState worldState)
        {
            PerformAbilityPacket incomingPacket = (PerformAbilityPacket)packet;
            ClientCharacter      mobileToUpdate = (ClientCharacter)worldState.GetCharacter(incomingPacket.CharacterId);

            if (mobileToUpdate == null)
            {
                worldState.MissingCharacters.Add(incomingPacket.CharacterId);
                return;
            }

            worldState.PerformAbility(incomingPacket.AbilityUsed, mobileToUpdate);
        }
        protected override void OnHandle(IPacket packet, ClientWorldState worldState)
        {
            UseItemPacket   incomingPacket = (UseItemPacket)packet;
            ClientCharacter mobileToUpdate = (ClientCharacter)worldState.GetCharacter(incomingPacket.MobileId);
            Item            itemToUse      = worldState.GetItem(incomingPacket.ItemId);

            if (mobileToUpdate == null)
            {
                worldState.MissingCharacters.Add(incomingPacket.MobileId);
            }

            if (mobileToUpdate != null && itemToUse != null)
            {
                if (itemToUse.IsWorldItem)
                {
                    if (!mobileToUpdate.PickupItem(itemToUse))
                    {
                        //ToDo: Simulation missmatch, Force server Authority
                    }
                }
                else
                {
                    if (itemToUse.Category == ItemCategory.Consumable)
                    {
                        ConsumableItem itemToConsume = (ConsumableItem)itemToUse;
                        if (!itemToConsume.Use(mobileToUpdate, worldState))
                        {
                            //ToDo: Simulation missmatch, Force server Authority
                        }
                    }
                    else if (itemToUse.Category == ItemCategory.Armor || itemToUse.Category == ItemCategory.Weapon)
                    {
                        if (!mobileToUpdate.Equip(itemToUse))
                        {
                            //ToDo: Sim missmatch, force server Auth
                        }
                    }
                }
            }
        }
        private void DrawCharacters(SpriteBatch spriteBatch)
        {
            Vector2 centerHead = headTexture.Bounds.Center.ToVector2();
            Vector2 centerBody = bodyTexture.Bounds.Center.ToVector2();

            centerBody.Y = 0f;

            Texture2D bodyTextureToUse, headTextureToUse;

            foreach (ushort id in world.Characters)
            {
                //if (id == world.PlayerCharacter.Id)
                //    continue;
                bodyTextureToUse = bodyTexture;
                headTextureToUse = headTexture;

                ClientCharacter charToDraw            = (ClientCharacter)world.GetCharacter(id);
                Vector2         charToDrawDirection   = charToDraw.AimToPosition.ToVector2() - charToDraw.Position.ToVector2();
                Vector2         bodyMovingBobPosition = Vector2.Zero;
                if (charToDraw.IsMoving)
                {
                    bodyMovingBobPosition = movementBodyBobEffect.PositioinBob;
                }

                Vector2 bodyRotationPosition = charToDrawDirection;
                if (bodyRotationPosition != Vector2.Zero)
                {
                    bodyRotationPosition.Normalize();
                }
                bodyRotationPosition.X *= 2f;
                if (bodyRotationPosition.Y < 0f)
                {
                    bodyRotationPosition.Y *= 10f;
                }

                if (charToDraw.IsDead)
                {
                    bodyTextureToUse = bodyGhostTexture;
                    headTextureToUse = headGhostTexture;
                }

                var   distance   = Vector2.Distance(world.PlayerCharacter.Position.ToVector2(), charToDraw.Position.ToVector2());
                float visibility = charToDraw.Stats.GetVisibility(distance);

                if (visibility > 0f)
                {
                    Color visibilityColor = Color.White * visibility;
                    //Draw Body
                    Vector2 clientScreenPostion = this.GetScreenPostion(charToDraw.DrawPosition).ToVector2();
                    spriteBatch.Draw(bodyTextureToUse, clientScreenPostion + bodyMovingBobPosition + bodyRotationPosition, null, visibilityColor,
                                     0f, centerBody, 1f, SpriteEffects.None, 1f);
                    if (charToDraw.Armor != null && !charToDraw.IsDead)
                    {
                        IArmorClientItem armorItem = (IArmorClientItem)charToDraw.Armor;
                        spriteBatch.Draw(armorItem.Texture, clientScreenPostion + bodyMovingBobPosition + bodyRotationPosition, null, visibilityColor,
                                         0f, new Vector2(armorItem.Texture.Bounds.Center.X, 0f), 1f, SpriteEffects.None, 1f);
                    }

                    //Draw Head
                    spriteBatch.Draw(headTextureToUse, clientScreenPostion, null, visibilityColor,
                                     (float)world.VectorToRadian(charToDrawDirection), centerHead, 1f, SpriteEffects.None, 1f);

                    //Draw Armor
                    if (charToDraw.Armor != null && !charToDraw.IsDead)
                    {
                        IArmorClientItem armorItem = (IArmorClientItem)charToDraw.Armor;
                        spriteBatch.Draw(armorItem.HeadTexture, clientScreenPostion, null, visibilityColor,
                                         (float)world.VectorToRadian(charToDrawDirection), centerHead, 1f, SpriteEffects.None, 1f);
                    }

                    //Draw Weapons
                    if (charToDraw.RightHand != null && !charToDraw.IsDead)
                    {
                        IClientItem weaponItem = (IClientItem)charToDraw.RightHand;
                        spriteBatch.Draw(weaponItem.Texture, (clientScreenPostion - (bodyMovingBobPosition * .5f)) + bodyRotationPosition + new Vector2(-weaponItem.Texture.Bounds.Width, weaponItem.Texture.Bounds.Center.Y * .5f), null, visibilityColor,
                                         -.5f, weaponItem.Texture.Bounds.Center.ToVector2(), 1f, SpriteEffects.None, 1f);
                    }

                    //Draw ChatIcon
                    if (charToDraw.IsWritingMessage)
                    {
                        spriteBatch.Draw(chatIcon, clientScreenPostion + new Vector2(0f, -30f), null, visibilityColor,
                                         0f, Vector2.Zero, 1f, SpriteEffects.None, 1f);
                    }
                }
            }

            //Vector2 start = world.PlayerCharacter.Position.ToVector2();
            //Vector2 end = world.PlayerCharacter.AimToPosition.ToVector2();
            ////float distance = Vector2.Distance(start, end);
            //Vector2 direction = end - start;

            //Vector2 plrbodyMovingBobPosition = Vector2.Zero;
            //if (world.PlayerCharacter.IsMoving)
            //    plrbodyMovingBobPosition = movementBodyBobEffect.PositioinBob;

            //Vector2 plrbodyRotationPosition = direction;
            //plrbodyRotationPosition.Normalize();
            //plrbodyRotationPosition.X *= 2f;
            //if (plrbodyRotationPosition.Y < 0f)
            //plrbodyRotationPosition.Y *= 10f;

            //spriteBatch.Draw(bodyTexture, CenterScreenVector2 + plrbodyMovingBobPosition + plrbodyRotationPosition, null, Color.White, 0f, centerBody, 1f, SpriteEffects.None, 1f);
            //spriteBatch.Draw(headTexture, CenterScreenVector2, headTexture.Bounds, Color.White, (float)world.VectorToRadian(direction), centerHead, 1f, SpriteEffects.None, 1f);
        }