Пример #1
0
def __doNPCSOS(sos):
    npcId = sos['npcId']
    (track, level, hp) = NPCToons.getNPCTrackLevelHp(npcId)
    if track != None:
        return NPCSOSfn_dict[track](sos, level, hp)
    else:
        return __cogsMiss(sos, 0, 0)
def __doNPCSOS(sos):
    npcId = sos['npcId']
    track, level, hp = NPCToons.getNPCTrackLevelHp(npcId)
    if track != None:
        return NPCSOSfn_dict[track](sos, level, hp)
    else:
        return __cogsMiss(sos, 0, 0)
Пример #3
0
    def __genToonAttackDicts(self, toons, suits, toonAttacks):
        for ta in toonAttacks:
            targetGone = 0
            track = ta[TOON_TRACK_COL]
            if track != NO_ATTACK:
                adict = {}
                toonIndex = ta[TOON_ID_COL]
                toonId = toons[toonIndex]
                toon = self.battle.findToon(toonId)
                if toon == None:
                    continue
                level = ta[TOON_LVL_COL]
                adict['toon'] = toon
                adict['track'] = track
                adict['level'] = level
                hps = ta[TOON_HP_COL]
                kbbonuses = ta[TOON_KBBONUS_COL]
                if track == NPCSOS:
                    adict['npcId'] = ta[TOON_TGT_COL]
                    toonId = ta[TOON_TGT_COL]
                    track, npc_level, npc_hp = NPCToons.getNPCTrackLevelHp(
                        adict['npcId'])
                    if track == None:
                        track = NPCSOS
                    adict['track'] = track
                    adict['level'] = npc_level
                elif track == PETSOS:
                    petId = ta[TOON_TGT_COL]
                    adict['toonId'] = toonId
                    adict['petId'] = petId
                if track == SOS:
                    targetId = ta[TOON_TGT_COL]
                    if targetId == base.localAvatar.doId:
                        target = base.localAvatar
                        adict['targetType'] = 'callee'
                    elif toon == base.localAvatar:
                        target = base.cr.identifyAvatar(targetId)
                        adict['targetType'] = 'caller'
                    else:
                        target = None
                        adict['targetType'] = 'observer'
                    adict['target'] = target
                elif track == NPCSOS or track == NPC_COGS_MISS or track == NPC_TOONS_HIT or track == NPC_TOONS_MISS or track == NPC_COGS_HIT or track == NPC_RESTOCK_GAGS or track == PETSOS:
                    adict['special'] = 1
                    toonHandles = []
                    for t in toons:
                        if t != -1:
                            target = self.battle.findToon(t)
                            if target == None:
                                continue
                            if track == NPC_TOONS_HIT or track == NPC_TOONS_MISS and t == toonId:
                                continue
                            toonHandles.append(target)

                    adict['toons'] = toonHandles
                    suitHandles = []
                    for s in suits:
                        if s != -1:
                            target = self.battle.findSuit(s)
                            if target == None:
                                continue
                            suitHandles.append(target)

                    adict['suits'] = suitHandles
                    if track == PETSOS:
                        del adict['special']
                        targets = []
                        for t in toons:
                            if t != -1:
                                target = self.battle.findToon(t)
                                if target == None:
                                    continue
                                tdict = {}
                                tdict['toon'] = target
                                tdict['hp'] = hps[toons.index(t)]
                                self.notify.debug(
                                    'PETSOS: toon: %d healed for hp: %d' %
                                    (target.doId, hps[toons.index(t)]))
                                targets.append(tdict)

                        if len(targets) > 0:
                            adict['target'] = targets
                elif track == HEAL:
                    if levelAffectsGroup(HEAL, level):
                        targets = []
                        for t in toons:
                            if t != toonId and t != -1:
                                target = self.battle.findToon(t)
                                if target == None:
                                    continue
                                tdict = {}
                                tdict['toon'] = target
                                tdict['hp'] = hps[toons.index(t)]
                                self.notify.debug(
                                    'HEAL: toon: %d healed for hp: %d' %
                                    (target.doId, hps[toons.index(t)]))
                                targets.append(tdict)

                        if len(targets) > 0:
                            adict['target'] = targets
                        else:
                            targetGone = 1
                    else:
                        targetIndex = ta[TOON_TGT_COL]
                        if targetIndex < 0:
                            targetGone = 1
                        else:
                            targetId = toons[targetIndex]
                            target = self.battle.findToon(targetId)
                            if target != None:
                                tdict = {}
                                tdict['toon'] = target
                                tdict['hp'] = hps[targetIndex]
                                adict['target'] = tdict
                            else:
                                targetGone = 1
                elif attackAffectsGroup(track, level, ta[TOON_TRACK_COL]):
                    targets = []
                    for s in suits:
                        if s != -1:
                            target = self.battle.findSuit(s)
                            if ta[TOON_TRACK_COL] == NPCSOS:
                                if track == LURE and self.battle.isSuitLured(
                                        target) == 1:
                                    continue
                                elif track == TRAP and (
                                        self.battle.isSuitLured(target) == 1
                                        or target.battleTrap != NO_TRAP):
                                    continue
                            targetIndex = suits.index(s)
                            sdict = {}
                            sdict['suit'] = target
                            sdict['hp'] = hps[targetIndex]
                            if ta[TOON_TRACK_COL] == NPCSOS and track == DROP and hps[
                                    targetIndex] == 0:
                                continue
                            sdict['kbbonus'] = kbbonuses[targetIndex]
                            sdict[
                                'died'] = ta[SUIT_DIED_COL] & 1 << targetIndex
                            sdict['revived'] = ta[
                                SUIT_REVIVE_COL] & 1 << targetIndex
                            if sdict['died'] != 0:
                                pass
                            sdict['leftSuits'] = []
                            sdict['rightSuits'] = []
                            targets.append(sdict)

                    adict['target'] = targets
                else:
                    targetIndex = ta[TOON_TGT_COL]
                    if targetIndex < 0:
                        targetGone = 1
                    else:
                        targetId = suits[targetIndex]
                        target = self.battle.findSuit(targetId)
                        sdict = {}
                        sdict['suit'] = target
                        if self.battle.activeSuits.count(target) == 0:
                            targetGone = 1
                            suitIndex = 0
                        else:
                            suitIndex = self.battle.activeSuits.index(target)
                        leftSuits = []
                        for si in xrange(0, suitIndex):
                            asuit = self.battle.activeSuits[si]
                            if self.battle.isSuitLured(asuit) == 0:
                                leftSuits.append(asuit)

                        lenSuits = len(self.battle.activeSuits)
                        rightSuits = []
                        if lenSuits > suitIndex + 1:
                            for si in xrange(suitIndex + 1, lenSuits):
                                asuit = self.battle.activeSuits[si]
                                if self.battle.isSuitLured(asuit) == 0:
                                    rightSuits.append(asuit)

                        sdict['leftSuits'] = leftSuits
                        sdict['rightSuits'] = rightSuits
                        sdict['hp'] = hps[targetIndex]
                        sdict['kbbonus'] = kbbonuses[targetIndex]
                        sdict['died'] = ta[SUIT_DIED_COL] & 1 << targetIndex
                        sdict[
                            'revived'] = ta[SUIT_REVIVE_COL] & 1 << targetIndex
                        if sdict['revived'] != 0:
                            pass
                        if sdict['died'] != 0:
                            pass
                        if track == DROP or track == TRAP:
                            adict['target'] = [sdict]
                        else:
                            adict['target'] = sdict
                adict['hpbonus'] = ta[TOON_HPBONUS_COL]
                adict['sidestep'] = ta[TOON_ACCBONUS_COL]
                if 'npcId' in adict:
                    adict['sidestep'] = 0
                adict['battle'] = self.battle
                adict['playByPlayText'] = self.playByPlayText
                if targetGone == 0:
                    self.toonAttackDicts.append(adict)
                else:
                    self.notify.warning('genToonAttackDicts() - target gone!')

        def compFunc(a, b):
            alevel = a['level']
            blevel = b['level']
            if alevel > blevel:
                return 1
            elif alevel < blevel:
                return -1
            return 0

        self.toonAttackDicts.sort(compFunc)
        return
Пример #4
0
    def __genToonAttackDicts(self, toons, suits, toonAttacks):
        """ Create a list of dictionaries for the
            toon attacks, sorted by increasing level
        """

        assert (self.notify.debug(
            'genToonAttackDicts() - toons: %s suits: %s toon attacks: %s' %
            (toons, suits, toonAttacks)))
        for ta in toonAttacks:
            targetGone = 0
            track = ta[TOON_TRACK_COL]
            if (track != NO_ATTACK):
                adict = {}
                toonIndex = ta[TOON_ID_COL]
                assert (toonIndex < len(toons))
                toonId = toons[toonIndex]
                assert (toonId != -1)
                toon = self.battle.findToon(toonId)
                if (toon == None):
                    continue
                level = ta[TOON_LVL_COL]
                adict['toon'] = toon
                adict['track'] = track
                adict['level'] = level
                hps = ta[TOON_HP_COL]
                kbbonuses = ta[TOON_KBBONUS_COL]
                # If it's an NPCSOS with a normal toon attack, do some
                # extra prep work first
                if (track == NPCSOS):
                    # This will indicate attack was NPCSOS after we change
                    # the track
                    adict['npcId'] = ta[TOON_TGT_COL]
                    toonId = ta[TOON_TGT_COL]
                    track, npc_level, npc_hp = NPCToons.getNPCTrackLevelHp(
                        adict['npcId'])
                    if (track == None):
                        track = NPCSOS
                    adict['track'] = track
                    adict['level'] = npc_level
                elif (track == PETSOS):
                    petId = ta[TOON_TGT_COL]
                    adict['toonId'] = toonId
                    adict['petId'] = petId
                if (track == SOS):
                    # For an SOS, the target is a toonHandle to a friend
                    targetId = ta[TOON_TGT_COL]
                    assert (targetId != -1)
                    # We can only show the name of the toon being called
                    # to the toon calling for help and the toon being called
                    if (targetId == base.localAvatar.doId):
                        target = base.localAvatar
                        adict['targetType'] = 'callee'
                    elif (toon == base.localAvatar):
                        target = base.cr.identifyAvatar(targetId)
                        assert (target != None)
                        adict['targetType'] = 'caller'
                    else:
                        target = None
                        adict['targetType'] = 'observer'
                    adict['target'] = target
                elif (track == NPCSOS or track == NPC_COGS_MISS
                      or track == NPC_TOONS_HIT or track == NPC_RESTOCK_GAGS
                      or track == PETSOS):
                    adict['special'] = 1
                    toonHandles = []
                    for t in toons:
                        if (t != -1):
                            target = self.battle.findToon(t)
                            if (target == None):
                                continue
                            # NPC_TOONS_HIT is like Heal - it only works
                            # on other toons
                            if (track == NPC_TOONS_HIT and t == toonId):
                                continue
                            toonHandles.append(target)
                    adict['toons'] = toonHandles
                    suitHandles = []
                    for s in suits:
                        if (s != -1):
                            target = self.battle.findSuit(s)
                            if (target == None):
                                continue
                            suitHandles.append(target)
                    adict['suits'] = suitHandles
                    if (track == PETSOS):
                        del adict['special']
                        targets = []
                        for t in toons:
                            if (t != -1):
                                target = self.battle.findToon(t)
                                if (target == None):
                                    continue
                                tdict = {}
                                tdict['toon'] = target
                                assert (toons.index(t) < len(hps))
                                tdict['hp'] = hps[toons.index(t)]
                                self.notify.debug(
                                    "PETSOS: toon: %d healed for hp: %d" %
                                    (target.doId, hps[toons.index(t)]))
                                targets.append(tdict)
                        if (len(targets) > 0):
                            adict['target'] = targets
                elif (track == HEAL):
                    # Odd level heals affect all toons (except the caster)
                    if (levelAffectsGroup(HEAL, level)):
                        targets = []
                        for t in toons:
                            if (t != toonId and t != -1):
                                target = self.battle.findToon(t)
                                if (target == None):
                                    continue
                                tdict = {}
                                tdict['toon'] = target
                                assert (toons.index(t) < len(hps))
                                tdict['hp'] = hps[toons.index(t)]
                                self.notify.debug(
                                    "HEAL: toon: %d healed for hp: %d" %
                                    (target.doId, hps[toons.index(t)]))
                                targets.append(tdict)
                        if (len(targets) > 0):
                            adict['target'] = targets
                        else:
                            targetGone = 1
                            #import pdb; pdb.set_trace()
                    else:
                        targetIndex = ta[TOON_TGT_COL]
                        if targetIndex < 0:
                            targetGone = 1
                        else:
                            assert (targetIndex < len(toons))
                            targetId = toons[targetIndex]
                            assert (targetId != -1)
                            target = self.battle.findToon(targetId)
                            if (target != None):
                                tdict = {}
                                tdict['toon'] = target
                                assert (targetIndex < len(hps))
                                tdict['hp'] = hps[targetIndex]
                                adict['target'] = tdict
                            else:
                                targetGone = 1
                                #import pdb; pdb.set_trace()
                else:
                    # Odd level lures affect all suits
                    # Sounds affect all suits
                    # NPC drops and traps affect all suits
                    if (attackAffectsGroup(track, level, ta[TOON_TRACK_COL])):
                        targets = []
                        for s in suits:
                            if (s != -1):
                                target = self.battle.findSuit(s)
                                assert (target != None)
                                if (ta[TOON_TRACK_COL] == NPCSOS):
                                    if (track == LURE
                                            and self.battle.isSuitLured(target)
                                            == 1):
                                        continue
                                    elif (track == TRAP and
                                          (self.battle.isSuitLured(target) == 1
                                           or target.battleTrap != NO_TRAP)):
                                        continue
                                targetIndex = suits.index(s)
                                sdict = {}
                                sdict['suit'] = target
                                assert (targetIndex < len(hps))
                                sdict['hp'] = hps[targetIndex]
                                if (ta[TOON_TRACK_COL] == NPCSOS
                                        and track == DROP
                                        and hps[targetIndex] == 0):
                                    continue
                                sdict['kbbonus'] = kbbonuses[targetIndex]
                                sdict['died'] = ta[SUIT_DIED_COL] & \
                                                (1<<targetIndex)
                                sdict['revived'] = ta[SUIT_REVIVE_COL] & (
                                    1 << targetIndex)
                                if (sdict['died'] != 0):
                                    assert (self.notify.debug('suit: %d died' %
                                                              target.doId))
                                # leftSuits and rightSuits are used for
                                # dodging, and since only NPC drops are
                                # group drops, and NPC drops always hit,
                                # there is no need for an actual list here
                                sdict['leftSuits'] = []
                                sdict['rightSuits'] = []
                                targets.append(sdict)
                        adict['target'] = targets
                    else:
                        targetIndex = ta[TOON_TGT_COL]
                        if targetIndex < 0:
                            targetGone = 1
                        else:
                            assert (targetIndex < len(suits))
                            targetId = suits[targetIndex]
                            assert (targetId != -1)
                            target = self.battle.findSuit(targetId)
                            assert (target != None)
                            sdict = {}
                            sdict['suit'] = target
                            # MPG bandaid on crash where target is not in
                            # activeSuits for some reason
                            if (self.battle.activeSuits.count(target) == 0):
                                targetGone = 1
                                suitIndex = 0
                            else:
                                suitIndex = self.battle.activeSuits.index(
                                    target)
                            leftSuits = []
                            for si in range(0, suitIndex):
                                asuit = self.battle.activeSuits[si]
                                if (self.battle.isSuitLured(asuit) == 0):
                                    leftSuits.append(asuit)
                            lenSuits = len(self.battle.activeSuits)
                            rightSuits = []
                            if (lenSuits > (suitIndex + 1)):
                                for si in range(suitIndex + 1, lenSuits):
                                    asuit = self.battle.activeSuits[si]
                                    if (self.battle.isSuitLured(asuit) == 0):
                                        rightSuits.append(asuit)
                            sdict['leftSuits'] = leftSuits
                            sdict['rightSuits'] = rightSuits
                            assert (targetIndex < len(hps))
                            sdict['hp'] = hps[targetIndex]
                            sdict['kbbonus'] = kbbonuses[targetIndex]
                            sdict['died'] = ta[SUIT_DIED_COL] & (
                                1 << targetIndex)
                            sdict['revived'] = ta[SUIT_REVIVE_COL] & (
                                1 << targetIndex)
                            if (sdict['revived'] != 0):
                                pass
                                #import pdb; pdb.set_trace()
                            if (sdict['died'] != 0):
                                assert (self.notify.debug('suit: %d died' %
                                                          targetId))
                            # MovieDrop and MovieTrap expect a list
                            # (because NPC drops affect groups of suits)
                            if (track == DROP or track == TRAP):
                                adict['target'] = [sdict]
                            else:
                                adict['target'] = sdict
                adict['hpbonus'] = ta[TOON_HPBONUS_COL]
                adict['sidestep'] = ta[TOON_ACCBONUS_COL]
                # NPC heals need to always succeed
                if ('npcId' in adict):
                    adict['sidestep'] = 0
                adict['battle'] = self.battle
                adict['playByPlayText'] = self.playByPlayText
                if (targetGone == 0):
                    self.toonAttackDicts.append(adict)
                else:
                    self.notify.warning('genToonAttackDicts() - target gone!')

        # Sort the dictionaries by ascending toon level ([TOON_LVL_COL])
        # I think this doesnt cause a problem similar to 'cogsmack' because
        # the AI uses  BattleBase.py's findToonAttack() to also do sorting
        # by toon level
        def compFunc(a, b):
            alevel = a['level']
            blevel = b['level']
            if (alevel > blevel):
                return 1
            elif (alevel < blevel):
                return -1
            return 0

        self.toonAttackDicts.sort(key=functools.cmp_to_key(compFunc))
Пример #5
0
    def __genToonAttackDicts(self, toons, suits, toonAttacks):
        for ta in toonAttacks:
            targetGone = 0
            track = ta[TOON_TRACK_COL]
            if track != NO_ATTACK:
                adict = {}
                toonIndex = ta[TOON_ID_COL]
                toonId = toons[toonIndex]
                toon = self.battle.findToon(toonId)
                if toon == None:
                    continue
                level = ta[TOON_LVL_COL]
                adict['toon'] = toon
                adict['track'] = track
                adict['level'] = level
                hps = ta[TOON_HP_COL]
                kbbonuses = ta[TOON_KBBONUS_COL]
                if track == NPCSOS:
                    adict['npcId'] = ta[TOON_TGT_COL]
                    toonId = ta[TOON_TGT_COL]
                    track, npc_level, npc_hp = NPCToons.getNPCTrackLevelHp(adict['npcId'])
                    if track == None:
                        track = NPCSOS
                    adict['track'] = track
                    adict['level'] = npc_level
                elif track == PETSOS:
                    petId = ta[TOON_TGT_COL]
                    adict['toonId'] = toonId
                    adict['petId'] = petId
                if track == SOS:
                    targetId = ta[TOON_TGT_COL]
                    if targetId == base.localAvatar.doId:
                        target = base.localAvatar
                        adict['targetType'] = 'callee'
                    elif toon == base.localAvatar:
                        target = base.cr.identifyAvatar(targetId)
                        adict['targetType'] = 'caller'
                    else:
                        target = None
                        adict['targetType'] = 'observer'
                    adict['target'] = target
                elif track == NPCSOS or track == NPC_COGS_MISS or track == NPC_TOONS_HIT or track == NPC_RESTOCK_GAGS or track == PETSOS:
                    adict['special'] = 1
                    toonHandles = []
                    for t in toons:
                        if t != -1:
                            target = self.battle.findToon(t)
                            if target == None:
                                continue
                            if track == NPC_TOONS_HIT and t == toonId:
                                continue
                            toonHandles.append(target)

                    adict['toons'] = toonHandles
                    suitHandles = []
                    for s in suits:
                        if s != -1:
                            target = self.battle.findSuit(s)
                            if target == None:
                                continue
                            suitHandles.append(target)

                    adict['suits'] = suitHandles
                    if track == PETSOS:
                        del adict['special']
                        targets = []
                        for t in toons:
                            if t != -1:
                                target = self.battle.findToon(t)
                                if target == None:
                                    continue
                                tdict = {}
                                tdict['toon'] = target
                                tdict['hp'] = hps[toons.index(t)]
                                self.notify.debug('PETSOS: toon: %d healed for hp: %d' % (target.doId, hps[toons.index(t)]))
                                targets.append(tdict)

                        if len(targets) > 0:
                            adict['target'] = targets
                elif track == HEAL:
                    if levelAffectsGroup(HEAL, level):
                        targets = []
                        for t in toons:
                            if t != toonId and t != -1:
                                target = self.battle.findToon(t)
                                if target == None:
                                    continue
                                tdict = {}
                                tdict['toon'] = target
                                tdict['hp'] = hps[toons.index(t)]
                                self.notify.debug('HEAL: toon: %d healed for hp: %d' % (target.doId, hps[toons.index(t)]))
                                targets.append(tdict)

                        if len(targets) > 0:
                            adict['target'] = targets
                        else:
                            targetGone = 1
                    else:
                        targetIndex = ta[TOON_TGT_COL]
                        if targetIndex < 0:
                            targetGone = 1
                        else:
                            targetId = toons[targetIndex]
                            target = self.battle.findToon(targetId)
                            if target != None:
                                tdict = {}
                                tdict['toon'] = target
                                tdict['hp'] = hps[targetIndex]
                                adict['target'] = tdict
                            else:
                                targetGone = 1
                elif attackAffectsGroup(track, level, ta[TOON_TRACK_COL]):
                    targets = []
                    for s in suits:
                        if s != -1:
                            target = self.battle.findSuit(s)
                            if ta[TOON_TRACK_COL] == NPCSOS:
                                if track == LURE and self.battle.isSuitLured(target) == 1:
                                    continue
                                elif track == TRAP and (self.battle.isSuitLured(target) == 1 or target.battleTrap != NO_TRAP):
                                    continue
                            targetIndex = suits.index(s)
                            sdict = {}
                            sdict['suit'] = target
                            sdict['hp'] = hps[targetIndex]
                            if ta[TOON_TRACK_COL] == NPCSOS and track == DROP and hps[targetIndex] == 0:
                                continue
                            sdict['kbbonus'] = kbbonuses[targetIndex]
                            sdict['died'] = ta[SUIT_DIED_COL] & 1 << targetIndex
                            sdict['revived'] = ta[SUIT_REVIVE_COL] & 1 << targetIndex
                            if sdict['died'] != 0:
                                pass
                            sdict['leftSuits'] = []
                            sdict['rightSuits'] = []
                            targets.append(sdict)

                    adict['target'] = targets
                else:
                    targetIndex = ta[TOON_TGT_COL]
                    if targetIndex < 0:
                        targetGone = 1
                    else:
                        targetId = suits[targetIndex]
                        target = self.battle.findSuit(targetId)
                        sdict = {}
                        sdict['suit'] = target
                        if self.battle.activeSuits.count(target) == 0:
                            targetGone = 1
                            suitIndex = 0
                        else:
                            suitIndex = self.battle.activeSuits.index(target)
                        leftSuits = []
                        for si in xrange(0, suitIndex):
                            asuit = self.battle.activeSuits[si]
                            if self.battle.isSuitLured(asuit) == 0:
                                leftSuits.append(asuit)

                        lenSuits = len(self.battle.activeSuits)
                        rightSuits = []
                        if lenSuits > suitIndex + 1:
                            for si in xrange(suitIndex + 1, lenSuits):
                                asuit = self.battle.activeSuits[si]
                                if self.battle.isSuitLured(asuit) == 0:
                                    rightSuits.append(asuit)

                        sdict['leftSuits'] = leftSuits
                        sdict['rightSuits'] = rightSuits
                        sdict['hp'] = hps[targetIndex]
                        sdict['kbbonus'] = kbbonuses[targetIndex]
                        sdict['died'] = ta[SUIT_DIED_COL] & 1 << targetIndex
                        sdict['revived'] = ta[SUIT_REVIVE_COL] & 1 << targetIndex
                        if sdict['revived'] != 0:
                            pass
                        if sdict['died'] != 0:
                            pass
                        if track == DROP or track == TRAP:
                            adict['target'] = [sdict]
                        else:
                            adict['target'] = sdict
                adict['hpbonus'] = ta[TOON_HPBONUS_COL]
                adict['sidestep'] = ta[TOON_ACCBONUS_COL]
                if 'npcId' in adict:
                    adict['sidestep'] = 0
                adict['battle'] = self.battle
                adict['playByPlayText'] = self.playByPlayText
                if targetGone == 0:
                    self.toonAttackDicts.append(adict)
                else:
                    self.notify.warning('genToonAttackDicts() - target gone!')

        def compFunc(a, b):
            alevel = a['level']
            blevel = b['level']
            if alevel > blevel:
                return 1
            elif alevel < blevel:
                return -1
            return 0

        self.toonAttackDicts.sort(compFunc)
        return