def generate_loot(self, requester):
        self.clear()

        money = randint(self.world_object.creature_template.gold_min, self.world_object.creature_template.gold_max)
        self.current_money = money

        for loot_item in self.loot_template:
            chance = float(round(uniform(0.0, 1.0), 2) * 100)
            item_template = WorldDatabaseManager.ItemTemplateHolder.item_template_get_by_entry(loot_item.item)
            if item_template:

                # Check if this is a quest item and if the player or group needs it.
                if requester and item_template.class_ == ItemClasses.ITEM_CLASS_QUEST:  # Quest item
                    if not requester.player_or_group_require_quest_item(item_template.entry):
                        continue  # Move on to next item.

                item_chance = loot_item.ChanceOrQuestChance
                item_chance = item_chance if item_chance > 0 else item_chance * -1

                if item_chance >= 100 or chance - item_chance < 0:
                    item = ItemManager.generate_item_from_entry(item_template.entry)
                    if item:
                        # TODO Not handling references to other templates at this moment (mincountOrRef < 0), ignore.
                        if loot_item.mincountOrRef < 0:
                            continue
                        self.current_loot.append(LootHolder(item, randint(loot_item.mincountOrRef, loot_item.maxcount)))
示例#2
0
    def generate_loot(self, requester):
        # Circular refs.
        from game.world.managers.objects.units.LootHolder import LootHolder
        from game.world.managers.objects.item.ItemManager import ItemManager
        self.clear()

        for loot_item in choices(self.loot_template, k=randint(min(3, len(self.loot_template)),
                                                               min(7, len(self.loot_template)))):
            chance = float(round(uniform(0.0, 1.0), 2) * 100)
            item_template = WorldDatabaseManager.ItemTemplateHolder.item_template_get_by_entry(loot_item.item)
            if item_template:
                # Check if this is a quest item and if the player needs it.
                if requester and item_template.class_ == ItemClasses.ITEM_CLASS_QUEST:  # Quest item.
                    if not requester.player_or_group_require_quest_item(item_template.entry, only_self=True):
                        continue  # Move on to next item.

                item_chance = loot_item.ChanceOrQuestChance
                item_chance = item_chance if item_chance > 0 else item_chance * -1

                # TODO: ChanceOrQuestChance = 0 on Items equals 100% chance?
                if item_chance >= 100 or chance - item_chance < 0 or loot_item.ChanceOrQuestChance == 0:
                    item = ItemManager.generate_item_from_entry(item_template.entry)
                    if item:
                        # TODO Not handling references to other templates at this moment (mincountOrRef < 0), ignore.
                        if loot_item.mincountOrRef < 0:
                            continue
                        self.current_loot.append(LootHolder(item, randint(loot_item.mincountOrRef, loot_item.maxcount)))
示例#3
0
 def add_loot(self, loot_item):
     from game.world.managers.objects.loot.LootHolder import LootHolder
     from game.world.managers.objects.item.ItemManager import ItemManager
     item = ItemManager.generate_item_from_entry(loot_item.item)
     if item:
         self.current_loot.append(
             LootHolder(
                 item, randint(loot_item.mincountOrRef,
                               loot_item.maxcount)))
    def generate_loot(self):
        # TODO: Implement loot group handling
        money = randint(self.world_obj.creature_template.gold_min, self.world_obj.creature_template.gold_max)
        self.current_money = money

        for loot_item in self.loot_template:
            chance = float(round(uniform(0.0, 1.0), 2) * 100)
            item_template = WorldDatabaseManager.item_template_get_by_entry(loot_item.item)
            if item_template:
                item_chance = loot_item.ChanceOrQuestChance
                item_chance = item_chance if item_chance > 0 else item_chance * -1

                if item_chance >= 100 or chance - item_chance < 0:
                    item = ItemManager.generate_item_from_entry(item_template.entry)
                    if item:
                        self.current_loot.append(LootHolder(item, randint(loot_item.mincountOrRef, loot_item.maxcount)))
示例#5
0
    def generate_loot(self, requester):
        # TODO: Even if called on parent, this is not properly set as with CreatureLootManager.
        if len(self.loot_template) == 0:
            self.loot_template = self.populate_loot_template()

        # For now, randomly pick 3..7 items.
        for loot_item in choices(self.loot_template, k=randint(min(3, len(self.loot_template)), min(7, len(self.loot_template)))):
            chance = float(round(uniform(0.0, 1.0), 2) * 100)
            item_template = WorldDatabaseManager.ItemTemplateHolder.item_template_get_by_entry(loot_item.item)
            if item_template:
                # Check if this is a quest item and if the player or group needs it.
                if requester and item_template.class_ == ItemClasses.ITEM_CLASS_QUEST:  # Quest item
                    if not requester.player_or_group_require_quest_item(item_template.entry):
                        continue  # Move on to next item.

                item_chance = loot_item.ChanceOrQuestChance
                item_chance = item_chance if item_chance > 0 else item_chance * -1

                # TODO: ChanceOrQuestChance = 0 on Gameobjects equals 100% chance?
                if item_chance >= 100 or chance - item_chance < 0 or loot_item.ChanceOrQuestChance == 0:
                    item = ItemManager.generate_item_from_entry(item_template.entry)
                    if item:
                        self.current_loot.append(LootHolder(item, randint(loot_item.mincountOrRef, loot_item.maxcount)))