def work(self, subject, objects=[], **kwargs): battle = kwargs["battle"] if subject != battle.sequence[-1]["action"].subject: return if len(objects) == 0: objects = battle.sequence[-1]["action"].objects sub_loc = battle.map.location(subject) for obj in objects: if battle.event(obj, BattleEvent.ACTMissed) is not None: continue obj_loc = battle.map.location(obj) obj_distance = battle.map.distance(sub_loc, obj_loc) dire = battle.map.direction(sub_loc, obj_loc) obj_tgt = battle.map.neighbour(obj_loc, dire) #print(obj.name, obj_loc, obj_tgt) if not battle.map.on_map(obj_tgt) or not battle.map.can_stay( obj, obj_tgt): continue current_distance = battle.map.distance(obj_tgt, sub_loc) if obj_tgt != obj_loc and current_distance > obj_distance: BattleMoveAction(showmsg=False, active=False, battle=battle, subject=obj, target=obj_tgt, path=[obj_tgt, obj_loc]).do() MSG(style=MSG.Effect, subject=subject, effect=self, details={"object": obj.name})
def work(self, subject, objects=[], **kwargs): battle = kwargs["battle"] if subject != battle.sequence[-1]["action"].subject: return if len(objects) == 0: objects = battle.sequence[-1]["action"].objects sub_loc = battle.map.location(subject) if battle.sequence[-1]["action"].skill.shape.style == Shape.Point: skill_tgt = battle.sequence[-1]["action"].target else: mid_points = [] tgt_distances = [] for obj in objects: mid_points.append(battle.map.location(obj)) tgt_distances.append( battle.map.distance(sub_loc, mid_points[-1])) skill_tgt = battle.map.center_point(mid_points) tgt_dire = battle.map.direction(sub_loc, skill_tgt) min_sub_distance = 99 min_obj_distance = 99 sub_tgt = sub_loc sub_dire = 2 for i in range(min(sub_loc[0], skill_tgt[0]), max(sub_loc[0], skill_tgt[0]) + 1): for j in range(min(sub_loc[1], skill_tgt[1]), max(sub_loc[1], skill_tgt[1]) + 1): pt = (i, j) if pt == sub_loc: continue if not battle.map.can_stay(subject, pt): continue pt_dire = abs(tgt_dire - battle.map.direction(sub_loc, pt)) pt_dire = 6 - pt_dire if pt_dire > 3 else pt_dire sub_distance = battle.map.distance(sub_loc, pt) obj_distance = battle.map.distance(skill_tgt, pt) if obj_distance > min_obj_distance: continue if obj_distance == min_obj_distance and \ sub_distance > min_sub_distance: continue if obj_distance == min_obj_distance and \ sub_distance == min_sub_distance and \ pt_dire >= sub_dire: continue min_obj_distance = obj_distance min_sub_distance = sub_distance sub_tgt = pt sub_dire = pt_dire if sub_tgt != sub_loc: battle.moved[subject.id] = False BattleMoveAction(showmsg=False, active=False, battle=battle, subject=subject, target=sub_tgt, path=[sub_tgt, sub_loc]).do() MSG(style=MSG.Effect, subject=subject, effect=self, details={"subject": subject.name})
def move(self, arg): position_text = "请输入要移动的地块坐标" p = self.battle.current allinscope, connections = self.battle.map.move_scope(p) validator = lambda x: PositionSelectControl.validator( self.battle.map, x, allinscope, False) control = BattlePositionSelectControl(battle=self.battle, subject=self.battle.current, validator=validator, positions=allinscope, text=position_text) control.run() if control.target is not None: map = self.battle.map self.location = map.location(p) move_trace = map.move_trace(self.position, self.location, connections) BattleMoveAction(subject=p, battle=self.battle, target=control.target, scope=allinscope, path=move_trace).do() self.battle.reset = True if self.battle.active(): self.launch() else: self.close()
def work(self, subject, objects=[], **kwargs): battle = kwargs["battle"] if subject != battle.sequence[-1]["action"].subject: return if len(objects) == 0: objects = battle.sequence[-1]["action"].objects sub_loc = battle.map.location(subject) if battle.sequence[-1]["action"].skill.shape.style == Shape.Point: skill_tgt = battle.sequence[-1]["action"].target tgt_distance = battle.map.distance(sub_loc, skill_tgt) else: mid_points = [] tgt_distances = [] for obj in objects: mid_points.append(battle.map.location(obj)) tgt_distances.append( battle.map.distance(sub_loc, mid_points[-1])) skill_tgt = battle.map.center_point(mid_points) tgt_distance = min(tgt_distances) obj_dire = battle.map.direction(sub_loc, skill_tgt) sub_tgt = sub_loc max_obj_distance = 0 sub_dire = None x_range, y_range = self.xy_range(battle.map, sub_loc, skill_tgt, tgt_distance) for i in x_range: for j in y_range: pt = (i, j) if pt == sub_loc: continue if not battle.map.can_stay(subject, pt): continue sub_distance = battle.map.distance(pt, sub_loc) obj_distance = battle.map.distance(pt, skill_tgt) pt_dire = abs(obj_dire - battle.map.direction(pt, skill_tgt)) pt_dire = pt_dire + 6 if pt_dire < 0 else pt_dire #print(pt, obj_distance, pt_dire, max_obj_distance, sub_dire) if sub_distance > tgt_distance: continue if obj_distance < max_obj_distance: continue if obj_distance == max_obj_distance and pt_dire >= sub_dire: continue max_obj_distance = obj_distance sub_dire = pt_dire sub_tgt = pt if sub_tgt != sub_loc: battle.moved[subject.id] = False BattleMoveAction(showmsg=False, active=False, battle=battle, subject=subject, target=sub_tgt, path=[sub_tgt, sub_loc]).do() MSG(style=MSG.Effect, subject=subject, effect=self, details={"subject": subject.name})
def work(self, subject, objects=[], **kwargs): battle = kwargs["battle"] if subject != battle.sequence[-1]["action"].subject: return if len(objects) == 0: objects = battle.sequence[-1]["action"].objects obj_loc = battle.sequence[-1]["action"].target obj = battle.map.loc_entity.get(obj_loc, None) if obj is None: return suj_loc = battle.map.location(subject) battle.map.remove(subject) battle.map.remove(obj) if not battle.map.can_stay( subject, obj_loc) or not battle.map.can_stay(obj, suj_loc): battle.map.locate(subject, suj_loc) battle.map.locate(obj, obj_loc) return battle.map.locate(subject, obj_loc) battle.map.locate(obj, suj_loc) battle.moved[subject.id] = False BattleMoveAction(active=False, showmsg=False, battle=battle, subject=subject, target=obj_loc, path=[obj_loc, suj_loc]).do() BattleMoveAction(active=False, showmsg=False, battle=battle, subject=obj, target=suj_loc, path=[suj_loc, obj_loc]).do() if not battle.silent: MSG(style=MSG.Effect, subject=subject, effect=self, details={ "subject": subject.name, "object": obj.name })
def work(self, subject, objects=[], **kwargs): battle = kwargs["battle"] if subject != battle.current: return pool = [] for i in range(battle.map.x): for j in range(battle.map.y): #if (i, j) not in battle.map.loc_entity and \ if battle.map.can_stay(subject, (i, j)): pool.append((i, j)) pos = random.sample(pool, 1)[0] if not battle.silent: MSG(style=MSG.Effect, subject=subject, effect=self, details={"pos": pos}) BattleMoveAction(motivated=False, battle=battle, subject=subject, target=pos, path=[pos, battle.map.location(subject)]).do() battle.moved[subject.id] = True
def work(self, subject, objects=[], **kwargs): battle = kwargs["battle"] if subject != battle.sequence[-1]["action"].subject: return if len(objects) == 0: objects = battle.sequence[-1]["action"].objects obj_loc = battle.sequence[-1]["action"].target obj = battle.map.loc_entity.get(obj_loc, None) if obj is None: return suj_loc = battle.map.location(subject) #old_dire = battle.map.direction(suj_loc, obj_loc) old_dire = (obj.direction + 3) % 6 tmp_locs = [] for pt in battle.map.circle(obj_loc, 1): if not battle.map.is_on_map(pt) or not battle.map.can_stay( subject, pt): continue new_dire = battle.map.direction(obj_loc, pt) dire_diff = abs(new_dire - old_dire) tmp_locs.append((pt, 1 if dire_diff == 5 else dire_diff)) tmp_locs.sort(key=lambda x: x[1]) target = tmp_locs[0][0] battle.moved[subject.id] = False BattleMoveAction(showmsg=False, active=False, battle=battle, subject=subject, target=target, path=[target, suj_loc]).do() #battle.redirect(subject, [obj], obj_loc, battle.sequence[-1]["action"].skill) if not battle.silent: MSG(style=MSG.Effect, subject=subject, effect=self, details={ "subject": subject.name, "object": obj.name })