def if_in_area(self, robot: Robot): if robot.group == "red": supply_area = self.supply_area_red elif robot.group == "blue": supply_area = self.supply_area_blue else: print("Wrong Input Object in supply area!") return False pos = robot.get_pos() x, y = pos.x, pos.y bx, by, w, h = supply_area return (bx <= x <= bx + w) and (by <= y <= by + h)
def detect(self, robot: Robot, t_now): # 0, 1, 2min refresh if (int(t_now) % 60 == 0): self.__activated = False self.__t_stay = 0 if self.__activated: return if robot.group != self.__group: return if self._if_in_area(robot.get_pos(), self.__box): self.__t_stay += t_now - self.__t_last if self.__t_stay >= TIME_BUFF_TRIGGER: self.__activated = True robot.buff_left_time = TIME_BUFF_INIT self.__t_stay = 0 else: self.__t_stay = 0 self.__t_last = t_now
def detect(self, robot: Robot, t_now): # 0, 1, 2min refresh bool_t = (t_now > 3.00 - 0.05 and t_now < 3.00 + 0.05) and (t_now > 120.00 - 0.05 and t_now < 120.00 + 0.05) if (int(t_now) % 60 == 0): # if t_now == 5.00 or t_now == 60.00: # if bool_t: self.__activated = False self.__t_stay = 0 self.__type = choice(TYPE) # print(f'time {t_now}') # print(f"buff type - 2 {self.__type}") if self.__activated: return if robot.group != self.__group and self.__type < 1: return if self._if_in_area(robot.get_pos(), self.__box): self.__t_stay += t_now - self.__t_last if self.__t_stay >= TIME_BUFF_TRIGGER: self.__activated = True if self.__type == 0: robot.lose_health(-1000) return if self.__type == 1: robot.supply() return robot.buff_left_time = PUNISH_TIME robot.buff_type = self.__type self.__t_stay = 0 else: self.__t_stay = 0 self.__t_last = t_now
def _update_robot_state(self, robot: Robot, state: RobotState): state.pos = robot.get_pos() state.health = robot.get_health() state.angle = robot.get_angle() state.velocity = robot.get_velocity() state.angular = robot.get_angular()