/**
	 * When mouse is not over yet
	 */
	function onMouseOut()
	{
		if (!Camera.action.active) {
			Cursor.setType( Cursor.ACTION.DEFAULT );
		}
		else {
			Cursor.setType( Cursor.ACTION.ROTATE );
		}

		if (this !== this.constructor.Manager.getFocusEntity()) {
			this.display.display = false;
			this.display.remove();
		}
	}
Exemple #2
0
	MapRenderer.setMap = function loadMap( mapname )
	{
		// TODO: stop the map loading, and start to load the new map.
		if (this.loading) {
			return;
		}

		// Support for instance map
		// Is it always 3 digits ?
		mapname = mapname
			.replace(/^(\d{3})(\d@)/, '$2') // 0061@tower   -> 1@tower
			.replace(/^\d{3}#/, '');        // 003#prontera -> prontera

		// Clean objects
		SoundManager.stop();
		Renderer.stop();
		UIManager.removeComponents();
		Cursor.setType(Cursor.ACTION.DEFAULT);

		// Don't reload a map when it's just a local teleportation
		if (this.currentMap !== mapname) {
			this.loading = true;
			BGM.stop();
			this.currentMap = mapname;

			// Parse the filename (ugly RO)
			var filename = mapname.replace(/\.gat$/i, '.rsw');

			Background.setLoading(function() {
				// Hooking Thread
				Thread.hook('MAP_PROGRESS', onProgressUpdate.bind(MapRenderer) );
				Thread.hook('MAP_WORLD',    onWorldComplete.bind(MapRenderer) );
				Thread.hook('MAP_GROUND',   onGroundComplete.bind(MapRenderer) );
				Thread.hook('MAP_ALTITUDE', onAltitudeComplete.bind(MapRenderer) );
				Thread.hook('MAP_MODELS',   onModelsComplete.bind(MapRenderer) );

				// Start Loading
				MapRenderer.free();
				Renderer.remove();
				Thread.send('LOAD_MAP', filename, onMapComplete.bind(MapRenderer) );
			});

			return;
		}

		var gl = Renderer.getContext();
		EntityManager.free();
		Damage.free( gl );
		EffectManager.free( gl );

		// Basic TP
		Background.remove(function(){
			MapRenderer.onLoad();
			Sky.setUpCloudData();

			Renderer.render( MapRenderer.onRender );
		});
	};
	/**
	 * When clicking on an Entity
	 *
	 */
	function onMouseDown()
	{
		var Entity = this.constructor;
		var pkt;

		switch (this.objecttype) {
			case Entity.TYPE_PET:
				break;

			case Entity.TYPE_ITEM:
				Cursor.setType( Cursor.ACTION.PICK, true, 2 );

				pkt       = new PACKET.CZ.ITEM_PICKUP();
				pkt.ITAID = this.GID;

				// Too far, walking to it
				if (vec2.distance(Session.Entity.position, this.position) > 2) {
					Session.moveAction = pkt;

					pkt         = new PACKET.CZ.REQUEST_MOVE();
					pkt.dest[0] = Mouse.world.x;
					pkt.dest[1] = Mouse.world.y;
					Network.sendPacket(pkt);

					return true;
				}

				Network.sendPacket(pkt);
				Session.Entity.lookTo( this.position[0], this.position[1] );
				return true;

			case Entity.TYPE_NPC:
				pkt      = new PACKET.CZ.CONTACTNPC();
				pkt.NAID = this.GID;
				pkt.type = 0; // TODO: what is it for ?
				Network.sendPacket(pkt);

				// Updare look
				Session.Entity.lookTo( this.position[0], this.position[1] );
				pkt = new PACKET.CZ.CHANGE_DIRECTION();
				pkt.headDir = Session.Entity.headDir;
				pkt.dir     = Session.Entity.direction;
				Network.sendPacket(pkt);
				return true;

			case Entity.TYPE_WARP:
				pkt         = new PACKET.CZ.REQUEST_MOVE();
				pkt.dest[0] = this.position[0];
				pkt.dest[1] = this.position[1];
				Network.sendPacket(pkt);
				break;
		}

		return false;
	}
Exemple #4
0
	/**
	 * What to do when clicking on the map ?
	 */
	function onMouseDown( event )
	{
		var action = event && event.which || 1;

		Session.moveAction = null;

		if (!Mouse.intersect) {
			return;
		}

		switch (action) {

			// Left click
			case 1:
				var entityFocus = EntityManager.getFocusEntity();
				var entityOver  = EntityManager.getOverEntity();
				var stop        = false;

				if (entityFocus && entityFocus != entityOver) {
					entityFocus.onFocusEnd();
					EntityManager.setFocusEntity(null);
				}

				// Entity picking ?
				if (entityOver) {
					stop = stop || entityOver.onMouseDown();
					stop = stop || entityOver.onFocus();
					EntityManager.setFocusEntity(entityOver);

					// Know if propagate to map mousedown
					if (stop) {
						return;
					}
				}

				// Start walking
				if (this.onRequestWalk) {
					this.onRequestWalk();
				}
				break;

			// Right Click
			case 3:
				_rightClickPosition[0] = Mouse.screen.x;
				_rightClickPosition[1] = Mouse.screen.y;

				Cursor.setType( Cursor.ACTION.ROTATE );
				Camera.rotate( true );
				break;
		}
	}
Exemple #5
0
	/**
	 * What to do when stop clicking on the map ?
	 */
	function onMouseUp( event )
	{
		var entity;
		var action = event && event.which || 1;

		// Not rendering yet
		if (!Mouse.intersect) {
			return;
		}

		switch (action) {

			// Left click
			case 1:
				// Remove entity picking ?
				entity = EntityManager.getFocusEntity();

				if (entity) {
					entity.onMouseUp();

					// Entity lock is only on MOB type
					if (Preferences.noctrl === false || entity.objecttype !== entity.constructor.TYPE_MOB) {
						EntityManager.setFocusEntity(null);
						entity.onFocusEnd();
					}
				}

				// stop walking
				if (this.onRequestStopWalk) {
					this.onRequestStopWalk();
				}
				break;

			// Right Click
			case 3:
				Cursor.setType( Cursor.ACTION.DEFAULT );
				Camera.rotate( false );

				// Seems like it's how the official client handle the contextmenu
				// Just check for the same position on mousedown and mouseup
				if (_rightClickPosition[0] === Mouse.screen.x && _rightClickPosition[1] === Mouse.screen.y) {
					entity = EntityManager.getOverEntity();

					if (entity && entity !== Session.Entity) {
						entity.onContextMenu();
					}
				}
				break;
		}
	}
	SkillTargetSelection.onRemove = function onRemove()
	{
		jQuery(window).off('mousedown.targetselection');

		Cursor.blockMagnetism = false;
		Cursor.freeze         = false;
		Cursor.setType(Cursor.ACTION.DEFAULT);

		if (_skillName.parentNode) {
			document.body.removeChild(_skillName);
		}

		if (_description.parentNode) {
			document.body.removeChild(_description);
		}
	};
	SkillTargetSelection.set = function set( skill, target, description )
	{
		_target = target;
		_skill  = skill;

		if (!_target) {
			return;
		}

		if (_target & (SkillTargetSelection.TYPE.PLACE|SkillTargetSelection.TYPE.TRAP)) {
			Cursor.blockMagnetism = true;
		}

		// Render skillName
		var sk = SkillInfo[ skill.SKID ];
		render(description || sk.SkillName, _skillName);

		Cursor.setType( Cursor.ACTION.TARGET);
		Cursor.freeze = true;
	};
	/*
	 * When mouse is over
	 */
	function onMouseOver()
	{
		var Entity = this.constructor;

		switch (this.objecttype) {
			case Entity.TYPE_PET:
				if (!Camera.action.active) {
					Cursor.setType( Cursor.ACTION.DEFAULT );
				}
				break;

			case Entity.TYPE_PC:
			case Entity.TYPE_ELEM:
			case Entity.TYPE_HOM:
				// TODO: Check for pvp flag ?
				if ((KEYS.SHIFT === false && Preferences.noshift === false) || this === Session.Entity)  {
					if (!Camera.action.active ) {
						Cursor.setType( Cursor.ACTION.DEFAULT );
					}
					break;
				}

				Cursor.setType( Cursor.ACTION.ATTACK );
				break;

			case Entity.TYPE_MOB:
				Cursor.setType( Cursor.ACTION.ATTACK );
				break;

			case Entity.TYPE_NPC:
				Cursor.setType( Cursor.ACTION.TALK, true );
				break;

			case Entity.TYPE_WARP:
				Cursor.setType( Cursor.ACTION.WARP );
				return;

			case Entity.TYPE_ITEM:
				Cursor.setType( Cursor.ACTION.PICK, true, 0 );
				break;
		}


		switch (this.display.load) {

			// Ask for the name
			case this.display.TYPE.NONE:
				this.display.load = this.display.TYPE.LOADING;

				var pkt = new PACKET.CZ.REQNAME();
				pkt.AID = this.GID;
				Network.sendPacket(pkt);
				break;

			// Nothing yet
			case this.display.TYPE.LOADING:
				break;

			// Display the name
			case this.display.TYPE.COMPLETE:
				mat4.multiply( _matrix, Camera.projection, this.matrix );
				this.display.render(_matrix);
				this.display.add();
				break;
		}
	}
	/**
	 * Focus the entity
	 */
	function onFocus()
	{
		var Entity = this.constructor;
		var main   = Session.Entity;
		var pkt;

		switch (this.objecttype) {

			case Entity.TYPE_PC:
			case Entity.TYPE_ELEM:
			case Entity.TYPE_HOM:
				// TODO: add check for PVP/WOE mapflag
				if (KEYS.SHIFT === false && Preferences.noshift === false)  {
					if (!Camera.action.active) {
						Cursor.setType( Cursor.ACTION.DEFAULT );
					}
					break;
				}
			// no break intended.

			case Entity.TYPE_MOB:

				// Start rendering the lock on arrow
				this.attachments.add({
					uid:    'lockon',
					spr:    'data/sprite/cursors.spr',
					act:    'data/sprite/cursors.act',
					frame:   Cursor.ACTION.LOCK,
					repeat:  true,
					depth:   10.0,
				});

				var out   = [];
				var count = PathFinding.search(
					main.position[0] | 0, main.position[1] | 0,
					this.position[0] | 0, this.position[1] | 0,
					main.attack_range + 1,
					out
				);

				// Can't attack
				if (!count) {
					return true;
				}

				pkt           = new PACKET.CZ.REQUEST_ACT();
				pkt.action    = 7;
				pkt.targetGID = this.GID;

				// in range send packet
				if (count < 2) {
					Network.sendPacket(pkt);
					return true;
				}

				// Move to entity
				Session.moveAction = pkt;

				pkt         = new PACKET.CZ.REQUEST_MOVE();
				pkt.dest[0] = out[(count-1)*2 + 0];
				pkt.dest[1] = out[(count-1)*2 + 1];
				Network.sendPacket(pkt);
				return true;
		}

		return false;
	}