@@ -71,14 +71,12 @@ var DuelStateManager = (function() {
7171 function _handleChallenge ( sender , data , blockNum , duels , worldState ) {
7272 var challengeRef = String ( blockNum ) ;
7373
74- // Verify target exists
75- var targetChar = worldState . characters [ data . target ] ;
76- var senderChar = worldState . characters [ sender ] ;
77- if ( ! targetChar || ! senderChar ) return [ ] ;
78-
7974 // Cannot challenge yourself
8075 if ( sender === data . target ) return [ ] ;
8176
77+ _ensureCharacterStub ( worldState , sender ) ;
78+ _ensureCharacterStub ( worldState , data . target ) ;
79+
8280 var duel = {
8381 id : challengeRef ,
8482 challenger : sender ,
@@ -121,6 +119,9 @@ var DuelStateManager = (function() {
121119 if ( duel . target !== sender ) return [ ] ;
122120 if ( blockNum > duel . deadlineBlock ) return [ ] ;
123121
122+ _ensureCharacterStub ( worldState , duel . challenger ) ;
123+ _ensureCharacterStub ( worldState , duel . target ) ;
124+
124125 // Move from pending to active
125126 duel . status = 'active' ;
126127 duel . energyPledgeB = data . energy_pledge || 100 ;
@@ -349,6 +350,41 @@ var DuelStateManager = (function() {
349350 } ] ;
350351 }
351352
353+ function _ensureCharacterStub ( worldState , account ) {
354+ if ( ! account ) return null ;
355+ worldState . characters = worldState . characters || { } ;
356+ if ( ! worldState . characters [ account ] ) {
357+ worldState . characters [ account ] = {
358+ account : account ,
359+ name : account ,
360+ className : '' ,
361+ school : '' ,
362+ level : 1 ,
363+ xp : 0 ,
364+ hp : 100 ,
365+ maxHp : 100 ,
366+ pot : 10 ,
367+ res : 5 ,
368+ swf : 5 ,
369+ int : 5 ,
370+ for_ : 5 ,
371+ coreBonus : 0 ,
372+ title : '' ,
373+ guild : '' ,
374+ equipment : { } ,
375+ spells : [ ] ,
376+ lastHuntBlock : 0 ,
377+ fallenUntilBlock : 0 ,
378+ currentZone : 'commons_first_light'
379+ } ;
380+ }
381+ worldState . inventories = worldState . inventories || { } ;
382+ if ( ! worldState . inventories [ account ] ) worldState . inventories [ account ] = [ ] ;
383+ worldState . quests = worldState . quests || { } ;
384+ if ( ! worldState . quests [ account ] ) worldState . quests [ account ] = { } ;
385+ return worldState . characters [ account ] ;
386+ }
387+
352388 /**
353389 * Handle a forfeit action.
354390 */
0 commit comments