public void Buy(int groupId, int slotId) { var slot = _shop.GetSlot(groupId, slotId); var good = _shop.GetGood(slot.GoodId); var current = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); if (!_shop.State.Groups.TryGetValue(groupId, out var groupData)) { Logger.Error($"no state group id = {groupId}", this); return; } if (groupData.FinishTime != 0) { if (slot.IsBuy) { throw new Exception($"Allready buy group id = {groupId} slot id = {slotId}"); } slot.IsBuy = true; } foreach (var price in good.Price?.Values ?? new IPrice[0]) { _scorers.Spend(price, _formula); } _impacts.ExecuteImpact(good.Impact); foreach (var temp in good.Items) { _dropLogic.Drop(temp.Value); } LogicLog.BuyGood(slot.GoodId); }
public void UnitUpgrateAbility(int unitId, int abilityId) { var(data, unit) = _units.GetUnit(unitId); if (!data.Abilities.ContainsKey(abilityId)) { throw new Exception($"Ability missing. Unit id = {unitId} ability id = {abilityId}"); } var currentLevel = data.Abilities[abilityId]; if (currentLevel >= data.Level) { throw new Exception($"Impossible to upgrade the ability. Unit id = {unitId} current level = {data.Level}"); } var abilityType = _units.Static.Abilities[abilityId].Params.Mode; var prices = _units.GetAbilityPrices(currentLevel, abilityType); foreach (var price in prices) { _scorers.Spend(price, _formuls); } data.Abilities[abilityId]++; LogicLog.UpgradeAbilityLevel(unitId, abilityId, data.Abilities[abilityId]); _impact.ExecuteContextImpact(unit.ImpactUpdrade, unitId); }
public override void Execute(IImpactUnitShard data) { var value = (int)_logic.Calculate(data.Shards); _accessor.AddUnitShard(data.UnitId, value); LogicLog.AddUnitShard(data.UnitId, value); }
public void StartBattle(ExplorerPositionData position) { _contextLogic.TurnType = BattleTurnResultType.StartTurn; _battleLogic.StartBattle(); _contextLogic.SetAbilityContext(-1, -1, false); _impactLogic.ExecuteImpact(_contextLogic.ImpactInit); _battleLogic.BatchEventBattle(); _contextLogic.TurnType = BattleTurnResultType.PassiveAbility; foreach (var temp in _battle.LiveAllies) { _contextLogic.TurnType = BattleTurnResultType.PassiveAbility; ExecuteStartAbility(temp, false); } foreach (var temp in _battle.LiveEnemies) { _contextLogic.TurnType = BattleTurnResultType.PassiveAbility; ExecuteStartAbility(temp, true); if (_contextLogic.MobImpacts.TryGetValue(temp, out var impact)) { _contextLogic.SetAbilityContext(temp, null, true); _impactLogic.ExecuteImpact(impact); } } _contextLogic.TurnType = BattleTurnResultType.EndTurn; _explorer.State.Position = position; _battleLogic.UpdateMobs(); _battleLogic.BatchEventBattle(); LogicLog.SetBattle(LogBattleType.Start, _explorer.State.LastInteractiveId, _explorer.State.RoomId, _explorer.CurrentStage); }
public void UpgradeNullRatity(IUnitData data) { if (data.Stars > 0) { return; } var countShards = GetShardsForUpgrage(data.Id, data.Stars); if (countShards > data.Shards) { return; } var allAbilities = Static.Abilities.Where(x => x.Value.Params.UnitId == data.Id); foreach (var temp in allAbilities) { data.Abilities[temp.Key] = 1; } var allPerks = Static.Perks.Where(x => x.Value.UnitId == data.Id); foreach (var temp in allPerks) { data.PerkStars[temp.Key] = 1; } data.EquipmentStars = 1; data.Stars = 1; data.Level = 1; data.Shards -= countShards; LogicLog.UpgradeRarityUnit(data.Id, data.Stars); }
private void UpdateDrop() { foreach (var temp in _battle.State.Data.Enemies.ToArray()) { if (temp.Value.Status == UnitBattleStatus.DeadInTernNoDropped) { _contextLogic.SetContextImpact(-1, -1, false); _impactLogic.ExecuteImpact(_explorer.GetMob(temp.Value.StaticId).ImpactWin); temp.Value.Status = UnitBattleStatus.DeadInTern; foreach (var buffData in temp.Value.Buffs) { var buff = _battle.Static.Buffs[buffData.Key]; _impactLogic.ExecuteImpact(buff.ImpactDie); } //var position = _battle.State.Data.StackMobs[_battle.State.Data.CurrentWave].MobData[temp.Key].Position; LogicLog.MobDeath(temp.Value.StaticId, _battle.State.Data.CurrentWave, 0); } } foreach (var temp in _battle.State.Data.Allies) { if (temp.Value.Status == UnitBattleStatus.DeadInTernNoDropped) { temp.Value.Status = UnitBattleStatus.DeadInTern; foreach (var buffData in temp.Value.Buffs) { var buff = _battle.Static.Buffs[buffData.Key]; _impactLogic.ExecuteImpact(buff.ImpactDie); } LogicLog.DeathUnit(temp.Value.StaticId); } } }
public void StartExplorer(int stage) { var stageData = _explorer.GetStage(stage); var staticData = _explorer.Stages[stage]; //UpdateExplorerSlots(); foreach (var temp in _units.State.LastTeam) { var data = _units.GetUnit(temp.Key).data; data.ExplorerPosition = temp.Value; data.Reserve = false; } if (_units.ExplorerUnits.Length == 0) { throw new Exception("The number of selected units in exploration should be: 0 < count < 3"); } if (!stageData.IsUnlock) { throw new Exception($"Stage is locked. stage_id = {stage}"); } if (stageData.DailyNumber <= 0) { throw new Exception($"Ended up trying for today. stage_id = {stage}."); } if (!staticData.NoExit) { stageData.DailyNumber--; } _scorers.Spend(staticData.Price, _formula); _explorerLogic.StartExplorer(stage); LogicLog.SetExplorer(stage, LogExplorerType.Start); }
public override void Execute(IImpactFamiliarUnlock data) { if (!_logic.TryGetUnit(data.UnitId, true, out var unit)) { return; } LogicLog.UnlockFamiliar(data.UnitId); unit.FamiliarUnlock = true; }
public void CheatEndExplorer() { CompleteStageFull(_explorer.CurrentStage); var scorer = _scorers.GetScorer(HardCodeIds.CurrentStage); _scorers.State.Values[scorer.Id]++; _battle.State.Data = null; LogicLog.SetExplorer(_explorer.CurrentStage, LogExplorerType.FinishImpact); _explorerLogic.FinishExplorer(true); }
public void StartSession() { var currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); LogicLog.SetAccessor(_accessor, _settings); if (_player.State.Level == 0) { FirstSession(currentTime); } _player.State.LastLoginTime = currentTime.ToString(); }
private void RegisterLogicModuleLogByName(params object[] args) { m_LogicDicLogs.Clear(); for (int i = 0; i < args.Length; i++) { string module_name = (string)args[i]; int cachesize = 4 * 1024 * 1024; LogicLog log = new LogicLog(module_name, cachesize); log.m_Type = 0; m_LogicDicLogs.Add(module_name, log); } }
public override void Execute(IImpactScorerData data) { var value = (long)_logic.Calculate(data.Value); var values = _scorers.GetScrorerMap(data.Id, data.StageId); if (values == null) { return; } long delta = 0; switch (data.Operator) { case OperationType.Add: delta = value; values[data.Id] += value; break; case OperationType.Set: delta = value - values[data.Id]; values[data.Id] = value; break; default: throw new ArgumentOutOfRangeException(); } if (delta > 0) { var staticData = _scorers._scorers.Static.MoneyTypes.Values.FirstOrDefault(x => x.ScorerId == data.Id); if (staticData != null && staticData.AchievScorerId != 0) { values = _scorers.GetScrorerMap(staticData.AchievScorerId, 0); if (values != null) { values[staticData.AchievScorerId] += delta; } } } if (_scorers.HasLog(data.Id)) { var logStage = data.StageId; if (logStage == 0) { if (_explorer.State.IsRun) { logStage = _explorer.CurrentStage; } } LogicLog.ChangeScorer(data.Id, data.Operator, value, logStage); } }
public void RefreshStamina() { if (!_explorer.State.IsRun) { Logger.Error($"Attempting to record stamina for stage outside of explorer", this); return; } _explorer.GetStage(_explorer.CurrentStage).Values[_scorers.StaminaId] += _settings.Settings.PlayerSettings.BuyStamina; _scorers.Spend(_settings.GetPriceStamina(_explorer.State.RefreshNumber), _formula); _explorer.State.RefreshNumber++; LogicLog.ExploreRenew(_explorer.State.StageId, _explorer.State.RefreshNumber); LogicLog.SetExplorer(_explorer.CurrentStage, LogExplorerType.BuyStamina); }
public void StageAutowin(int selectedStageId, int tryCount) { var stage = _explorer.Stages[selectedStageId]; var stageData = _explorer.GetStage(stage.Id); for (var i = 0; i < tryCount; i++) { _explorer.SetCurrentStage(selectedStageId); Impact.ExecuteImpact(stage.ImpactAutowin); Scorers.Spend(stage.Price, Formula); _explorer.ClearCurrentStage(); LogicLog.SetExplorer(selectedStageId, LogExplorerType.AutoWin); } stageData.DailyNumber = Mathf.Clamp(stageData.DailyNumber - tryCount, 0, int.MaxValue); }
public void ActivationObject(int id, int index, PerkExecuteData data, ExplorerPositionData position) { _changeLogic.SetMode(ApplyMode.Manual); LogicLog.Activate(id, index); var activation = _explorer.GetActivation(id, index); _explorer.State.Position = position; _impactLogic.ExecuteImpact(activation.Impact); var staminaId = _scorers.StaminaId; if (data != null) { var perk = _units.Static.Perks[data.PerkId]; if (perk.ClassId != activation.Source.PerkClassId) { throw new Exception($"Perk cannot be applied. UnitId = {data.UnitId} perkId = {data.PerkId} perk class id = {perk.ClassId} activation perkClassId = {activation.Source.PerkClassId}"); } if (activation.Source.UnitId != 0 && activation.Source.UnitId != data.UnitId) { throw new Exception($"Perk cannot be applied. UnitId = {data.UnitId} need unit id = {activation.Source.UnitId}"); } var(unit, _) = _units.GetUnit(data.UnitId); if (!unit.PerkStars.TryGetValue(data.PerkId, out var stars) || stars < activation.Source.PerkLevel) { throw new Exception($"Not enough stars to use the perk. UnitId = {data.UnitId} perkId = {data.PerkId} perkStars = {stars} activation stars = {activation.Source.PerkLevel} "); } if (!unit.PerkCharges.TryGetValue(data.PerkId, out var value) || value == 0) { throw new Exception($"НNot enough stars to use the perk. UnitId = {data.UnitId} perkId = {data.PerkId}"); } unit.PerkCharges[data.PerkId]--; } else { if (activation.Source.PerkClassId != 0) { throw new Exception($"Can't complete activation without perk. activation perkClassId = {activation.Source.PerkClassId}"); } } //_explorer.SpendScorer(staminaId, (int)_formulaLogic.Calculate(activation.Cost.Stamina)); //_explorer.ActivateInteractiveObject(id); _explorer.State.LastInteractiveId = id; _changeLogic.BatchCutScene(0); _changeLogic.SetMode(ApplyMode.Auto); }
public void UpgradeRarity(int unitId) { var(data, unit) = GetUnit(unitId); if (Static.Units[unitId].Rarities.Count == data.Stars) { throw new Exception($"Maximum rarity level reached. unit_id = {unitId}"); } var countShards = GetShardsForUpgrage(unitId, data.Stars); if (data.Shards < countShards) { throw new Exception($"Not enough shards to level up rarity. unit_id = {unitId} countStards = {countShards} neededStards = {data.Shards}"); } data.Stars++; LogicLog.UpgradeRarityUnit(unitId, data.Stars); data.Shards -= countShards; }
public void Drop(int gachaId, GachaCountType count) { var(gachaItem, prices, countDrop) = _resources.GetGacha(gachaId, count, _condition); for (var i = 0; i < countDrop; i++) { _impactLogic.ExecuteImpact(gachaItem.Impact); } var gachaPrice = prices.Prices ?? new Dictionary <int, IPrice>(); foreach (var price in gachaPrice.Values) { _scorers.Spend(price, _formuls); } _impactLogic.ExecuteImpact(prices.Impact); LogicLog.Gacha(gachaId, countDrop); UpdateDropItems(); }
public void SetUnitEquipment(int unitId, int slot) { var(data, defUnit) = _units.GetUnit(unitId); var currentEquipment = defUnit.Equipment.Values.FirstOrDefault(x => x.Slot == slot && x.Stars == data.EquipmentStars); if (currentEquipment == null) { throw new Exception($"Unit id ={unitId} no equipment id = {slot}"); } if (!_resources.HasItem(currentEquipment.ItemId)) { throw new Exception($"Unable to insert equipment for a unit. no required item in inventory. unit id = {unitId} slot = {slot} item_id = {currentEquipment.ItemId}"); } data.Equipment[slot] = currentEquipment.ItemId; _resources.SpendItem(currentEquipment.ItemId, 1); LogicLog.SetEquip(unitId, currentEquipment.ItemId, slot, data.EquipmentStars); }
public int UpgradeUnitLevel(int unitId, int exp, int maxLevel) { var(data, unit) = GetUnit(unitId); if (data.Stars < 1) { return(0); } var levels = GetSortedLevels(); if (data.Level == levels.Count) { return(data.Level); } var newExp = data.Exp + exp; var max = levels.Last().ExpMin; if (newExp > max) { newExp = max; } while (data.Level < levels.Count) { if (data.Level == maxLevel) { newExp = 0; break; } var levelData = levels[data.Level]; if (newExp >= levelData.ExpMin) { data.Level += 1; LogicLog.UpdateUnitLevel(unitId, data.Level, exp); } else { break; } } data.Exp = newExp; return(data.Level); }
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); }
public void PerkUpgrateRarity(int unitId, int perkId) { var(data, unit) = _units.GetUnit(unitId); var perk = _units.Static.Perks[perkId]; if (!data.PerkStars.ContainsKey(perkId)) { throw new Exception($"Perk missing. Unit id = {unitId} perk id = {perkId}"); } var rarity = perk.Rarities.Values.FirstOrDefault(x => x.Stars == data.PerkStars[perkId]); foreach (var price in rarity.Prices?.Values ?? new IPrice[0]) { _scorers.Spend(price, _formuls); } data.PerkStars[perkId]++; LogicLog.UpgradePerkLevel(unitId, perkId, data.PerkStars[perkId]); _impact.ExecuteContextImpact(unit.ImpactUpdrade, unitId); }
public override void Execute(IImpactChangeMoney data) { var value = (int)_logic.Calculate(data.Value); var data1 = _scorers.Static.MoneyTypes[data.MoneyTypeId]; var id = _scorers.Static.MoneyTypes[data.MoneyTypeId].ScorerId; var dict = _scorers.State.Values; dict.TryGetValue(id, out var oldValue); var delta = 0; switch (data.Operator) { case OperationType.Add: dict[id] = oldValue + value; delta = value; break; case OperationType.Set: delta = value - (int)oldValue; dict[id] = value; break; default: throw new ArgumentOutOfRangeException(); } if (delta > 0) { if (data1.AchievScorerId != 0) { if (!dict.ContainsKey(data1.AchievScorerId)) { dict[data1.AchievScorerId] = 0; } dict[data1.AchievScorerId] += delta; } } if (dict[id] <= 0) { dict.Remove(id); } LogicLog.ChangeMoneyType(data.MoneyTypeId, data.Operator, value); }
public void UpgradeUnitEquipment(int unitId) { var(data, unit) = _units.GetUnit(unitId); if (!_units.IsFullEquipment(unitId)) { throw new Exception($"The unit does not have all the equipment for pumping. id = {unitId}"); } if (unit.EquipmentRarities.TryGetValue(data.EquipmentStars - 1, out var rarity)) { foreach (var price in rarity.Prices) { _scorers.Spend(price.Value, _formula); } } data.Equipment.Clear(); data.EquipmentStars += 1; LogicLog.UpgradeEquipRarity(unitId, data.EquipmentStars); _impact.ExecuteContextImpact(unit.ImpactUpdrade, unitId); }
public override void Execute(IImpactStageAccess data) { var stage = _explorer.GetStage(data.StageId); switch (data.Access) { case AccessType.Lock: stage.IsUnlock = false; break; case AccessType.Unlock: stage.IsUnlock = true; stage.DailyNumber = _settings.Settings.PlayerSettings.StageDailyNumber; break; default: throw new ArgumentOutOfRangeException(); } LogicLog.StageAccess(data.StageId, data.Access); }
public override void Execute(IImpactChangePerkCharges data) { var value = (int)_logic.Calculate(data.Value); var unitData = _units.ExplorerUnits .Select(x => { var(unit, _) = _units.GetUnit(x); return(unit); }) .FirstOrDefault(x => { x.PerkCharges.TryGetValue(data.PerkId, out value); return(value > 0); }); if (unitData == null) { throw new Exception($"Закончились заряды перка"); } unitData.PerkCharges[data.PerkId] -= 1; LogicLog.ChangePerkCharge(data.PerkId, value); }
public void EndExplorer(int[] inventoryIds, LogExplorerType result) { if (result == LogExplorerType.Start) { throw new Exception("Invalid exploration end state"); } if (result == LogExplorerType.FinishImpact) { if (inventoryIds.Length > 10) { throw new Exception("The number of selected items must not exceed 100"); } foreach (var id in inventoryIds) { _inventory.AddItem(id, _explorer.State.Inventory[id]); } } _battle.State.Data = null; LogicLog.SetExplorer(_explorer.State.StageId, result); _explorerLogic.FinishExplorer(result == LogExplorerType.FinishImpact); }
public void FinishBattle() { if (_battle.State.Data.Status == BattleStatus.Running) { _battle.State.Data.Status = BattleStatus.Leave; LogicLog.SetBattle(LogBattleType.Leave, _explorer.State.LastInteractiveId, _explorer.State.RoomId, _explorer.CurrentStage); } var status = _battle.State.Data.Status; _battleLogic.ClearBattle(); if (status == BattleStatus.Win) { _impactLogic.ExecuteImpact(_contextLogic.ImpactWin); LogicLog.SetBattle(LogBattleType.Win, _explorer.State.LastInteractiveId, _explorer.State.RoomId, _explorer.CurrentStage); } else { _impactLogic.ExecuteImpact(_contextLogic.ImpactLose); LogicLog.SetBattle(LogBattleType.Lose, _explorer.State.LastInteractiveId, _explorer.State.RoomId, _explorer.CurrentStage); } }
public override void Execute(IImpactItemData data) { var value = (int)_logic.Calculate(data.Value); ILogicDictionary <int, int> dict; if (!data.IsExplorer) { if (!_inventory.State.Items.ContainsKey(data.ItemId)) { _inventory.State.Items[data.ItemId] = 0; } dict = _inventory.State.Items; } else { if (!_explorer.State.Inventory.ContainsKey(data.ItemId)) { _explorer.State.Inventory[data.ItemId] = 0; } dict = _explorer.State.Inventory; } switch (data.Operator) { case OperationType.Add: dict[data.ItemId] += value; break; case OperationType.Set: dict[data.ItemId] = value; break; default: throw new ArgumentOutOfRangeException(); } if (dict[data.ItemId] <= 0) { dict.Remove(data.ItemId); } LogicLog.ChangeItemValue(data.ItemId, value); }
public int UpgradeLevel() { var newExp = State.Exp; if (State.Level == Static.Levels.Count) { return(State.Level); } var neededLevel = State.Level + 1; var level = Static.Levels.Values.FirstOrDefault(x => x.Level == neededLevel); while (level != null && newExp >= level.ExpMin && neededLevel < Static.Levels.Count + 1) { neededLevel++; LogicLog.UpdatePlayerLevel(State.Level, newExp); level = Static.Levels.Values.FirstOrDefault(x => x.Level == neededLevel); } State.Level = neededLevel - 1; var expMin = GetLevel(State.Level).ExpMin; State.Exp = level == null ? expMin : newExp; return(State.Level); }
public void Buy(int offerId) { var offer = _shop.Static.Offers[offerId]; var good = _shop.GetGood(offer.GoodId); //var current = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); //if (current < slot.WaitTime) //{ // throw new Exception($"wait time = "); //} //slot.WaitTime = current; if (good.RealPrice != 0) { //var price = _shop.Static.RealPrices[good.RealPrice]; //if (_shop.State.Transactions[price.StoreId] != PaymentProgress.Complete) //{ // throw new Exception("transactions no complete"); //} //else //{ // _shop.State.Transactions.Remove(price.StoreId); //} } else { foreach (var price in good.Price?.Values ?? new IPrice[0]) { _scorers.Spend(price, _formula); } } _impacts.ExecuteImpact(good.Impact); foreach (var temp in good.Items) { _dropLogic.Drop(temp.Value); } LogicLog.BuyOffer(offerId); }