예제 #1
0
        public void FieldOfViewUpdate()
        {
            //UInt16 range = _statsDerivative[(sbyte)StatDerivative.SightRange];
            UInt16 range = GetSightRange();

            //Map currentMap = this.InhabitedMap;

            if (range < 0)
            {
                return;
            }

            //REMOVE REDUNDANCY HERE
            BitArray[] update = new BitArray[_map.BoundX];
            for (int i = 0; i < _map.BoundX; ++i)
            {
                update[i] = new BitArray(_map.BoundY);
            }

            for (Int32 i = -range; i <= range; i++)
            {
                for (Int32 j = -range; j <= range; j++)
                {
                    Coords current = new Coords(CoordsType.Tile, _positionTile.X + i, _positionTile.Y + j);
                    if (
                        !this._map.CheckInBounds(current)
                        ||
                        (StaticMathFunctions.DistanceBetweenTwoCoordsHex(this._positionTile, current) > range)
                        )
                    {
                        continue;
                    }

                    bool val = _myVisibilityTracker.RayTracerVisibilityCheckTile(this._positionTile, current, true, range);

                    update[current.X][current.Y] = val;
                }
            }

            // determine values that were changed
            for (int i = 0; i < _map.BoundX; ++i)
            {
                update[i] = update[i].Xor(_fieldOfView[i]);
            }

            // update changes
            for (int i = 0; i < _map.BoundX; ++i)
            {
                for (int j = 0; j < _map.BoundY; ++j)
                {
                    if (update[i][j])
                    {
                        bool val = _fieldOfView[i][j];
                        _fieldOfView[i][j] = !val;
                        //_inhabitedMap.GetTile(i, j).VisibilityUpdate(this, !val);
                        _myVisibilityTracker.VisibilityUpdate(new Coords(CoordsType.Tile, i, j), this, !val);
                    }
                }
            }
        }
예제 #2
0
        public override bool Execute(Coords?_target)
        {
            if (_target == null)
            {
                throw new Exception("Basic Attack no target hex passed.");
            }

            _range = _agent.GetAttackRange();
            int distance = StaticMathFunctions.DistanceBetweenTwoCoordsHex(_agent.PositionGet(), _target.Value);

            if (distance > _range)
            {
                // target not in range; do nothing
                return(false);
            }

            Creature quarry = _map.TenancyMap[_target.Value.X, _target.Value.Y];

            if (quarry == null)
            {
                // no one to hit: do nothing.
                return(false);
            }

            Item weapon = _agent.InventoryEquipped.GetItem((sbyte)InventoryType.HandWeapon);

            if (weapon == null || (weapon.ItemFunctions[ItemProperty.Range] <= 1))
            {
                // weapon not of proper type; do nothing.
                return(false);
            }

            // determine damage
            int damage = (UInt16)Math.Max(_agent.GetAttackDamage() - quarry.GetArmor(), 1);

            // substract HP
//            quarry.AddToStatBasic(Creature.StatBasic.HP, -damage);
            quarry.EffectRegister(new EffectChangeStatBasic(_agent, 0, quarry, Creature.StatBasic.HP, -damage));

            // NOTE: AP substraction done at ActionUseSpell level.

            // Check if target is dead.
            //if (quarry.Dead)
            //{
            //    _agent.AddToStatBasic(Creature.StatBasic.XP, StaticMathFunctions.XPFormula(quarry));
            //}

            // Ranged attack anim
            // for now use arrow by default; later associate particle sprites to the various ranged weapons (slings?)
            _drawer.Animations.Add(new AnimProjectile(Constants.AnimProjectileArrowBaseSpeed * distance,
                                                      _drawer.Particles[(sbyte)SpriteParticle.ParticleArrow],
                                                      _interface.HexPosition(_agent.PositionGet()) + new Vector2(Constants.TileSize / 2, Constants.TileSize / 2),
                                                      _interface.HexPosition(_target.Value) + new Vector2(Constants.TileSize / 2, Constants.TileSize / 2)));

            // Floating message addition
            _drawer.FloatingMessages.Add(new FloatingMessage(Constants.FloatingTextDefaultTimer, "-" + damage.ToString() + "HP",
                                                             _interface.HexPosition(_target.Value) + new Vector2(Constants.TileSize / 2, Constants.TileSize / 2)));

            return(true);
        }
예제 #3
0
        public override bool Execute(Coords?_target)
        {
            if (_target == null)
            {
                throw new Exception("Basic Attack no target hex passed.");
            }

            int distance = StaticMathFunctions.DistanceBetweenTwoCoordsHex(_agent.PositionGet(), _target.Value);

            if (distance > 1)
            {
                // target not in range; do nothing
                return(false);
            }

            Creature quarry = _map.TenancyMap[_target.Value.X, _target.Value.Y];

            if (quarry == null)
            {
                // no one to hit: do nothing.
                return(false);
            }

            Item weapon = _agent.InventoryEquipped.GetItem((sbyte)InventoryType.HandWeapon);

            if (weapon != null && (weapon.MyType != ItemType.Weapon || weapon.ItemFunctions[ItemProperty.Range] > 1))
            {
                // weapon not of proper type; do nothing.
                return(false);
            }

            // determine damage
            int damage = (UInt16)Math.Max(_agent.GetAttackDamage() - quarry.GetArmor(), 1);

            // substract HP
            //quarry.AddToStatBasic(Creature.StatBasic.HP, -damage);
            quarry.EffectRegister(new EffectChangeStatBasic(_agent, 0, quarry, Creature.StatBasic.HP, -damage));

            // Check if target is dead.
            //if (quarry.Dead)
            //{
            //    _agent.AddToStatBasic(Creature.StatBasic.XP, StaticMathFunctions.XPFormula(quarry));
            //}

            // NOTE: AP substraction done at ActionUseSpell level.

            // Melee slash anim
            if (weapon != null)
            {
                _drawer.Animations.Add(new AnimWeaponSlash(Constants.AnimWeaponSlashBaseDuration, _drawer.Items[(sbyte)weapon.ItemBitmap],
                                                           _interface.HexPosition(_target.Value) + new Vector2(Constants.TileSize / 2, Constants.TileSize / 2)));
            }

            // Floating message addition
            _drawer.FloatingMessages.Add(new FloatingMessage(Constants.FloatingTextDefaultTimer, "-" + damage.ToString() + "HP",
                                                             _interface.HexPosition(_target.Value) + new Vector2(Constants.TileSize / 2, Constants.TileSize / 2)));

            return(true);
        }
예제 #4
0
        private void DrawCreatures(SpriteBatch spriteBatch)
        {
            int tilesize = Constants.TileSize;
            int offset   = tilesize / 4;

            // CREATURES
            foreach (KeyValuePair <UInt32, Creature> kvp in _currentMap.Menagerie)
            {
                Creature  tenant            = kvp.Value;
                Texture2D tenantBitmap      = _creatures[(sbyte)tenant.MyBitmap];
                Int32     i                 = tenant.PositionGet().X;
                Int32     j                 = tenant.PositionGet().Y;
                Int16     visibilityTracker = _currentMap.MyVisibilityTracker.VisibilityCheck(tenant.PositionGet(), _myGame.PlayerTeam);
                Vector2   pos               = new Vector2(i * tilesize + (j % 2) * (tilesize / 2), j * tilesize - j * offset) + _screenAnchor;
                Rectangle rectHex           = ZoomTransform(new Rectangle((int)pos.X, (int)pos.Y, tilesize, tilesize));
                Rectangle rectCreature      = ZoomTransform(new Rectangle((int)pos.X, (int)pos.Y, tenantBitmap.Width, tenantBitmap.Height));

                if (tenant != null && (tenant.Team == _myGame.PlayerTeam || visibilityTracker > 0))
                {
                    // if the tenant is selected, draw selection box
                    if (_myInterface.SelectedCreature == tenant)
                    {
                        spriteBatch.Draw(_tiles[(sbyte)SpriteTile.HexRed], rectHex, Color.White);
                    }

                    // if the tenant is an enemy and within range of a friendly selected creature, draw an indication
                    if (_myInterface.SelectedCreature != null && _myInterface.SelectedCreature.Team == _myGame.PlayerTeam &&
                        tenant.Team != _myGame.PlayerTeam && _myInterface.SelectedCreature.GetAttackRange() >=
                        StaticMathFunctions.DistanceBetweenTwoCoordsHex(_myInterface.SelectedCreature.PositionGet(), tenant.PositionGet()))
                    {
                        spriteBatch.Draw(_tiles[(sbyte)SpriteTile.HexRed], rectHex, Color.Red);
                    }

                    // If there is an active animation for the creature, draw it.
                    if (_creatureAnimations.ContainsKey(tenant.UniqueID))
                    {
                        List <AnimUnitMove> currentStack = _creatureAnimations[tenant.UniqueID];
                        AnimUnitMove        current      = currentStack.Last();
                        current.Draw(spriteBatch, _screenAnchor, Color.White, _zoom);
                    }
                    // Otherwise, draw static sprite of the creature.
                    else
                    {
                        spriteBatch.Draw(_creatures[(sbyte)tenant.MyBitmap], rectCreature, Color.White);

                        //HP bar:
                        float   hpRatio     = (float)tenant.GetHP() / (float)tenant.GetHPMax();
                        Vector2 barLocation = pos;
                        barLocation.X += 3 * Constants.TileSize / 4;
                        barLocation.Y += (1 - hpRatio) * Constants.TileSize;
                        Color drawColor = Color.Lerp(Color.Red, Color.Green, hpRatio);
                        drawColor.A = 64;
                        spriteBatch.Draw(_particles[(sbyte)SpriteParticle.ParticlePixel], ZoomTransform(new Rectangle((int)barLocation.X,
                                                                                                                      (int)barLocation.Y, Constants.TileSize / 12, (int)(hpRatio * Constants.TileSize))), drawColor);
                    }
                }
            }
        }
예제 #5
0
 public Int32 DistanceTo(Coords c)
 {
     return(StaticMathFunctions.DistanceBetweenTwoCoordsHex(this, c));
 }