public P_MovementRangeLight(P_BattleMap battlemap, List <int> movementrange, IEntityActor actor) { _OldTime = (float)DateTime.Now.TimeOfDay.TotalMilliseconds; _Lag = 250; _Actor = actor; _Value = -1; _BattleMap = battlemap; _MovementRange = new List <int>(movementrange); _State = 1; _Rings = LightDist(battlemap, _MovementRange, actor); _Render = new PrototypeComponents.P_RenderComponent(); _Render.SizeX = _BattleMap.TheMap.Width * P_Const.TILE_WIDTH + 1; _Render.SizeY = _BattleMap.TheMap.Length / _BattleMap.TheMap.Width; _Render.OffsetBoss = _BattleMap; _Render.RenderLayer = RenderLayerEnum.Effects; _Render.LayerPriority = 51; _Render.BackgroundColor = ConsoleColor.Cyan; _Render.Visable = true; _Render.Graphic = new char[_Render.SizeX * _Render.SizeY]; for (int i = 0; i < _Render.Graphic.Length; i++) { _Render.Graphic[i] = P_Const.NULL_CHAR; } Active = true; }
public async Task <IHttpActionResult> GetEntityView(EntityTypes type, int businesskey) { var error = ""; var handler = HandlersFactory.GetProfilerHandler(TheSettingService); handler.Start(LOG_TAG, "GetEntityView", GetServiceProperties()); try { IActorLocationService actorLocator = ServiceFactory.GetActorLocationService(); IEntityActor entityActor = actorLocator.Create <IEntityActor>(new Entity(type, businesskey).GetPartitionKey(), Constants.ApplicationName); var entity = await entityActor.GetEntity(); var actorView = await entityActor.GetView(); var parent = entity.Parent; var parentView = new EntityView(); if (parent != null) { IEntityActor parentActor = actorLocator.Create <IEntityActor>(new Entity(parent.Type, parent.BusinessKey).GetPartitionKey(), Constants.ApplicationName); parentView = await parentActor.GetView(); } var children = await entityActor.GetChildren(); Dictionary <string, EntityView> childrenViews = new Dictionary <string, EntityView>(); foreach (var child in children) { IEntityActor childActor = actorLocator.Create <IEntityActor>(new Entity(child.Type, child.BusinessKey).GetPartitionKey(), Constants.ApplicationName); var childView = await childActor.GetView(); childrenViews.Add(child.Name, childView); } return(Ok(new { ParentName = parent != null ? parent.Name : "", ParentView = parent != null ? parentView : null, ThisView = actorView, ChildrenViews = childrenViews })); } catch (Exception ex) { error = ex.Message; return(BadRequest(ex.Message)); } finally { handler.Stop(error); } }
public void SetFactionActorsToNotMyTurn() { for (int i = 0; i < this.MapEntity.Count; i++) { IEntityActor dude = MapEntity[i] as IEntityActor; if (dude != null) { if (dude.Faction == ActiveFaction && dude.ActiveState == EntityCharacterState.Active) { dude.TurnStatus = EntityCharacterTurnStatus.NotMyTurn; } } } }
public P_BMSChose_Movement(P_BattleMap map, IEntityActor actor) { _Actor = actor; _Cursor = new P_SelectionCursor(actor.MyLocation); _Cursor.AcceptP_Render(map.Renderer); _CursorIndex = actor.MyTileIndex; _ValidMoveIndex = MovementRange(map, actor); _MoveLights = new P_MovementRangeLight(map, _ValidMoveIndex, actor); _MoveLights.AcceptP_Render(map.Renderer); _MoveLights.AcceptUpdater(map.Updater); map.MyState = this; }
public bool IsFactionTurnOver() { for (int i = 0; i < this.MapEntity.Count; i++) { IEntityActor dude = MapEntity[i] as IEntityActor; if (dude != null) { if (dude.Faction == ActiveFaction && dude.TurnStatus == EntityCharacterTurnStatus.MyTurn) { return(false); } } } return(true); }
private List <int> MovementRange(P_BattleMap battlemap, IEntityActor actor) { List <int> ReturnValue = new List <int>(); List <int> Check = new List <int>(); Check.Add(actor.MyTileIndex); while (Check.Count > 0) { List <int> NeighborsIndex = battlemap.TheMap.TileNeighborsIndex(Check[0]); for (int i = 0; i < NeighborsIndex.Count; i++) { if (Check.Contains(NeighborsIndex[i]) || ReturnValue.Contains(NeighborsIndex[i])) { continue; } if (battlemap.TheMap.MyTiles[NeighborsIndex[i]].IsTilePassable() == false) { continue; } if (battlemap.TheMap.MyTiles[NeighborsIndex[i]].EntityList.Count > 0) { continue; } List <P_CubeCoords> path = P_HexPath.GetPath(battlemap.TheMap, battlemap.TheMap.IndexToCube(NeighborsIndex[i]), battlemap.TheMap.IndexToCube(actor.MyTileIndex)); if (path.Count > actor.MovementPoints + 1) { continue; } Check.Add(NeighborsIndex[i]); } ReturnValue.Add(Check[0]); Check.RemoveAt(0); } return(ReturnValue); }
public void MoveActor(IEntityActor actor, int tileindex) { RemoveEntityFromTiles(actor); AddEntityToTile(actor, tileindex); }
// IRemindable Interface Implementation public async Task ReceiveReminderAsync(string reminderName, byte[] context, TimeSpan dueTime, TimeSpan period) { var error = ""; var handler = HandlersFactory.GetProfilerHandler(SettingService); handler.Start(LOG_TAG, "ReceiveReminderAsync", GetActorProperties()); try { handler.Info("Reminder " + reminderName); var state = await this.StateManager.GetStateAsync <EntityActorState>(ActorStatePropertyName); EntityTransaction transaction = (EntityTransaction)ByteArrayToObject(context); if (transaction == null) { handler.Info("Transaction is null"); } switch (reminderName) { case ReprocessReminder: { // Unregister the reminder so the actor will be garbage collected IActorReminder reminder = this.GetReminder(ReprocessReminder); await this.UnregisterReminderAsync(reminder); // Process this transaction if (transaction.TransactionType == TransactionTypes.Purchase) { state.Purchases++; state.SoldItems += transaction.SoldItems; state.Revenue += transaction.Revenue; state.Tax += transaction.Tax; state.Shipping += transaction.Shipping; } else if (transaction.TransactionType == TransactionTypes.Cancellation) { state.Cancellations++; state.SoldItems -= transaction.SoldItems; state.Revenue -= transaction.Revenue; state.Tax -= transaction.Tax; state.Shipping -= transaction.Shipping; } // Make sure the state is saved await SetEntityStateAsync(state); // Publish an event that we are done processing // Right now it is useless // It is an excercise to see how events work var ev = GetEvent <IEntityActorEvents>(); ev.MeasuresRecalculated(await GetEntity(), state.Purchases, state.Cancellations, state.SoldItems, state.Revenue, state.Tax, state.Shipping); // If available, process the parent var parent = await GetParent(); if (parent != null) { handler.Info("Parent actor type " + parent.Type); IEntityActor parentActor = ActorLocationService.Create <IEntityActor>(parent.GetPartitionKey(), ApplicationName); await parentActor.Process(transaction); } return; } default: { // We should never arrive here normally. The system won't call reminders that don't exist. // But for our own sake in case we add a new reminder somewhere and forget to handle it, this will remind us. handler.Info("Unknown reminder: " + reminderName); return; } } } catch (Exception ex) { error = ex.Message; } finally { handler.Stop(error); } }
public P_BMSChose_Faction_Actor(P_BattleMap map, IEntityActor actor) { map.MyState = this; }
private static List <List <int> > LightDist(P_BattleMap battlemap, List <int> moverange, IEntityActor actor) { List <List <int> > ReturnValue = new List <List <int> >(); for (int i = 0; i <= actor.MovementPoints + 1; i++) { List <int> Range = new List <int>(); for (int j = 0; j < moverange.Count; j++) { if (P_HexPath.GetPath(battlemap.TheMap, battlemap.TheMap.IndexToCube(actor.MyTileIndex), battlemap.TheMap.IndexToCube(moverange[j])).Count == i) { Range.Add(moverange[j]); } } for (int j = 0; j < Range.Count; j++) { moverange.Remove(Range[j]); } ReturnValue.Add(Range); } for (int i = 0; i < ReturnValue.Count; i++) { for (int j = 0; j < ReturnValue[j].Count; j++) { moverange.Add(ReturnValue[i][j]); } } return(ReturnValue); }
private static List <List <int> > LightRings(P_BattleMap battlemap, List <int> moverange, IEntityActor actor) { List <List <int> > ReturnValue = new List <List <int> >(); for (int i = 0; i <= actor.MovementPoints; i++) { List <P_CubeCoords> foo = GetRing(battlemap.TheMap.IndexToCube(actor.MyTileIndex), i); List <int> bar = new List <int>(); for (int j = 0; j < foo.Count; j++) { int fuk = battlemap.TheMap.CubeToIndex(foo[j]); if (moverange.Contains(fuk)) { bar.Add(fuk); } } ReturnValue.Add(bar); } return(ReturnValue); }
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { // Gets (or creates) a replicated dictionary called "myDictionary" in this partition. var requests = await this.StateManager.GetOrAddAsync <IReliableQueue <EntityTransaction> >(ProcessQueueName); try { // This partition's replica continues processing until the replica is terminated. while (!cancellationToken.IsCancellationRequested) { using (var tx = this.StateManager.CreateTransaction()) { var result = await requests.TryDequeueAsync(tx, TxTimeout, cancellationToken); if (result.HasValue) { var error = ""; var handler = HandlersFactory.GetProfilerHandler(SettingService); handler.Start(LOG_TAG, "AcquiredQueueItem", GetServiceProperties()); try { EntityTransaction transaction = result.Value; handler.Info("Acquired item business key: " + transaction.BusinessKey + " - entity type: " + transaction.EntityType); IActorLocationService locator = ServiceFactory.GetActorLocationService(); IEntityActor entityActor = locator.Create <IEntityActor>(new Entity(transaction.EntityType, transaction.BusinessKey).GetPartitionKey(), Constants.ApplicationName); await entityActor.SubscribeAsync <IEntityActorEvents>(this); await entityActor.Process(transaction); } catch (Exception ex) { error = ex.Message; } finally { handler.Stop(error); } } // This commits the dequeue operations. // If the request to add the stock to the inventory service throws, this commit will not execute // and the items will remain on the queue, so we can be sure that we didn't dequeue items // that didn't get saved successfully in the inventory service. // However there is a very small chance that the stock was added to the inventory service successfully, // but service execution stopped before reaching this commit (machine crash, for example). await tx.CommitAsync(); } // Pause for 2 second before continue processing. await Task.Delay(TimeSpan.FromSeconds(2), cancellationToken); } } catch (Exception ex) { } // Pause for 1 second before continue processing. await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken); }