/// <summary>
 /// Class which can be used to "import" subscriptions via the API into Chargify
 /// </summary>
 /// <param name="vaultToken">The "token" provided by your vault storage for an already stored payment profile</param>
 /// <param name="customerVaultToken">The "customerProfileId" for the owner of the "customerPaymentProfileId" provided as the VaultToken</param>
 /// <param name="currentVault">The vault that stores the payment profile with the provided VaultToken</param>
 /// <param name="expYear">The year of expiration</param>
 /// <param name="expMonth">The month of expiration</param>
 /// <param name="cardType">If you know the card type, you may supply it here so that Chargify may display it in the AdminUI</param>
 /// <param name="lastFourDigits">The last four digits of the credit card for use in masked numbers</param>
 public PaymentProfileAttributes(string vaultToken, string customerVaultToken, VaultType currentVault, int expYear, int expMonth, CardType cardType, string lastFourDigits)
 {
     _vaultToken         = vaultToken;
     _customerVaultToken = customerVaultToken;
     _currentVault       = currentVault;
     _expirationYear     = expYear;
     _expirationMonth    = expMonth;
     _cardType           = cardType;
     _lastFour           = lastFourDigits;
 }
Esempio n. 2
0
            static void DoThreadOne(VaultType bmv, StartToken tkn)
            {
                HpTimeStamps.TimeStampSource.Calibrate();
                while (!tkn.IsSet)
                {
                }

                using var lck = bmv.Lock();
                Thread.Sleep(TimeSpan.FromMilliseconds(750));
                lck.Value += "Hi mom!";
            }
            static void DoThreadOne(VaultType bmv, StartToken tkn, string shouldBe)
            {
                HpTimeStamps.TimeStampSource.Calibrate();
                while (!tkn.IsSet)
                {
                }

                using var lck = bmv.RoLock();
                Thread.Sleep(TimeSpan.FromMilliseconds(750));
                Assert.Equal(lck.Value, shouldBe);
            }
Esempio n. 4
0
    protected override void StateStart(ref PlayerController ctrl)
    {
        base.StateStart(ref ctrl);
        //Set the hitboxes infromation and store its original size
        originalLowerHeight      = ctrl.colInfo.LowerHeight;
        ctrl.colInfo.LowerHeight = ctrl.PlayerVaultHeight - ctrl.colInfo.UpperHeight;
        //Set the distance from the edge of the obstacle. Need it for math later
        vaultDistFromObstacle = ctrl.colInfo.Radius + ctrl.VaultDistance;

        type = VaultType.SpeedVault;

        entryTimer = 0;
    }
Esempio n. 5
0
 public Tile(string[] tileData)
 {
     row           = Convert.ToInt32(tileData[0]);
     column        = Convert.ToInt32(tileData[1]);
     room          = bool.Parse(tileData[2]);
     spawn         = bool.Parse(tileData[3]);
     containsVault = (VaultType)Enum.Parse(typeof(VaultType), tileData[4]);
     objective     = bool.Parse(tileData[5]);
     TopSide       = (RoomSide)Enum.Parse(typeof(RoomSide), tileData[6]);
     BottomSide    = (RoomSide)Enum.Parse(typeof(RoomSide), tileData[7]);
     LeftSide      = (RoomSide)Enum.Parse(typeof(RoomSide), tileData[8]);
     RighSide      = (RoomSide)Enum.Parse(typeof(RoomSide), tileData[9]);
 }
Esempio n. 6
0
        void ClimbOver(RaycastHit hit, ref bool willClimb)
        {
            float targetDistance = distanceToCheckForward + 0.1f;

            if (run)
            {
                targetDistance += 0.5f;
            }

            Vector3 ClimbCheckOrigin
                = transform.position + (Vector3.up * Statics.walkUpHeight);
            RaycastHit climbHit;

            Vector3 wallDirection = -hit.normal * targetDistance;

            Debug.DrawRay(ClimbCheckOrigin, wallDirection, Color.yellow);
            if (Physics.Raycast(ClimbCheckOrigin, wallDirection, out climbHit, 1.2f, ignoreLayers))
            {
                // do nothing
            }
            else
            {
                Vector3 origin2 = hit.point;
                origin2.y = transform.position.y;
                origin2  += Vector3.up * Statics.walkUpHeight;
                origin2  += wallDirection * 0.2f;
                Debug.DrawRay(origin2, -Vector3.up, Color.yellow);
                if (Physics.Raycast(origin2, -Vector3.up, out climbHit, 1, ignoreLayers))
                {
                    float diff = climbHit.point.y - transform.position.y;
                    if (Mathf.Abs(diff) > Statics.walkUpThreshold)
                    {
                        vaulting            = true;
                        targetVaultPosition = climbHit.point;
                        curVaultType        = VaultType.walk_up;
                        obstacleForward     = false;
                        willClimb           = true;
                        skipGroundCheck     = true;
                        return;
                    }
                }
            }
        }
Esempio n. 7
0
            static IClortonGameFactory GetGameFactory(int idx, VaultType evenVaultType)
            {
                IClortonGameFactory ret;
                var  factory = new ClortonGameFactorySource();
                bool isEven  = idx % 2 == 0;

                if (isEven)
                {
                    ret = evenVaultType == VaultType.Basic
                        ? factory.BasicVaultGameFactory
                        : factory.CustomVaultGameFactory;
                }
                else
                {
                    ret = evenVaultType == VaultType.Basic
                        ? factory.CustomVaultGameFactory
                        : factory.BasicVaultGameFactory;
                }
                return(ret);
            }
Esempio n. 8
0
 static void DoThreadTwo(VaultType bv, StartToken tkn, ExceptionReceptor receptor)
 {
     HpTimeStamps.TimeStampSource.Calibrate();
     while (!tkn.IsSet)
     {
     }
     Thread.Sleep(TimeSpan.FromMilliseconds(250));
     try
     {
         using var lck = bv.Lock(TimeSpan.FromMilliseconds(10));
         receptor.SetBadException();
     }
     catch (TimeoutException ex)
     {
         receptor.SupplyExceptionOrThrow(ex);
     }
     catch (Exception rx)
     {
         receptor.SupplyExceptionOrThrow(rx);
     }
 }
Esempio n. 9
0
        void IsClear(Vector3 origin, Vector3 direction, float distance, ref bool isHit)
        {
            RaycastHit hit            = new RaycastHit();
            float      targetDistance = distance;

            if (run)
            {
                targetDistance += 0.5f; // når man løber måler Raycastet længere fremme end når man går.
            }
            int numberOfHits = 0;

            for (int i = -1; i < 2; i++) // man laver tre raycasts fremad for at være sikker at man ikke bare rammer kanten af et obstacle.
            {
                Vector3 targetOrigin = origin;
                targetOrigin += transform.right * (i * 0.3f);
                Debug.DrawRay(targetOrigin, direction * targetDistance, Color.green);
                if (Physics.Raycast(targetOrigin, direction, out hit, targetDistance, ignoreLayers))
                {
                    numberOfHits++;
                }
            }

            if (numberOfHits > 2)
            {
                isHit = true;
            }
            else
            {
                isHit = false;
            }

            if (obstacleForward)
            {
                Vector3 incomingVec = hit.point - origin;
                Vector3 reflectVect = Vector3.Reflect(incomingVec, hit.normal);
                float   angle       = Vector3.Angle(incomingVec, reflectVect);

                if (angle < 70)
                {
                    obstacleForward = false;
                }
                else
                {
                    if (numberOfHits > 2) // antal af raycasts forud der skal ramme et "vaultable object" for at kunne vaulte
                    {
                        bool willVault = false;
                        CanVaultOver(hit, ref willVault);

                        if (willVault)
                        {
                            curVaultType = VaultType.walk;
                            if (run)
                            {
                                curVaultType = VaultType.run;
                            }
                            obstacleForward = false;
                            return;
                        }
                        else
                        {
                            bool willClimb = false;

                            ClimbOver(hit, ref willClimb);

                            if (!willClimb)
                            {
                                obstacleForward = true;
                                return;
                            }
                        }
                    }
                }
            }

            if (groundForward)
            {
                if (curState == CharStates.moving)
                {
                    Vector3 p1    = transform.position;
                    Vector3 p2    = hit.point;
                    float   diffy = p1.y - p2.y;
                    groundAngle = diffy;
                }

                float targetIncline = 0;

                if (Mathf.Abs(groundAngle) > 0.3f)
                {
                    if (groundAngle < 0)
                    {
                        targetIncline = 1;
                    }
                    else
                    {
                        targetIncline = -1;
                    }
                }

                if (groundAngle == 0)
                {
                    targetIncline = 0;
                }

                anim.SetFloat(Statics.incline, targetIncline, 0.3f, Time.deltaTime);
            }
        }
Esempio n. 10
0
    protected override void StateUpdate(ref PlayerController ctrl)
    {
        base.StateUpdate(ref ctrl);
        if (type == VaultType.SpeedVault && entryTimer < vaultEntryTime)
        {
            entryTimer += Time.deltaTime;
            if (InputManager.GetInput("Crouch") != 0)
            {
                actionInputPressed = false;
                type = VaultType.MonkeyVault;
                //Find the DoJump transition index
                for (int i = 0; i < transitions.Length; i++)
                {
                    if (transitions[i] as DidJump != null)
                    {
                        transitionIndex = i;
                    }
                }
            }
            else if (InputManager.GetInput("Grab") != 0
                     //Make sure we can perform the switch vault or 180 vault.
                     && !Physics.SphereCast(ctrl.colInfo.GetOriginPosition() + ctrl.direction.HozDirection * MoveDist,
                                            ctrl.colInfo.Radius + ctrl.colInfo.CollisionOffset,
                                            Vector3.down,
                                            out _,
                                            //We assume that the bottom of the players collider is basically at the same height as the obstacles
                                            ctrl.colInfo.Height + ctrl.colInfo.LowerHeight))
            {
                //There is enough space to perform the 180 vault.
                type = VaultType.SwitchVault;
                //Since we are doing a 180 vault, we need to know the distance to the other side of the obstacle for the ledge move when we swap into it at the end
                if (!Physics.Raycast(ctrl.transform.position + ctrl.direction.HozDirection * MoveDist + Vector3.down * (ctrl.colInfo.Height + originalLowerHeight)
                                     , -ctrl.direction.HozDirection,
                                     out RaycastHit h,
                                     MoveDist))
                {
                    //Let somebody know that the switch vault broke a bit
                    Debug.LogError("Obstacle not found. Switch Vault/180Vault cannot assign propper values for the AtLedge transition check later.");
                }
                else
                {
                    ctrl.CheckDir      = -h.normal;
                    ctrl.CheckDirRange = h.distance;
                }
                //Now all we need to do is make sure the players origin is positioned correctly before we check AtLedge.
                //The correct position is where the top of their collider is only just above the ledge.
                //We can just use height since the players height has already changed. Since we are only changing the players lower height, it makes it easier.
                //We take the current position offset. We assume that the bottom of the players collider is basically just above the obstacle so we can use that to move the origin just below the ledge, like I said 2 lines up
                Vector3 offsetToApply = ctrl.colInfo.PositionOffset + (Vector3.down * ctrl.colInfo.Height);
                //Now the offsetToApply is the direction and how much by, we need to move the player to be below the top of the obstacle
                ctrl.transform.position += offsetToApply;
                //We need to apply the inverse to the players collider offset else it won't be the right height for the vault and might cause collision problems
                ctrl.colInfo.PositionOffset -= offsetToApply;
                ctrl.camFol.positionOffset   = -offsetToApply;
                camOriginalPositionOffset    = ctrl.camFol.positionOffset;
                //Now the players height is correct!
                //Find the AtLedge transition index
                for (int i = 0; i < transitions.Length; i++)
                {
                    if (transitions[i] as SwitchVaultToLedgeGrab != null)
                    {
                        transitionIndex = i;
                    }
                }

                //NOTE: IF ATLEDGE TRANSITION IS EVER CHANGED TO USE ctrl.colInfo.GetOriginPosition() INSTEAD OF ctrl.transform.position
                //THIS WILL HAVE TO BE UPDATED.
            }
        }
Esempio n. 11
0
        private static void PlayMultipleClortonGames(int count, FileInfo outputFile)
        {
            if (count < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(count), count, "Parameter not positive.");
            }

            string    failingBufferContents = string.Empty;
            VaultType oddVaultType          = TheRng.Next(0, 2) == 0 ? VaultType.Basic : VaultType.Custom;
            VaultType evenVaultType         = oddVaultType == VaultType.Basic ? VaultType.Custom : VaultType.Basic;

            for (int i = 1; i <= count; ++i)
            {
                using IBufferBasedOutputHelper outputHelper = OrderedThreadSafeTestOutputHelper.CreateInstance();
                {
                    Console.WriteLine($"Starting game {i} of {count}");
                    ClortonGameResult?result;
                    var factory = GetGameFactory(i, evenVaultType);
                    using (IClortonGame game = factory.CreateClortonGame(outputHelper, 3, ClortonGame_GameEnded))
                    {
                        Console.WriteLine("Concrete type of clorton game: [" + game.GetType().Name + "].");
                        result = WaitForGameEndOrTimeout(TimeSpan.FromSeconds(3));

                        if (result == null)
                        {
                            Console.Error.WriteLine(
                                $"FAILED: The clorton game# {i} of {count} faulted.  No results can be retrieved.");
                            string bufferContents = TryGetBufferContents(TimeSpan.FromSeconds(2), outputHelper);
                            LogContents(i, null, bufferContents, outputFile);
                            return;
                        }

                        ClortonGameResult finalRes = result.Value;
                        bool success = finalRes.Success && ValidateFinalResult(in finalRes);
                        if (success)
                        {
                            Console.WriteLine($"Game {i} of {count} finished ok.");
                        }
                        else
                        {
                            Console.WriteLine($"FAULT Game {i} of {count} FAULTED.");
                            if (finalRes.Cancelled)
                            {
                                Console.WriteLine("The game was cancelled.");
                            }
                            else
                            {
                                Console.WriteLine("There were {0} xes and {1} oes.", finalRes.XCount,
                                                  finalRes.OCount);
                                Console.WriteLine(finalRes.WinningThreadIndex != null
                                    ? ("The winning reader thread was thread at index " +
                                       finalRes.WinningThreadIndex.Value + ".")
                                    : "There was no winning thread.");
                            }
                            Environment.Exit(-1);
                            return;
                        }
                    }
                }
            }

            void LogContents(int gameNum, in ClortonGameResult?res, string buff, FileInfo of)
            {
                Console.WriteLine($"Writing final string and logs to file for failed game# {gameNum}.");
                try
                {
                    using (var sw = of.CreateText())
                    {
                        sw.WriteLine("The final string was:");
                        sw.WriteLine(res?.FinalString ?? string.Empty);
                        sw.WriteLine("END FINAL STRING");

                        if (!string.IsNullOrWhiteSpace(buff))
                        {
                            sw.WriteLine();
                            sw.WriteLine("Log follows:");
                            sw.WriteLine(buff);
                            sw.WriteLine("End LOG.");
                        }
                        else
                        {
                            sw.WriteLine();
                            sw.WriteLine("Log unavailable.");
                        }
                    }

                    Console.WriteLine("Successfully wrote to [" + outputFile.FullName + "].");
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine("There was an error writing to file [" + outputFile.FullName +
                                            "]: contents: [" + ex + "].  File not written.");
                }
            }

            string TryGetBufferContents(TimeSpan timeout, IBufferBasedOutputHelper helper)
            {
                string ret;

                try
                {
                    ret = helper.GetCurrentTextAndClearBuffer(timeout);
                }
                catch (TimeoutException ex)
                {
                    Console.Error.WriteLine(ex.ToString());
                    string moreToSay =
                        "Unable to retrieve logs from the output helper " +
                        "because of timeout.  No results file can be written.";
                    Console.Error.WriteLine(moreToSay);
                    ret = string.Empty;
                }
                catch (Exception ex)
                {
                    Console.Error.WriteLine(ex.ToString());
                    string moreToSay = "Unable to retrieve logs from the output helper " +
                                       "because of unexpected exception.  No results file can be written.";
                    Console.Error.WriteLine(moreToSay);
                    ret = string.Empty;
                }

                return(ret);
            }