Example #1
0
 protected Loot(ILootable looted, uint money, LootItem[] items)
     : this()
 {
     Money    = money;
     Items    = items;
     Lootable = looted;
 }
Example #2
0
        public static void FindLooters(ILootable lootable, Character initialLooter, IList <LooterEntry> looters)
        {
            if (lootable.UseGroupLoot)
            {
                var groupMember = initialLooter.GroupMember;
                if (groupMember != null)
                {
                    var group          = groupMember.Group;
                    var method         = group.LootMethod;
                    var usesRoundRobin = method == LootMethod.RoundRobin;

                    if (usesRoundRobin)
                    {
                        var member = group.GetNextRoundRobinMember();
                        if (member != null)
                        {
                            looters.Add(member.Character.LooterEntry);
                        }
                    }
                    else
                    {
                        group.GetNearbyLooters(lootable, initialLooter, looters);
                    }
                    return;
                }
            }

            looters.Add(initialLooter.LooterEntry);
        }
Example #3
0
        private bool IsAlreadyAuctioned(NPC auctioneer, ILootable item)
        {
            if (item == null)
            {
                return(true);
            }

            var itemId = item.EntityId.Low;

            //if (AllowInterFactionAuctions)
            //    return NeutralAuctions.HasItemById(itemId);

            //if (auctioneer.AuctioneerEntry.Auctions.HasItemById(itemId))
            //    return true;

            //switch (auctioneer.AuctioneerEntry.LinkedHouseFaction)
            //{
            //    case AuctionHouseFaction.Alliance:
            //        return NeutralAuctions.HasItemById(itemId) || HordeAuctions.HasItemById(itemId);
            //    case AuctionHouseFaction.Horde:
            //        return NeutralAuctions.HasItemById(itemId) || AllianceAuctions.HasItemById(itemId);
            //    case AuctionHouseFaction.Neutral:
            //        return AllianceAuctions.HasItemById(itemId) || HordeAuctions.HasItemById(itemId);
            //    default:
            //        return true;
            //}
            return(AuctionItems.ContainsKey(itemId));
        }
Example #4
0
        /// <summary>
        /// Generates loot for Items and GOs.
        /// </summary>
        /// <param name="lootable">The Object or Unit that is being looted</param>
        /// <returns>The object's loot or null if there is nothing to get or the given Character can't access the loot.</returns>
        public static ObjectLoot CreateAndSendObjectLoot(ILootable lootable, Character initialLooter,
                                                         LootEntryType type, bool heroic)
        {
            var oldLoot = initialLooter.LooterEntry.Loot;

            if (oldLoot != null)
            {
                oldLoot.ForceDispose();
            }
            var looters = FindLooters(lootable, initialLooter);

            var loot = CreateLoot <ObjectLoot>(lootable, initialLooter, type, heroic, 0);            // TODO: pass mapid

            if (loot != null)
            {
                initialLooter.LooterEntry.Loot = loot;
                loot.Initialize(initialLooter, looters, 0);                 // TODO: pass mapid
                LootHandler.SendLootResponse(initialLooter, loot);
            }
            else
            {
                //lootable.OnFinishedLooting();
                // empty Item -> Don't do anything
            }
            return(loot);
        }
Example #5
0
        public static IList <LooterEntry> FindLooters(ILootable lootable, Character initialLooter)
        {
            var looters = new List <LooterEntry>();

            FindLooters(lootable, initialLooter, looters);
            return(looters);
        }
Example #6
0
 protected Loot(ILootable looted, uint money, LootItem[] items)
     : this()
 {
     this.Money    = money;
     this.Items    = items;
     this.Lootable = looted;
 }
Example #7
0
        /// <summary>
        /// Creates a new Loot object and returns it or null, if there is nothing to be looted.
        /// </summary>
        /// <typeparam name="T"><see cref="ObjectLoot"/> or <see cref="NPCLoot"/></typeparam>
        /// <param name="lootable"></param>
        /// <param name="initialLooter"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static T CreateLoot <T>(ILootable lootable, Character initialLooter, LootEntryType type, bool heroic, MapId mapid)
            where T : Loot, new()
        {
            var looters = FindLooters(lootable, initialLooter);

            var items = CreateLootItems(lootable.GetLootId(type), type, heroic, looters);
            var money = lootable.LootMoney * DefaultMoneyDropFactor;

            if (items.Length == 0 && money == 0)
            {
                if (lootable is GameObject)
                {
                    // TODO: Don't mark GO as lootable if it has nothing to loot
                    money = 1;
                }
            }

            if (items.Length > 0 || money > 0)
            {
                var loot = new T {
                    Lootable = lootable, Money = money, Items = items
                };
                loot.Initialize(initialLooter, looters, mapid);
                return(loot);
            }
            else
            {
                //var loot = new T { Lootable = lootable, Money = 1, Items = LootItem.EmptyArray };
                //loot.Initialize(initialLooter, looters);
                //return loot;
                return(null);
            }
        }
Example #8
0
        public void GetNearbyLooters(ILootable lootable, WorldObject initialLooter,
                                     ICollection <LooterEntry> looters)
        {
            WorldObject center;

            if (lootable is WorldObject)
            {
                center = (WorldObject)lootable;
            }
            else
            {
                center = initialLooter;
            }

            GroupMember otherMember;

            foreach (Character chr in center.GetObjectsInRadius(LootMgr.LootRadius, ObjectTypes.Player, false, 0))
            {
                if (chr.IsAlive && (chr == initialLooter ||
                                    ((otherMember = chr.GroupMember) != null && otherMember.Group == this)))
                {
                    looters.Add(chr.LooterEntry);
                }
            }
        }
Example #9
0
        public static IList <LooterEntry> FindLooters(ILootable lootable, Character initialLooter)
        {
            List <LooterEntry> looterEntryList = new List <LooterEntry>();

            LootMgr.FindLooters(lootable, initialLooter, (IList <LooterEntry>)looterEntryList);
            return((IList <LooterEntry>)looterEntryList);
        }
Example #10
0
 public static void FindLooters(ILootable lootable, Character initialLooter, IList <LooterEntry> looters)
 {
     /*if (lootable.UseGroupLoot)
      * {
      *      var groupMember = initialLooter.GroupMember;
      *      if (groupMember != null)
      *      {
      *              var group = groupMember.Group;
      *              var method = group.LootMethod;
      *              var usesRoundRobin = method == LootMethod.RoundRobin;
      *
      *              if (usesRoundRobin)
      *              {
      *                      var member = group.GetNextRoundRobinMember();
      *                      if (member != null)
      *                      {
      *                              looters.Add(member.Character.LooterEntry);
      *                      }
      *              }
      *              else
      *              {
      *                      group.GetNearbyLooters(lootable, initialLooter, looters);
      *              }
      *              return;
      *      }
      * }
      *
      * looters.Add(initialLooter.LooterEntry);*/
 }
Example #11
0
        /// <summary>
        /// Whether the given lootable contains quest items for the given Character when looting with the given type
        /// </summary>
        public static bool ContainsQuestItemsFor(this ILootable lootable, Character chr, LootEntryType type)
        {
            Asda2Loot loot = lootable.Loot;

            if (loot != null)
            {
                return(((IEnumerable <Asda2LootItem>)loot.Items).Any <Asda2LootItem>((Func <Asda2LootItem, bool>)(item =>
                {
                    if (item.Template.HasQuestRequirements)
                    {
                        return item.Template.CheckQuestConstraints(chr);
                    }
                    return false;
                })));
            }
            ResolvedLootItemList entries = lootable.GetEntries(type);

            if (entries != null)
            {
                return(entries.Any <LootEntity>((Func <LootEntity, bool>)(entry =>
                {
                    if (entry.ItemTemplate.HasQuestRequirements)
                    {
                        return entry.ItemTemplate.CheckQuestConstraints(chr);
                    }
                    return false;
                })));
            }
            return(false);
        }
Example #12
0
        private void GenerateLoot(ILootable lootable)
        {
            LootConfig.LootDropDef lootDropDef = lootable._lootDropDef;

            List <LootConfig.ProbabilityDef> probabilities = lootDropDef.probabilities;

            probabilities.Sort(LootUtil.CompareLootByProbability);

            int   lootToDrop = LootUtil.GetLootDropCount(lootDropDef);
            float totalSum   = LootUtil.GetTotalSum(probabilities);

            for (int i = 0; i < lootToDrop; i++)
            {
                Loot.Rarity        rarity  = LootUtil.GetWeightedRarity(probabilities, totalSum);
                LootConfig.LootDef lootDef = _lootConfig.GetLootDef(rarity);
                int bucket = Random.Range(0, lootDef.lootItems.Count);
                LootConfig.LootItemDef itemDef = lootDef.lootItems[bucket];
                string    key  = Storeable.GetCachedStoreableKey(itemDef.type);
                ILootItem item = _lootPool.GetPooledObject(key).GetComponent <ILootItem>();
                if (item != null)
                {
                    item.Init(lootable, _playerCombatSystem.playerController.transform, lootDef, _lootConfig, itemDef);
                }
                else
                {
                    Debug.LogError("Item of type " + key + " does not implement  ILootItem");
                }
            }
        }
Example #13
0
        public ChildNode <TKey, TGenerate> AddLeaf(ILootable <TKey, TGenerate> value)
        {
            if (value == null)
            {
                _logger?.Log(
                    "null value detected in leaf-node, leaf is ignored",
                    LoggerSeverity.Error,
                    this
                    );
                return(this);
            }
            if (_items.Contains(value))
            {
                _logger?.Log(
                    $"key [{value.Key}] is already registered, new rarity [{value.Rarity}] is ignored",
                    LoggerSeverity.Warning
                    );
            }

            _logger?.Log(
                $"{value} registered",
                LoggerSeverity.Info
                );
            _items.Add(value);
            _items.Sort(Comparer <ILootable <TKey, TGenerate> > .Create((a, b) => a.Rarity.CompareTo(b.Rarity)));
            return(this);
        }
Example #14
0
 public bool Pickup(ILootable pickupEntity)
 {
     if (pickupEntity.pickupType == PickupType.KEY)
     {
         return(AddKey(pickupEntity));
     }
     return(AddToSql(pickupEntity));
 }
Example #15
0
 private bool IsAlreadyAuctioned(NPC auctioneer, ILootable item)
 {
     if (item == null)
     {
         return(true);
     }
     return(AuctionItems.ContainsKey(item.EntityId.Low));
 }
Example #16
0
 public void Add(ILootable <string> item)
 {
     if (currMode != ItemLibraryMode.All)
     {
         lootHashMap[currMode].Add(item);
     }
     allLoot.Add(item);
 }
Example #17
0
 protected virtual void OnDispose()
 {
     if (Lootable != null)
     {
         Lootable.OnFinishedLooting();
         Lootable = null;
     }
 }
Example #18
0
 protected virtual void OnDispose()
 {
     if (this.Lootable == null)
     {
         return;
     }
     this.Lootable.OnFinishedLooting();
     this.Lootable = (ILootable)null;
 }
Example #19
0
 protected virtual void OnDispose()
 {
     if (Lootable == null)
     {
         return;
     }
     Lootable.OnFinishedLooting();
     Lootable = null;
 }
Example #20
0
 public static void SendLootFail(Character looter, ILootable lootable)
 {
     using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_LOOT_RESPONSE))
     {
         packet.Write(lootable.EntityId);
         packet.Write((uint)LootResponseType.Fail);
         looter.Client.Send(packet);
     }
 }
 /// <summary>
 /// Generiert aus dem uu. variablen normalen Loot-Objekt (<see cref="ILootable{T}"/>) einen Loot container, der die sonstigen Werte übernimmt
 /// </summary>
 /// <param name="item">Das normale Loot-Objekt</param>
 /// <param name="representationString">Optionaler <see cref="string"/> für benutzerdefinierte Repräsentation in ToString()</param>
 public LootObjectContainer(ILootable <T> item, string representationString = null)
 {
     innerItem       = item.Item;
     containerName   = item.Name;
     containerRarity = item.Rarity;
     containerType   = item.Type;
     rarityTable     = item.rarTable;
     rep             = representationString;
 }
Example #22
0
 void SetLoot(ILootable l)
 {
     currentlyLooting = l;
     foreach (Item i in currentlyLooting.GetLoot())
     {
         LootItemObject temp = Instantiate(prefab, transform.position, Quaternion.identity, transform);
         temp.SetItem(i);
     }
 }
Example #23
0
 /// <summary>
 /// Fügt ein neues Element zur momentanen Liste hinzu
 /// </summary>
 /// <param name="item">Das neue Element</param>
 public virtual void Add(ILootable <T> item)
 {
     if (currMode != "All")
     {
         lootHashMap[currMode].Add(item);
     }
     allInternalLoot.Add(item);
     OnLootChanged(this, new SplitLootChangedEventArgs <T>(item, EditType.ItemsAdded, currMode));
 }
Example #24
0
        private void OnEnemyDestroyed(GhostGen.GeneralEvent e)
        {
            ILootable lootable = e.data as ILootable;

            if (lootable != null)
            {
                GenerateLoot(lootable);
            }
        }
Example #25
0
 public static void SendLootFail(Character looter, ILootable lootable)
 {
     using (RealmPacketOut packet = new RealmPacketOut(RealmServerOpCode.SMSG_LOOT_RESPONSE))
     {
         packet.Write((ulong)lootable.EntityId);
         packet.Write(0U);
         looter.Client.Send(packet, false);
     }
 }
Example #26
0
 private bool AddToSql(ILootable pickupEntity)
 {
     if (!Player.I.TryGetComponent <SqlComponent>(out SqlComponent sqlComponent))
     {
         return(false);
     }
     sqlComponent.AddItem(pickupEntity.loot);
     return(true);
 }
Example #27
0
 private bool AddKey(ILootable pickupEntity)
 {
     if (pickupEntity.loot.objectType == typeof(DirectoryKey))
     {
         HostHandler.I.currentHost.RegisterKey(pickupEntity.loot);
         return(true);
     }
     HostHandler.I.currentHost.GetComponent <SshKey>().isAvailable = true;
     return(true);
 }
Example #28
0
        /// <summary>
        /// Löscht ein Item aus der Liste
        /// </summary>
        /// <param name="item">Das zu löschende Item</param>
        /// <returns>True bei Erfolg</returns>
        public virtual bool Remove(ILootable <T> item)
        {
            bool result = allLoot.Remove(item);

            if (result)
            {
                OnLootChanged(this, new LootChangedEventArgs <T>(item, EditType.ItemsRemoved));
            }
            return(result);
        }
Example #29
0
        /// <summary>
        /// Löscht ein Item aus der Liste
        /// </summary>
        /// <param name="item">Das zu löschende Item</param>
        /// <param name="key">Der Loot-Pool-Key</param>
        /// <returns>True bei Erfolg</returns>
        public virtual bool Remove(ILootable <T> item, string key = null)
        {
            key = key ?? "all";
            bool result = lootHashMap[key].Remove(item);

            if (result)
            {
                OnLootChanged(this, new SplitLootChangedEventArgs <T>(item, EditType.ItemsRemoved, key));
            }
            return(result);
        }
Example #30
0
    public void ShowLootWindow(ILootable l)
    {
        if (!gameObject.activeSelf)
        {
            gameObject.SetActive(true);
        }
        Clear();


        SetLoot(l);
        // transform.position = pos;
    }
Example #31
0
 protected Loot(ILootable looted, uint money, LootItem[] items)
     : this()
 {
     Money = money;
     Items = items;
     Lootable = looted;
 }
Example #32
0
		public void GetNearbyLooters(ILootable lootable, WorldObject initialLooter,
			ICollection<LooterEntry> looters)
		{
			WorldObject center;
			if (lootable is WorldObject)
			{
				center = (WorldObject)lootable;
			}
			else
			{
				center = initialLooter;
			}

			GroupMember otherMember;
			foreach (Character chr in center.GetObjectsInRadius(LootMgr.LootRadius, ObjectTypes.Player, false, 0))
			{
				if (chr.IsAlive && (chr == initialLooter ||
					((otherMember = chr.GroupMember) != null && otherMember.Group == this)))
				{
					looters.Add(chr.LooterEntry);
				}
			}
		}
Example #33
0
 protected virtual void OnDispose()
 {
     if (Lootable != null)
     {
         Lootable.OnFinishedLooting();
         Lootable = null;
     }
 }
Example #34
0
		public static void SendLootFail(Character looter, ILootable lootable)
		{
			using (var packet = new RealmPacketOut(RealmServerOpCode.SMSG_LOOT_RESPONSE))
			{
				packet.Write(lootable.EntityId);
				packet.Write((uint)LootResponseType.Fail);
				looter.Client.Send(packet);
			}
		}
Example #35
0
		public NPCLoot(ILootable looted, uint money, LootItem[] items)
			: base(looted, money, items)
		{
		}
Example #36
0
		public NPCLoot(ILootable looted, uint money, ItemStackTemplate[] items)
			: base(looted, money, LootItem.Create(items))
		{
		}
Example #37
0
		/// <summary>
		/// Requires loot to already be generated
		/// </summary>
		/// <param name="lootable"></param>
		public void TryLoot(ILootable lootable)
		{
			Release(); // make sure that the Character is not still looting something else

			var loot = lootable.Loot;
			if (loot == null)
			{
				LootHandler.SendLootFail(m_owner, lootable);
				// TODO: Kneel and unkneel?
			}
			else if (MayLoot(loot))
			{
				// we are either already a looter or become a new one
				m_owner.CancelAllActions();
				Loot = loot;

				LootHandler.SendLootResponse(m_owner, loot);
			}
			else
			{
				LootHandler.SendLootFail(m_owner, lootable);
			}
		}