def refund_investigation_skill(skills_dict): """ Gets the amount of resources for investigation skill refund Args: skills_dict: dictionary of our skills Returns: The amount of resources to refund them. """ return abs(cost_at_rank("investigation", skills_dict.get("investigation", 0), 0))
def func(self): """Execute command.""" caller = self.caller ability = ("ability" in self.switches or self.cmdstring == "@adjustability" or self.cmdstring == "@adjustabilities") char = None if "reset" in self.switches or "refund" in self.switches: try: char = caller.search(self.lhs).char_ob except (AttributeError, ValueError, TypeError): caller.msg("No player by that name.") return if char.db.xp is None: char.db.xp = 0 if "reset" in self.switches: try: from commands.base_commands.guest import ( setup_voc, XP_BONUS_BY_SRANK, ) rhs = self.rhs.lower() setup_voc(char, rhs) char.db.vocation = rhs total_xp = char.db.total_xp or 0 total_xp = int(total_xp) xp = XP_BONUS_BY_SRANK[char.db.social_rank] xp += total_xp char.db.xp = xp caller.msg( "%s has had their skills and stats set up as a %s." % (char, rhs)) return except (AttributeError, ValueError, TypeError, KeyError): caller.msg("Could not set %s to %s vocation." % (char, self.rhs)) return if "refund" in self.switches: if not ability: skill_history = char.db.skill_history or {} try: current = len(char.db.skill_history[self.rhs]) skill_list = skill_history[self.rhs] cost = skill_list.pop() skill_history[self.rhs] = skill_list char.db.skill_history = skill_history except (KeyError, IndexError, TypeError): try: current = char.traits.get_skill_value(self.rhs) except KeyError: caller.msg("No such skill.") return cost = stats_and_skills.cost_at_rank( self.rhs, current - 1, current) if current <= 0: caller.msg("That would give them a negative skill.") return char.traits.set_skill_value(self.rhs, current - 1) char.db.xp += cost else: ability_history = char.db.ability_history or {} try: current = char.traits.get_ability_value(self.rhs) ability_list = ability_history[self.rhs] cost = ability_list.pop() ability_history[self.rhs] = ability_list char.db.ability_history = ability_history except (KeyError, IndexError, TypeError): current = char.traits.get_ability_value(self.rhs) if not current: caller.msg("No such ability.") return cost = stats_and_skills.cost_at_rank( self.rhs, current - 1, current) if current <= 0: caller.msg("That would give them a negative rating.") return char.traits.set_ability_value(self.rhs, current - 1) char.db.xp += cost caller.msg("%s had %s reduced by 1 and was refunded %s xp." % (char, self.rhs, cost)) return try: player, skill = self.lhs.strip().split("/") rhs = int(self.rhs) except (AttributeError, ValueError, TypeError): caller.msg("Invalid syntax") return targ = caller.search(player) if not targ: caller.msg("No player found by that name.") return char = targ.char_ob if not char: caller.msg("No active character for %s." % targ) return if ability: char.traits.set_ability_value(skill, rhs) else: char.traits.set_skill_value(skill, rhs) if rhs <= 0: if ability: caller.msg("Removed ability %s from %s." % (skill, char)) else: caller.msg("Removed skill %s from %s." % (skill, char)) else: caller.msg("%s's %s set to %s." % (char, skill, rhs)) if not caller.check_permstring("immortals"): inform_staff("%s set %s's %s skill to %s." % (caller, char, skill, rhs))