Guest User

Untitled

a guest
Apr 21st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. # This file is part of Merlin.
  2. # Merlin is the Copyright (C)2008-2009 of Robin K. Hansen, Elliot Rosemarine, Andreas Jacobsen.
  3.  
  4. # Individual portions may be copyright by individual contributors, and
  5. # are included in this collective work with permission of the copyright
  6. # owners.
  7.  
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12.  
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17.  
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, write to the Free Software
  20. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21.  
  22. from Core.db import session
  23. from Core.maps import Galaxy, Planet, Alliance, Intel
  24. from Core.loadable import loadable
  25.  
  26. options = ['alliance', 'nick', 'fakenick', 'defwhore', 'covop', 'scanner', 'dists', 'bg', 'gov', 'relay', 'reportchan', 'comment']
  27.  
  28. @loadable.module("half")
  29. class intel(loadable):
  30. """View or set intel for a planet. Valid options: """
  31. __doc__ += ", ".join(options)
  32. usage = " x.y[.z] [option=value]+"
  33. paramre = loadable.coordre
  34.  
  35. def execute(self, message, user, params):
  36.  
  37. if params.group(3) is None:
  38. galaxy = Galaxy.load(*params.group(1,2))
  39. if galaxy is None:
  40. message.alert("No galaxy with coords %s:%s" % params.group(1,2))
  41. return
  42. prev = []
  43. for planet in galaxy.planets:
  44. if planet.intel is not None:
  45. reply = "#%s"%(planet.z,)
  46. if planet.intel.nick:
  47. reply += " %s"%(planet.intel.nick,)
  48. if planet.alliance:
  49. reply += " [%s]"%(planet.alliance.name[:3],)
  50. prev.append(reply)
  51. if len(prev):
  52. reply ="Intel %d:%d - "%(galaxy.x,galaxy.y,)
  53. reply+="Score (%d) Value (%d) Size (%d)"%(galaxy.score_rank,galaxy.value_rank,galaxy.size_rank)
  54. reply+=" - "
  55. reply+=" - ".join(prev)
  56. message.reply(reply)
  57. else:
  58. message.reply("No information stored for %s:%s" % (galaxy.x, galaxy.y,))
  59. return
  60.  
  61. planet = Planet.load(*params.group(1,2,3))
  62. if planet is None:
  63. message.alert("No planet with coords %s:%s:%s" % params.group(1,2,3))
  64. return
  65.  
  66. if planet.intel is None:
  67. planet.intel = Intel()
  68.  
  69. if user.is_member():
  70.  
  71. params = self.split_opts(message.get_msg())
  72. for opt, val in params.items():
  73. if opt == "alliance":
  74. if val in self.nulls:
  75. planet.intel.alliance = None
  76. continue
  77. alliance = Alliance.load(val)
  78. if alliance is None:
  79. message.alert("No alliances match %s" % (val,))
  80. continue
  81. planet.intel.alliance = alliance
  82. if (opt in options) and (val in self.nulls):
  83. setattr(planet.intel, opt, None)
  84. continue
  85. if opt in ("nick","fakenick","bg","gov","reportchan"):
  86. setattr(planet.intel, opt, val)
  87. if opt in ("defwhore","covop","scanner","relay"):
  88. if val in self.true:
  89. setattr(planet.intel, opt, True)
  90. if val in self.false:
  91. setattr(planet.intel, opt, False)
  92. if opt == "dists":
  93. try:
  94. planet.intel.dists = int(val)
  95. except ValueError:
  96. pass
  97. if opt == "comment":
  98. planet.intel.comment = message.get_msg().split("comment=")[1]
  99. session.commit()
  100. message.reply(("Information stored for %s:%s:%s -"+str(planet.intel) if str(planet.intel) else "No information stored for %s:%s:%s") % (planet.x, planet.y, planet.z,))
Add Comment
Please, Sign In to add comment