Exemplo n.º 1
0
        /// <summary>
        ///   Builds a combat animation packet for broadcast use.
        ///   TODO: Might not work for attacker==defender -- unsure about this.
        ///   len=14
        /// </summary>
        public static byte[] CombatAnimation(GameObject attacker, GameLiving defender, ushort weaponID, ushort shieldID,
                                             int style, byte stance, byte result)
        {
            var pak = new GSTCPPacketOut((byte)ePackets.CombatAnimation);

            if (attacker != null)
            {
                pak.WriteShort((ushort)(attacker.ObjectState == GameObject.eObjectState.Deleted
          ? attacker.LastObjectID
          : attacker.ObjectID));
            }
            else
            {
                pak.WriteShort(0x00);
            }

            byte health = 0x00;

            if (defender != null)
            {
                pak.WriteShort((ushort)(defender.ObjectState == GameObject.eObjectState.Deleted
          ? defender.LastObjectID
          : defender.ObjectID));
                health = defender.HealthPercent;
            }
            else
            {
                pak.WriteShort(0x00);
            }

            pak.WriteShort(weaponID);
            pak.WriteShort(shieldID);
            pak.WriteShortLowEndian((ushort)style);
            pak.WriteByte(stance);
            pak.WriteByte(result);
            pak.WriteByte(health);

            pak.WriteByte(0x6F); // TODO: Check whether this still needs to be 0x6F for attacker==player / 0x00 otherwise

            pak.WritePacketLength();
            return(pak.GetBuffer());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle the packet
        /// </summary>
        /// <param name="client"></param>
        /// <param name="packet"></param>
        /// <returns></returns>
        public void HandlePacket(GameClient client, GSPacketIn packet)
        {
            packet.ReadByte(); // unknown
            int position    = packet.ReadByte();
            int housenumber = packet.ReadShort();
            int method      = packet.ReadByte();

            House house = HouseMgr.GetHouse(client.Player.CurrentRegionID, housenumber);

            if (house == null)
            {
                return;
            }

            if (client.Player == null)
            {
                return;
            }

            // log.DebugFormat("House PickupItem - Method: {0}, Position: {0}", method, position);
            switch (method)
            {
            case 1:     // garden item
                // no permission to remove items from the garden, return
                if (!house.CanChangeGarden(client.Player, DecorationPermissions.Remove))
                {
                    return;
                }

                foreach (var entry in house.OutdoorItems)
                {
                    // continue if this is not the item in question
                    OutdoorItem oitem = entry.Value;
                    if (oitem.Position != position)
                    {
                        continue;
                    }

                    int i = entry.Key;
                    GameServer.Database.DeleteObject(oitem.DatabaseItem);     // delete the database instance

                    // return indoor item into inventory item, add to player inventory
                    var invitem = GameInventoryItem.Create(house.OutdoorItems[i].BaseItem);
                    if (client.Player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, invitem))
                    {
                        InventoryLogging.LogInventoryAction($"(HOUSE;{house.HouseNumber})", client.Player, eInventoryActionType.Other, invitem.Template, invitem.Count);
                    }

                    house.OutdoorItems.Remove(i);

                    // update garden
                    client.Out.SendGarden(house);

                    ChatUtil.SendSystemMessage(client, "Garden object removed.");
                    ChatUtil.SendSystemMessage(client, $"You get {invitem.Name} and put it in your backpack.");
                    return;
                }

                // no object @ position
                ChatUtil.SendSystemMessage(client, $"There is no Garden Tile at slot {position}!");
                break;

            case 2:
            case 3:     // wall/floor mode
                // no permission to remove items from the interior, return
                if (!house.CanChangeInterior(client.Player, DecorationPermissions.Remove))
                {
                    return;
                }

                if (house.IndoorItems.ContainsKey(position) == false)
                {
                    return;
                }

                IndoorItem iitem = house.IndoorItems[position];
                if (iitem == null)
                {
                    client.Player.Out.SendMessage("error: id was null", eChatType.CT_Help, eChatLoc.CL_SystemWindow);
                    return;
                }

                if (iitem.BaseItem != null)
                {
                    var item = GameInventoryItem.Create(house.IndoorItems[position].BaseItem);
                    if (GetItemBack(item))
                    {
                        if (client.Player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, item))
                        {
                            string removalMsg = $"The {item.Name} is cleared from the {(method == 2 ? "wall surface" : "floor")}.";

                            ChatUtil.SendSystemMessage(client, removalMsg);
                            InventoryLogging.LogInventoryAction($"(HOUSE;{house.HouseNumber})", client.Player, eInventoryActionType.Other, item.Template, item.Count);
                        }
                        else
                        {
                            ChatUtil.SendSystemMessage(client, "You need place in your inventory !");
                            return;
                        }
                    }
                    else
                    {
                        ChatUtil.SendSystemMessage(client, $"The {item.Name} is cleared from the wall surface.");
                    }
                }
                else if (iitem.DatabaseItem.BaseItemID.Contains("GuildBanner"))
                {
                    var it = new ItemTemplate
                    {
                        Id_nb         = iitem.DatabaseItem.BaseItemID,
                        CanDropAsLoot = false,
                        IsDropable    = true,
                        IsPickable    = true,
                        IsTradable    = true,
                        Item_Type     = 41,
                        Level         = 1,
                        MaxCharges    = 1,
                        MaxCount      = 1,
                        Model         = iitem.DatabaseItem.Model,
                        Emblem        = iitem.DatabaseItem.Emblem,
                        Object_Type   = (int)eObjectType.HouseWallObject,
                        Realm         = 0,
                        Quality       = 100
                    };

                    string[] idnb = iitem.DatabaseItem.BaseItemID.Split('_');
                    it.Name = $"{idnb[1]}\'s Banner";

                    // TODO: Once again with guild banners, templates are memory only and will not load correctly once player logs out - tolakram
                    var inv = GameInventoryItem.Create(it);
                    if (client.Player.Inventory.AddItem(eInventorySlot.FirstEmptyBackpack, inv))
                    {
                        string invMsg = $"The {inv.Name} is cleared from the {(method == 2 ? "wall surface" : "floor")}.";

                        ChatUtil.SendSystemMessage(client, invMsg);
                        InventoryLogging.LogInventoryAction($"(HOUSE;{house.HouseNumber})", client.Player, eInventoryActionType.Other, inv.Template, inv.Count);
                    }
                    else
                    {
                        ChatUtil.SendSystemMessage(client, "You need place in your inventory !");
                        return;
                    }
                }
                else if (method == 2)
                {
                    ChatUtil.SendSystemMessage(client, "The decoration item is cleared from the wall surface.");
                }
                else
                {
                    ChatUtil.SendSystemMessage(client, "The decoration item is cleared from the floor.");
                }

                GameServer.Database.DeleteObject(house.IndoorItems[position].DatabaseItem);
                house.IndoorItems.Remove(position);

                var pak = new GSTCPPacketOut(client.Out.GetPacketCode(eServerPackets.HousingItem));
                if (client.Version >= GameClient.eClientVersion.Version1125)
                {
                    pak.WriteShortLowEndian((ushort)housenumber);
                    pak.WriteByte(0x01);
                    pak.WriteByte(0x00);
                    pak.WriteByte((byte)position);
                    pak.Fill(0x00, 11);
                }
                else
                {
                    pak.WriteShort((ushort)housenumber);
                    pak.WriteByte(0x01);
                    pak.WriteByte(0x00);
                    pak.WriteByte((byte)position);
                    pak.WriteByte(0x00);
                }

                foreach (GamePlayer plr in house.GetAllPlayersInHouse())
                {
                    plr.Out.SendTCP(pak);
                }

                break;
            }
        }