Exemplo n.º 1
0
        protected override void OnHandle(IPacket packet, NetState netState, ServerWorldState worldState)
        {
            ChatStatusPacket packetToHandle  = (ChatStatusPacket)packet;
            ServerCharacter  serverCharacter = (ServerCharacter)worldState.GetCharacter(netState.WorldId);

            if (serverCharacter != null)
            {
                foreach (int mapCharacterId in worldState.Characters)
                {
                    ServerCharacter  characterToUpdate = (ServerCharacter)worldState.GetCharacter(mapCharacterId);
                    NetState         clientSendTo      = characterToUpdate.Owner;
                    ChatStatusPacket packetToSend;

                    if (serverCharacter.IsDead && !characterToUpdate.IsDead)
                    {
                        packetToSend = new ChatStatusPacket(serverCharacter.Id, packetToHandle.State);
                    }
                    else
                    {
                        packetToSend = new ChatStatusPacket(serverCharacter.Id, packetToHandle.State);
                    }

                    clientSendTo.Send(packetToSend);
                }
            }
        }
Exemplo n.º 2
0
        protected override void OnHandle(IPacket packet, NetState netState, ServerWorldState worldState)
        {
            AimToPacket     packetToHandle  = (AimToPacket)packet;
            ServerCharacter serverCharacter = (ServerCharacter)worldState.GetCharacter(netState.WorldId);

            if (serverCharacter != null)
            {
                serverCharacter.SetAimToPosition(new Point(packetToHandle.X, packetToHandle.Y));
                worldState.SendStatChangeToMapCharacters(serverCharacter);
            }
        }
        private void OnSuccessfulChange(int mapId, int mobileId, int containerID, int itemId, ServerWorldState worldState)
        {
            foreach (int characterId in worldState.GetMapCharacters(mapId))
            {
                if (characterId == mobileId)
                {
                    continue;
                }

                ServerCharacter characterToUpdate = ((ServerCharacter)worldState.GetCharacter(characterId));
                NetState        clientSendTo      = characterToUpdate.Owner;

                clientSendTo.Send(new MoveItemServerPacket(itemId, mobileId, containerID));
            }
        }
        protected override void OnHandle(IPacket packet, NetState netState, ServerWorldState worldState)
        {
            PerformAbilityPacket incomingPacket = (PerformAbilityPacket)packet;
            ServerCharacter      mobileToUpdate = (ServerCharacter)worldState.GetCharacter(netState.WorldId);

            if (mobileToUpdate != null)
            {
                if (worldState.PerformAbility(incomingPacket.AbilityUsed, mobileToUpdate))
                {
                    foreach (int characterId in worldState.GetMapCharacters(mobileToUpdate.CurrentMapId))
                    {
                        if (characterId == mobileToUpdate.Id)
                        {
                            continue;
                        }

                        ServerCharacter characterToUpdate = ((ServerCharacter)worldState.GetCharacter(characterId));
                        NetState        clientSendTo      = characterToUpdate.Owner;

                        clientSendTo.Send(incomingPacket);
                    }
                }
            }
        }
        protected override void OnHandle(IPacket packet, NetState netState, ServerWorldState worldState)
        {
            UseItemPacket incomingPacket = (UseItemPacket)packet;
            //if (incomingPacket.MobileId != netState.WorldId)
            //{
            //    netState.SendError(0, string.Format("Invalid CMD: '{0},{1},{2}'.", incomingPacket.PacketId, incomingPacket.MobileId, incomingPacket.ItemId));
            //    return;
            //}

            ServerCharacter serverCharacter = (ServerCharacter)worldState.GetCharacter(netState.WorldId);
            Item            itemToUse       = worldState.GetItem(incomingPacket.ItemId);

            if (serverCharacter != null && itemToUse != null)
            {
                if (itemToUse.IsWorldItem)
                {
                    if (serverCharacter.PickupItem(itemToUse))
                    {
                        worldState.SaveItemPosition(itemToUse);
                        this.OnSuccessfulUse(serverCharacter.CurrentMapId, incomingPacket.MobileId, incomingPacket.ItemId, worldState);
                    }
                }
                else
                {
                    if (itemToUse.Category == ItemCategory.Consumable)
                    {
                        ConsumableItem consumable = (ConsumableItem)itemToUse;
                        if (consumable.Use(serverCharacter, worldState))
                        {
                            worldState.SaveItemUse(itemToUse);
                            this.OnSuccessfulUse(serverCharacter.CurrentMapId, incomingPacket.MobileId, incomingPacket.ItemId, worldState);
                        }
                    }
                    if (itemToUse.Category == ItemCategory.Armor || itemToUse.Category == ItemCategory.Weapon)
                    {
                        if (serverCharacter.Equip(itemToUse))
                        {
                            worldState.SaveCharacterItems(serverCharacter);
                            this.OnSuccessfulUse(serverCharacter.CurrentMapId, incomingPacket.MobileId, incomingPacket.ItemId, worldState);
                        }
                    }
                }
            }
        }
        protected override void OnHandle(IPacket packet, NetState netState, ServerWorldState worldState)
        {
            MoveItemPacket incomingPacket = (MoveItemPacket)packet;
            //if (incomingPacket.MobileId != netState.WorldId)
            //{
            //    netState.SendError(0, string.Format("Invalid CMD: '{0},{1},{2}'.", incomingPacket.PacketId, incomingPacket.MobileId, incomingPacket.ItemId));
            //    return;
            //}

            ServerCharacter serverCharacter = (ServerCharacter)worldState.GetCharacter(netState.WorldId);
            Item            item            = (Item)worldState.GetItem(incomingPacket.ItemID);

            if (serverCharacter != null && item != null)
            {
                if (incomingPacket.MoveToID.HasValue) //item.Data.IsWorldItem &&
                {
                    int           containerID = incomingPacket.MoveToID.Value;
                    ContainerItem moveTo      = (ContainerItem)worldState.GetItem(containerID);
                    if (moveTo != null)
                    {
                        if (serverCharacter.MoveItem(item, moveTo))
                        {
                            worldState.SaveItemPosition(item);
                            this.OnSuccessfulChange(serverCharacter.CurrentMapId, serverCharacter.Id, containerID, incomingPacket.ItemID, worldState);
                        }
                    }
                }
                else if (incomingPacket.MoveToPosition.HasValue)
                {
                    Point moveToPostion = incomingPacket.MoveToPosition.Value;
                    if (serverCharacter.MoveItem(item, moveToPostion))
                    {
                        worldState.SaveItemPosition(item);
                        this.OnSuccessfulChange(serverCharacter.CurrentMapId, serverCharacter.Id, moveToPostion, incomingPacket.ItemID, worldState);
                    }
                }
            }
        }