예제 #1
0
        public async void RecordTransaction(UserTransaction userTransaction, RechargeRequestResource rechargeRequestResource)
        {
            userTransaction.DateCreated           = DateTime.Now;
            userTransaction.TransactionFee        = 2 * transactionFee;
            userTransaction.UserPoint             = PointFunctions.GetBonus(userTransaction.Amount);
            userTransaction.AdditionalInformation = rechargeRequestResource.AdditionalInformation();
            if (userTransaction.User.RefererId != null)
            {
                RecordReferersTransaction(userTransaction);
            }

            userTransaction.Balance = userTransaction.UserPoint + await GetUsersPoint(userTransaction.User.Id.ToString());

            _context.Add(userTransaction);

            // var Transaction = new UserTransaction() {
            //     UserId = e.User.Id,
            //     RefererId = e.User.RefererId,
            //     Amount = e.Transaction.Amount,
            //     // Points = Functions.GetBonus(e.Transaction.amount),
            //     // RefererPoint = Functions.GetBonus(e.Transaction.amount, false),
            //     // PaymentType = e.Transaction.PaymentType(),
            //     AdditionalInformation = e.Transaction.AdditionalInformation(),
            //     DateCreated = DateTime.Now,
            //     TransactionFee = .015m * e.Transaction.Amount
            // };
            // _context.Add(Transaction);

            // if(!await _context.SaveAll()){
            //     throw new Exception("Failed to save transaction");
            // }

            // RecordPublicTransaction(_mapper.Map<UserTransaction, PublicPaymentTransaction>(Transaction), e.User);
        }
예제 #2
0
        private async void RecordReferersTransaction(UserTransaction userTransaction)
        {
            var referTransaction = _mapper.Map <UserTransaction>(userTransaction);

            referTransaction.TransactionFee        = 1 * transactionFee;
            referTransaction.UserPoint             = PointFunctions.GetBonus(userTransaction.Amount, false);
            referTransaction.Amount                = 0.0m;
            referTransaction.User                  = userTransaction.User.Referer;
            referTransaction.Transactions          = new List <AppTransaction>();
            referTransaction.AdditionalInformation = null;
            referTransaction.Balance               = referTransaction.UserPoint + await GetUsersPoint(userTransaction.User.Id.ToString());

            _context.Add(referTransaction);
            //  _context.Add(transaction);
            // var publicTransactions = _repo.PublicPaymentTransactions.Where(u => u.UserId == user.Id);
            // var count = await publicTransactions.CountAsync();
            // if(count > maxCount + 1) {
            //     // var newPublicTransactions = publicTransactions.OrderByDescending(d => d.DateCreated).Take(maxCount);
            //     var mergePublicTransactions = publicTransactions.OrderByDescending(d => d.DateCreated).TakeLast(count - maxCount);
            //     var newPublicTransactions = new PublicPaymentTransaction(){
            //         DateCreated = DateTime.MinValue
            //     };

            //     foreach (var trans in mergePublicTransactions)
            //     {
            //         newPublicTransactions.Points += trans.Points;
            //         newPublicTransactions.RefererPoint += trans.RefererPoint;
            //         newPublicTransactions.Amount += trans.Amount;
            //     }

            //     _context.Delete(mergePublicTransactions);
            //     _context.Add(newPublicTransactions);
            // }
        }
예제 #3
0
        public static double FindMaxDistance(IList <Point> contourPoints, PointF candidate)
        {
            double result = double.MaxValue;

            foreach (var point in contourPoints)
            {
                result = Math.Min(PointFunctions.Distance(point.X, point.Y, candidate.X, candidate.Y), result);
            }
            return(result);
        }
예제 #4
0
        public double Interpolate(double x)
        {
            var interval = PointFunctions.FindInterval(x, _points);

            if (interval.left is null || interval.right is null || interval.left.Equals(interval.right))
            {
                throw new ArgumentOutOfRangeException($"Wrong interpolation point (x = {x}).");
            }
            return(interval.left.Y + (((x - interval.left.X) / (interval.right.X - interval.left.X)) * (interval.right.Y - interval.left.Y)));
        }
예제 #5
0
    public bool isInRange(int targetX, int targetY, int range)
    {
        float dist = PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetX, targetY));

        if (dist <= range)
        {
            return(true);
        }

        return(false);
    }
예제 #6
0
        public double Interpolate(double x)
        {
            var interval = PointFunctions.FindInterval(x, _points);

            if (interval.Item1 is null || interval.Item2 is null || interval.Item1.Equals(interval.Item2))
            {
                throw new ArgumentOutOfRangeException($"Wrong interpolation point (x = {x}).");
            }

            double deltaX = interval.Item2.X - interval.Item1.X;

            double _xt = (1.0 - Math.Cos((x - interval.Item1.X) / deltaX * Math.PI)) / 2.0;

            return(interval.Item1.Y * (1.0 - _xt) + interval.Item2.Y * _xt);
        }
예제 #7
0
        public double Interpolate(double x)
        {
            var _interval = PointFunctions.FindIntervalIndex(x, _points);
            int _idxLeft  = _interval.Item1;
            int _idxRight = _interval.Item2;

            //width of bracketing interval
            double _dX = _points[_idxRight].X - _points[_idxLeft].X;

            if (_dX == 0.0)
            {
                throw new ArgumentOutOfRangeException($"Two points have the same X value (x={x}).");
            }

            double _rightX = (_points[_idxRight].X - x) / _dX;
            double _leftX  = (x - _points[_idxLeft].X) / _dX;
            double _result = _rightX * _points[_idxLeft].Y +
                             _leftX * _points[_idxRight].Y +
                             ((Math.Pow(_rightX, 3) - _rightX) * _derivatives[_idxLeft] +
                              (Math.Pow(_leftX, 3) - _leftX) * _derivatives[_idxRight]) *
                             Math.Pow(_dX, 2) / 6.0;

            return(_result);
        }
예제 #8
0
    // Update is called once per frame
    void Update()
    {
        if (m_isDead && m_myTurn)
        {
            m_battleSystem.EndTurn();
            return;
        }

        if (m_playingSkillAnimation || m_playingItemAnimation)
        {
            return;
        }

        //move animation
        if (moveTimer > 0)
        {
            r_myTurnMarker.SetActive(false);
            moveTimer -= Time.deltaTime * 2;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(newPos, oldPos, moveTimer), gameObject.transform.rotation);
        }
        else if (moveTimer < 0)
        {
            r_myTurnMarker.SetActive(true);
            moveTimer = 0;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(newPos, oldPos, moveTimer), gameObject.transform.rotation);
        }

        //attackAnimation
        if (attackTimer > 0 && m_attackHasHit == false)
        {
            r_myTurnMarker.SetActive(false);
            attackTimer -= Time.deltaTime * 4;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(attackPos, oldPos, attackTimer), gameObject.transform.rotation);
        }
        else if (attackTimer < 0 && m_attackHasHit == false)
        {
            r_myTurnMarker.SetActive(false);
            m_attackHasHit = true;
            //deal Damage
            m_battleSystem.m_battleSpaces[m_targetX, m_targetY].m_pawn.TakeDamage(this, DamageType.DAMAGETYPE_PHYSICAL, 1.0f);
            if (gameObject.tag == "Player")
            {
                m_battleSystem.AttackEnd(false);
            }
        }
        else if (attackTimer > 1 && m_attackHasHit == true)
        {
            r_myTurnMarker.SetActive(true);
            attackTimer = 1;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(attackPos, oldPos, attackTimer), gameObject.transform.rotation);
        }
        else if (attackTimer < 1 && m_attackHasHit == true)
        {
            r_myTurnMarker.SetActive(false);
            attackTimer += Time.deltaTime * 3;
            gameObject.transform.SetPositionAndRotation(Vector3.Lerp(attackPos, oldPos, attackTimer), gameObject.transform.rotation);
        }



        if (m_HP <= 0)
        {
            Death();
            return;
        }

        if (!m_myTurn)
        {
            r_myTurnMarker.SetActive(false);
            return;
        }

        if (m_AP == 0 && m_myTurn)
        {
            EndTurn();
            return;
        }

        if (gameObject.tag == "Enemy" && m_myTurn)
        {
            m_enemyActionTimer += Time.deltaTime;
            if (m_enemyActionTimer < m_enemyActionDelay)
            {
                return;
            }
            //check if player is in range
            m_enemyActionTimer = 0;
            //attack an adjecent enemy
            {
                //right space
                if (m_x < 7)
                {
                    if (m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x + 1, m_y, m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }
                //up space
                if (m_y < 3)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x, m_y + 1, m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }
                //left space
                if (m_x > 0)
                {
                    if (m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x - 1, m_y, m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }

                //down space
                if (m_y > 0)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_occupied)
                    {
                        if (m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_pawn.gameObject.tag == "Player")
                        {
                            Attack(m_x, m_y - 1, m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_pawn.gameObject.transform.position);
                            m_AP--;
                            return;
                        }
                    }
                }
            }
            //if no adjecent enemy, move towards target
            List <BattleSpace> targetSpaces = r_targetPlayer.GetAdjacentSpaces();
            List <float>       distences    = new List <float>();

            int i = 0;
            //right space
            if (r_targetPlayer.m_x > 0)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }
            //up space
            if (r_targetPlayer.m_y < 3)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }
            //left space
            if (r_targetPlayer.m_x < 7)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }

            //down space
            if (r_targetPlayer.m_y > 0)
            {
                distences.Add(PointFunctions.DistanceTo(new Vector2(m_x, m_y), new Vector2(targetSpaces[i].x, targetSpaces[i].y)));
                i++;
            }
            bool found = false;

            float lowestDist = 0;
            int   lowestJ    = 0;

            while (!found && distences.Count >= 0)
            {
                lowestJ    = 0;
                lowestDist = 0;
                for (int j = 0; j < distences.Count; j++)
                {
                    if (distences[j] < lowestDist)
                    {
                        lowestJ    = j;
                        lowestDist = distences[j];
                    }
                }

                if (targetSpaces[lowestJ].m_occupied)
                {
                    targetSpaces.RemoveAt(lowestJ);
                    distences.RemoveAt(lowestJ);
                }
                else
                {
                    found = true;
                }
            }

            if (found)
            {
                BattleSpace targetSpace = targetSpaces[lowestJ];
                //if the target space is to the right move right
                if (targetSpace.x > m_x)
                {
                    //only if right is unocupied
                    if (m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_occupied == false)
                    {
                        MoveTo(m_x + 1, m_y, new Vector3(m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x + 1, m_y].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }

                //if it is left move left
                if (targetSpace.x < m_x)
                {
                    //and if left is unocupied
                    if (m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_occupied == false)
                    {
                        MoveTo(m_x - 1, m_y, new Vector3(m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x - 1, m_y].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }
                // if it is up
                if (targetSpace.y > m_y)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_occupied == false)
                    {
                        MoveTo(m_x, m_y + 1, new Vector3(m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x, m_y + 1].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }

                // if it is down
                if (targetSpace.y < m_y)
                {
                    if (m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_occupied == false)
                    {
                        MoveTo(m_x, m_y - 1, new Vector3(m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_cube.transform.position.x,
                                                         gameObject.transform.position.y,
                                                         m_battleSystem.m_battleSpaces[m_x, m_y - 1].m_cube.transform.position.z));
                        m_AP--;
                        return;
                    }
                }
            }



            EndTurn();
        }
    }