using System.Collections.Generic; using Decal.Adapter.Wrappers; namespace Mag.Shared { public static class MyWorldObjectCreator { public static MyWorldObject Create(WorldObject wo) { MyWorldObject mwo = new MyWorldObject(); Dictionary boolValues = new Dictionary(); Dictionary doubleValues = new Dictionary(); Dictionary intValues = new Dictionary(); Dictionary stringValues = new Dictionary(); List activeSpells = new List(); List spells = new List(); foreach (var key in wo.BoolKeys) boolValues.Add(key, wo.Values((BoolValueKey)key)); foreach (var key in wo.DoubleKeys) doubleValues.Add(key, wo.Values((DoubleValueKey)key)); foreach (var key in wo.LongKeys) intValues.Add(key, wo.Values((LongValueKey)key)); foreach (var key in wo.StringKeys) stringValues.Add(key, wo.Values((StringValueKey)key)); for (int i = 0 ; i < wo.ActiveSpellCount ; i++) activeSpells.Add(wo.ActiveSpell(i)); for (int i = 0; i < wo.SpellCount; i++) spells.Add(wo.Spell(i)); mwo.Init(wo.HasIdData, wo.Id, wo.LastIdTime, (int)wo.ObjectClass, wo.Icon, boolValues, doubleValues, intValues, stringValues, activeSpells, spells); return mwo; } public static MyWorldObject Combine(MyWorldObject older, WorldObject newer) { // Always repair missing icons from old JSON files (plugin upgrades) if (older.Icon == 0 && newer.Icon != 0) { older.Icon = newer.Icon; } if (!older.HasIdData || newer.HasIdData) return Create(newer); MyWorldObject mwo = Create(newer); older.AddTo(mwo.BoolValues, mwo.DoubleValues, mwo.IntValues, mwo.StringValues); return older; } } }