Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Introduce pet capture system

Still missing Pet Informations UI and control (feed, action, ...)
  • Loading branch information...
vthibault committed Mar 30, 2014
1 parent c028d98 commit 33350658f8a2fb93ac63e052f01aa07e746b3667
@@ -125,6 +125,7 @@ define(function( require )
require('./MapEngine/Guild').call();
require('./MapEngine/Skill').call();
require('./MapEngine/ChatRoom').call();
require('./MapEngine/Pet').call();
}


@@ -0,0 +1,86 @@
/**
* Engine/MapEngine/Pet.js
*
* Manage Pets
*
* This file is part of ROBrowser, Ragnarok Online in the Web Browser (http://www.robrowser.com/).
*
* @author Vincent Thibault
*/

define(function( require )
{
'use strict';


/**
* Load dependencies
*/
var Network = require('Network/NetworkManager');
var PACKET = require('Network/PacketStructure');
var Renderer = require('Renderer/Renderer');
var SlotMachine = require('UI/Components/SlotMachine/SlotMachine');
var SkillTargetSelection = require('UI/Components/SkillTargetSelection/SkillTargetSelection');
var ItemSelection = require('UI/Components/ItemSelection/ItemSelection');


/**
* Server ask to select a monster
*
* @param {object} pkt - PACKET.ZC.START_CAPTURE
*/
function onStartCapture( pkt )
{
var fakeSkill = { SKID:-10, level:0 };

SkillTargetSelection.append();
SkillTargetSelection.set( fakeSkill, SkillTargetSelection.TYPE.PET, 'Capture Monster');
SkillTargetSelection.onPetSelected = function onPetSelected(gid){
SlotMachine.append();
SlotMachine.onTry = function onTry(){
var pkt = new PACKET.CZ.TRYCAPTURE_MONSTER();
pkt.targetAID = gid;
Network.sendPacket(pkt);
};
};
}


/**
* Received capture result from server
*
* @param {object} pkt - PACKET.ZC.TRYCAPTURE_MONSTER
*/
function onCaptureResult( pkt )
{
SlotMachine.setResult( pkt.result );
}


/**
* Get pet list from server
*
* @param {object} pkt - PACKET.ZC.PETEGG_LIST
*/
function onPetList( pkt )
{
ItemSelection.append();
ItemSelection.setList(pkt.eggList);
ItemSelection.onIndexSelected = function(index) {
var pkt = new PACKET.CZ.SELECT_PETEGG();
pkt.index = index;
Network.sendPacket(pkt);
};
}


/**
* Initialize
*/
return function NPCEngine()
{
Network.hookPacket( PACKET.ZC.START_CAPTURE, onStartCapture);
Network.hookPacket( PACKET.ZC.TRYCAPTURE_MONSTER, onCaptureResult);
Network.hookPacket( PACKET.ZC.PETEGG_LIST, onPetList);
};
});
@@ -213,12 +213,12 @@ define( ['./PacketStructure' ], function( PACKET )
0x199: PACKET.ZC.NOTIFY_MAPPROPERTY,
0x19a: PACKET.ZC.NOTIFY_RANKING,
0x19b: PACKET.ZC.NOTIFY_EFFECT,
0x19e: PACKET.ZC.START_CAPTURE,
0x1a0: PACKET.ZC.TRYCAPTURE_MONSTER,
0x19e: PACKET.ZC.START_CAPTURE, // ok
0x1a0: PACKET.ZC.TRYCAPTURE_MONSTER, // ok
0x1a2: PACKET.ZC.PROPERTY_PET,
0x1a3: PACKET.ZC.FEED_PET,
0x1a4: PACKET.ZC.CHANGESTATE_PET,
0x1a6: PACKET.ZC.PETEGG_LIST,
0x1a6: PACKET.ZC.PETEGG_LIST, // ok
0x1aa: PACKET.ZC.PET_ACT,
0x1ab: PACKET.ZC.PAR_CHANGE_USER,
0x1ac: PACKET.ZC.SKILL_UPDATE,
@@ -162,10 +162,6 @@ define( function( require )
for (i = 0; i < count; ++i) {
switch (keys[i]) {

// Set it manually
case 'objecttype':
break;

// Already set
case 'sex':
case 'job':
@@ -122,6 +122,7 @@ define(['Renderer/Renderer', 'DB/DBManager'], function( Renderer, DB )
break;

// Mob action
case Entity.TYPE_PET:
case Entity.TYPE_MOB:
this.ACTION.IDLE = 0;
this.ACTION.WALK = 1;
@@ -156,7 +157,6 @@ define(['Renderer/Renderer', 'DB/DBManager'], function( Renderer, DB )
break;

//TODO: define others Entities ACTION
case Entity.TYPE_PET:
case Entity.TYPE_ELEM:
break;
}
@@ -143,7 +143,7 @@ define(function(require)
// Title feature
.on('mouseover', '.item', function(){
var idx = parseInt( this.className.match(/ (\d+)$/)[1], 10);
var item = getItemByIndex(idx);
var item = Inventory.getItemByIndex(idx);

if (!item) {
return;
@@ -193,7 +193,7 @@ define(function(require)

var matches = this.className.match(/(\w+) (\d+)/);
var index = parseInt(matches[2], 10);
var item = getItemByIndex(index);
var item = Inventory.getItemByIndex(index);

if (!item) {
return;
@@ -221,7 +221,7 @@ define(function(require)
.on('contextmenu', '.item', function(event) {
var matches = this.className.match(/(\w+) (\d+)/);
var index = parseInt(matches[2], 10);
var item = getItemByIndex(index);
var item = Inventory.getItemByIndex(index);

event.stopImmediatePropagation();

@@ -246,7 +246,7 @@ define(function(require)
.on('dblclick', '.item', function(event) {
var matches = this.className.match(/(\w+) (\d+)/);
var index = parseInt(matches[2], 10);
var item = getItemByIndex(index);
var item = Inventory.getItemByIndex(index);

if (item) {
Inventory.useItem(item);
@@ -471,7 +471,7 @@ define(function(require)
* @param {number} index
* @returns {Item}
*/
function getItemByIndex( index )
Inventory.getItemByIndex = function getItemByIndex( index )
{
var i, count;
var list = Inventory.list;
@@ -483,7 +483,7 @@ define(function(require)
}

return null;
}
};


/**
@@ -553,7 +553,7 @@ define(function(require)
*/
Inventory.addItem = function AddItem( item )
{
var object = getItemByIndex(item.index);
var object = this.getItemByIndex(item.index);

if (object) {
object.count += item.count;
@@ -639,7 +639,7 @@ define(function(require)
*/
Inventory.removeItem = function RemoveItem( index, count )
{
var item = getItemByIndex(index);
var item = this.getItemByIndex(index);

// Emulator failed to complete the operation
// do not remove item from inventory
@@ -678,7 +678,7 @@ define(function(require)
*/
Inventory.updateItem = function UpdateItem( index, count )
{
var item = getItemByIndex(index);
var item = this.getItemByIndex(index);

if (!item) {
return;
@@ -0,0 +1,13 @@
#ItemSelection { z-index:100; position:absolute; width:200px; }
#ItemSelection .head { position:absolute; width:180px; height:22px; top:0px; left:0px; }
#ItemSelection .bottom { position:relative; width:180px; height:120px; top:80px; left:0px; }

#ItemSelection .content { position:absolute; width:158px; top:22px; left:0px; padding-left:10px; padding-right:10px; background-color:white; border-left:1px solid #c7c7c7; border-right:1px solid #c7c7c7; }
#ItemSelection .list { background-color:#f7f7f7; height:130px; width:160px; font-size:12px; overflow-y:auto;}
#ItemSelection .list .item { display:block; height:28px; margin:4px 4px 4px 4px; position:relative; }
#ItemSelection .list .item .icon { width:24px; height:24px; border:none; background-color:transparent; background-repeat:no-repeat; }
#ItemSelection .list .item .name { font-size:12px; position:absolute; top:7px; left:30px; width:90px; }

#ItemSelection .btn { position:absolute; bottom:0px; border:0; width:42px; height:20px; bottom:4px; background-color:transparent; }
#ItemSelection .ok { right: 50px; }
#ItemSelection .cancel { right: 5px; }
@@ -0,0 +1,10 @@
<div id="ItemSelection">
<div class="head" data-background="login_interface/win_service.bmp"></div>
<div class="bottom" data-background="login_interface/win_service.bmp">
<button class="btn cancel" data-background="btn_cancel.bmp" data-hover="btn_cancel_a.bmp" data-down="btn_cancel_b.bmp"></button>
<button class="btn ok" data-background="btn_ok.bmp" data-hover="btn_ok_a.bmp" data-down="btn_ok_b.bmp"></button>
</div>
<div class="content">
<div class="list"></div>
</div>
</div>
Oops, something went wrong.

0 comments on commit 3335065

Please sign in to comment.
You can’t perform that action at this time.