Example #1
0
        public string EvaluateFormula_Base(string formula, BaseClasses.Data.BaseRecord dataSourceForEvaluate, string format, System.Collections.Generic.IDictionary <string, object> variables, bool includeDS)
        {
            FormulaEvaluator e = new FormulaEvaluator();

            // add variables for formula evaluation
            if (variables != null)
            {
                System.Collections.Generic.IEnumerator <System.Collections.Generic.KeyValuePair <string, object> > enumerator = variables.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    e.Variables.Add(enumerator.Current.Key, enumerator.Current.Value);
                }
            }

            if (includeDS)
            {
                // add datasource as variables for formula evaluation

                if (View_Trap_SummaryCountQuery != null && View_Trap_SummaryCountQuery.Initialized)
                {
                    e.Variables.Add("View_Trap_SummaryCountQuery", View_Trap_SummaryCountQuery);
                }
            }


            e.CallingControl = this;

            // All variables referred to in the formula are expected to be
            // properties of the DataSource.  For example, referring to
            // UnitPrice as a variable will refer to DataSource.UnitPrice
            e.DataSource = dataSourceForEvaluate;

            // Define the calling control.
            e.CallingControl = this;

            object resultObj = e.Evaluate(formula);

            if (resultObj == null)
            {
                return("");
            }

            if (!string.IsNullOrEmpty(format) && (string.IsNullOrEmpty(formula) || formula.IndexOf("Format(") < 0))
            {
                return(FormulaUtils.Format(resultObj, format));
            }
            else
            {
                return(resultObj.ToString());
            }
        }
Example #2
0
        //public static PlayerItem CreateActorItemWithLevel(ICharacter itemData, int level)
        //{
        //    if (level <= 0)
        //        level = 1;
        //    //var itemTier = itemData.itemTier;
        //    var sumExp = 0;
        //    var result = new PlayerItem(PlayerItem.ItemType.character);
        //    result.itemType = PlayerItem.ItemType.character;
        //    for (var i = 1; i < level; ++i)
        //    {
        //        //sumExp += itemTier.expTable.Calculate(i + 1, itemTier.maxLevel);
        //        sumExp += Const.NextEXP;
        //    }
        //    result.ItemID = itemData.guid;
        //    //if(!isplayer)
        //    //result.GUID = itemData.;
        //    result.Exp = sumExp;
        //    result.ExtrAttributesData = GetExtraAttributes(type);
        //    return result;
        //}
        static CalculationAttributes GetExtraAttributes(Const.StageType type)
        {
            switch (type)
            {
            case Const.StageType.Normal:
                return(null);

                break;

            case Const.StageType.Tower:
                return(FormulaUtils.GetTowerExtraAttributes(false));

                break;
            }
            return(null);
        }
Example #3
0
 /// <summary>
 /// The running total of the field.
 /// This function is called as {TableName}TableControlRow.RUNNINGTOTAL().
 /// Say there are 5 rows and they contain 57, 32, 12, 19, 98.
 /// The respecitive values for running totals will be  be 57, 89, 101, 120, 218
 /// To make sure all the formula functions are in the same location, we call
 /// the RUNNINGTOTAL function in the FormulaUtils class, which actually does the work
 /// and return the value.  The function in FormulaUtils will need to know the
 /// TableControl, so it is passed as the first instance.
 /// </summary>
 /// <param name="controlName">The string name of the UI control (e.g., "UnitPrice") </param>
 /// <returns>The running total of the row.</returns>
 public virtual decimal RunningTotal(string controlName)
 {
     return(FormulaUtils.RunningTotal(this.GetParentTableControl(), this as BaseApplicationRecordControl, controlName));
 }
Example #4
0
 /// <summary>
 /// The row number of this record control within the table control.
 /// This function is called as {TableName}TableControlRow.ROWNUM().
 /// To make sure all the formula functions are in the same location, we call
 /// the ROWNUM function in the FormulaUtils class, which actually does the work
 /// and return the value. The function in FormulaUtils will need to know the
 /// TableControl, so it is passed as the first instance.
 /// The row number is 1 based.
 /// </summary>
 /// <returns>The row number of this row relative to the other rows in the table control.</returns>
 public virtual decimal RowNum()
 {
     return(FormulaUtils.RowNum(this.GetParentTableControl(), this as BaseApplicationRecordControl));
 }
Example #5
0
    public AttackInfo ReceiveDamage(CharacterEntity attacker, int pAtk, int mAtk, int acc, float critChance, float critDamageRate, int hitCount = 1, int fixDamage = 0)
    {
        lastAttacker = attacker;
        AttackInfo attackInfo = new AttackInfo();

        attackInfo.lastHP = self.Hp;
        if (hitCount <= 0)
        {
            hitCount = 1;
        }
        var attributes = self.GetTotalAttributes();
        var isCritical = false;
        var isBlock    = false;
        var totalDmg   = FormulaUtils.FightFormula(pAtk, mAtk, acc, critChance, critDamageRate, attributes, hitCount, fixDamage);

        // Critical occurs
        if (Random.value <= critChance)
        {
            totalDmg         = Mathf.CeilToInt(totalDmg * critDamageRate);
            isCritical       = true;
            attackInfo.baoji = true;
            self.ApplySkillAndBuff(CustomSkill.TriggerType.gobaoji);
        }
        // Block occurs
        if (Random.value <= attributes.exp_blockChance)
        {
            totalDmg          = Mathf.CeilToInt(totalDmg / attributes.exp_blockDamageRate);
            isBlock           = true;
            attackInfo.gedang = true;
            self.ApplySkillAndBuff(CustomSkill.TriggerType.gogedang);
        }

        var hitChance = 0f;

        if (acc > 0)
        {
            hitChance = acc / attributes.eva;
        }

        // Cannot evade, receive damage
        if (hitChance < 0 || Random.value > hitChance)
        {
            attackInfo.shanbi = true;
            DeductBlood((int)totalDmg, DmgType.Miss);
            self.ApplySkillAndBuff(CustomSkill.TriggerType.gomiss);
        }
        else
        {
            if (isBlock)
            {
                DeductBlood((int)totalDmg, DmgType.Block);
            }
            else if (isCritical)
            {
                DeductBlood((int)totalDmg, DmgType.Critical);
            }
            else
            {
                DeductBlood((int)totalDmg, DmgType.Normal);
            }
        }
        attackInfo.totalDamage = (int)totalDmg;
        if (self.Hp <= 0)
        {
            attackInfo.die = true;
        }
        self.ApplySkillAndBuff(CustomSkill.TriggerType.receiveDamage);
        // Play hurt animation
        //CacheAnimator.ResetTrigger(ANIM_KEY_HURT);
        //CacheAnimator.SetTrigger(ANIM_KEY_HURT);
        AnimReceiveDamage();
        FriensReceiveDamage();
        return(attackInfo);
    }
Example #6
0
 /// <summary>
 /// Range of the rows in the table control.
 /// This function is called as [Product]TableControl.COUNTA().
 /// To make sure all the formula functions are in the same location, we call
 /// the RANGE function in the FormulaUtils class, which actually does the work
 /// and return the value. The function in FormulaUtils will need to know the
 /// TableControl, so it is passed as the first instance.
 /// </summary>
 /// <param name="controlName">The string name of the UI control (e.g., "UnitPrice") </param>
 /// <returns>The total number of rows in the table control.</returns>
 public virtual decimal Range(string controlName)
 {
     return(FormulaUtils.Range(this as BaseApplicationTableControl, controlName));
 }