Example #1
0
 def think(self, thought):
     # Think about something. Rolls a d6, and checks
     # if its less/equal to the parameter given (1 to 5).
     # Returns True/False
     #dice = 3
     dice = cl_Game.rollDice(6, 1, 0)
     return dice <= thought
Example #2
0
 def tripCheck(self):
     t = self.trip + self.tripAdd
     d = cl_Game.rollDice(20,1,0)
     if(d <= t):
         # Trip number rolled under
         # Activate hazard
         # Reset added likeliness to 0
         self.tripAdd = 0
         return True
     else:
         # Trip number rolled over
         # Don't activate hazard
         # make it more likely to activate next time
         self.tripAdd += 1
         return False
Example #3
0
    def hazardActivate(self,target):
        from cl_Mob import Mob
        if(isinstance(target,Mob)):
            def addToTargets(h=self.damageTargets,c=1):
                if(str(target.name) in h):
                    h[str(target.name)] += c
                else:
                    h[str(target.name)] = c
            
            damage = cl_Game.rollDice(self.sides,self.dice,self.mod)
            if(target.buffTimer > 0 and target.buffType == "Defence"):
                damage = int(damage/2)

            target.hitpoints -= damage
            target.lastHitBy = "Room Hazard"
            target.lastHitWith = self
            addToTargets()
            addToTargets(self.damageDone,damage)
            print(self.name+" "+self.atkDesc+" "+target.name+" for "+str(damage)+" points of damage!")
            target.updateHitpoints()

            if(target.hitpoints <= 0):
                from random import choice
                #Apply Salvation Sphere effects if buff active
                if(target.buffTimer > 0 and target.buffType == "Salvation"):
                    print(target.name+"'s Salvation Sphere activates!")
                    target.alive = True
                    target.hitpoints = 25
                    target.buffType = None
                    target.buffTimer = 0
                    target.cheatedDeath += 1
                    target.healingGot += 25
                    target.updateHitpoints()
                    if(target.think(target.ai_talk) == True):
                        target.sayDoSomething(choice(target.readyStrings))
                else:
                    if(target.think(target.ai_talk) == True):
                        target.sayDoSomething(choice(target.loseStrings))
                    self.kills.append(target.name)
        else:
            pass
Example #4
0
    def attackMob(self, attack, target=None):
        # Returns true or false if the attack succeeds or fails
        # in being carried out, regardless of hitting or missing.

        # Check if attack used is an attack.
        if (isinstance(self.attacks[attack], Attack)):
            atk = self.attacks[attack]
            #Attack is correct. Is target correct?
            if (isinstance(target, Mob)):
                if (self.lookForMob(target) == True):
                    # Target is a mob, define adding function for statistics...
                    def addToTargets(t=atk.targets, c=1):
                        if (str(target.name) in t):
                            t[str(target.name)] += c
                        else:
                            t[str(target.name)] = c

                    # Check if target is alive.
                    if (target.alive == True):
                        # Target is alive, therefore can be attacked. Sweet!
                        # Roll the dices! If attacker is equal/higher to defender, its a hit.
                        attackRoll = cl_Game.rollDice(
                            20, 1, self.stats[atk.statAttack] + atk.toHit)
                        defendRoll = cl_Game.rollDice(
                            20, 1, target.stats[atk.statDefend])

                        def attackDefendDifference():
                            return attackRoll - defendRoll

                        chatThreshold = 6  # How much of a difference needs to occur between attack and defence rolls make the character think about talking.

                        if (attackRoll >= defendRoll):
                            # Attack hits!
                            diceSides = atk.damDiceSides
                            diceNumber = atk.damDiceNumber
                            diceMod = atk.damDiceMod

                            # Roll damage
                            damage = cl_Game.rollDice(diceSides, diceNumber,
                                                      diceMod)
                            if (self.buffTimer > 0
                                    and self.buffType == "Attack"):
                                damage = damage * 2
                            if (target.buffTimer > 0
                                    and target.buffType == "Defence"):
                                damage = int(damage / 2)
                            target.hitpoints -= damage
                            print(self.name + "'s " + str(atk.name) +
                                  " hits " + str(target.name) + " for " +
                                  str(damage) + " points of damage! (" +
                                  str(attackRoll) + " vs " + str(defendRoll) +
                                  ")")

                            # Report and Apply damage
                            if (target.think(target.ai_talk) == True):
                                target.sayDoSomething(
                                    choice(target.hurtStrings))
                            atk.hits += 1
                            target.updateHitpoints()
                            atk.damage += damage
                            addToTargets(atk.targetHits)
                            addToTargets(atk.targetDamage, damage)
                            target.lastHitBy = self
                            target.lastHitWith = atk
                            '''
                            if(attackDefendDifference() >= 8):
                                if(target.think(target.ai_talk) == True):
                                        target.sayDoSomething(choice(target.complimentStrings))
                            '''

                            # add to attack's Kill List if target killed.
                            if (target.hitpoints <= 0):
                                #Apply Salvation Sphere effects if buff active
                                if (target.buffTimer > 0
                                        and target.buffType == "Salvation"):
                                    # Activate salvation sphere! Another soul saved!
                                    print(target.name +
                                          "'s Salvation Sphere activates!")
                                    target.alive = True
                                    target.hitpoints = 25
                                    target.buffType = None
                                    target.buffTimer = 0
                                    target.cheatedDeath += 1
                                    target.healingGot += 25
                                    target.updateHitpoints()
                                    if (target.think(target.ai_talk) == True):
                                        target.sayDoSomething(
                                            choice(target.readyStrings))
                                else:
                                    # Die normally
                                    atk.kills.append(target.name)
                                    target.hpPerRound.append(target.hitpoints)
                                    if (target.think(target.ai_talk) == True):
                                        target.sayDoSomething(
                                            choice(target.loseStrings))
                        else:
                            # Attack misses!
                            print(self.name + "'s " + atk.name + " misses " +
                                  target.name + "! (" + str(attackRoll) +
                                  " vs " + str(defendRoll) + ")")
                            atk.misses += 1
                            addToTargets(atk.targetMisses)
                            target.lastMissedBy = self

                            if (attackDefendDifference() <= -chatThreshold):
                                if (target.think(target.ai_talk) == True):
                                    target.sayDoSomething(
                                        choice(target.insultStrings))
                        # Regardless of hit/miss, do logging
                        addToTargets()
                        self.travel.append(self.location.id)
                        self.travelFight.append(self.location.id)
                        self.lastAttacked = target
                        self.currentTarget = target
                        target.travelAttacked.append(target.location.id)

                        self.location.addToAttacksBy(self)
                        target.location.addToAttacksOn(target)
                        return True
                    else:
                        # Target isn't alive. Shouldn't/Can't attack...
                        print(self.name + "'s target " + target.name +
                              " is already dead!")
                        return False
                else:
                    # Target not in same room as Mob.
                    print(self.name + " can't find " + target.name + "!")
                    return False
            elif (target == None):
                # No target set.
                print(self.name + " has no target set.")
                return False
            else:
                #Target doesn't exist/isn't a mob.
                print(self.name + "'s specified target " + target.name +
                      " is not a Mob!")
                return False
        else:
            #Attack is not correct. Abort!
            print(self.name + "'s specified attack is not an Attack!")
            return False
Example #5
0
    def playGame(self):
        if (self.alive):
            from cl_Room import Room
            from cl_Room import roomList

            if (isinstance(self.location, Room)):
                # Initialise the 'brain' of the mob.
                attacks = randint(0, len(self.attacks) - 1)
                targets = self.location.mobs.copy()
                targets.append(self.lastMissedBy)
                targets.append(self.lastHitBy)
                targets.append(self.lastAttacked)
                targets.append(self.currentTarget)
                targets.reverse()
                targetChoices = []
                allies = self.locateTeammates()

                # Pick up something in the room at the start of turn.
                self.getPickup()

                #With list of targets, remove self, and remove None-s.
                for t in targets:
                    if (self.lookForMob(t)):
                        targetChoices.append(t)
                    if (self in targetChoices):
                        targetChoices.remove(self)
                    if (None in targetChoices):
                        targetChoices.remove(None)
                        continue

                    # Figure out what's a mob, and if they're a target.
                    # Then remove teammates, the dead, and the invisible.
                    # from the targets list.
                    if (isinstance(t, Mob) and t in targetChoices):
                        if (self.team == t.team and t.team != None):
                            targetChoices.remove(t)
                            continue
                        if (t.alive == False):
                            targetChoices.remove(t)
                            continue
                        if (t.buffType == "Invisible"):
                            targetChoices.remove(t)
                            continue

                # If target list is at least 1 or more, fight.
                # If attack fails or no choices, go to another room.
                if (len(targetChoices)):
                    # Targets available. Choose to fight or move.
                    if (self.buffType != None
                            or self.hitpoints > int(self.maxHitpoints / 2)):
                        # Don't run while got powerup or healthy
                        do = "fight"
                    else:
                        # 1 in 3 chance of moving normally
                        do = choice(["fight", "fight", "move"])

                    # Act on choice.
                    if (do == "fight"):
                        if (self.think(self.ai_talk) == True):
                            self.sayDoSomething(choice(self.attackStrings))
                        self.attackMob(attacks, choice(targetChoices))
                    else:
                        if (self.think(self.ai_talk) == True):
                            self.sayDoSomething(choice(self.moveStrings))
                        self.goToAnotherRoom()
                else:
                    # No targets in sight. Move or wait.
                    if (self.buffType != None or len(self.location.hazards)):
                        # Don't idle while mob has a powerup, or location has a hazard in it
                        do = "move"
                    else:
                        do = choice(["move", "move", "move", "wait"])

                    if (do == "move"):
                        # Prioritise going to rooms with pickups or other Mobs
                        # with a chance of just going somewhere random because
                        roomChoices = [-1]
                        for ex in self.location.exits:
                            if (len(roomList[ex].items)):
                                roomChoices.append(ex)
                        # Add rooms with mobs in them
                        for ex in self.location.exits:
                            if (len(roomList[ex].mobs)):
                                for m in roomList[ex].mobs:
                                    if (m.alive and m.buffType != "Invisible"):
                                        roomChoices.append(ex)
                        # Remove hazardous rooms from set choices
                        for ex in self.location.exits:
                            if (len(roomList[ex].hazards)
                                    and ex in roomChoices):
                                roomChoices.remove(ex)

                        #print(roomChoices)
                        if (len(roomChoices)):
                            # Go to specific Room
                            goto = choice(roomChoices)
                        else:
                            # Go to random room
                            goto = -1
                        if (self.think(self.ai_talk) == True):
                            self.sayDoSomething(choice(self.moveStrings))
                        self.goToAnotherRoom(goto)
                    elif (do == "wait"):
                        self.travel.append(self.location.id)
                        print(self.name + " waits at " + self.location.name +
                              "...")
                        if (self.think(self.ai_talk) == True):
                            self.sayDoSomething(choice(self.waitStrings))

                # Try picking up something in the room at end step.
                self.getPickup()

                # Do regeneration
                if (self.buffTimer > 0 and self.buffType == "Regen"):
                    if (self.hitpoints < self.maxHitpoints):
                        regen = cl_Game.rollDice(6, 1, 0)
                        self.hitpoints += regen
                        if (self.hitpoints > self.maxHitpoints):
                            self.hitpoints = self.maxHitpoints
                        print(self.name + " regenerates " + str(regen) +
                              " HP!")
                        self.healingGot += regen
                        self.updateHitpoints()
                # Do hazard check
                if (len(self.location.hazards)):
                    for h in self.location.hazards:
                        if (h.tripCheck() and self.alive):
                            print(self.name + " triggered the " + h.name + "!")
                            if (self.buffType != "Warning"):
                                if (self.think(self.ai_talk) == True):
                                    self.sayDoSomething(
                                        choice(self.hazardStrings))
                                h.hazardActivate(self)
                                self.hazardsTripped += 1
                            else:
                                print(self.name + " was warned of " + h.name +
                                      " and took no damage!")
                                if (self.think(self.ai_talk) == True):
                                    self.sayDoSomething(
                                        choice(self.insultStrings))
                        elif (self.alive):
                            self.hazardsAvoided += 1
                # Update HP Per Turn
                self.hpPerRound.append(self.hitpoints)
            else:
                print(
                    self.name +
                    " has not been placed in a room. They can't play the game!"
                )
                self.placeInRoom(0)
        else:
            # Character is dead. Cannot take actions.
            pass