
using System;
using PlanetExpress.items.weapon;
using System.IO;
using System.Collections.Generic;
using Math2D;
using Math2D.Shapes;

namespace PlanetExpress.items {
	
	
	public class PersonClass : CustomGameObject {
		
		public PersonClass() : base() {
			Weapon = new CustomWeapon(this);
			Weapon2 = new CustomWeapon(this);
		}
		
		public override bool Action (double time) {
			base.Action(time);
			Weapon.Action(time);
			Weapon2.Action(time);
			return false;
		}

		private CustomWeapon FWeapon;
		public CustomWeapon Weapon {
			get { return FWeapon;}
			set { FWeapon = value; }
		}
		
		private CustomWeapon FWeapon2;
		public CustomWeapon Weapon2 {
			get { return FWeapon2;}
			set { FWeapon2 = value; }
		}
		
		public virtual bool Shoot() {
			return Weapon.Shoot(X, Y, 0f);
		}
		
		public virtual bool Shoot2() {
			return Weapon2.Shoot(X, Y, 0f);
		}
		
		protected override Polygon2D[] GetShape () {
			Polygon2D[] map = new Polygon2D[BaseMap.Length];
			Matrix2D m = GetMapTransformation();
			for (int i=0; i<BaseMap.Length; i++) {
				map[i] = BaseMap[i] * m;
			}
			return map;
		}

		
		protected virtual Matrix2D GetMapTransformation() {
			return  Matrix2D.GetInitIdent();
		}
		
		protected Polygon2D[] BaseMap = new Polygon2D[0];
		
		protected void LoadMap(string manFileName) {
			FileStream fs = new FileStream(manFileName, FileMode.Open);
			BinaryReader br = new BinaryReader(fs);
			int count = br.ReadInt32();
			Polygon2D[] map = new Polygon2D[count];
			for (int i=0; i<count; i++) {
				float x1 = br.ReadInt32();
				float y1 = br.ReadInt32();
				float x2 = br.ReadInt32();
				float y2 = br.ReadInt32();
				float x3 = br.ReadInt32();
				float y3 = br.ReadInt32();
				map[i] = new Polygon2D(
				                       new Vector2D(x1, y1),
				                       new Vector2D(x2, y2),
				                       new Vector2D(x3, y3));				
				
			}	
			BaseMap = map;
			fs.Close();
		}
	}
}
