Ejemplo n.º 1
0
    public void IncrementPartOption()
    {
        int maxPartIndex;

        maxPartIndex = inventory.inventoryParts[types[partTypeIndex]].Length - 1;

        // Destroy children of current part
        foreach (Transform part in avatarParts[partTypeIndex])
        {
            Destroy(part.gameObject);
        }

        if (partIndices[partTypeIndex] < maxPartIndex)
        {
            partIndices[partTypeIndex]++;
        }

        else
        {
            partIndices[partTypeIndex] = 0;
        }

        // Instantiate new children in parent GameObject
        GameObject bodyPart = Instantiate(
            inventory.partForTypeIndex(types[partTypeIndex], partIndices[partTypeIndex]),
            avatarParts[partTypeIndex],
            false);

        // Disable if current option is null
        UpdateNullBodyPart(bodyPart, types[partTypeIndex], partIndices[partTypeIndex], false);

        UpdatePrevNextButtons();
        GlobalPlayer.SetPart(types[partTypeIndex], partIndices[partTypeIndex]);
    }
Ejemplo n.º 2
0
    public void BuyItem(ShopItem item)
    {
        if (messageText == null)
        {
            messageText = gameObject.GetComponentInChildren <Text>();
        }

        if (GlobalPlayer.HasEnoughMoney(item.cost))
        {
            if (GlobalPlayer.unlockIds.Contains(item.id))
            {
                messageText.text = "Already purchased!";
            }

            else
            {
                GlobalPlayer.UnlockItem(item.id, item.cost);
                messageText.text = "Item Purchased!";
            }
        }
        else
        {
            messageText.text = "Not Enough Money!";
        }
    }
Ejemplo n.º 3
0
        private void ConnectionConfirmMessage(GlobalPlayer player, NetworkMessage msg)
        {
            if (msg.AvailableBytes > 0)
            {
                int playerId = msg.GetInt();
                if (AllPlayers.ContainsKey(playerId))
                {
                    player = AllPlayers[playerId];
                }
                else
                {
                    player = new GlobalPlayer(msg.Peer, playerId);
                }
            }
            else
            {
                player = new GlobalPlayer(msg.Peer);
            }

            _server.RegisterPlayer(player);
            if (!AllPlayers.ContainsKey(player.Id))
            {
                AllPlayers.Add(player.Id, player);
            }

            Logger.WriteLine("Confirmation Connection for player {0}", player.Id);

            var writer = new NetworkWriter(GlobalProtocol.ServerToClient.ConnectionConfirm);

            writer.Put(player.Id);

            player.SendWriter(writer, DeliveryMethod.ReliableOrdered);
        }
Ejemplo n.º 4
0
 private void AttachPals(DefaultLoaderPlayer loaderPlayer, GlobalPlayer player)
 {
     if (player == null || player.PlayerCfg == null || player.PlayerCfg.Files == null)
     {
         loaderPlayer.PalNameList = null;
     }
     else
     {
         var    files = player.PlayerCfg.Files;
         string name  = GetConfigFileNameNoExt(files.pal1);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal2);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal3);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal4);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal5);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal6);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal7);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal8);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal9);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal10);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal11);
         loaderPlayer.AddPalName(name);
         name = GetConfigFileNameNoExt(files.pal12);
         loaderPlayer.AddPalName(name);
     }
 }
Ejemplo n.º 5
0
    public GlobalPlayer LoadPlayer_(string playerName, out GlobalPlayerLoaderResult result)
    {
        if (string.IsNullOrEmpty(playerName))
        {
            result = GlobalPlayerLoaderResult.ParamError;
            return(null);
        }
        var trans = this.transform;
        DefaultLoaderPlayer finder = null;

        for (int i = 0; i < trans.childCount; ++i)
        {
            var child = trans.GetChild(i);
            DefaultLoaderPlayer loader = child.GetComponent <DefaultLoaderPlayer>();
            if (loader == null)
            {
                continue;
            }
            var plyName = loader.GetPlayerName();
            if (string.Compare(plyName, playerName) == 0)
            {
                finder = loader;
                break;
            }
        }
        if (finder == null)
        {
            GameObject obj = new GameObject(playerName, typeof(DefaultLoaderPlayer));
            obj.transform.SetParent(this.transform, false);
            finder = obj.GetComponent <DefaultLoaderPlayer>();
        }
        GlobalPlayer ret = LoadPlayer(finder, out result);

        return(ret);
    }
Ejemplo n.º 6
0
    // 取第一个有效的PalletName
    private string GetFirstVaildPalletName()
    {
        GlobalPlayer player = this.GPlayer;

        if (player == null || player.PlayerCfg == null || !player.PlayerCfg.IsVaild ||
            player.PlayerCfg.Files == null)
        {
            return(string.Empty);
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal1))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal1));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal2))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal2));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal3))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal3));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal4))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal4));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal5))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal5));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal6))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal6));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal7))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal7));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal8))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal8));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal9))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal9));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal10))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal10));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal11))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal11));
        }
        if (!string.IsNullOrEmpty(player.PlayerCfg.Files.pal12))
        {
            return(GlobalConfigMgr.GetConfigFileNameNoExt(player.PlayerCfg.Files.pal12));
        }
        return(string.Empty);
    }
Ejemplo n.º 7
0
    private void RegisterPlayerInLobby(GlobalPlayer globalPlayer)
    {
        var lobbyController = LobbyController.FindInScene();

        lobbyController.OnLobbyPlayerConnected(globalPlayer.LobbyPlayerData);
        AirConsoleBridge.Instance.SendOrUpdateAvatarForPlayer(globalPlayer);
        AirConsoleBridge.Instance.BroadcastCharacterSetChanged(_globalPlayers);
    }
Ejemplo n.º 8
0
    private void LoadPlayerParts()
    {
        partIndices = new int[types.Count];

        for (int i = 0; i < (types.Count); i++)
        {
            partIndices[i] = GlobalPlayer.IndexForType(types[i]);
        }
    }
Ejemplo n.º 9
0
        private void PlayerNameMessage(GlobalPlayer player, NetworkMessage msg)
        {
            string newName = msg.GetString();

            player.Name = newName;
            Logger.WriteLine("Player {0} changed its name to {1}", player.Id, newName);

            var writer = new NetworkWriter(GlobalProtocol.ServerToClient.PlayerNameChanged);

            player.SendWriter(writer, DeliveryMethod.ReliableOrdered);
        }
Ejemplo n.º 10
0
 private void AttachAnim(DefaultLoaderPlayer loaderPlayer, GlobalPlayer player)
 {
     if (player == null || player.PlayerCfg == null || player.PlayerCfg.Files == null)
     {
         loaderPlayer.LoadAnim = string.Empty;
     }
     else
     {
         var files = player.PlayerCfg.Files;
         loaderPlayer.LoadAnim = GetConfigFileNameNoExt(files.anim);
     }
 }
 // Start is called before the first frame update
 void Start()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         Destroy(Instance.gameObject);
         Instance = this;
     }
 }
Ejemplo n.º 12
0
    public bool RunCmd(string cmdName)
    {
        if (string.IsNullOrEmpty(cmdName))
        {
            return(false);
        }
        GlobalPlayer ply = this.GPlayer;

        if (ply == null || ply.CmdCfg == null)
        {
            return(false);
        }
        Cmd_Command cmd = ply.CmdCfg.GetCommand(cmdName);

        if (cmd == null)
        {
            return(false);
        }

        bool       mustCheckTrigger;
        AI_Command aiCmd = ply.CmdCfg.GetAICommand(cmd, this, out mustCheckTrigger);

        if (aiCmd == null || (mustCheckTrigger && !aiCmd.CanTrigger(this, cmdName)))
        {
            return(false);
        }

        CNSConfig cnsCfg = ply.CnsCfg;

        if (cnsCfg == null)
        {
            if (ply.LuaCfg != null)
            {
                cnsCfg = ply.LuaCfg.CnsCfg;
                if (cnsCfg == null)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
        int id;

        if (!cnsCfg.GetCNSStateId(aiCmd.value, out id))
        {
            return(false);
        }
        return(ChangeState((PlayerState)id, true));
    }
Ejemplo n.º 13
0
 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
         return;
     }
     else
     {
         instance = this;
     }
     DontDestroyOnLoad(this.gameObject);
 }
Ejemplo n.º 14
0
 private void CreateLuaPlayer()
 {
     DestroyLuaPlayer();
     if (m_LoaderPlayer != null)
     {
         GlobalPlayer player = m_LoaderPlayer.GetGlobalPayer();
         if (player != null && player.LuaCfg != null)
         {
             // 创建LUA对象
             m_LuaPlayer = player.LuaCfg.NewLuaPlayer(this);
         }
     }
 }
Ejemplo n.º 15
0
    public GlobalPlayer LoadPlayer(DefaultLoaderPlayer loaderPlayer, out GlobalPlayerLoaderResult result)
    {
        if (loaderPlayer == null)
        {
            result = GlobalPlayerLoaderResult.ParamError;
            return(null);
        }
        string       playerName = loaderPlayer.GetPlayerName();
        GlobalPlayer ret        = LoadPlayer(playerName, out result, loaderPlayer.CnsName);

        if (ret != null)
        {
        }
        return(ret);
    }
Ejemplo n.º 16
0
    public static GlobalPlayer CreatePlayer(string playerName, out GlobalPlayerLoaderResult result, string cnsName = "")
    {
        if (string.IsNullOrEmpty(playerName))
        {
            result = GlobalPlayerLoaderResult.ParamError;
            return(null);
        }
        GlobalPlayer player = new GlobalPlayer();
        bool         ret    = player.Init(playerName, out result);

        if (!ret)
        {
            return(null);
        }
        return(player);
    }
Ejemplo n.º 17
0
    private GlobalPlayer LoadPlayer(string playerName, out GlobalPlayerLoaderResult result, string cnsName = "")
    {
        result = GlobalPlayerLoaderResult.Ok;
        GlobalPlayer player;

        if (m_PlayerDict.TryGetValue(playerName, out player) && player != null)
        {
            return(player);
        }
        player = GlobalPlayer.CreatePlayer(playerName, out result, cnsName);
        if (player != null)
        {
            m_PlayerDict [playerName] = player;
        }
        return(player);
    }
Ejemplo n.º 18
0
    private void RegisterGlobalPlayer(int deviceId)
    {
        var playerIndex = IndexOfPlayerWithDeviceId(deviceId);

        if (playerIndex < 0)
        {
            var availableAvatar = FindAvailableAvatar();
            var globalPlayer    = new GlobalPlayer(deviceId, availableAvatar);
            _globalPlayers.Add(globalPlayer);

            if (_currentGameState == GameState.OnLobby)
            {
                RegisterPlayerInLobby(globalPlayer);
            }
        }
    }
Ejemplo n.º 19
0
    public override void OnStartLocalPlayer()
    {
        base.OnStartLocalPlayer();


        foreach (int val in GlobalPlayer.AllParts().Values)
        {
            avatarOptions += val.ToString();
            avatarOptions += ",";
        }
        avatarOptions = avatarOptions.Remove(avatarOptions.Length - 1);
        CmdSetAvatar(avatarOptions);

        playerName = GlobalPlayer.playerName;
        CmdSetName(playerName);
    }
Ejemplo n.º 20
0
        private void ConnectToRoomMessage(GlobalPlayer player, NetworkMessage msg)
        {
            bool spectator = msg.GetBool();

            GameInstance tojoin = null;

            if (spectator)
            {
                int roomID = msg.GetInt();
                if (!Rooms.ContainsKey(roomID))
                {
                    return;
                }
                tojoin = Rooms[roomID];
            }
            else
            {
                foreach (var room in Rooms)
                {
                    if (room.Value.Joinable)
                    {
                        tojoin = room.Value;
                        break;
                    }
                }

                if (tojoin == null)
                {
                    tojoin = new GameInstance(this);
                    Rooms.Add(tojoin.Id, tojoin);
                }
            }

            player.IsSpectator = spectator;
            tojoin.AddExpectedPlayer(player);

            NetworkWriter writer = new NetworkWriter(GlobalProtocol.ServerToClient.ConnectToRoom);

            writer.Put(tojoin.ListenPort);
            player.SendWriter(writer, DeliveryMethod.ReliableOrdered);
        }
Ejemplo n.º 21
0
 private void AddCnsList(DefaultLoaderPlayer loaderPlayer, GlobalPlayer player)
 {
     if (player == null || player.PlayerCfg == null || player.PlayerCfg.Files == null)
     {
         loaderPlayer.CnsNameList = null;
     }
     else
     {
         var    files = player.PlayerCfg.Files;
         string name  = GetConfigFileNameNoExt(files.cns);
         loaderPlayer.AddCnsName(name);
         name = GetConfigFileNameNoExt(files.st);
         loaderPlayer.AddCnsName(name);
         name = GetConfigFileNameNoExt(files.st2);
         loaderPlayer.AddCnsName(name);
         name = GetConfigFileNameNoExt(files.st3);
         loaderPlayer.AddCnsName(name);
         name = GetConfigFileNameNoExt(files.st4);
         loaderPlayer.AddCnsName(name);
     }
 }
Ejemplo n.º 22
0
    public void Start()
    {
        avatarParts = new Transform[] { head, eyes, hat, mouth, mustache, body, weapon };
        types       = new List <PartType>();

        foreach (PartType type in Enum.GetValues(typeof(PartType)))
        {
            types.Add(type);
        }

        LoadPlayerParts();

        // Initialize button text
        UpdatePrevNextPartTypeText();

        // Prevent any null body parts from being rendered
        for (int i = 0; i < types.Count; i++)
        {
            foreach (Transform part in avatarParts[i])
            {
                UpdateNullBodyPart(part.gameObject, types[i], partIndices[i], false);
            }
        }

        // Destroy items that player hasn't unlocked
        RemoveLockedParts();

        // Instantiate initial next and prev button objects
        UpdatePrevNextButtons();

        // Add listener for input field
        playerNameField.onValueChanged.AddListener(delegate { GlobalPlayer.SetPlayerName(playerNameField.text); });

        // Set text if player has set a name before
        if (!GlobalPlayer.playerNameIsDefault)
        {
            playerNameField.text = GlobalPlayer.playerName;
        }
    }
Ejemplo n.º 23
0
    public bool IsCommandInputKeyOk(string cmdName)
    {
        if (string.IsNullOrEmpty(cmdName))
        {
            return(false);
        }
        GlobalPlayer ply = this.GPlayer;

        if (ply == null || ply.CmdCfg == null)
        {
            return(false);
        }
        Cmd_Command cmd = ply.CmdCfg.GetCommand(cmdName);

        if (cmd == null)
        {
            return(false);
        }
        bool ret = PlayerControls.GetInstance().InputCtl.CheckPlayerCmdCommandInputOk(this.PlyType, cmd);

        return(ret);
    }
Ejemplo n.º 24
0
    void Start()
    {
        photonView = GetComponent<PhotonView> ();

        if (photonView.isMine) {
                        myCamera = Camera.main;
                        ((PlayerMainGui)myCamera.GetComponent (typeof(PlayerMainGui))).SetLocalPlayer(this);
                        //TODO: UNCOMMENT
                        robotTimer = robotTime;

                        //this.name = "Player";
                        PlayerName = "Player" + PhotonNetwork.playerList.Length;
                        //	photonView.RPC ("ASKTeam", PhotonTargets.MasterClient);
                        globalPlayer =  FindObjectOfType<GlobalPlayer>();
                        UID = globalPlayer.GetUID();
                        PlayerName = globalPlayer.GetPlayerName();
                        friendsInfo = globalPlayer.friendsInfo;
                        photonView.RPC("RPCSetNameUID",PhotonTargets.AllBuffered,UID,PlayerName);
                        EventHolder.instance.FireEvent(typeof(LocalPlayerListener),"EventAppear",this);
                        //StatisticHandler.StartStats(UID,PlayerName);
        } else {
            Destroy(GetComponent<MusicHolder>());
            Destroy(GetComponent<AudioSource>());
        }
    }
Ejemplo n.º 25
0
 public void GameOver()
 {
     GlobalPlayer.bank += cash;
     GlobalPlayer.AddScore(totalPoints);
     GameObject.FindObjectOfType <MainLobby>().GameOver();
 }
Ejemplo n.º 26
0
 public void AddMoney()
 {
     GlobalPlayer.AddMoney(100);
     Debug.Log("current money: " + GlobalPlayer.bank);
 }
Ejemplo n.º 27
0
    public void StartGame(List <GlobalPlayer> players)
    {
        AirConsoleBridge.Instance.BroadcastLoadingScreen("WATCH THE MAIN SCREEN");
        if (players == null)
        {
            Debug.LogError("NO PLAYERS PROVIDED!");
        }
        if (players.Count <= 0)
        {
            Debug.LogError("NO PLAYERS GIVEN!");
        }
        List <PrefabReplacer> humanSpawns  = new List <PrefabReplacer>();
        List <PrefabReplacer> playerSpawns = new List <PrefabReplacer>();

        foreach (PrefabReplacer replacer in GameObject.FindObjectsOfType <PrefabReplacer>())
        {
            if (replacer.gameObject.name.Contains("Human"))
            {
                humanSpawns.Add(replacer);
            }
            else if (replacer.gameObject.name.Contains("Player"))
            {
                playerSpawns.Add(replacer);
            }
        }

        if (humanSpawns.Count < 0)
        {
            Debug.LogError("NO HUMAN SPAWNS FOUND!");
        }
        if (playerSpawns.Count < 0)
        {
            Debug.LogError("NO PLAYER SPAWNS FOUND!");
        }


        int playersToSpawn = players.Count;

        for (int playerId = 0; playerId < playersToSpawn; playerId++)
        {
            int replacerIndex = Mathf.RoundToInt(Random.value * (playerSpawns.Count - 1));
            while (replacerIndex >= playerSpawns.Count)
            {
                replacerIndex = Mathf.RoundToInt(Random.value * (playerSpawns.Count - 1));
            }
            PrefabReplacer replacer = playerSpawns[replacerIndex];
            playerSpawns.Remove(replacer);
            GameObject   newPlayer  = replacer.SpawnPrefab();
            GlobalPlayer thisPlayer = players[playerId];
            newPlayer.GetComponent <MonsterAnimationController>().SetCharacter(thisPlayer.LobbyPlayerData.Character);
            newPlayer.GetComponent <ScoreTracker>().Character = thisPlayer.LobbyPlayerData.Character;

            SpawnPositionEffect effect = Instantiate(spawnPositionEffect);
            effect.transform.SetParent(effectCanvas.transform);
            effect.transform.localScale = Vector3.one;
            Debug.Log("New Spawn effect! " + thisPlayer.LobbyPlayerData.Character + " " + newPlayer + " " + AirConsole.instance.GetNickname(thisPlayer.LobbyPlayerData.Id));
            effect.SetCharacter(thisPlayer.LobbyPlayerData.Character, newPlayer, AirConsole.instance.GetNickname(thisPlayer.LobbyPlayerData.Id), playerId * effect.displayTime);
        }
        float totalDisplayTime = spawnPositionEffect.displayTime * playersToSpawn;

        foreach (PrefabReplacer replacer in playerSpawns)
        {
            Destroy(replacer.gameObject);
        }
        int humansToSpawn = humansToSpawnPerPlayer[playersToSpawn - 1];

        for (int humanId = 0; humanId < humansToSpawn; humanId++)
        {
            PrefabReplacer replacer = humanSpawns[Mathf.RoundToInt(Random.value * (humanSpawns.Count - 1))];
            humanSpawns.Remove(replacer);
            replacer.SpawnPrefab();
        }
        foreach (PrefabReplacer replacer in humanSpawns)
        {
            Destroy(replacer.gameObject);
        }

        GameObject.FindObjectOfType <LeaderboardTracker>().OnGameStart();

        StartCoroutine(StartInASecond(totalDisplayTime));
    }
Ejemplo n.º 28
0
        public async Task Run(string filepath)
        {
            //STEP.Player #850 reset results.txt
            GlobalPlayer.ResetResult();
            var selectedJSXML = openFileDialog2.FileName = filepath;

            CloseCodeCeptJsWindow();

            //todo: make this LIstbox not gridview error on ui when using grid
            // ActivateGroupBox(groupBoxRec);
            //  groupBoxRec.Visible = true;

            //STEP_.Player #802 load defaultXML
            Open_File(selectedJSXML);

            string ext = Path.GetExtension(selectedJSXML);

            if (ext.ToLower() == ".js")
            {
                //update latest_test.js
                //STEP_.Player #803 get extension variables
                var runCmd = FileEndPointManager.ReadInputWFCmdJsonFile();

                var externalParam  = runCmd.EventParameters;
                var internalResult = BotHttpClient.DevNoteGetParameters(runCmd.EventName).Content;//.ReadAsStringAsync();

                var internalParam = JsonConvert.DeserializeObject <Dictionary <string, string> >(internalResult);

                var script = File.ReadAllText(openFileDialog1.FileName);

                if (internalParam != null && externalParam != null)
                {
                    //STEP_.Player #804 CrossBreed the parameters
                    Dictionary <string, string> crossBreed = new Dictionary <string, string>();
                    foreach (var external in externalParam)
                    {
                        //internalParam-(arg.MappedTo_Input_X, arg.PropertyName.lower());
                        //ExternalParam---------------------------(PropertyName.tolower(), value); this is the external dictionary  crossed
                        //results to ---(arg.MappedTo_Input_X,value)
                        if (internalParam.ContainsValue(external.Key.ToLower()))
                        {
                            var internalP = internalParam.First(p => p.Value == external.Key.ToLower());
                            crossBreed.Add(internalP.Key, external.Value);
                        }
                    }
                    //STEP_.Player #803 insert variables
                    Interpreter it = new Interpreter();
                    //STEP.Player #804 Insert Variables
                    var selectedContent = it.InsertVariables(openFileDialog1.FileName, crossBreed).ToString();

                    script = selectedContent;
                    BotHttpClient.UpdateMainUI("InsertVariables " + Environment.NewLine + crossBreed.ToArray().ToString());
                }
                //  var selectedContent = File.ReadAllText(selectedJSXML);
                var dir = LogApplication.Agent.GetCurrentDir();
                dir = dir.Replace("file:\\", string.Empty);
                string drive       = Path.GetPathRoot(dir);
                string driveLetter = drive.First().ToString();

                var codeceptjsFolder = string.Format("{0}\\CodeceptJs\\Project2", dir);  //@"D:\_ROBOtFRAMeWORK\CodeceptsJs\Project1\";
                var codeceptTestPath = Path.Combine(codeceptjsFolder, "latest_test.js");

                if (File.Exists(codeceptTestPath))
                {
                    File.Delete(codeceptTestPath);
                }

                File.WriteAllText(codeceptTestPath, script);
                //play
                // dgActions.DataSource = actionSource;
                // dgActions.Refresh(); // Make sure this comes first
                //  dgActions.Parent.Refresh(); // Make sure this comes second
                //  flowMain.Refresh();
            }

            //STEP.Player #803 run _test.js using bat file
            RunCondeceptjsDefault();

            var started = DateTime.Now;

            //Application.DoEvents();
            TaskWaiter.Conditions cond = new TaskWaiter.Conditions("Wait_CondceptJS_Console");
            await cond.WaitUntil(() => (DateTime.Now - started).TotalSeconds > 5)
            .ContinueWith(x =>
            {
                WindowsHelper.FollowConsole(CmdExeForCodecept);
            });

            //STEP.Player #855 //check result
            //wait for output
            //todo HERE...

            //var cond1 = new TaskWaiter.Conditions("wait_for_result.txt");
            //await cond1.WaitUntil(() => AutoPlayPolicy.AssertPlayerResultExist(started) == true, 1000).ContinueWith(x =>
            //{
            //    //setStatus(string.Format("Retried {0} times", MyRetry), EnumPlayStatus.Success);
            //    //Task.Delay(1000);
            //    //IsAutoPlaying = false;

            //    //Stop();

            //    //var result =  await AutoPlay();
            //    BotHttpClient.Log("Done.. Play codecept.");

            //    //step# 12 done EnumTaskStatus.DoneCodeCept
            //    //IsAutoplayDone = EnumTaskStatus.DoneCodeCept;


            //    //MyPayload.IsSuccess = true;
            //    //MyPayload.IsRespond = true;

            //    //step# 12.4 finished status
            //    //IsAutoplayDone = EnumTaskStatus.Finished;

            //    //not here.. yet it will retry
            //    // GlobalPlayer.CreateWFOutput("none");
            //});

            //check result
            //STEP_.Player screenshot ERROR
            //if (GlobalPlayer.IsFailedResult)
            //{
            //    return false;// continue to retry
            //}
            //else
            //    return true; //no need to retry
        }
Ejemplo n.º 29
0
    public void SetPartForType(PartType type)
    {
        Transform partTransform = null;

        switch (type)
        {
        case PartType.Body:
            partTransform = body;
            break;

        case PartType.Eyes:
            partTransform = eyes;
            break;

        case PartType.Hat:
            partTransform = hat;
            break;

        case PartType.Head:
            partTransform = head;
            break;

        case PartType.Mouth:
            partTransform = mouth;
            break;

        case PartType.Mustache:
            partTransform = mustache;
            break;

        case PartType.Weapon:
            partTransform = weapon;
            break;

        default:
            partTransform = null;
            break;
        }

        if (partTransform == null || GlobalPlayer.IndexForType(type) == -1)
        {
            return;
        }

        // Destroy children of current part
        foreach (Transform part in partTransform)
        {
            Destroy(part.gameObject);
        }

        bool drawPart = true;

        // Instantiate new children in parent GameObject if the object is not empty (hat, weapon, etc)
        switch (type)
        {
        case PartType.Hat:
        case PartType.Weapon:
        case PartType.Mustache:
            if (GlobalPlayer.IndexForType(type) == 0)
            {
                drawPart = false;
            }
            break;
        }

        if (drawPart)
        {
            Instantiate(
                inventory.partForTypeIndex(type, GlobalPlayer.IndexForType(type)),
                partTransform,
                false);
        }
    }
Ejemplo n.º 30
0
        public object Deserialize(string fileName)
        {
            var serializer = new XmlSerializer(typeof(game));

            directory = new FileInfo(fileName).Directory.FullName;
            game g        = null;
            var  fileHash = "";

            using (var fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                g = (game)serializer.Deserialize(fs);
                if (g == null)
                {
                    return(null);
                }
                using (MD5 md5 = new MD5CryptoServiceProvider())
                {
                    fs.Seek(0, SeekOrigin.Begin);
                    byte[] retVal = md5.ComputeHash(fs);
                    fileHash = BitConverter.ToString(retVal).Replace("-", ""); // hex string
                }
            }
            var ret = new Game()
            {
                Id                  = new Guid(g.id),
                Name                = g.name,
                CardBack            = String.IsNullOrWhiteSpace(g.card.back) ? "pack://application:,,,/Resources/Back.jpg" : Path.Combine(directory, g.card.back),
                CardFront           = String.IsNullOrWhiteSpace(g.card.front) ? "pack://application:,,,/Resources/Front.jpg" : Path.Combine(directory, g.card.front),
                CardHeight          = int.Parse(g.card.height),
                CardWidth           = int.Parse(g.card.width),
                CardCornerRadius    = int.Parse(g.card.cornerRadius),
                Version             = Version.Parse(g.version),
                CustomProperties    = new List <PropertyDef>(),
                DeckSections        = new Dictionary <string, DeckSection>(),
                SharedDeckSections  = new Dictionary <string, DeckSection>(),
                GlobalVariables     = new List <GlobalVariable>(),
                Authors             = g.authors.Split(',').ToList(),
                Description         = g.description,
                Filename            = fileName,
                Fonts               = new List <Font>(),
                GameUrl             = g.gameurl,
                IconUrl             = g.iconurl,
                Tags                = g.tags.Split(' ').ToList(),
                OctgnVersion        = Version.Parse(g.octgnVersion),
                Variables           = new List <Variable>(),
                MarkerSize          = g.markersize,
                Documents           = new List <Document>(),
                Sounds              = new Dictionary <string, GameSound>(),
                FileHash            = fileHash,
                Events              = new Dictionary <string, GameEvent[]>(),
                InstallPath         = directory,
                UseTwoSidedTable    = g.usetwosidedtable == boolean.True ?true : false,
                NoteBackgroundColor = g.noteBackgroundColor,
                NoteForegroundColor = g.noteForegroundColor,
            };

            #region variables
            if (g.variables != null)
            {
                foreach (var item in g.variables)
                {
                    ret.Variables.Add(new Variable
                    {
                        Name    = item.name,
                        Global  = bool.Parse(item.global.ToString()),
                        Reset   = bool.Parse(item.reset.ToString()),
                        Default = int.Parse(item.@default)
                    });
                }
            }
            #endregion variables
            #region table
            ret.Table = this.DeserialiseGroup(g.table, 0);
            #endregion table
            #region shared
            if (g.shared != null)
            {
                var player = new GlobalPlayer {
                    Counters = new List <Counter>(), Groups = new List <Group>()
                };
                var curCounter = 1;
                var curGroup   = 1;
                if (g.shared.counter != null)
                {
                    foreach (var i in g.shared.counter)
                    {
                        (player.Counters as List <Counter>).Add(
                            new Counter
                        {
                            Id    = (byte)curCounter,
                            Name  = i.name,
                            Icon  = Path.Combine(directory, i.icon ?? ""),
                            Reset = bool.Parse(i.reset.ToString()),
                            Start = int.Parse(i.@default)
                        });
                        curCounter++;
                    }
                }
                if (g.shared.group != null)
                {
                    foreach (var i in g.shared.group)
                    {
                        (player.Groups as List <Group>).Add(this.DeserialiseGroup(i, curGroup));
                        curGroup++;
                    }
                }
                ret.GlobalPlayer = player;
            }
            #endregion shared
            #region Player
            if (g.player != null)
            {
                var player = new Player
                {
                    Groups           = new List <Group>(),
                    GlobalVariables  = new List <GlobalVariable>(),
                    Counters         = new List <Counter>(),
                    IndicatorsFormat = g.player.summary
                };
                var curCounter = 1;
                var curGroup   = 1;
                foreach (var item in g.player.Items)
                {
                    if (item is counter)
                    {
                        var i = item as counter;
                        (player.Counters as List <Counter>)
                        .Add(new Counter
                        {
                            Id    = (byte)curCounter,
                            Name  = i.name,
                            Icon  = Path.Combine(directory, i.icon ?? ""),
                            Reset = bool.Parse(i.reset.ToString()),
                            Start = int.Parse(i.@default)
                        });
                        curCounter++;
                    }
                    else if (item is gamePlayerGlobalvariable)
                    {
                        var i  = item as gamePlayerGlobalvariable;
                        var to = new GlobalVariable {
                            Name = i.name, Value = i.value, DefaultValue = i.value
                        };
                        (player.GlobalVariables as List <GlobalVariable>).Add(to);
                    }
                    else if (item is hand)
                    {
                        player.Hand = this.DeserialiseGroup(item as hand, 0);
                    }
                    else if (item is group)
                    {
                        var i = item as group;
                        (player.Groups as List <Group>).Add(this.DeserialiseGroup(i, curGroup));
                        curGroup++;
                    }
                }
                ret.Player = player;
            }
            #endregion Player

            #region documents
            if (g.documents != null)
            {
                foreach (var doc in g.documents)
                {
                    var d = new Document();
                    d.Icon   = Path.Combine(directory, doc.icon);
                    d.Name   = doc.name;
                    d.Source = Path.Combine(directory, doc.src);
                    ret.Documents.Add(d);
                }
            }
            #endregion documents
            #region sounds
            if (g.sounds != null)
            {
                foreach (var sound in g.sounds)
                {
                    var s = new GameSound();
                    s.Gameid = ret.Id;
                    s.Name   = sound.name;
                    s.Src    = Path.Combine(directory, sound.src);
                    ret.Sounds.Add(s.Name.ToLowerInvariant(), s);
                }
            }
            #endregion sounds
            #region deck
            if (g.deck != null)
            {
                foreach (var ds in g.deck)
                {
                    ret.DeckSections.Add(ds.name, new DeckSection {
                        Group = ds.group, Name = ds.name, Shared = false
                    });
                }
            }
            if (g.sharedDeck != null)
            {
                foreach (var s in g.sharedDeck)
                {
                    ret.SharedDeckSections.Add(s.name, new DeckSection {
                        Group = s.group, Name = s.name, Shared = true
                    });
                }
            }
            #endregion deck
            #region card
            if (g.card != null && g.card.property != null)
            {
                foreach (var prop in g.card.property)
                {
                    var pd = new PropertyDef();
                    pd.Name = prop.name;
                    switch (prop.textKind)
                    {
                    case propertyDefTextKind.Free:
                        pd.TextKind = PropertyTextKind.FreeText;
                        break;

                    case propertyDefTextKind.Enum:
                        pd.TextKind = PropertyTextKind.Enumeration;
                        break;

                    case propertyDefTextKind.Tokens:
                        pd.TextKind = PropertyTextKind.Tokens;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    pd.Type       = (PropertyType)Enum.Parse(typeof(PropertyType), prop.type.ToString());
                    pd.IgnoreText = bool.Parse(prop.ignoreText.ToString());
                    pd.Hidden     = bool.Parse(prop.hidden);
                    ret.CustomProperties.Add(pd);
                }
            }
            var namepd = new PropertyDef();
            namepd.Name     = "Name";
            namepd.TextKind = PropertyTextKind.FreeText;
            namepd.Type     = PropertyType.String;
            ret.CustomProperties.Add(namepd);
            #endregion card
            #region fonts
            if (g.fonts != null)
            {
                foreach (gameFont font in g.fonts)
                {
                    Font f = new Font();
                    f.Src  = Path.Combine(directory, font.src ?? "");
                    f.Size = (int)font.size;
                    switch (font.target)
                    {
                    case fonttarget.chat:
                        f.Target = Enum.Parse(typeof(fonttarget), "chat").ToString();
                        break;

                    case fonttarget.context:
                        f.Target = Enum.Parse(typeof(fonttarget), "context").ToString();
                        break;

                    case fonttarget.deckeditor:
                        f.Target = Enum.Parse(typeof(fonttarget), "deckeditor").ToString();
                        break;
                    }
                    ret.Fonts.Add(f);
                }
            }
            #endregion fonts
            #region scripts
            if (g.scripts != null)
            {
                foreach (var s in g.scripts)
                {
                    var coll = Def.Config
                               .DefineCollection <GameScript>("Scripts")
                               .OverrideRoot(x => x.Directory("GameDatabase"))
                               .SetPart(x => x.Directory(ret.Id.ToString()));
                    var pathParts = s.src.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                    for (var index = 0; index < pathParts.Length; index++)
                    {
                        var i = index;
                        if (i == pathParts.Length - 1)
                        {
                            coll.SetPart(x => x.File(pathParts[i]));
                        }
                        else
                        {
                            coll.SetPart(x => x.Directory(pathParts[i]));
                        }
                    }
                    coll.SetSerializer(new GameScriptSerializer(ret.Id));
                }
            }
            #endregion scripts

            #region events

            if (g.events != null)
            {
                foreach (var e in g.events)
                {
                    var eve = new GameEvent()
                    {
                        Name           = e.name.Clone() as string,
                        PythonFunction =
                            e.action.Clone() as string
                    };
                    if (ret.Events.ContainsKey(e.name))
                    {
                        var narr = ret.Events[e.name];
                        Array.Resize(ref narr, narr.Length + 1);
                        narr[narr.Length - 1] = eve;
                        ret.Events[e.name]    = narr;
                    }
                    else
                    {
                        ret.Events.Add(e.name, new GameEvent[1] {
                            eve
                        });
                    }
                }
            }
            #endregion Events
            #region proxygen
            if (g.proxygen != null)
            {
                var coll =
                    Def.Config.DefineCollection <ProxyDefinition>("Proxies")
                    .OverrideRoot(x => x.Directory("GameDatabase"))
                    .SetPart(x => x.Directory(ret.Id.ToString()));
                //.SetPart(x => x.Property(y => y.Key));
                var pathParts = g.proxygen.definitionsrc.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
                for (var index = 0; index < pathParts.Length; index++)
                {
                    var i = index;
                    if (i == pathParts.Length - 1)
                    {
                        coll.SetPart(x => x.File(pathParts[i]));
                    }
                    else
                    {
                        coll.SetPart(x => x.Directory(pathParts[i]));
                    }
                }
                coll.SetSerializer(new ProxyGeneratorSerializer(ret.Id, g.proxygen));
            }
            #endregion proxygen
            #region globalvariables
            if (g.globalvariables != null)
            {
                foreach (var item in g.globalvariables)
                {
                    ret.GlobalVariables.Add(new GlobalVariable {
                        Name = item.name, Value = item.value, DefaultValue = item.value
                    });
                }
            }
            #endregion globalvariables
            #region hash
            #endregion hash
            return(ret);
        }
Ejemplo n.º 31
0
        /****************************************************************************/

        private void OnPlayerDisconnect(GlobalPlayer player)
        {
            Logger.WriteLine("Player {0} disconnected.", player.Id);
            AllPlayers.Remove(player.Id);
        }