Example #1
0
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 OnUpdate(self):
        if self.isShowButton:

            exchangeButton = self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE]
            distance = player.GetCharacterDistance(self.vid)

            if distance < 0:
                return

            diceButton = self.buttonDict[localeInfo.TARGET_BUTTON_DICE]
            if diceButton.IsShow():
                if distance > self.DICE_LIMIT_RANGE:
                    self.RefreshButton()

            else:
                if distance < self.DICE_LIMIT_RANGE:
                    self.RefreshButton()

            if exchangeButton.IsShow():
                if distance > self.EXCHANGE_LIMIT_RANGE:
                    self.RefreshButton()

            else:
                if distance < self.EXCHANGE_LIMIT_RANGE:
                    self.RefreshButton()
Example #3
0
 def SearchVIDClosest(self):
     npcs = dict()
     for vid in net_packet.InstancesList:
         chr.SelectInstance(vid)
         curr_race = chr.GetRace()
         if self.race == curr_race:
             dist = player.GetCharacterDistance(vid)
             npcs[vid] = dist
     if len(npcs) == 0:
         return None
     min_vid = min(npcs.keys(), key=(lambda k: npcs[k]))
     return min_vid
Example #4
0
	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)
Example #5
0
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
Example #6
0
    def OnUpdate(self):
        if player.IsPVPInstance(self.vid):
            if app.GetTime() > self.SaveSecond:
                self.SaveSecond = app.GetTime() + 0.2
                if str(chr.GetNameByVID(self.vid)) != "None":
                    net.SendWhisperPacket(
                        str(self.name.GetText()),
                        "CODE_MESSAGE_OPPONENTS_HP_29305|" +
                        str(player.GetMainCharacterIndex()))
                if constInfo.OPPONENTS_HP[1] != 0:
                    if constInfo.OPPONENTS_HP[0] <= 0:
                        self.SetHP(0)
                    else:
                        self.SetHP(((float(constInfo.OPPONENTS_HP[0]) /
                                     float(constInfo.OPPONENTS_HP[1])) * 100))

                    self.HPText.SetText(
                        "%d/%d" %
                        (constInfo.OPPONENTS_HP[0], constInfo.OPPONENTS_HP[1]))
                    self.HPText.Show()

        else:
            self.HPText.Hide()

        if self.isShowButton:

            exchangeButton = self.buttonDict[localeInfo.TARGET_BUTTON_EXCHANGE]
            distance = player.GetCharacterDistance(self.vid)

            if distance < 0:
                return

            if exchangeButton.IsShow():
                if distance > self.EXCHANGE_LIMIT_RANGE:
                    self.RefreshButton()

            else:
                if distance < self.EXCHANGE_LIMIT_RANGE:
                    self.RefreshButton()
Example #7
0
    def RefreshButton(self):

        self.HideAllButton()

        if chr.INSTANCE_TYPE_BUILDING == chr.GetInstanceType(self.vid):
            #self.__ShowButton(locale.TARGET_BUTTON_BUILDING_DESTROY)
            #self.__ArrangeButtonPosition()
            return

        if player.IsPVPInstance(self.vid) or player.IsObserverMode():
            # PVP_INFO_SIZE_BUG_FIX
            self.SetSize(200 + 7 * self.nameLength, 40)
            self.UpdatePosition()
            # END_OF_PVP_INFO_SIZE_BUG_FIX
            return

        self.ShowDefaultButton()

        if guild.MainPlayerHasAuthority(guild.AUTH_ADD_MEMBER):
            if not guild.IsMemberByName(self.nameString):
                if 0 == chr.GetGuildID(self.vid):
                    self.__ShowButton(locale.TARGET_BUTTON_INVITE_GUILD)

        if not messenger.IsFriendByName(self.nameString):
            self.__ShowButton(locale.TARGET_BUTTON_FRIEND)

        if player.IsPartyMember(self.vid):

            self.__HideButton(locale.TARGET_BUTTON_FIGHT)

            if player.IsPartyLeader(self.vid):
                self.__ShowButton(locale.TARGET_BUTTON_LEAVE_PARTY)
            elif player.IsPartyLeader(player.GetMainCharacterIndex()):
                self.__ShowButton(locale.TARGET_BUTTON_EXCLUDE)

        else:
            if player.IsPartyMember(player.GetMainCharacterIndex()):
                if player.IsPartyLeader(player.GetMainCharacterIndex()):
                    self.__ShowButton(locale.TARGET_BUTTON_INVITE_PARTY)
            else:
                if chr.IsPartyMember(self.vid):
                    self.__ShowButton(locale.TARGET_BUTTON_REQUEST_ENTER_PARTY)
                else:
                    self.__ShowButton(locale.TARGET_BUTTON_INVITE_PARTY)

            if player.IsRevengeInstance(self.vid):
                self.__HideButton(locale.TARGET_BUTTON_FIGHT)
                self.__ShowButton(locale.TARGET_BUTTON_AVENGE)
            elif player.IsChallengeInstance(self.vid):
                self.__HideButton(locale.TARGET_BUTTON_FIGHT)
                self.__ShowButton(locale.TARGET_BUTTON_ACCEPT_FIGHT)
            elif player.IsCantFightInstance(self.vid):
                self.__HideButton(locale.TARGET_BUTTON_FIGHT)

            if not player.IsSameEmpire(self.vid):
                self.__HideButton(locale.TARGET_BUTTON_INVITE_PARTY)
                self.__HideButton(locale.TARGET_BUTTON_FRIEND)
                self.__HideButton(locale.TARGET_BUTTON_FIGHT)

        distance = player.GetCharacterDistance(self.vid)
        if distance > self.EXCHANGE_LIMIT_RANGE:
            self.__HideButton(locale.TARGET_BUTTON_EXCHANGE)
            self.__ArrangeButtonPosition()

        self.__ArrangeButtonPosition()