Esempio n. 1
0
        public NPC(Map map, Vector2 pos, string name)
            : base(map, pos, name)
        {
            switch (name)
            {
            case "Lilis":
                this.texture = ResourceController.Characters_Lilis;
                break;

            case "Olivia":
                this.texture = ResourceController.Characters_Olivia;
                break;

            case "Sabina":
                this.texture = ResourceController.Characters_Sabina;
                break;

            default:
                break;
            }
            this.renderRectangle = new Rectangle(frame * 2 * Define.UnitOFpixel, (anim * 16 + direct * 4) * Define.UnitOFpixel, 2 * Define.UnitOFpixel, 4 * Define.UnitOFpixel);
            //this.connectNPC = NPC.NULL;
            this.playerCollideTime        = 0;
            this.ifplayerCollideProtect   = false;
            this.playerCollideProtectTime = 0;
            this.movingCollide            = false;
            this.movingCollideTime        = 0;
            this.movingProtect            = false;
            this.idleTime           = 0;
            this.thinkTime          = 0;
            this.emotion            = string.Empty;
            this.pathArray          = new int[] { };
            this.targetMapTemporary = new Vector2();
            nT = new GlobalController.NpcTrigger();
        }
Esempio n. 2
0
 void MoveByPath(int time)
 {
     if (this.targetPosition.Map.Name == this.map.Name)
     {
         if ((int)(this.position.X / Define.UnitOFpixel) == (int)(this.targetPosition.Position.X / Define.UnitOFpixel) && (int)(this.position.Y / Define.UnitOFpixel) == (int)(this.targetPosition.Position.Y / Define.UnitOFpixel))
         {
             this.action = "idle";
             Random ran = new Random();
             idleTime    = ran.Next(3000, 10000);
             this.direct = this.targetPosition.Direct;
             this.anim   = 0;
             this.frame  = 0;
         }
         else
         {
             if (this.path.Count == 0)
             {
                 if (GlobalController.NpcSceneCollide.Count > 0)
                 {
                     FindPath(new Vector2((int)TargetPosition.Position.X / Define.UnitOFpixel, (int)TargetPosition.Position.Y / Define.UnitOFpixel));
                 }
             }
             else if (0 < this.path.Count)
             {
                 Vector2 tPos;
                 if (this.position == new Vector2(this.path[1].pos.X * 24, this.path[1].pos.Y * 24))
                 {
                     this.path.RemoveAt(0);
                     tPos = this.path[1].pos;
                 }
                 else
                 {
                     tPos = this.path[1].pos;
                 }
                 if (this.position.X < tPos.X * 24)
                 {
                     ActionMove(time, 2);
                 }
                 else if (this.position.X > tPos.X * 24)
                 {
                     ActionMove(time, 1);
                 }
                 if (this.position.Y < tPos.Y * 24)
                 {
                     ActionMove(time, 0);
                 }
                 else if (this.position.Y > tPos.Y * 24)
                 {
                     ActionMove(time, 3);
                 }
             }
             else
             {
                 closeList.Clear();
                 openList.Clear();
                 this.path.Clear();
                 this.FindingPath = false;
             }
         }
     }
     else
     {
         if ((int)(this.position.X / Define.UnitOFpixel) == (int)this.targetMapTemporary.X && (int)((this.position.Y) / Define.UnitOFpixel) == (int)this.targetMapTemporary.Y)
         {
             this.map = Map.GetMapByID(this.pathArray[0]);
             ArrayList al = new ArrayList(this.pathArray);
             al.RemoveAt(0);
             this.pathArray          = (int[])al.ToArray(typeof(int));
             this.targetMapTemporary = Vector2.Zero;
             this.path.Clear();
             this.position = this.nT.targetPosition * Define.UnitOFpixel;
             this.nT       = new GlobalController.NpcTrigger();
         }
         else
         {
             if (this.pathArray.Length == 0)
             {
                 this.pathArray = GlobalController._Cv_func._Npc_MapWeighted(this.map, this.targetPosition.Map);
             }
             else if (this.path.Count == 0)
             {
                 Map tMap = Map.GetMapByID(this.pathArray[0]);
                 foreach (GlobalController.NpcTrigger nT in GlobalController.NpcTriggerList)
                 {
                     if (nT.targetMap.Name == tMap.Name && nT.currentMap.Name == this.map.Name)
                     {
                         this.nT = nT;
                         this.targetMapTemporary = nT.position;
                         break;
                     }
                 }
                 FindPath(this.targetMapTemporary);
             }
             else if (0 < this.path.Count)
             {
                 Vector2 tPos;
                 if (this.position == new Vector2(this.path[1].pos.X * 24, this.path[1].pos.Y * 24))
                 {
                     this.path.RemoveAt(0);
                     tPos = this.path[1].pos;
                 }
                 else
                 {
                     tPos = this.path[1].pos;
                 }
                 if (this.position.X < tPos.X * 24)
                 {
                     ActionMove(time, 2);
                 }
                 else if (this.position.X > tPos.X * 24)
                 {
                     ActionMove(time, 1);
                 }
                 if (this.position.Y < tPos.Y * 24)
                 {
                     ActionMove(time, 0);
                 }
                 else if (this.position.Y > tPos.Y * 24)
                 {
                     ActionMove(time, 3);
                 }
             }
             else
             {
                 closeList.Clear();
                 openList.Clear();
                 this.path.Clear();
                 this.FindingPath = false;
             }
         }
     }
 }