public NPC(NPCData data) : base(EOGame.Instance) { Index = data.Index; X = data.X; Y = data.Y; Direction = data.Direction; Data = (NPCRecord)World.Instance.ENF.Data[data.ID]; HP = Data.HP; bool success = true; npcSheet = new EONPCSpriteSheet(this); int tries = 0; do { try { //attempt to get standing frame 1. It will have non-black pixels if it exists. Frame = NPCFrame.StandingFrame1; Texture2D tmp = npcSheet.GetNPCTexture(); Color[] tmpData = new Color[tmp.Width * tmp.Height]; tmp.GetData(tmpData); hasStandFrame1 = tmpData.Any(_c => _c.R != 0 || _c.G != 0 || _c.B != 0); //get the first non-transparent pixel to determine offsets for name labels and damage counters Frame = NPCFrame.Standing; tmp = npcSheet.GetNPCTexture(); tmpData = new Color[tmp.Width * tmp.Height]; tmp.GetData(tmpData); int i = 0; while (i < tmpData.Length && tmpData[i].A == 0) { i++; } TopPixel = i == tmpData.Length - 1 ? 0 : i / tmp.Height; } //this block throws errors sometimes..no idea why. Keep looping until it works. catch (InvalidOperationException) { success = false; tries++; } } while (!success && tries < 3); if (tries >= 3) { throw new InvalidOperationException("Something weird happened initializing this NPC."); } m_chatBubble = new EOChatBubble(this); m_damageCounter = new DamageCounter(this, GetType()); }
public NPC(NPCData data) : base(EOGame.Instance) { ApplyData(data); bool success = true; npcSheet = new EONPCSpriteSheet(this); int tries = 0; do { try { //attempt to get standing frame 1. It will have non-black pixels if it exists. Frame = NPCFrame.StandingFrame1; Texture2D tmp = npcSheet.GetNPCTexture(); Color[] tmpData = new Color[tmp.Width*tmp.Height]; tmp.GetData(tmpData); hasStandFrame1 = tmpData.Any(_c => _c.R != 0 || _c.G != 0 || _c.B != 0); //get the first non-transparent pixel to determine offsets for name labels and damage counters Frame = NPCFrame.Standing; tmp = npcSheet.GetNPCTexture(); tmpData = new Color[tmp.Width*tmp.Height]; tmp.GetData(tmpData); int i = 0; while (i < tmpData.Length && tmpData[i].A == 0) i++; TopPixel = i == tmpData.Length - 1 ? 0 : i/tmp.Height; } //this block throws errors sometimes..no idea why. Keep looping until it works. catch (InvalidOperationException) { success = false; tries++; } } while (!success && tries < 3); if(tries >= 3) throw new InvalidOperationException("Something weird happened initializing this NPC."); m_chatBubble = new EOChatBubble(this); m_damageCounter = new DamageCounter(this, GetType()); }
public override void Initialize() { base.Initialize(); sb = new SpriteBatch(GraphicsDevice); Frame = NPCFrame.Standing; baseFrame = npcSheet.GetNPCTexture(); npcArea = new Rectangle(0, 0, baseFrame.Width, baseFrame.Height); DrawArea = new Rectangle( offX + 320 - World.Instance.MainPlayer.ActiveCharacter.OffsetX - (int)((baseFrame.Width / 6.4) * 3.2), offY + 168 - World.Instance.MainPlayer.ActiveCharacter.OffsetY - baseFrame.Height, npcArea.Width, npcArea.Height); Walking = false; walkTimer = new Timer(_walkCallback, null, Timeout.Infinite, Timeout.Infinite); Attacking = false; attackTimer = new Timer(_attackCallback, null, Timeout.Infinite, Timeout.Infinite); m_chatBubble.Initialize(); m_chatBubble.LoadContent(); }