internal static Gizmo CreateInstance(Gizmo template, int instanceID, int acdID, AABB aabb, Vector2f direction, uint worldID, uint sceneID) { Gizmo gizmo = template.MemberwiseClone() as Gizmo; gizmo.InstanceID = instanceID; gizmo.AcdID = acdID; gizmo.BoundingBox = aabb; gizmo.Direction = direction; gizmo.WorldID = worldID; gizmo.SceneID = sceneID; return gizmo; }
private void UpdateActors() { Dictionary <int, D3ActorCommonData> d3ACDs = memReader.GetACDs(); List <Hero> heros = new List <Hero>(); List <Gizmo> gizmos = new List <Gizmo>(); List <Monster> monsters = new List <Monster>(); List <Item> items = new List <Item>(); Dictionary <int, NPC> npcs = new Dictionary <int, NPC>(); List <Actor> actors = new List <Actor>(); foreach (D3ActorCommonData d3ACD in d3ACDs.Values) { // Handle inventory and equipped items if (d3ACD.Placement != -1) { PlaceItem(d3ACD); continue; } Actor templateActor = ActorTemplates.Actors[d3ACD.SnoID]; AABB aabb = new AABB(d3ACD.Pos1, d3ACD.Pos2); Vector2f direction = d3ACD.Direction; int acdID = (int)d3ACD.AcdID; D3AttributeValue teamID; d3ACD.Attributes.TryGetValue(D3Attribute.TeamID, out teamID); if (templateActor is Gizmo) { Gizmo gizmo = Gizmo.CreateInstance((Gizmo)templateActor, acdID, acdID, aabb, direction, d3ACD.WorldID, d3ACD.SceneID); gizmos.Add(gizmo); } else if (templateActor is Hero) { if (this.Me == null || acdID != this.Me.AcdID) { Hero hero = Hero.CreateInstance((Hero)templateActor, acdID, acdID, aabb, direction, d3ACD.WorldID, d3ACD.SceneID); heros.Add(hero); } } else if (templateActor is Item) { ItemDefinition itemDef; if (!ItemDefinitions.Definitions.TryGetValue((int)d3ACD.GBID, out itemDef)) { throw new MemoryReadException("Unrecognized GBID", d3ACD.GBID); } ItemType type = ItemTypes.Types[itemDef.ItemTypeHash]; Item item = Item.CreateInstance((Item)templateActor, itemDef, acdID, acdID, aabb, direction, d3ACD.WorldID, d3ACD.SceneID, type, -1, 0, 0); items.Add(item); } else if (templateActor is Monster) { int level = d3ACD.Attributes[D3Attribute.Level].Value; int xpGranted = d3ACD.Attributes[D3Attribute.Experience_Granted].Value; float hpCur = d3ACD.Attributes[D3Attribute.Hitpoints_Cur].ValueF; float hpMax = d3ACD.Attributes[D3Attribute.Hitpoints_Max].Value; Monster monster = Monster.CreateInstance((Monster)templateActor, acdID, acdID, aabb, direction, d3ACD.WorldID, d3ACD.SceneID, level, xpGranted, hpCur, hpMax); monsters.Add(monster); } else if (templateActor is NPC) { bool isOperatable = false; // FIXME: int level = 0; int hpCur = 0; int hpMax = 0; NPC npc = NPC.CreateInstance((NPC)templateActor, acdID, acdID, aabb, direction, d3ACD.WorldID, d3ACD.SceneID, isOperatable, level, hpCur, hpMax); npcs.Add(npc.InstanceID, npc); } else { Actor actor = Actor.CreateInstance(templateActor, acdID, acdID, aabb, direction, d3ACD.WorldID, d3ACD.SceneID); actors.Add(actor); } } this.Heros = heros.ToArray(); this.Gizmos = gizmos.ToArray(); this.Items = items.ToArray(); this.Monsters = monsters.ToArray(); if (this.NPCs == null || this.NPCs.Length != npcs.Count) { this.NPCs = new NPC[npcs.Count]; } npcs.Values.CopyTo(this.NPCs, 0); this.OtherActors = actors.ToArray(); }