コード例 #1
0
ファイル: ItemCommands.cs プロジェクト: 0xFh/Asda2-Project
            public static bool AddItem(Character chr, Asda2ItemTemplate templ, int amount, Character triggerer)
            {
                var actualAmount = amount;
                var inv          = chr.Asda2Inventory;

                // just add
                Asda2Item           item = null;
                Asda2InventoryError err  = inv.TryAdd((int)templ.ItemId, amount, false, ref item);

                if (err != Asda2InventoryError.Ok || amount < actualAmount)
                {
                    // something went wrong
                    if (err != Asda2InventoryError.Ok)
                    {
                        Asda2InventoryHandler.SendItemReplacedResponse(chr.Client);
                    }
                    return(false);
                }

                Log.Create(Log.Types.ItemOperations, LogSourceType.Character, chr.EntryId)
                .AddAttribute("source", 0, "created_by_gm")
                .AddItemAttributes(item)
                .AddAttribute("map", (double)chr.MapId, chr.MapId.ToString())
                .AddAttribute("x", chr.Asda2Position.X)
                .AddAttribute("y", chr.Asda2Position.Y)
                .AddAttribute("gm", triggerer.EntryId, triggerer.Name)
                .Write();
                Asda2InventoryHandler.SendBuyItemResponse(Asda2BuyItemStatus.Ok, chr, new[] { item, null, null, null, null });
                return(true);
            }
コード例 #2
0
            public static bool AddItem(Character chr, Asda2ItemTemplate templ, int amount, Character triggerer)
            {
                int num = amount;
                Asda2PlayerInventory asda2Inventory      = chr.Asda2Inventory;
                Asda2Item            asda2Item           = (Asda2Item)null;
                Asda2InventoryError  asda2InventoryError = asda2Inventory.TryAdd((int)templ.ItemId, amount, false,
                                                                                 ref asda2Item, new Asda2InventoryType?(), (Asda2Item)null);

                if (asda2InventoryError != Asda2InventoryError.Ok || amount < num)
                {
                    if (asda2InventoryError != Asda2InventoryError.Ok)
                    {
                        Asda2InventoryHandler.SendItemReplacedResponse(chr.Client, Asda2InventoryError.NotInfoAboutItem,
                                                                       (short)0, (byte)0, 0, (short)0, 0, (byte)0, 0, (short)0, false);
                    }
                    return(false);
                }

                Log.Create(Log.Types.ItemOperations, LogSourceType.Character, chr.EntryId)
                .AddAttribute("source", 0.0, "created_by_gm").AddItemAttributes(asda2Item, "")
                .AddAttribute("map", (double)chr.MapId, chr.MapId.ToString())
                .AddAttribute("x", (double)chr.Asda2Position.X, "")
                .AddAttribute("y", (double)chr.Asda2Position.Y, "")
                .AddAttribute("gm", (double)triggerer.EntryId, triggerer.Name).Write();
                Asda2InventoryHandler.SendBuyItemResponse(Asda2BuyItemStatus.Ok, chr, new Asda2Item[5]
                {
                    asda2Item,
                    null,
                    null,
                    null,
                    null
                });
                return(true);
            }
コード例 #3
0
ファイル: Asda2Loot.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// This gives items to everyone involved. Will only work the first time its called.
        /// Afterwards <c>IsMoneyLooted</c> will be true.
        /// </summary>
        public bool GiveItems()
        {
            if (!(this.Lootable is NPC))
            {
                return(false);
            }
            if (this.Group == null)
            {
                Asda2LooterEntry asda2LooterEntry = this.Looters.FirstOrDefault <Asda2LooterEntry>();
                if (asda2LooterEntry != null && asda2LooterEntry.Owner != null)
                {
                    foreach (Asda2LootItem asda2LootItem in this.Items)
                    {
                        Asda2Item           asda2Item           = (Asda2Item)null;
                        Asda2InventoryError asda2InventoryError =
                            asda2LooterEntry.Owner.Asda2Inventory.TryAdd((int)asda2LootItem.Template.ItemId,
                                                                         asda2LootItem.Amount, true, ref asda2Item, new Asda2InventoryType?(), (Asda2Item)null);
                        Log.Create(Log.Types.ItemOperations, LogSourceType.Character, asda2LooterEntry.Owner.EntryId)
                        .AddAttribute("source", 0.0, "loot").AddItemAttributes(asda2Item, "")
                        .AddAttribute("map", (double)asda2LooterEntry.Owner.MapId,
                                      asda2LooterEntry.Owner.MapId.ToString())
                        .AddAttribute("x", (double)asda2LooterEntry.Owner.Asda2Position.X, "")
                        .AddAttribute("y", (double)asda2LooterEntry.Owner.Asda2Position.Y, "")
                        .AddAttribute("monstrId",
                                      (double)(this.MonstrId.HasValue ? this.MonstrId : new short?((short)0)).Value, "")
                        .Write();
                        if (asda2InventoryError != Asda2InventoryError.Ok)
                        {
                            Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.NoSpace,
                                                                           (Asda2Item)null, asda2LooterEntry.Owner);
                            break;
                        }

                        Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.Ok, asda2Item,
                                                                       asda2LooterEntry.Owner);
                        if (asda2Item.Template.Quality >= Asda2ItemQuality.Green)
                        {
                            ChatMgr.SendGlobalMessageResponse(asda2LooterEntry.Owner.Name,
                                                              ChatMgr.Asda2GlobalMessageType.HasObinedItem, asda2Item.ItemId, (short)0, (short)0);
                        }
                        asda2LootItem.Taken = true;
                    }
                }
            }
            else
            {
                List <Character> characterList = new List <Character>();
                if (this.UsesRoundRobin)
                {
                    Asda2LooterEntry asda2LooterEntry = this.Looters.FirstOrDefault <Asda2LooterEntry>();
                    if (asda2LooterEntry != null && asda2LooterEntry.Owner != null)
                    {
                        characterList.Add(asda2LooterEntry.Owner);
                        foreach (Character objectsInRadiu in (IEnumerable <WorldObject>)(!(this.Lootable is WorldObject)
                                ? (WorldObject)asda2LooterEntry.Owner
                                : (WorldObject)this.Lootable)
                                 .GetObjectsInRadius <WorldObject>(Asda2LootMgr.LootRadius, ObjectTypes.Player, false, 0))
                        {
                            GroupMember groupMember;
                            if (objectsInRadiu.IsAlive &&
                                (objectsInRadiu == asda2LooterEntry.Owner ||
                                 (groupMember = objectsInRadiu.GroupMember) != null && groupMember.Group == this.Group))
                            {
                                characterList.Add(objectsInRadiu);
                            }
                        }
                    }
                }
                else
                {
                    foreach (Asda2LooterEntry looter in (IEnumerable <Asda2LooterEntry>) this.Looters)
                    {
                        if (looter.m_owner != null)
                        {
                            characterList.Add(looter.m_owner);
                        }
                    }
                }

                if (characterList.Count > 0)
                {
                    List <List <Asda2LootItem> > asda2LootItemListList = new List <List <Asda2LootItem> >();
                    int index1 = 0;
                    if (characterList.Count == 1)
                    {
                        asda2LootItemListList.Add(new List <Asda2LootItem>((IEnumerable <Asda2LootItem>) this.Items));
                    }
                    else
                    {
                        foreach (Character character in characterList)
                        {
                            asda2LootItemListList.Add(new List <Asda2LootItem>());
                        }
                        foreach (Asda2LootItem asda2LootItem in this.Items)
                        {
                            int index2 = Utility.Random(0, characterList.Count - 1);
                            asda2LootItemListList[index2].Add(asda2LootItem);
                        }
                    }

                    foreach (Character chr in characterList)
                    {
                        foreach (Asda2LootItem asda2LootItem in asda2LootItemListList[index1])
                        {
                            Asda2Item           asda2Item           = (Asda2Item)null;
                            Asda2InventoryError asda2InventoryError =
                                chr.Asda2Inventory.TryAdd((int)asda2LootItem.Template.ItemId, asda2LootItem.Amount,
                                                          true, ref asda2Item, new Asda2InventoryType?(), (Asda2Item)null);
                            Log.Create(Log.Types.ItemOperations, LogSourceType.Character, chr.EntryId)
                            .AddAttribute("source", 0.0, "loot").AddItemAttributes(asda2Item, "")
                            .AddAttribute("map", (double)chr.MapId, chr.MapId.ToString())
                            .AddAttribute("x", (double)chr.Asda2Position.X, "")
                            .AddAttribute("y", (double)chr.Asda2Position.Y, "").AddAttribute("monstrId",
                                                                                             (double)(this.MonstrId.HasValue ? this.MonstrId : new short?((short)0)).Value, "")
                            .Write();
                            if (asda2InventoryError != Asda2InventoryError.Ok)
                            {
                                Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.NoSpace,
                                                                               (Asda2Item)null, chr);
                                break;
                            }

                            Asda2InventoryHandler.SendItemPickupedResponse(Asda2PickUpItemStatus.Ok, asda2Item, chr);
                            asda2LootItem.Taken = true;
                        }

                        ++index1;
                    }
                }
            }

            if (!this.IsAllItemsTaken)
            {
                return(false);
            }
            this.Dispose();
            return(true);
        }