示例#1
0
        public override bool Check(IConditionFormula data)
        {
            var value1 = _logic.Calculate(data.FormulaValue1);
            var value2 = _logic.Calculate(data.FormulaValue2);

            return(data.Operator.Check(value1, value2));
        }
示例#2
0
 public override void Execute(IImpactDelay data)
 {
     if (_context.BattleMode)
     {
         if (_context.TurnType == BattleTurnResultType.ActiveAbility || _context.TurnType == BattleTurnResultType.PassiveAbility)
         {
             _logic.BatchAbilityInFrame();
             var frameData = new FrameAbility
             {
                 FamiliarAnimStart = false,
                 UnityId           = null,
                 Time = (float)_formula.Calculate(data.Value)
             };
             _logic.Data = frameData;
         }
         else
         {
             _logic.BatchOtherInFrame();
             var frameData = new FrameOther
             {
                 Time = (float)_formula.Calculate(data.Value)
             };
             _logic.Other = frameData;
         }
     }
     else
     {
         var delay = (float)_formula.Calculate(data.Value);
         _logic.BatchCutScene(delay);
     }
 }
 public override double Calculate(IFormulaIf formulaData)
 {
     if (_condition.Check(formulaData.If))
     {
         return(_formula.Calculate(formulaData.Than));
     }
     return(_formula.Calculate(formulaData.Else));
 }
        public override double Calculate(IFormulaRand formulaData)
        {
            var max = _logic.Calculate(formulaData.Max);
            var min = _logic.Calculate(formulaData.Min);

            if (!_data.IsEmulate)
            {
                return(min + (float)new System.Random().NextDouble() * (max - min));
            }
            else
            {
                return(min);
            }
        }
        public void UpdateAbility(int owner, int abilityId)
        {
            var data          = _battle.GetMember(owner);
            var abilityData   = data.Abilities[abilityId];
            var abilityStatic = _units.Static.Abilities[abilityId];

            _context.SetContextFormula(owner);
            var value = (int)_formula.Calculate(abilityStatic.Mana);

            _context.SetContextFormula(null);
            if (value != 0)
            {
                SpendManaAction(value);
            }
            abilityData.CountTurn   += 1;
            abilityData.CountBattle += 1;

            //if (_manager._mainTarget == null)
            //{
            //    Logger.Error($"No main target ownerId = {owner} ability Id = {abilityId}", this);
            //    if (_battle.State.Data.Enemies.ContainsKey(owner))
            //    {
            //        _manager.SetAbilityTarget(_battle.State.Data.Allies.FirstOrDefault().Key);
            //    }
            //    else
            //    {
            //        _manager.SetAbilityTarget(_battle.State.Data.Enemies.FirstOrDefault().Key);
            //    }
            //}

            _manager.BatchBattleAbility(owner, abilityId);
        }
示例#6
0
        public void UpdateGroups(int groupId, long currentTime)
        {
            var group = _shop.GetGroup(groupId);

            if (group.Slots != null && group.Slots.Count > 0)
            {
                if (!_shop.State.Groups.TryGetValue(groupId, out var data))
                {
                    data = _shop.State.Groups[groupId] = _shop.Factory.CreateGroup();
                }
                data.FinishTime = currentTime;
                var list = new List <IGoodSlotItem>();

                foreach (var temp in group.Slots.OrderBy(x => x.Key))
                {
                    if (temp.Value.Goods == null)
                    {
                        Logger.Error($"groupId = {groupId} slot = {temp.Key} groups = null", this);
                        continue;
                    }
                    var dataWeight = new List <(int, int)>();
                    foreach (var temp1 in temp.Value.Goods)
                    {
                        var weight = (int)_formula.Calculate(temp1.Value.Weight);
                        dataWeight.Add((weight, temp1.Value.GoodId));
                    }
                    var goodId = _settings.GetWeightRandom(dataWeight).Item2;
                    list.Add(_shop.Factory.CreateSlot(goodId));
                }
                _shop.State.Groups[groupId].CurrentSlots = _shop.Factory.CreateGroupSlot(list.ToArray());
            }
        }
        public BattleParamData CalculateInitiative(int mobId, FormulaController formulaLogic)
        {
            var mob = GetMob(mobId);

            return(new BattleParamData()
            {
                Value = (float)formulaLogic.Calculate(mob.Initiative)
            });
        }
        public override bool Check(IUnitConditionHp restictionData)
        {
            var current   = _context.GetCurrentHp(_context.ContextCondition.CurrentTarget);
            var maxHp     = _context.GetMaxHp(_context.ContextCondition.CurrentTarget, _logic);
            var currentHp = 100 * current / maxHp;
            var value     = (int)_logic.Calculate(restictionData.Value);

            return(restictionData.Operator.Check(currentHp, value));
        }
        public BattleParamData CalculateStreath(int mobId, FormulaController formulaLogic)
        {
            var mob = GetMob(mobId);

            return(new BattleParamData()
            {
                Value = (float)formulaLogic.Calculate(mob.Strength)
            });
        }
        public override double Calculate(IFormulaModObjects formulaData)
        {
            if (formulaData.ArgsMod == null || formulaData.ArgsMod.Count == 0)
            {
                return(0);
            }
            long result = (long)(_logic.Calculate(formulaData.ArgsMod[0]) * Val);

            if (formulaData.ArgsMod.Count == 1)
            {
                return(result);
            }

            for (var i = 1; i < formulaData.ArgsMod.Count; i++)
            {
                result = result % (long)(_logic.Calculate(formulaData.ArgsMod[i]) * Val);
            }
            return((float)result / Val);
        }
示例#11
0
        public override double Calculate(IFormulaMult formulaData)
        {
            var result = 1.0;

            foreach (var temp in formulaData.ArgsMult.Values)
            {
                result *= _logic.Calculate(temp);
            }
            return(result);
        }
        public override double Calculate(IFormulaDiv formulaData)
        {
            if (formulaData.ArgsDiv == null || formulaData.ArgsDiv.Count == 0)
            {
                return(0);
            }
            var result = _logic.Calculate(formulaData.ArgsDiv[0]);

            if (formulaData.ArgsDiv.Count == 1)
            {
                return(result);
            }

            for (var i = 1; i < formulaData.ArgsDiv.Count; i++)
            {
                result = result / _logic.Calculate(formulaData.ArgsDiv[i]);
            }
            return(result);
        }
示例#13
0
        public override double Calculate(IFormulaPow formulaData)
        {
            var result = 0.0;

            if (formulaData.Root != null)
            {
                var f = (float)_logic.Calculate(formulaData.Root);
                result = Mathf.Pow(f, formulaData.Power);
            }
            return(result);
        }
示例#14
0
        public BattleParamData CalculateInitiative(IUnitData data, FormulaController formula)
        {
            var unit = Static.Units[data.Id];

            return(new BattleParamData
            {
                Value = (int)formula.Calculate(unit.Initiative),
                Equip = CalculateEquipInit(data.Id),
                Base = unit.Rarities.Where(x => x.Value.Stars == data.Stars).Sum(x => x.Value.Initiative),
            });
        }
示例#15
0
        public override double Calculate(IFormulaSum formulaData)
        {
            var result = 0.0;

            if (formulaData.ArgsSum != null)
            {
                foreach (var temp in formulaData.ArgsSum.Values)
                {
                    result += _logic.Calculate(temp);
                }
            }
            return(result);
        }
        public override double Calculate(IFormulaRound formulaData)
        {
            var calculate = _logic.Calculate(formulaData.Value);

            if (formulaData.FractionDigits < 0)
            {
                var s = (int)(Mathf.Pow(10, -formulaData.FractionDigits));
                var t = ((int)calculate / s) * s;
                return(t);
            }
            switch (formulaData.DigitType)
            {
            case DigitType.Normal:
            {
                var value = Math.Round(calculate, formulaData.FractionDigits, MidpointRounding.AwayFromZero);
                return(value);
            }

            case DigitType.More:
            {
                if (calculate == 0)
                {
                    return(0);
                }

                if (formulaData.FractionDigits == 0)
                {
                    var digit = calculate / Mathf.Abs((float)calculate);
                    if (digit > 0)
                    {
                        return((int)(calculate - 0.00001) + digit);
                    }
                    else
                    {
                        return((int)(calculate + 0.00001));
                    }
                }
                return(Math.Round(calculate, formulaData.FractionDigits, MidpointRounding.AwayFromZero));
            }

            case DigitType.Less:
            {
                var x     = Mathf.Pow(10, formulaData.FractionDigits);
                var value = ((int)(calculate * x)) / x;
                return(value);
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#17
0
        private double GetBuffResult(IEnumerable <int> buffs, IFormulaMod formulaData, ModifierType type)
        {
            var result = type == ModifierType.Relative ? 1.0 : 0.0;

            foreach (var buffData in buffs)
            {
                var buff = _battle.Static.Buffs[buffData];
                foreach (var mod in buff.Mods ?? new Dictionary <int, IBuffModifier>())
                {
                    if (mod.Value.ModId == formulaData.ModId)
                    {
                        if (type == ModifierType.Relative)
                        {
                            result *= _formula.Calculate(mod.Value.Value);
                        }
                        else
                        {
                            result += _formula.Calculate(mod.Value.Value);
                        }
                    }
                }
            }
            return(result);
        }
示例#18
0
        public override void Execute(IUnitImpactExp impactData)
        {
            int currentTarget = _context.ContextImpact.CurrentTarget;

            if (_context.BattleMode)
            {
                if (_context.ContextImpact.IsEnemy)
                {
                    Logger.Error($"The enemy cannot receive exp target = {_context.ContextImpact.CurrentTarget}", this);
                    return;
                }
            }
            var(data, unit) = _units.GetUnit(currentTarget);

            var oldLevel = data.Level;
            var exp      = (int)_formula.Calculate(impactData.Value);

            if (exp < 1)
            {
                return;
            }
            var newLevel = _units.UpgradeUnitLevel(data.Id, exp, _player.State.Level);

            var updateLevel = oldLevel != newLevel;

            while (oldLevel != newLevel)
            {
                oldLevel++;
                var levelData = _units.Static.UnitLevels.Values.FirstOrDefault(x => x.Level == oldLevel);
                _logic.ExecuteImpact(levelData?.Impact);
                _logic.ExecuteImpact(unit.ImpactUpdrade);
            }

            if (updateLevel && _context.BattleMode)
            {
                _context.SetContextFormula(unit.Id);
                _context.NeedExploreParam = true;

                var member = _battle.GetMember(currentTarget);
                member.HpMax      = _units.CalculateMaxHp(data, _formula);
                member.Strength   = _units.CalculateStrength(data, _formula);
                member.Initiative = _units.CalculateInitiative(data, _formula);

                _context.SetContextFormula(null);
                _context.NeedExploreParam = false;
            }
        }
示例#19
0
        public void CompleteAchievement(int achievementId)
        {
            var achievement = _accessor.Static.Achievements[achievementId];
            var value       = _scorersLogic.GetScorer(achievement.ScorerId, 0);
            var maxValue    = _formula.Calculate(achievement.Value);

            if (value < maxValue)
            {
                throw new Exception($"error update achievement. value = {value} maxValue = {maxValue}");
            }
            _impacts.ExecuteImpact(achievement.Impact);
            foreach (var temp in achievement.Items)
            {
                _dropLogic.Drop(temp.Value);
            }
            _accessor.State.Achievements[achievementId].Complete = true;
            LogicLog.CompleteAchievement(achievementId);
        }
示例#20
0
        public void Drop(IDropItem drop)
        {
            var value = (int)_formula.Calculate(drop.Value);

            switch (drop.Item.Type)
            {
            case DropType.Inventory:
                _inventory.AddItem(drop.Item.ItemId, value);
                break;

            case DropType.Money:
                var data1 = _scorers.Static.MoneyTypes[drop.Item.MoneyId];
                var dict  = _scorers.State.Values;
                dict.TryGetValue(data1.ScorerId, out var oldValue);
                dict[data1.ScorerId] = oldValue + value;
                if (data1.AchievScorerId != 0)
                {
                    if (!dict.ContainsKey(data1.AchievScorerId))
                    {
                        dict[data1.AchievScorerId] = 0;
                    }
                    dict[data1.AchievScorerId] += value;
                }
                break;

            case DropType.Shard:
                _units.AddUnitShard(drop.Item.UnitId, value);
                var data = _units.State.Units.FirstOrDefault(x => x.Id == drop.Item.UnitId);
                if (data != null)
                {
                    TryUpdateNullRarity(data);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#21
0
        private void FirstSession(long currentTime)
        {
            _player.State.RegisterTime = currentTime.ToString();
            _explorer.State.IsRun      = false;
            _explorer.State.StageId    = -1;
            _player.UpgradeLevel(0);
            foreach (var temp in _shop.Static.GoodGroups)
            {
                var group = _shop.GetGroup(temp.Key);
                if (group.Period == 0)
                {
                    _shopLogic.UpdateGroups(temp.Key, 0);
                }
                else
                {
                    _shopLogic.UpdateGroups(temp.Key, currentTime + group.Period);
                }
                if (_shop.State.Groups.TryGetValue(temp.Value.Id, out var data))
                {
                    data.RefreshNumber = 1;
                }
            }
            foreach (var temp in _achievement.Static.Achievements)
            {
                var data     = _achievement.CreateAchievementData(temp.Key);
                var duration = (int)_formula.Calculate(temp.Value.Time);
                if (duration > 0)
                {
                    data.FinishTime = currentTime + duration;
                }
            }

            LogicLog.SetSession(LogSessionType.OpenGame);
            _settings.State.CurrentVersion = Application.version;
            _settings.State.Build          = _settings.Settings.Builds.FirstOrDefault(x => x.Value.Version == Application.version).Key;
        }
示例#22
0
        public override double Calculate(IFormulaUnitsParam formulaData)
        {
            if (!_battle.Static.BattleParams.TryGetValue(formulaData.Param, out var param))
            {
                //var param = _battle.Static.BattleParams[formulaData.Param];
                Logger.Error($"FormulaUnitParam no param id = {formulaData.Param}. return 1", this);
                return(1);
            }
            switch (param.Label)
            {
            case ParamType.EnergyMax:
                return(_formula.Calculate(_player.GetLevel(_player.State.Level).EnergyMax));

            case ParamType.UnitEquipStars:
                if (_context.ContextFormula == null)
                {
                    return(1);
                }
                if (_units.TryGetUnit(_context.ContextFormula.Value, true, out var unitData))
                {
                    return(unitData.EquipmentStars);
                }
                else
                {
                    return(1);
                }
            }
            if (_context.NeedExploreParam || !_context.BattleMode)
            {
                if (_context.ContextFormula == null)
                {
                    return(1);
                }
                var(data1, unit) = _units.GetUnit(_context.ContextFormula.Value);
                var sum = 0;
                switch (param.Label)
                {
                case ParamType.UserLevel:
                    return(data1.Level);

                case ParamType.UnitHp:
                    return(data1.CurrentHp);

                case ParamType.UnitStrength:
                    return(_formula.Calculate(unit.Strength));

                case ParamType.UnitStrBase:
                    return(unit.Rarities.Where(x => x.Value.Stars == data1.Stars).Sum(x => x.Value.Strength));

                case ParamType.UnitStrEquip:
                    return(_units.CalculateEquipStrength(_context.ContextFormula.Value));

                case ParamType.UnitHpMax:
                    return(_formula.Calculate(unit.HpMax));

                case ParamType.UnitHpBase:
                    return(unit.Rarities.Where(x => x.Value.Stars == data1.Stars).Sum(x => x.Value.HpMax));

                case ParamType.UnitHpEquip:
                    return(_units.CalculateEquipHp(_context.ContextFormula.Value));

                case ParamType.UnitInitiative:
                    return(_formula.Calculate(unit.Initiative));

                case ParamType.UnitInitBase:
                    return(unit.Rarities.Where(x => x.Value.Stars == data1.Stars).Sum(x => x.Value.Initiative));

                case ParamType.UnitInitEquip:
                    return(_units.CalculateEquipInit(_context.ContextFormula.Value));

                case ParamType.UnitAblBase:
                    return(GetAbilityParam(unit.Id, AbilityType.BaseAttack));

                case ParamType.UnitAblFamiliar:
                    return(GetAbilityParam(unit.Id, AbilityType.UpgradeAttack));

                case ParamType.UnitAblUlta:
                    return(GetAbilityParam(unit.Id, AbilityType.Ultimate));

                case ParamType.UnitStamina:
                    return(unit.Rarities.Where(x => x.Value.Stars == data1.Stars).Sum(x => x.Value.Stamina));
                }
                return(1);
            }

            IMemberBattleData member = _context.GetMember(formulaData.TargetType);

            if (member == null)
            {
                Logger.Error($"FormulaUnitParam no param id = {formulaData.Param} return 1", this);
                return(1);
            }

            switch (param.Label)
            {
            case ParamType.UserLevel:
                return(1);

            case ParamType.UnitHp:
                return(member.CurrentHp);

            case ParamType.UnitStrength:
                return(member.Strength.Value);

            case ParamType.UnitStrBase:
                return(member.Strength.Base);

            case ParamType.UnitStrEquip:
                return(member.Strength.Equip);

            case ParamType.UnitHpMax:
                return(member.HpMax.Value);

            case ParamType.UnitHpBase:
                return(member.HpMax.Base);

            case ParamType.UnitHpEquip:
                return(member.HpMax.Equip);

            case ParamType.UnitInitiative:
                return(member.Initiative.Value);

            case ParamType.UnitInitBase:
                return(member.Initiative.Base);

            case ParamType.UnitInitEquip:
                return(member.Initiative.Equip);

            case ParamType.UnitAblBase:
                return(member.MemberType == BattleMemberType.Unit ? GetAbilityParam(member.StaticId, AbilityType.BaseAttack) : 0);

            case ParamType.UnitAblFamiliar:
                return(member.MemberType == BattleMemberType.Unit ? GetAbilityParam(member.StaticId, AbilityType.UpgradeAttack) : 0);

            case ParamType.UnitAblUlta:
                return(member.MemberType == BattleMemberType.Unit ? GetAbilityParam(member.StaticId, AbilityType.Ultimate) : 0);

            default:
                throw new ArgumentOutOfRangeException(param.Label);
            }

            float GetAbilityParam(int id, AbilityType type)
            {
                var ability = _units.Static.Abilities.Values.FirstOrDefault(y => y.Params.UnitId == id && y.Params.Mode == type);

                if (ability == null)
                {
                    Logger.Error($"FormulaUnitParam param id = {formulaData.Param}. userId = {id} abilityType = {type} no ability. return 1", this);
                    return(1);
                }
                if (!_units.GetUnit(id).data.Abilities.TryGetValue(ability.Id, out var level))
                {
                    Logger.Error($"FormulaUnitParam param id = {formulaData.Param}. userId = {id} abilityType = {type} no ability. return 1", this);
                    return(1);
                }
                return(level);
            }
        }
        public override void Execute(IUnitImpactHp data)
        {
            var targetId = _context.ContextImpact.CurrentTarget;
            var value    = (float)_logic.Calculate(data.Value);

            if (_context.BattleMode)
            {
                var member = _battle.GetMember(targetId);
                if (member == null)
                {
                    Logger.Error($"No member in battle CurrentTarget = {targetId} ", this);
                    return;
                }
                var oldHp = member.CurrentHp;

                if (value < 0)
                {
                    value            = Mathf.Min(value, member.CurrentHp);
                    member.CurrentHp = member.CurrentHp + value;
                    if (member.CurrentHp <= 0)
                    {
                        member.Status = UnitBattleStatus.DeadInTernNoDropped;
                        if (member.MemberType == BattleMemberType.Unit)
                        {
                            _units.SetUnitReserve(member.StaticId, true);
                        }
                    }
                }
                else
                {
                    value            = Mathf.Min(value, (float)member.HpMax.Value - member.CurrentHp);
                    member.CurrentHp = member.CurrentHp + value;
                }
                if (_units.Static.Abilities.TryGetValue(_context.CurrentAbility, out var ability))
                {
                    if (member.CurrentHp < oldHp)
                    {
                        if (ability.Influence.Values.Contains(InfluenceType.Attack))
                        {
                            member.TurnInfluence.Add(InfluenceTargetType.Attack);
                        }
                        if (ability.Influence.Values.Contains(InfluenceType.AttackDistance))
                        {
                            member.TurnInfluence.Add(InfluenceTargetType.AttackDistance);
                        }
                    }
                    if (member.CurrentHp > oldHp)
                    {
                        if (ability.Influence.Values.Contains(InfluenceType.Attack))
                        {
                            member.TurnInfluence.Add(InfluenceTargetType.Heal);
                        }
                    }
                }
            }
            else
            {
                var(member, unit) = _units.GetUnit(targetId);
                var max = _units.CalculateMaxHp(member, _logic);
                if (value < 0)
                {
                    value            = Mathf.Min(value, member.CurrentHp);
                    member.CurrentHp = member.CurrentHp + value;
                    if (member.CurrentHp <= 0)
                    {
                        _units.SetUnitReserve(targetId, true);
                    }
                }
                else
                {
                    member.CurrentHp = Mathf.Min(member.CurrentHp + value, (float)max.Value);
                }
            }
        }
 public override double Calculate(IFormulaBase formulaData)
 {
     return(_logic.Calculate(formulaData.Formula));
 }
示例#25
0
 public double Calculate(IFormula data)
 {
     return(_formula.Calculate(data));
 }
示例#26
0
 public override double Calculate(IFormulaMin formulaData)
 {
     return(formulaData.ArgsMin.Values.Select(x => _logic.Calculate(x)).Min(y => y));
 }