Thread: [wpdev-commits] xmlscripts/scripts/system skillgain.py,1.7,1.8
Brought to you by:
rip,
thiagocorrea
From: Sebastian H. <dar...@us...> - 2004-09-26 16:15:21
|
Update of /cvsroot/wpdev/xmlscripts/scripts/system In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22031/system Modified Files: skillgain.py Log Message: fix for statgain Index: skillgain.py =================================================================== RCS file: /cvsroot/wpdev/xmlscripts/scripts/system/skillgain.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** skillgain.py 7 Jul 2004 03:14:32 -0000 1.7 --- skillgain.py 26 Sep 2004 16:15:06 -0000 1.8 *************** *** 30,99 **** # def gainstat(char, stat): ! realstr = char.strength - char.strength2 ! realdex = char.dexterity - char.dexterity2 ! realint = char.intelligence - char.intelligence2 ! totalstats = realstr + realdex + realint ! resendstats = 0 ! # Atrohpy ! # Like the skill atrophy we have a certain chance to ! # decrease another (lock: down) stat here. ! # Only active for players ! if char.player and totalstats / char.statcap >= random(): ! stats = [0, 1, 2] ! if char.strengthlock != 1 or stat == 0 or realstr <= 1: ! stats.remove(0) ! if char.dexteritylock != 1 or stat == 1 or realdex <= 1: ! stats.remove(1) ! if char.intelligencelock != 1 or stat == 2 or realint <= 1: ! stats.remove(2) ! # We found a stat to lower ! if len(stats) > 0: ! lower = choice(stats) ! if lower == 0: ! char.strength -= 1 ! # NPCs hitpoints are not related to strength at all ! if char.npc: ! char.maxhitpoints -= 1 ! char.updatehealth() ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost one point of strength [%u].\n' % (char.serial, char.strength)) ! elif lower == 1: ! char.dexterity -= 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost one point of dexterity [%u].\n' % (char.serial, char.dexterity)) ! elif lower == 2: ! char.intelligence -= 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost one point of intelligence [%u].\n' % (char.serial, char.intelligence)) ! totalstats -= 1 ! resendstats = 1 ! # Increase the stat if we didn't hit our total ! # statcap yet. ! if totalstats < char.statcap: ! if stat == 0: ! char.strength += 1 ! # For NPCs we manually increase the max hitpoints ! # Players are accounted for automatically ! if char.npc: ! char.maxhitpoints += 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained one point of strength [%u].\n' % (char.serial, char.strength)) ! elif stat == 1: ! char.dexterity += 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained one point of dexterity [%u].\n' % (char.serial, char.dexterity)) ! elif stat == 2: ! char.intelligence += 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained one point of intelligence [%u].\n' % (char.serial, char.intelligence)) ! resendstats = 1 ! if resendstats and char.socket: ! char.socket.resendstatus() # --- 30,99 ---- # def gainstat(char, stat): ! realstr = char.strength - char.strength2 ! realdex = char.dexterity - char.dexterity2 ! realint = char.intelligence - char.intelligence2 ! totalstats = realstr + realdex + realint ! resendstats = 0 ! # Atrohpy ! # Like the skill atrophy we have a certain chance to ! # decrease another (lock: down) stat here. ! # Only active for players ! if char.player and totalstats / char.statcap >= random(): ! stats = [0, 1, 2] ! if char.strengthlock != 1 or stat == 0 or realstr <= 1: ! stats.remove(0) ! if char.dexteritylock != 1 or stat == 1 or realdex <= 1: ! stats.remove(1) ! if char.intelligencelock != 1 or stat == 2 or realint <= 1: ! stats.remove(2) ! # We found a stat to lower ! if len(stats) > 0: ! lower = choice(stats) ! if lower == 0: ! char.strength -= 1 ! # NPCs hitpoints are not related to strength at all ! if char.npc: ! char.maxhitpoints -= 1 ! char.updatehealth() ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost one point of strength [%u].\n' % (char.serial, char.strength)) ! elif lower == 1: ! char.dexterity -= 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost one point of dexterity [%u].\n' % (char.serial, char.dexterity)) ! elif lower == 2: ! char.intelligence -= 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost one point of intelligence [%u].\n' % (char.serial, char.intelligence)) ! totalstats -= 1 ! resendstats = 1 ! # Increase the stat if we didn't hit our total ! # statcap yet. ! if totalstats < char.statcap: ! if stat == 0: ! char.strength += 1 ! # For NPCs we manually increase the max hitpoints ! # Players are accounted for automatically ! if char.npc: ! char.maxhitpoints += 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained one point of strength [%u].\n' % (char.serial, char.strength)) ! elif stat == 1: ! char.dexterity += 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained one point of dexterity [%u].\n' % (char.serial, char.dexterity)) ! elif stat == 2: ! char.intelligence += 1 ! if DEBUG_STATS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained one point of intelligence [%u].\n' % (char.serial, char.intelligence)) ! resendstats = 1 ! if resendstats and char.socket: ! char.socket.resendstatus() # *************** *** 103,177 **** # def gainskill(char, skill, totalskill, totalcap): ! value = char.skill[skill] / 10.0 ! lock = char.skilllock[skill] ! cap = char.skillcap[skill] / 10.0 ! info = SKILLS[skill] ! if lock == 0 and value < cap: ! # Skills lower than 10.0% will gain 0.1% - 0.5% at once ! if value < 10.0: ! points = randint(1, 5) / 10.0 ! else: ! points = 0.1 ! # This will always happen if we are above the skillcap ! # But if we have some skills set to lower, they ! # are lowered even if we are below the skillcap ! if totalskill / totalcap >= random(): ! for i in range(0, ALLSKILLS): ! if i != skill and char.skilllock[i] == 1 and char.skill[i] / 10.0 >= points: ! char.skill[i] -= int(points * 10) ! totalskill -= points ! if DEBUG_SKILLS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost %0.01f%% of %s [%02.01f%%].\n' % (char.serial, points, SKILLS[i][SKILL_NAME], char.skill[i] / 10.0)) ! if char.socket: ! char.socket.updateskill(i) ! break ! # We can only gain in this skill if we are still below ! # the total skill cap. Atrophy has been taken care of ! # in the if before this. ! if totalskill + points <= totalcap: ! char.skill[skill] += int(points * 10) ! totalskill += points ! if DEBUG_SKILLS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained %0.01f%% of %s [%02.01f%%].\n' % (char.serial, points, info[SKILL_NAME], char.skill[skill] / 10.0)) ! if char.socket: ! char.socket.updateskill(skill) ! # It's not important that we actually gained the skill ! # in order to gain stats by using it. ! if lock == 0: ! strchance = info[SKILL_STRCHANCE] ! dexchance = info[SKILL_DEXCHANCE] ! intchance = info[SKILL_INTCHANCE] ! realstr = char.strength - char.strength2 ! realdex = char.dexterity - char.dexterity2 ! realint = char.intelligence - char.intelligence2 ! if (char.npc or char.strengthlock == 0) and realstr >= char.strengthcap: ! strchance = 0.0 ! else: ! strchance /= 33.3 ! if (char.npc or char.dexteritylock == 0) and realdex >= char.dexteritycap: ! dexchance = 0.0 ! else: ! dexchance /= 33.3 ! if (char.npc or char.intelligencelock == 0) and realint >= char.intelligencecap: ! intchance = 0.0 ! else: ! intchance /= 33.3 ! if strchance > random(): ! gainstat(char, 0) ! elif dexchance > random(): ! gainstat(char, 1) ! elif intchance > random(): ! gainstat(char, 2) # --- 103,177 ---- # def gainskill(char, skill, totalskill, totalcap): ! value = char.skill[skill] / 10.0 ! lock = char.skilllock[skill] ! cap = char.skillcap[skill] / 10.0 ! info = SKILLS[skill] ! if lock == 0 and value < cap: ! # Skills lower than 10.0% will gain 0.1% - 0.5% at once ! if value < 10.0: ! points = randint(1, 5) / 10.0 ! else: ! points = 0.1 ! # This will always happen if we are above the skillcap ! # But if we have some skills set to lower, they ! # are lowered even if we are below the skillcap ! if totalskill / totalcap >= random(): ! for i in range(0, ALLSKILLS): ! if i != skill and char.skilllock[i] == 1 and char.skill[i] / 10.0 >= points: ! char.skill[i] -= int(points * 10) ! totalskill -= points ! if DEBUG_SKILLS == 1: ! char.log(LOG_TRACE, 'Character [%x] lost %0.01f%% of %s [%02.01f%%].\n' % (char.serial, points, SKILLS[i][SKILL_NAME], char.skill[i] / 10.0)) ! if char.socket: ! char.socket.updateskill(i) ! break ! # We can only gain in this skill if we are still below ! # the total skill cap. Atrophy has been taken care of ! # in the if before this. ! if totalskill + points <= totalcap: ! char.skill[skill] += int(points * 10) ! totalskill += points ! if DEBUG_SKILLS == 1: ! char.log(LOG_TRACE, 'Character [%x] gained %0.01f%% of %s [%02.01f%%].\n' % (char.serial, points, info[SKILL_NAME], char.skill[skill] / 10.0)) ! if char.socket: ! char.socket.updateskill(skill) ! # It's not important that we actually gained the skill ! # in order to gain stats by using it. ! if lock == 0: ! strchance = info[SKILL_STRCHANCE] ! dexchance = info[SKILL_DEXCHANCE] ! intchance = info[SKILL_INTCHANCE] ! realstr = char.strength - char.strength2 ! realdex = char.dexterity - char.dexterity2 ! realint = char.intelligence - char.intelligence2 ! if (char.npc or char.strengthlock == 0) or realstr >= char.strengthcap: ! strchance = 0.0 ! else: ! strchance /= 33.3 ! if (char.npc or char.dexteritylock == 0) or realdex >= char.dexteritycap: ! dexchance = 0.0 ! else: ! dexchance /= 33.3 ! if (char.npc or char.intelligencelock == 0) or realint >= char.intelligencecap: ! intchance = 0.0 ! else: ! intchance /= 33.3 ! if strchance > random(): ! gainstat(char, 0) ! elif dexchance > random(): ! gainstat(char, 1) ! elif intchance > random(): ! gainstat(char, 2) # *************** *** 179,243 **** # def onSkillGain(char, skill, lower, higher, success): ! # See if we can gain at all ! # GMs don't gain skills ! if char.dead or char.gm or char.polymorph: ! return ! if not SKILLS.has_key(skill): ! char.log(LOG_ERROR, "Is using an unidentified skill: %u\n" % skill) ! return ! info = SKILLS[skill] ! skills = char.skill ! value = skills[skill] / 10.0 # Convert into float ! lower /= 10.0 ! higher /= 10.0 ! # NPCs only learn by using skills ! # they already have ! if char.npc and value <= 0.0: ! return ! # No gain for effortless or futile attempts ! if value < lower or value >= higher: ! return ! chance = (value - lower) / (higher - lower) ! cap = char.skillcap[skill] / 10.0 ! # Skills capped at zero are disabled for this character ! if cap == 0: ! return ! totalskills = 0.0 ! for i in range(0, ALLSKILLS): ! totalskills += skills[i] / 10.0 ! # Calculate the GainChance ! # (RunUO has a nice approach. Doing it similar) ! totalcap = settings.getnumber("General", "SkillCap", 700) ! gainchance = (totalcap - totalskills) / totalcap # How near are we to our global skill cap ! gainchance += (cap - value) / cap # How near are we to our skill cap ! # Use the difficulty to influence the skill gain ! if success: ! gainchance += 0.5 - chance * 0.5 ! else: ! gainchance += 0.2 - chance * 0.2 ! gainchance /= 3.0 # The average of the three values ! # Introduce a new "Gain Factor" ! # There is also a 1% minimum chance for gain ! gainchance = max(0.01, gainchance * info[SKILL_GAINFACTOR]) ! # Tamed creatures get a * 2 bonus for their gain. ! if char.npc and char.tamed: ! gainchance *= 2 ! # Skills below 10% always gain, otherwise take the gainchance into ! # account. ! if gainchance >= random() or value < 10.0: ! gainskill(char, skill, totalskills, totalcap) # --- 179,243 ---- # def onSkillGain(char, skill, lower, higher, success): ! # See if we can gain at all ! # GMs don't gain skills ! if char.dead or char.gm or char.polymorph: ! return ! if not SKILLS.has_key(skill): ! char.log(LOG_ERROR, "Is using an unidentified skill: %u\n" % skill) ! return ! info = SKILLS[skill] ! skills = char.skill ! value = skills[skill] / 10.0 # Convert into float ! lower /= 10.0 ! higher /= 10.0 ! # NPCs only learn by using skills ! # they already have ! if char.npc and value <= 0.0: ! return ! # No gain for effortless or futile attempts ! if value < lower or value >= higher: ! return ! chance = (value - lower) / (higher - lower) ! cap = char.skillcap[skill] / 10.0 ! # Skills capped at zero are disabled for this character ! if cap == 0: ! return ! totalskills = 0.0 ! for i in range(0, ALLSKILLS): ! totalskills += skills[i] / 10.0 ! # Calculate the GainChance ! # (RunUO has a nice approach. Doing it similar) ! totalcap = settings.getnumber("General", "SkillCap", 700) ! gainchance = (totalcap - totalskills) / totalcap # How near are we to our global skill cap ! gainchance += (cap - value) / cap # How near are we to our skill cap ! # Use the difficulty to influence the skill gain ! if success: ! gainchance += 0.5 - chance * 0.5 ! else: ! gainchance += 0.2 - chance * 0.2 ! gainchance /= 3.0 # The average of the three values ! # Introduce a new "Gain Factor" ! # There is also a 1% minimum chance for gain ! gainchance = max(0.01, gainchance * info[SKILL_GAINFACTOR]) ! # Tamed creatures get a * 2 bonus for their gain. ! if char.npc and char.tamed: ! gainchance *= 2 ! # Skills below 10% always gain, otherwise take the gainchance into ! # account. ! if gainchance >= random() or value < 10.0: ! gainskill(char, skill, totalskills, totalcap) # *************** *** 245,277 **** # def onLoad(): ! wolfpack.registerglobal(EVENT_SKILLGAIN, "system.skillgain") ! # Load all the neccesary data from the definitions ! for i in range(0, ALLSKILLS): ! skilldef = wolfpack.getdefinition(WPDT_SKILL, str(i)) ! # Load the skill information ! if skilldef: ! SKILLS[i] = { ! SKILL_GAINFACTOR: 1.0, ! SKILL_STRCHANCE: 0.0, ! SKILL_DEXCHANCE: 0.0, ! SKILL_INTCHANCE: 0.0 ! } ! for j in range(0, skilldef.childcount): ! child = skilldef.getchild(j) ! if child.name == 'name': ! SKILLS[i][SKILL_NAME] = child.value ! elif child.name == 'title': ! SKILLS[i][SKILL_TITLE] = child.value ! elif child.name == 'defname': ! SKILLS[i][SKILL_DEFNAME] = child.value ! elif child.name == 'gainfactor': ! SKILLS[i][SKILL_GAINFACTOR] = float(child.value) ! elif child.name == 'strchance': ! SKILLS[i][SKILL_STRCHANCE] = float(child.value) ! elif child.name == 'dexchance': ! SKILLS[i][SKILL_DEXCHANCE] = float(child.value) ! elif child.name == 'intchance': ! SKILLS[i][SKILL_INTCHANCE] = float(child.value) --- 245,277 ---- # def onLoad(): ! wolfpack.registerglobal(EVENT_SKILLGAIN, "system.skillgain") ! # Load all the neccesary data from the definitions ! for i in range(0, ALLSKILLS): ! skilldef = wolfpack.getdefinition(WPDT_SKILL, str(i)) ! # Load the skill information ! if skilldef: ! SKILLS[i] = { ! SKILL_GAINFACTOR: 1.0, ! SKILL_STRCHANCE: 0.0, ! SKILL_DEXCHANCE: 0.0, ! SKILL_INTCHANCE: 0.0 ! } ! for j in range(0, skilldef.childcount): ! child = skilldef.getchild(j) ! if child.name == 'name': ! SKILLS[i][SKILL_NAME] = child.value ! elif child.name == 'title': ! SKILLS[i][SKILL_TITLE] = child.value ! elif child.name == 'defname': ! SKILLS[i][SKILL_DEFNAME] = child.value ! elif child.name == 'gainfactor': ! SKILLS[i][SKILL_GAINFACTOR] = float(child.value) ! elif child.name == 'strchance': ! SKILLS[i][SKILL_STRCHANCE] = float(child.value) ! elif child.name == 'dexchance': ! SKILLS[i][SKILL_DEXCHANCE] = float(child.value) ! elif child.name == 'intchance': ! SKILLS[i][SKILL_INTCHANCE] = float(child.value) |