using RimWorld;
using Verse;

namespace LTF_Crystal_Lockdowner
{
    [StaticConstructorOnStartup]
    public static class LockdownerUtility
    {
        private const float defaultFireSize = 0.5f;
        //private static Graphic graphicInt;

        public static IntVec3 Behind(Pawn pawn)
        {
            //IntVec3 offset = new IntVec3(0,0,0);
            IntVec3 offset;// = null;
            int x, y, z;
            x = 0;y = 0; z = 0;

            if (pawn.Rotation == Rot4.North)
            {
                x = 1;
                
            }else if (pawn.Rotation == Rot4.South)
            {
                x = -1;
            }
            else if (pawn.Rotation == Rot4.West)
            {
                z = 1;
            }
            else if (pawn.Rotation == Rot4.East)
            {
                z = -1;
            }
            else
            {
                Log.Warning("wtf rot");
                
            }
            offset = new IntVec3(x,y,z);

            return (pawn.Position + offset);

            //return null;
        }

        public static void CreateLockBlocks(Thing hitThing)
        {
            Log.Warning("CreateLockBlocks");
            IntVec3 destinationCell = hitThing.Position;

            //actor
            Pawn lockDowner;
            lockDowner = destinationCell.GetFirstPawn(hitThing.Map);

            // block
            Building lockBlock = (Building)ThingMaker.MakeThing(ThingDef.Named("LTF_LockdownBlock"), null);
            lockBlock.SetColor(lockDowner.DrawColor);
            //lockDowner.Rotation

            GenSpawn.Spawn( lockBlock, Behind(lockDowner), Find.VisibleMap, Rot4.North, false);

            //lockDowner.Position.
            /*
            Fire fire = (Fire)ThingMaker.MakeThing(ThingDefOf.Fire, null);
            fire.fireSize = defaultFireSize;
            if (hitThing != null)
            {
                if (hitThing is Pawn) hitThing.TryAttachFire(defaultFireSize);
                else GenSpawn.Spawn(fire, hitThing.Position, Find.VisibleMap, Rot4.North, false);
            }
            else
            {
                GenSpawn.Spawn(fire, destinationCell, Find.VisibleMap, Rot4.North, false);
            }
            */
        }

        /*
        public static Graphic XenarrowGraphic
        {
            get
            {
                if (graphicInt == null)
                {
                    GraphicData graphicData = new GraphicData()
                    {
                        texPath = "Projectile/Xenarrow",
                        graphicClass = typeof(Graphic_Single),
                        shaderType = ShaderType.TransparentPostLight
                    };
                    graphicInt = graphicData.Graphic;
                }
                return graphicInt;
            }
        }
        */
    }

}