MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / newSimMob

Function newSimMob

internal/combat/simulate.go:41–92  ·  view source on GitHub ↗

newSimMob creates a fully initialized mob from a template without registering it in the global instance map. If forceLevel > 0, the mob's level is overridden.

(mobId mobs.MobId, forceLevel int)

Source from the content-addressed store, hash-verified

39// newSimMob creates a fully initialized mob from a template without registering
40// it in the global instance map. If forceLevel > 0, the mob's level is overridden.
41func newSimMob(mobId mobs.MobId, forceLevel int) (*mobs.Mob, error) {
42 mob := mobs.GetMobSpec(mobId)
43 if mob == nil {
44 return nil, fmt.Errorf("mob %d not found", mobId)
45 }
46
47 if forceLevel > 0 {
48 mob.Character.Level = forceLevel
49 }
50
51 mob.Character.PlayerDamage = make(map[int]int)
52 mob.Character.StatPoints = 0
53 {
54 cfgProg := configs.GetProgressionConfig()
55 for lvl := 1; lvl <= mob.Character.Level; lvl++ {
56 if int(cfgProg.StatPointsEveryNLevels) <= 1 || lvl%int(cfgProg.StatPointsEveryNLevels) == 0 {
57 mob.Character.StatPoints += int(cfgProg.StatPointsPerLevel)
58 }
59 }
60 }
61 mob.Character.Level--
62 mob.Character.Experience = mob.Character.XPTNL()
63 mob.Character.Level++
64
65 mob.Character.AutoTrain()
66 mob.Character.Health = mob.Character.HealthMax.Value
67 mob.Character.Mana = mob.Character.ManaMax.Value
68
69 mob.Character.SetPermaBuffs(mob.BuffIds)
70 mob.Character.Buffs = buffs.New()
71
72 for idx := range mob.Character.Items {
73 mob.Character.Items[idx].Validate()
74 }
75
76 if mob.Character.Alignment == 0 {
77 if raceInfo := races.GetRace(mob.Character.GetRaceId()); raceInfo != nil {
78 if raceInfo.DefaultAlignment != 0 {
79 mob.Character.Alignment = raceInfo.DefaultAlignment
80 }
81 }
82 }
83
84 for _, slot := range characters.AllSlots() {
85 mob.Character.Equipment.Get(slot).Validate()
86 }
87
88 mob.Validate()
89 mob.Character.Validate(true)
90
91 return mob, nil
92}
93
94// SimulateCombat runs an instant fight between two mobs identified by their
95// template IDs. levelA/levelB override the template level when > 0.

Callers 2

RankMobsFunction · 0.85
SimulateCombatFunction · 0.85

Calls 11

GetMobSpecFunction · 0.92
GetProgressionConfigFunction · 0.92
NewFunction · 0.92
GetRaceFunction · 0.92
AllSlotsFunction · 0.92
XPTNLMethod · 0.80
AutoTrainMethod · 0.80
SetPermaBuffsMethod · 0.80
GetRaceIdMethod · 0.80
ValidateMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected