@@ -23,6 +23,7 @@ public class IPPlugin {
2323 public readonly IList < string > Globals ;
2424
2525 public readonly Dictionary < string , IPTimedEvent > Timers ;
26+ public readonly List < IPTimedEvent > ParallelTimers ;
2627
2728 public IPPlugin ( string name , string code , DirectoryInfo path ) {
2829 Name = name ;
@@ -36,7 +37,7 @@ public IPPlugin(string name, string code, DirectoryInfo path) {
3637 Scope . SetVariable ( "Server" , Fougerite . Server . GetServer ( ) ) ;
3738 Scope . SetVariable ( "DataStore" , DataStore . GetInstance ( ) ) ;
3839 Scope . SetVariable ( "Util" , Util . GetUtil ( ) ) ;
39- Scope . SetVariable ( "Entities " , new LookUp ( ) ) ;
40+ // Scope.SetVariable("Structures ", new LookUp.Structures ());
4041 Scope . SetVariable ( "World" , World . GetWorld ( ) ) ;
4142 Engine . Execute ( code , Scope ) ;
4243 Class = Engine . Operations . Invoke ( Scope . GetVariable ( name ) ) ;
@@ -50,7 +51,7 @@ public void Invoke(string func, params object[] obj) {
5051 else
5152 Fougerite . Logger . LogDebug ( "[IronPython] Function: " + func + " not found in plugin: " + Name ) ;
5253 } catch ( Exception ex ) {
53- Fougerite . Logger . LogException ( ex ) ;
54+ Fougerite . Logger . LogError ( Engine . GetService < ExceptionOperations > ( ) . FormatException ( ex ) ) ;
5455 }
5556 }
5657
@@ -88,21 +89,6 @@ public bool CreateDir(string path) {
8889 return false ;
8990 }
9091
91- // there is no json yet
92- public void ToJsonFile ( string path , string json ) {
93- path = ValidateRelativePath ( path + ".json" ) ;
94- File . WriteAllText ( path , json ) ;
95- }
96-
97- public string FromJsonFile ( string path ) {
98- string json = @"" ;
99- path = ValidateRelativePath ( path + ".json" ) ;
100- if ( File . Exists ( path ) )
101- json = File . ReadAllText ( path ) ;
102-
103- return json ;
104- }
105-
10692 // Dumper methods
10793 public bool DumpObjToFile ( string path , object obj , string prefix = "" ) {
10894 return DumpObjToFile ( path , obj , 1 , 30 , false , false , prefix ) ;
@@ -311,26 +297,18 @@ public void OnDoorUse(Fougerite.Player player, DoorEvent evt) {
311297 }
312298
313299 public void OnEntityDecay ( DecayEvent evt ) {
314- // CONSIDER: if(!evt.Entity...IsAlive) return;
315-
316300 this . Invoke ( "On_EntityDecay" , new object [ ] { evt } ) ;
317301 }
318302
319303 public void OnEntityDeployed ( Fougerite . Player player , Entity entity ) {
320304 this . Invoke ( "On_EntityDeployed" , new object [ ] { player , entity } ) ;
321305 }
322306
323- public void OnEntityDestroyed ( Events . DestroyEvent evt ) {
324- if ( evt . WeaponName == null ) {
325- evt . WeaponName = fixWeaponName ( evt . DamageEvent ) ;
326- }
307+ public void OnEntityDestroyed ( DestroyEvent evt ) {
327308 this . Invoke ( "On_EntityDestroyed" , new object [ ] { evt } ) ;
328309 }
329310
330311 public void OnEntityHurt ( HurtEvent evt ) {
331- if ( evt . WeaponName == null ) {
332- evt . WeaponName = fixWeaponName ( evt . DamageEvent ) ;
333- }
334312 this . Invoke ( "On_EntityHurt" , new object [ ] { evt } ) ;
335313 }
336314
@@ -339,17 +317,11 @@ public void OnItemsLoaded(ItemsBlocks items) {
339317 }
340318
341319 public void OnNPCHurt ( HurtEvent evt ) {
342- if ( evt . WeaponName == null ) {
343- evt . WeaponName = fixWeaponName ( evt . DamageEvent ) ;
344- }
345320 DumpObjToFile ( "NPCHurt" , evt , 3 , 20 , true , true ) ;
346321 this . Invoke ( "On_NPCHurt" , new object [ ] { evt } ) ;
347322 }
348323
349324 public void OnNPCKilled ( DeathEvent evt ) {
350- if ( evt . WeaponName == null ) {
351- evt . WeaponName = fixWeaponName ( evt . DamageEvent ) ;
352- }
353325 DumpObjToFile ( "NPCKilled" , evt , 3 , 20 , true , true ) ;
354326 this . Invoke ( "On_NPCKilled" , new object [ ] { evt } ) ;
355327 }
@@ -367,16 +339,10 @@ public void OnPlayerGathering(Fougerite.Player player, GatherEvent evt) {
367339 }
368340
369341 public void OnPlayerHurt ( HurtEvent evt ) {
370- if ( evt . WeaponName == null ) {
371- evt . WeaponName = fixWeaponName ( evt . DamageEvent , evt . DamageType ) ;
372- }
373342 this . Invoke ( "On_PlayerHurt" , new object [ ] { evt } ) ;
374343 }
375344
376345 public void OnPlayerKilled ( DeathEvent evt ) {
377- if ( evt . WeaponName == null ) {
378- evt . WeaponName = fixWeaponName ( evt . DamageEvent , evt . DamageType ) ;
379- }
380346 this . Invoke ( "On_PlayerKilled" , new object [ ] { evt } ) ;
381347 }
382348
@@ -396,17 +362,9 @@ public void OnServerShutdown() {
396362 this . Invoke ( "On_ServerShutdown" , new object [ 0 ] ) ;
397363 }
398364
399- // timer hooks
400-
401- public void OnTimerCB ( string name ) {
402- if ( Globals . Contains ( name + "Callback" ) ) {
403- Invoke ( name + "Callback" , new object [ 0 ] ) ;
404- }
405- }
406-
407- public void OnTimerCBArgs ( string name , Dictionary < string , object > args ) {
408- if ( Globals . Contains ( name + "Callback" ) ) {
409- Invoke ( name + "Callback" , args ) ;
365+ public void OnTimerCB ( IPTimedEvent evt ) {
366+ if ( Globals . Contains ( evt . Name + "Callback" ) ) {
367+ Invoke ( evt . Name + "Callback" , evt ) ;
410368 }
411369 }
412370
@@ -429,7 +387,7 @@ public IPTimedEvent CreateTimer(string name, int timeoutDelay, Dictionary<string
429387 if ( timedEvent == null ) {
430388 timedEvent = new IPTimedEvent ( name , ( double ) timeoutDelay ) ;
431389 timedEvent . Args = args ;
432- timedEvent . OnFireArgs += new IPTimedEvent . TimedEventFireArgsDelegate ( OnTimerCBArgs ) ;
390+ timedEvent . OnFire += new IPTimedEvent . TimedEventFireDelegate ( OnTimerCB ) ;
433391 Timers . Add ( name , timedEvent ) ;
434392 }
435393 return timedEvent ;
@@ -447,47 +405,53 @@ public IPTimedEvent GetTimer(string name) {
447405
448406 public void KillTimer ( string name ) {
449407 IPTimedEvent timer = GetTimer ( name ) ;
450- if ( timer ! = null )
408+ if ( timer = = null )
451409 return ;
452410
453- timer . Stop ( ) ;
411+ timer . Kill ( ) ;
454412 Timers . Remove ( name ) ;
455413 }
456414
457415 public void KillTimers ( ) {
458416 foreach ( IPTimedEvent current in Timers . Values ) {
459- current . Stop ( ) ;
417+ current . Kill ( ) ;
418+ }
419+ foreach ( IPTimedEvent timer in ParallelTimers ) {
420+ timer . Kill ( ) ;
460421 }
461422 Timers . Clear ( ) ;
423+ ParallelTimers . Clear ( ) ;
462424 }
463425
464426 #endregion
465427
466- // temporarly, for my laziness
467- public Dictionary < string , object > CreateDict ( ) {
468- return new Dictionary < string , object > ( ) ;
428+ #region ParalellTimers
429+
430+ public IPTimedEvent CreateParallelTimer ( string name , int timeoutDelay , Dictionary < string , object > args ) {
431+ IPTimedEvent timedEvent = new IPTimedEvent ( name , ( double ) timeoutDelay ) ;
432+ timedEvent . Args = args ;
433+ timedEvent . OnFire += new IPTimedEvent . TimedEventFireDelegate ( OnTimerCB ) ;
434+ ParallelTimers . Add ( timedEvent ) ;
435+ return timedEvent ;
469436 }
470437
471- public string fixWeaponName ( DamageEvent evt , string dmgType = "Unknown" ) {
472- string weaponName = "" ;
473- if ( evt . attacker . id is TimedExplosive ) {
474- weaponName = "Explosive Charge" ;
475- } else if ( evt . attacker . id is TimedGrenade ) {
476- weaponName = "F1 Grenade" ;
477- } else if ( evt . attacker . id . ToString ( ) . Contains ( "MutantBear" ) ) {
478- weaponName = "Mutant Bear Claw" ;
479- } else if ( evt . attacker . id . ToString ( ) . Contains ( "Bear" ) ) {
480- weaponName = "Bear Claw" ;
481- } else if ( evt . attacker . id . ToString ( ) . Contains ( "MutantWolf" ) ) {
482- weaponName = "Mutant Wolf Claw" ;
483- } else if ( evt . attacker . id . ToString ( ) . Contains ( "Wolf" ) ) {
484- weaponName = "Wolf Claw" ;
485- } else if ( evt . attacker . id . Equals ( evt . victim . id ) ) {
486- weaponName = dmgType ;
487- } else {
488- weaponName = "Hunting Bow" ;
438+ public List < IPTimedEvent > GetParallelTimer ( string name ) {
439+ return ( from timer in ParallelTimers
440+ where timer . Name == name
441+ select timer ) . ToList ( ) ;
442+ }
443+
444+ public void KillParallelTimer ( string name ) {
445+ foreach ( IPTimedEvent timer in GetParallelTimer ( name ) ) {
446+ timer . Kill ( ) ;
447+ ParallelTimers . Remove ( timer ) ;
489448 }
490- return weaponName ;
449+ }
450+
451+ #endregion
452+
453+ public Dictionary < string , object > CreateDict ( ) {
454+ return new Dictionary < string , object > ( ) ;
491455 }
492456 }
493457}
0 commit comments