Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions internal/characters/alignment_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package characters

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestAlignmentToString(t *testing.T) {
tests := []struct {
name string
alignment int8
expected string
}{
// Unholy
{"Unholy lower bound", -100, "unholy"},
{"Unholy upper bound", -80, "unholy"},
{"Just above Unholy", -79, "evil"},

// Evil
{"Evil lower bound", -79, "evil"},
{"Evil upper bound", -60, "evil"},
{"Just above Evil", -59, "corrupt"},

// Corrupt
{"Corrupt lower bound", -59, "corrupt"},
{"Corrupt upper bound", -40, "corrupt"},
{"Just above Corrupt", -39, "misguided"},

// Misguided
{"Misguided lower bound", -39, "misguided"},
{"Misguided upper bound", -20, "misguided"},
{"Just above Misguided", -19, "neutral"},

// Neutral
{"Neutral low", -19, "neutral"},
{"Neutral", 0, "neutral"},
{"Neutral high", 19, "neutral"},
{"Just above Neutral high", 20, "lawful"},

// Lawful
{"Lawful lower bound", 20, "lawful"},
{"Lawful upper bound", 39, "lawful"},
{"Just above Lawful", 40, "virtuous"},

// Virtuous
{"Virtuous lower bound", 40, "virtuous"},
{"Virtuous upper bound", 59, "virtuous"},
{"Just above Virtuous", 60, "good"},

// Good
{"Good lower bound", 60, "good"},
{"Good upper bound", 79, "good"},
{"Just above Good", 80, "holy"},

// Holy
{"Holy lower bound", 80, "holy"},
{"Holy upper bound", 100, "holy"},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := AlignmentToString(tt.alignment)
assert.Equal(t, tt.expected, result)
})
}
}
51 changes: 16 additions & 35 deletions internal/characters/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import (
"github.com/GoMudEngine/GoMud/internal/statmods"
"github.com/GoMudEngine/GoMud/internal/stats"
"github.com/GoMudEngine/GoMud/internal/util"

//
"maps"
"slices"
)

var (
Expand Down Expand Up @@ -219,7 +222,7 @@ func (c *Character) GetBaseCastSuccessChance(spellId string) int {
}

func (c *Character) CarryCapacity() int {
return 5 + int(math.Floor(float64(c.Stats.Strength.ValueAdj/3)))
return 5 + c.Stats.Strength.ValueAdj/3
}

func (c *Character) DeductActionPoints(amount int) bool {
Expand Down Expand Up @@ -271,7 +274,7 @@ func (c *Character) GetMiscDataKeys(prefixMatch ...string) []string {
}

allKeys := []string{}
for key, _ := range c.MiscData {
for key := range c.MiscData {
allKeys = append(allKeys, key)
}

Expand Down Expand Up @@ -380,9 +383,7 @@ func (c *Character) GetDefaultDiceRoll() (attacks int, dCount int, dSides int, b

func (c *Character) GetSpells() map[string]int {
ret := make(map[string]int)
for sName, sCasts := range c.SpellBook {
ret[sName] = sCasts
}
maps.Copy(ret, c.SpellBook)
return ret
}

Expand Down Expand Up @@ -444,10 +445,7 @@ func (c *Character) GrantXP(xp int) (actualXP int, xpScale int) {
actualXP = xp
} else {

scaleFloat := float64(xpScale) / 100
if scaleFloat < 1 {
scaleFloat = 1
}
scaleFloat := max(float64(xpScale)/100, 1)

actualXP = int(float64(xp) * scaleFloat)
}
Expand All @@ -463,7 +461,7 @@ func (c *Character) TrackCharmed(mobId int, add bool) {
for pos, mobInstanceId := range c.CharmedMobs {
if mobInstanceId == mobId {
if !add {
c.CharmedMobs = append(c.CharmedMobs[:pos], c.CharmedMobs[pos+1:]...)
c.CharmedMobs = slices.Delete(c.CharmedMobs, pos, pos+1)
}
return
}
Expand Down Expand Up @@ -507,13 +505,10 @@ func (c *Character) IsCharmed(userId ...int) bool {
return c.Charmed != nil
}

for _, uId := range userId {
if c.Charmed.UserId == uId {
return true
}
if c.Charmed == nil {
return false
}

return false
return slices.Contains(userId, c.Charmed.UserId)
}

// Returns userId of whoever had charmed them
Expand Down Expand Up @@ -561,9 +556,7 @@ func (c *Character) GetHealthAppearance() string {

func (c *Character) GetAllSkillRanks() map[string]int {
retMap := make(map[string]int)
for skillName, skillLevel := range c.Skills {
retMap[skillName] = skillLevel
}
maps.Copy(retMap, c.Skills)
return retMap
}

Expand Down Expand Up @@ -606,12 +599,7 @@ func (c *Character) GetPlayerName(viewingUserId int, renderFlags ...NameRenderFl
}

func (c *Character) HasAdjective(adj string) bool {
for _, a := range c.Adjectives {
if a == adj {
return true
}
}
return false
return slices.Contains(c.Adjectives, adj)
}

func (c *Character) SetAdjective(adj string, addToList bool) {
Expand All @@ -623,7 +611,7 @@ func (c *Character) SetAdjective(adj string, addToList bool) {
if addToList {
return
} else {
c.Adjectives = append(c.Adjectives[:i], c.Adjectives[i+1:]...)
c.Adjectives = slices.Delete(c.Adjectives, i, i+1)
return
}
}
Expand Down Expand Up @@ -708,7 +696,6 @@ func (c *Character) PruneCooldowns() {
}

c.Cooldowns.Prune()

}

func (c *Character) GetCooldown(trackingTag string) int {
Expand All @@ -726,9 +713,7 @@ func (c *Character) GetAllCooldowns() map[string]int {
return ret
}

for trackingTag, rounds := range c.Cooldowns {
ret[trackingTag] = rounds
}
maps.Copy(ret, c.Cooldowns)

return ret
}
Expand Down Expand Up @@ -1513,11 +1498,7 @@ func (c *Character) AutoTrain() {
}

func (c *Character) CanDualWield() bool {

if c.GetSkillLevel(skills.DualWield) > 0 {
return true
}
return false
return c.GetSkillLevel(skills.DualWield) > 0
}

// Returns whether a correction was in order
Expand Down
Loading
Loading