def getClosestInstance(_type, is_unblocked=True): """ Get the VID of the closest matching one of the types specified instance from the main player. Args: _type ([list]): A list of VID types. is_unblocked (bool, optional): If True it will ignore instance in walls. Defaults to True. Returns: [int]: Returns the VID of the closest instance. """ (closest_vid, _dist) = (-1, 999999999) for vid in net_packet.InstancesList: if not chr.HasInstance(vid): continue if is_unblocked: mob_x, mob_y, mob_z = chr.GetPixelPosition(vid) if net_packet.IsPositionBlocked(mob_x, mob_y): continue this_distance = player.GetCharacterDistance(vid) if net_packet.IsDead(vid): continue type = chr.GetInstanceType(vid) if type in _type or (BOSS_TYPE in type and isBoss(vid)): if this_distance < _dist and not isPlayerCloseToInstance(vid): _dist = this_distance closest_vid = vid return closest_vid
def FollowTarget_1(self): x,y = chr.GetPixelPosition(TargetVid)[:2] chr.MoveToDestPosition(player.GetMainCharacterIndex(),int(x),int(y)) self.UpdateFollow = OpenLib.WaitingDialog() self.UpdateFollow.Open(1.0) self.UpdateFollow.SAFE_SetTimeOverEvent(self.FollowTarget_1)
def OnUpdate(self): if not self.vid: return if systemSetting.IsShowSalesText(): if GetShopNamesRange() == 1.000: self.Show() (x, y) = chr.GetProjectPosition(self.vid, 220) self.SetPosition(x - self.GetWidth() / 2, y - self.GetHeight() / 2) else: LIMIT_RANGE = abs(constInfo.SHOPNAMES_RANGE * GetShopNamesRange()) (to_x, to_y, to_z) = chr.GetPixelPosition(self.vid) (my_x, my_y, my_z) = player.GetMainCharacterPosition() if abs(my_x - to_x) <= LIMIT_RANGE and abs( my_y - to_y) <= LIMIT_RANGE: (x, y) = chr.GetProjectPosition(self.vid, 220) self.SetPosition(x - self.GetWidth() / 2, y - self.GetHeight() / 2) self.Show() else: self.Hide() self.SetPosition(-10000, 0) else: for key in g_privateShopAdvertisementBoardDict.keys(): if player.GetMainCharacterIndex() == key: g_privateShopAdvertisementBoardDict[key].Show() x, y = chr.GetProjectPosition( player.GetMainCharacterIndex(), 220) g_privateShopAdvertisementBoardDict[key].SetPosition( x - self.GetWidth() / 2, y - self.GetHeight() / 2) else: g_privateShopAdvertisementBoardDict[key].Hide()
def GetNextMonster(self): (closest_vid, _dist) = (0, 999999999) my_pos = player.GetMainCharacterPosition() for vid in net_packet.InstancesList: if not chr.HasInstance(vid): continue if net_packet.IsDead(vid): continue _type = chr.GetInstanceType(vid) monst_pos = chr.GetPixelPosition(vid) if self.ignoreBlockedPosition and net_packet.IsPositionBlocked( monst_pos[0], monst_pos[1]): continue if _type != OpenLib.MONSTER_TYPE: continue if OpenLib.dist(self.startPosition[0], self.startPosition[1], monst_pos[0], monst_pos[1]) > self.Range: continue this_dist = OpenLib.dist(my_pos[0], my_pos[1], monst_pos[0], monst_pos[1]) if this_dist < _dist: _dist = this_dist closest_vid = vid return closest_vid
def AttackArch(self,lst,x,y): vid_hits = 0 #chat.AppendChat(3,"Attacking with arch") for enemy in lst: x,y,z = chr.GetPixelPosition(enemy) net_packet.SendAddFlyTarget(enemy,x,y) net_packet.SendShoot(net_packet.COMBO_SKILL_ARCH) lst.remove(enemy) vid_hits+=1 return vid_hits
def BuyItemDirectly(self, item): vid = item.shop slot = item.slot x, y, z = player.GetMainCharacterPosition() dst_x, dst_y, dst_z = chr.GetPixelPosition(vid) if (dst_x + dst_y < 0.000001): return Movement.TeleportStraightLine(x, y, dst_x, dst_y) net.SendOnClickPacket(vid) net.SendShopBuyPacket(slot) Movement.TeleportStraightLine(dst_x, dst_y, x, y) net.SendShopEndPacket()
def OnUpdate(self): val, self.lastTime = OpenLib.timeSleep(self.lastTime,self.speed) if(val and self.enableButton.isOn and not self.pause): if OpenLib.GetCurrentPhase() != OpenLib.PHASE_GAME: return isArch = self.IsWeaponArch() main_vid = net.GetMainActorVID() x,y,z = chr.GetPixelPosition(main_vid) self.lastPos = (x,y) lst = list() chat.AppendChat(3,str(len(net_packet.InstancesList))) for vid in net_packet.InstancesList: if vid == main_vid: continue if not chr.HasInstance(vid): continue if self.playerClose.isOn and chr.GetInstanceType(vid) == OpenLib.PLAYER_TYPE and vid != net.GetMainActorVID(): return if self.MetinButton.isOn and chr.GetInstanceType(vid) != OpenLib.METIN_TYPE: continue if player.GetCharacterDistance(vid) < self.range and not net_packet.IsDead(vid): lst.append(vid) hit_counter = 0 i = 0 while len(lst) > 0 and hit_counter < self.maxMonster: vid = lst[0] mob_x, mob_y, mob_z = chr.GetPixelPosition(vid) if net_packet.IsPositionBlocked(mob_x,mob_y): lst.remove(vid) continue #Checking the distance between teleports might increase the range and make it more stable if isArch: hit_counter+=self.AttackArch(lst,mob_x, mob_y) else: hit_counter+=self.TeleportAttack(lst,mob_x, mob_y) i+=1 Movement.TeleportStraightLine(self.lastPos[0],self.lastPos[1],x,y)
def isPlayerCloseToInstance(vid_target): """ Check if an instance is close to another instance. Args: vid_target ([type]): [description] Returns: [type]: [description] """ my_vid = net.GetMainActorVID() target_x, target_y, zz = chr.GetPixelPosition(vid_target) for vid in net_packet.InstancesList: if not chr.HasInstance(vid): continue if chr.GetInstanceType(vid) == PLAYER_TYPE and vid != my_vid: curr_x, curr_y, z = chr.GetPixelPosition(vid) distance = dist(target_x, target_y, curr_x, curr_y) if (distance < 300): return True return False
def TeleportAttack(self,lst,x,y): Movement.TeleportStraightLine(self.lastPos[0],self.lastPos[1],x,y) self.lastPos = (x,y) net_packet.SendStatePacket(x,y,0,net_packet.CHAR_STATE_STOP,0) vid_hits = 0 for vid in lst: mob_x, mob_y, mob_z = chr.GetPixelPosition(vid) if OpenLib.dist(x,y,mob_x,mob_y) < ATTACK_MAX_DIST_NO_TELEPORT: #chat.AppendChat(3,"Sent Attack, X:" + str(mob_x) + " Y:" + str(mob_y) + "VID: " +str(vid)) net_packet.SendAttackPacket(vid,0) lst.remove(vid) vid_hits+=1 return vid_hits
def AttackTarget(vid): """ Attack the instance vid. If the player is not in range, it will start an action to move to the target. Args: vid ([int]): The target VID. Returns: [int]: If the target is dead returns TARGET_IS_DEAD, if is attacking the target returns ATTACKING_TARGET else returns MOVING_TO_TARGET """ if net_packet.IsDead(vid): return TARGET_IS_DEAD mob_x, mob_y, mob_z = chr.GetPixelPosition(vid) if player.GetCharacterDistance(vid) < ATTACK_RANGE: Movement.StopMovement() RotateMainCharacter(mob_x, mob_y) player.SetAttackKeyState(True) return ATTACKING_TARGET else: player.SetAttackKeyState(False) Movement.GoToPositionAvoidingObjects(mob_x, mob_y) return MOVING_TO_TARGET
def MoveSelectedShop(self): itemList = self.ListBoxItems.GetSelectedItem() if itemList: item = itemList.GetText() x, y, z = chr.GetPixelPosition(item.shop) chr.MoveToDestPosition(player.GetMainCharacterIndex(), x, y)