d2player/game_controls: learnskills cmd not always creating new skill objects

when we ran the command before we would always throw away old skill
objects and create a new one. This is nasty if we have a pointer to the
old object. By throwing it away we have to update all these pointers.

Now we rather increase the skillpoint, if the hero already has this
skill.
This commit is contained in:
juander 2020-11-09 15:03:00 +01:00
parent 77cd538c2f
commit 83acaefea2
1 changed files with 14 additions and 9 deletions

View File

@ -1014,18 +1014,23 @@ func (g *GameControls) bindLearnSkillsCommand(term d2interface.Terminal) error {
continue
}
skill, skillErr := g.heroState.CreateHeroSkill(1, skillDetailRecord.Skill)
if skill == nil {
continue
}
if skill, ok := g.hero.Skills[skillDetailRecord.ID]; ok {
skill.SkillPoints++;
learnedSkillsCount++
} else {
skill, skillErr := g.heroState.CreateHeroSkill(1, skillDetailRecord.Skill)
if skill == nil {
continue
}
learnedSkillsCount++
learnedSkillsCount++
g.hero.Skills[skill.ID] = skill
g.hero.Skills[skill.ID] = skill
if skillErr != nil {
err = skillErr
break
if skillErr != nil {
err = skillErr
break
}
}
}