Exemplo n.º 1
0
 public static GameInterpreter getInstance()
 {
     if (instance == null)
     {
         GameObject obj = new GameObject("Game Interpreter");
         instance = obj.AddComponent <GameInterpreter>();
     }
     return(instance);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Initialise le mode de jeu de la scène.
        /// </summary>
        void InitializeGameMode()
        {
            if (m_skipPicks)
            {
                // Charge le contrôleur humain.

                /*Entities.EntityHero hero = new EntityHero() { Position = new Vector2(25, 25), Type = EntityType.Team1Player, Role = EntityHeroRole.Fighter, BaseMaxHP = 50000, HP = 50000 };
                 * Server.Controlers.HumanControler humanControler = new Server.Controlers.HumanControler(hero) { HeroName = "Test" };
                 * m_clientIdToControlerId.Add(hero.ID, 0);
                 * Controlers.Add(0, humanControler);*/
            }

            // Création de la map.
            Map = new Map();
            Map.Initialize();

            // Création de l'event scheduler.
            EventSheduler = new Scheduler();


            // Charge les variables dans l'interpréteur.
            GameInterpreter.MainContext.LocalVariables.Add("map", new PonyCarpetExtractor.ExpressionTree.Mutable(GameServer.GetMap()));
            GameInterpreter.MainContext.LocalVariables.Add("scene", new PonyCarpetExtractor.ExpressionTree.Mutable(GameServer.GetScene()));
            // GameInterpreter.MainContext.LocalVariables.Add("ctrl", new PonyCarpetExtractor.ExpressionTree.Mutable(Controlers[0]));
            GameInterpreter.Eval("print = function(arg) { Interpreter.Puts(arg); };");


            // Chargement des héros à partir des contrôleurs loggués.
            LoadPlayers();
            __initDone = true;
            // Création du système de récompenses.
            RewardSystem = new RewardSystem(Map.Heroes);

            // Chargement de la map.
            MapFile loaded = MapFile.FromFile(Ressources.MapFilename);

            Map.Load(loaded);

            if (m_skipPicks)
            {
                // Démarre le serveur de commandes.
                CommandServer.Start();
            }



            // DEBUG

            /*Map.Heroes[0].Weapon = new Equip.Weapon(Map.Heroes[0], GameServer.GetScene().ShopDB.Weapons.First());
             * Map.Heroes[0].Armor = new Equip.Armor(Map.Heroes[0], GameServer.GetScene().ShopDB.Armors.First());
             * Map.Heroes[0].Boots = new Equip.Boots(Map.Heroes[0], GameServer.GetScene().ShopDB.Boots.First());*/
        }
Exemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     gameObject.GetInstanceID();
     if (instance != null && instance != this)
     {
         Destroy(this);
     }
     else
     {
         instance        = this;
         commandsToParse = new Queue <Command>();
     }
 }
Exemplo n.º 4
0
    /// <summary>
    /// 启动事件页
    /// </summary>
    /// <param name="page"></param>
    public void setupPage(int page)
    {
        Debug.Log(string.Format("setupPage {0}", page));
        this.page = page;
        if (this.page == -1)
        {
            this.list          = null;
            this.interpreter   = null;
            this.characterName = "";    // 清理图像
        }
        else
        {
            // 显示控制
            EventPage[] pages = this.getEventSprite().GetComponentsInChildren <EventPage>(true);

            // 只显示本页对应精灵
            EventPage currPage = pages[page];
            this.characterName = currPage.characterName;
            this.direction     = currPage.direction;
            Debug.Log(string.Format("curr char pattern {0}", this.pattern));
            this.pattern = currPage.pattern;
            Debug.Log(string.Format("curr char pattern {0}", this.pattern));
            this.priorityType  = currPage.priorityType;
            this.through       = currPage.through;
            this.moveSpeed     = currPage.moveSpeed;
            this.moveFrequency = currPage.moveFrequency;
            this.walkAnime     = currPage.walkAnime;
            this.stepAnime     = currPage.stepAnime;
            this.directionFix  = currPage.directionFix;
            this.list          = this.getCommands(page);
            this.trigger       = this.getPageInfo(page).trigger;
            this.isDirty       = true;
            // 注册光效
            GameTemp.gameScreen.registerLight(this.eventId, currPage.lightType);
            // 并行解释器
            if (this.trigger == GameInterpreter.TriggerTypes.Async)
            {
                // 并行处理:
                this.interpreter = new GameInterpreter(0, false);
            }
            else
            {
                this.interpreter = null;
            }
        }
    }
Exemplo n.º 5
0
    public static XLua.LuaTable getInterpreterEnvTable(GameInterpreter interpreter)
    {
        XLua.LuaTable scriptEnv = LuaManager.LuaEnv.NewTable();
        // 为每个脚本设置一个独立的环境,可一定程度上防止脚本间全局变量、函数冲突
        XLua.LuaTable meta = LuaManager.LuaEnv.NewTable();
        meta.Set("__index", LuaManager.LuaEnv.Global);
        scriptEnv.SetMetaTable(meta);
        meta.Dispose();

        scriptEnv.Set("self", interpreter);
        scriptEnv.Set("gameVariables", GameTemp.gameVariables);
        scriptEnv.Set("gameSwitches", GameTemp.gameSwitches);
        scriptEnv.Set("gameSelfSwitches", GameTemp.gameSelfSwitches);
        scriptEnv.Set("gamePlayer", GameTemp.gamePlayer);
        scriptEnv.Set("gameMap", GameTemp.gameMap);

        return(scriptEnv);
    }
Exemplo n.º 6
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;
    }
Exemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     if (instance != null && instance != this)
     {
         Destroy(this);
     }
     else
     {
         instance = this;
         gameObject.SetActive(false);                            // this object starts out disabled
         gameInterpreter      = GameInterpreter.getInstance();
         commandLineText      = GetComponentInChildren <Text>(); // get the text object to hold the text
         commandLineText.text = cliPromptText;                   // set the text to start with the prompt text
         scrollbar            = GetComponentInChildren <ScrollRect>();
         canvas                  = GetComponentInParent <Canvas>();
         commandHistory          = ""; // set history empty string
         terminationCharacterStr = new string(new char[] { terminationCharacter });
     }
 }
Exemplo n.º 8
0
    /// <summary>
    /// 117 调用公共事件
    /// 名称/编号,优先使用编号,编号从1开始
    /// </summary>
    /// <returns></returns>
    public bool command_commonEvent()
    {
        int cmdId = 0;
        List <EventCommand> cmdList = null;

        int.TryParse(this.currentParam[0], out cmdId);
        if (cmdId > 0)
        {
            cmdId   = cmdId - 1; // 转为从0开始的编号
            cmdList = ((SceneMap)SceneManager.Scene).getCommonEventCmd(cmdId);
        }
        else
        {
            cmdList = ((SceneMap)SceneManager.Scene).getCommonEventCmd(this.currentParam[0], out cmdId);
        }
        // 生成子解释器
        this.childInterpreter = new GameInterpreter(this.depth + 1, false);
        this.childInterpreter.setup(cmdList, this.eventId, cmdId);
        return(true);
    }
 // Use this for initialization
 void Start()
 {
     isCliActivated  = false;
     gameInterpreter = GameInterpreter.getInstance();
 }
Exemplo n.º 10
0
    /// <summary>
    /// 读取地图信息
    /// </summary>
    /// <param name="tilemapNode"></param>
    public void setupMap(GameObject tilemapNode, bool isLoad = false)
    {
        this.mapName = tilemapNode.name;

        tilemapNode.transform.Find(layers[0]).GetComponent <Tilemap>().CompressBounds();
        int minX = tilemapNode.transform.Find(layers[0]).GetComponent <Tilemap>().cellBounds.xMin;
        int minY = tilemapNode.transform.Find(layers[0]).GetComponent <Tilemap>().cellBounds.yMin;
        int maxX = tilemapNode.transform.Find(layers[0]).GetComponent <Tilemap>().cellBounds.xMax;
        int maxY = tilemapNode.transform.Find(layers[0]).GetComponent <Tilemap>().cellBounds.yMax;

        foreach (string layerName in layers)
        {
            tilemapNode.transform.Find(layerName).GetComponent <Tilemap>().CompressBounds();
            minX = Mathf.Min(minX, tilemapNode.transform.Find(layerName).GetComponent <Tilemap>().cellBounds.xMin);
            minY = Mathf.Min(minY, tilemapNode.transform.Find(layerName).GetComponent <Tilemap>().cellBounds.yMin);
            maxX = Mathf.Max(maxX, tilemapNode.transform.Find(layerName).GetComponent <Tilemap>().cellBounds.xMax);
            maxY = Mathf.Max(maxY, tilemapNode.transform.Find(layerName).GetComponent <Tilemap>().cellBounds.yMax);
            Debug.Log(string.Format("min x {0}, layer:{1}", tilemapNode.transform.Find(layerName).GetComponent <Tilemap>().cellBounds.xMin, layerName));
        }
        bool isNew = this.mapInfo == null || !tilemapNode.name.Equals(this.mapInfo.name);

        if (isNew)
        {
            this.mapInfo              = new MapInfo();
            this.mapInfo.name         = tilemapNode.name;
            this.mapInfo.minTile      = new Vector3Int(minX, minY, 0);
            this.mapInfo.maxTile      = new Vector3Int(maxX, maxY, 0);
            this.mapInfo.width        = maxX - minX;
            this.mapInfo.height       = maxY - minY;
            this.mapInfo.minTileWorld = tilemapNode.transform.Find(layers[0]).GetComponent <Tilemap>().CellToWorld(new Vector3Int(minX, minY, 0));
            this.mapInfo.maxTileWorld = tilemapNode.transform.Find(layers[0]).GetComponent <Tilemap>().CellToWorld(new Vector3Int(maxX, maxY, 0));
        }

        // 读取碰撞信息
        Tilemap passageLayer = tilemapNode.transform.Find(getLayerName(Layers.LayerPassage)).GetComponent <Tilemap>();

        passageLayer.color = new Color(0, 0, 0, 0);
        passageLayer.CompressBounds();
        Vector3Int min = passageLayer.cellBounds.min;
        Vector3Int max = passageLayer.cellBounds.max;

        this.mapInfo.passageColliders.Clear();
        for (int x = min.x; x < max.x; x += 1)
        {
            for (int y = min.y; y < max.y; y += 1)
            {
                if (passageLayer.GetTile(new Vector3Int(x, y, min.z)) != null)
                {
                    Vector3        worldPos = passageLayer.CellToWorld(new Vector3Int(x, y, min.z));
                    Vector3        size     = passageLayer.cellSize;
                    List <Vector2> points   = new List <Vector2>();
                    points.Add(new Vector2(worldPos.x, worldPos.y));
                    points.Add(new Vector2(worldPos.x, worldPos.y + size.y));
                    points.Add(new Vector2(worldPos.x + size.x, worldPos.y + size.y));
                    points.Add(new Vector2(worldPos.x + size.x, worldPos.y));
                    Intersection.Polygon polygon = new Intersection.Polygon(points);
                    this.mapInfo.passageColliders.Add(polygon);
                }
            }
        }

        if (!isLoad)  // 读取事件信息
        {
            Tilemap       eventLayer   = tilemapNode.transform.Find(getLayerName(Layers.LayerEvents)).GetComponent <Tilemap>();
            SpriteEvent[] spriteEvents = eventLayer.GetComponentsInChildren <SpriteEvent>();
            if (isNew)
            {
                this.events = new List <GameEvent>();
                int i = 0;
                foreach (SpriteEvent s in spriteEvents)
                {
                    this.events.Add((GameEvent)s.character);
                    ((GameEvent)s.character).setup(this.mapName, i + 1);
                    i += 1;
                }
            }
            else
            {
                int i = 0;
                foreach (SpriteEvent s in spriteEvents)
                {
                    s.setEvent(this.events[i]);
                    i += 1;
                }
            }

            // 初始化事件解释器
            this.interpreter = new GameInterpreter(0, true);

            this.refresh();
        }
        else
        {
            // 读档处理,使用读取的数据重置精灵内事件数据
            Tilemap       eventLayer   = tilemapNode.transform.Find(getLayerName(Layers.LayerEvents)).GetComponent <Tilemap>();
            SpriteEvent[] spriteEvents = eventLayer.GetComponentsInChildren <SpriteEvent>();
            int           i            = 0;
            foreach (SpriteEvent s in spriteEvents)
            {
                Debug.Log(string.Format("load event {0}", i + 1));
                s.setEvent(this.events[i]);
                this.events[i].loadInitSprite();
                // 恢复事件解释器
                if (i + 1 == this.interpreter.eventId)
                {
                    Debug.Log(string.Format("reset interpreter for event {0}, page {1}", this.interpreter.eventId, this.interpreter.eventPageForList));
                    this.events[i].loadCommands(this.interpreter.eventPageForList);
                    this.interpreter.loadList(this.events[i].list);
                }
                else
                {
                    this.events[i].loadCommands(this.events[i].page);
                }
                // 重置事件的并行解释器调用公共事件部分的数据
                this.events[i].loadInterpreterCommonEventList();
                i += 1;
            }
            // 读档后重置公共事件解释器数据
            if (this.interpreter.childInterpreter != null)
            {
                this.interpreter.childInterpreter.loadList(
                    ((SceneMap)SceneManager.Scene).getCommonEventCmd(this.interpreter.childInterpreter.eventPageForList)
                    );
            }
        }

        Debug.Log(string.Format("setup map {0}", this.mapInfo));
    }
Exemplo n.º 11
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;
         }
     }
 }