@@ -64,9 +64,9 @@ public MapBlock(ushort x, ushort y, SukaLambdaEngine? vm)
64
64
this . vm = vm ;
65
65
}
66
66
67
- public bool AllowEntrancy ( Character character ,
67
+ public virtual bool AllowEntrancy ( Character character ,
68
68
Heading ? [ ] movements , ushort movementIndexEnteringThisBlock ) => true ;
69
- public bool AllowDeparture ( Character character ,
69
+ public virtual bool AllowDeparture ( Character character ,
70
70
Heading ? [ ] movements , ushort movementIndexEnteringThisBlock ) => true ;
71
71
72
72
/// <summary>
@@ -76,7 +76,7 @@ public bool AllowDeparture(Character character,
76
76
/// <param name="movements"></param>
77
77
/// <param name="movementIndexEnteringThisBlock">0 if the movement starts from this block</param>
78
78
/// <param name="vm"></param>
79
- public void OnCharacterMovingIn ( Character character ,
79
+ public virtual void OnCharacterMovingIn ( Character character ,
80
80
Heading ? [ ] movements , ushort movementIndexEnteringThisBlock )
81
81
{ }
82
82
/// <summary>
@@ -86,14 +86,14 @@ public void OnCharacterMovingIn(Character character,
86
86
/// <param name="movements"></param>
87
87
/// <param name="movementIndexLeavingThisBlock">0 if the movement starts from this block</param>
88
88
/// <param name="vm"></param>
89
- public void OnCharacterMovingOut ( Character character ,
89
+ public virtual void OnCharacterMovingOut ( Character character ,
90
90
Heading ? [ ] movements , ushort movementIndexLeavingThisBlock )
91
91
{ }
92
- public void OnCharacterMovingOutOfMapFromThisBlock ( Character character ,
92
+ public virtual void OnCharacterMovingOutOfMapFromThisBlock ( Character character ,
93
93
Heading ? [ ] movements , ushort movementIndexLeavingThisBlock )
94
94
{ }
95
95
96
- public string RenderAsText ( Language lang ) => blockAsText ;
96
+ public virtual string RenderAsText ( Language lang ) => blockAsText ;
97
97
}
98
98
99
99
[ Index ( nameof ( positionX ) ) ]
@@ -343,10 +343,7 @@ public void CharacterMove(Character character, Heading[] headings, ushort[] dist
343
343
// You can also change distances by yourself!
344
344
345
345
Tuple < ushort , ushort > currentPosition = new ( x , y ) ;
346
- dynamic ? block = null ;
347
- if ( this . blocks . ContainsKey ( currentPosition ) )
348
- block = blocks [ currentPosition ] ;
349
- if ( block != null )
346
+ if ( this . blocks . TryGetValue ( currentPosition , out MapBlock ? block ) )
350
347
{
351
348
if ( outOfMap )
352
349
block . OnCharacterMovingOutOfMapFromThisBlock ( character , headings , i ) ;
@@ -374,16 +371,16 @@ public void CharacterMove(Character character, Heading[] headings, ushort[] dist
374
371
if ( vm == null ) break ;
375
372
character . OnMoveInMap ( vm , currentPosition , plannedHeading , destination , headingResult ) ;
376
373
if ( character . removedFromMap || character . statusTemporary . Mobility <= 0 ) break ;
377
- if ( blocks . ContainsKey ( destination ) ) // blockTo
374
+ if ( this . blocks . TryGetValue ( destination , out block ) ) // blockTo
378
375
{
379
- block = blocks [ destination ] ;
380
376
if ( block != null && ! block . AllowEntrancy ( character , headings , i ) )
381
377
{ // cancel movement
382
378
x -= movement . Item1 ;
383
379
y -= movement . Item2 ;
384
380
break ;
385
381
}
386
- block . OnCharacterMovingIn ( character , headings , i ) ;
382
+ if ( block != null )
383
+ block . OnCharacterMovingIn ( character , headings , i ) ;
387
384
}
388
385
if ( character . removedFromMap || character . statusTemporary . Mobility <= 0 ) break ;
389
386
}
@@ -409,8 +406,7 @@ public string RenderAsText(Language lang, Alignment? alignment = null)
409
406
foreach ( var kvp in blocks )
410
407
{
411
408
if ( kvp . Key . Item1 >= width || kvp . Key . Item2 >= height ) continue ;
412
- dynamic block = kvp . Value ; // kvp.Value.RenderAsText(lang) returns "⚪"
413
- string text = block . RenderAsText ( lang ) ;
409
+ string text = kvp . Value . RenderAsText ( lang ) ;
414
410
if ( text == "" ) continue ;
415
411
if ( text . Count ( ch => ch == '\n ' ) == 0 )
416
412
text = string . Join ( "\n " , Enumerable . Repeat ( text , basicBlockOccupiesRows ) ) ;
0 commit comments