public MapUnit(string name) : this() { Template = TemplateLoader.GetMonsterByName(name); if (Template == null) { Debug.LogFormat("Invalid unit created (name={0})", name); } else { InitUnit(); } }
public MapUnit(int serverId) : this() { Template = TemplateLoader.GetMonsterById(serverId); if (Template == null) { Debug.LogFormat("Invalid unit created (serverId={0})", serverId); } else { InitUnit(); } }
private void InitUnit() { InitBaseUnit(); Class = UnitClassLoader.GetUnitClassById(Template.TypeID); if (Class == null) { Debug.LogFormat("Invalid unit created (class not found, serverId={0}, typeId={1})", Template.ServerID, Template.TypeID); Template = null; return; } Width = Template.TokenSize; Height = Width; CoreStats.Health = CoreStats.HealthMax = Math.Max(Template.HealthMax, 0); CoreStats.Mana = CoreStats.ManaMax = Math.Max(Template.ManaMax, 0); // they sometimes put -1 as mana counter for fighters CoreStats.HealthRegeneration = (short)Template.HealthRegeneration; CoreStats.ManaRegeneration = (short)Template.ManaRegeneration; // BRMS CoreStats.Body = (short)Template.Body; CoreStats.Reaction = (short)Template.Reaction; CoreStats.Mind = (short)Template.Mind; CoreStats.Spirit = (short)Template.Spirit; // physical damage and resists int templateMin = Template.PhysicalMin; int templateMax = Template.PhysicalMax - templateMin; if (IsIgnoringArmor && ((templateMin & 0x80) != 0)) { templateMin = (templateMin & 0x7F) * 15; templateMax *= 15; } if (templateMax < 0) { templateMin = Template.PhysicalMax; templateMax = (Template.PhysicalMin - Template.PhysicalMax) * 64; } CoreStats.DamageMin = (short)templateMin; CoreStats.DamageMax = (short)(templateMax + templateMin); CoreStats.ToHit = (short)Template.ToHit; CoreStats.Absorbtion = (short)Template.Absorbtion; CoreStats.Defence = (short)Template.Defense; // magical resists CoreStats.ProtectionFire = (byte)Template.ProtectionFire; CoreStats.ProtectionWater = (byte)Template.ProtectionWater; CoreStats.ProtectionAir = (byte)Template.ProtectionAir; CoreStats.ProtectionEarth = (byte)Template.ProtectionEarth; CoreStats.ProtectionAstral = (byte)Template.ProtectionAstral; // physical resists (custom) CoreStats.ProtectionBlade = (byte)Template.ProtectionBlade; CoreStats.ProtectionAxe = (byte)Template.ProtectionAxe; CoreStats.ProtectionBludgeon = (byte)Template.ProtectionBludgeon; CoreStats.ProtectionPike = (byte)Template.ProtectionPike; CoreStats.ProtectionShooting = (byte)Template.ProtectionShooting; // speed and scanrange CoreStats.RotationSpeed = (byte)Template.RotationSpeed; if (CoreStats.RotationSpeed < 1) { CoreStats.RotationSpeed = 1; } CoreStats.Speed = (byte)Template.Speed; if (CoreStats.Speed < 1) { CoreStats.Speed = 1; } CoreStats.ScanRange = Template.ScanRange; // initial items if (Template.EquipItem1.Length > 0) { Item item1 = new Item(Template.EquipItem1); if (item1.IsValid) { PutItemToBody((BodySlot)item1.Class.Option.Slot, item1); } } if (Template.EquipItem2.Length > 0) { Item item2 = new Item(Template.EquipItem2); if (item2.IsValid) { PutItemToBody((BodySlot)item2.Class.Option.Slot, item2); } } // spellbook for (int i = 0; i < 32; i++) { uint sp = 1u << i; if (Template.ManaMax > 0 && (Template.KnownSpells & sp) != 0) { Spell cspell = new Spell(i, this); SpellBook.Add(cspell); } } CalculateVision(); UpdateItems(); }