コード例 #1
0
        public static bool InventoryContainsDragonball(int whichDragonball, Item[] inventory)
        {
            for (var i = 0; i < inventory.Length; i++)
            {
                var item = inventory[i];
                if (item == null)
                {
                    continue;
                }

                if (item.modItem == null)
                {
                    continue;
                }

                if (!(item.modItem is DragonBallItem))
                {
                    continue;
                }

                var dbItem = item.modItem as DragonBallItem;
                // assume this runs before the inventory loop that turns stone balls into real ones - we don't care which it is, if it's legit, we don't want to spawn dragonballs replacing it.
                if (dbItem.item.type == ItemHelper.GetItemTypeFromName(DragonBallItem.GetStoneBallFromNumber(whichDragonball)) && dbItem.WorldDragonBallKey == GetWorld().WorldDragonBallKey)
                {
                    return(true);
                }
                if (dbItem.item.type == ItemHelper.GetItemTypeFromName(DragonBallItem.GetDragonBallItemTypeFromNumber(whichDragonball)) && dbItem.WorldDragonBallKey == GetWorld().WorldDragonBallKey)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public static void SwapDragonBallWithStoneBall(Item[] inventory, int WorldDragonBallKey, int WhichDragonBall)
        {
            // this dragon ball was pulled in from another world. Turn it into a rock.
            int dbKey  = WorldDragonBallKey;
            int dbSlot = ItemHelper.RemoveDragonBall(inventory, WorldDragonBallKey, WhichDragonBall);

            // something went wrong, abort.
            if (dbSlot == -1)
            {
                return;
            }
            var newStoneBall = DBZMOD.instance.GetItem(DragonBallItem.GetStoneBallFromNumber(WhichDragonBall)).item.DeepClone();
            var dbData       = newStoneBall.modItem as DragonBallItem;

            dbData.WorldDragonBallKey = dbKey;
            inventory[dbSlot]         = newStoneBall;
        }
コード例 #3
0
        /// <summary>
        ///     Return the slot of the inventory a dragon ball was in after deleting it.
        ///     This is used to replace a dragon ball with an inert dragon ball brought from other worlds.
        /// </summary>
        /// <returns></returns>
        public static int RemoveStoneBall(Item[] inventory, int dbKey, int whichDragonBall)
        {
            string ballType    = DragonBallItem.GetStoneBallFromNumber(whichDragonBall);
            int    ballTypeInt = GetItemTypeFromName(ballType);

            for (var i = 0; i < inventory.Length; i++)
            {
                var item = inventory[i];
                if (item == null)
                {
                    continue;
                }

                if (item.modItem == null)
                {
                    continue;
                }

                if (item.type != ballTypeInt)
                {
                    continue;
                }

                if (item.modItem is DragonBallItem)
                {
                    var dBall = item.modItem as DragonBallItem;
                    if (dBall.WorldDragonBallKey == dbKey)
                    {
                        inventory[i].TurnToAir();
                        return(i);
                    }
                }
            }

            // dragonball wasn't found, return an oob index.
            return(-1);
        }