Ejemplo n.º 1
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            state.Level.PlayerTurn = false;
            state.Level.MovedUnits.Clear();

            LevelAiLogic.AddCommands(state, config, buffer);
        }
Ejemplo n.º 2
0
 public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
 {
     foreach (var cmd in Childs)
     {
         buffer.Add(cmd);
     }
 }
Ejemplo n.º 3
0
 public CommandWorkItem(ICommand command, GameState state, ConfigRoot config, ICommandBuffer buffer)
 {
     _state  = state;
     _config = config;
     _buffer = buffer;
     Command = command;
 }
Ejemplo n.º 4
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var unit      = state.Units[UnitId];
            var maxHealth = config.Units[unit.Descriptor].MaxHealth[unit.Level];

            unit.Health = maxHealth;
        }
Ejemplo n.º 5
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer _)
        {
            var item = FindItem(state);
            var unit = FindUnit(state);

            unit.Items.Add(item);

            state.Items.Remove(item.Id);
        }
Ejemplo n.º 6
0
        public virtual void RollbackTo(int tick)
        {
            ICommandBuffer commandBuffer = this.cmdBuffer;

            if (commandBuffer != null)
            {
                commandBuffer.Jump(this.CurTick, tick);
            }
        }
        public void BufferCommands(params Command[] commands)
        {
            if (commands == null)
            {
                return;
            }

            _commandBuffer = new ParallelCommandBuffer(commands);
        }
Ejemplo n.º 8
0
        public virtual void Clean(int maxVerifiedTick)
        {
            ICommandBuffer commandBuffer = this.cmdBuffer;

            if (commandBuffer != null)
            {
                commandBuffer.Clean(maxVerifiedTick);
            }
        }
Ejemplo n.º 9
0
        public void RegisterCommandBuffer(CommandBufferStage stage, ICommandBuffer commandbuffer)
        {
            var buffers = m_commandBuffer[stage];

            if (!buffers.Contains(commandbuffer))
            {
                buffers.Add(commandbuffer);
            }
        }
Ejemplo n.º 10
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var unit = state.Units[UnitId];

            unit.Experience += Amount;
            if (unit.Experience >= config.UnitLevels[unit.Level])
            {
                buffer.Add(new LevelUpCommand(UnitId));
            }
        }
Ejemplo n.º 11
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer _)
        {
            var unit = state.Units[Id];

            foreach (var item in unit.Items)
            {
                state.Items.Add(item.Id, item);
            }
            state.Units.Remove(Id);
        }
Ejemplo n.º 12
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var info = config.Events[EventName];

            state.Events[EventName] = true;
            state.Progress.Remove(info.Scope);
            var rewardLevel = info.RewardLevel;

            RewardLogic.AppendReward(rewardLevel, state, config, buffer);
        }
Ejemplo n.º 13
0
        public void RemoveCommandBuffer(CommandBufferStage stage, ICommandBuffer commandBuffer)
        {
            var buffers = m_commandBuffer[stage];

            if (buffers.Contains(commandBuffer))
            {
                buffers.Remove(commandBuffer);
                commandBuffer.Dispose();
            }
        }
Ejemplo n.º 14
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            state.Level.MovedUnits.Add(DealerId);
            var damage = DamageLogic.GetDamage(state, config, DealerId, TargetId);
            var target = state.Level.FindUnitById(TargetId);

            target.Health -= damage;
            if (target.Health <= 0)
            {
                buffer.Add(new KillUnitCommand(target.Id));
            }
        }
Ejemplo n.º 15
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            foreach (var unit in state.Level.PlayerUnits)
            {
                state.AddUnit(unit);
                if (!config.IsFeatureEnabled(Features.AutoHeal))
                {
                    continue;
                }
                var unitConfig = config.Units[unit.Descriptor];
                if (unit.Health < unitConfig.MaxHealth[unit.Level])
                {
                    buffer.Add(new HealUnitCommand(unit.Id));
                }
            }

            var levelDesc   = state.Level.Descriptor;
            var playerUnits = state.Level.PlayerUnits;

            state.Level = null;

            if (!Win)
            {
                return;
            }

            foreach (var unit in playerUnits)
            {
                if (unit.Level >= config.UnitLevels.Length)
                {
                    continue;
                }
                var expAccum = 0;
                foreach (var enemyDesc in config.Levels[levelDesc].EnemyDescriptors)
                {
                    var enemyConfig = config.Units[enemyDesc];
                    expAccum += enemyConfig.Experience;
                }
                if (expAccum > 0)
                {
                    buffer.Add(new AddExperienceCommand(unit.Id, expAccum));
                }
            }

            var scope = LevelUtils.GetScope(levelDesc);

            state.Progress[scope] = Math.Min(state.Progress.GetOrDefault(scope) + 1, LevelUtils.GetIndex(levelDesc) + 1);

            var rewardLevel = config.Levels[levelDesc].RewardLevel;

            RewardLogic.AppendReward(rewardLevel, state, config, buffer);
        }
Ejemplo n.º 16
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var days            = GetDaysBetween(state);
            var maxStreaks      = config.DailyRewards.Length;
            var isNeedToDiscard = (days >= 2) || (state.DailyReward.Streak == (maxStreaks - 1));
            var newStreak       = isNeedToDiscard ? 0 : (state.DailyReward.Streak + 1);

            state.DailyReward.LastClaimDate = state.Time.GetRealTime();
            state.DailyReward.Streak        = newStreak;
            var rewardLevel = config.DailyRewards[newStreak];

            RewardLogic.AppendReward(rewardLevel, state, config, buffer);
        }
Ejemplo n.º 17
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var item          = state.Items[Id];
            var upgradePrices = GetUpgradePrices(config, item.Descriptor)[item.Level];

            foreach (var pair in upgradePrices)
            {
                var res   = pair.Key;
                var price = pair.Value;
                buffer.Add(new SpendResourceCommand(res, price));
            }
            item.Level++;
        }
        protected void UpdateCommandBuffer()
        {
            if (_commandBuffer == null)
            {
                return;
            }

            if (_commandBuffer.IsCompleted)
            {
                _commandBuffer.Dispose();
                _commandBuffer = null;
                OnBufferCompleted();
                return;
            }

            _commandBuffer.RefreshBuffer(Time.deltaTime);
        }
Ejemplo n.º 19
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer _)
        {
            var playerUnits = FindPlayerUnits(state);
            var enemyUnits  = CreateEnemyUnits(state, config);

            state.Level            = new LevelState(LevelDesc, playerUnits, enemyUnits);
            state.Level.PlayerTurn = true;

            foreach (var unitId in PlayerUnits)
            {
                state.Units.Remove(unitId);
            }
            if (FarmLogic.IsFarmigLevel(LevelDesc, config))
            {
                var scope = LevelUtils.GetScope(LevelDesc);
                state.Farming[scope] = state.Time.GetRealTime();
            }
        }
Ejemplo n.º 20
0
        public static void AddCommands(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var level   = state.Level;
            var damages = new Dictionary <ulong, int>();

            foreach (var enemy in level.EnemyUnits)
            {
                var enemyId = enemy.Id;
                if (!TrySelectPlayerToAttack(level.PlayerUnits, damages, out var playerUnit))
                {
                    break;
                }
                var playerId      = playerUnit.Id;
                var attackCommand = new AttackCommand(enemyId, playerId);
                buffer.Add(attackCommand);
                var damage = DamageLogic.GetDamage(state, config, enemyId, playerId);
                damages[playerId] = damages.GetOrDefault(playerId) + damage;
            }
            buffer.Add(new EndEnemyTurnCommand());
        }
Ejemplo n.º 21
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var unit     = state.Units[UnitId];
            var oldLevel = unit.Level;

            unit.Level++;
            unit.Experience -= config.UnitLevels[oldLevel];
            var isLastLevel = (unit.Level == config.UnitLevels.Length);

            if (isLastLevel)
            {
                unit.Experience = 0;
            }

            buffer.Add(new HealUnitCommand(UnitId));

            if (!isLastLevel && (unit.Experience >= config.UnitLevels[unit.Level]))
            {
                buffer.Add(new LevelUpCommand(UnitId));
            }
        }
Ejemplo n.º 22
0
        private void ThreadStart()
        {
            try
            {
                ICommandBuffer buff = mDevice.CreateCommandBuffer();

                try
                {
                    ReadWriteData(mDevice, buff, mTopOfPipeline, mIsBackup);
                }
                catch (Exception)
                {
                    mDeviceSet.SignalAbort();
                    throw;
                }
            }
            catch (Exception e)
            {
                mException = e;
            }
        }
Ejemplo n.º 23
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var level = state.Level;

            if (TryKill(level.PlayerUnits, out var player))
            {
                if (config.IsFeatureEnabled(Features.AutoHeal))
                {
                    buffer.Add(new HealUnitCommand(player.Id));
                }
                state.Units.Add(UnitId, player);
                if (level.PlayerUnits.Count == 0)
                {
                    buffer.Add(new FinishLevelCommand(false));
                }
            }
            TryKill(level.EnemyUnits, out _);
            if (level.EnemyUnits.Count == 0)
            {
                buffer.Add(new FinishLevelCommand(true));
            }
        }
Ejemplo n.º 24
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
        {
            var health = config.Units[Descriptor].MaxHealth[0];

            state.AddUnit(new UnitState(Descriptor, health).WithId(Id));
        }
Ejemplo n.º 25
0
 public Simulation(IWorld world, ICommandBuffer remoteCommandBuffer)
 {
     _world = world;
     _remoteCommandBuffer = remoteCommandBuffer;
 }
 public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
 {
     state.Time.PersistentOffset += Amount;
 }
Ejemplo n.º 27
0
 protected BaseService()
 {
     this.cmdBuffer = new CommandBuffer();
     this.cmdBuffer.Init(this, this.GetRollbackFunc());
 }
Ejemplo n.º 28
0
        public void Execute(GameState state, ConfigRoot config, ICommandBuffer _)
        {
            var oldValue = state.Resources.GetOrDefault(Kind);

            state.Resources[Kind] = oldValue - Count;
        }
Ejemplo n.º 29
0
 public void Execute(GameState state, ConfigRoot config, ICommandBuffer buffer)
 {
     buffer.Add(new AddResourceCommand(Resource.Coins, 50));
     buffer.Add(new AddUnitCommand(state.NewEntityId(), "weak_unit"));
 }
Ejemplo n.º 30
0
        private static void ReadWriteData(IVirtualDevice device, ICommandBuffer buff, Stream stream, bool isBackup)
        {
            while (device.GetCommand(null, buff))
            {
                if (!buff.TimedOut)
                {
                    CompletionCode completionCode   = CompletionCode.DiskFull;
                    uint           bytesTransferred = 0;

                    try
                    {
                        switch (buff.CommandType)
                        {
                        case DeviceCommandType.Write:

                            if (!isBackup)
                            {
                                throw new InvalidOperationException("Cannot write in 'restore' mode");
                            }

                            bytesTransferred = (uint)buff.WriteToStream(stream);

                            completionCode = CompletionCode.Success;

                            break;

                        case DeviceCommandType.Read:

                            if (isBackup)
                            {
                                throw new InvalidOperationException("Cannot read in 'backup' mode");
                            }

                            bytesTransferred = (uint)buff.ReadFromStream(stream);

                            if (bytesTransferred > 0)
                            {
                                completionCode = CompletionCode.Success;
                            }
                            else
                            {
                                completionCode = CompletionCode.HandleEof;
                            }

                            break;

                        case DeviceCommandType.ClearError:
                            completionCode = CompletionCode.Success;
                            break;

                        case DeviceCommandType.Flush:
                            stream.Flush();
                            completionCode = CompletionCode.Success;
                            break;

                        default:
                            throw new ArgumentException(string.Format("Unknown command: {0}", buff.CommandType));
                        }
                    }
                    finally
                    {
                        device.CompleteCommand(buff, completionCode, bytesTransferred, (ulong)0);
                    }
                }
            }
        }