Esempio n. 1
0
    public void FixedUpdate()
    {
        if (ConstructingUnit != null)
        {
            ConstructionTimeLeft -= Time.deltaTime;

            if (ConstructionTimeLeft <= 0f)
            {
                ConstructingUnit.gameObject.SetActive(true);
                ConstructingUnit = null;

                GetComponent <SpriteRenderer>().sprite = CompletedSprite;
            }
        }

        if (QueueTimeLeft > 0)
        {
            QueueTimeLeft -= Time.fixedDeltaTime;
        }
        else if (CurrentQueuedItem != QueueType.None)
        {
            var coords   = CordUtil.WorldToTile(transform.position);
            var freespot = _map.FindNextFreeTile(coords.First, coords.Second);
            _unitfactory.Create(QueuedUnit, PlayerOwner, freespot.First, freespot.Second - 2);
            CurrentQueuedItem = QueueType.None;
        }

        if (HP <= 0)
        {
            //Building dies
            Destroy(gameObject);
        }
    }
Esempio n. 2
0
        public void MoveTo(int x, int y, bool ignoreblocking = false)
        {
            SetupPathFinder();

            if (Map.Map[x, y].Blocked && !ignoreblocking)
            {
                _currentpath = null;
                return;
            }

            TargetX = x;
            TargetY = y;

            var position = CordUtil.WorldToTile(transform.position);
            var currentx = position.First;
            var currenty = position.Second;

            Pathfinder.ResultFound = r =>
            {
                _currentpath = r;

                if (_currentpath != null)
                {
                    _nextworldpos = CordUtil.TileToWorld(_currentpath.X, _currentpath.Y);
                }
            };

            _currentpath = null;
            Pathfinder.FindPath(currentx, currenty, x, y, this);
        }
Esempio n. 3
0
        public void Initialize()
        {
            _tileClick.Event += (btn, x, y) =>
            {
                if (btn != 0)
                {
                    return;
                }

                if (!_sessionModifiers.PlacingBuilding)
                {
                    return;
                }

                var worldcords = _camera.ScreenToWorldPoint(Input.mousePosition);
                var tilecords  = CordUtil.WorldToTile(worldcords);

                var obj = _buildingFactory.Create(_sessionModifiers.SelectedBuildingType, 0, tilecords.First, tilecords.Second);

                _selectionManager.PrimaryUnit.TargetBuilding = obj.GetComponent <BuildingController>();
                _selectionManager.PrimaryUnit.GetComponent <PathFinderFollower>().MoveTo(tilecords.First, tilecords.Second);

                _sessionModifiers.PlacingBuilding = false;
            };
        }
Esempio n. 4
0
        public void Attack(UnitController unit)
        {
            TargeType        = TragetType.Combat;
            CombatUnitTarget = unit;

            var location = CordUtil.WorldToTile(unit.transform.position);

            _pathFinder.MoveTo(location.First, location.Second, true);
            _combatTargetX      = location.First;
            _combatTargetY      = location.Second;
            _pathFindCheckCount = 10f;
        }
Esempio n. 5
0
        void FixedUpdate()
        {
            if (_unit.TargeType != TragetType.Harvest)
            {
                var pos  = CordUtil.WorldToTile(transform.position);
                var tree = FindNextTree(pos.First, pos.Second);

                if (tree == null)
                {
                    enabled = false;
                    return;
                }

                _unit.Harvest(tree.First, tree.Second);
            }
        }
Esempio n. 6
0
        void Start()
        {
            _current = Cooldown;

            var pos = CordUtil.WorldToTile(transform.position);

            _x = pos.First;
            _y = pos.Second - 2;

            if (_y < 0)
            {
                _y = pos.Second + 2;
            }

            _controller = GetComponent <BuildingController>();
        }
Esempio n. 7
0
        public void FixedUpdate()
        {
            if (_currentcooldown > 0f)
            {
                _currentcooldown -= Time.fixedDeltaTime;
            }



            if (TargeType == TragetType.Harvest)
            {
                if (HarvestHP <= 0f)
                {
                    TargeType = TragetType.None;
                    var player = _playerManager.Players.First(p => p.ID == PlayerOwner);

                    switch (_map.Map[HarvestTargetX, HarvestTargetY].ResourceType)
                    {
                    case MinableResourceType.None:
                        break;

                    case MinableResourceType.Food:
                        player.Food += 10;
                        break;

                    case MinableResourceType.Rock:
                        player.Stone += 10;
                        break;

                    case MinableResourceType.Wood:
                        player.Wood += 10;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    _map.Map[HarvestTargetX, HarvestTargetY].Decorators.Clear();
                    _map.Map[HarvestTargetX, HarvestTargetY].Type = TileTypes.Dirt;
                    _map.RebuildTile(HarvestTargetX, HarvestTargetY);
                    _map.Apply();

                    HarvestHP = 10f;
                }
                else
                {
                    var playerloc = CordUtil.WorldToTile(transform.position);
                    var xdiff     = playerloc.First - HarvestTargetX;
                    var ydiff     = playerloc.Second - HarvestTargetY;

                    if (xdiff == -1)
                    {
                        xdiff = 1;
                    }
                    if (ydiff == -1)
                    {
                        ydiff = 1;
                    }

                    if (xdiff <= 1 && ydiff <= 1)
                    {
                        HarvestHP -= Time.fixedDeltaTime;
                    }
                }
            }

            if (CombatUnitTarget != null && _currentcooldown <= 0f)
            {
                var loc = CordUtil.WorldToTile(CombatUnitTarget.transform.position);

                if (loc.First != _combatTargetX || loc.Second != _combatTargetY)
                {
                    Attack(CombatUnitTarget);
                }


                if (Vector3.Distance(transform.position, CombatUnitTarget.transform.position) < CombatDistance)
                {
                    CombatUnitTarget.Hit(CombatDamage);
                    _currentcooldown = CombatCooldown;
                }
            }

            if (HP <= 0)
            {
                //Unit dies
                Destroy(gameObject);
            }
        }