Пример #1
0
 /// <summary>
 /// 判定是否对于其他事件可通行,会处理事件的目标位置
 /// </summary>
 /// <returns><c>true</c>, if pre passable was ised, <c>false</c> otherwise.</returns>
 /// <param name="polygon">Polygon.</param>
 /// <param name="character">Character.</param>
 public bool isPreOtherEventsPassable(Intersection.Polygon polygon, GameCharacterBase character)
 {
     if (character.through)
     {
         return(true);
     }
     // 检测事件通行
     foreach (GameEvent e in this.events)
     {
         Intersection.Polygon eventTargetCollider = e.targetCollider();
         if (e.through == false && Intersection.polygonPolygon(eventTargetCollider, polygon))
         {
             if (character.GetType() == typeof(GameEvent))
             {
                 GameEvent eChar = (GameEvent)character;
                 if (!e.erased && !e.through && e.priorityType == GameCharacterBase.PRIORITIES.SAME && e.isPageActive() && character != e &&
                     !eChar.erased && !eChar.through && eChar.priorityType == GameCharacterBase.PRIORITIES.SAME)
                 {
                     return(false);
                 }
             }
             else
             {
                 if (!e.erased && !e.through && e.priorityType == GameCharacterBase.PRIORITIES.SAME && e.isPageActive() && character != e)
                 {
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Пример #2
0
 public void updateCurrPos()
 {
     // 刷新镜头移动
     if (this.isTargetingToPos())            // 移向位置
     {
         this.targetToFrame += 1;
         this.currTargetPos  = Vector2.Lerp(this.targetPositionFrom, this.targetPositionTo, 1.0f * this.targetToFrame / this.targetToDuration);
         if (this.targetToFrame == this.targetToDuration)
         {
             this.targetToDuration = -1;
         }
     }
     else
     {
         // 跟随角色
         if (this.targetToGameObject >= 0)
         {
             if (this.targetToGameObject == 0)                       // 跟随主角
             {
                 this.currTargetPos = new Vector2(GameTemp.gamePlayer.screenX(), GameTemp.gamePlayer.screenY());
             }
             else                            // 跟随事件
             {
                 GameCharacterBase character = GameTemp.gameMap.getCharacter(this.targetToGameObject);
                 this.currTargetPos = new Vector2(character.screenX(), character.screenY());
             }
         }
     }
 }
Пример #3
0
    /// <summary>
    /// 209 设置移动路线
    /// lua移动指令
    /// 移动对象
    /// 是否等待结束
    /// </summary>
    /// <returns></returns>
    public bool command_moveByRoute()
    {
        XLua.LuaTable scriptEnv = LuaManager.getInterpreterEnvTable(this);

        Debug.Log("route:");
        Debug.Log(this.currentParam[0]);

        object[] result = LuaManager.LuaEnv.DoString(this.currentParam[0], string.Format("command_move_by_route_{0}", this.eventId), scriptEnv);

        // 移动对象
        GameCharacterBase character = this.getCharacter(int.Parse(this.currentParam[1]));

        // 是否等待移动结束
        if (bool.Parse(this.currentParam[2]))
        {
            this.movingCharacter = character;
        }

        // 处理移动指令
        List <MoveRoute> list = new List <MoveRoute>();

        for (int i = 0; i < ((XLua.LuaTable)result[0]).Length; i += 1)
        {
            MoveRoute route = ((XLua.LuaTable)result[0]).Get <int, MoveRoute>(i + 1);
            route.args.Add(this.currentParam[1]);               // 操作的事件id
            route.args.Add(this.eventId.ToString());            // 当前解释器所属事件id
            list.Add(route);
            Debug.Log(route);
        }

        character.setMoveRoute(list);

        return(true);
    }
Пример #4
0
 /// <summary>
 /// 是否和人物重合
 /// </summary>
 /// <returns><c>true</c>, if over char, <c>false</c> otherwise.</returns>
 /// <param name="character">Character.</param>
 public virtual bool isOverChar(GameCharacterBase character)
 {
     Intersection.Polygon eventCollider = character.currMidCollider();
     if (Intersection.polygonPolygon(eventCollider, this.currMidCollider()))
     {
         return(true);
     }
     return(false);
 }
Пример #5
0
    public void clear()
    {
        this.mapName          = "";                             // 启动时的地图id
        this.origEventId      = 0;                              // 启动时的事件id
        this.eventId          = 0;                              // 事件id
        this.list             = null;                           // 执行内容
        this.eventPageForList = -1;
        this.index            = 0;                              // 当前指令索引
        this.lastLoopIndex    = 0;                              // 上一个循环开始指令索引
        this.gotoMarks        = new Dictionary <string, int>(); //标签跳转索引记录
        this.messageWaiting   = false;                          // 等待文章结束
        this.choiceWaiting    = false;                          // 等待选择项
        this.movingCharacter  = null;                           // 等待移动结束
        this.waitCount        = 0;                              // 等待帧数
        this.childInterpreter = null;                           // 子解释器(公共事件)

        this.currentCode = 0;
    }
Пример #6
0
    /// <summary>
    /// 返回面向的格子事件ID
    /// </summary>
    /// <returns></returns>
    public int getFaceToEventId(GameCharacterBase character)
    {
        GameEvent result = null;
        float     step   = GameTemp.gamePlayer.getStep() * 2;

        Intersection.Polygon   testPolygon = character.currCollider();
        GameCharacterBase.DIRS dir         = character.direction;
        if (dir == GameCharacterBase.DIRS.DOWN)
        {
            testPolygon = Intersection.polygonMove(testPolygon, 0, -step);
        }
        if (dir == GameCharacterBase.DIRS.LEFT)
        {
            testPolygon = Intersection.polygonMove(testPolygon, -step, 0);
        }
        if (dir == GameCharacterBase.DIRS.RIGHT)
        {
            testPolygon = Intersection.polygonMove(testPolygon, step, 0);
        }
        if (dir == GameCharacterBase.DIRS.UP)
        {
            testPolygon = Intersection.polygonMove(testPolygon, 0, step);
        }
        List <GameEvent> events = new List <GameEvent>();

        foreach (GameEvent e in this.events)
        {
            Intersection.Polygon eventCollider = e.currCollider();
            if (Intersection.polygonPolygon(eventCollider, testPolygon))
            {
                if (!e.erased && !e.Equals(character))
                {
                    events.Add(e);
                }
            }
        }
        if (events.Count > 0)
        {
            result = events[(new System.Random()).Next(events.Count)];
            return(result.eventId);
        }
        return(0);
    }
Пример #7
0
    /// <summary>
    /// 向指定角色移动
    /// </summary>
    /// <returns><c>true</c>, if towards was moved, <c>false</c> otherwise.</returns>
    /// <param name="charId">Char identifier.</param>
    public bool moveTowards(int charId)
    {
        GameCharacterBase character = GameTemp.gameMap.interpreter.getCharacter(charId);
        float             targetX   = character.realX;
        float             targetY   = character.realY;
        float             offsetX   = Mathf.Abs(targetX - this.realX);
        float             offsetY   = Mathf.Abs(targetY - this.realY);
        DIRS dir = DIRS.NONE;

        if (this.isPassable(this.realX, this.realY, DIRS.UP) &&
            this.isPassable(this.realX, this.realY, DIRS.DOWN) &&
            this.isPassable(this.realX, this.realY, DIRS.LEFT) &&
            this.isPassable(this.realX, this.realY, DIRS.RIGHT))
        {
            // 四面无障碍
            if (offsetX > offsetY)
            {
                if (this.realX < targetX)
                {
                    dir = DIRS.RIGHT;
                }
                else
                {
                    dir = DIRS.LEFT;
                }
            }
            else
            {
                if (this.realY < targetY)
                {
                    dir = DIRS.UP;
                }
                else
                {
                    dir = DIRS.DOWN;
                }
            }
        }
        else
        {
            if (offsetX > offsetY && (new System.Random()).Next(100) > 30)
            {
                if (this.realX < targetX)
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.RIGHT;
                    }
                    else
                    {
                        dir = DIRS.LEFT;
                    }
                }
                else
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.LEFT;
                    }
                    else
                    {
                        dir = DIRS.RIGHT;
                    }
                }
            }
            else
            {
                if (this.realY < targetY)
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.UP;
                    }
                    else
                    {
                        dir = DIRS.DOWN;
                    }
                }
                else
                {
                    if ((new System.Random()).Next(100) > 20)
                    {
                        dir = DIRS.DOWN;
                    }
                    else
                    {
                        dir = DIRS.UP;
                    }
                }
            }
        }
        return(this.moveGridStraight(dir));
    }
Пример #8
0
    /// <summary>
    /// 判断碰撞盒是否可通行
    /// </summary>
    /// <param name="polygon"></param>
    /// <param name="character"></param>
    /// <param name="isPlayerStep">判定玩家的行走</param>
    /// <returns></returns>
    public bool isPassable(Intersection.Polygon polygon, GameCharacterBase character)
    {
        if (character.through)
        {
            return(true);
        }
        // 检测图块通行
        foreach (Intersection.Polygon mapCollider in this.mapInfo.passageColliders)
        {
            if (Intersection.polygonPolygon(mapCollider, polygon))
            {
                return(false);
            }
        }
        // 检测事件通行
        character.lastHit.Clear();
        foreach (GameEvent e in this.events)
        {
            Intersection.Polygon eventCollider = e.currCollider();
            if (e.through == false && Intersection.polygonPolygon(eventCollider, polygon))
            {
                if (character != null && character != e && !e.erased && !character.lastHit.Contains(e))
                {
                    character.lastHit.Add(e);
                }

                if (character.GetType() == typeof(GameEvent))
                {
                    GameEvent eChar = (GameEvent)character;
                    if (!e.erased && !e.through && e.priorityType == GameCharacterBase.PRIORITIES.SAME && e.isPageActive() && character != e &&
                        !eChar.erased && !eChar.through && eChar.priorityType == GameCharacterBase.PRIORITIES.SAME)
                    {
                        return(false);
                    }
                }
                else
                {
                    if (!e.erased && !e.through && e.priorityType == GameCharacterBase.PRIORITIES.SAME && e.isPageActive() && character != e)
                    {
                        return(false);
                    }
                }
            }
        }
        // 检查事件碰到主角
        if (character.GetType() == typeof(GameEvent))
        {
            Intersection.Polygon playerCollider = GameTemp.gamePlayer.currCollider();
            GameEvent            e = (GameEvent)character;
            if (e.through == false && Intersection.polygonPolygon(playerCollider, polygon))
            {
                if (e != null && !e.erased && !e.lastHit.Contains(GameTemp.gamePlayer))
                {
                    e.lastHit.Add(GameTemp.gamePlayer);
                    if (!GameTemp.gamePlayer.lastHit.Contains(e))
                    {
                        GameTemp.gamePlayer.lastHit.Add(e);                             // 给玩家碰撞数据加上本事件
                    }
                }
                if (!e.erased && !e.through && e.isPageActive() && e.priorityType == GameCharacterBase.PRIORITIES.SAME)
                {
                    return(false);
                }
            }
        }
        return(true);
    }
Пример #9
0
 public void update()
 {
     while (true)                                                 // while跳过无用指令
     {
         if (!GameTemp.gameMap.mapInfo.name.Equals(this.mapName)) // 地图和启动地图有差异
         {
             this.eventId = 0;
         }
         // 公共事件处理
         if (this.childInterpreter != null)
         {
             this.childInterpreter.update();
             if (!this.childInterpreter.isRunning())
             {
                 this.childInterpreter = null;
             }
             // 公共事件仍在执行则退出当前事件解释
             if (this.childInterpreter != null)
             {
                 return;
             }
         }
         if (this.messageWaiting)    // 文章显示中
         {
             return;
         }
         if (this.choiceWaiting)
         {
             return;
         }
         if (this.movingCharacter != null)   // 等待移动
         //Debug.Log(string.Format("this.movingCharacter.isForcedMoving() {0}", this.movingCharacter.isForcedMoving()));
         {
             if (this.movingCharacter.isForcedMoving())    // 移动中
             {
                 return;
             }
             this.movingCharacter = null;
         }
         if (this.waitCount > 0)     // 等待n帧
         {
             this.waitCount -= 1;
             return;
         }
         // 执行相关
         if (this.list == null)
         {
             if (this.isMain)
             {
                 // 尝试启动地图事件
                 this.setupStartingEvent();
             }
             if (this.list == null)
             {
                 // 没有可启动的事件
                 return;
             }
         }
         else
         {
             if (!this.executeCmd())     // 执行并前往下一个指令
             {
                 return;
             }
             this.index += 1;
         }
     }
 }