Example #1
0
        private static void InitializeCharNames()
        {
            CharacterNames = new Dictionary <ulong, script_character>();
            string tempStr = UnityWrapper.LoadTextFileAsString("March22/CHARACTER_NAMES");

            tempStr += "\n\n"; // <- hack to fix last line being cut off

            string[] lines = tempStr.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            foreach (string line in lines)
            {
                string[] lineSplit = line.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                string   shortName = lineSplit[0];
                string   longName  = Regex.Match(line, "\"([^\"]*)\"").ToString();

                script_character temp = new script_character();
                temp.name  = longName.Substring(1, longName.Length - 2);
                temp.color = new UnityWrapper.Color32(
                    (byte)Int32.Parse(lineSplit[lineSplit.Length - 3]),
                    (byte)Int32.Parse(lineSplit[lineSplit.Length - 2]),
                    (byte)Int32.Parse(lineSplit[lineSplit.Length - 1]),
                    (byte)255
                    );

                CharacterNames.Add(CalculateHash(shortName), temp);
            }
        }
        public void AssertTextOnPage()
        {
            _searchPage = UnityWrapper.Resolve <ISearchPage>();
            var titel     = _searchPage.GetPageTitel();
            var pageTitel = "Nuneaton Properties for Sale | Purplebricks";

            Assert.AreEqual(titel, pageTitel);
        }
Example #3
0
 private void Start()
 {
     if (PlayerPrefsWrapper.Get(KeyShouldExist) != 0)
     {
         UnityWrapper.GetRequestMethod(Request).Invoke();
         PlayerPrefsWrapper.Take(KeyShouldExist);
     }
     ;
 }
        public void AssertPageTitel()
        {
            _homePage = UnityWrapper.Resolve <IHomePage>();
            var titel     = _homePage.GetPageTitel();
            var pageTitel = "Purplebricks Estate Agents - You'll Be Totally Sold";

            Assert.AreEqual(titel, pageTitel);
            _homePage.EnterSearchString("CV10 8QY");
            _homePage.ClickOnElementSearchButton();
        }
        public void SetUp()
        {
            _homePage = UnityWrapper.Resolve <IHomePage>();

            _loginPage = _homePage.ClickOnLoginLink <LoginPage>();

            var email    = JsonConfig.GetJsonValue("Email");
            var password = JsonConfig.GetJsonValue("Password");

            _loginPage.EnterEmail(email);
            _loginPage.EnterPassword(password);
            _loginPage.CheckRememberMeRadioButton();
            _userAccountPage = _loginPage.ClickOnlogInButton <UserAccountPage>();
        }
        public void SetUp()
        {
            _homePage = UnityWrapper.Resolve <IHomePage>();

            _loginPage = _homePage.ClickOnLoginLink <LoginPage>();

            var email    = "*****@*****.**";
            var password = "******";

            _loginPage.EnterEmail(email);
            _loginPage.EnterPassword(password);
            _loginPage.CheckRememberMeRadioButton();
            _userAccountPage = _loginPage.ClickOnlogInButton <UserAccountPage>();
        }
Example #7
0
        public static void Initialize()
        {
            FunctionHashes = new Dictionary <ulong, M22.LINETYPE>();

            InitializeCharNames();

            if (FunctionNames.Length != (int)M22.LINETYPE.NUM_OF_LINETYPES)
            {
                UnityWrapper.LogError("Number of LINETYPE entries do not match number of FunctionNames");
            }

            for (int i = 0; i < FunctionNames.Length; i++)
            {
                FunctionHashes.Add(CalculateHash(FunctionNames[i]), (M22.LINETYPE)i);
            }
        }
Example #8
0
        static public LoadedVariables LoadVariablesFile()
        {
            var result = new LoadedVariables();
            var file   = UnityWrapper.LoadTextFileAsString("March22/VARIABLES");

            if (file == null || file == "")
            {
                UnityWrapper.LogError("Failed to load \"Resources/March22/VARIABLES.txt\"! You should have one even if you aren't using it!");
                return(result);
            }

            if (file[file.Length - 1] != '\n')
            {
                file += '\n';
            }
            var varLines = SplitByChar('\n', ref file);

            file                = "";
            result.variables    = new string[varLines.Count];
            result.variableData = new string[varLines.Count];

            for (int i = 0; i < varLines.Count; i++)
            {
                var currentLine = varLines[i];
                currentLine = currentLine.Trim(' ', '\n', '\r');
                if (currentLine.Length < 4)
                {
                    continue;
                }

                List <string> splitStr = new List <string>();
                SplitString(ref currentLine, ref splitStr, "===");
                for (int n = 0; n < splitStr.Count; n++)
                {
                    splitStr[n] = splitStr[n].Trim(' ', '\n', '\r');
                }
                if (splitStr.Count < 2)
                {
                    continue;
                }

                result.variables[i]    = splitStr[0];
                result.variableData[i] = splitStr[1];
            }

            return(result);
        }
Example #9
0
        static public M22.Script.Script CompileScript(string filename)
        {
            var result = new M22.Script.Script();

            LoadedVariables loadedVars = LoadVariablesFile();

            //var file = File.ReadAllText(filename, Encoding.UTF8);
            var file = UnityWrapper.LoadTextFileAsString(filename);

            if (file.Length == 0)
            {
                UnityWrapper.LogError("Failed to load script file: " + filename);
                return(result);
            }

            var scriptLines = SplitByChar('\n', ref file);

            file = "";

            //List<string> CURRENT_LINE_SPLIT = new List<string>();
            int scriptPos = 0;

            for (int i = 0; i < scriptLines.Count; i++)
            {
                string currScriptLine = scriptLines[i];

                for (int n = 0; n < loadedVars.variables.Length; n++)
                {
                    if (loadedVars.variables[n] != null)
                    {
                        string tempStr = "[[" + loadedVars.variables[n] + "]]";
                        currScriptLine = currScriptLine.Replace(tempStr, loadedVars.variableData[n]);
                    }
                }

                M22.line_c tempLine_c = CompileLine(ref currScriptLine, i); // ref can't be an index so have to copy then copy back
                scriptLines[i] = currScriptLine;
                //if(tempLine_c.m_lineType == LINETYPE.NULL_OPERATOR)
                result.AddLine(tempLine_c);
                scriptPos++;
            }

            result.ClearNullOperators();

            return(result);
        }
Example #10
0
        public void SetUp()
        {
            _homePage = UnityWrapper.Resolve <IHomePage>();

            _random = new Random();
            var value = _random.Next(1, 20000);

            _registerPage = _homePage.ClickOnRegisterLink <RegisterPage>();

            var email    = $"nsntestaccount{value}@yahoo.com";
            var password = "******";

            _registerPage.EnterEmail(email);
            _registerPage.EnterPassword(password);
            _registerPage.EnterConfirmPassword(password);
            _registerConfirmationPage = _registerPage.ClickOnSubmitButton <RegisterConfirmationPage>();
        }
Example #11
0
        static void OnLoad(string path)
        {
            Dictionary <string, string> args = UnityWrapper.ProcessLaunchArguments();
            string logto;

            if (args.TryGetValue("+logto", out logto))
            {
                int port;
                if (int.TryParse(logto, out port))
                {
                    StartSendingLogsTo(port);
                }
                else
                {
                    Log.Write("Could not parse {0} as port", port);
                }
                return;
            }
        }
        public void SetUp()
        {
            _homePage = UnityWrapper.Resolve <IHomePage>();

            _random   = new Random();
            telNumber = _random.Next(100000, 200000000);
            var value = _random.Next(100, 20000);

            _loginPage = _homePage.ClickOnLoginLink <LoginPage>();

            var email    = JsonConfig.GetJsonValue("Email");
            var password = JsonConfig.GetJsonValue("Password");

            newEmail = $"nsntestaccount{value}@yahoo.com";
            _loginPage.EnterEmail(email);
            _loginPage.EnterPassword(password);
            _loginPage.CheckRememberMeRadioButton();
            _userAccountPage = _loginPage.ClickOnlogInButton <UserAccountPage>();
        }
        public void SetUp()
        {
            _homePage = UnityWrapper.Resolve <IHomePage>();

            _random   = new Random();
            telNumber = _random.Next(100000, 200000000);
            var value = _random.Next(100, 20000);

            _loginPage = _homePage.ClickOnLoginLink <LoginPage>();

            var email    = "*****@*****.**";
            var password = "******";

            newEmail = $"snscareers{value}@yahoo.com";
            _loginPage.EnterEmail(email);
            _loginPage.EnterPassword(password);
            _loginPage.CheckRememberMeRadioButton();
            _userAccountPage = _loginPage.ClickOnlogInButton <UserAccountPage>();
        }
Example #14
0
 public override void Func(string[] _params)
 {
     if (_params[0].Equals("out"))
     {
         if (SpriteInstance == null)
         {
             UnityWrapper.LogWarningFormat("DrawSprite is null; trying to fade out when there isn't a sprite?");
         }
         else
         {
             SpriteInstance.GetComponent <SpriteObjectScript>().Hide();
             SpriteInstance = null;
         }
     }
     else
     {
         SpriteInstance = GameObject.Instantiate <GameObject>(SpritePrefab, this.scriptMaster.GetCanvas(M22.ScriptMaster.CANVAS_TYPES.POSTCHARACTER).transform);
         SpriteInstance.GetComponent <SpriteObjectScript>().SetSprite(Resources.Load <Sprite>("March22/Images/" + _params[1]));
     }
 }
Example #15
0
        void trans(Hashtable param)
        {
            string method = "crossfade";

            if (param.ContainsKey("method"))
            {
                method = param["method"] as string;
            }
            string resourcePath = "";

            switch (method)
            {
            case "crossfade":
                //TODO !
//		            resource = "";
                break;

            case "blind":
                resourcePath = "Effects/Blind";
                break;

            case "tile":
                resourcePath = "Effects/TileFade";
                break;
            }
//		    float time = float.Parse( param["time"] as string )/1000f;

            Object loadedResource = Resources.Load(resourcePath);

            if (loadedResource == null)
            {
                Debug.LogError("Resources.Load Error ! path:" + resourcePath);
                return;
            }

            ViNoSceneManager sm         = ViNoSceneManager.Instance;
            string           parentName = sm.transform.parent.gameObject.name;          // It is expected that the "Panels" object or the "Camera" object.

            UnityWrapper.InstantiateAsGameObject(loadedResource, parentName);
        }
Example #16
0
 // param1 = in or out
 // param2 = text, delimited by underscores
 public override void Func(string[] _params)
 {
     if (_params[0].Equals("out"))
     {
         if (WrittenNoteInstance == null)
         {
             UnityWrapper.LogWarningFormat("WrittenNoteInstance is null; trying to fade out when there isn't a note?");
         }
         else
         {
             WrittenNoteInstance.GetComponent <WrittenNoteObjectScript>().HideNote();
             WrittenNoteInstance = null;
         }
     }
     else
     {
         string param2_fixed = _params[1].Replace('_', ' ');
         param2_fixed        = param2_fixed.Replace("\\n", "\n");
         WrittenNoteInstance = GameObject.Instantiate <GameObject>(WrittenNotePrefab, this.scriptMaster.GetCanvas(M22.ScriptMaster.CANVAS_TYPES.POSTCHARACTER).transform);
         WrittenNoteInstance.GetComponentInChildren <Text>().text = param2_fixed;
     }
 }
 public void Awake()
 {
     _button = GetComponent <Button>();
     _button.onClick.AddListener(UnityWrapper.GetRequestMethod(Request));
     PlayerPrefsWrapper.StringPrefsChanged += ValueChanged;
 }
Example #18
0
    // ------------- Override --------------------.

    /// <summary>
    /// Handles the opcode.
    /// </summary>
    public override void OnUpdate()
    {
        if (IsFinish())
        {
            return;
        }

        // Pomp Message to MessagingHandler.
        if (m_MessagePompToMsghandler)
        {
            if (m_MessagingHandler != null)
            {
                bool handled = m_MessagingHandler.HandleOpcode(this);
                m_MessagePompToMsghandler = !handled;
            }
            return;
        }

        m_CanTextProgress = false;
        switch (code[pc])
        {
        case Opcode.STRING:             pc = ByteCodeReader.readString(code, pc + 1);        m_TextBuilder.Append(loadedString);   break;

        case Opcode.TEXT:               pc = ReadText(pc);                                                                                                                                            break;

        case Opcode.VAR:                pc = ByteCodeReader.readVar(code, pc, ref paramHash, ref m_TextBuilder, stubIndent);       break;

        case Opcode.TABLE:              pc = ByteCodeReader.readTable(code, pc, ref paramHash);                                                                     break;

        case Opcode.ASSIGN_STRING:
//			Debug.Log("OPCODE>ASSIGN_STRING");
            pc        = ByteCodeReader.readString(code, pc + 2);
            leftHand  = loadedString;
            pc        = ByteCodeReader.readString(code, pc + 1);
            rightHand = loadedString;
//			Debug.Log(  "Opcode.ASSIGN key=" + leftHand + " value=\"" + rightHand + "\"" );

// Assign Value to Hashtable ?.
#if false
            symbolTable[leftHand] = rightHand;

// Assign Value to FlagTable.
#else
            ScenarioNode scenario = ScenarioNode.Instance;
            if (scenario != null && scenario.flagTable != null)
            {
                scenario.flagTable.SetStringValue(leftHand, rightHand);
            }
#endif
            leftHand  = "";
            rightHand = "";
            break;

        case Opcode.NULL:              pc++;                                                                                                                                                                           break;

        case Opcode.MESSAGING:
            pc = ByteCodeReader.readString(code, pc + 2);
            messagingTargetName       = loadedString;
            m_MessagePompToMsghandler = true;
            bool isIgnoreObj = loadedString.Equals("env");
            if (!isIgnoreObj)
            {
                if (tweenDataCached.tweenTarget != null)
                {
                    if (!tweenDataCached.tweenTarget.name.Equals(messagingTargetName))
                    {
                        tweenDataCached.tweenTarget = GameObject.Find(messagingTargetName);
                    }
                }
                else
                {
                    tweenDataCached.tweenTarget = GameObject.Find(messagingTargetName);
                }
            }
            tweenDataCached.paramTable = paramHash;
            break;

        case Opcode.NODE:
            m_PrevNodeName = m_CurrNodeName;
            pc             = ByteCodeReader.readString(code, pc + 2);
            ViNoDebugger.Log("NODE", loadedString);

            m_CurrNodeName            = loadedString;
            m_NodePcMap[loadedString] = pc;
            SetCurrentNodeToScriptEngine();

            // Callback to ScriptBinder.
            scriptBinder.OnEnterNode(this);
            break;

        case Opcode.LOAD_RESOURCE:
            m_LoadedResourcePath = VirtualMachine.loadedTextLiteralString;
            m_LoadedResource     = UnityWrapper.LoadResource(m_LoadedResourcePath);
            pc++;
            break;

// TODO : Need to Test .
        case Opcode.PLAY_AUDIO_FROM_RESOURCE:
            m_LoadedResourcePath = VirtualMachine.loadedTextLiteralString;
            ISoundPlayer.Instance.PlayAudioClip(m_LoadedResource as AudioClip, m_LoadedResourcePath, ViNoConfig.prefsBgmVolume, 0f);
            m_LoadedResource = null;
            Resources.UnloadUnusedAssets();

            pc++;
            break;

        case Opcode.INSTANTIATE_AS_GAMEOBJECT:
            if (m_LoadedResource != null)
            {
                string parentName = VirtualMachine.loadedTextLiteralString;

                UnityWrapper.InstantiateAsGameObject(m_LoadedResource, parentName);

                m_LoadedResource = null;
                Resources.UnloadUnusedAssets();
            }
            else
            {
                Debug.LogError("Resource not loaded.");
            }
            pc++;
            break;

        case Opcode.DESTROY_OBJECT:
            string     goName = VirtualMachine.loadedTextLiteralString;
            GameObject go     = GameObject.Find(goName);                                // TODO : GO.Find is Slow .
            GameObject.Destroy(go);
            pc++;
            break;

        case Opcode.JUMP:               // Jump to loadedString Node  .
            ByteCodeReader.readString(code, pc + 2);
            GoToLabel(loadedString);
            ViNoDebugger.Log("NODE", "jump to :" + loadedString);
            break;

        case Opcode.IF:
            pc = ByteCodeReader.readString(code, pc + 2);
            string flagName = VirtualMachine.loadedString;
            Debug.Log("flag name :" + flagName);

            bool isOnOrOff = (code[pc] == 1) ? true : false;
            pc++;

            pc = ByteCodeReader.readString(code, pc + 1);
            string ifTarget = VirtualMachine.loadedString;
            Debug.Log("IF =>" + ifTarget);
            pc = ByteCodeReader.readString(code, pc + 1);
            string elseTarget = VirtualMachine.loadedString;
            Debug.Log("ELSE =>" + elseTarget);

            bool isFlagOn = ScenarioNode.Instance.flagTable.CheckFlagBy(flagName);
            if (isFlagOn == isOnOrOff)
            {
                Debug.Log("IF");
                GoToLabel(ifTarget);
            }
            else
            {
                Debug.Log("ELSE");
                GoToLabel(elseTarget);
            }
            break;

            // ----- Layer -----.
#if false
        case Opcode.LAYOPT:                             GOOptionNode.Do(paramHash);           pc++;   break;
#endif
        case Opcode.BEGIN_TRANSITION:   UnityWrapper.BeginTransition();         pc++;   break;

        case Opcode.END_TRANSITION:             UnityWrapper.EndTransition();           pc++;   break;

        case Opcode.SCENE_NODE:
            SceneData.SceneNodeData data = SceneCreator.CreateNodeData(paramHash);
            SceneCreator.Create(data);
            pc++;
            break;

        case Opcode.LOAD_SCENE:
//			bool destroy = ( code[ pc + 1 ] == 0 ) ? true : false ;
//			UnityWrapper.LoadScene( m_LoadedResource , destroy );
            LoadSceneNode.Do(m_LoadedResource, paramHash);
            m_LoadedResource = null;
            Resources.UnloadUnusedAssets();
            pc++;
            break;

        case Opcode.CLEAR_SCENE:
            GameObject advSceneRoot     = ViNoSceneManager.Instance.theSavedPanel;
            bool       immediateDestroy = false;
            SceneCreator.DestroyScene(advSceneRoot, immediateDestroy);
            pc++;
            break;

/*		case Opcode.PLAY_ANIMATION:
 *                      byte animationID = code[ pc + 1 ];
 *                      ViNoAnimationManager.Instance.PlayAnimation( (int)animationID );
 *                      pc+= 2;
 *                      break;
 * //*/

        // ----- Message -----.
        case Opcode.BR:
//			m_TextBuilder.Append( "\n" );
            pc++;           break;            //scriptBinder.BR( this );	pc++;		break;

        case Opcode.CM:         ClearMessage();                         pc++;           break;

        case Opcode.ER:
            AddToBacklog();
            ClearTextBuilder();
            if (m_MsgTargetTextBox != null)
            {
                m_MsgTargetTextBox.ClearMessage();
            }
            else
            {
                Debug.LogWarning("Current Message Target Not Set.");
            }
            pc++;
            break;

        case Opcode.PRINT:              scriptBinder.PRINT(this);                     pc++;           break;

        case Opcode.CURRENT:
            TriggerMessageEvent("OnMessageTargetChanged", code[pc + 1], "", true);
            break;

        case Opcode.SET_TEXT:
            TriggerMessageEvent("OnSetText", code[pc + 1], VirtualMachine.loadedTextLiteralString, true);
            m_CurrentText = m_MessageEventData.message;
            break;

        case Opcode.HIDE_MESSAGE:
            TriggerMessageEvent("OnHideMessage", code[pc + 1], "", false);
            break;

        // ------ System Opcode -----.
        case Opcode.START_WAIT:
            m_ElapsedSec = 0f;
            if (!string.IsNullOrEmpty(loadedTextLiteralString))
            {
                m_WaitSec = float.Parse(loadedTextLiteralString);
            }
            else
            {
                m_WaitSec = kWaitSec;
            }
            pc++;
            break;

        case Opcode.UPDATE_WAIT:
//			ViNoDebugger.Log( "VM" , "waiting ...");
            m_ElapsedSec += Time.deltaTime;
            if (m_ElapsedSec > m_WaitSec)
            {
                pc++;
            }
            break;

        case Opcode.STOP:
            // Wait Until Player choosing from options . or reached to the end of a leaf node .
            // Nothing to do...

            break;

        case Opcode.END:
            ViNoEventManager.Instance.TriggerEvent("OnFinishScenario");
            update = false;
            break;

        case Opcode.PLAY_SCENARIO:
            pc = ByteCodeReader.readString(code, pc + 2);
            string     scenarioName = loadedString;
            GameObject scenarioObj  = GOCache.SetActive(scenarioName, true);
            if (scenarioObj != null)
            {
                ScenarioNode s = scenarioObj.GetComponent <ScenarioNode>();
                s.Play();
            }
            break;

        case Opcode.FLAG_ON:
            if (ScenarioNode.Instance != null && ScenarioNode.Instance.flagTable != null)
            {
                ScenarioNode.Instance.flagTable.SetFlagBy(VirtualMachine.loadedTextLiteralString, true);
            }
            pc++;
            break;

        case Opcode.FLAG_OFF:
            if (ScenarioNode.Instance != null && ScenarioNode.Instance.flagTable != null)
            {
                ScenarioNode.Instance.flagTable.SetFlagBy(VirtualMachine.loadedTextLiteralString, false);
            }
            pc++;
            break;

        case Opcode.SELECTIONS:
            ISelectionsCtrl selCtrl = ISelectionsCtrl.Instance;
            if (selCtrl != null)
            {
                if (!selCtrl.IsActive())
                {
                    string title = VirtualMachine.loadedTextLiteralString;
                    selCtrl.SetTitle(title);
                    ISelectionsCtrl.Instance.ChangeActive(true);
                }
            }
            else
            {
                Debug.LogError("ISelectionsCtrl instance not found.");
            }
            pc++;
            break;

        case Opcode.LINK:               ISelectionsCtrl.Instance.AddSelection(ref paramHash); pc++;   break;

        case Opcode.WAIT_TOUCH:
            if (IScriptEngine.skip)
            {
                if (IScriptEngine.skipAlreadyPass && !VirtualMachine._ALREADY_PASS_THE_NODE)
                {
                    return;
                }

                _SkipText( );

                ISoundPlayer pl = ISoundPlayer.Instance;
                if (pl != null)
                {
                    if (pl.IsPlayingVoice())
                    {
                        pl.StopVoice();
                    }
                }
                m_CanTextProgress = true;
                return;
            }

            if (autoMode)
            {
                float dt = Time.deltaTime;
                m_TimeElapsed += dt;
                if (m_TimeElapsed > _AUTO_MODE_WAIT_TIME)
                {
                    m_TimeElapsed = 0f;
                    _SkipText();
                }
                return;
            }
            m_CanTextProgress = true;
            break;

//		case Opcode.PLAY_BGM:
//			break;

        // -----Audio -----.
        case Opcode.PLAY_SOUND:
            byte soundCategory = code[pc + 1];                  // 0: BGM 1:SE 2: VOICE.
            byte soundID       = code[pc + 2];

            UnityWrapper.PlaySound(soundCategory, soundID);
            if (soundCategory == 2)
            {
                SET_CURRENT_VOICE_ID(true, soundID);
            }
            pc += 3;
            break;

        case Opcode.STOP_SOUND:
            //TODO :

            pc++;
            break;

        case Opcode.STOP_VOICE:
            SET_CURRENT_VOICE_ID(false, 0);
            if (ISoundPlayer.Instance != null)
            {
                ISoundPlayer.Instance.StopVoice();
            }
            pc++;
            break;

        default:
            ViNoDebugger.LogError("VM", "PC : " + pc);
            break;
        }
    }
 public override void HandleSignal()
 {
     MessageBox.Info(success);
     UnityWrapper.LoadScene(Scenes.Lobby);
 }
 public void SetUp()
 {
     _homePage = UnityWrapper.Resolve <IHomePage>();
 }
Example #21
0
 private void OnButtonClicked()
 {
     UnityWrapper.LoadScene(SceneName);
 }
Example #22
0
        public ResponseHeaderType SaveOrUpdateVoyage(VoyageRequest request)
        {
            try
            {
                UnityWrapper.ConfiguredContainer.RegisterType <ILoginInformation, WcfLoginInformation>(
                    new UnityOperationContextLifetimeManager(),
                    new InjectionFactory(
                        container =>
                {
                    log.Debug($"Operation context hash: {OperationContext.Current.GetHashCode()} Creating WCFLoginInformation {request.Header.UserName}");
                    return(WcfLoginInformation.Authenticate(request.Header.UserName));
                })
                    );

                LoggedInPersonIDInterceptorUtil.RegisterPersonIdProviderWcfContext(() => new HasLoggedInPersonID
                {
                    LoggedInPersonID   = UnityWrapper.Resolve <ILoginInformation>().ID,
                    UserIdentification = UnityWrapper.Resolve <ILoginInformation>().UserIdentification,
                });

                //This variable delay simulates variances in the time it takes to handle a request in the real application.
                //E.g. some requests take longer to validate since the payload is larger.

                //Note: If this variable delay is removed, the clients will not interfere with each other.
                var delay = (int)(1000 * new Random().NextDouble());
                log.Debug($"Operation context hash: {OperationContext.Current.GetHashCode()} Delaying: {delay}, {request.Header.UserName}");
                Thread.Sleep(delay);

                var user = UnityWrapper.Resolve <ILoginInformation>();
                if (user == null)
                {
                    return(CreateResponse(StatusCodeEnumType.AccessDenied, $"Login failed for user {request.Header.UserName}"));
                }



                var dto = new VoyageService().GetById(request.Body.VoyageID) ?? new DAL.DTO.Classes.Voyage();

                if (!string.IsNullOrWhiteSpace(request.Body.ShipName))
                {
                    dto.ShipName = request.Body.ShipName;
                }

                if (!string.IsNullOrWhiteSpace(request.Body.ToLocation))
                {
                    dto.ToLocation = request.Body.ToLocation;
                }

                if (!string.IsNullOrWhiteSpace(request.Body.FromLocation))
                {
                    dto.FromLocation = request.Body.FromLocation;
                }

                if (request.Body.ETD != default(DateTime))
                {
                    dto.ETD = request.Body.ETD;
                }

                if (request.Body.ETA != default(DateTime))
                {
                    dto.ETA = request.Body.ETA;
                }

                dto = new VoyageService().SaveOrUpdate(dto);

                if (dto.ModifiedByPersonID != user.ID)
                {
                    var modifiedBy = new PersonService().GetById(dto.ModifiedByPersonID.GetValueOrDefault());
                    return(CreateResponse(StatusCodeEnumType.ServerError, $"The voyage with ID {dto.VoyageID} was modified by {modifiedBy.UserIdentification} - not {user.UserIdentification}"));
                }
            }
            catch (Exception ex)
            {
                return(CreateResponse(StatusCodeEnumType.ServerError, ex.Message));
            }

            return(CreateResponse(StatusCodeEnumType.OK));
        }
Example #23
0
        static public void CompileLine(ref M22.line_c _lineC, List <string> _splitStr, ref List <M22.script_checkpoint> _chkpnt, int _scriptPos)
        {
            for (int i = 0; i < _splitStr.Count; i++)
            {
                _splitStr[i] = _splitStr[i].Trim('\r', '\n', '\t');
            }
            switch (_lineC.m_lineType)
            {
            case M22.LINETYPE.CHECKPOINT:
                _lineC.m_parameters_txt = new List <string>();
                _splitStr[0]            = _splitStr[0].Substring(2).TrimEnd('\r', '\n');
                _lineC.m_parameters_txt.Add(_splitStr[0]);
                _chkpnt.Add(new M22.script_checkpoint(_scriptPos, _splitStr[0]));
                break;

            case M22.LINETYPE.ANIMATION_TYPE:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters = new List <int>();
                    _splitStr[1]        = _splitStr[1].ToLower();
                    if (_splitStr[1].Equals("lerp"))
                    {
                        _lineC.m_parameters.Add((int)ANIMATION_TYPES.LERP);
                    }
                    else if (_splitStr[1].Equals("smooth"))
                    {
                        _lineC.m_parameters.Add((int)ANIMATION_TYPES.SMOOTH);
                    }
                    else
                    {
                        UnityWrapper.LogErrorFormat("Invalid animation type at line {0}!", _lineC.m_origScriptPos);
                        _lineC.m_parameters.Add(0);
                    }
                }
                break;

            case M22.LINETYPE.TEXT_SPEED:
            case M22.LINETYPE.MOVEMENT_SPEED:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.SET_ACTIVE_TRANSITION:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.GOTO:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.NEW_PAGE:
                break;

            case M22.LINETYPE.DRAW_CHARACTER:
                if (_splitStr.Count > 1)
                {
                    if (_splitStr.Count < 4)
                    {
                        UnityWrapper.LogError("Not enough parameters for DrawCharacter @ Line " + _lineC.m_origScriptPos.ToString());
                    }
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                    _lineC.m_parameters_txt.Add(_splitStr[2]);
                    _lineC.m_parameters = new List <int>();
                    _lineC.m_parameters.Add(Int32.Parse(_splitStr[3]));
                    if (_splitStr.Count >= 5)
                    {
                        if (_splitStr[4].Equals("true"))
                        {
                            _lineC.m_parameters.Add(1);
                        }
                        else
                        {
                            _lineC.m_parameters.Add(0);
                        }
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                    }

                    if (!M22.VNHandler.LoadCharacter(_lineC.m_parameters_txt[0], _lineC.m_parameters_txt[1]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load character \"{0}\" at line {1}!", (_lineC.m_parameters_txt[0] + " - " + _lineC.m_parameters_txt[1]), _lineC.m_origScriptPos);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.WAIT:
                _lineC.m_parameters = new List <int>();
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters.Add(Int32.Parse(_splitStr[1]));
                }
                else
                {
                    _lineC.m_parameters.Add(1000);
                }
                break;

            case M22.LINETYPE.CLEAR_CHARACTERS:
                _lineC.m_parameters = new List <int>();
                if (_splitStr.Count > 1 && _splitStr[1].Equals("true"))
                {
                    _lineC.m_parameters.Add(1);
                }
                else
                {
                    _lineC.m_parameters.Add(0);
                }
                if (_splitStr.Count > 2 && _splitStr[2].Equals("true"))
                {
                    _lineC.m_parameters.Add(1);
                }
                else
                {
                    _lineC.m_parameters.Add(0);
                }
                break;

            case M22.LINETYPE.PLAY_STING:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (!M22.AudioMaster.LoadSting(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogError("Failed to load sting! - " + _lineC.m_parameters_txt[0]);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.PLAY_MUSIC:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (!M22.AudioMaster.LoadMusic(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load music file \"{0}\" at line {1}!", _lineC.m_parameters_txt[0], _lineC.m_origScriptPos);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.EXECUTE_FUNCTION:
                if (_splitStr.Count > 1)
                {
                    // heart_throb 4.0 2.0
                    //            |
                    _lineC.m_parameters_txt = new List <string>();
                    for (int i = 1; i < _splitStr.Count; i++)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[i]);
                    }
                    _splitStr[_splitStr.Count - 1] = _splitStr[_splitStr.Count - 1].TrimEnd('\r', '\n');
                    // _lineC.m_parameters_txt.Add(_splitStr[_splitStr.Count - 1]);

                    // should be 4
                    while (_lineC.m_parameters_txt.Count < 4)
                    {
                        _lineC.m_parameters_txt.Add("");
                    }

                    if (RegisteredCustomFunctions.TryGetValue(_splitStr[0], out _lineC.m_custFunc) == false)
                    {
                        UnityWrapper.LogErrorFormat("Custom function \"{0}\" does not exist at line {1}!", _lineC.m_parameters_txt[0], _lineC.m_origScriptPos);
                    }
                }
                break;

            case M22.LINETYPE.STOP_MUSIC:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    //_splitStr[1] = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                // we store the float value as a string for later use, if provided.
                // otherwise, just continue
                break;

            case M22.LINETYPE.TRANSITION:
                if (_splitStr.Count > 1)
                {       //Transition other_iwanako tr_eyes 0
                    _lineC.m_parameters_txt = new List <string>();
                    for (int i = 1; i < _splitStr.Count; i++)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[i]);
                    }

                    if (!M22.BackgroundMaster.LoadBackground(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load background - \"{0}\"", _lineC.m_parameters_txt[0]);
                        // failed to load bg!
                    }
                    ;
                }
                break;

            case M22.LINETYPE.DRAW_BACKGROUND:
                if (_splitStr.Count >= 2)
                {
                    _lineC.m_parameters     = new List <int>();
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                    if (_splitStr.Count >= 3)
                    {
                        _lineC.m_parameters.Add(Int32.Parse(_splitStr[2]));
                        if (_splitStr.Count >= 4)
                        {
                            _lineC.m_parameters.Add(Int32.Parse(_splitStr[3]));
                        }
                        if (_splitStr.Count >= 5)
                        {
                            _lineC.m_parameters_txt.Add(_splitStr[4]);
                        }
                        if (_splitStr.Count >= 6)
                        {
                            _lineC.m_parameters_txt.Add(_splitStr[5]);
                        }
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                        _lineC.m_parameters.Add(0);
                        _lineC.m_parameters_txt.Add("1.0");
                        _lineC.m_parameters_txt.Add("1.0");
                    }

                    if (_splitStr[_splitStr.Count - 1].Equals("true"))
                    {
                        _lineC.m_parameters.Add(1);
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                    }

                    if (!M22.BackgroundMaster.LoadBackground(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogErrorFormat("Failed to load background \"{0}\" at line {1}", _lineC.m_parameters_txt[0], _lineC.m_origScriptPos);
                    }
                    ;
                }
                else
                {
                    UnityWrapper.LogErrorFormat("Not enough parameters on DrawBackground at line {0}", _lineC.m_origScriptPos);
                }
                break;

            case M22.LINETYPE.ENABLE_NOVEL_MODE:
                break;

            case M22.LINETYPE.DISABLE_NOVEL_MODE:
                break;

            case M22.LINETYPE.PLAY_VIDEO:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (M22.ScriptMaster.LoadVideoFile(_splitStr[1]) == false)
                    {
                        UnityWrapper.LogError("Failed to load video file: " + _splitStr[1]);
                    }
                }
                break;

            case M22.LINETYPE.CLEAR_CHARACTER:
                if (_splitStr.Count >= 2)
                {
                    _lineC.m_parameters     = new List <int>();
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                    if (_splitStr.Count >= 3)
                    {
                        if (_splitStr[2].Equals("true"))
                        {
                            _lineC.m_parameters.Add(1);
                        }
                        else
                        {
                            _lineC.m_parameters.Add(0);
                        }
                    }
                    else
                    {
                        _lineC.m_parameters.Add(0);
                    }
                }
                break;

            case M22.LINETYPE.LOAD_SCRIPT:
            case M22.LINETYPE.HIDE_WINDOW:
            case M22.LINETYPE.SHOW_WINDOW:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.SET_FLAG:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _splitStr[1]            = _splitStr[1].TrimEnd('\r', '\n');
                    _lineC.m_parameters_txt.Add(_splitStr[1]);
                }
                break;

            case M22.LINETYPE.IF_STATEMENT:
                // m22IF _flag_to_check_if_true Command [params]
                //
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    line_c        tempCompiledLine = new line_c();
                    List <string> functionSplit    = new List <string>();
                    for (int i = 2; i < _splitStr.Count; i++)
                    {
                        functionSplit.Add(_splitStr[i]);
                    }
                    tempCompiledLine.m_lineType = CheckLineType(_splitStr[2]);
                    CompileLine(ref tempCompiledLine, functionSplit, ref _chkpnt, _scriptPos);
                    if (tempCompiledLine.m_lineContents == null)
                    {
                        tempCompiledLine.m_lineContents = "";
                        for (int i = 2; i < _splitStr.Count; i++)
                        {
                            tempCompiledLine.m_lineContents += _splitStr[i] + " ";
                        }
                    }
                    tempCompiledLine.m_lineContents = tempCompiledLine.m_lineContents.Replace("\\n", "\n");
                    _lineC.m_lineContents           = tempCompiledLine.m_lineContents;
                    _lineC.m_lineTypeSecondary      = tempCompiledLine.m_lineType;

                    if (tempCompiledLine.m_parameters_txt != null)
                    {
                        for (int i = 0; i < tempCompiledLine.m_parameters_txt.Count; i++)
                        {
                            _lineC.m_parameters_txt.Add(tempCompiledLine.m_parameters_txt[i]);
                        }
                    }

                    if (tempCompiledLine.m_parameters != null)
                    {
                        _lineC.m_parameters = new List <int>();
                        for (int i = 0; i < tempCompiledLine.m_parameters.Count; i++)
                        {
                            _lineC.m_parameters.Add(tempCompiledLine.m_parameters[i]);
                        }
                    }
                }
                break;

            case M22.LINETYPE.PLAY_SFX_LOOPED:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (_splitStr.Count > 3)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[2]);
                        _lineC.m_parameters_txt.Add(_splitStr[3]);
                    }
                    else
                    {
                        _lineC.m_parameters_txt.Add("1.0");
                        _lineC.m_parameters_txt.Add("1.0");
                    }

                    if (!M22.AudioMaster.LoadSting(_lineC.m_parameters_txt[0]))
                    {
                        UnityWrapper.LogError("Failed to load sting! - " + _lineC.m_parameters_txt[0]);
                    }
                    ;
                }
                break;

            case M22.LINETYPE.STOP_SFX_LOOPED:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    _lineC.m_parameters_txt.Add(_splitStr[1]);

                    if (AudioMaster.IsAudioLoaded(_splitStr[1]) == false)
                    {
                        UnityWrapper.LogWarningFormat("Stopping a looped SFX that isn't played/loaded yet at line {0}; this shouldn't happen!", _lineC.m_origScriptPos);
                    }

                    if (_splitStr.Count > 2)
                    {
                        _lineC.m_parameters_txt.Add(_splitStr[2]);
                    }
                    else
                    {
                        _lineC.m_parameters_txt.Add("1.0");
                    }
                }
                break;

            case M22.LINETYPE.MAKE_DECISION:
                if (_splitStr.Count > 1)
                {
                    _lineC.m_parameters_txt = new List <string>();
                    string reconstructed = "";
                    for (int i = 0; i < _splitStr.Count; i++)
                    {
                        reconstructed += _splitStr[i] + " ";
                    }
                    List <string> splitByQuote = new List <string>();
                    SplitString(ref reconstructed, ref splitByQuote, '\"');

                    // Should be 5 or 7
                    if (splitByQuote.Count != 5 && splitByQuote.Count != 7)
                    {
                        UnityWrapper.LogError("MakeDecision error; mismatched number of quotemarks!");
                    }

                    for (int i = 1; i < splitByQuote.Count; i++)
                    {
                        //splitByQuote[i] = _splitStr[i].TrimEnd(' ');
                        //splitByQuote[i] = _splitStr[i].TrimStart(' ');
                        splitByQuote[i] = splitByQuote[i].Trim(' ', '\"');
                        _lineC.m_parameters_txt.Add(splitByQuote[i]);
                    }

                    // up to 6 parameters
                    // flags do not use "" but the text string does
                    // i.e. MakeDecision "Choice 1" choice_1 "Choice 2" choice_2 "Choice 3" choice_3
                    // if(num of quotemarks != 6) mismatch error
                    //
                    // This means splitStr is useless cus of spaces, and will need to be re-split in terms of " marks
                    // i.e. splitStr[0] == "MakeDecision ";
                    // splitStr[1] == "Choice 1";
                    // splitStr[2] == " choice_1 ";
                }
                break;
            }
            return;
        }
 public override void HandleSignal()
 {
     UnityWrapper.LoadScene(Scenes.Session);
 }
 public TService ApplicationService <TService>()
 {
     return(UnityWrapper.Resolve <TService>());
 }