public void MouseClickCreature(CreatureComponent creature)
        {
            if (!IsTargetValid(creature) || _attackCreature == null)
            {
                return;
            }
            _currentCreature.behavior.Target = creature.transform.gameObject;
            TileBehaviour.OnMove             = true;
            ExecuteOnMainThread.Enqueue(() =>
            {
                _creatureHelper.AttackMelee.SetActive(false);
                _creatureHelper.AttackRange.SetActive(false);
            });

            if (_selectedTile != null && _currentCreature.Type == CreatureType.Melee)
            {
                var tileBehavior = _tiles.SingleOrDefault(x => x.TileHex == _selectedTile);
                MoveCreatureToSelectedTile(tileBehavior);
                MustAttack = true;
                _currentCreature.MustAttack = true;
                _selectedTile   = null;
                _attackCreature = null;
                return;
            }

            var targetIndex = _currentCreature.behavior.Target.GetComponent <CreatureComponent>().Index;

            GameFlow.Instance.Channel.AttackCreature(targetIndex, _currentCreature.Index);
            _attackCreature = null;
        }
        public void MouseOverCreature(CreatureComponent creature)
        {
            if (!IsTargetValid(creature) || TileBehaviour.OnMove)
            {
                return;
            }

            if (_currentCreature.Type == CreatureType.Melee)
            {
                var xCoor = _currentCreature.Piece.Location.X;
                var yCoor = _currentCreature.Piece.Location.Y;
                var currentCreatureTile  = _game.GameBoard[xCoor, yCoor];
                var selectedCreatureTile = _game.GameBoard[creature.Piece.Location.X, creature.Piece.Location.Y];
                if (IsTilesNeighbours(currentCreatureTile, selectedCreatureTile))
                {
                    _selectedTile   = null;
                    _attackCreature = creature;
                    _currentCreature.behavior.DisplayAttackIcon(_currentCreature.creatureHelper.Canvas);
                    return;
                }
                var closestTile = _movementRange
                                  .SelectMany(tile => tile)
                                  .FirstOrDefault(tile => IsTilesNeighbours(selectedCreatureTile, tile));
                if (closestTile == null)
                {
                    return;
                }
                _currentCreature.behavior.DisplayAttackIcon(_currentCreature.creatureHelper.Canvas);
                _selectedTile = closestTile;
            }
            _attackCreature = creature;
            _currentCreature.behavior.DisplayAttackIcon(_currentCreature.creatureHelper.Canvas);
        }
Ejemplo n.º 3
0
        public override void DefenseCreature(CreatureComponent creature)
        {
            var parameters = new List <SerializableType> {
                creature.Piece.Location
            };
            var remoteMethod = new RemoteInvokeMethod("BoardBehavior", Command.Defend, parameters);

            BeginSendPackage(remoteMethod);
        }
        private void AttachInfoText(CreatureComponent creatureComponent)
        {
            var text = Instantiate(TextPrefab);

            text.transform.SetParent(CreatureCountPanel.transform);
            creatureComponent.Text = text.GetComponent <RectTransform>();
            creatureComponent.Text.GetComponent <Text>().alignment = TextAnchor.UpperLeft;
            creatureComponent.Text.localPosition = new Vector3(0, 0, -2);
            _creaturesComponent.Add(creatureComponent);
        }
 public void MouseExitCreature(CreatureComponent creature)
 {
     _attackCreature = null;
     _selectedTile   = null;
     if (_currentCreature == null)
     {
         return;
     }
     _currentCreature.behavior.HideAttackIcon();
 }
 private void DisableCreatureComponent(CreatureComponent creatureComponent, TileBehaviour tileBehavior)
 {
     _creatureImageDictionary[creatureComponent.Attributes.Index].sprite = _creatureHelper.DeathIcon.sprite;
     creatureComponent.gameObject.SetActive(false);
     creatureComponent.GetComponent <SphereCollider>().enabled = false;
     creatureComponent._textComponent.gameObject.SetActive(false);
     creatureComponent.Status = CreatureStatus.Death;
     tileBehavior.ResetColor();
     FinishAction(creatureComponent);
 }
        private bool IsTargetValid(CreatureComponent creature)
        {
            if (_currentCreature == null)
            {
                return(false);
            }
            var isSameTeam = _canMove && !TileBehaviour.OnMove && _currentCreature.Team == creature.Team;

            return(IsYourTurn(_currentCreature) && !isSameTeam);
        }
Ejemplo n.º 8
0
        private static bool CellIsOccupiable(IHexGridCell cell, bool isSquad)
        {
            if (cell is null)
            {
                return(false);
            }

            CreatureComponent creatureComponent = cell.GetComponent <CreatureComponent>();

            System.Type creatureType = isSquad ? typeof(EnemyMovementController) : typeof(Squads.SquadController);
            return(!cell.HasComponent <UnselectableComponent>() &&
                   (creatureComponent is null || creatureComponent.Creature.GetType() == creatureType));
        }
 public override List <IHexGridCell> GetPath(IHexGridCell currentLocation, int speed)
 {
     foreach (IHexGridCell cell in guardedCells)
     {
         CreatureComponent creatureComponent = cell.GetComponent <CreatureComponent>();
         if (creatureComponent?.Creature?.GetType() == typeof(CreatureMovementController))
         {
             chasing = creatureComponent;
             return(AStarModule.FindPath(currentLocation, creatureComponent.Creature.Location, false));
         }
     }
     chasing = null;
     return(base.GetPath(currentLocation, speed));
 }
        public void Attack(AttackModel attackInfo)
        {
            _currentCreature = _creaturesComponent.SingleOrDefault(x => x.Index == attackInfo.SenderCreatureIndex);
            var target = _creaturesComponent.SingleOrDefault(x => x.Index == attackInfo.TargetCreatureIndex);

            ExecuteOnMainThread.Enqueue(() =>
            {
                _currentCreature.behavior.Damage = attackInfo.Damage;
                _currentCreature.behavior.Target = target.gameObject;
                _currentCreature.Attack();
                _currentCreature.behavior.Attack(_currentCreature.transform.position);
                _currentCreature._anim.SetFloat("attack", 1);
            });
        }
        public void ChangeTurn(NextTurn turn)
        {
            TileBehaviour.OnMove = false;
            _currentCreature     = _creaturesComponent.SingleOrDefault(x => x.Index == turn.CreatureIndex);

            if (!IsYourTurn(_currentCreature))
            {
                _canMove = false;
                ExecuteOnMainThread.Enqueue(() => { UpdateTurnIterface("Enemy Turn"); });
                return;
            }

            _canMove = true;
            ExecuteOnMainThread.Enqueue(() => { UpdateTurnIterface("Your Turn"); });
            ExecuteOnMainThread.Enqueue(CheckPath);
        }
Ejemplo n.º 12
0
 protected virtual bool UpdateLocation(IHexGridCell location)
 {
     if (!OccupiableLocation(location))
     {
         return(false);
     }
     if (Location != null)
     {
         AssertHelper.Assert(creatureComponent != null, "Missing creature component", this);
         bool success = Location.RemoveComponent(creatureComponent);
         AssertHelper.Assert(success, "Failed to remove creature component", this);
     }
     else
     {
         creatureComponent = new CreatureComponent(this);
     }
     Location = location;
     Location.AddComponent(creatureComponent);
     return(true);
 }
Ejemplo n.º 13
0
        protected override bool UpdateLocation(IHexGridCell location)
        {
            CreatureComponent otherCreature = location.GetComponent <CreatureComponent>();

            if (!(otherCreature is null) &&
                !(otherCreature.Creature is EnemyMovementController && IsUserControlledFunction()))
            {
                return(false);
            }
            if (Location != null)
            {
                AssertHelper.Assert(creatureComponent != null, "Missing creature component", this);
                bool success = Location.RemoveComponent(creatureComponent);
                AssertHelper.Assert(success, "Failed to remove creature component", this);
            }
            else
            {
                creatureComponent = new CreatureComponent(this);
            }
            Location = location;
            Location.AddComponent(creatureComponent);
            return(true);
        }
Ejemplo n.º 14
0
 public abstract void DefenseCreature(CreatureComponent creature);
Ejemplo n.º 15
0
 public override void DefenseCreature(CreatureComponent creatureComponent)
 {
 }
 public void FinishAction(CreatureComponent creature)
 {
     TileBehaviour.OnMove = false;
     _canMove             = false;
     ExecuteOnMainThread.Enqueue(ResetState);
 }
 private bool IsYourTurn(CreatureComponent creature)
 {
     return(GameFlow.Instance.IsGameCreator && creature.Team == Team.Red ||
            !GameFlow.Instance.IsGameCreator && creature.Team == Team.Blue);
 }
Ejemplo n.º 18
0
 public virtual void DieCreature(CreatureComponent creature)
 {
 }