package com.Tutorial
{
    import com.adamatomic.flixel.*;
    public class NPC extends FlxSprite
    {
        [Embed(source = '../../data/gfx/npcs.png')] private var ImgNPCs:Class;

	    [Embed(source = '../../data/dice.txt', mimeType = "application/octet-stream")] static private var DiceDat:Class;

        private var _move_speed:int = 400;
        private var _jump_power:int = 800;   
        private var _max_health:int = 10;
        private var _hurt_counter:Number = 0;
		public var npcIndex:int;
		public var ownername:String;
		public var diename:String;
		public var conv:Array;
		public var nums:String;
		public var beats:int;
		public var hates:int;
        
        public function NPC(X:Number,Y:Number,Num:int):void
        {
			npcIndex = Num;
			refreshdat();
			
			super(ImgNPCs, X, Y, true, true);//Max speeds
            maxVelocity.x = 200;
            maxVelocity.y = 200;
            health = 1;
            acceleration.y = 0;
            drag.x = 300;
            width = 16;
            height = 16;
            offset.x = 0;
            offset.y = 0;
            addAnimation("empty", [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32], 0,false);
			play("empty");
			this.specificFrame(Num);
			this._curFrame = Num;
			this.update();
        }
		
		public function refreshdat():void
		{
			conv = new Array();
			diename = new String();
			ownername = new String();
			nums = new String();
			
			var cols:Array;
			var dicedat:String = new DiceDat;
			var rows:Array = dicedat.split("\n");
			cols = rows[npcIndex].split(",");
			
			nums = cols[1];
			diename = cols[2];
			ownername = cols[3];
			if (cols[4]!="X")
				beats = int(cols[4]);
			else
				beats = -1;
				
			if (cols[5] != "X")
				hates = int(cols[5]);
			else
				hates = -1;
			
			for (var i:int = 6; i < cols.length; i++)
			{
				conv.push(cols[i]);
			}							
			
		}
		
		public function changeframe(n:int):void
		{			
			npcIndex = n;
			this.specificFrame(n);
			this._curFrame = n;
			refreshdat();
			this.update();
		}
        override public function update():void
        {
            if(dead)
            {
                if(finished) exists = false;
                else
                    super.update();
                return;
            }            			
			
            super.update();
        }       
		
		public function description():String
		{
			
			trace("index", npcIndex);
			
			var s:String;
			s = new String;
			
			s += diename + "\n";
			s += nums + "\n";
			if (!FlxG.hasdie[npcIndex])
			{
				s += "[ Don't Have ]\n";
			}
			s += "Fears:\n";
			if (hates == -1)
			{
				s += " No One\n";
			}
			else
			{
				s += " " + (new NPC(0, 0, hates)).diename+"\n";
			}
			s += "Strong vs:\n";
			if (beats == -1)
			{
				s += " No One\n";
			}
			else
			{
				s += " " + (new NPC(0, 0, beats)).diename+"\n";
			}
			
			return s;
		}
        
    }
}