public override void Update() { // have agent update move space to be safe _owner.MyMoveRangeCalculator.Update(); // careful with this loop while ((_owner as Creature).GetAP() > 0) { // if no enemies in sight, engage in idle behavior if (base._observedEnemies.Count == 0) { // idle behavior Coords goal = RandomAccessibleHex(_owner.MyMoveRangeCalculator); if (goal != _owner.PositionGet()) { Action goSomewhere = new ActionMove((_owner as Creature), _owner.MyMoveRangeCalculator.RetrieveRoute(goal), _owner.MyMoveRangeCalculator.Cost(goal), _drawer); goSomewhere.Execute(); } return; } // if enemy in range, attack Creature potentialTarget = EnemyNearest(); float range = (_owner as Creature).GetAttackRange(); if (potentialTarget.PositionGet().DistanceTo(_owner.PositionGet()) <= (_owner as Creature).GetAttackRange()) { UInt16 ap = (_owner as Creature).GetAP(); if ((_owner as Creature).GetAP() > (_owner as Creature).SpellCurrent.ExecutionTime) { Action attack = new ActionUseSpell(_owner as Creature, (_owner as Creature).SpellCurrent, potentialTarget.PositionGet()); attack.Execute(); } else { // not enough AP. end turn. return; } } else { Coords goal = NearestAcessibleHex(potentialTarget.PositionGet(), _owner.MyMoveRangeCalculator); if (goal != _owner.PositionGet()) { Action goToAction = new ActionMove(_owner, _owner.MyMoveRangeCalculator.RetrieveRoute(goal), _owner.MyMoveRangeCalculator.Cost(goal), _drawer); goToAction.Execute(); } else { return; } } // no enemy in range - approach nearest enemy } }
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); } } } }
private void HandlerMouse_LeftButton_GeneralArea(MouseState mouse) { // try to drop selected item if (_itemSelected != null) { Tile tileUnderAgent = _currentMap.GetTile(_selectedCreature.PositionGet()); if (!tileUnderAgent.MyInventory.Full() && _selectedCreature.GetStatBasic(Creature.StatBasic.AP, true) >= _selectedCreature.GetAPActionCost(APCostTypes.ItemDrop)) { // drop item //tileUnderAgent.MyInventory.ItemAddToList(_selectedItem); ActionItemDrop action = new ActionItemDrop(_selectedCreature, _itemSelected); _myGame.ExecuteAction(action); _itemSelected = null; } } // try to select tenant else { Coords selectedHex = ClickedHex(new Vector2(mouse.X, mouse.Y), _myDrawer.ScreenAnchor); _selectedCreature = _currentMap.TenancyMap[selectedHex.X, selectedHex.Y]; if (_selectedCreature != null) { _selectedCreature.MyMoveRangeCalculator.Update(); } } }
// returns the item's position (in Coords) public Nullable <Coords> Position() { Nullable <Coords> returnValue = null; if (this._ownerTile != null) { returnValue = _ownerTile.Position; } else if (this._ownerCreature != null) { returnValue = _ownerCreature.PositionGet(); } return(returnValue); }
private Creature EnemyNearest() { if (_observedEnemies.Count == 0) { return(null); } Creature nearestEnemy = _observedEnemies[0] as Creature; Int32 nearestDistance = nearestEnemy.PositionGet().DistanceTo(_owner.PositionGet()); for (int i = 1; i < _observedEnemies.Count; ++i) { Creature currentEnemy = _observedEnemies[i] as Creature; Int32 currentDistance = currentEnemy.PositionGet().DistanceTo(_owner.PositionGet()); if (currentDistance < nearestDistance) { nearestDistance = currentDistance; nearestEnemy = currentEnemy; } } return(nearestEnemy); }
public void Update() { CalculateMoveRange(_owner.PositionGet(), _owner.APMoveCosts, _owner.GetAP()); }