コード例 #1
0
        def GenerateInventory(caller: unrealsdk.UObject, function: unrealsdk.UFunction, params: unrealsdk.FStruct) -> bool:
            # Whenever a vendor inventory is generated, update our cached costs
            # Unfortuantly ShopInventory is a fixed array, which we can't iterate though, so we have
            #  to do a findall to find the items
            unrealsdk.DoInjectedCallNext()
            caller.GenerateInventory()

            PC = unrealsdk.GetEngine().GamePlayers[0].Actor

            if caller.ShopType == 1:
                self.AmmoCosts[caller] = {}

            for item in unrealsdk.FindAll("WillowUsableItem"):
                if item.Owner != caller:
                    continue
                if item.DefinitionData is None or item.DefinitionData.ItemDefinition is None:
                    continue

                if caller.ShopType == 2:
                    if item.DefinitionData.ItemDefinition.Name == "BuffDrink_HealingInstant":
                        self.VialCosts[caller] = caller.GetSellingPriceForInventory(item, PC, 1)
                        break

                elif caller.ShopType == 1:
                    name = item.DefinitionData.ItemDefinition.Name
                    if name not in self.AMMO_COUNTS:
                        continue

                    info = self.AMMO_COUNTS[name]
                    price = caller.GetSellingPriceForInventory(item, PC, 1) / info.BulletsPerItem
                    self.AmmoCosts[caller][info.ResourcePoolName] = price

            return False
コード例 #2
0
    def GetAmmoCost(self, Pawn: unrealsdk.UObject,
                    Vendor: unrealsdk.UObject) -> int:
        manager = Pawn.Controller.ResourcePoolManager

        ammo_needed = {}
        for pool in unrealsdk.FindAll("AmmoResourcePool"):
            if pool.Outer != manager:
                continue
            name = pool.Definition.Resource.Name
            ammo_needed[name] = int(pool.GetMaxValue()) - int(
                pool.GetCurrentValue())
        # Of course there had to be one odd one out :|
        for pool in unrealsdk.FindAll("ResourcePool"):
            if pool.Outer != manager:
                continue
            if pool.Definition.Resource.Name == "Ammo_Grenade_Protean":
                name = pool.Definition.Resource.Name
                ammo_needed[name] = int(pool.GetMaxValue()) - int(
                    pool.GetCurrentValue())
                break

        total_price = 0
        for item in unrealsdk.FindAll("WillowUsableItem"):
            if item.Owner != Vendor:
                continue
            if item.DefinitionData is None or item.DefinitionData.ItemDefinition is None:
                continue
            name = item.DefinitionData.ItemDefinition.Name
            if name not in self.AMMO_MAP:
                continue

            amount = self.AMMO_MAP[name].AmountPerPurchase
            price = Vendor.GetSellingPriceForInventory(item, Pawn.Controller,
                                                       1) / amount
            needed = ammo_needed[self.AMMO_MAP[name].ResourceName]

            if needed != 0:
                total_price += max(1, int(needed * price))

        return total_price
コード例 #3
0
    def GetHealthCost(self, Pawn: unrealsdk.UObject,
                      Vendor: unrealsdk.UObject) -> int:
        if Pawn.GetHealth() == Pawn.GetMaxHealth():
            return 0

        vial = None
        for item in unrealsdk.FindAll("WillowUsableItem"):
            if item.Owner != Vendor:
                continue
            if item.DefinitionData is None or item.DefinitionData.ItemDefinition is None:
                continue
            name = item.DefinitionData.ItemDefinition.Name
            if name == "BuffDrink_HealingInstant":
                vial = item
                break
        else:
            return 0

        # Again going to assume you haven't modded how much a vial heals
        full_heal_cost = 4 * Vendor.GetSellingPriceForInventory(
            vial, Pawn.Controller, 1)
        missing_health = 1 - (Pawn.GetHealth() / Pawn.GetMaxHealth())

        return max(1, int(full_heal_cost * missing_health))