public override bool FromStream(Stream mstream, short ParsingRule, ThingDb.Thing thing) { NoxBinaryReader br = new NoxBinaryReader(mstream); DirectionId = (byte)Array.IndexOf(MonsterXfer.NOX_DIRECT_LONG, br.ReadUInt64()); ScriptEvents = new string[10]; // Fix for some old maps (null) NPCVoiceSet = ""; BuffList = new MonsterXfer.BuffEntry[0]; // Читаем имена обработчиков скриптовых событий for (int i = 0; i < 10; i++) { if (i == 2) { DetectEventTimeout = br.ReadUInt16(); } ScriptEvents[i] = br.ReadScriptEventString(); } // Пропуск (0) br.ReadInt32(); // цвета NPCColors = new Color[6]; byte R, G, B; for (int i = 0; i < 6; i++) { R = br.ReadByte(); G = br.ReadByte(); B = br.ReadByte(); NPCColors[i] = Color.FromArgb(R, G, B); } // основной блок инфы if (ParsingRule >= 32) { ActionRoamPathFlag = br.ReadByte(); if (ParsingRule < 49) { StatusFlags = (NoxEnums.MonsterStatus)br.ReadUInt16(); } else { StatusFlags = (NoxEnums.MonsterStatus)br.ReadUInt32(); } HealthMultiplier = br.ReadSingle(); RetreatRatio = br.ReadSingle(); ResumeRatio = br.ReadSingle(); SightRange = br.ReadSingle(); Health = br.ReadInt16(); Aggressiveness = br.ReadSingle(); if (ParsingRule < 35) { DefaultAction = br.ReadInt32(); } EscortObjName = br.ReadString(); if (ParsingRule >= 34) { int spells = br.ReadInt32(); KnownSpells = new List <MonsterXfer.SpellEntry>(); string spellName = null; uint spellFlags = 0; for (int i = 0; i < spells; i++) { spellName = br.ReadString(); spellFlags = br.ReadUInt32(); if (ThingDb.Spells.Keys.Contains(spellName)) { KnownSpells.Add(new MonsterXfer.SpellEntry(spellName, spellFlags)); } } } else { br.BaseStream.Seek(0x224, SeekOrigin.Current); } // Задержки между заклинаниями if (ParsingRule < 47) { ReactionCastingDelayMin = (ushort)br.ReadByte(); ReactionCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } BuffCastingDelayMin = (ushort)br.ReadByte(); BuffCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } DebuffCastingDelayMin = (ushort)br.ReadByte(); DebuffCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } OffensiveCastingDelayMin = (ushort)br.ReadByte(); OffensiveCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } BlinkCastingDelayMin = (ushort)br.ReadByte(); BlinkCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } } else { ReactionCastingDelayMin = br.ReadUInt16(); ReactionCastingDelayMax = br.ReadUInt16(); BuffCastingDelayMin = br.ReadUInt16(); BuffCastingDelayMax = br.ReadUInt16(); DebuffCastingDelayMin = br.ReadUInt16(); DebuffCastingDelayMax = br.ReadUInt16(); OffensiveCastingDelayMin = br.ReadUInt16(); OffensiveCastingDelayMax = br.ReadUInt16(); BlinkCastingDelayMin = br.ReadUInt16(); BlinkCastingDelayMax = br.ReadUInt16(); } if (ParsingRule < 34) { MagicNumber = br.ReadUInt32(); } if (ParsingRule >= 33) { LockPathDistance = br.ReadSingle(); } if (ParsingRule >= 34) { SpellPowerLevel = br.ReadInt32(); NPCStrength = br.ReadByte(); NPCSpeed = br.ReadSingle(); AimSkillLevel = br.ReadSingle(); if (ParsingRule < 42) { if (br.ReadInt16() == 0) { Immortal = true; } } TrapSpell1 = br.ReadString(); TrapSpell2 = br.ReadString(); TrapSpell3 = br.ReadString(); } if (ParsingRule >= 35) { string action = br.ReadString(); DefaultAction = Array.IndexOf(NoxEnums.AIActionStrings, action); } if (ParsingRule >= 41) { // here you have to read just a huge amount of information // however it is used very rarely, usually entryType = 4; forced = 0 short entryType = br.ReadInt16(); if (entryType <= 4) { byte forced = 1; if (entryType >= 2) { forced = br.ReadByte(); } if (forced == 1 || entryType < 2) { return(false); // TODO для ПОЛНОЙ совместимости, придётся } } } if (ParsingRule >= 42) { Immortal = br.ReadBoolean(); } if (ParsingRule >= 44) { MagicNumber = br.ReadUInt32(); } if (ParsingRule >= 45) { MaxHealth = (short)br.ReadInt32(); } if (ParsingRule >= 46) { AddedSubclass = br.ReadUInt32(); } if (ParsingRule >= 48) { Health = br.ReadInt16(); } if (ParsingRule >= 51) { Experience = br.ReadSingle(); } if (ParsingRule >= 52) { NPCVoiceSet = br.ReadString(); } if (ParsingRule < 61) { return(true); } // энчанты short buffsType = br.ReadInt16(); if (buffsType > 2 || buffsType <= 0) { return(false); } byte count = br.ReadByte(); BuffList = new MonsterXfer.BuffEntry[count]; while (count > 0) { MonsterXfer.BuffEntry be = new MonsterXfer.BuffEntry(); be.Name = br.ReadString(); be.Power = br.ReadByte(); be.Duration = br.ReadInt32(); if (be.Name == ENCHANT_SHIELD && buffsType >= 2) { be.ShieldHealth = br.ReadInt32(); } BuffList[count - 1] = be; count--; } Array.Reverse(BuffList); if (ParsingRule >= 62) { PoisonLevel = br.ReadByte(); } } return(true); }
public override bool FromStream(Stream mstream, short ParsingRule, ThingDb.Thing thing) { NoxBinaryReader br = new NoxBinaryReader(mstream); DirectionId = (byte)Array.IndexOf(NOX_DIRECT_LONG, br.ReadUInt64()); ScriptEvents = new string[10]; // Read script event handler names for (int i = 0; i < 10; i++) { if (i == 2) { DetectEventTimeout = br.ReadUInt16(); } ScriptEvents[i] = br.ReadScriptEventString(); } // Skip (0) if (ParsingRule >= 11) { br.ReadInt32(); } if (ParsingRule >= 31) { ActionRoamPathFlag = br.ReadByte(); if (ParsingRule < 51) { StatusFlags = (NoxEnums.MonsterStatus)br.ReadUInt16(); } else { StatusFlags = (NoxEnums.MonsterStatus)br.ReadUInt32(); } HealthMultiplier = br.ReadSingle(); RetreatRatio = br.ReadSingle(); ResumeRatio = br.ReadSingle(); SightRange = br.ReadSingle(); if (ParsingRule < 33) { br.BaseStream.Seek(2, SeekOrigin.Current); } Aggressiveness = br.ReadSingle(); if (ParsingRule < 34) { DefaultAction = br.ReadInt32(); } EscortObjName = br.ReadString(); if (ParsingRule >= 34) { int spells = br.ReadInt32(); KnownSpells = new List <SpellEntry>(); string spellName = null; uint spellFlags = 0; for (int i = 0; i < spells; i++) { spellName = br.ReadString(); spellFlags = br.ReadUInt32(); if (ThingDb.Spells.Keys.Contains(spellName)) { KnownSpells.Add(new SpellEntry(spellName, spellFlags)); } } } else { br.BaseStream.Seek(0x224, SeekOrigin.Current); } // Spell usage delay values if (ParsingRule < 46) { ReactionCastingDelayMin = (ushort)br.ReadByte(); ReactionCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } BuffCastingDelayMin = (ushort)br.ReadByte(); BuffCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } DebuffCastingDelayMin = (ushort)br.ReadByte(); DebuffCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } OffensiveCastingDelayMin = (ushort)br.ReadByte(); OffensiveCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } BlinkCastingDelayMin = (ushort)br.ReadByte(); BlinkCastingDelayMax = (ushort)br.ReadByte(); if (ParsingRule <= 32) { br.ReadInt32(); } } else { ReactionCastingDelayMin = br.ReadUInt16(); ReactionCastingDelayMax = br.ReadUInt16(); BuffCastingDelayMin = br.ReadUInt16(); BuffCastingDelayMax = br.ReadUInt16(); DebuffCastingDelayMin = br.ReadUInt16(); DebuffCastingDelayMax = br.ReadUInt16(); OffensiveCastingDelayMin = br.ReadUInt16(); OffensiveCastingDelayMax = br.ReadUInt16(); BlinkCastingDelayMin = br.ReadUInt16(); BlinkCastingDelayMax = br.ReadUInt16(); } if (ParsingRule > 32) { LockPathDistance = br.ReadSingle(); } if (ParsingRule >= 33) { SpellPowerLevel = br.ReadInt32(); AimSkillLevel = br.ReadSingle(); if (ParsingRule < 42) { if (br.ReadInt16() == 0) { Immortal = true; } } if (ParsingRule < 53) { int spellIndex = br.ReadInt32(); TrapSpell1 = ThingDb.Spells.Values[spellIndex].Name; spellIndex = br.ReadInt32(); TrapSpell2 = ThingDb.Spells.Values[spellIndex].Name; spellIndex = br.ReadInt32(); TrapSpell3 = ThingDb.Spells.Values[spellIndex].Name; } else { TrapSpell1 = br.ReadString(); TrapSpell2 = br.ReadString(); TrapSpell3 = br.ReadString(); } } if (ParsingRule >= 34) { string action = br.ReadString(); DefaultAction = Array.IndexOf(NoxEnums.AIActionStrings, action); } if (ParsingRule >= 41) { // large, complex structure dealing with AI-specific data // it is only used on saved games, normally entryType = 4; forced = 0 short entryType = br.ReadInt16(); if (entryType <= 4) { byte forced = 1; if (entryType >= 2) { forced = br.ReadByte(); } if (forced == 1 || entryType < 2) { return(false); // TODO implement for full compatibility } } } if (ParsingRule >= 42) { Immortal = br.ReadBoolean(); } if (ParsingRule >= 43 && thing.Subclass[(int)ThingDb.Thing.SubclassBitIndex.SHOPKEEPER]) { // Shop contents ShopkeeperInfoStruct si = new ShopkeeperInfoStruct(); if (ParsingRule >= 50) { si.BuyValueMultiplier = br.ReadSingle(); } if (ParsingRule >= 61) { si.SellValueMultiplier = br.ReadSingle(); } if (ParsingRule >= 48) { si.ShopkeeperGreetingText = br.ReadString(); } byte items = br.ReadByte(); si.ShopItems = new ShopItemInfo[items]; for (int i = 0; i < items; i++) { ShopItemInfo item = new ShopItemInfo(); if (ParsingRule < 50) { br.ReadInt32(); } item.Count = br.ReadByte(); item.Name = br.ReadString(); if (ParsingRule >= 47) { item.SpellID = br.ReadString(); item.Ench1 = br.ReadString(); item.Ench2 = br.ReadString(); item.Ench3 = br.ReadString(); item.Ench4 = br.ReadString(); } si.ShopItems[i] = item; } ShopkeeperInfo = si; } if (ParsingRule >= 44) { MagicNumber = br.ReadUInt32(); } if (ParsingRule >= 45) { AddedSubclass = br.ReadUInt32(); } if (ParsingRule >= 49) { Health = br.ReadInt16(); } if (ParsingRule >= 51) { SetDefaultResumeRatio = br.ReadBoolean(); SetDefaultRetreatRatio = br.ReadBoolean(); SetDefaultMonsterStatus = br.ReadBoolean(); LearnDefaultSpells = br.ReadBoolean(); } if (ParsingRule >= 54 && thing.Subclass[(int)ThingDb.Thing.SubclassBitIndex.FEMALE_NPC]) { MaidenBodyColors = new Color[6]; byte R, G, B; for (int i = 0; i < 6; i++) { R = br.ReadByte(); G = br.ReadByte(); B = br.ReadByte(); MaidenBodyColors[i] = Color.FromArgb(R, G, B); } if (ParsingRule >= 55) { MaidenVoiceSet = br.ReadString(); } } if (ParsingRule >= 62) { short entryType = br.ReadInt16(); if (entryType > 2 || entryType <= 0) { return(false); } byte count = br.ReadByte(); BuffList = new BuffEntry[count]; while (count > 0) { BuffEntry be = new BuffEntry(); be.Name = br.ReadString(); be.Power = br.ReadByte(); be.Duration = br.ReadInt32(); if (be.Name == ENCHANT_SHIELD && entryType >= 2) { be.ShieldHealth = br.ReadInt32(); } BuffList[count] = be; count--; } Array.Reverse(BuffList); } if (ParsingRule >= 63 && thing.Subclass[(int)ThingDb.Thing.SubclassBitIndex.WOUNDED_NPC]) { WoundedNPCVoiceSet = br.ReadString(); } if (ParsingRule >= 64) { PoisonLevel = br.ReadByte(); } } return(true); }