Thread: [KT] Drop Tables 3 DSL

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1 [kt\any] new -- drop table 4 dsl 
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    feedback is welcome and appreciated
    if you use this in your project or server, attribution please :)

    This post was originally created to show off my old crappy drop table dsl, but has now evolved to be much more flexible and powerful tahn I could have imagined.. If you want to check out older versions of DropTable, there is a link at the bottom of this post to the repository.

    heyo. while working on NBX, I came across some more ugly disgusting code related to generating an item based on rarity. superman to the rescue, because i know this plagues other servers as well.
    as usual, heres something ive created to further streamline development for myself that i know other aspiring developers (the good ones probably beat the shit out of me with their code lol) could find useful. this is very similar to my last snippet-type post of the same nature: drop table creator. I have improved greatly upon that older model, which (for some god forsaken reason, what was I thinking?) required you to put in the TOTAL slots AND the weights as well as assigning IDs to each bracket and putting those in an array. DropTable DSL uses much less brainpower to write and is much more powerful in terms of flexibility

    Benefits of using DropTable over commonly used drop rate-ish systems
    • Intuitive
      • It just makes sense to use. Once you understand what a producer is and how it works, it is a breeze to get going.
    • Flexibility
      • Put your own producers wherever you like! The ones contained are just sample implementations ��
    • Customizability
      • Make the most simple or the most complex producer you want. You can leave it be or stick it in a table or... whatever you want to do with it! The possibilities are hard to count!
    • Code completion
      • No more text editing for drop table editors!


    Spoiler for recent updates:

    Spoiler for update 21/06/18:

    2021/06/18

    DropTable 4.0

    There is NO 3 to 4 changelist as DropTable has been re-written from the ground up! However, here's a list of features 
    • Separated in to 2 modules, one being the more generic ProducerUtil (of which is a dependency to the latter), and DropTable which is an elaborate Producer wrapper.
      • ProducerUtil essentially boils down to a single function, Producer<T>.produce(Arguments) -> T with some helpers to help you along the way in your journey.
    • No more named parameters and parameter clutter, I am now welcoming ArgumentKey<T> and Arguments in to the fold.
      • This means you can just... call the damn producer! While making sure you are setting the target, of course...
      • Modify arguments as they pass through the pipes
      • Check out your arguments when onSelect is called
    • Lighter weight! DropTable used to come with the full RandomUtil with it but now it only comes with what it needs (the random tables) and a few useful helpers (Like the random integral ranges and progressions)
    • Much much more flexible and powerful than DropTable 3 ever could even dream about approaching the level of.
    • Make whatever you want in to a Producer simply by calling .toProducer()
    • NO WRAPPERS REQUIRED, JUST SHAKE AND BAKE BABY!!
    • A brand new type of table: MultiRollTable
      • Every producer you put in has whatever chance you get it to be picked no matter what else is rolled on
      • You can have anywhere from 0 to size drops depending on how lucky you are!
      • This is generally a good spot to put exclusive tables, it's useful for stuff like dropping bones and a drop and maybe even something else all within 1 thing


    very quick and insufficient but FUNKY demonstration


    Spoiler for Exclusive Table Sample:

    Attached image


    Spoiler for Multi Roll Sample:

    Attached image


    Spoiler for How to call (including argument usage):

    Attached image






    Bitbucket DT4: https://bitbucket.org/Nbness2/droptable/src/master/
    Bitbucket DT Jars: https://bitbucket.org/Nbness2/droptable/downloads/
    Last edited by nbness2; 06-19-2021 at 02:31 AM. Reason: DT4
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  2. #2  
    pride, love, happiness
    .alycia's Avatar
    Join Date
    Jun 2010
    Age
    28
    Posts
    4,106
    Thanks given
    1,714
    Thanks received
    2,062
    Rep Power
    5000
    This looks awesome, thanks for your contribution
    Reply With Quote  
     

  3. #3  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    update:
    • rewrote the base kotlin library to be more proper in terms of abstraction and reflection, also more intuitive and safe
    • separated the classes from eachother
    • wrote a separate tests class
    • also rewrote in java for you stubborn people, and python.


    new kotlin: https://gist.github.com/nbness2/2a9d...4df5f8e035a140
    new java: https://gist.github.com/nbness2/6178...c97cae9620cfc6
    new python: https://gist.github.com/nbness2/c064...dc35e082ad1ea4
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  4. #4  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    fixed a bug that was causing unintended interactions with WeightedTable and a modifier amount
    the bug: modifier did not properly apply to WeightedTable pick calls (anything that wasnt a multiple of 100) because i kept it as an int, therefore it did integer division and would truncate (round down to the nearest whole basically) and only work with multiples of 100 (because was dividing with 100)
    the fix: converted modifier to double when calculating the new modified weight, this avoids integer division truncation and much much much more accurately reflects what should be going on.

    the below pictures are not 100% accurate, just gives you an idea of what was happening
    old bugged example, it would look like a staircase (the steps are where multiplier equals multiples of 100) which is NOT how it was supposed to happen.

    Spoiler for before and after fix:

    Attached image


    new fixed example, it now looks like it should, a radical half pipe.
    Attached image



    Added ItemPair object. You initialize ItemPair and calling ItemPair.newItem will generate a new item from the initialized data. This makes creating items really easy and absolutely unnecessary when picking from a table (and other places if you decide to implement it elsewhere ).
    You can now define an array of item ids to an amount (or range of amounts )rather than separately defining each item id and amount
    You can now define a range of item ids (including a step if wanted) to an amount (or range of amounts) rather than separately defining each item id and amount
    These don't change the chances of an item being picked, they just help you better maintain your drop tables.

    Spoiler for new feature examples:

    ItemPair Example
    Attached image

    New ItemPair declarations
    Attached image

    DropTable gist (includes an example drop table)
    https://gist.github.com/nbness2/5cf8...078e932ced380b
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  5. #5  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    download link to update: http://www.mediafire.com/file/r6h2ywh62a6roe3/src.rar
    download link cause its easier than gists tbh what was i thinking

    Update to kotlin drop tables for some upcoming content I have been slow to work on due to medical issues:
    • Separated a lot of stuff so its a bit more organized
    • You can now call on weightedTable with custom weights using weightedTable.pick(customWeights=intArrayOf( .. ))
      • Same requirements to custom weights as the initial weights. Each weight must be unique (because it will always pick one of the items with the same weight otherwise, and never the other one), and each weight must be over 0.
      • custom weights are assumed to be sorted assuming they meet the requirements, as there is nothing to sort them against unlike the initialization of the weightedTable where both items and weights are given.
      • The hash of each custom weight used on the table are saved for future usage.
      • If the custom weights DO meet the requirements, a RandomRange is saved in the map storing the already verified weights, otherwise a WeightStatus is.
      • This results in a net performance gain (unless every single time a custom weight array is given its unique) and decreased gc pressure (because the randomranges are stored and dont have to be instantiated every time the non-unique weights table is given) at the cost of increased constant memory usage (stores the weight tables hashcodes as well as the randomrange\status)
    • Brackets will automatically consolidate all ItemPairs with the same AmountRanges in to the same ItemPair.
      • RandomRange now has hashcode as a side effect
      • https://i.imgur.com/HnoAzee.png
      • I did this to keep the development process visually streamlined without impairing runtime performance while also decreasing overall memory usage
    • Changed ItemPair properties to make a bit more sense
    • added some demo tables
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  6. #6  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Update - 2018/12/09
    General changes:
    • Fixed ItemGenerator consolidation bug
      • bug was with RandomRange and for some reason the hashCode not working, so...
      • changed RandomRange to be a data class, now functionally identical RandomRanges are actually identical and will be treated as such.
    • Better organization
    • ItemPair has been renamed to ItemGenerator
    • Added RandomUtil.BaseRandom and all children (found in my sig) to this project.
      • DropTable now inherits from MemoWeightedTable
    • Added NumberUtil.toByteArray and NumberUtil.fromByteArray (found in my sig) to this project.

    Serialization and Deserialization added to:
    • ItemGenerator
    • Bracket
    • DropTable


    DSL has been added to:
    • ItemGenerator
    • Bracket
    • DropTable

    The DSL Grammar has been made to be very easy for people who can read and write english.
    Using the DSL may require more LOC in most cases, but doesnt require as much thinking to convey your ideas and change the tables. Time efficiency while writing comprehensive and understandable code!
    Mor Ul Rek gem stall has been changed a little to use available DSL constructs and has 2 more demo tables to show usage of using full DSL and hybrid DSL. They all compile and serialize to the same thing.
    Anecdotal: My brother who hasnt programmed using anything but scratch was able to write a drop table in DSL in around 10 minutes once he had all the data entry (names ids and amounts) known. That's about 20 minutes quicker than using the non-DSL syntax. Of course this margin would be lower for people used to programming, but its still much easier to understand and write. That is my goal with this, create robust but easy to understand and create drop tables, and the addition of the DSL is a big step towards understanding and creating them more efficiently.

    The following examples contain different examples of how you can utilize the DSL to meet your needs.
    Spoiler for DSL examples:

    Full DSL Mor Ul Rek Gem Stall
    Attached image

    Semi-DSL Mor Ul Rek Gem Stall
    Attached image

    No-DSL Mor Ul Rek Gem Stall
    Attached image
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  7. #7  
    Registered Member deji's Avatar
    Join Date
    Dec 2018
    Posts
    75
    Thanks given
    4
    Thanks received
    21
    Rep Power
    66
    Python one looks so good. Well done fascinates me.
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    Update 2018/12/12

    not much today, folks
    • Added sneaky get overload in ItemGenerator to make it seem like you are using implicit receiver infix with a collection literal to add ids and set amounts
      • You can use as many ints as you want when setting ids, or you can use an IntProgression
      • You can only use 2 ints when setting amounts.
      • The old syntax is still compatible with this change
    • Added a README to the main git page to more gently introduce someone to the idea of using the DSL and what the different parts of the DSL do.
    • Renamed some "newItem" and "pick" to "createItem" to make it more consistent throughout.


    Spoiler for new syntax:

    old
    Code:
    ItemGenerator {
        with ids intArrayOf(2, 4, 6, 7, 10)
        with ids 25 step 4 to 100
        with amounts 2 to 10
    }
    new
    Code:
    ItemGenerator {
        withIds [2, 4, 6, 7, 10]
        withIds [25 .. 100 step 4]
        withAmounts [2, 10]
    }
    Looks a bit nicer IMO, but then again thats because I came from languages that have collection literals, which kotlin still doesn't have any of


    Quote Originally Posted by deji View Post
    Python one looks so good. Well done fascinates me.
    Hey, thanks man! I try to write as good as I can
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  10. #9  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    2018/12/14

    Not much today either
    • Fixed MemoWeightedTable bug
      • Was using .hashCode() instead of .contentHashCode() for weights, and that would produce different hashcodes for identical weight arrays.
    • Added .dslString() for DropTable, Bracket and ItemGenerator
      • This was made because I wanted to convert my NBX tables from old syntax to DSL syntax
      • Easy and proper conversion for you guys.
      • Preserves IntProgressions if they are the only thing in the idList.
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

  11. #10  
    Extreme Donator

    nbness2's Avatar
    Join Date
    Aug 2011
    Posts
    692
    Thanks given
    274
    Thanks received
    139
    Rep Power
    430
    I am slowly rewriting this in to DropTable3 DSL. I'll make up what version I'm on next update The plan is for DT2 tables to be compatible all the way until the last DT2 release. DT2 tables will not be fully compatible with DT3. I am slowly adding DT3 features to DT2 until DT3 release.
    With the updates leading to DT3 release, I am going to be slowly abstracting stuff, as people I work with get a hard on for that, and I think it's good practise.

    Updates
    • BaseRandom now implements Create<T>
      • Create<T> implementors must define pickItem(modifier: Int): T. That's it.
    • Reorganization
      • Components (Item, ItemGenerator, Bracket and DropTable) are now in their own folder.
      • Builders are now in util.Builders rather than their respective component's file.
    • [!!!] Bracket.onAnnounce: EXAMPLE
      • You can now add a function to Bracket that will execute every time Bracket.pickItemWithWeights(Int) is called and Bracket.announceDrop is true.
      • onAnnounce can be given in Bracket constructors or inside Bracket builder using "onAnnounce { item, bracketName, tableName -> code }"
      • It takes arguments (item: Item, bracketName: String, tableName: String). This should be all the information you need from the table for whatever you plan to do with it.
      • onAnnounce can do anything you want, no more needing big switch statements that hardly relate to the code it's in. Define it all in the Bracket, or a general lambda that takes (Item, String, String) and use those!!
      • onAnnounce is not required (default function does nothing).


    papa nbness says: remember to name your code meaningfully! with sufficient enough naming, you don't need to write nearly as much documentation if any, as the code documents itself! smaller variable names do not make your program run faster, and neither does putting multiple lines of code on the same line using semicolons! it's all the same when you compile!
    KT/JAVA - NBX 637 - HERE!
    KT - Drop table 4: Flexible, Powerful - HERE!
    KT - Command: Simplify writing commands - HERE
    KT - NbUtil: Make your kotlin easier - HERE
    KT - Hopping Islands: From Java to Kotlin - P1 - P2 - P3 - P4 - P5
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [KT] Drop Tables 3 DSL
    By nbness2 in forum Snippets
    Replies: 17
    Last Post: 06-22-2021, 01:49 AM
  2. Replies: 23
    Last Post: 01-17-2014, 05:30 AM
  3. [PI] Underingstanding The Rare Drop Table
    By Merrow in forum Snippets
    Replies: 4
    Last Post: 04-06-2013, 04:59 AM
  4. perfect tormented demon drop table
    By Teemuzz in forum Configuration
    Replies: 21
    Last Post: 03-30-2010, 05:17 PM
  5. Drop Tables.
    By Bando in forum RS2 Server
    Replies: 21
    Last Post: 02-13-2010, 10:12 PM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •