示例#1
0
        public override void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
        {
            base.GetHeldItemInfo(inSlot, dsc, world, withDebugInfo);

            float[]     chances = new float[10];
            ItemStack[] stacks  = new ItemStack[10];
            int         i       = 0;

            foreach (var val in inSlot.Itemstack.Attributes)
            {
                if (!val.Key.StartsWith("stack") || !(val.Value is TreeAttribute))
                {
                    continue;
                }

                TreeAttribute subtree = val.Value as TreeAttribute;

                if (i == 0)
                {
                    dsc.AppendLine("Contents: ");
                }
                ItemStack cstack = subtree.GetItemstack("stack");
                cstack.ResolveBlockOrItem(world);

                dsc.AppendLine(cstack.StackSize + "x " + cstack.GetName() + ": " + subtree.GetFloat("chance") + "%");

                i++;
            }
        }
        internal void ResolveLoot(ItemSlot slot, InventoryBase inventory, IWorldAccessor worldForResolve)
        {
            double diceRoll = worldForResolve.Rand.NextDouble();

            ItemStack ownstack = slot.Itemstack;

            slot.Itemstack = null;

            IAttribute[] vals = ownstack.Attributes.Values;
            vals.Shuffle(worldForResolve.Rand);

            foreach (var val in vals)
            {
                if (!(val is TreeAttribute))
                {
                    continue;
                }

                TreeAttribute subtree = val as TreeAttribute;
                float         chance  = subtree.GetFloat("chance") / 100f;

                if (chance > diceRoll)
                {
                    ItemStack cstack = subtree.GetItemstack("stack");
                    cstack.ResolveBlockOrItem(worldForResolve);
                    slot.Itemstack = cstack;
                    return;
                }

                diceRoll -= chance;
            }
        }
示例#3
0
        internal void ResolveLoot(ItemSlot slot, IWorldAccessor worldForResolve)
        {
            object dval;

            worldForResolve.Api.ObjectCache.TryGetValue("donotResolveImports", out dval);
            if (dval is bool && (bool)dval)
            {
                return;
            }

            double diceRoll = rand.NextDouble();

            ItemStack ownstack = slot.Itemstack;

            slot.Itemstack = null;

            IAttribute[] vals = ownstack.Attributes.Values;
            vals.Shuffle(rand);

            foreach (var val in vals)
            {
                if (!(val is TreeAttribute))
                {
                    continue;
                }

                TreeAttribute subtree = val as TreeAttribute;
                float         chance  = subtree.GetFloat("chance") / 100f;

                if (chance > diceRoll)
                {
                    ItemStack cstack = subtree.GetItemstack("stack").Clone();

                    // A items and blocks ItemStackAttributes already has the FixMapping applied to them during Collectible.OnLoadCollectibleMappings(), so we only need to check if the collectible is set or not
                    if (cstack.Collectible != null)
                    {
                        cstack.ResolveBlockOrItem(worldForResolve);
                        slot.Itemstack = cstack;
                    }
                    else
                    {
                        slot.Itemstack = null;
                    }
                    return;
                }

                diceRoll -= chance;
            }
        }
示例#4
0
        internal void ResolveLoot(ItemSlot slot, InventoryBase inventory, IWorldAccessor worldForResolve)
        {
            object dval = null;

            worldForResolve.Api.ObjectCache.TryGetValue("donotResolveImports", out dval);
            if (dval is bool && (bool)dval)
            {
                return;
            }

            double diceRoll = rand.NextDouble();

            ItemStack ownstack = slot.Itemstack;

            slot.Itemstack = null;

            IAttribute[] vals = ownstack.Attributes.Values;
            vals.Shuffle(rand);

            foreach (var val in vals)
            {
                if (!(val is TreeAttribute))
                {
                    continue;
                }

                TreeAttribute subtree = val as TreeAttribute;
                float         chance  = subtree.GetFloat("chance") / 100f;

                if (chance > diceRoll)
                {
                    ItemStack cstack = subtree.GetItemstack("stack");
                    cstack.ResolveBlockOrItem(worldForResolve);
                    slot.Itemstack = cstack;
                    return;
                }

                diceRoll -= chance;
            }
        }
        private void OnEventLootRandomizer(string eventName, ref EnumHandling handling, IAttribute data)
        {
            if (capi == null)
            {
                return;
            }

            string   inventoryd = (data as TreeAttribute).GetString("inventoryId");
            int      slotId     = (data as TreeAttribute).GetInt("slotId");
            ItemSlot slot       = capi.World.Player.InventoryManager.GetInventory(inventoryd)[slotId];

            if (dialogs.ContainsKey(slot))
            {
                return;
            }

            float[]     chances = new float[10];
            ItemStack[] stacks  = new ItemStack[10];
            int         i       = 0;

            foreach (var val in slot.Itemstack.Attributes)
            {
                if (!val.Key.StartsWith("stack") || !(val.Value is TreeAttribute))
                {
                    continue;
                }

                TreeAttribute subtree = val.Value as TreeAttribute;

                chances[i] = subtree.GetFloat("chance");
                stacks[i]  = subtree.GetItemstack("stack");
                stacks[i].ResolveBlockOrItem(capi.World);
                i++;
            }


            dialogs[slot] = new GuiDialogItemLootRandomizer(stacks, chances, capi);
            dialogs[slot].TryOpen();
            dialogs[slot].OnClosed += () => DidCloseLootRandomizer(slot, dialogs[slot]);
        }
示例#6
0
 /// <summary> Get the current pewter fatigue </summary>
 public float GetPewterFatigue()
 {
     return(allomancyTree.GetFloat("pewterFatigue"));
 }