def equip(self,eObj): if eObj in self.inv and eObj != self.equipped[eObj.iType]: self.equipped[eObj.iType].equipped = False self.equipped[eObj.iType]=eObj eObj.equipped=True log("Equipped " + eObj.name) toast("You equip %s." %(eObj.name))
def checkLevelUp(self): if self.xp >= self.lvlup: self.xp -= self.lvlup self.maxHP += self.lvl*2 self.hp = self.maxHP self.lvl += 1 self.attack +=1 self.lvlup += self.lvl*5 toast("%s leveled up."%(self.name)) toast("%s is now level %d"%(self.name,self.lvl))
def useItem(self,uObj): # If item takes away hunger: if uObj.iType == "healing": self.hunger+=uObj.hunger if self.hunger >= self.maxHunger: self.hunger = self.maxHunger # If item has temporary effects: for effect in uObj.effects: if effect not in self.effects: self.effects.append(effect) toast("You %s a %s" % (uObj.used, uObj.name)) self.inv.remove(uObj)
def update(self, player): for enemy in self.enemies: if enemy.hp <= 0: toast("%s has died"%(enemy.name)) toast("%s gave %d experience"%(enemy.name,enemy.xp)) player.xp += enemy.xp enemy.weapon.x,enemy.weapon.y=enemy.x,enemy.y self.items.append(enemy.weapon) self.enemies.remove(enemy) else: enemy.update(self.cMap, self.cellTypes, self.enemies, player) self.indicator = (player.x, player.y)
def update(self,wMap, cellTypes, enemies, player): if self.hp > 0: if not self.attack: self.wander(wMap,cellTypes,player) elif self.attack and getDistanceOf(self.x,self.y,player.x,player.y)<2: attack = self.getAttack() if attack > 0: toast("%s attacked the player for %d damage." % (self.name, attack)) else: toast("%s misses his attack." % (self.name)) player.hp-=attack player.fighting = 5
def pickUp(self,obj,tMap): i = 0 for item in self.inv: if item.iType == obj.iType: i+=1 if self.getInventorySize() < self.getMaxInventory() and i<13: self.inv.append(obj) tMap.items.remove(obj) self.moved = True # This is being used for debugging purposes. There is a chance this will not be added to the actual game. elif i >= 15: toast("You have too many weapons in you inventory.") else: toast("You do not have enough inventory space.")
def enter(self,player): toast("You have entered: " + self.name) if len(self.items) < 1 and random.randint(0,0)==0: n = random.randint(0,2) # This is set to 0,0 so that only weapons generate. if n == 0: # THIS IS WHERE ISSUE #10 HAPPENS self.items.append(self.itemGen.generateNewWeapon(-1,player.lvl,-1)) elif n == 1: self.items.append(self.itemGen.generateNewConsumable(-1,-1,player.lvl)) else: self.items.append(self.itemGen.generateNewArmor(-1,-1,player.lvl,-1))
def update(self): log("Updating player.") if not self.fighting: if self.hunger > 8: self.hp += int(self.maxHP*0.2) elif self.hunger > 5: self.hp += int(self.maxHP*0.1) elif self.fighting > 1: self.fighting -= 1 else: self.fighting = False self.hTimer += 1 if self.hTimer >= self.hungerTimerCountDown: self.hunger -= 1 if self.hunger <= 4: toast("Your stomach growls.") if self.hunger<0: self.hunger = 0 self.hTimer -= self.hungerTimerCountDown if self.hunger < 1: self.hp -= int(round((self.maxHP*0.05))) if self.hp <= 0: # Death function here. Not yet made. toast("You die from starvation.") toast("I know you are still alive.") toast("Shut up about it already.") if self.hp > self.maxHP: self.hp = self.maxHP
def attackEnemy(self,enemy): if getDistanceOf(self.x,self.y,enemy.x,enemy.y)<self.getAttackDistance(): maxAttack = self.getAttack() attack = random.randint(maxAttack/2,maxAttack) enemy.hp -= attack if attack > 0: toast("You attack the %s for %d damage"%(enemy.name,attack)) else: toast("Your attack missed.") else: toast("Your attack from too far away.") enemy.attack = True self.moved = True