1. package CustomObjectIdGenerator
  2. int array id
  3. constant heroPrefix = 'W'
  4. constant nonheroPrefix = '%'
  5. boolean helperActivator = initHelper()
  6. function initHelper() returns boolean
  7. for int i = 0 to 2
  8. id[ i ] = '0'
  9. return true
  10. function nextValid( int c ) returns int
  11. int r = c + 1
  12. if r == '_' or r == ', 'or r == '"'or r == '\' or r == ' - '
  13. r + +
  14. if r == '_' or r == ', 'or r == '"'or r == '\' or r == ' - '
  15. r + +
  16. return r
  17. function fourChar( int a, int b, int c, int d ) returns int
  18. return((((( a * 256 ) + b ) * 256 ) + c ) * 256 ) + d
  19. function newId( int prefix ) returns int
  20. if helperActivator
  21. for i = 0 to 2
  22. if id[ i ] < '~'
  23. id[ i ] = nextValid( id[ i ] )
  24. for j = 0 to i - 1
  25. id[ j ] = '!'
  26. return fourChar( prefix, id[ 2 ], id[ 1 ], id[ 0 ] )
  27. error( "No vaild id left" )
  28. return 0
  29. public function genId() returns int
  30. return newId( nonheroPrefix )
  31. public function genHeroId() returns int
  32. return newId( heroPrefix )

Diesen Code in Original-Formatierung anzeigen
goto line:
Compare with:
text copy window edit this code post new code