Thread: [Apollo] Set Widget Model (Barrow Puzzle Shapes)

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1 [Apollo] Set Widget Model (Barrow Puzzle Shapes) 
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,335
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    Spoiler for Documentation:
    Code:
    Barrow Shapes
    
    Arrows:
    o< 6713
    o> 6714
    <o 6715
    vo 6716
    >o 6717
    ^o 6718
    
    
    Squares:
    o dark grey x light gray
    
    ox 6719
    xx
    
    xx 6720
    0x
    
    xx 6721
    xx
    
    oo 6722
    oo
    
    ox 6723
    oo
    
    ox 6724
    ox
    
    xx 6725
    oo
    
    xo 6726
    xo
    
    xx 6727
    oo
    --
    
    oo 6728
    xx
    
    oo 6729
    xx
    --
    
    --
    oo 6730
    xx
    
    
    Shapes:
    
    square 6731
    down pentagon 6732
    triangle 6733
    heptagon 6734
    hexagon 6735
    up pentago 6736


    Display Model Packet
    317:
    Code:
    package org.apollo.game.release.r317;
    
    import org.apollo.game.message.impl.SetWidgetModelMessage;
    import org.apollo.net.codec.game.DataOrder;
    import org.apollo.net.codec.game.DataTransformation;
    import org.apollo.net.codec.game.DataType;
    import org.apollo.net.codec.game.GamePacket;
    import org.apollo.net.codec.game.GamePacketBuilder;
    import org.apollo.net.release.MessageEncoder;
    
    /**
     * A {@link MessageEncoder} for the {@link SetWidgetModelMessage}.
     *
     * @author Shamon King
     */
    public final class SetWidgetModelMessageEncoder extends MessageEncoder<SetWidgetModelMessage> {
    
    	@Override
    	public GamePacket encode(SetWidgetModelMessage message) {
    		GamePacketBuilder builder = new GamePacketBuilder(8);
    		
    		builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId());
    		builder.put(DataType.SHORT, message.getModelId());
    
    		return builder.toGamePacket();
    	}
    
    }
    377:
    Code:
    package org.apollo.game.release.r377;
    
    import org.apollo.game.message.impl.SetWidgetModelMessage;
    import org.apollo.net.codec.game.DataOrder;
    import org.apollo.net.codec.game.DataTransformation;
    import org.apollo.net.codec.game.DataType;
    import org.apollo.net.codec.game.GamePacket;
    import org.apollo.net.codec.game.GamePacketBuilder;
    import org.apollo.net.release.MessageEncoder;
    
    /**
     * A {@link MessageEncoder} for the {@link SetWidgetModelMessage}.
     *
     * @author Shamon King
     */
    public final class SetWidgetModelMessageEncoder extends MessageEncoder<SetWidgetModelMessage> {
    
    	@Override
    	public GamePacket encode(SetWidgetModelMessage message) {
    		GamePacketBuilder builder = new GamePacketBuilder(216);
    
    		builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getModelId());
    		builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId());
    
    		return builder.toGamePacket();
    	}
    
    }

    Code:
    package org.apollo.game.message.impl;
    
    import org.apollo.net.message.Message;
    
    /**
     * A {@link Message} sent to the client to set a widget's displayed model.
     *
     * @author Shamon king
     */
    public final class SetWidgetModelMessage extends Message {
    	/**
    	 * The interface's id.
    
    	 */
    	private final int interfaceId;
    
    	/**
    	 * The model's id.
    	 */
    	private final int modelId;
    
    	/**
    	 * Creates a new set interface model message.
    	 *
    	 * @param interfaceId The interface's id.
    	 * @param modelId The model's id.
    	 */
    	public SetWidgetModelMessage(int interfaceId, int modelId) {
    		this.interfaceId = interfaceId;
    		this.modelId = modelId;
    	}
    
    	/**
    	 * Gets the interface's id.
    	 *
    	 * @return The id.
    	 */
    	public int getInterfaceId() {
    		return interfaceId;
    	}
    
    	/**
    	 * Gets the model's id.
    	 *
    	 * @return The id.
    	 */
    	public int getModelId() {
    		return modelId;
    	}
    
    }
    Register it
    Code:
    register(SetWidgetModelMessage.class, new SetWidgetModelMessageEncoder());
    Ya I know should be in ruby, but the majority of the userbase doesn't use apollo so this is more useful.

    Code:
    package org.apollo.game.model.content;
    
    public enum BarrowsPuzzle {
    	
    	ARROWS(6713, new int[] { 6716, 6717, 6718 }, new int[] { 6713, 6714, 6715 }),
    	SQUARES(6719, new int[] { 6722, 6723, 6724 }, new int[] { 6719, 6720, 6721 }),
    	SQUARES_OFFSET(6725, new int[] { 6728, 6729, 6730 }, new int[] { 6725, 6726, 6727 }),
    	SHAPES(6731, new int[] { 6734, 6735, 6736 }, new int[] { 6731, 6732, 6733 });
    
    	/**
    	 * The answer to the barrows puzzle.
    	 */
    	private final int answer;
    
    	/**
    	 * The initial puzzle sequence.
    	 */
    	private final int[] sequence;
    
    	/**
    	 * The options to finish the sequence.
    	 */
    	private final int[] options;
    	
    	/**
    	 * Creates a new barrow puzzle.
    	 * 
    	 * @param answer
    	 *            The answer to the barrows puzzle.
    	 * @param sequence
    	 *            The initial puzzle sequence.
    	 * @param options
    	 *            The options to finish the sequence.
    	 */
    	private BarrowsPuzzle(int answer, int[] sequence, int[] options) {
    		this.answer = answer;
    		this.sequence = sequence;
    		this.options = options;
    	}
    	
    	public int getAnswer() {
    		return answer;
    	}
    	
    	public int getSequenceModel(int index) {
    		return sequence[index];
    	}
    	
    	public int[] getSequence() {
    		return sequence;
    	}
    	
    	public int[] getOptions() {
    		return options;
    	}
    }
    Code:
    package org.apollo.game.model.content;
    
    import org.apollo.game.message.impl.SetWidgetModelMessage;
    import org.apollo.game.model.entity.Player;
    
    public class BarrowsPuzzleDisplay {
    	/**
    	 * Buttons.
    	 */
    	private static final int FIRST_OPTION_BUTTON = 4550;
    	private static final int SECOND_OPTION_BUTTON = 4551;
    	private static final int THIRD_OPTION_BUTTON = 4552;
    
    	/**
    	 * Main interface.
    	 */
    	private static final int BARROWS_PUZZLE_INTERFACE = 4543;
    	
    	/**
    	 * Model childs.
    	 */
    	private static final int SEQUENCE_CHILD_START = 4545;
    	private static final int OPTIONS_CHILD_START = 4550;
    
    	/**
    	 * The puzzle being displayed.
    	 */
    	private final BarrowsPuzzle puzzle;
    
    	/**
    	 * The current shuffled options.
    	 */
    	private final int[] shuffledOptions;
    
    	/**
    	 * Create a new instanfe of a puzzle.
    	 * 
    	 * @param puzzle
    	 *            The puzzle to display.
    	 */
    	public BarrowsPuzzleDisplay(BarrowsPuzzle puzzle) {
    		this.puzzle = puzzle;
    		this.shuffledOptions = Util.shuffleIntArray(puzzle.getOptions());
    	}
    
    	/**
    	 * Display the puzzle interface with random options.
    	 * 
    	 * @param player
    	 *            The instance of the player.
    	 */
    	public void displayInterface(Player player) {
    		for (int i = 0; i < 3; i++) {
    			int sequenceModel = puzzle.getSequenceModel(i);
    			player.send(new SetWidgetModelMessage(SEQUENCE_CHILD_START + i, sequenceModel));
    
    			int optionModel = shuffledOptions[i];
    			player.send(new SetWidgetModelMessage(OPTIONS_CHILD_START + i, optionModel));
    		}
    
    		player.getInterfaceSet().openWindow(BARROWS_PUZZLE_INTERFACE);
    	}
    
    	/**
    	 * @param buttonClicked
    	 *            The button clicked on puzzle interface.
    	 *            
    	 * @return true if the button clicked is the correct shape.
    	 */
    	public boolean checkCorrectAnswer(int buttonClicked) {
    		int index = buttonClicked - FIRST_OPTION_BUTTON;
    
    		int model = shuffledOptions[index];
    
    		return model == puzzle.getAnswer();
    	}
    }
    Integer shuffle method.
    Code:
    import java.util.Random;
    
    public class Util {
    
    	private static final Random random = new Random();
    
    	public static int[] shuffleIntArray(int[] array) {
    		int[] shuffledArray = new int[array.length];
    		System.arraycopy(array, 0, shuffledArray, 0, array.length);
    
    		for (int i = shuffledArray.length - 1; i > 0; i--) {
    			int index = random.nextInt(i + 1);
    			int a = shuffledArray[index];
    			shuffledArray[index] = shuffledArray[i];
    			shuffledArray[i] = a;
    		}
    
    		return shuffledArray;
    	}
    }
    Ruby implementation
    Code:
    BARROWS_PUZZELS = {}
    
    class BarrowsPuzzle
    	attr_reader :answer, :sequence, :options
    
    	def initialize(answer, sequence, options)
    		@answer = answer
    		@sequence = sequence
    		@options = options
    	end
    end
    
    def create_puzzle(name, hash)
    	unless hash.has_keys?(:answer, :sequence, :options)
    		fail 'Hash must have answer, sequence, and options keys.'
    	end
    
    	puzzle = BarrowsPuzzle.new hash[:answer], hash[:sequence], hash[:options]
    	BARROWS_PUZZELS[name] = puzzle
    end
    
    create_puzzle :arrows, answer: 6713, sequence: [6716, 6717, 6718], options: [6713, 6714, 6715]
    create_puzzle :squares, answer: 6719, sequence: [6722, 6723, 6724], options: [6719, 6720, 6721]
    create_puzzle :squares_offset, answer: 6725, sequence: [6728, 6729, 6730], options: [6725, 6726, 6727]
    create_puzzle :shapes, answer: 6731, sequence: [6734, 6735, 6736], options: [6731, 6732, 6733]
    Code:
    # Buttons
    FIRST_OPTION_BUTTON = 4550
    SECOND_OPTION_BUTTON = 4551
    THIRD_OPTION_BUTTON = 4552
    
    # Main interface.
    BARROWS_PUZZLE_INTERFACE = 4543
    	
    # Model childs.
    SEQUENCE_CHILD_START = 4545
    OPTIONS_CHILD_START = 4550
    
    require 'java'
    
    java_import 'org.apollo.game.message.impl.SetWidgetModelMessage'
    
    class BarrowsPuzzleDisplay
    
    	attr_reader :puzzle, :shuffled_options
    
    	def initialize(name)
    		@puzzle = BARROWS_PUZZELS[name]
    		@shuffled_options = puzzle.options.shuffle
    	end
    	
    	def display_interface(player)
    		(0..2).each do |n|
    			sequence_model = puzzle.sequence[n]
    			options_model = shuffled_options[n]
    			
    			player.send SetWidgetModelMessage.new SEQUENCE_CHILD_START + n, sequence_model
    			player.send SetWidgetModelMessage.new OPTIONS_CHILD_START + n, options_model
    		end
    		player.interfaceSet.openWindow(BARROWS_PUZZLE_INTERFACE)
    	end
    	
    	def check_answer(button)
    		index = button - FIRST_OPTION_BUTTON
    		shuffled_options[index] == puzzle.answer
    	end
    end
    
    on :command, :test, RIGHTS_ADMIN do |player, _command|
    	puzzle = BarrowsPuzzleDisplay.new :arrows
    	puzzle.display_interface player
    end
    
    def test(name)
    	puzzle = BarrowsPuzzleDisplay.new name
    	puts "Testing #{name}"
    	puts "#{puzzle.puzzle.answer}, #{puzzle.puzzle.sequence}, #{puzzle.shuffled_options}"
    	puts "Option 1: #{puzzle.check_answer FIRST_OPTION_BUTTON}, Option 2: #{puzzle.check_answer SECOND_OPTION_BUTTON}, Option 3: #{puzzle.check_answer THIRD_OPTION_BUTTON}"
    	puts ""
    end
    
    test(:arrows)
    test(:arrows)
    test(:shapes)
    test(:squares)
    test(:squares_offset)
    Tudah. Now someone make me an awesome minigame!



    Last edited by Shamon King; 02-09-2016 at 05:49 PM. Reason: Went a head and did all the puzzles. Enjoy.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    強い者は生き残る
    Ashpire's Avatar
    Join Date
    Mar 2012
    Age
    27
    Posts
    2,721
    Thanks given
    914
    Thanks received
    1,897
    Rep Power
    2231
    Nice
    Attached image
    Reply With Quote  
     

  4. Thankful user:


  5. #3  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    Probably first time I have seen some1 else doing this properly.. ppl always send items instead of models, iirc there was even a release where u had to add the shapes as items into the client
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  6. Thankful user:


  7. #4  
    The One And Only

    01053's Avatar
    Join Date
    Apr 2011
    Age
    28
    Posts
    2,887
    Thanks given
    417
    Thanks received
    885
    Rep Power
    856
    Good job this is neat.


    Reply With Quote  
     

  8. Thankful user:


  9. #5  
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,335
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    Quote Originally Posted by mige5 View Post
    Probably first time I have seen some1 else doing this properly.. ppl always send items instead of models, iirc there was even a release where u had to add the shapes as items into the client
    Haha ya. With the realese of invention Ive been doing barrows like crazy. It reminded me how this was still a mystery and I finally cracked it!
    Reply With Quote  
     

  10. #6  
    Renown Programmer & Respected Member

    Ryley's Avatar
    Join Date
    Aug 2011
    Posts
    596
    Thanks given
    254
    Thanks received
    521
    Rep Power
    1332
    Think you could find the same frame for 377 and maybe even submit a pull request with your changes? After combat and the rest of the little issues are resolved this may be something I would be down to write.
    Reply With Quote  
     

  11. Thankful user:


  12. #7  
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,335
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    Quote Originally Posted by Ryley View Post
    Think you could find the same frame for 377 and maybe even submit a pull request with your changes? After combat and the rest of the little issues are resolved this may be something I would be down to write.
    Sure, I'll download a 377 later tonight I'm about to go to class. I just updated the thread with the all the puzzles. I'm not too good at ruby anymore so I just wrote it in java.

    If you want to find it yourself in the mean time in RSInterface theres a method similar to this where MEDIA_TYPE_MODEL is equal to 1.

    Code:
    	private Model getModelForMediaType(int type, int modelId) {
    		Model model = (Model) modelNodes.insertFromCache((type << 16) + modelId);
    
    		if (model != null) {
    			return model;
    		}
    
    		if (type == MEDIA_TYPE_MODEL) {
    			model = Model.getModel(modelId);
    		}
    		if (type == MEDIA_TYPE_NPC) {
    			model = NpcDef.forID(modelId).method160();
    		}
    		if (type == MEDIA_TYPE_PLAYER) {
    			model = Client.myPlayer.method453();
    		}
    		if (type == MEDIA_TYPE_ITEM) {
    			model = ItemDef.forID(modelId).getInventoryModel(50);
    		}
    		if (type == MEDIA_TYPE_RESET) {
    			model = null;
    		}
    		if (model != null) {
    			modelNodes.removeFromCache(model, (type << 16) + modelId);
    		}
    		return model;
    	}
    The packet in 317 is
    Code:
    if (pktType == 8) {
    				int id = inStream.getUnsignedLEShortA();
    				int model = inStream.getUnsignedShort();
    				
    				Widget.interfaceCache[id].defaultMediaType = Widget.MEDIA_TYPE_MODEL;
    				Widget.interfaceCache[id].defaultMedia = model;
    				pktType = -1;
    				return true;
    			}
    You'd be looking for a packet that contains.
    Code:
    Widget.interfaceCache[id].defaultMediaType = 1;
    Reply With Quote  
     

  13. #8  


    Major's Avatar
    Join Date
    Jan 2011
    Posts
    2,997
    Thanks given
    1,293
    Thanks received
    3,556
    Rep Power
    5000
    This should definitely be in ruby

    Never seen this in an RSPS before tho so great job hunting this stuff down
    Reply With Quote  
     

  14. #9  
    Community Veteran

    mige5's Avatar
    Join Date
    Aug 2008
    Posts
    5,528
    Thanks given
    573
    Thanks received
    1,410
    Rep Power
    2114
    Quote Originally Posted by Major View Post
    Never seen this in an RSPS before tho
    http://www.rune-server.org/runescape...l-barrows.html
    Number of page #1 releases with most views & posts: (Updated: 2023)
    RS2 server section: 1
    RS2 client section: 2
    Reply With Quote  
     

  15. Thankful user:


  16. #10  
    Registered Member Emre's Avatar
    Join Date
    Jan 2014
    Posts
    596
    Thanks given
    91
    Thanks received
    61
    Rep Power
    7
    Looks really good
    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. Barrows puzzle shapes
    By huch in forum Help
    Replies: 5
    Last Post: 11-21-2014, 08:04 PM
  2. Barrows Puzzle Shapes
    By ProgrammerPF in forum Help
    Replies: 0
    Last Post: 07-18-2013, 04:09 PM
  3. Barrows Minigame
    By n33bscape in forum Tutorials
    Replies: 5
    Last Post: 06-07-2007, 01:31 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •