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)
| 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. |
| 41 | func 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. |
no test coverage detected