本文整理汇总了C#中EventContext.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# EventContext.Commit方法的具体用法?C# EventContext.Commit怎么用?C# EventContext.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventContext
的用法示例。
在下文中一共展示了EventContext.Commit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteAction
private bool ExecuteAction(Character character, ActionDescriptor actionDescriptor, ISet<Character> finishedCharacters, Dictionary<Room, List<ObservableInformation>> informations)
{
//Find a matching event to execute.
Event eventToPlay = eventManager.FindEventForAction(actionDescriptor, this);
if (eventToPlay != null)
{
//We pass in an event results instead of accepting a return value because we want all
//the event logic along the way to touch the same instance instead of having to worry
//about merging a number of different instances.
EventResults results = new EventResults();
EventContext context = new EventContext(actionDescriptor);
eventToPlay.Execute(results, this, context);
//We need to commit any changes that occurred.
context.Commit();
//Did the target get their turn consumed?
if (!results.TargetGetsTurn && actionDescriptor.Target != null)
{
//Remove the target from the room (since they are busy) and make sure they don't
//get their normal action.
finishedCharacters.Add(actionDescriptor.Target);
actionDescriptor.Target.MarkBusy();
}
if(results.HasInformation)
{
//Add any information to the list of things that characters in the room might observe.
List<ObservableInformation> infos = null;
if (!informations.TryGetValue(character.CurrentRoom, out infos))
{
infos = new List<ObservableInformation>();
informations.Add(character.CurrentRoom, infos);
}
infos.AddRange(results.ObservableInformation);
}
if (results.ContinueTurn)
{
//The turn is incomplete. The character isn't busy or finished yet.
return false;
}
}
//This character is now done.
finishedCharacters.Add(character);
// The initiator always gets their turn consumed so remove them from the room.
character.MarkBusy();
//The turn completed successfully.
return true;
}
示例2: ExecuteOnTold
public void ExecuteOnTold(Character currentCharacter, Game game, Room room)
{
//The current character is the root of the new context so that they will be the
//default scope in the on_told we are about to run.
// We might need tellingCharacter here but removing it for now since it's never used.
EventContext observeContext = new EventContext(currentCharacter, parameters);
information.OnTold.Execute(new EventResults(), game, observeContext);
observeContext.Commit();
}
示例3: ExecuteOnObserve
public void ExecuteOnObserve(Character currentCharacter, Game game, Room room)
{
foreach(var param in information.Parameters)
{
if(param.Type == typeof(Character) && param.Inform)
{
Character curr = parameters[param.Name] as Character;
curr.AddHistory(this);
}
}
//The current character is the root of the new context so that they will be the
//default scope in the on_observe we are about to run.
EventContext observeContext = new EventContext(currentCharacter, parameters);
information.OnObserve.Execute(new EventResults(), game, observeContext);
observeContext.Commit();
}
示例4: GiveJobTo
public void GiveJobTo(Job job, Character newHolder, Game game)
{
if(job.Unique)
{
Character oldHolder = uniqueJobs[job];
if(oldHolder != null)
{
if (job.Permanent)
throw new InvalidOperationException("You tried to fire the king!! He chops your head off instead.");
oldHolder.FireFromJob(job);
Event fireEvent = game.GetEventById(job.OnFire);
if (fireEvent != null)
{
EventContext context = new EventContext(oldHolder);
fireEvent.Execute(new EventResults(), game, context);
//We need to commit any changes.
context.Commit();
}
}
if(newHolder != null)
{
newHolder.GiveJob(job);
Event hireEvent = game.GetEventById(job.OnHire);
if (hireEvent != null)
{
EventContext context = new EventContext(newHolder);
hireEvent.Execute(new EventResults(), game, context);
//We need to commit any changes.
context.Commit();
}
}
uniqueJobs[job] = newHolder;
}
else
{
if(newHolder != null)
{
newHolder.GiveJob(job);
Event hireEvent = game.GetEventById(job.OnHire);
if (hireEvent != null)
{
EventContext context = new EventContext(newHolder);
hireEvent.Execute(new EventResults(), game, context);
//We need to commit any changes.
context.Commit();
}
}
}
}