using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Assets.Scripts.Network
{
    public struct PlayerUpdate
    {
        public Vector2 Position;
        public Vector2 Direction;
        public float Orientation;
        public float Time;
    }

    public class Player : WorldObject
    {
        public Player() : base()
        {
            Type = WorldObjectType.wotPlayer;
            FlashLight.DrainRate = WorldConfig.FlashLightDischargeRate;
        }

        public IList<PlayerUpdate> Updates = new List<PlayerUpdate>();

        public Color PlayerColor = Color.red;
        public DrainableResource FlashLight = new DrainableResource();
        public IList<Crystal> Crystals = new List<Crystal>();
        public int CrystalCapacity = 1;
        public bool IsInHome = false;
        public Vector2 Direction = new Vector2();

        public bool IsMe()
        {
            return ID == World.MyID;
        }

        public float Speed = 20;
        private bool IsMoving = false;

        public override void UpdateAssignedObject( float FrameTime )
        {
            if( Moved )
            {
                if( !IsMoving )
                {
                    IsMoving = true;
                    Manager._.WorldEvent.Invoke(this, Manager.WorldEventTypes.wetPlayerMovingStart);
                }
            }
            else
            {
                if (IsMoving)
                {
                    IsMoving = false;
                    Manager._.WorldEvent.Invoke(this, Manager.WorldEventTypes.wetPlayerMovingStop);
                }
            }
            base.UpdateAssignedObject(FrameTime);
            FlashLight.Update(FrameTime);
        }
    }
}
