Beispiel #1
0
        private void ExecuteHandler(ClientSession session)
        {
            if (_isParsed)
            {
                MapInstance instance = session.CurrentMapInstance;

                Observable.Timer(TimeSpan.FromSeconds(0)).Subscribe(observer =>
                {
                    for (int i = 0; i < Count; i++)
                    {
                        MapCell cell = instance.Map.GetRandomPosition();
                        MonsterMapItem droppedItem = new MonsterMapItem(cell.X, cell.Y, VNum, Amount);
                        instance.DroppedList[droppedItem.TransportId] = droppedItem;
                        instance.Broadcast(
                            $"drop {droppedItem.ItemVNum} {droppedItem.TransportId} {droppedItem.PositionX} {droppedItem.PositionY} {(droppedItem.GoldAmount > 1 ? droppedItem.GoldAmount : droppedItem.Amount)} 0 -1");

                        Thread.Sleep(Time * 1000 / Count);
                    }
                });
            }
            else
            {
                session.SendPacket(session.Character.GenerateSay(ReturnHelp(), 10));
            }
        }
Beispiel #2
0
 public void DropItems(List <Tuple <short, int, short, short> > list)
 {
     // TODO: Parallelize, if possible.
     foreach (Tuple <short, int, short, short> drop in list)
     {
         var droppedItem = new MonsterMapItem(drop.Item3, drop.Item4, drop.Item1, drop.Item2);
         DroppedList[droppedItem.TransportId] = droppedItem;
         Broadcast(
             $"drop {droppedItem.ItemVNum} {droppedItem.TransportId} {droppedItem.PositionX} {droppedItem.PositionY} {(droppedItem.GoldAmount > 1 ? droppedItem.GoldAmount : droppedItem.Amount)} 0 0 -1");
     }
 }
Beispiel #3
0
        public void DropItemByMonster(long?owner, DropDTO drop, short mapX, short mapY, bool isQuest = false)
        {
            // TODO: Parallelize, if possible.
            try
            {
                short          localMapX     = mapX;
                short          localMapY     = mapY;
                List <MapCell> possibilities = new List <MapCell>();

                for (short x = -1; x < 2; x++)
                {
                    for (short y = -1; y < 2; y++)
                    {
                        possibilities.Add(new MapCell {
                            X = x, Y = y
                        });
                    }
                }

                foreach (MapCell possibilitie in possibilities.OrderBy(s => ServerManager.Instance.RandomNumber()))
                {
                    localMapX = (short)(mapX + possibilitie.X);
                    localMapY = (short)(mapY + possibilitie.Y);
                    if (!Map.IsBlockedZone(localMapX, localMapY))
                    {
                        break;
                    }
                }

                var droppedItem = new MonsterMapItem(localMapX, localMapY, drop.ItemVNum, drop.Amount, owner ?? -1);
                DroppedList[droppedItem.TransportId] = droppedItem;
                Broadcast(
                    $"drop {droppedItem.ItemVNum} {droppedItem.TransportId} {droppedItem.PositionX} {droppedItem.PositionY} {(droppedItem.GoldAmount > 1 ? droppedItem.GoldAmount : droppedItem.Amount)} {(isQuest ? 1 : 0)} 0 -1");
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Beispiel #4
0
        private void ExecuteHandler(ClientSession session)
        {
            if (session.Character.LastSkillUse.AddSeconds(1) > DateTime.UtcNow ||
                (session.Character.IsVehicled &&
                 session.CurrentMapInstance?.MapInstanceType != MapInstanceType.EventGameInstance) ||
                !session.HasCurrentMapInstance)
            {
                return;
            }

            if (TransportId < 100000)
            {
                MapButton button = session.CurrentMapInstance.Buttons.Find(s => s.MapButtonId == TransportId);
                if (button != null)
                {
                    session.SendPacket(UserInterfaceHelper.GenerateDelay(2000, 1, $"#git^{button.MapButtonId}"));
                }
            }
            else
            {
                if (!session.CurrentMapInstance.DroppedList.ContainsKey(TransportId))
                {
                    return;
                }

                MapItem mapItem = session.CurrentMapInstance.DroppedList[TransportId];

                if (mapItem != null)
                {
                    bool canpick = false;
                    switch (PickerType)
                    {
                    case 1:
                        canpick = session.Character.IsInRange(mapItem.PositionX, mapItem.PositionY, 8);
                        break;

                    case 2:
                        Mate mate = session.Character.Mates.Find(s =>
                                                                 s.MateTransportId == PickerId && s.CanPickUp);
                        if (mate != null)
                        {
                            canpick = mate.IsInRange(mapItem.PositionX, mapItem.PositionY, 8);
                        }

                        break;
                    }

                    if (canpick && session.HasCurrentMapInstance)
                    {
                        if (mapItem is MonsterMapItem item)
                        {
                            MonsterMapItem monsterMapItem = item;
                            if (session.CurrentMapInstance.MapInstanceType != MapInstanceType.LodInstance &&
                                monsterMapItem.OwnerId.HasValue && monsterMapItem.OwnerId.Value != -1)
                            {
                                Group group = ServerManager.Instance.Groups.Find(g =>
                                                                                 g.IsMemberOfGroup(monsterMapItem.OwnerId.Value) &&
                                                                                 g.IsMemberOfGroup(session.Character.CharacterId));
                                if (item.CreatedDate.AddSeconds(30) > DateTime.UtcNow &&
                                    !(monsterMapItem.OwnerId == session.Character.CharacterId ||
                                      (group?.SharingMode == (byte)GroupSharingType.Everyone)))
                                {
                                    session.SendPacket(
                                        session.Character.GenerateSay(
                                            Language.Instance.GetMessageFromKey("NOT_YOUR_ITEM"), 10));
                                    return;
                                }
                            }

                            // initialize and rarify
                            item.Rarify(null);
                        }

                        if (mapItem.ItemVNum != 1046)
                        {
                            ItemInstance mapItemInstance = mapItem.GetItemInstance();
                            if (mapItemInstance.Item.ItemType == ItemType.Map)
                            {
                                if (mapItemInstance.Item.Effect == 71)
                                {
                                    session.Character.SpPoint += mapItem.GetItemInstance().Item.EffectValue;
                                    if (session.Character.SpPoint > 10000)
                                    {
                                        session.Character.SpPoint = 10000;
                                    }

                                    session.SendPacket(UserInterfaceHelper.GenerateMsg(
                                                           string.Format(Language.Instance.GetMessageFromKey("SP_POINTSADDED"),
                                                                         mapItem.GetItemInstance().Item.EffectValue), 0));
                                    session.SendPacket(session.Character.GenerateSpPoint());
                                }

                                if (ServerManager.Instance.QuestModelList.FirstOrDefault(s =>
                                                                                         s.QuestGiver.QuestGiverId == mapItemInstance.Item.VNum &&
                                                                                         s.QuestGiver.Type == QuestGiverType.ItemLoot) is QuestModel model)
                                {
                                    session.Character.QuestManager.AddQuest(model.QuestId);
                                }

                                session.CurrentMapInstance.DroppedList.Remove(TransportId);
                                session.CurrentMapInstance?.Broadcast(
                                    session.Character.GenerateGet(PickerId, TransportId));
                            }
                            else
                            {
                                lock (session.Character.Inventory)
                                {
                                    short        amount = mapItem.Amount;
                                    ItemInstance inv    = session.Character.Inventory.AddToInventory(mapItemInstance)
                                                          .FirstOrDefault();
                                    if (inv != null)
                                    {
                                        session.CurrentMapInstance.DroppedList.Remove(TransportId);
                                        session.CurrentMapInstance?.Broadcast(
                                            session.Character.GenerateGet(PickerId, TransportId));
                                        if (PickerType == 2)
                                        {
                                            Mate mate = session.Character.Mates.FirstOrDefault(s => s.MateTransportId == PickerId && s.CanPickUp);
                                            if (mate != null)
                                            {
                                                session.SendPacket(session.Character.GenerateIcon(1, 1, inv.ItemVNum));
                                                mate.Owner?.Session.CurrentMapInstance?.Broadcast(StaticPacketHelper.GenerateEff(UserType.Npc, mate.MateTransportId, 5004), mate.PositionX, mate.PositionY);
                                            }
                                            else
                                            {
                                                return;
                                            }
                                        }

                                        session.SendPacket(session.Character.GenerateSay(
                                                               $"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {inv.Item.Name} x {amount}",
                                                               12));
                                        if (session.CurrentMapInstance.MapInstanceType == MapInstanceType.LodInstance)
                                        {
                                            session.CurrentMapInstance?.Broadcast(
                                                session.Character.GenerateSay(
                                                    $"{string.Format(Language.Instance.GetMessageFromKey("ITEM_ACQUIRED_LOD"), session.Character.Name)}: {inv.Item.Name} x {mapItem.Amount}",
                                                    10));
                                        }

                                        session.Character.OnPickupItem(new PickupItemEventArgs(inv.Item));
                                    }
                                    else
                                    {
                                        session.SendPacket(UserInterfaceHelper.GenerateMsg(
                                                               Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE"), 0));
                                    }
                                }
                            }
                        }
                        else
                        {
                            // handle gold drop
                            long   maxGold    = ServerManager.Instance.Configuration.MaxGold;
                            double multiplier =
                                1 + (session.Character.GetBuff(BCardType.CardType.Item,
                                                               (byte)AdditionalTypes.Item.IncreaseEarnedGold)[0] / 100D);
                            multiplier +=
                                (session.Character.ShellEffectMain.FirstOrDefault(s =>
                                                                                  s.Effect == (byte)ShellWeaponEffectType.GainMoreGold)?.Value ?? 0) / 100D;
                            if (mapItem is MonsterMapItem droppedGold)
                            {
                                if (session.Character.Gold + (droppedGold.GoldAmount * multiplier) <= maxGold)
                                {
                                    if (PickerType == 2)
                                    {
                                        session.SendPacket(session.Character.GenerateIcon(1, 1, 1046));
                                    }

                                    session.Character.Gold += (int)(droppedGold.GoldAmount * multiplier);
                                    GameLogger.Instance.LogPickupGold(ServerManager.Instance.ChannelId,
                                                                      session.Character.Name, session.Character.CharacterId,
                                                                      (int)(droppedGold.GoldAmount * multiplier), false);
                                    session.SendPacket(session.Character.GenerateSay(
                                                           $"{Language.Instance.GetMessageFromKey("ITEM_ACQUIRED")}: {mapItem.GetItemInstance().Item.Name} x {droppedGold.GoldAmount}{(multiplier > 1 ? $" + {(int) (droppedGold.GoldAmount * multiplier) - droppedGold.GoldAmount}" : string.Empty)}",
                                                           12));
                                }
                                else
                                {
                                    session.Character.Gold = maxGold;
                                    GameLogger.Instance.LogPickupGold(ServerManager.Instance.ChannelId,
                                                                      session.Character.Name, session.Character.CharacterId,
                                                                      (int)(droppedGold.GoldAmount * multiplier), true);
                                    session.SendPacket(
                                        UserInterfaceHelper.GenerateMsg(Language.Instance.GetMessageFromKey("MAX_GOLD"),
                                                                        0));
                                }
                            }

                            session.SendPacket(session.Character.GenerateGold());
                            session.CurrentMapInstance.DroppedList.Remove(TransportId);
                            session.CurrentMapInstance?.Broadcast(session.Character.GenerateGet(PickerId, TransportId));
                        }
                    }
                }
            }
        }