コード例 #1
0
ファイル: MinerAI.cs プロジェクト: NeilMartin/Thrusty
    private Vector3 CalcTargetForState( MinerState state )
    {
        // default stay still
        Vector3 targetPos = gameObject.transform.position;
        switch(state)
        {
        case MinerState.Idle:
            targetPos = CalcIdleTarget();
            break;

        case MinerState.TeleportToCrystal:
            targetPos = CalcCrystalTarget(false);
            break;

        case MinerState.GoToCrystal:
            targetPos = CalcCrystalTarget(true);
            break;

        case MinerState.GoToShip:
            targetPos = mPlayer.transform.position;
            break;

        case MinerState.MineCrystal:
            targetPos = gameObject.transform.position;
            break;

        default:
            Debug.LogError("Unknown state");
            break;
        }
        return targetPos;
    }
コード例 #2
0
        /// <summary>
        /// Start mining process when StartMining is called
        /// </summary>
        public void StartMining()
        {
            if (_state == MinerState.MINING)
            {
                return;
            }
            // prepare a bat script as this will simulate our miner
            var batFileContents = new StringBuilder();

            batFileContents.AppendLine($"echo \"{"I am a fake ExampleMiner from ExamplePlugin"}\"");
            batFileContents.AppendLine($"echo \"{$"Currently mining algorithm {_algorithmType.ToString()}"}\"");
            batFileContents.AppendLine($"echo \"{$"On mining location {_miningLocation}"}\"");
            batFileContents.AppendLine($"echo \"{$"With username {_username}"}\"");
            batFileContents.AppendLine($"echo \"{$"With devices:"}\"");
            foreach (var mp in _miningPairs)
            {
                batFileContents.AppendLine($"echo \"    {$"{mp.Device.Name}:{mp.Device.ID}:{mp.Device.UUID}"}\"");
            }
            batFileContents.AppendLine($"echo \"{"Mining..."}\"");
            batFileContents.AppendLine("pause");

            var tempMiner = Path.GetTempFileName().Replace(".tmp", ".bat");

            File.WriteAllText(tempMiner, batFileContents.ToString());
            _miningProcess = Process.Start(new ProcessStartInfo("cmd.exe", "/c " + tempMiner));
            _state         = MinerState.MINING;
        }
コード例 #3
0
        private void SetState(MinerState state)
        {
            switch (state)
            {
            case MinerState.Stopped:
                this.SetStateVariables(false, false, false);
                break;

            case MinerState.Paused:
                this.SetStateVariables(true, true, false);
                break;

            case MinerState.PausedInitializing:
                this.SetStateVariables(true, false, false);
                break;

            case MinerState.Initializing:
                this.SetStateVariables(true, false, true);
                break;

            case MinerState.Running:
                this.SetStateVariables(true, true, true);
                break;
            }

            OnMinerStateChange?.Invoke(state);
        }
コード例 #4
0
 private Miner(MinerState state)
 {
     Name           = state.Name;
     TaterTokens    = state.TaterTokens;
     InventoryItems = state.InventoryItems.Select(x =>
                                                  new InventoryItem
     {
         Count = x.Count,
         Item  = Game.Gateway.GameItems.GetAll().First(gi => gi.Id == x.ItemId)
     }).ToList();
     AttainedAchievements = state.AttainedAchievements;
     LifetimeStats        = state.LifeTimeStats;
     Diggers.AddRange(state.Diggers.Select(x => ChipDigger.FromState(x)));
 }
コード例 #5
0
        public async Task <IActionResult> GetUserByNameAsync([FromRoute] long id)
        {
            var user = await DbContext.Users
                       .Include(x => x.Miners)
                       .FirstOrDefaultAsync(x => x.Id == id);

            if (user == null)
            {
                return(NotFound());
            }

            user.MinerState = MinerState.FromMiners(user.Miners);
            return(Ok(user.WithoutSecrets()));
        }
コード例 #6
0
 /// <summary>
 /// End mining process when StopMining is called
 /// </summary>
 public void StopMining()
 {
     if (_state == MinerState.STOPPED)
     {
         return;
     }
     try
     {
         _miningProcess.Kill();
         _miningProcess.Dispose();
     }
     catch (Exception)
     {
     }
     _state = MinerState.STOPPED;
 }
コード例 #7
0
        private void GotoNextDestination()
        {
            _minerState = _haveGold ? MinerState.GoingToVillage : MinerState.GoingToMine;

            if (DateTime.Now.Subtract(_lastMove).TimeOfDay > _moveTime)
            {
                if (_currentPosition.X > _currentDestination.X) _currentPosition.X--;
                else if (_currentPosition.X < _currentDestination.X) _currentPosition.X++;

                if (_currentPosition.Y > _currentDestination.Y) _currentPosition.Y--;
                else if (_currentPosition.Y < _currentDestination.Y) _currentPosition.Y++;

                _lastMove = DateTime.Now.TimeOfDay;
            }
        }
コード例 #8
0
        private void FindNextDestination(bool goingToMine)
        {
            _minerState = MinerState.Thinking;
            _thinkStart = DateTime.Now.TimeOfDay;
            _stepsToComplete++;

            Path path = null;
            LabyrinthPathFinder labyrinthPathFinder = (LabyrinthPathFinder)Game.Services.GetService(typeof(LabyrinthPathFinder));
            if (goingToMine)
            {
                path = labyrinthPathFinder.FindWay(base.Game, new Coordinate(LabyrinthCorX, LabyrinthCorY), new Coordinate(_mineCorX, _mineCorY));
            }
            else
            {
                path = labyrinthPathFinder.FindWay(base.Game, new Coordinate(LabyrinthCorX, LabyrinthCorY), new Coordinate(_villageCorX, _villageCorY));
            }

            if (path.DestinationReached == false)
            {
                ChangeVillageLocation();
                ChangeMineLocation();
            }

            if (path.CoordinatesCollection.Count > 1) path.CoordinatesCollection.RemoveAt(0);
            Random rand = new Random(DateTime.Now.Millisecond);
            _thinkTime = new TimeSpan(0, 0, 0, 0, path.CoordinatesCollection.Count * rand.Next(50));
            //Game.Components.Add(path);

            Vector2 newPosition = GetFirstPathStepConverted(path);

            _currentDestination = newPosition;

            LabyrinthCorX = ((int)newPosition.X - 25) / LabyrinthUnit.Length;
            LabyrinthCorY = ((int)newPosition.Y - 25) / LabyrinthUnit.Length;
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: aahriman/RobotBattlefield
        public static void Main(string[] args)
        {
            ClientRobot.Connect(args);
            while (true)
            {
                RepairmenState repairmenState = getRepairmenState();
                MinerState     minerState     = getMinerState();


                switch (minerState)
                {
                case MinerState.DETONATE:
                    if (mineLayer.PutMinesList.Count > 0)
                    {
                        mineLayer.DetonateMine(mineLayer.PutMinesList[0].ID);
                    }
                    break;

                case MinerState.PUT_MINE:
                    mineLayer.PutMine();
                    break;

                case MinerState.GO_TO_REPAIRMAN:
                    mineLayer.Drive(AngleUtils.AngleDegree(mineLayer.X, mineLayer.Y, repairman.X, repairman.Y),
                                    mineLayer.Motor.ROTATE_IN);
                    break;

                case MinerState.GO_TO_BASE:
                    robotDriveToBase(mineLayer);
                    break;

                case MinerState.GO_AROUND:
                    if (EuclideanSpaceUtils.Distance(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y) < BaseCapture.BASE_SIZE * 3.0 / 4.0)
                    {
                        scan1 = mineLayer.Scan(AngleUtils.AngleDegree(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y), 10);
                    }
                    else
                    {
                        robotDriveAround(mineLayer);
                    }
                    break;
                }

                switch (repairmenState)
                {
                case RepairmenState.GO_AROUND:
                    if (EuclideanSpaceUtils.Distance(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y) <
                        BaseCapture.BASE_SIZE * 3.0 / 4.0)
                    {
                        scan2 = repairman.Scan(AngleUtils.AngleDegree(mineLayer.X, mineLayer.Y, capturedBase.X, capturedBase.Y), 10);
                    }
                    else
                    {
                        robotDriveAround(repairman);
                    }
                    break;

                case RepairmenState.GO_TO_BASE:
                    robotDriveToBase(repairman);
                    break;

                case RepairmenState.REPAIR:
                    repairman.Repair((int)EuclideanSpaceUtils.Distance(repairman.X, repairman.Y, mineLayer.X, mineLayer.Y) + 1);
                    break;
                }

                if (repairmenState == RepairmenState.REPAIR)
                {
                    mineLayer.previousHitpoints = mineLayer.HitPoints;
                }
            }
        }
コード例 #10
0
ファイル: MinerAI.cs プロジェクト: NeilMartin/Thrusty
 void Start()
 {
     mPlayer = null;
     mState = MinerState.TeleportToCrystal;
     mNextState = MinerState.TeleportToCrystal;
     mTargetPos = CalcTargetForState( mState );
     mStateTimer = 0.0f;
     mbStateChanged = false;
 }
コード例 #11
0
ファイル: MinerAI.cs プロジェクト: NeilMartin/Thrusty
 private void SetNextState( MinerState nextState )
 {
     mbStateChanged = true;
     mNextState = nextState;
 }
コード例 #12
0
ファイル: MinerAI.cs プロジェクト: NeilMartin/Thrusty
    void FixedUpdate()
    {
        if( null == mPlayer )
        {
            mPlayer = GameObject.FindWithTag("Player");
        }

        if( mbStateChanged )
        {
            mStateTimer = 0.0f;
            mState = mNextState;
            mbStateChanged = false;
        }
        else
        {
            mStateTimer += Time.fixedDeltaTime;
        }

        switch(mState)
        {
        case MinerState.TeleportToCrystal:
            {
                mTargetPos = CalcTargetForState(mState);
                transform.position = mTargetPos;
                SetNextState(MinerState.Idle);
                mTargetPos = CalcTargetForState(GetNextState());
            }
            break;
        case MinerState.Idle:
            {
                MoveTowardsTarget();
                if( (null != mPlayer) && IsInRange( mPlayer.transform.position, goToShipRadius ) )
                {
                    SetNextState(MinerState.GoToShip);
                    mTargetPos = CalcTargetForState(GetNextState());
                }
                else if( IsInRange(mTargetPos, 0.1f) )
                {
                    SetNextState( (Random.Range(0,100) > 50) ? MinerState.Idle : MinerState.GoToCrystal );
                    mTargetPos = CalcTargetForState(GetNextState());
                }
            }
            break;

        case MinerState.GoToCrystal:
            {
                MoveTowardsTarget();
                if( (null != mPlayer) && IsInRange( mPlayer.transform.position, goToShipRadius ) )
                {
                    SetNextState( MinerState.GoToShip );
                    mTargetPos = CalcTargetForState(GetNextState());
                }
                else if( IsInRange(mTargetPos, 0.1f) )
                {
                    SetNextState( MinerState.MineCrystal );
                }
            }
            break;

        case MinerState.MineCrystal:
            {
                MoveTowardsTarget();
                if( (null != mPlayer) && IsInRange( mPlayer.transform.position, goToShipRadius ) )
                {
                    SetNextState( MinerState.GoToShip );
                    mTargetPos = CalcTargetForState(GetNextState());
                }
                else if( mStateTimer > 5.0f )
                {
                    SetNextState( MinerState.Idle );
                    mTargetPos = CalcTargetForState(GetNextState());
                }
            }
            break;

        case MinerState.GoToShip:
            {
                mTargetPos = CalcTargetForState(mState);
                MoveTowardsTarget();
                if( (null == mPlayer) || (false == IsInRange( mPlayer.transform.position, goToShipRadius ) ) )
                {
                    SetNextState( MinerState.Idle );
                    mTargetPos = CalcTargetForState(GetNextState());
                }
                else if( mbCollected )
                {
                    SetNextState( MinerState.EnterShip );
                }
            }
            break;

        case MinerState.EnterShip:
            {
                GlobalCounter.Increment( CountMe.CountType.MinerCollected );
                Destroy(gameObject);
            }
            break;
        }
    }
コード例 #13
0
    public void Update()
    {
        var dir = new Vector2();
        var pos = pysicItem.Position;

        switch (State)
        {
        case MinerState.idleReturn:
            if (cooldownIdleReturn == null)
            {
                cooldownIdleReturn = CooldownManager.AddCooldown(1, null, () => {
                    CooldownManager.RemoveCooldown(cooldownIdleReturn);
                    cooldownIdleReturn = null;

                    direcr = 1;

                    State = MinerState.runMine;

                    view.StopTruck();
                });
            }

            break;

        case MinerState.idleMine:
            if (cooldownIdleMine == null)
            {
                cooldownIdleMine = CooldownManager.AddCooldown(1, null, () => {
                    direcr = -1;

                    State = MinerState.runReturn;
                    CooldownManager.RemoveCooldown(cooldownIdleMine);
                    cooldownIdleMine = null;
                    view.StopKirka();

                    view.PlayTruck();
                });
                view.PlayKirka();
            }
            break;

        case MinerState.runMine:
            dir = new Vector2(speed * direcr, 0);
            pysicItem.AddVelocity(dir);

            if (pos.x > maxPos.x && direcr != -1)
            {
                pysicItem.SetVelocity(new Vector2());



                State = MinerState.idleMine;
            }

            break;


        case MinerState.runReturn:
            dir = new Vector2(speed * direcr, 0);
            pysicItem.AddVelocity(dir);

            if (pos.x < minPos.x && direcr != 1)
            {
                pysicItem.SetVelocity(new Vector2());
                pysicItem.SetPosition(new Vector2(minPos.x, pysicItem.Position.y));
                //   direcr = 1;
                speed = UnityEngine.Random.Range(0.1f, 4.5f);



                State = MinerState.idleReturn;
            }

            break;
        }
    }
コード例 #14
0
 public static Miner FromState(MinerState state)
 {
     return(new Miner(state));
 }