protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings electionTimeoutDict = new ActionBindings(); electionTimeoutDict.Add(typeof(eQueryElectionTimeout), new Action(CheckElectionTimeout)); electionTimeoutDict.Add(typeof(eStop), new Action(Stop)); ActionBindings heartBeatingDict = new ActionBindings(); heartBeatingDict.Add(typeof(eQueryHeartBeating), new Action(CheckHeartBeat)); heartBeatingDict.Add(typeof(eStop), new Action(Stop)); ActionBindings clientTimeoutDict = new ActionBindings(); clientTimeoutDict.Add(typeof(eQueryClientTimeout), new Action(CheckClientTimeout)); clientTimeoutDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(ElectionTimeout), electionTimeoutDict); dict.Add(typeof(HeartBeating), heartBeatingDict); dict.Add(typeof(ClientTimeout), clientTimeoutDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings invalidDict = new ActionBindings(); invalidDict.Add(typeof(eStop), new Action(Stop)); ActionBindings invalidWaitingDict = new ActionBindings(); invalidWaitingDict.Add(typeof(eStop), new Action(Stop)); ActionBindings sharingDict = new ActionBindings(); sharingDict.Add(typeof(eStop), new Action(Stop)); sharingDict.Add(typeof(eAskShare), new Action(Ack)); ActionBindings shareWaitingDict = new ActionBindings(); shareWaitingDict.Add(typeof(eStop), new Action(Stop)); ActionBindings exclusiveDict = new ActionBindings(); exclusiveDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Invalid), invalidDict); dict.Add(typeof(InvalidWaiting), invalidWaitingDict); dict.Add(typeof(Sharing), sharingDict); dict.Add(typeof(ShareWaiting), shareWaitingDict); dict.Add(typeof(Exclusive), exclusiveDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings joiningDict = new ActionBindings(); joiningDict.Add(typeof(eQueryId), new Action(SendId)); ActionBindings waitingDict = new ActionBindings(); waitingDict.Add(typeof(eQueryId), new Action(SendId)); waitingDict.Add(typeof(eStabilize), new Action(Stabilize)); waitingDict.Add(typeof(eFindPredecessor), new Action(SendPredecessor)); waitingDict.Add(typeof(eFindSuccessor), new Action(FindSuccessor)); waitingDict.Add(typeof(eFindSuccessorResp), new Action(SuccessorFound)); waitingDict.Add(typeof(eNotifySuccessor), new Action(UpdatePredecessor)); waitingDict.Add(typeof(eFindPredecessorResp), new Action(UpdateSuccessor)); waitingDict.Add(typeof(eAskForKeys), new Action(SendCorrespondingKeys)); waitingDict.Add(typeof(eAskForKeysAck), new Action(UpdateKeys)); waitingDict.Add(typeof(eFail), new Action(Failing)); waitingDict.Add(typeof(eStop), new Action(Stopping)); dict.Add(typeof(Joining), joiningDict); dict.Add(typeof(Waiting), waitingDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings activeDict = new ActionBindings(); activeDict.Add(typeof(eCreateAccount), new Action(CreateAccount)); activeDict.Add(typeof(eCloseAccount), new Action(CloseAccount)); activeDict.Add(typeof(eWithdraw), new Action(Withdraw)); activeDict.Add(typeof(eDeposit), new Action(Deposit)); activeDict.Add(typeof(eTransfer), new Action(Transfer)); activeDict.Add(typeof(eBalanceInquiry), new Action(BalanceInquiry)); activeDict.Add(typeof(eUnlock), new Action(UnlockAccount)); activeDict.Add(typeof(eLock), new Action(LockAccount)); activeDict.Add(typeof(eStop), new Action(Stop)); ActionBindings waitingAccountToCloseDict = new ActionBindings(); waitingAccountToCloseDict.Add(typeof(eCloseAck), new Action(CloseAccountAck)); dict.Add(typeof(Active), activeDict); dict.Add(typeof(WaitingAccountToClose), waitingAccountToCloseDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings checkValueProposedDict = new ActionBindings(); checkValueProposedDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(CheckValueProposed), checkValueProposedDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings sendLeaderDict = new ActionBindings(); sendLeaderDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(SendLeader), sendLeaderDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings timerStartedDict = new ActionBindings(); timerStartedDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(TimerStarted), timerStartedDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings syncDict = new ActionBindings(); syncDict.Add(typeof(eReq), new Action(CountReq)); syncDict.Add(typeof(eDone), new Action(CheckIfDone)); dict.Add(typeof(Sync), syncDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings activeDict = new ActionBindings(); activeDict.Add(typeof(eBoot), new Action(Boot)); activeDict.Add(typeof(eSum), new Action(Sum)); dict.Add(typeof(Active), activeDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings waitingDict = new ActionBindings(); waitingDict.Add(typeof(eFindSuccessor), new Action(FindSuccessor)); waitingDict.Add(typeof(eJoinAck), new Action(QueryStabilize)); dict.Add(typeof(Waiting), waitingDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings activeDict = new ActionBindings(); activeDict.Add(typeof(eIntervals), new Action(Intervals)); activeDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Active), activeDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings waitDict = new ActionBindings(); waitDict.Add(typeof(ePrepare), new Action(Prepare)); waitDict.Add(typeof(eAccept), new Action(Accept)); waitDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Wait), waitDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings waitingDict = new ActionBindings(); waitingDict.Add(typeof(eQueryIdResp), new Action(ReceiveSuccessorId)); waitingDict.Add(typeof(eFindSuccessorResp), new Action(SuccessorFound)); waitingDict.Add(typeof(eStop), new Action(Stopping)); dict.Add(typeof(Waiting), waitingDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings loopDict = new ActionBindings(); loopDict.Add(typeof(eGLOBAL_ABORT), new Action(HandleGlobalAbort)); loopDict.Add(typeof(eGLOBAL_COMMIT), new Action(HandleGlobalCommit)); loopDict.Add(typeof(eREQ_REPLICA), new Action(HandleReqReplica)); dict.Add(typeof(Loop), loopDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings waitDict = new ActionBindings(); waitDict.Add(typeof(eMonitorClientSent), new Action(AddClientSet)); waitDict.Add(typeof(eMonitorProposerSent), new Action(AddProposerSet)); waitDict.Add(typeof(eMonitorProposerChosen), new Action(CheckChosenValidity)); waitDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Wait), waitDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings initDict = new ActionBindings(); initDict.Add(typeof(eMONITOR_WRITE), new Action(DoWrite)); initDict.Add(typeof(eMONITOR_READ_SUCCESS), new Action(CheckReadSuccess)); initDict.Add(typeof(eMONITOR_READ_UNAVAILABLE), new Action(CheckReadUnavailable)); initDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Init), initDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings queryingDict = new ActionBindings(); queryingDict.Add(typeof(eClientTimedOut), new Action(SendNewQuery)); queryingDict.Add(typeof(eClientHasNotTimedOut), new Action(QueryClientTimeout)); queryingDict.Add(typeof(eClientReqAck), new Action(ProcessesResponse)); queryingDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Querying), queryingDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings activeDict = new ActionBindings(); activeDict.Add(typeof(eWithdraw), new Action(Withdraw)); activeDict.Add(typeof(eDeposit), new Action(Deposit)); activeDict.Add(typeof(eTransfer), new Action(Transfer)); activeDict.Add(typeof(eBalanceInquiry), new Action(BalanceInquiry)); activeDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Active), activeDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings startingDict = new ActionBindings(); startingDict.Add(typeof(eHook), new Action(Hook)); startingDict.Add(typeof(eGetNumber), new Action(GetNumber)); startingDict.Add(typeof(eGetCount), new Action(GetCount)); startingDict.Add(typeof(eGetString), new Action(GetString)); startingDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Starting), startingDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings runningDict = new ActionBindings(); runningDict.Add(typeof(eRequestVote), new Action(PropagateVote)); runningDict.Add(typeof(eRequestVoteAck), new Action(PropagateVoteAck)); runningDict.Add(typeof(eClientReq), new Action(PropagateClientRequest)); runningDict.Add(typeof(eAppendEntriesAck), new Action(PropagateAppendEntriesAck)); runningDict.Add(typeof(eUpdateLeader), new Action(UpdateLeader)); dict.Add(typeof(Running), runningDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings loopDict = new ActionBindings(); loopDict.Add(typeof(eStop), new Action(Stop)); ActionBindings startedDict = new ActionBindings(); startedDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Loop), loopDict); dict.Add(typeof(Started), startedDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings proposeValuePhase1Dict = new ActionBindings(); proposeValuePhase1Dict.Add(typeof(eAgree), new Action(CheckCountAgree)); ActionBindings proposeValuePhase2Dict = new ActionBindings(); proposeValuePhase2Dict.Add(typeof(eAccepted), new Action(CheckCountAccepted)); dict.Add(typeof(ProposeValuePhase1), proposeValuePhase1Dict); dict.Add(typeof(ProposeValuePhase2), proposeValuePhase2Dict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings receivingDict = new ActionBindings(); receivingDict.Add(typeof(eStop), new Action(Stop)); ActionBindings checkingInvariantDict = new ActionBindings(); checkingInvariantDict.Add(typeof(eInvalidateAck), new Action(RecAck)); dict.Add(typeof(Receiving), receivingDict); dict.Add(typeof(CheckingInvariant), checkingInvariantDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings initDict = new ActionBindings(); initDict.Add(typeof(eInit), new Action(InitAction)); ActionBindings sendCountDict = new ActionBindings(); sendCountDict.Add(typeof(eMyCount), new Action(ConfirmThatInSync)); dict.Add(typeof(Init), initDict); dict.Add(typeof(SendCount), sendCountDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings loopDict = new ActionBindings(); loopDict.Add(typeof(eWRITE_REQ), new Action(DoWrite)); loopDict.Add(typeof(eREAD_REQ), new Action(DoRead)); ActionBindings countVoteDict = new ActionBindings(); countVoteDict.Add(typeof(eREAD_REQ), new Action(DoRead)); countVoteDict.Add(typeof(eRESP_REPLICA_ABORT), new Action(HandleAbort)); dict.Add(typeof(Loop), loopDict); dict.Add(typeof(CountVote), countVoteDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings initDict = new ActionBindings(); initDict.Add(typeof(eAllNodes), new Action(UpdateAcceptors)); // Action bindings for PerformOperation ActionBindings performOperationDict = new ActionBindings(); // Proposer performOperationDict.Add(typeof(eUpdate), new Action(CheckIfLeader)); // Acceptor performOperationDict.Add(typeof(ePrepare), new Action(Prepare)); performOperationDict.Add(typeof(eAccept), new Action(Accept)); // Leader Election performOperationDict.Add(typeof(ePing), new Action(ForwardToLE)); performOperationDict.Add(typeof(eNewLeader), new Action(UpdateLeader)); performOperationDict.Add(typeof(eStop), new Action(Stop)); // Action bindings for ProposeValuePhase1 ActionBindings proposeValuePhase1Dict = new ActionBindings(); proposeValuePhase1Dict.Add(typeof(eAgree), new Action(CheckCountAgree)); proposeValuePhase1Dict.Add(typeof(ePrepare), new Action(Prepare)); // Action bindings for ProposeValuePhase2 ActionBindings proposeValuePhase2Dict = new ActionBindings(); proposeValuePhase2Dict.Add(typeof(eAccepted), new Action(CheckCountAccepted)); proposeValuePhase2Dict.Add(typeof(eAccept), new Action(Accept)); dict.Add(typeof(Init), initDict); dict.Add(typeof(PerformOperation), performOperationDict); dict.Add(typeof(ProposeValuePhase1), proposeValuePhase1Dict); dict.Add(typeof(ProposeValuePhase2), proposeValuePhase2Dict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings bootingDict = new ActionBindings(); bootingDict.Add(typeof(eHook), new Action(Hook)); bootingDict.Add(typeof(eGetCountAck), new Action(ProcessPostRoundResults)); bootingDict.Add(typeof(eGetStringAck), new Action(HandleGetStringAck)); bootingDict.Add(typeof(eGetNumberAck), new Action(HandleGetNumberAck)); ActionBindings secondRoundDict = new ActionBindings(); secondRoundDict.Add(typeof(eHook), new Action(Hook)); secondRoundDict.Add(typeof(eGetCountAck), new Action(ProcessPostRoundResults)); secondRoundDict.Add(typeof(eGetStringAck), new Action(HandleGetStringAck)); secondRoundDict.Add(typeof(eGetNumberAck), new Action(HandleGetNumberAck)); dict.Add(typeof(Booting), bootingDict); dict.Add(typeof(SecondRound), secondRoundDict); return(dict); }
protected override Dictionary <Type, ActionBindings> DefineActionBindings() { Dictionary <Type, ActionBindings> dict = new Dictionary <Type, ActionBindings>(); ActionBindings followerDict = new ActionBindings(); followerDict.Add(typeof(eElectionTimedOut), new Action(ProcessElectionTimeout)); followerDict.Add(typeof(eElectionHasNotTimedOut), new Action(QueryElectionTimeout)); followerDict.Add(typeof(eRequestVote), new Action(ProcessVote)); followerDict.Add(typeof(eAppendEntries), new Action(ProcessAppendEntries)); followerDict.Add(typeof(eStop), new Action(Stop)); ActionBindings candidateDict = new ActionBindings(); candidateDict.Add(typeof(eElectionTimedOut), new Action(ProcessElectionTimeout)); candidateDict.Add(typeof(eElectionHasNotTimedOut), new Action(QueryElectionTimeout)); candidateDict.Add(typeof(eRequestVote), new Action(ProcessVote)); candidateDict.Add(typeof(eRequestVoteAck), new Action(ProcessVoteAck)); candidateDict.Add(typeof(eAppendEntries), new Action(ProcessAppendEntries)); candidateDict.Add(typeof(eStop), new Action(Stop)); ActionBindings leaderDict = new ActionBindings(); leaderDict.Add(typeof(eSendHeartBeat), new Action(ProcessHeartBeat)); leaderDict.Add(typeof(eDoNotSendHeartBeat), new Action(QueryHeartBeat)); leaderDict.Add(typeof(eAppendEntries), new Action(ProcessAppendEntries)); leaderDict.Add(typeof(eAppendEntriesAck), new Action(ProcessAppendEntriesAck)); leaderDict.Add(typeof(eClientReq), new Action(ProcessClientReq)); leaderDict.Add(typeof(eUpdateLeader), new Action(UpdateLeaderInformation)); leaderDict.Add(typeof(eStop), new Action(Stop)); dict.Add(typeof(Follower), followerDict); dict.Add(typeof(Candidate), candidateDict); dict.Add(typeof(Leader), leaderDict); return(dict); }
/// <summary> /// Configures the state transitions of the monitor. /// </summary> /// <param name="state">State</param> private void ConfigureStateTransitions(MonitorState state) { this.GotoTransitions = state.GotoTransitions; this.ActionBindings = state.ActionBindings; this.IgnoredEvents = state.IgnoredEvents; }
/// <summary> /// Initializes the state. /// <param name="monitor">Monitor</param> /// <param name="isHot">Is hot</param> /// <param name="isCold">Is cold</param> internal void InitializeState(Monitor monitor, bool isHot, bool isCold) { this.Monitor = monitor; this.IsHot = isHot; this.IsCold = isCold; this.GotoTransitions = new GotoStateTransitions(); this.ActionBindings = new ActionBindings(); this.IgnoredEvents = new HashSet<Type>(); var entryAttribute = this.GetType().GetCustomAttribute(typeof(OnEntry), false) as OnEntry; var exitAttribute = this.GetType().GetCustomAttribute(typeof(OnExit), false) as OnExit; if (entryAttribute != null) { var method = this.Monitor.GetType().GetMethod(entryAttribute.Action, BindingFlags.NonPublic | BindingFlags.Instance); var action = (Action)Delegate.CreateDelegate(typeof(Action), this.Monitor, method); this.EntryAction = action; } if (exitAttribute != null) { var method = this.Monitor.GetType().GetMethod(exitAttribute.Action, BindingFlags.NonPublic | BindingFlags.Instance); var action = (Action)Delegate.CreateDelegate(typeof(Action), this.Monitor, method); this.ExitAction = action; } var gotoAttributes = this.GetType().GetCustomAttributes(typeof(OnEventGotoState), false) as OnEventGotoState[]; var doAttributes = this.GetType().GetCustomAttributes(typeof(OnEventDoAction), false) as OnEventDoAction[]; foreach (var attr in gotoAttributes) { if (attr.Action == null) { this.GotoTransitions.Add(attr.Event, attr.State); } else { var method = this.Monitor.GetType().GetMethod(attr.Action, BindingFlags.NonPublic | BindingFlags.Instance); var action = (Action)Delegate.CreateDelegate(typeof(Action), this.Monitor, method); this.GotoTransitions.Add(attr.Event, attr.State, action); } } foreach (var attr in doAttributes) { var method = this.Monitor.GetType().GetMethod(attr.Action, BindingFlags.NonPublic | BindingFlags.Instance); var action = (Action)Delegate.CreateDelegate(typeof(Action), this.Monitor, method); this.ActionBindings.Add(attr.Event, action); } var ignoreEventsAttribute = this.GetType().GetCustomAttribute(typeof(IgnoreEvents), false) as IgnoreEvents; if (ignoreEventsAttribute != null) { this.IgnoredEvents.UnionWith(ignoreEventsAttribute.Events); } }
/// <summary> /// Initializes the state. /// </summary> internal void InitializeState() { this.IsStart = false; this.GotoTransitions = new GotoStateTransitions(); this.PushTransitions = new PushStateTransitions(); this.ActionBindings = new ActionBindings(); this.IgnoredEvents = new HashSet<Type>(); this.DeferredEvents = new HashSet<Type>(); var entryAttribute = this.GetType().GetCustomAttribute(typeof(OnEntry), false) as OnEntry; var exitAttribute = this.GetType().GetCustomAttribute(typeof(OnExit), false) as OnExit; if (entryAttribute != null) { this.EntryAction = entryAttribute.Action; } if (exitAttribute != null) { this.ExitAction = exitAttribute.Action; } var gotoAttributes = this.GetType().GetCustomAttributes(typeof(OnEventGotoState), false) as OnEventGotoState[]; var pushAttributes = this.GetType().GetCustomAttributes(typeof(OnEventPushState), false) as OnEventPushState[]; var doAttributes = this.GetType().GetCustomAttributes(typeof(OnEventDoAction), false) as OnEventDoAction[]; foreach (var attr in gotoAttributes) { if (attr.Action == null) { this.GotoTransitions.Add(attr.Event, attr.State); } else { this.GotoTransitions.Add(attr.Event, attr.State, attr.Action); } } foreach (var attr in pushAttributes) { this.PushTransitions.Add(attr.Event, attr.State); } foreach (var attr in doAttributes) { this.ActionBindings.Add(attr.Event, attr.Action); } var ignoreEventsAttribute = this.GetType().GetCustomAttribute(typeof(IgnoreEvents), false) as IgnoreEvents; var deferEventsAttribute = this.GetType().GetCustomAttribute(typeof(DeferEvents), false) as DeferEvents; if (ignoreEventsAttribute != null) { this.IgnoredEvents.UnionWith(ignoreEventsAttribute.Events); } if (deferEventsAttribute != null) { this.DeferredEvents.UnionWith(deferEventsAttribute.Events); } if (this.GetType().IsDefined(typeof(Start), false)) { this.IsStart = true; } }
//The multitude of options here is for easy debug purposes public void CreatePlayer(string name, int entityId, ActionBindings actionBindings, Vector2 position = default(Vector2), bool movable = true, bool useDefaultMoveComponent = true, MoveComponent customMoveComponent = null, bool cameraFollow = false, bool collision = false, bool disabled = false, bool isCaged = false, int cageId = 0) { if (disabled) { return; } if (position == default(Vector2)) { position = new Vector2(150, 150); } var renderComponent = new RenderComponent() { DimensionsComponent = new DimensionsComponent() { Height = 100, Width = 100 }, }; var positionComponent = new PositionComponent() { Position = position, ZIndex = 10 }; var dampeningComponent = new InertiaDampeningComponent(); var backwardsPenaltyComponent = new BackwardsPenaltyComponent(); ComponentManager.Instance.AddComponentToEntity(dampeningComponent, entityId); ComponentManager.Instance.AddComponentToEntity(backwardsPenaltyComponent, entityId); var spriteComponent = new SpriteComponent() { SpriteName = "topDownSoldier", Scale = 1 }; var light = new LightComponent() { Light = new Spotlight() { Position = new Vector2(150, 150), Scale = new Vector2(850f), Radius = (float)0.0001, Intensity = (float)0.6, ShadowType = ShadowType.Solid // Will not lit hulls themselves } }; var sound = new SoundComponent() { SoundEffectName = "walking" }; // var animation = new SpriteAnimationComponent() // { //// Spritesheet = Content.Load<Texture2D>("blood"), //// SpritesheetSize = new Point(3, 3), //// MillisecondsPerFrame = 30, // AnimationStarted = 0, // CurrentAnimatedState = // }; // ComponentManager.Instance.AddComponentToEntity(animation, entityId); var animationBindings = new SpriteAnimationBindingsBuilder() .Binding( new SpriteAnimationBindingBuilder() .Positions(new Point(0, 0), new Point(1000, 1000)) .StateConditions(State.WalkingForward) .Length(30) .Build() ) .Build(); ComponentManager.Instance.AddComponentToEntity(sound, entityId); ComponentManager.Instance.AddComponentToEntity(renderComponent, entityId); ComponentManager.Instance.AddComponentToEntity(positionComponent, entityId); ComponentManager.Instance.AddComponentToEntity(spriteComponent, entityId); ComponentManager.Instance.AddComponentToEntity(actionBindings, entityId); ComponentManager.Instance.AddComponentToEntity(light, entityId); ComponentManager.Instance.AddComponentToEntity(animationBindings, entityId); if (movable && useDefaultMoveComponent) { var moveComponent = new MoveComponent() { MaxVelocitySpeed = 200, AccelerationSpeed = 380, RotationSpeed = 4, Direction = new Random(DateTime.Now.Millisecond).Next(0, 40) / 10 }; ComponentManager.Instance.AddComponentToEntity(moveComponent, entityId); } else if (movable && customMoveComponent != null) { ComponentManager.Instance.AddComponentToEntity(customMoveComponent, entityId); } if (collision) { var collisionComponent = new CollisionComponent() { spriteBoundingRectangle = new Rectangle(30, 20, 70, 60) }; ComponentManager.Instance.AddComponentToEntity(collisionComponent, entityId); } if (cameraFollow) { var cameraFollowComponent = new CameraFollowComponent(); ComponentManager.Instance.AddComponentToEntity(cameraFollowComponent, entityId); } if (isCaged) { var cageComponent = new CageComponent() { CageId = cageId }; ComponentManager.Instance.AddComponentToEntity(cageComponent, entityId); } var playerComponent = new PlayerComponent() { Name = name }; ComponentManager.Instance.AddComponentToEntity(playerComponent, entityId); var healthComponent = new HealthComponent() { CurrentHealth = new Random().Next(0, 100) }; ComponentManager.Instance.AddComponentToEntity(healthComponent, entityId); var weaponComponent = new WeaponComponent() { Damage = 10 }; ComponentManager.Instance.AddComponentToEntity(weaponComponent, entityId); }
//The multitude of options here is for easy debug purposes public void CreatePlayer(int entityId, ActionBindings actionBindings, Vector2 position = default(Vector2), bool movable = true, bool useDefaultMoveComponent = true, MoveComponent customMoveComponent = null, bool cameraFollow = false, bool collision = false, bool disabled = false, bool isCaged = false, int cageId = 0) { if (disabled) { return; } if (position == default(Vector2)) { position = new Vector2(150, 150); } //Initializing first, movable, entity //var renderComponent = new RenderComponentBuilder() // //.Position(150 + new Random(DateTime.Now.Millisecond).Next(0, 500), 150, 10) // .Position(position.X, position.Y, 10) // //.Radius(60) // .Dimensions(100, 100) // .Build(); var renderComponent3 = new RenderComponent() { DimensionsComponent = new DimensionsComponent() { Height = 100, Width = 100 }, Radius = 60 }; var positionComponent3 = new PositionComponent() { Position = position, ZIndex = 10 }; ComponentManager.Instance.AddComponentToEntity(renderComponent3, entityId); ComponentManager.Instance.AddComponentToEntity(positionComponent3, entityId); var spriteComponent = new SpriteComponent() { SpriteName = "topDownSoldier" }; var light = new LightComponent() { Light = new Spotlight() { Position = new Vector2(150, 150), Scale = new Vector2(850f), Radius = (float)0.0001, Intensity = (float)0.6, ShadowType = ShadowType.Solid // Will not lit hulls themselves } }; var sound = new SoundComponent() { SoundEffectName = "walking" }; ComponentManager.Instance.AddComponentToEntity(sound, entityId); // ComponentManager.Instance.AddComponentToEntity(renderComponent, entityId); ComponentManager.Instance.AddComponentToEntity(spriteComponent, entityId); ComponentManager.Instance.AddComponentToEntity(actionBindings, entityId); ComponentManager.Instance.AddComponentToEntity(light, entityId); if (movable && useDefaultMoveComponent) { var moveComponent = new MoveComponent() { MaxVelocitySpeed = 200, AccelerationSpeed = 380, RotationSpeed = 4, Direction = new Random(DateTime.Now.Millisecond).Next(0, 40) / 10 }; ComponentManager.Instance.AddComponentToEntity(moveComponent, entityId); } else if (movable && customMoveComponent != null) { ComponentManager.Instance.AddComponentToEntity(customMoveComponent, entityId); } if (collision) { var collisionComponent = new CollisionComponent() { spriteBoundingRectangle = new Rectangle(30, 20, 70, 60) }; ComponentManager.Instance.AddComponentToEntity(collisionComponent, entityId); } if (cameraFollow) { var cameraFollowComponent = new CameraFollowComponent(); ComponentManager.Instance.AddComponentToEntity(cameraFollowComponent, entityId); } if (isCaged) { var cageComponent = new CageComponent() { CageId = cageId }; ComponentManager.Instance.AddComponentToEntity(cageComponent, entityId); } var playerComponent = new PlayerComponent() { Name = entityId.ToString() }; ComponentManager.Instance.AddComponentToEntity(playerComponent, entityId); var healthComponent = new HealthComponent() { CurrentHealth = new Random().Next(0, 100) }; ComponentManager.Instance.AddComponentToEntity(healthComponent, entityId); var weaponComponent = new WeaponComponent() { Damage = 10 }; ComponentManager.Instance.AddComponentToEntity(weaponComponent, entityId); }