def snub(self, other): self.setLastSocialInteraction(other, "sbun {}".format(other.name)) other.setLastSocialInteraction(self, "snubed by {}".format(self.name)) if other not in self.social_xp.keys(): self.social_xp[other] = 0 if self not in other.social_xp.keys(): other.social_xp[self] = 0 self.social_xp[other] = max((self.social_xp[other] - 2) * other.social, -100) other.social_xp[self] = max((other.social_xp[self] - 2) * self.social, -100) self.global_xp += 1 pc.add_relation_sprite(self, other, "snub", basic_colors.RED)
def talk(self, other): self.setLastSocialInteraction(other, "talk with {}".format(other.name)) other.setLastSocialInteraction(self, "talk with {}".format(self.name)) if other not in self.social_xp.keys(): self.social_xp[other] = 0 if self not in other.social_xp.keys(): other.social_xp[self] = 0 self.social_xp[other] = min((self.social_xp[other] + 2) * other.social, 100) other.social_xp[self] = min((other.social_xp[self] + 2) * self.social, 100) self.global_xp += 1 pc.add_relation_sprite(self, other, "talk", basic_colors.LIME)
def befriend(self, other): self.setLastSocialInteraction(other, "befriend {}".format(other.name)) other.setLastSocialInteraction(self, "befriended by {}".format(self.name)) if other not in self.social_xp.keys(): self.social_xp[other] = 0 if self not in other.social_xp.keys(): other.social_xp[self] = 0 self.social_xp[other] = min((self.social_xp[other] + 4) * other.social, 100) other.social_xp[self] = min((other.social_xp[self] + 4) * self.social, 100) self.global_xp += 3 pc.add_relation_sprite(self, other, "befriend", basic_colors.LIME)
def insult(self, other): self.setLastSocialInteraction(other, "insult {}".format(other.name)) other.setLastSocialInteraction(self, "insulted by {}".format(self.name)) #Change xp if other not in self.social_xp.keys(): self.social_xp[other] = 0 if self not in other.social_xp.keys(): other.social_xp[self] = 0 self.social_xp[other] = max((self.social_xp[other] - 4) * other.social, -100) other.social_xp[self] = max((other.social_xp[self] - 4) * self.social, -100) self.global_xp += 3 pc.add_relation_sprite(self, other, "insult", basic_colors.RED)
def shareFoodMemory(self, other): self.setLastSocialInteraction(other, "share food with {}".format(other.name)) other.setLastSocialInteraction(self, "food shared by {}".format(self.name)) for mf in self.known_food.keys(): other.known_food[mf] = 0 #add xp if other not in self.social_xp.keys(): self.social_xp[other] = 0 if self not in other.social_xp.keys(): other.social_xp[self] = 0 self.social_xp[other] = min((self.social_xp[other] + 3) * other.social, 100) other.social_xp[self] = min((other.social_xp[self] + 5) * self.social, 100) self.global_xp += 5 pc.add_relation_sprite(self, other, "share food", basic_colors.LIME)
def attack_other(self, other): if other not in self.social_xp.keys(): self.social_xp[other] = 0 if self not in other.social_xp.keys(): other.social_xp[self] = 0 self.social_xp[other] = max((self.social_xp[other] - 8) * other.social, -100) other.social_xp[self] = max((other.social_xp[self] - 8) * self.social, -100) atck_value = random.randint(1, 20) + self.attack if atck_value >= other.defense: damage_value = self.attack_damage for i in range(self.attack_dice[0]): damage_value += random.randint(1, self.attack_dice[1]) other.hitpoint -= damage_value self.global_xp += 8 self.setLastSocialInteraction( other, "attack {} for {} dmg! ".format(other.name, damage_value)) other.setLastSocialInteraction( self, "attacked by {}, took {} dmg!".format(self.name, damage_value)) pc.add_relation_sprite(self, other, "attack succeeds", basic_colors.RED) else: self.setLastSocialInteraction( other, "attack {}: failed! ".format(other.name)) other.setLastSocialInteraction( self, "attacked by {}, defended!".format(self.name)) other.global_xp += 10 pc.add_relation_sprite(self, other, "attack failed", basic_colors.RED)
def shareFood(self, other): if "food" in self.bagpack.keys( ) and self.bagpack["food"] > self.hunger_thresh * 0.15: v = self.bagpack["food"] / 2.0 self.bagpack["food"] -= v other.putInBagpack("food", v) self.setLastSocialInteraction( other, "shared {} food with {}".format(round(v, 2), other.name)) other.setLastSocialInteraction( self, "{} food shared by {}".format(round(v, 2), self.name)) if other not in self.social_xp.keys(): self.social_xp[other] = 0 if self not in other.social_xp.keys(): other.social_xp[self] = 0 self.social_xp[other] = min( (self.social_xp[other] + 3) * other.social, 100) other.social_xp[self] = min( (other.social_xp[self] + 5) * self.social, 100) self.global_xp += 5 pc.add_relation_sprite(self, other, "share food", basic_colors.LIME)
def giveBirth(self, other): self.reproduction_cd = 1800 child = NPC(self.env, name="npc" + str(self.env.idNPC)) child.parents = [self, other] child.age = 0 child.generation = max(self.generation, other.generation) + 1 child.setPose( int(self.pose.x + other.pose.x) / 2, int(self.pose.y + other.pose.y) / 2) mutation = 0.4 if random.random() < mutation * 1.25: #Mutation child.courage = random.randint(child.courage_min, child.courage_max) else: #Genetic passage child.courage = int(round((self.courage + other.courage) / 2.0)) if random.random() < mutation * 1.25: #Mutation child.kindness = random.randint(child.kindness_min, child.kindness_max) else: #Genetic passage child.kindness = int(round((self.kindness + other.kindness) / 2.0)) child.strength = random.randint(child.str_min, child.str_max) + int( round(child.courage * 0.33)) child.attack_damage = int(round(child.strength * 1.2)) child.attack_dice = [ int(round((self.attack_dice[0] + other.attack_dice[0]) / 2.0)), int(round((self.attack_dice[1] + other.attack_dice[1]) / 2.0)) ] child.hitpoint_max = int( round((self.hitpoint_max + other.hitpoint_max) / 2.0)) child.hitpoint = child.hitpoint_max * 0.25 child.defense = 10 + (child.courage_max - child.courage) + int( round(child.strength * 0.33)) if random.random() < mutation * 0.75: #Mutation child.memory = random.randint(800, 1200) else: #Genetic passage child.memory = int(round((self.memory + other.memory) / 2.0)) if random.random() < mutation * 0.5: child.speed = round(random.random() * 0.6, 2) + 0.4 else: child.speed = (self.speed + other.speed) / 2.0 if random.random() < mutation * 0.5: child.regen_hitpoint = random.random() * 0.003 + 0.001 else: child.regen_hitpoint = (self.regen_hitpoint + other.regen_hitpoint) / 2.0 if random.random() < mutation * 0.5: child.harvester = random.random() * 0.8 + 0.4 else: child.harvester = (self.harvester + other.harvester) / 2.0 if random.random() < mutation * 0.5: child.social = random.random() * 0.8 + 0.4 else: child.social = (self.social + other.social) / 2.0 child.setNeigh_computation_thread(self.neigh_computation_thread) child.setClosestfood_computation_thread( self.closestfood_computation_thread) self.env.pgo_obj.updatePosition(child) child.setInitialSocialXP() for npc in self.env.npcs: npc.social_xp[child] = 0 child.setIdleBehaviour() self.env.addNPC(child) self.social_xp[other] = min( (self.social_xp[other] + 10) * other.social, 100) other.social_xp[self] = min((other.social_xp[self] + 10) * self.social, 100) self.social_xp[child] = 30 other.social_xp[child] = 30 child.social_xp[self] = 26 * utils.signof(random.random() - 0.5) child.social_xp[other] = 26 * utils.signof(random.random() - 0.5) self.setLastSocialInteraction(other, "reproduce with {}".format(other.name)) other.setLastSocialInteraction(self, "reproduce with {}".format(self.name)) child.start() pc.add_relation_sprite(self, other, "reproduce", basic_colors.LIME) pc.add_relation_sprite(other, self, "reproduce", basic_colors.LIME)