var Choco = ( Choco ) ? Choco : { NO_ICON_IMG:'/images/choco/items/dummy.gif', SEX_N: 0, SEX_M: 1, SEX_W: 2, FACE_N: 15, HAIR_N: 18, COLOR_N: 10, ZOK_NONE: 0, ZOK_FIRE: 1, ZOK_WATER: 2, ZOK_DARK: 3, ZOK_LIGHT: 4, ZOK_WOOD: 5, ST: { POW: 'POW', INT: 'INT', SPD: 'SPD', VIT: 'VIT', LUK: 'LUK', HP: 'HP', SP: 'SP'
}, IT: { CONSUME: 'i', OTHER: 'o', ARMS: 'arms', SHIELD: 'shield', HEAD: 'head', BACK: 'back', HAND: 'hand', NECK: 'neck', CLOTHES: 'clothes', BOOTS: 'boots'
}, ITEM: { CONSUME: 'i', OTHER: 'o'
}, EQ: { ARMS: 'arms', SHIELD: 'shield', HEAD: 'head', BACK: 'back', HAND: 'hand', NECK: 'neck', CLOTHES: 'clothes', BOOTS: 'boots'
}, ATACK: { NORMAL: 0, CRITICAL: 1, KIAI: 11, CHOU: 12, SHIN: 13, BUNDOLU: 14, GOUDATSU: 15, MIDARENDA: 16, MIDAREPPA: 17, WI1_TARGET: 18, WI1_AROUND: 19, WI2_TARGET: 23, WI2_AROUND: 24, MA1: 21, MA2: 22, ENM_CRITICAL: 98, ENM_NORMAL: 99
}, ODDS: { 0: 1, 1: 1.75, 11: 4, 12: 7, 13: 7, 14: 1.5, 15: 1.8, 16: 0.4, 17: 0.35, 18: 1.4, 19: 0.7, 23: 2, 24: 1, 21: 28, 22: 60, 98: 1.5 * 1.75, 99: 1.5
}, MIDARENDA_ODDS: [ 1, 2, 3, 4, 7 ], MIDAREPPA_ODDS: [ 1, 1.4, 2, 3, 3.4, 4, 4.6, 5, 6, 12 ], MAX_LV: 99, MAX_AP: 1500, MAX_INT: 170, cashes:{}, createItem:function( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, lv, sex, atk, def, pow, int, spd, vit, luk, hp, sp, vimg1, vimg2, voption, eq_sets, drops, mats, mat_of, q_fee_of, q_item_of, events ) { if ( type == 'i' || type == 'o' ) { return new Choco.Item( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, drops, mats, mat_of, q_fee_of, q_item_of, events );} else { return new Choco.Equip( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, lv, sex, atk, def, pow, int, spd, vit, luk, hp, sp, vimg1, vimg2, voption, eq_sets, drops, mats, mat_of, q_fee_of, q_item_of, events );}
}, getItemsByType:function( type ) { return Choco.cashes.itemsByType ? Choco.cashes.itemsByType[ type ] : Choco._getItemsByType( type );}, _getItemsByType:function( type ) { if ( !Choco.items ) { return undefined;}
Choco.cashes.itemsByType = {}; Choco.cashes.itemsByType[ Choco.IT.CONSUME ] = []; Choco.cashes.itemsByType[ Choco.IT.OTHER ] = []; Choco.cashes.itemsByType[ Choco.IT.ARMS ] = []; Choco.cashes.itemsByType[ Choco.IT.SHIELD ] = []; Choco.cashes.itemsByType[ Choco.IT.HEAD ] = []; Choco.cashes.itemsByType[ Choco.IT.BACK ] = []; Choco.cashes.itemsByType[ Choco.IT.HAND ] = []; Choco.cashes.itemsByType[ Choco.IT.NECK ] = []; Choco.cashes.itemsByType[ Choco.IT.CLOTHES ] = []; Choco.cashes.itemsByType[ Choco.IT.BOOTS ] = []; for ( var i in Choco.items ) { var item = Choco.items[i]; if ( item ) { var itype = item.getType(); if ( Choco.cashes.itemsByType[ itype ] ) { Choco.cashes.itemsByType[ itype ].push( item );}
}
}
return Choco.cashes.itemsByType[ type ];}
}; Choco._Base = function() {}
MJ.extend( Choco._Base, { init:function( id, name, kana, note ) { this.id = id; this.name = name; this.kana = kana; this.note = note; this._caches = {};}, getId:function() { return this.id;}, getName:function() { return this.name;}, getKana:function() { return this.kana;}, getNote:function() { return this.note;}, linkHash:function( org_data, var_name, link_name, id_name ) { if ( !this[ var_name ] ) { return undefined;}
if ( !org_data ) { return this[ var_name ];}
for ( var i in this[ var_name ] ) { if ( this[ var_name ][i] ) { var data = org_data[ this[ var_name ][i][ id_name ] ]; if ( data ) { this[ var_name ][i][ link_name ] = data;}
} else { delete this[ var_name ][i];}
}
this._caches[ var_name ] = this[ var_name ]; return this._caches[ var_name ];}, linkArray:function( org_data, var_name, sort_func ) { if ( !this[ var_name ] || !org_data ) { return undefined;}
this._caches[ var_name ] = []; for ( var i in this[ var_name ] ) { var data = org_data[ this[ var_name ][i] ]; if ( data ) { this._caches[ var_name ].push( data );}
}
if ( sort_func ) { this._caches[ var_name ].sort( sort_func );}
return this._caches[ var_name ];}, linkData:function( org_data, var_name, trg_id ) { if ( !org_data ) { return undefined;}
this._caches[ var_name ] = org_data[ trg_id ]; return this._caches[ var_name ];}
}); Choco.Area = function( id, pre, rank, name, kana, sname, note, aimg, maps, monsters, npcs ) { this.init( id, name, kana, note ); this.pre = pre || ''; this.sname = sname; this.rank = parseInt( rank, 10 ); this.note = note || ''; this.maps = maps; this.npcs = npcs; this.monsters = monsters;}; MJ.extend( Choco.Area, Choco._Base ); MJ.extend( Choco.Area, { getShortName:function() { return this.sname;}, getMaps:function() { return this._caches.maps || this.linkArray( Choco.maps, 'maps' );}, getMonsters:function( sort_func ) { return this._caches.monsters || this.linkArray( Choco.monsters, 'monsters', sort_func );}, getMonsterIds:function() { return this.monsters;}, addMonster:function( m ) { var id = m.getId(); if ( MJ.isUndefined( this.monsters[ id ] ) ) { this.monsters[ id ] = m; m.addArea( this ); return true;}
return false;}
}); Choco.Map = function( id, name, kana, note, img, aid, monsters, npcs, events ) { this.init( id, name, kana, note ); this.img = img; this.aid = aid; this.monsters = monsters; this.npcs = npcs; this.events = events;}; MJ.extend( Choco.Map, Choco._Base ); MJ.extend( Choco.Map, { getArea:function() { return this._caches.area || this.linkData( Choco.areas, 'area', this.aid );}
}); Choco.Item = function( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, drops, mats, mat_of, q_fee_of, q_item_of, events ) { this._init( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, drops, mats, mat_of, q_fee_of, q_item_of, events );}; MJ.extend( Choco.Item, Choco._Base ); MJ.extend( Choco.Item, { _init: function( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, drops, mats, mat_of, q_fee_of, q_item_of, events ) { this.init( id, name, kana, note ); this.type = type; this.sell_c = sell_c; this.buy_c = buy_c; this.buy_cp = buy_cp; this.make_c = make_c; this.make_cp = make_cp; this.desc = desc; this.img = img; this.drops = drops; this.mats = mats; this.mat_of = mat_of; this.q_fee_of = q_fee_of; this.q_item_of = q_item_of; this.events = events;}, isEquip:function() { return false;}, getType:function() { return this.type;}, getDesc:function() { return this.desc;}, getImg:function() { return this.img || Choco.NO_ICON_IMG;}, getSellC:function() { return this.sell_c;}, getBuyC:function() { return this.buy_c;}, getBuyCp:function() { return this.buy_cp;}, getMakeC:function() { return this.make_c;}, getMakeCp:function() { return this.make_cp;}, getDrops:function() { return this._caches.drops || this.linkHash( Choco.monsters, 'drops', 'monster', 'mid' );}, getMaterials:function() { return this._caches.mats || this.linkHash( Choco.items, 'mats', 'item', 'iid' );}, getMaterialOf:function() { return this._caches.mat_of || this.linkHash( Choco.items, 'mat_of', 'item', 'iid' );}, getQuestFeeOf:function() { return this._caches.q_fee_of || this.linkHash( Choco.quests, 'q_fee_of', 'quest', 'qid' );}, getQuestItemOf:function() { return this._caches.q_item_of || this.linkHash( Choco.quests, 'q_item_of', 'quest', 'qid' );}, getEvents:function() { return this._caches.events || this.linkArray( Choco.events, 'events' );}, hasDrop:function() { return this._caches.drops ? this._caches.drops.length : this._hasDrop();}, _hasDrop:function() { return this.getDrops() ? this._caches.drops.length : 0;}, hasMaterial:function() { return this._caches.mats ? this._caches.mats.length : this._hasMaterial();}, _hasMaterial:function() { return this.getMaterials() ? this._caches.mats.length : 0;}, hasMaterialOf:function() { return this._caches.mat_of ? this._caches.mat_of.length : this._hasMaterialOf();}, _hasMaterialOf:function() { return this.getMaterialOf() ? this._caches.mat_of.length : 0;}, hasQuestItemOf:function() { return this._caches.q_item_of ? this._caches.q_item_of.length : this._hasQuestItemOf();}, _hasQuestItemOf:function() { return this.getQuestItemOf() ? this._caches.q_item_of.length : 0;}, hasQuestFeeOf:function() { return this._caches.q_fee_of ? this._caches.q_fee_of.length : this._hasQuestFeeOf();}, _hasQuestFeeOf:function() { return this.getQuestFeeOf() ? this._caches.q_fee_of.length : 0;}, hasQuestItemForFirstFeeOf:function() { var qs = this.getQuestFeeOf(); return ( qs && qs.length ) ? qs[0].quest.hasQuestItem() : 0;}, hasEvent:function() { return this._caches.events ? this._caches.events.length : this._hasEvent();}, _hasEvent:function() { return this.getEvents() ? this._caches.events.length : 0;}, canBuy:function() { return !!( this.buy_c || this.buy_cp );}, canMake:function() { return !!( this.make_c || this.make_cp || this.getMaterials().length );}
}); Choco.Equip = function( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, lv, sex, atk, def, pow, int, spd, vit, luk, hp, sp, vimg1, vimg2, voption, eq_sets, drops, mats, mat_of, q_fee_of, q_item_of, events ) { this._init( id, type, sell_c, buy_c, buy_cp, make_c, make_cp, name, kana, desc, note, img, drops, mats, mat_of, q_fee_of, q_item_of, events ); this.lv = lv; this.sex = sex; this.atk = atk; this.def = def; this.options = {}; this.options[ Choco.ST.POW ] = pow; this.options[ Choco.ST.INT ] = int; this.options[ Choco.ST.SPD ] = spd; this.options[ Choco.ST.VIT ] = vit; this.options[ Choco.ST.LUK ] = luk; this.options[ Choco.ST.HP ] = hp; this.options[ Choco.ST.SP ] = sp; this.vimg1 = vimg1; this.vimg2 = vimg2; this.voption = voption; this.equip_sets = eq_sets;}; MJ.extend( Choco.Equip, Choco.Item ); MJ.extend( Choco.Equip, { isEquip:function() { return true;}, getLv:function() { return this.lv;}, getSex:function() { return this.sex;}, getAtk:function() { return this.atk;}, getDef:function() { return this.def;}, getOpt:function( type ) { return this.options[ type ] || 0;}, getEquipSetIds:function() { return this.equip_sets;}, getEquipSets:function() { return this._caches.equip_sets || this.linkArray( Choco.equip_sets, 'equip_sets' );}, getVisImg:function( other_one_flag ) { return ( other_one_flag ) ? this.vimg2 : this.vimg1;}, getVisOpt:function() { return this.voption;}, hasEquipSet:function() { return this._caches.equip_sets ? this._caches.equip_sets.length : this._hasEquipSet();}, _hasEquipSet:function() { return this.getEquipSets() ? this._caches.equip_sets.length : 0;}
}); Choco.EquipSet = function( id, pow, int, spd, vit, luk, hp, sp, name, kana, note, equips ) { this.init( id, name, kana, note ); this.options = {}; this.options[ Choco.ST.POW ] = pow; this.options[ Choco.ST.INT ] = int; this.options[ Choco.ST.SPD ] = spd; this.options[ Choco.ST.VIT ] = vit; this.options[ Choco.ST.LUK ] = luk; this.options[ Choco.ST.HP ] = hp; this.options[ Choco.ST.SP ] = sp; this.equips = equips;}; MJ.extend( Choco.EquipSet, Choco._Base ); MJ.extend( Choco.EquipSet, { getOpt:function( type ) { return this.options[ type ] || 0;}, getEquips:function() { return this._caches.equips || Choco.equips ? this.linkArray( Choco.equips, 'equips' ) : this.linkArray( Choco.items, 'equips' );}, getN:function() { return this._caches.n || this._getN();}, _getN:function() { var equips = this.getEquips(); var types = {}; var n = 0; for ( var i in equips ) { types[ equips[i].getType() ] = 1;}
for ( var j in Choco.IT ) { if ( Choco.IT[j] != Choco.IT.CONSUME && Choco.IT[j] != Choco.IT.OTHER ) { if ( types[ Choco.IT[j] ] ) { n++;}
}
}
this._caches.n = n; return n;}
}); Choco.Monster = function( id, type, lv, zok, exp, atk, def, mdef, hp, name, kana, note, img, maps, areas, drops, events ) { this.init( id, name, kana, note ); this.type = type; this.lv = ( isNaN( lv ) || lv < 1 ) ? 1 : Number( lv ); this.zok = ( MJ.isEmpty( zok ) || isNaN( zok ) || zok < 0 || zok > Choco.ZOK_WOOD ) ? undefined : Number( zok ); this.exp = ( MJ.isEmpty( exp ) || isNaN( exp ) || exp < 0 ) ? undefined : Number( exp ); this.hp = ( MJ.isEmpty( hp ) || isNaN( hp ) || hp < 0 ) ? undefined : Number( hp ); this.atk = ( MJ.isEmpty( atk ) || isNaN( atk ) || atk < 0 ) ? undefined : Number( atk ); this.def = ( MJ.isEmpty( def ) || isNaN( def ) || def < 0 ) ? undefined : Number( def ); this.mdef = ( MJ.isEmpty( mdef ) || isNaN( mdef ) || mdef < 0 ) ? undefined : Number( mdef ); this.img = img; this.maps = maps; this.areas = areas; this.drops = drops; this.events = events;}; MJ.extend( Choco.Monster, Choco._Base ); MJ.extend( Choco.Monster, { getLv:function() { return this.lv;}, getZok:function() { return this.zok;}, getExp:function() { return this.exp;}, getHp:function() { return this.hp;}, getAtk:function( type, z, def, dmg ) { return ( MJ.isUndefined( this.atk ) ) ? this.calcAtk( type, z, def, dmg ) : this.atk ;}, getDef:function( type, z, ap, dmg ) { return ( MJ.isEmpty( this.def ) ) ? this.calcDef( type, z, ap, dmg ) : this.def ;}, getMdef:function( type, z, int, dmg ) { return ( MJ.isUndefined( this.mdef ) ) ? this.calcMdef( type, z, int, dmg ) : this.mdef;}, getMaps:function() { return this._caches.maps || this.linkArray( Choco.maps, 'maps' );}, getMapIds:function() { return this.maps;}, getAreas:function() { return this._caches.areas || this.linkArray( Choco.areas, 'areas' );}, getAreaIds:function() { return this.areas;}, getDrops:function() { return this._caches.drops || this.linkHash( Choco.items, 'drops', 'item', 'iid' );}, getEvents:function() { return this._caches.events || this.linkArray( Choco.events, 'events' );}, getDamage: function( type, z, ap, renda_n ) { if ( MJ.isUndefined( this.def ) ) { return undefined;}
var n = this.oddsOfAtack( type, z, renda_n ); var d = MJ.Util.round( ( ap - this.def ) * 2 * n, 1 ); return ( d > 0 ) ? Math.floor(d) : 0;}, getDamageMahou: function( type, z, int ) { if ( MJ.isUndefined( this.mdef ) ) { return undefined;}
type = ( type == Choco.ATACK.MA1 ) ? Choco.ATACK.MA1 : Choco.ATACK.MA2; var l = Choco.ODDS[ type ]; var n = this.oddsOfZok( z, this.zok ); var m = (n == 0.8) ? 4 : (n == 0.9) ? 2 : (n == 1) ? 0 : (n == 1.5) ? 2 : 4; var o = ( type == Choco.ATACK.MA1 ) ? 1 : 2; var d = MJ.Util.round( ( l * int - this.mdef ) * n - m * o, 1 ); return ( d > 0 ) ? Math.floor(d) : 0;}, getDamageMidare: function( type, ap ) { var b = this.getDamage( type, 0, ap, 1 ); return ( type == Choco.ATACK.MIDARENDA ) ?
[ Math.ceil(b*1), Math.ceil(b*2), Math.ceil(b*3), Math.ceil(b*4), Math.ceil(b*7) ]:
[ Math.ceil(b*1), Math.ceil(b*1.4), Math.ceil(b*2), Math.ceil(b*3), Math.ceil(b*3.4), Math.ceil(b*4), Math.ceil(b*4.6), Math.ceil(b*5), Math.ceil(b*6), Math.ceil(b*12) ];}, getSufferDamage: function( type, z, def ) { if ( MJ.isUndefined( this.atk ) ) { return undefined;}
var n = this.oddsOfAtack( type, z ); var d = MJ.Util.round( ( this.atk - def ) * n, 1 ); return ( d > 0 ) ? Math.floor(d) : 0;}, calcAtk: function( type, z, def, dmg ) { if ( MJ.isEmpty( type ) || MJ.isEmpty( z ) || MJ.isEmpty( def ) || MJ.isEmpty( dmg ) ) { return undefined;}
var n = this.oddsOfZok( this.zok, z ); return MJ.Util.round( def + ( dmg / Choco.ODDS[ Choco.ATACK.ENM_NORMAL ] / n ), 1 );}, calcDef: function( type, z, ap, dmg ) { if ( MJ.isEmpty( type ) || MJ.isEmpty( z ) || MJ.isEmpty( ap ) || MJ.isEmpty( dmg ) ) { return undefined;}
var n = this.oddsOfAtack( type, z ); var def = MJ.Util.round( ap - ( dmg / 2 / n ), 1 ); return ( def > 0 ) ? def : 0;}, calcMdef: function( type, z, int, dmg ) { if ( MJ.isEmpty( type ) || MJ.isEmpty( z ) || MJ.isEmpty( int ) || MJ.isEmpty( dmg ) ) { return undefined;}
var l = Choco.ODDS[ type ]; var n = this.oddsOfZok( z, this.zok ); var m1 = (n == 0.8) ? 4 : (n == 0.9) ? 2 : (n == 1) ? 0 : (n == 1.5) ? 2 : 4; var m2 = ( type == Choco.ATACK.MA1 ) ? 1 : 2; var mdef = MJ.Util.round( l * int - ( dmg + m1 * m2 ) / n, 1 ); return ( mdef > 0 ) ? mdef : 0;}, getKillAp: function( type, z, atk_n, renda_n ) { if ( MJ.isEmpty( this.def ) || MJ.isEmpty( this.hp ) ) { return undefined;}
var n = this.oddsOfAtack( type, z, renda_n, true ); return Math.ceil( ( this.hp / atk_n ) / 2 / n + this.def );}, getKillInt: function( type, z, atk_n ) { if ( MJ.isEmpty( this.mdef ) || MJ.isEmpty( this.hp ) ) { return undefined;}
var l = this.oddsOfAtack( type, z ); var n = this.oddsOfZok( z, this.zok ); var m = (n == 0.8) ? 4 : (n == 0.9) ? 2 : (n == 1) ? 0 : (n == 1.5) ? 2 : 4; var o = ( type == Choco.ATACK.MA1 ) ? 1 : 2; return Math.ceil( ( ( this.hp + m * o ) / n + this.mdef ) / l );}, oddsOfAtack: function( type, z, renda_n, total_f ) { var n = Choco.ODDS[ type ]; switch ( type ) { case Choco.ATACK.NORMAL:
case Choco.ATACK.CRITICAL: return n * this.oddsOfZok( z, this.zok ); case Choco.ATACK.ENM_NORMAL:
case Choco.ATACK.ENM_CRITICAL: return n * this.oddsOfZok( this.zok, z ); case Choco.ATACK.MIDARENDA:
renda_n = renda_n || 5; return total_f ? this._mida_total( n, renda_n, Choco.MIDARENDA_ODDS ) : n * Choco.MIDARENDA_ODDS[ --renda_n ]; case Choco.ATACK.MIDAREPPA:
renda_n = renda_n || 10; return total_f ? this._mida_total( n, renda_n, Choco.MIDAREPPA_ODDS ) : n * Choco.MIDAREPPA_ODDS[ --renda_n ]; default: return n;}
}, _mida_total: function( n, renda_n, arr ) { var m = 0; for ( var i = 0; i < renda_n; i++ ) { m += arr[ i ];}
return n * m;}, oddsOfZok: function( hitter_z, getter_z ) { if ( hitter_z == 0 || getter_z == 0 ) { return 1;}
switch ( hitter_z - getter_z ) { case -1:
case 4: return 0.8; case -2:
case 3: return 1.5; case -3:
case 2: return 0.9; case -4:
case 1: return 2; default: return 1;}
}, addArea: function( area ) { var id = area.getId(); if ( MJ.isUndefined( this.areas[ id ] ) ) { this.areas[ id ] = area; area.addMonster( this ); return true;}
return false;}, isEventMonster:function() { return !!( MJ.isArray( this.events ) && this.events.length );}
}); Choco.NPC = function( id, name, kana, note, img, maid, quests, events ) { this.init( id, name, kana, note ); this.img = img; this.maid = maid; this.quests = quests; this.events = events;}; MJ.extend( Choco.NPC, Choco._Base ); MJ.extend( Choco.NPC, { getMap:function() { return this._caches.map || this.linkData( Choco.maps, 'map', this.maid );}, getEvents:function() { return this._caches.events || this.linkArray( Choco.events, 'events' );}
}); Choco.Quest = function( id, name, kana, note, nid, lv, fee_c, fee_exp, q_fees, q_items, q_monsters, events ) { this.init( id, name, kana, note ); this.lv = lv; this.nid = nid; this.fee_c = fee_c; this.fee_exp = fee_exp; this.q_fees = q_fees; this.q_items = q_items; this.q_monsters = q_monsters; this.events = events;}; MJ.extend( Choco.Quest, Choco._Base ); MJ.extend( Choco.Quest, { getLv:function() { return this.lv;}, getNpcId:function() { return this.nid;}, getFeeChoco:function() { return this.fee_c;}, getFeeExp:function() { return this.fee_exp;}, getQuestFees:function() { return this._caches.q_fees || this.linkHash( Choco.items, 'q_fees', 'item', 'iid' );}, getQuestItems:function() { return this._caches.q_items || this.linkHash( Choco.items, 'q_items', 'item', 'iid' );}, getQuestMonsters:function() { return this._caches.q_monsters || this.linkHash( Choco.monsters, 'q_monsters', 'monster', 'mid' );}, getEvents:function() { return this._caches.events || this.linkArray( Choco.events, 'events' );}, hasQuestItem:function() { return this._caches.q_items ? this._caches.q_items.length : this._hasQuestItem();}, _hasQuestItem:function() { return this.getQuestItems() ? this._caches.q_items.length : 0;}
}); Choco.Event = function( id, name, kana, note, start_date, end_date, areas, maps, items, monsters, npcs, quests ) { this.init( id, name, kana, note ); this.start_date = start_date; this.end_date = end_date; this.areas = areas; this.maps = maps; this.items = items; this.monsters = monsters; this.npcs = npcs; this.quests = quests;}; MJ.extend( Choco.Event, Choco._Base ); MJ.extend( Choco.Event, { getStartDate:function() { return this.start_date;}, getEndDate:function() { return this.end_date;}
}); Choco.Face = function( id, name, kana, note, flag, sex, img ) { this.init( id, name, kana, note ); this.flag = flag; this.sex = sex; this.img = img;}; MJ.extend( Choco.Face, Choco._Base ); MJ.extend( Choco.Face, { getImg:function() { return this.img;}, getNextFaceId:function() { var fid = 0; for ( var i = this.id + 1; i < Choco.faces[ this.sex ].length; i++ ) { var f = Choco.faces[ this.sex ][i]; if ( f.flag ) { fid = f.id; break;}
}
return fid;}, getNextEyeId:function() { var f = Choco.faces[ this.sex ][ this.id + 1 ]; if ( f && !f.flag ) { return f.id;}
if ( this.flag ) { return this.id;}
var fid = 0; for ( var i = this.id - 1; i >= 0; i-- ) { f = Choco.faces[ this.sex ][i]; if ( f.flag ) { fid = f.id; break;}
}
return fid;}
}); Choco.Hair = function( id, name, kana, note, flag, sex, img_f, img_b ) { this.init( id, name, kana, note ); this.flag = flag; this.sex = sex; this.img_f = img_f; this.img_b = img_b;}; MJ.extend( Choco.Hair, Choco._Base ); MJ.extend( Choco.Hair, { getImg:function( f ) { return f ? this.img_b : this.img_f;}, getNextHairId:function() { var hid = 0; for ( var i = this.id + 1; i < Choco.hairs[ this.sex ].length; i++ ) { var h = Choco.hairs[ this.sex ][i]; if ( h.flag ) { hid = h.id; break;}
}
return hid;}, getNextColorId:function() { var h = Choco.hairs[ this.sex ][ this.id + 1 ]; if ( h && !h.flag ) { return h.id;}
if ( this.flag ) { return this.id;}
var hid = 0; for ( var i = this.id - 1; i >= 0; i-- ) { h = Choco.hairs[ this.sex ][i]; if ( h.flag ) { hid = h.id; break;}
}
return hid;}
}); Choco.Character = function( args ) { this.cons( args );}; Choco.Character.EV = { ALL: 1, VIS: 2, IT: 3, ST: 4
}; MJ.extend( Choco.Character, MJ.Evnt.CustomEvent ); MJ.extend( Choco.Character, { cons: function( args ) { this.st = {}; this.stC = {}; this.stA = {}; this.stE = {}; this.stEs = {}; this.equips = {}; this.saveString = undefined; if ( MJ.isUndefined( args ) ) { args = {};}
this.setAll( args );}, setAll: function( args ) { this.sex = this.chkVarSex( args[ 'sex' ] ) || Choco.SEX_M; this.face = this.chkVarFace( args[ 'face' ] ) || 0; this.hair = this.chkVarHair( args[ 'hair' ] ) || 0; this.zok = this.chkVarZok( args[ 'zok' ] ) || 1; this.lv = this.chkVarLv( args[ 'lv' ] ) || 1; this.stC.POW = this.chkVarSt( args[ 'pow_c' ] ) || 1; this.stC.INT = this.chkVarSt( args[ 'int_c' ] ) || 1; this.stC.SPD = this.chkVarSt( args[ 'spd_c' ] ) || 1; this.stC.VIT = this.chkVarSt( args[ 'vit_c' ] ) || 1; this.stC.LUK = this.chkVarSt( args[ 'luk_c' ] ) || 1; this.bonus = this.calcBonus(); if ( this.bonus > ( this.lv - 1 ) * 3 || this.bonus < 0 ) { this.stC.POW = 1; this.stC.INT = 1; this.stC.SPD = 1; this.stC.VIT = 1; this.stC.LUK = 1; this.bonus = this.calcBonus();}
this.stC.HP = this.calcHpC(); this.stC.SP = this.calcSpC(); this.stA.POW = this.chkVarSt( args['pow_a'] ) || 0; this.stA.INT = this.chkVarSt( args['int_a'] ) || 0; this.stA.SPD = this.chkVarSt( args['spd_a'] ) || 0; this.stA.VIT = this.chkVarSt( args['vit_a'] ) || 0; this.stA.LUK = this.chkVarSt( args['luk_a'] ) || 0; this.equips[ Choco.IT.ARMS ] = args[ Choco.IT.ARMS ] || undefined; this.equips[ Choco.IT.SHIELD ] = args[ Choco.IT.SHIELD ] || undefined; this.equips[ Choco.IT.HEAD ] = args[ Choco.IT.HEAD ] || undefined; this.equips[ Choco.IT.BACK ] = args[ Choco.IT.BACK ] || undefined; this.equips[ Choco.IT.HAND ] = args[ Choco.IT.HAND ] || undefined; this.equips[ Choco.IT.NECK ] = args[ Choco.IT.NECK ] || undefined; this.equips[ Choco.IT.CLOTHES ] = args[ Choco.IT.CLOTHES ] || undefined; this.equips[ Choco.IT.BOOTS ] = args[ Choco.IT.BOOTS ] || undefined; this.stE = this.getStE(); this.stEs = this.getStEs(); this.st[ Choco.ST.POW ] = this.calcSt( Choco.ST.POW ); this.st[ Choco.ST.INT ] = this.calcSt( Choco.ST.INT ); this.st[ Choco.ST.SPD ] = this.calcSt( Choco.ST.SPD ); this.st[ Choco.ST.VIT ] = this.calcSt( Choco.ST.VIT ); this.st[ Choco.ST.LUK ] = this.calcSt( Choco.ST.LUK ); this.st[ Choco.ST.HP ] = this.calcHp(); this.st[ Choco.ST.SP ] = this.calcSp(); this.atk = this.calcAtk(); this.ap = this.calcAp(); this.def = this.calcDef(); this.updated( Choco.Character.EV.ALL );}, getSex: function() { return this.sex;}, setSex: function( sex ) { sex = this.chkVarSex( sex ); if ( MJ.isUndefined( sex ) || !this.isChangeSex() ) { return undefined;}
this.sex = sex; this.updated( Choco.Character.EV.VIS ); return this.sex;}, toggleSex: function() { this.setSex( ( this.sex == Choco.SEX_M ) ? Choco.SEX_W : Choco.SEX_M );}, isChangeSex: function() { for ( var i in this.equips ) { if ( this.equips[i] && this.equips[i].sex == this.sex ) { return false;}
}
return true;}, chkVarSex: function( sex ){ sex = parseInt( sex, 10 ); return ( sex == Choco.SEX_M || sex == Choco.SEX_W ) ? sex : undefined;}, getFaceImg: function() { return Choco.faces ? Choco.faces[ this.sex ][ this.face ].getImg() : undefined;}, setFace: function( face ) { return Choco.faces ? this.setVisParam( 'face', face, Choco.faces[ this.sex ].length ) : undefined;}, toggleFace: function() { return Choco.faces ? this.setFace( Choco.faces[ this.sex ][ this.face ].getNextFaceId() ) : undefined;}, toggleEye: function() { return Choco.faces ? this.setFace( Choco.faces[ this.sex ][ this.face ].getNextEyeId() ) : undefined;}, chkVarFace: function( face ) { return Choco.faces ? this.chkVisParam( face, Choco.faces[ this.sex ].length ) : undefined;}, getHairImg:function(f) { return Choco.hairs ? Choco.hairs[ this.sex ][ this.hair ].getImg(f) : undefined;}, setHair:function( hair ) { return Choco.hairs ? this.setVisParam( 'hair', hair, Choco.hairs[ this.sex ].length ) : undefined;}, toggleHair: function() { return Choco.hairs ? this.setHair( Choco.hairs[ this.sex ][ this.hair ].getNextHairId() ) : undefined;}, toggleColor: function() { return Choco.hairs ? this.setHair( Choco.hairs[ this.sex ][ this.hair ].getNextColorId() ) : undefined;}, chkVarHair: function( hair ) { return Choco.hairs ? this.chkVisParam( hair, Choco.hairs[ this.sex ].length ) : undefined;}, getZok: function() { return this.zok;}, setZok: function( zok ) { return this.setVisParam( 'zok', zok, Choco.ZOK_WOOD + 1 );}, toggleZok: function() { this.setZok( ( this.zok == Choco.ZOK_WOOD ) ? 1 : this.zok + 1 );}, chkVarZok: function( zok ) { return this.chkVisParam( zok, Choco.ZOK_WOOD + 1 );}, setVisParam: function( key, param, max ) { param = this.chkVisParam( param, max ); if ( MJ.isUndefined( param ) ) { return undefined;}
this[key] = param; this.updated( Choco.Character.EV.VIS ); return this[key];}, chkVisParam: function( param, max ) { param = parseInt( param, 10 ); return ( param < 0 || param >= max ) ? undefined : param;}, getLv: function() { return this.lv;}, setLv: function( lv ) { lv = this.isSetLv( lv ); if ( MJ.isUndefined( lv ) ) { return undefined;}
this.lv = lv; this.bonus = this.calcBonus(); this.stC.SP = this.calcSpC(); this.st.SP = this.calcSp(); this.stC.HP = this.calcHpC(); this.st.HP = this.calcHp(); this.updated( Choco.Character.EV.ST ); return this.lv;}, isSetLv: function( lv ) { lv = this.chkVarLv( lv ); if ( MJ.isUndefined( lv ) ) { return undefined;}
if ( MJ.isUndefined( this.lv ) ) { return lv;}
var b_low = ( MJ.isUndefined( this.bonus ) || this.bonus <= 0 ) ? this.lv : this.lv - Math.floor( this.bonus / 3 ); if ( lv < b_low ) { return undefined;}
var e_low = 1; for ( var i in this.equips ) { if ( this.equips[i] && this.equips[i].lv > e_low ) { e_low = this.equips[i].lv;}
}
return ( lv < e_low ) ? undefined : lv;}, chkVarLv: function( lv ) { lv = parseInt( lv, 10 ); if ( isNaN( lv ) ) { return undefined;}
return ( lv > Choco.MAX_LV || lv < 1 ) ? undefined : lv;}, getBonus: function() { return ( MJ.isUndefined( this.bonus ) ) ? this.calcBonus() : this.bonus;}, calcBonus: function() { var p = this.stC.POW || 1; var i = this.stC.INT || 1; var s = this.stC.SPD || 1; var v = this.stC.VIT || 1; var l = this.stC.LUK || 1; return ( this.lv - 1 ) * 3 + 5 - p - i - s - v - l;}, getPowC: function() { return this.stC.POW;}, getIntC: function() { return this.stC.INT;}, getSpdC: function() { return this.stC.SPD;}, getVitC: function() { return this.stC.VIT;}, getLukC: function() { return this.stC.LUK;}, getHpC: function() { return ( MJ.isUndefined( this.stC.HP ) ) ? this.calcHpC() : this.stC.HP;}, getSpC: function() { return ( MJ.isUndefined( this.stC.SP ) ) ? this.calcSpC() : this.stC.SP;}, setPowC: function( p ) { return this.setStC( 'POW', p );}, setIntC: function( i ) { return this.setStC( 'INT', i );}, setSpdC: function( s ) { return this.setStC( 'SPD', s );}, setVitC: function( v ) { return this.setStC( 'VIT', v );}, setLukC: function( l ) { return this.setStC( 'LUK', l );}, setStC: function( key, st ) { st = this.isSetStC( key, st ); if ( MJ.isUndefined( st ) ) { return undefined;}
this.stC[ key ] = st; this.st[ key ] = this.calcSt( key ); switch ( key ) { case 'POW':
this.atk = this.calcAtk(); this.ap = this.calcAp(); break; case 'INT':
this.stC.SP = this.calcSpC(); this.st.SP = this.calcSp(); break; case 'VIT':
this.stC.HP = this.calcHpC(); this.st.HP = this.calcHp(); this.def = this.calcDef(); break;}
this.bonus = this.calcBonus(); this.updated( Choco.Character.EV.ST ); return this.stC[ key ];}, isSetPowC: function( p ) { return this.isSetStC( 'POW', p );}, isSetIntC: function( i ) { return this.isSetStC( 'INT', i );}, isSetSpdC: function( s ) { return this.isSetStC( 'SPD', s );}, isSetVitC: function( v ) { return this.isSetStC( 'VIT', v );}, isSetLukC: function( l ) { return this.isSetStC( 'LUK', l );}, isSetStC: function( key, st ) { st = this.chkVarSt( st ); return ( !MJ.isUndefined( st ) && this.stC[ key ] + this.bonus >= st && this.stE[ key ] + st > 0 ) ? st : undefined;}, calcHpC: function() { return ( this.lv + this.stC.VIT - 2 ) * 40 + 120;}, calcSpC: function() { return ( this.lv < 10 ) ? ( this.stC.INT - 1 ) * 40 : ( this.lv + this.stC.INT - 11 ) * 40 + 200;}, chkVarSt: function( st ) { if ( MJ.isUndefined( st ) || isNaN( st ) ) { return undefined;}
st = parseInt( st, 10 ); return ( st > 99 || st < 1 ) ? undefined : st;}, getPowA: function() { return this.stA.POW;}, getIntA: function() { return this.stA.INT;}, getSpdA: function() { return this.stA.SPD;}, getVitA: function() { return this.stA.VIT;}, getLukA: function() { return this.stA.LUK;}, setPowA: function( p ) { return this.setStA( 'POW', p );}, setIntA: function( i ) { return this.setStA( 'INT', i );}, setSpdA: function( s ) { return this.setStA( 'SPD', s );}, setVitA: function( v ) { return this.setStA( 'VIT', v );}, setLukA: function( l ) { return this.setStA( 'LUK', l );}, setStA: function( key, st ) { st = this.chkVarStA( st ); if ( MJ.isUndefined( st ) ) { return undefined;}
this.stA[ key ] = st; this.st[ key ] = this.calcSt( key ); switch ( key ) { case 'POW':
this.atk = this.calcAtk(); this.ap = this.calcAp(); break; case 'VIT':
this.def = this.calcDef(); break;}
this.updated( Choco.Character.EV.ST ); return this.stA[ key ];}, isSetStA:function( st ) { return this.chkVarStA( st );}, chkVarStA: function( st ) { if ( MJ.isUndefined( st ) || isNaN( st ) ) { return undefined;}
st = parseInt( st, 10 ); return ( st > 99 || st < 0 ) ? undefined : st;}, getPowE: function() { return this.stE.POW;}, getIntE: function() { return this.stE.INT;}, getSpdE: function() { return this.stE.SPD;}, getVitE: function() { return this.stE.VIT;}, getLukE: function() { return this.stE.LUK;}, getHpE: function() { return this.stE.HP;}, getSpE: function() { return this.stE.SP;}, getPowEs: function() { return this.stEs.POW;}, getIntEs: function() { return this.stEs.INT;}, getSpdEs: function() { return this.stEs.SPD;}, getVitEs: function() { return this.stEs.VIT;}, getLukEs: function() { return this.stEs.LUK;}, getHpEs: function() { return this.stEs.HP;}, getSpEs: function() { return this.stEs.SP;}, getPow: function() { return this.st.POW;}, getInt: function() { return this.st.INT;}, getSpd: function() { return this.st.SPD;}, getVit: function() { return this.st.VIT;}, getLuk: function() { return this.st.LUK;}, getHp: function() { return this.st.HP;}, getSp: function() { return this.st.SP;}, calcPow: function() { return this.calcSt( 'POW' );}, calcInt: function() { return this.calcSt( 'INT' );}, calcSpd: function() { return this.calcSt( 'SPD' );}, calcVit: function() { return this.calcSt( 'VIT' );}, calcLuk: function() { return this.calcSt( 'LUK' );}, calcHp: function() { return this.getHpC() + this.getHpE() + this.getHpEs();}, calcSp: function() { return this.getSpC() + this.getSpE() + this.getSpEs();}, calcSt: function( key ) { if ( key == Choco.ST.HP ) { return this.calcHp();}
if ( key == Choco.ST.SP ) { return this.calcSp();}
return this.stC[ key ] + this.stA[ key ] + this.stE[ key ] + this.stEs[ key ];}, getAtk: function( souryo ) { if ( !souryo ) { return this.atk || this.calcAtk();}
var per = souryo.getAtkPer(); return ( per ) ? Math.floor( this.atk * per / 100 ) : this.atk;}, getAtkPer: function() { if ( !this.isSklAtaku() ) { return 0;}
var lp = this.lv + this.st.POW; return ( lp > 110 ) ? lp : 110;}, calcAtk: function() { var atk = this.st.POW * 2; return this.equips[ Choco.IT.ARMS ] ? atk + this.equips[ Choco.IT.ARMS ].getAtk() : atk;}, getAp: function( souryo ) { if ( !souryo ) { return this.ap || this.calcAp();}
var per = souryo.getApPer(); return ( per ) ? Math.floor( this.atk * per / 100 + this.st.POW ) : this.ap;}, getApPer: function() { var atk_per = this.getAtkPer(); return ( atk_per ) ? ( atk_per - 100 ) / 2 + 100 : 0;}, calcAp: function() { return this.atk + this.st.POW;}, getDef: function( souryo ) { if ( !souryo ) { return this.def || this.calcDef();}
var per = souryo.getDefPer(); return ( per ) ? Math.floor( this.def * per / 100 ) : this.def;}, getDefPer: function() { if ( !this.isSklMamoru() ) { return 0;}
var lv = this.lv + this.st.VIT; return ( lv > 110 ) ? lv : 110;}, calcDef: function() { var def = this.st.VIT * 2; for ( var i in this.equips ) { if ( this.equips[i] ) { def += this.equips[i].getDef();}
}
return def;}, getStE: function() { var ste = { POW:0, INT:0, SPD:0, VIT:0, LUK:0, HP:0, SP:0 }; for ( var i in this.equips ) { if ( this.equips[i] ) { for ( var j in Choco.ST ) { ste[ j ] += this.equips[ i ].getOpt( j );}
}
}
return ste;}, getEquip: function( type ) { return this.equips[ type ];}, setEquip: function( equip ) { var after_ste = this.isSetEquip( equip ); if ( after_ste ) { this.equips[ equip.type ] = equip; this.stE = after_ste; this.stEs = this.getStEs(); for ( var i in Choco.ST ) { this.st[ i ] = this.calcSt( i );}
this.atk = this.calcAtk(); this.ap = this.calcAp(); this.def = this.calcDef(); this.updated( Choco.Character.EV.EQ );}
}, delEquip: function( type ) { var this_equip = this.equips[ type ]; if ( this_equip ) { for ( var i in Choco.ST ) { if ( i == Choco.ST.HP || i == Choco.ST.SP ) { continue;}
if ( this.stC[i] + this.stE[i] - this_equip.getOpt( i ) < 1 ) { return false;}
}
this.equips[ type ] = undefined; this.stE = this.getStE(); this.stEs = this.getStEs(); for ( var j in Choco.ST ) { this.st[ j ] = this.calcSt( j );}
this.atk = this.calcAtk(); this.ap = this.calcAp(); this.def = this.calcDef(); this.updated( Choco.Character.EV.EQ ); return true;}
return false;}, isSetEquip: function( equip ) { if ( !equip || equip.getLv() > this.lv ) { return undefined;}
var e_sex = equip.getSex(); if ( e_sex && e_sex != this.sex ) { return undefined;}
var ste = {}; var this_equip = this.equips[ equip.type ]; for ( var i in Choco.ST ) { ste[i] = ( this_equip ) ? this.stE[i] - this_equip.getOpt(i) + equip.getOpt(i) : this.stE[i] + equip.getOpt(i); if ( i == Choco.ST.HP || i == Choco.ST.SP ) { continue;}
if ( this.stC[ i ] + ste[ i ] < 1 ) { return undefined;}
}
return ste;}, getStEs: function() { var stes = { POW:0, INT:0, SPD:0, VIT:0, LUK:0, HP:0, SP:0 }; var hash = {}; for ( var i in this.equips ) { if ( !this.equips[i] ) { continue;}
var sets = this.equips[i].getEquipSets(); if ( !MJ.isArray( sets ) || sets.length <= 0 ) { continue;}
for ( var j in sets ) { var id = sets[j].getId(); if ( hash[ id ] ) { hash[ id ].n++; if ( hash[ id ].es.getN() <= hash[ id ].n ) { for ( var k in Choco.ST ) { stes[k] += hash[ id ].es.getOpt( k );}
}
} else { hash[ id ] = { es:sets[j], n:1 };}
}
}
return stes;}, isSklAtaku: function() { return !!( this.stC.POW >= 27 && this.stC.INT >= 20 );}, isSklMamoru: function() { return !!( this.stC.INT >= 35 && this.stC.VIT >= 45 );}, isSklKiai: function() { return !!( this.stC.POW >= 18 && this.stC.VIT >= 8 );}, isSklChou: function() { return !!( this.stC.POW >= 38 && this.stC.VIT >= 15 );}, isSklShin: function() { return !!( this.stC.POW >= 38 && this.stC.VIT >= 15 );}, isSklMa1: function() { return !!( this.stC.INT >= 15 && this.stC.SPD >= 10 );}, isSklMa2: function() { return !!( this.stC.INT >= 33 && this.stC.SPD >= 25);}, updated: function( event_type ) { this.saveString = this.toSaveString(); this.lastEvent = event_type; this.dispatch( 'update' );}, reset: function() { this.setAll( {} );}, isDefault: function() { return ( this.toSaveString() == '1,1,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0' );}, getSaveString:function() { return this.saveString || this.toSaveString();}, toSaveString: function() { var arr = [ this.sex, this.zok, this.face, this.hair, 0, this.lv, this.stC.POW, this.stC.INT, this.stC.SPD, this.stC.VIT, this.stC.LUK, this.stA.POW, this.stA.INT, this.stA.SPD, this.stA.VIT, this.stA.LUK ]; for ( var i in this.equips ) { if ( this.equips[i] ) { arr.push( this.equips[i].getId() );} else { arr.push( '0' );}
}
return arr.join( ',' );}
}); Choco.Character.createByString = function( str ) { if ( !str || str === '' ) { return new Choco.Character();}
str = unescape( str ); var arr = str.split(','); var args = { sex: arr[0], zok: arr[1], face: arr[2], hair: arr[3], color: arr[4], lv: arr[5], pow_c: arr[6], int_c: arr[7], spd_c: arr[8], vit_c: arr[9], luk_c: arr[10], pow_a: arr[11], int_a: arr[12], spd_a: arr[13], vit_a: arr[14], luk_a: arr[15]
}; for (var j = 16; j < 24; j++) { if ( arr[j] != '0' ) { var equip = Choco.equips[ arr[j] ]; if ( MJ.isUndefined( equip ) ) { continue;}
args[ equip.getType() ] = equip;}
}
return new Choco.Character( args );}; Choco.FreeChar = function() { this.cons();}; MJ.extend( Choco.FreeChar, Choco.Character ); MJ.extend( Choco.FreeChar, { isSetLv: function( lv ) { return this.chkVarLv( lv );}, calcBonus: function() { return 0;}, isSetStC: function( key, st ) { return this.chkVarSt( st );}, chkVarSt: function( st ) { st = parseInt( st, 10 ); return ( st > 200 || st < 0 ) ? undefined : st;}, setAtk: function( atk ) { atk = parseInt( atk, 10 ); this.atk = isNaN( atk ) ? 0 : atk; this.ap = this.calcAp(); this.dispatch('update'); return this.atk;}, setDef: function( def ) { def = parseInt( def, 10 ); this.def = isNaN( def ) ? 0 : def; this.dispatch('update'); return this.def;}, isSklAtaku: function() { return ( isNaN( this.lv ) || this.lv < 16 || isNaN( this.st.POW ) || this.st.POW < 1 ) ? false : true;}, isSklMamoru: function() { return ( isNaN( this.lv ) || this.lv < 26 || isNaN( this.st.VIT ) || this.st.VIT < 1 ) ? false : true;}
}); 