def __init__(self,player, messages, enable=True, name="", panel_location=None): super().__init__() self._messages = messages self._triggers = None self._enable = enable self._name = name self._triggers = [] self.panel_location = panel_location self.player = player # for player in self._players: p_triggers = [] for i in range(len(self._messages)): message, camera, duration,color = self._messages[i] if color is None: color = Color.WHITE t = Trigger(enable=False, name="{} {}th instruction".format(self._name, i)) if i > 0: _, _, duration_previous_message,_ = self._messages[i - 1] t.if_(Timer(duration_previous_message)) if camera is not None: x, y = camera t.then_(MoveCamera(self.player, x, y)) t.then_(SendInstruction(message=message, time=duration, panel_location=self.panel_location,player=self.player,color=color)) p_triggers.append(t) for i in range(len(p_triggers) - 1): p_triggers[i].then_(ActivateTrigger(p_triggers[i + 1])) p_triggers[0].enable = self._enable self._triggers.extend(p_triggers)
def create_win_area(x, y, sep=4, team=None): for unit_constant in [UnitConstant.FLAG_A.value]: uns = [ scn.units.new(owner=team.players[0].id, x=x, y=y, unit_cons=unit_constant), scn.units.new(owner=team.players[1].id, x=x + sep, y=y + sep, unit_cons=unit_constant), scn.units.new(owner=team.players[2].id, x=x, y=y + sep, unit_cons=unit_constant), scn.units.new(owner=team.players[3].id, x=x + sep, y=y, unit_cons=unit_constant) ] for unit_constant in [UnitConstant.KING.value]: uns = [ scn.units.new(owner=team.players[0].id, x=x + 1, y=y + 1, unit_cons=unit_constant), scn.units.new(owner=team.players[1].id, x=x + sep - 1, y=y + sep - 1, unit_cons=unit_constant), scn.units.new(owner=team.players[2].id, x=x + 1, y=y + sep - 1, unit_cons=unit_constant), scn.units.new(owner=team.players[3].id, x=x + sep - 1, y=y + 1, unit_cons=unit_constant) ] for tile in scn.map.tiles.getArea(x, y, x + sep - 1, y + sep - 1): tile.type = EnumTile.ROCK.value for player in range(1, 9): scn.units.new(owner=player, x=x + int(sep / 2), y=y + int(sep / 2), unit_cons=UnitConstant.MAP_REVEAL.value) for ir, relic in enumerate(relics): create_flag_score = Trigger( "create_flag_score for relic {} ({})".format(ir, team.name), enable=True) remove_flag_score = Trigger( "remove_flag_score for relic {} ({})".format(ir, team.name)) create_flag_score.if_( UnitInArea(player=0, unit=relic, x1=x, x2=x + sep - 1, y1=y, y2=y + sep - 1)) create_flag_score.then_( CreateObject(player=0, x=x + int(sep / 2), y=y + int(sep / 2) - 1 + ir, unit_cons=UnitConstant.FLAG_B.value)) create_flag_score.then_( SendInstruction("{} captured a relic !".format(team.name))) create_flag_score.then_(ActivateTrigger(remove_flag_score)) scn.add(create_flag_score) remove_flag_score.if_( Not( UnitInArea(player=0, unit=relic, x1=x, x2=x + sep - 1, y1=y, y2=y + sep - 1))) remove_flag_score.then_( RemoveObjectByConstant(player=0, x1=x + int(sep / 2), y1=y + int(sep / 2) - 1 + ir, x2=x + int(sep / 2), y2=y + int(sep / 2) - 1 + ir, unit_cons=UnitConstant.FLAG_B.value)) remove_flag_score.then_(ActivateTrigger(create_flag_score)) remove_flag_score.then_( SendInstruction("{} lost a relic !".format(team.name))) scn.add(remove_flag_score) team.x1_win = x team.y1_win = y team.x2_win = x + sep team.y2_win = y + sep
sep=sep_win_area, team=team1) create_win_area(x=scn.get_width() - position_win_area - sep_win_area, y=int(scn.get_height() / 2 - sep_win_area / 2), sep=sep_win_area, team=team2) for team in [team1, team2]: for p in team.players: x, y = team.x1_win + int(sep_win_area / 2), team.y1_win + int( sep_win_area / 2) for ir, relic in enumerate(relics): t = Trigger("move relics {} (P{})".format(ir, p.id), enable=True, loop=True) t.if_(CaptureUnit(player=p.id, unit=relic)) t.then_( MoveObjectToPoint(player=p.id, unit=relic, x=x, y=y - 1 + ir)) scn.add(t) reset_relics = Trigger("reset relics") for ir, relic in enumerate(relics): reset_relics.then_( ChangeOwnershipByUnit(source_player=0, target_player=0, unit=relic)) reset_relics.then_( MoveObjectToPoint(player=0, unit=relic, x=relic.reset_position[0], y=relic.reset_position[1]))