protected void InitializeTileRelated(ISpaceRouteElement element) { Location = element; watchAroungOrigin = element.Tile; LiveAsync(); }
public IEnumerable <ISpaceRouteElement> GetToNeighbour(ISpaceRouteElement location, ITile targetTile, bool useFullSpaces) { var moveDirection = location.Tile.Neighbors.Single(t => t.Item1 == targetTile).Item2; var currentSpace = location.Space; //currentTile.LayoutManager.FindCurrentSpace(entity); var curTileBridges = AllSpaces .Where(s => s.Sides.Contains(moveDirection)) .Where(s => s == currentSpace || useFullSpaces || location.Tile.LayoutManager.IsFree(s)); var targetTileBridges = AllSpaces .Where(s => s.Sides.Contains(moveDirection.Opposite)) .Where(s => useFullSpaces || targetTile.LayoutManager.IsFree(s)); var bridges = curTileBridges.Join(targetTileBridges, ospace => ospace.Sides.First(s => s != moveDirection), ispace => ispace.Sides.First(s => s != moveDirection.Opposite), Tuple.Create); var bridgesRoutes = bridges .Select(b => GetToSpace(location, b.Item1, useFullSpaces)?.Concat(new FourthSpaceRouteElement(b.Item2, targetTile).ToEnumerable()).ToArray()) .Where(r => r != null) .ToArray(); if (bridgesRoutes.Any()) { var minLen = bridgesRoutes.Min(x => x.Length); return(bridgesRoutes.First(br => br.Length == minLen)); } else { return(null); } }
public override async Task <bool> MoveToAsync(ISpaceRouteElement newLocation) { var b = base.MoveToAsync(newLocation); var p = MovePartyAsync(newLocation.Tile); await Task.WhenAll(p, b); return(true); }
public override async Task <bool> MoveToAsync(ISpaceRouteElement newLocation) { if (location == newLocation) { throw new InvalidOperationException("Cannot move from space to itself."); } bool alreadyOnTile = location?.Tile == newLocation.Tile; bool differentLevel = location?.Tile?.Level != newLocation?.Tile?.Level; if (animator.IsAnimating) { animator.AbortFinishAsync(); } if (!newLocation.Tile.LayoutManager.TryGetSpace(this, newLocation.Space)) { return(false); } //following line is done by animator itself //Position = newLocation.StayPoint; location?.Tile.LayoutManager.FreeSpace(this, location.Space); await animator.MoveToAsync(this, newLocation, false); if (!alreadyOnTile) { location?.Tile?.OnObjectLeft(this); if (differentLevel) { location?.Tile?.Level?.Updateables.Remove(this); } } location = newLocation; if (!alreadyOnTile) { location?.Tile?.OnObjectEntered(this); if (differentLevel) { location?.Tile?.Level?.Updateables.Add(this); } } //move following line before animation start in order to let creatures //move more consistently //location?.Tile.LayoutManager.FreeSpace(this, location.Space); return(true); }
public async void MoveToWithoutFree(ISpaceRouteElement newLocation, bool setNewLocation) { if (!newLocation.Tile.LayoutManager.TryGetSpace(this, newLocation.Space)) { throw new InvalidOperationException("cannot reserve the space"); } await animator.MoveToAsync(this, newLocation, false); if (setNewLocation) { location = newLocation; } }
private async Task <bool> MoveToSpace(ISpaceRouteElement destination) { if (destination.Tile.LayoutManager.TryGetSpace(this, destination.Space)) { //free previous location location?.Tile.LayoutManager.FreeSpace(this, location.Space); await animator.MoveToAsync(this, destination, setLocation : true); return(true); } else { return(false); } }
public override async Task <bool> MoveToAsync(ISpaceRouteElement newLocation) { if (!newLocation.Tile.LayoutManager.TryGetSpace(this, newLocation.Space)) { return(false);//throw new InvalidOperationException("cannot reserve the space"); } if (!await animator.MoveToAsync(this, newLocation, false)) { newLocation.Tile.LayoutManager.FreeSpace(this, newLocation.Space); return(false); } location.Tile.LayoutManager.FreeSpace(this, location.Space); location = newLocation; return(true); }
protected override bool TryApplyBeforeMoving(ISpaceRouteElement newLocation) { if (!newLocation.Tile.IsAccessible) { var doors = newLocation.Tile as IHasEntity; if (doors != null) { var L0488_i_Attack = Impact.GetImpact(this); L0488_i_Attack.Attack++; SwingAttack.F232_dzzz_GROUP_IsDoorDestroyedByAttack(doors.Entity, L0488_i_Attack.Attack + rand.Next(L0488_i_Attack.Attack), Impact.IsMagic); } return(true); } return(F217_xxxx_PROJECTILE_HasImpactOccured(newLocation)); }
bool F217_xxxx_PROJECTILE_HasImpactOccured(ISpaceRouteElement newLocation) { //potionException(L0486_T_ProjectileAssociatedThing, ref L0491_ps_Group, ref L0492_ps_Potion, ref L0498_T_ExplosionThing, ref L0508_i_PotionPower, ref L0509_B_RemovePotion, L0510_i_ProjectileAssociatedThingType); var matchingEnemies = Location.Tile.LayoutManager.GetEntities(Location.Space).ToArray(); if (matchingEnemies.Length == 0) { return(false); } var closestSpace = GetClosestSpace(Location, matchingEnemies.Select(x => x.Location)); //var enemy = matchingEnemies.First(x => x.Location == closestSpace); ILiveEntity enemy; if (closestSpace != null) { enemy = Location.Tile.LayoutManager.GetEntities(closestSpace.Space).First(); //matchingEnemies.First(x => x.Location == closestSpace); } else if (Location.Tile.LayoutManager.Entities.Any()) { enemy = Location.Tile.LayoutManager.Entities.First(); } else { return(false); } AttackInfo impact = Impact.GetImpact(this); int L0488_i_Attack = (impact.Attack << 6) / (enemy.GetProperty(PropertyFactory <DefenseProperty> .Instance).Value + 1); //TODO remove +1, it is just to avoid division by zero exception if (L0488_i_Attack > 0) { int adjustedPoisonEffect = F192_ayzz_GROUP_GetResistanceAdjustedPoisonAttack(enemy, impact.PoisonAttack); var health = enemy.GetProperty(PropertyFactory <HealthProperty> .Instance); health.Value -= L0488_i_Attack + adjustedPoisonEffect; // TODO itemAbsorbtion(); } //TODO champions //L0488_i_Attack = F216_xxxx_PROJECTILE_GetImpactAttack(L0490_ps_Projectile, L0486_T_ProjectileAssociatedThing); //if (L0489_i_ChampionAttack && F321_AA29_CHAMPION_AddPendingDamageAndWounds_GetDamage(AP456_i_ChampionIndex, L0488_i_Attack, MASK0x0004_HEAD | MASK0x0008_TORSO, G367_i_ProjectileAttackType) && G366_i_ProjectilePoisonAttack && M05_RANDOM(2)) // F322_lzzz_CHAMPION_Poison(AP456_i_ChampionIndex, G366_i_ProjectilePoisonAttack); return(true); }
public IEnumerable <ISpaceRouteElement> GetToSide(ISpaceRouteElement location, MapDirection mapDirection, bool useFullSpaces) { ISpace currentSpace = location.Space;// currentTile.LayoutManager.FindCurrentSpace(entity); ISpace destSpace = null; searcher.LayoutManager = useFullSpaces ? null : location.Tile.LayoutManager; searcher.StartSearch(AllSpaces.First(), currentSpace, 1, (space, layer, bundle) => { if (space.Sides.Any(x => x == mapDirection)) { searcher.StopSearch(); destSpace = space; } }); return(destSpace != null?searcher.GetShortestRoute(destSpace).Select(s => new FourthSpaceRouteElement(s, location.Tile)) : null); }
protected override bool TryApplyBeforeMoving(ISpaceRouteElement newLocation) { var doorTile = Location.Tile as DoorTile; if (doorTile != null) { if (doorTile.HasButton && !doorTile.Door.Open) { doorTile.ActivateTileContent(); } return(true); } else { return(false); } }
public Creature(IGroupLayout layout, ISpaceRouteElement location, RelationToken relationToken, IEnumerable <RelationToken> enemiesTokens, int moveDuration, int detectRange, int sightRange) : base(location.StayPoint) { GroupLayout = layout; MoveDuration = moveDuration; DetectRange = detectRange; SightRange = sightRange; watchAroungOrigin = location.Tile; if (!location.Tile.LayoutManager.TryGetSpace(this, location.Space)) { throw new ArgumentException("Location is not accessable!"); } ((ILocalizable <ISpaceRouteElement>) this).Location = location; RelationManager = new DefaultRelationManager(relationToken, enemiesTokens); ((CubeGraphic)Graphics).Texture = ResourceProvider.Instance.DrawRenderTarget("creature", Color.Red, Color.White); }
private void Kill() { Activated = false; Died?.Invoke(this, this); location.Tile.LayoutManager.FreeSpace(this, location.Space); foreach (var storage in Body.Storages) { for (int i = 0; i < storage.Storage.Count; i++) { var item = storage.TakeItemFrom(i); if (item != null) { item.Location = GroupLayout.GetSpaceElement(Location.Space, location.Tile); } } } bones.Location = GroupLayout.GetSpaceElement(Location.Space, location.Tile); location = null; }
protected virtual async Task <bool> MoveToSpace(ISpaceRouteElement destination) { //something stole control to creature, i.e. falling to pit if (animator.IsAnimating) { //wait until finish move await animator.AnimatingTask; //reset movement return(false); } bool EnemyAtTile = destination.Tile.LayoutManager.Entities.Any(x => RelationManager.IsEnemy(x.RelationManager.RelationToken)); if (Activated && destination.Tile.IsAccessible && !EnemyAtTile) { return(await MoveToAsync(destination)); } else { return(false); } }
private IEnumerable <ISpaceRouteElement> GetToSpace(ISpaceRouteElement location, ISpace destSpace, bool useFullSpaces) { bool found = false; ISpace currentSpace = location.Space; //currentTile.LayoutManager.FindCurrentSpace(entity); if (currentSpace == destSpace) { return(new FourthSpaceRouteElement(currentSpace, location.Tile).ToEnumerable()); } searcher.LayoutManager = useFullSpaces ? null : location.Tile.LayoutManager; searcher.StartSearch(AllSpaces.First(), currentSpace, 1, (space, layer, bundle) => { if (space == destSpace) { searcher.StopSearch(); found = true; } }); return(found ? searcher.GetShortestRoute(destSpace).Select(s => new FourthSpaceRouteElement(s, location.Tile)) : null); }
public IEnumerable <ISpaceRouteElement> GetToSide(ISpaceRouteElement currentTile, MapDirection mapDirection, bool useFullSpaces) { throw new NotImplementedException(); }
private async Task<bool> MoveToSpace(ISpaceRouteElement destination) { if (destination.Tile.LayoutManager.TryGetSpace(this, destination.Space)) { //free previous location location?.Tile.LayoutManager.FreeSpace(this, location.Space); await animator.MoveToAsync(this, destination, setLocation: true); return true; } else return false; }
public override async void MoveTo(ISpaceRouteElement newLocation) { await MoveToAsync(newLocation); }
public Creature(IGroupLayout layout, ISpaceRouteElement location, RelationToken relationToken, IEnumerable<RelationToken> enemiesTokens, int moveDuration, int detectRange, int sightRange) : base(location.StayPoint) { GroupLayout = layout; MoveDuration = moveDuration; DetectRange = detectRange; SightRange = sightRange; watchAroungOrigin = location.Tile; if (!location.Tile.LayoutManager.TryGetSpace(this, location.Space)) throw new ArgumentException("Location is not accessable!"); ((ILocalizable<ISpaceRouteElement>)this).Location = location; RelationManager = new DefaultRelationManager(relationToken, enemiesTokens); ((CubeGraphic) Graphics).Texture = ResourceProvider.Instance.DrawRenderTarget("creature", Color.Red, Color.White); }
public IEnumerable <ISpaceRouteElement> GetToNeighbour(ISpaceRouteElement location, ITile targetTile, bool useFullSpaces) { return(AllSpaces.Select(x => new OnethSpaceRouteElement(x, location.Tile))); }
public IEnumerable <ISpaceRouteElement> GetToSide(ISpaceRouteElement location, MapDirection mapDirection, bool useFullSpaces) { return(AllSpaces.Select(x => new OnethSpaceRouteElement(x, location.Tile))); }
public abstract void MoveTo(ISpaceRouteElement newLocation);
public abstract Task <bool> MoveToAsync(ISpaceRouteElement newLocation);
public IEnumerable <ISpaceRouteElement> GetToNeighbour(ISpaceRouteElement location, ITile targetTile, bool useFullSpaces) { throw new NotImplementedException(); }
public void SetLocationNoEvents(ISpaceRouteElement tile) { location = tile; }