Example #1
0
 public CommandStub_Teleport(string teleporterID, int x, int y, int z, FloorState destinationFloor) : base(teleporterID)
 {
     this.X = x;
     this.Y = y;
     this.Z = z;
     this.DestinationFloor = destinationFloor;
 }
Example #2
0
        private void HandleAttack(GameEvent_PrepareAttack ev)
        {
            if (ev.ExecutorEntity == this.Parent)
            {
                // If it's out of range, then the attack misses
                int weaponRange = ev.ExecutorEntity.TryGetAttribute(EntityAttributeType.MAX_RANGE, ev.ExecutorEntity)
                                  .Value;
                int distance = FloorState.DistanceBetweenEntities(ev.Target, ev.CommandEntity);
                if (distance > weaponRange)
                {
                    ev.RegisterResult("MISS (out of range)");
                    return;
                }

                // TODO: This sequence of early exists is crufty because there's a lot of "before-exit-do" stuff here!
                // If any of the cells isn't walkable, then your shot is blocked and the attack stops
                var targetPos   = ev.Target.TryGetPosition();
                var attackerPos = ev.CommandEntity.TryGetPosition();
                var lineCells   = ev.GameMap.GetCellsAlongLine(attackerPos.X, attackerPos.Y, targetPos.X, targetPos.Y);

                if (lineCells.Any(c => !c.IsWalkable))
                {
                    ev.RegisterResult("MISS (no straight shot)");
                    return;
                }

                // Forward the attack to the target
                var receiveAttack = new GameEvent_ReceiveAttack(ev);
                ev.Target.HandleEvent(receiveAttack);
                if (!receiveAttack.Completed)
                {
                    Log.DebugLine("Could not resolve attack against " + ev.Target.ToString());
                }
            }
        }
Example #3
0
        public void testIsInvalidSituation_Valid_DifferentFloors()
        {
            var objs = new List <List <string> >();

            objs.Add(new List <string>()
            {
                "BM"
            });
            objs.Add(new List <string>()
            {
                "BG"
            });
            objs.Add(new List <string>()
            {
                "CM"
            });
            objs.Add(new List <string>()
            {
                "CG"
            });

            var floorState = new FloorState(0, objs, 0);
            var result     = floorState.IsInvalidSituation();

            Assert.False(result);
        }
Example #4
0
        public override GameEvent_Command ReifyStub(FloorState arena)
        {
            var user = arena.ResolveEID(this.UserEID);
            var item = user.GetComponentOfType <Component_Inventory>().FindByEid(this.ItemEID);

            return(new GameEvent_UseItem(arena.CurrentTick, Config.ONE, user, item, arena.ResolveEID(this.TargetEID)));
        }
Example #5
0
    private void ElevatorButtonClicked(int floor)
    {
        FloorState state = Behaviour.GetState(floor);

        state.ChoosedInElevator = true;
        Behaviour.SetState(floor, state);
        Behaviour.Continue();
    }
Example #6
0
 private void ResetToDefaults()
 {
     _State        = FloorState.UNBROKEN;
     Break         = false;
     Dissolving    = 0;
     TakenPressure = 0;
     _Dissolve.SetProgress(0f);
 }
Example #7
0
    public void Buy(GameObject buyer)
    {
        CurrentState = FloorState.Bought;
        ShowInteriorMap(true);

        GameMode.Instance.onBusinessModeStarted.AddListener(() => SetArragnedFurnituresInteractionEnable(false));
        GameMode.Instance.onEditorModeStarted.AddListener(() => SetArragnedFurnituresInteractionEnable(true));
    }
Example #8
0
 // Wait for a signal to start breaking (breaking)
 private void ListenForActivation()
 {
     if (Break)
     {
         _State     = FloorState.BREAKING;
         Dissolving = BreakingDissolve;
         _Dissolve.SetProgress(Dissolving);
     }
 }
Example #9
0
 // floor falls towards the Bedrock
 private void Fall()
 {
     transform.localPosition += transform.TransformDirection(Vector3.down) * _FallSpeed * World.Instance.DeltaTime;
     if (transform.localPosition.y < Bedrock)
     {
         _State = FloorState.DOWN;
         transform.localPosition.Set(transform.localPosition.x, Bedrock, transform.localPosition.z);
     }
 }
Example #10
0
    public void SetState(int i, FloorState state)
    {
        _floorStates[i] = state;
        OnStateChanged(i, state);

        if (CallsNumber == 1 || (i <= _currentPosition && __elevatorDirection == ElevatorDirection.Down) || (i >= _currentPosition && __elevatorDirection == ElevatorDirection.Up))
        {
            _aimFloor = GetNextAim();
        }
    }
Example #11
0
        public static int MinimumStepsToTopFloor2(FloorState initialState, int targetFloor, Floor targetTopFloor)
        {
            bool TargetCondition(FloorState f)
            {
                return(f.ElevatorFloor == targetFloor && f.Floors[targetFloor] == targetTopFloor);
            }

            var(terminationNode, _) = initialState.ShortestPath(floor => floor.Next(), TargetCondition);

            return(terminationNode.Depth);
        }
Example #12
0
        private void MoveCursor(int dx, int dy)
        {
            var cell      = this.Floor.FloorMap.GetCell(this.X + dx, this.Y + dy);
            var playerPos = this.Floor.Player.TryGetPosition();

            if (FloorState.DistanceBetweenPositions(playerPos.X, playerPos.Y, cell.X, cell.Y) <= this.Range &&
                cell.IsInFov && cell.IsWalkable)
            {
                this.X += dx;
                this.Y += dy;
            }
        }
Example #13
0
        public override GameEvent_Command ReifyStub(FloorState floor)
        {
            // TODO: Equipped items are *not* "Whatever is held in right right arm"
            var attackerEntity = floor.ResolveEID(this.AttackerEID);
            var equippedWeapon = attackerEntity.GetComponentOfType <Component_Skeleton>()
                                 .InspectBodyPart(BodyPartLocation.RIGHT_ARM)
                                 .TryGetSubEntities(SubEntitiesSelector.WEAPON)
                                 .FirstOrDefault();

            return(new GameEvent_PrepareAttack(floor.CurrentTick, Config.ONE, attackerEntity,
                                               floor.ResolveEID(this.TargetEID), equippedWeapon, floor.FloorMap, this.SubTarget));
        }
Example #14
0
 protected override void OnPlayerExit(Player player)
 {
     base.OnPlayerExit(player);
     if (declineAfterExit && m_floorState == FloorState.UP)
     {
         // Decline
         //Debug.Log("Player exits floor");
         m_floorState      = FloorState.DOWN;
         m_lavaFillCounter = 1;
         UpdateFloor();
     }
 }
Example #15
0
    void SetState(FloorState newState)
    {
        if (currentState != null)
        {
            currentState.Exit();
        }
        currentState = newState;
        currentState.Enter();
        GChess chessOnFloor = GridManager.instance.GetChess(floor.location);

        if (chessOnFloor)
        {
            currentState.OnChessEnter(chessOnFloor);
        }
    }
Example #16
0
        public void FirstStarExample2()
        {
            var initialState = new FloorState(0, new List <Floor>
            {
                Floor.HydrogenChip | Floor.LithiumChip,
                Floor.HydrogenGenerator,
                Floor.LithiumGenerator,
                Floor.Empty
            });


            int steps = Problem.MinimumStepsToTopFloor2(initialState, 3, Floor.HydrogenChip | Floor.LithiumChip | Floor.HydrogenGenerator | Floor.LithiumGenerator);

            Assert.Equal(11, steps);
        }
Example #17
0
    private IEnumerator MoveElevator(float speed)
    {
        while (true)
        {
            if (_elevatorState == ElevatorState.Moving)
            {
                if (Mathf.Abs(_currentPosition - _aimFloor) < _arrivingTresshold)
                {
                    bool hadCalls = HasCalls;

                    FloorState state = _floorStates[CurrentFloor];

                    state.ChoosedInElevator = false;
                    if (__elevatorDirection == ElevatorDirection.Down)
                    {
                        state.DownPressed = false;
                    }
                    if (__elevatorDirection == ElevatorDirection.Up)
                    {
                        state.UpPresed = false;
                    }

                    SetState(CurrentFloor, state);

                    if (_elevatorState != ElevatorState.Loading && hadCalls)
                    {
                        _elevatorState = ElevatorState.Loading;
                        yield return(new WaitForSeconds(LoadingTime));
                    }
                    yield return(null);
                }
                else
                {
                    if (_currentPosition > _aimFloor)
                    {
                        _currentPosition -= Speed * Time.deltaTime;
                    }
                    else
                    {
                        _currentPosition += Speed * Time.deltaTime;
                    }
                }

                yield return(null);
            }
            yield return(null);
        }
    }
Example #18
0
    private void FloorButtonClicked(int floor, FloorPanel.Direction direction)
    {
        FloorState state = Behaviour.GetState(floor);

        switch (direction)
        {
        case FloorPanel.Direction.Down:
            state.DownPressed = true;
            break;

        case FloorPanel.Direction.Up:
            state.UpPresed = true;
            break;
        }
        Behaviour.SetState(floor, state);
    }
Example #19
0
        public void DeterminePatrolPath(FloorState state, IRandom rand)
        {
            this.PatrolStart = this.Parent.TryGetPosition();
            var  cells = state.WalkableCells();
            Cell cell  = rand.RandomElement(cells);

            while (Config.MinPatrolDistance < FloorState.DistanceBetweenPositions(this.PatrolStart.X,
                                                                                  this.PatrolStart.Y, cell.X, cell.Y))
            {
                cell = rand.RandomElement(cells);
            }
            var endPos = new GameQuery_Position();

            endPos.RegisterPosition(cell.X, cell.Y, state.Level, false);
            this.PatrolEnd = endPos;
        }
Example #20
0
    private void FloorStateChanged(int floor, FloorState state)
    {
        if (!state.DownPressed)
        {
            Shaft.ResetButton(floor, FloorPanel.Direction.Down);
        }
        if (!state.UpPresed)
        {
            Shaft.ResetButton(floor, FloorPanel.Direction.Up);
        }

        if (!state.ChoosedInElevator)
        {
            View.ResetButton(floor);
        }
    }
Example #21
0
        public void testIsComplete_Success()
        {
            var objs = new List <List <string> >();

            objs.Add(new List <string>());
            objs.Add(new List <string>());
            objs.Add(new List <string>());
            objs.Add(new List <string>()
            {
                "BM", "BG", "CM", "CG"
            });

            var floorState = new FloorState(0, objs, 3);
            var result     = floorState.IsComplete();

            Assert.True(result);
        }
Example #22
0
        public void testIsComplete_Fail_Elevator()
        {
            var objs = new List <List <string> >();

            objs.Add(new List <string>());
            objs.Add(new List <string>());
            objs.Add(new List <string>());
            objs.Add(new List <string>()
            {
                "BM", "BG", "CM", "CG"
            });

            var floorState = new FloorState(0, objs, 1);
            var result     = floorState.IsComplete();

            Assert.False(result);
        }
Example #23
0
        private void HandleQueryCommand(GameQuery_Command q)
        {
            if (this.Alerted)
            {
                this.activeBook.TryRegisterCommand(q);
            }
            else if (q.FloorState.Player != null &&
                     FloorState.DistanceBetweenEntities(this.Parent, q.FloorState.Player) <=
                     this.Parent.TryGetAttribute(EntityAttributeType.DETECTION_RADIUS).Value)
            {
                q.FloorState.AlertAllAIs();
            }
            else
            {
                var myPos = this.Parent.TryGetPosition();
                if (myPos.X == this.PatrolStart.X && myPos.Y == this.PatrolStart.Y)
                {
                    this.OnReturnLeg = false;
                }
                else if (myPos.X == this.PatrolEnd.X && myPos.Y == this.PatrolEnd.Y)
                {
                    this.OnReturnLeg = true;
                }

                Cell myCell = q.FloorState.FloorMap.GetCell(myPos.X, myPos.Y);
                Path patrolPath;
                if (!this.OnReturnLeg)
                {
                    patrolPath = q.FloorState.ShortestPath(myCell, this.PositionToCell(this.PatrolEnd, q.FloorState));
                }
                else
                {
                    patrolPath = q.FloorState.ShortestPath(myCell,
                                                           this.PositionToCell(this.PatrolStart, q.FloorState));
                }
                if (patrolPath != null)
                {
                    q.RegisterCommand(this.MoveEventForPath(q, patrolPath));
                }
                else
                {
                    q.RegisterCommand(new CommandStub_Delay(this.Parent.EntityID, Config.ONE));
                }
            }
        }
Example #24
0
        public CellInfo AlertCells(FloorState floor)
        {
            var info         = new CellInfo();
            var scanRadius   = this.Parent.TryGetAttribute(EntityAttributeType.SCAN_REQUIRED_RADIUS).Value;
            var detectRadius = this.Parent.TryGetAttribute(EntityAttributeType.DETECTION_RADIUS).Value;
            var myPosition   = this.Parent.TryGetPosition();

            if (!this.Alerted)
            {
                info.AlertCells = floor.CellsInRadius(myPosition.X, myPosition.Y, detectRadius);
            }
            if (!this.Scanned)
            {
                info.ScanCells = floor.CellsInRadius(myPosition.X, myPosition.Y, scanRadius);
            }

            return(info);
        }
Example #25
0
        public override GameEvent_Command ReifyStub(FloorState floor)
        {
            var commandEntity          = floor.ResolveEID(this.CommandEID);
            var commandPosition        = commandEntity.TryGetPosition();
            var entityAtTargetPosition = floor.EntityAtPosition(commandPosition.X + (int)this.X,
                                                                commandPosition.Y + (int)this.Y);

            if (entityAtTargetPosition != null)
            {
                // TODO: Don't always bump attack to torso
                return(new CommandStub_PrepareTargetedAttack(this.CommandEID, entityAtTargetPosition.EntityID,
                                                             entityAtTargetPosition.Label, BodyPartLocation.TORSO)
                       .ReifyStub(floor));
            }
            else
            {
                return(new GameEvent_MoveSingle(floor.CurrentTick, Config.ONE, commandEntity, this.X, this.Y, floor));
            }
        }
Example #26
0
        private static string FirstStarUsingEnumFlags()
        {
            var initialState = new FloorState(0, new List <Floor>
            {
                Floor.ThuliumGenerator | Floor.ThuliumChip | Floor.PlutoniumGenerator | Floor.StrontiumGenerator,
                Floor.PlutoniumChip | Floor.StrontiumChip,
                Floor.PromethiumGenerator | Floor.PromethiumChip | Floor.RutheniumGenerator | Floor.RutheniumChip,
                Floor.Empty
            });

            var targetTopFloor = Floor.PlutoniumChip | Floor.PlutoniumGenerator |
                                 Floor.PromethiumChip | Floor.PromethiumGenerator |
                                 Floor.RutheniumChip | Floor.RutheniumGenerator |
                                 Floor.StrontiumChip | Floor.StrontiumGenerator |
                                 Floor.ThuliumChip | Floor.ThuliumGenerator;

            var result = MinimumStepsToTopFloor2(initialState, 3, targetTopFloor);

            return(result.ToString());
        }
Example #27
0
 // Wait for a signal to start going down (broken)
 private void ListenForForce()
 {
     // floor is broken immediately
     if (_BreakImmediately)
     {
         _State     = FloorState.BROKEN;
         Dissolving = DownDissolve;
         _Dissolve.SetProgress(Dissolving);
     }
     else if (_playerProxSwitch.Activated)
     {
         TakenPressure += World.Instance.DeltaTime;
         if (TakenPressure >= _Resistance)
         {
             _State        = FloorState.BROKEN;
             TakenPressure = _Resistance;
         }
         float pressureRatio = (_Resistance > 0f ? TakenPressure / _Resistance : 1f);
         Dissolving = BreakingDissolve + pressureRatio * (DownDissolve - BreakingDissolve);
         _Dissolve.SetProgress(Dissolving);
     }
 }
Example #28
0
 protected override void OnTickEnd()
 {
     base.OnTickEnd();
     if (!receiveTick)
     {
         return;
     }
     if (declineAfterExit && m_floorState == FloorState.DOWN)
     {
         //step counter
         m_stepsAfterDecline++;
         if (m_stepsAfterDecline > stepsBeforeIncline)
         {
             //Debug.Log(m_stepsAfterDecline);
             m_stepsAfterDecline = 0;
             // Incline
             m_floorState = FloorState.UP;
             m_lavaFlows  = false;
             UpdateFloor();
         }
     }
 }
Example #29
0
        public override GameEvent_Command ReifyStub(FloorState floor)
        {
            var attackerEntity = floor.ResolveEID(this.AttackerEID);
            var equippedWeapon = attackerEntity.GetComponentOfType <Component_Skeleton>()
                                 .InspectBodyPart(BodyPartLocation.RIGHT_ARM)
                                 .TryGetSubEntities(SubEntitiesSelector.WEAPON)
                                 .FirstOrDefault();

            // TODO: Don't require exact square
            var attackerPosition = attackerEntity.TryGetPosition();
            var targetEntity     = floor.EntityAtPosition(attackerPosition.X + this.x, attackerPosition.Y + this.y);

            if (targetEntity != null)
            {
                return(new GameEvent_PrepareAttack(floor.CurrentTick, Config.ONE, attackerEntity, targetEntity,
                                                   equippedWeapon, floor.FloorMap, this.SubTarget));
            }
            else
            {
                return(new GameEvent_Delay(floor.CurrentTick, Config.ONE, attackerEntity));
            }
        }
Example #30
0
        public override bool IsMet(GameQuery_Command commandQuery)
        {
            // TODO: This is gonna show up in a lot of conditions, and looks pretty janky.
            Entity target = commandQuery.FloorState.Player;

            // TODO: Smooth out this int? business!
            // It's an int? because some conditions (asking for WEAPON_RANGE on something which has no range, like a
            // MechSkeleton, but which does get turns) are nonsensical.
            int?optionDistance = this.ResolveOptionDistance(commandQuery, target);

            if (optionDistance == null)
            {
                return(true);
            }

            int currDist = FloorState.DistanceBetweenEntities(target, commandQuery.CommandEntity);

            switch (this.Operator)
            {
            case ComparisonOperator.EQUAL:
                return(currDist == optionDistance);

            case ComparisonOperator.LESS_THAN:
                return(currDist < optionDistance);

            case ComparisonOperator.LESS_THAN_EQUAL:
                return(currDist <= optionDistance);

            case ComparisonOperator.GREATER_THAN:
                return(currDist > optionDistance);

            case ComparisonOperator.GREATER_THAN_EQUAL:
                return(currDist >= optionDistance);

            default:
                throw new InvalidOperationException("Condition_Distance can't handle " + this.Operator);
            }
        }