本文整理汇总了C#中WheelMUD.Core.ActionInput类的典型用法代码示例。如果您正苦于以下问题:C# ActionInput类的具体用法?C# ActionInput怎么用?C# ActionInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ActionInput类属于WheelMUD.Core命名空间,在下文中一共展示了ActionInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Guards
/// <summary>Checks against the guards for the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
/// <returns>A string with the error message for the user upon guard failure, else null.</returns>
public override string Guards(ActionInput actionInput)
{
IController sender = actionInput.Controller;
string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
if (commonFailure != null)
{
return commonFailure;
}
// Rule: Do we have an item matching in our inventory?
// @@@ TODO: Support drinking from, for instance, a fountain sitting in the room.
string itemIdentifier = actionInput.Tail.Trim();
this.thingToDrink = sender.Thing.FindChild(itemIdentifier.ToLower());
if (this.thingToDrink == null)
{
return "You do not hold " + actionInput.Tail.Trim() + ".";
}
// Rule: Is the item drinkable?
this.drinkableBehavior = this.thingToDrink.Behaviors.FindFirst<DrinkableBehavior>();
if (this.drinkableBehavior == null)
{
return itemIdentifier + " is not drinkable";
}
return null;
}
示例2: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
var contextMessage = new ContextualString(sender.Thing, this.target)
{
ToOriginator = "You cast ThunderClap at $ActiveThing.Name!",
ToReceiver = "$Aggressor.Name casts ThunderClap at you, you only hear a ringing in your ears now.",
ToOthers = "You hear $Aggressor.Name cast ThunderClap at $ActiveThing.Name! It was very loud.",
};
var sm = new SensoryMessage(SensoryType.Hearing, 100, contextMessage);
var attackEvent = new AttackEvent(this.target, sm, sender.Thing);
sender.Thing.Eventing.OnCombatRequest(attackEvent, EventScope.ParentsDown);
if (!attackEvent.IsCancelled)
{
var deafenEffect = new AlterSenseEffect()
{
SensoryType = SensoryType.Hearing,
AlterAmount = -1000,
Duration = new TimeSpan(0, 0, 45),
};
this.target.Behaviors.Add(deafenEffect);
sender.Thing.Eventing.OnCombatEvent(attackEvent, EventScope.ParentsDown);
}
}
示例3: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
this.itemToWieldBehavior.Wielder = sender.Thing;
// Create an event handler that intercepts the ChangeOwnerEvent and
// prevents dropping/trading the item around while it is wielded.
// A reference is stored in the WieldableBehavior instance so it
// can be easily removed by the unwield command.
var interceptor = new CancellableGameEventHandler(this.Eventing_MovementRequest);
this.itemToWieldBehavior.MovementInterceptor = interceptor;
this.itemToWield.Eventing.MovementRequest += interceptor;
var contextMessage = new ContextualString(sender.Thing, this.itemToWield.Parent)
{
ToOriginator = "You wield the $WieldedItem.Name.",
ToOthers = "$ActiveThing.Name wields a $WieldedItem.Name.",
};
var sensoryMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);
var wieldEvent = new WieldUnwieldEvent(this.itemToWield, true, sender.Thing, sensoryMessage);
sender.Thing.Eventing.OnCombatRequest(wieldEvent, EventScope.ParentsDown);
if (!wieldEvent.IsCancelled)
{
sender.Thing.Eventing.OnCombatEvent(wieldEvent, EventScope.ParentsDown);
}
}
示例4: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
// Remove "weapon" from input tail and use the rest as the name.
string weaponName = actionInput.Tail.Substring(6).Trim().ToLower();
Thing weaponItem = new Thing(new WieldableBehavior(), new MovableBehavior());
weaponItem.Name = weaponName;
weaponItem.SingularPrefix = "a";
//weaponItem.ID = Guid.NewGuid().ToString();
weaponItem.ID = "0";
var wasAdded = sender.Thing.Parent.Add(weaponItem);
var userControlledBehavior = sender.Thing.Behaviors.FindFirst<UserControlledBehavior>();
if (wasAdded)
{
userControlledBehavior.Controller.Write(string.Format("You create a weapon called {0}.", weaponItem.Name));
}
else
{
userControlledBehavior.Controller.Write(string.Format("Could not add {0} to the room!", weaponItem.Name));
}
}
示例5: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
var parameters = actionInput.Params;
// Ensure two 'credits' commands at the same time do not race for shared cache, etc.
lock (cacheLockObject)
{
if (cachedContents == null || (parameters.Length > 0 && parameters[0].ToLower() == "reload"))
{
StreamReader reader = new StreamReader("Files\\Credits.txt");
StringBuilder stringBuilder = new StringBuilder();
string s;
while ((s = reader.ReadLine()) != null)
{
if (!s.StartsWith(";"))
{
stringBuilder.AppendLine(s);
}
}
cachedContents = stringBuilder.ToString();
}
sender.Write(cachedContents);
}
}
示例6: Guards
/// <summary>Prepare for, and determine if the command's prerequisites have been met.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
/// <returns>A string with the error message for the user upon guard failure, else null.</returns>
public override string Guards(ActionInput actionInput)
{
string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
if (commonFailure != null)
{
return commonFailure;
}
// Rule: We should have at least 1 item in our words array.
int numberWords = actionInput.Params.Length;
if (numberWords < 2)
{
return "You must specify a room to create a portal to.";
}
// Check to see if the first word is a number.
string roomToGet = actionInput.Params[1];
if (string.IsNullOrEmpty(roomToGet))
{
// Its not a number so it could be an entity... try it.
this.targetPlace = GameAction.GetPlayerOrMobile(actionInput.Params[0]);
if (this.targetPlace == null)
{
return "Could not convert " + actionInput.Params[0] + " to a room number.";
}
}
// this.targetRoom = bridge.World.FindRoom(roomToGet);
if (this.targetPlace == null)
{
return string.Format("Could not find the room {0}.", roomToGet);
}
return null;
}
示例7: TestParseText
public void TestParseText()
{
// Test empty string
var actionInput = new ActionInput(string.Empty, null);
Verify.IsNull(actionInput.Noun);
Verify.IsNull(actionInput.Tail);
Verify.IsNull(actionInput.Params);
// Test simple 1-word command
var oneWordInput = new ActionInput("look", null);
Verify.AreEqual(oneWordInput.Noun, "look");
Verify.IsNull(actionInput.Tail);
Verify.IsNull(actionInput.Params);
// Test 2-word command
var twoWordInput = new ActionInput("look foo", null);
Verify.AreEqual(twoWordInput.Noun, "look");
Verify.AreEqual(twoWordInput.Tail, "foo");
Verify.IsNotNull(twoWordInput.Params);
Verify.AreEqual(twoWordInput.Params.Length, 1);
// Test 2-word command
var threeWordInput = new ActionInput("create consumable metal", null);
Verify.AreEqual(threeWordInput.Noun, "create");
Verify.AreEqual(threeWordInput.Tail, "consumable metal");
Verify.IsNotNull(threeWordInput.Params);
Verify.AreEqual(threeWordInput.Params.Length, 2);
// Test input with leading/trailing spaces
var spacedWordInput = new ActionInput(" look foo ", null);
Verify.AreEqual(spacedWordInput.Noun, "look");
Verify.AreEqual(spacedWordInput.Tail, "foo");
Verify.IsNotNull(spacedWordInput.Params);
Verify.AreEqual(spacedWordInput.Params.Length, 1);
}
示例8: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
if (sender != null && sender.Thing != null)
{
Thing entity = sender.Thing;
if (entity != null)
{
if (!string.IsNullOrEmpty(this.NewDescription))
{
entity.Description = this.NewDescription;
entity.Save();
sender.Write("Description successfully changed.");
}
else
{
sender.Write(string.Format("Your current description is \"{0}\".", entity.Description));
}
}
else
{
sender.Write("Unexpected error occurred changing description, please contact admin.");
}
}
}
示例9: Guards
/// <summary>Prepare for, and determine if the command's prerequisites have been met.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
/// <returns>A string with the error message for the user upon guard failure, else null.</returns>
public override string Guards(ActionInput actionInput)
{
string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
if (commonFailure != null)
{
return commonFailure;
}
// Rule: Did they specify a tree to chop?
// @@@ TODO: Better thing finders...
Thing parent = actionInput.Controller.Thing.Parent;
Thing thing = parent.Children.Find(t => t.Name.Equals(actionInput.Params[0], StringComparison.CurrentCultureIgnoreCase));
if (thing == null)
{
return string.Format("{0} is not here.", actionInput.Params[0]);
}
// @@@ TODO: Detect ConsumableProviderBehavior on the item, and detect if it is choppable.
//if (!(item is Item))
//{
// return string.Format("{0} is not a tree.", actionInput.Params[0]);
//}
//this.tree = (Item) item;
//if (this.tree.NumberOfResources <= 0)
//{
// return string.Format("The tree doesn't contain any suitable wood.");
//}
return null;
}
示例10: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
this.itemToUnwieldBehavior.Wielder = null;
// Remove the event handler that prevents dropping the item while wielded.
var interceptor = this.itemToUnwieldBehavior.MovementInterceptor;
this.itemToUnwield.Eventing.MovementRequest -= interceptor;
var contextMessage = new ContextualString(sender.Thing, this.itemToUnwield.Parent)
{
ToOriginator = "You unwield the $WieldedItem.Name.",
ToOthers = "$ActiveThing.Name unwields a $WieldedItem.Name.",
};
var sensoryMessage = new SensoryMessage(SensoryType.Sight, 100, contextMessage);
var unwieldEvent = new WieldUnwieldEvent(this.itemToUnwield, true, sender.Thing, sensoryMessage);
sender.Thing.Eventing.OnCombatRequest(unwieldEvent, EventScope.ParentsDown);
if (!unwieldEvent.IsCancelled)
{
sender.Thing.Eventing.OnCombatEvent(unwieldEvent, EventScope.ParentsDown);
}
}
示例11: Guards
/// <summary>Checks against the guards for the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
/// <returns>A string with the error message for the user upon guard failure, else null.</returns>
public override string Guards(ActionInput actionInput)
{
IController sender = actionInput.Controller;
Thing wielder = sender.Thing;
Thing room = wielder.Parent;
string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
if (commonFailure != null)
{
return commonFailure;
}
string itemName = actionInput.Tail.Trim().ToLower();
// First look for a matching item in inventory and make sure it can
// be wielded. If nothing was found in inventory, look for a matching
// wieldable item in the surrounding environment.
this.itemToUnwield = wielder.FindChild(item => item.Name.ToLower() == itemName && item.HasBehavior<WieldableBehavior>() && item.Behaviors.FindFirst<WieldableBehavior>().Wielder == sender.Thing);
if (this.itemToUnwield == null)
{
this.itemToUnwield = wielder.Parent.FindChild(item => item.Name.ToLower() == itemName && item.HasBehavior<WieldableBehavior>() && item.Behaviors.FindFirst<WieldableBehavior>().Wielder == sender.Thing);
}
if (this.itemToUnwield == null)
{
return "You are not wielding the " + itemName + ".";
}
this.itemToUnwieldBehavior = this.itemToUnwield.Behaviors.FindFirst<WieldableBehavior>();
return null;
}
示例12: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
string[] normalizedParams = this.NormalizeParameters(sender);
string role = normalizedParams[0];
string playerName = normalizedParams[1];
Thing player = GameAction.GetPlayerOrMobile(playerName);
if (player == null)
{
// If the player is not online, then load the player from the database
//player = PlayerBehavior.Load(playerName);
}
var userControlledBehavior = player.Behaviors.FindFirst<UserControlledBehavior>();
var existingRole = (from r in userControlledBehavior.Roles where r.Name == role select r).FirstOrDefault();
if (existingRole == null)
{
var roleRepository = new RoleRepository();
// @@@ TODO: The role.ToUpper is a hack. Need to create a case insensitive method for the RoleRepository.NoGen.cs class.
RoleRecord record = roleRepository.GetByName(role.ToUpper());
//userControlledBehavior.RoleRecords.Add(record);
//userControlledBehavior.UpdateRoles();
player.Save();
sender.Write(player.Name + " has been granted the " + role + " role.", true);
}
}
示例13: Guards
/// <summary>Checks against the guards for the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
/// <returns>A string with the error message for the user upon guard failure, else null.</returns>
public override string Guards(ActionInput actionInput)
{
string commonFailure = VerifyCommonGuards(actionInput, ActionGuards);
if (commonFailure != null)
{
return commonFailure;
}
string[] normalizedParams = this.NormalizeParameters(actionInput.Controller);
string role = normalizedParams[0];
string playerName = normalizedParams[1];
Thing player = GameAction.GetPlayerOrMobile(playerName);
if (player == null)
{
// If the player is not online, then load the player from the database
//player = PlayerBehavior.Load(playerName);
}
// Rule: Does the player exist in our Universe?
// @@@ TODO: Add code to make sure the player exists.
// Rule: Does player already have role?
/* @@@ FIX
if (Contains(player.Roles, role))
{
return player.Name + " already has the " + role + " role.";
}*/
return null;
}
示例14: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
// Not sure what would call this other than a player, but exit early just in case.
// Implicitly also verifies that this.sender exists.
if (this.userControlledBehavior == null)
{
return;
}
// No arguments were provided. Just show the current buffer setting and exit.
if (string.IsNullOrEmpty(actionInput.Tail))
{
this.ShowCurrentBuffer();
return;
}
// Set the value for the current session
if (this.session.Connection != null)
{
this.session.Connection.PagingRowLimit = (this.parsedBufferLength == -1) ? this.session.Terminal.Height : this.parsedBufferLength;
}
this.userControlledBehavior.PagingRowLimit = this.parsedBufferLength;
this.userControlledBehavior.Save();
this.ShowCurrentBuffer();
}
示例15: Execute
/// <summary>Executes the command.</summary>
/// <param name="actionInput">The full input specified for executing the command.</param>
public override void Execute(ActionInput actionInput)
{
IController sender = actionInput.Controller;
Thing parent = sender.Thing.Parent;
string searchString = actionInput.Tail.Trim().ToLower();
if (string.IsNullOrEmpty(searchString))
{
sender.Write("You must specify something to search for.");
return;
}
// Unique case. Use 'here' to list the contents of the room.
if (searchString == "here")
{
sender.Write(this.ListRoomItems(parent));
return;
}
// First check the place where the sender is located (like a room) for the target,
// and if not found, search the sender's children (like inventory) for the target.
Thing thing = parent.FindChild(searchString) ?? sender.Thing.FindChild(searchString);
if (thing != null)
{
// @@@ TODO: Send a SensoryEvent?
sender.Write(thing.Description);
}
else
{
sender.Write("You cannot find " + searchString + ".");
}
}