100 lines
2.8 KiB
Python
100 lines
2.8 KiB
Python
#gameevents.py
|
|
|
|
# Experimental: events are ordered in the order that they were created,
|
|
# to resolve issues where two events happen at the same time.
|
|
_eventNum = 0
|
|
|
|
def resetEventNum():
|
|
global _eventNum
|
|
_eventNum = 0
|
|
|
|
class GameEvent(object):
|
|
|
|
def __init__(self, eventType: str):
|
|
global _eventNum
|
|
self.eventType = eventType
|
|
# Experimental, also NOT THREAD SAFE!
|
|
self.eventNum = _eventNum
|
|
_eventNum += 1
|
|
|
|
def __str__(self):
|
|
return "{0} ({1})".format(self.eventType, self.eventNum)
|
|
|
|
def __eq__(self, other):
|
|
if isinstance(other, GameEvent):
|
|
return self.eventNum == other.eventNum
|
|
else:
|
|
return self.eventNum == other
|
|
|
|
def __ne__(self, other):
|
|
if isinstance(other, GameEvent):
|
|
return self.eventNum != other.eventNum
|
|
else:
|
|
return self.eventNum != other
|
|
|
|
def __lt__(self, other):
|
|
if isinstance(other, GameEvent):
|
|
return self.eventNum < other.eventNum
|
|
else:
|
|
return self.eventNum < other
|
|
|
|
def __le__(self, other):
|
|
if isinstance(other, GameEvent):
|
|
return self.eventNum <= other.eventNum
|
|
else:
|
|
return self.eventNum <= other
|
|
|
|
def __gt__(self, other):
|
|
if isinstance(other, GameEvent):
|
|
return self.eventNum > other.eventNum
|
|
else:
|
|
return self.eventNum > other
|
|
|
|
def __ge__(self, other):
|
|
if isinstance(other, GameEvent):
|
|
return self.eventNum >= other.eventNum
|
|
else:
|
|
return self.eventNum >= other
|
|
|
|
class NoOpEvent(GameEvent):
|
|
|
|
def __init__(self):
|
|
super(NoOpEvent, self).__init__('noop')
|
|
|
|
class GoEvent(GameEvent):
|
|
|
|
def __init__(self, actor, x, y):
|
|
super(GoEvent, self).__init__('go')
|
|
self.actor = actor
|
|
self.x = x
|
|
self.y = y
|
|
|
|
class ArriveEvent(GameEvent):
|
|
|
|
def __init__(self, actor, x, y, t):
|
|
super(ArriveEvent, self).__init__('arrive')
|
|
self.actor = actor
|
|
self.x = x
|
|
self.y = y
|
|
self.t = t
|
|
|
|
class UseEvent(GameEvent):
|
|
def __init__(self, thing):
|
|
super(UseEvent, self).__init__('use')
|
|
self.thing = thing
|
|
|
|
class UseOnEvent(GameEvent):
|
|
def __init__(self, item, thing):
|
|
super(UseOnEvent, self).__init__('useon')
|
|
self.thing = thing # thing can be a coordinate pair?
|
|
self.item = item
|
|
|
|
class TakeEvent(GameEvent):
|
|
def __init__(self, item):
|
|
super(TakeEvent, self).__init__('take')
|
|
self.item = item
|
|
|
|
class DropEvent(GameEvent):
|
|
def __init__(self, item):
|
|
super(DropEvent, self).__init__('drop')
|
|
self.item = item
|