本文整理汇总了C#中TradeAndTravel.Person.AddToInventory方法的典型用法代码示例。如果您正苦于以下问题:C# Person.AddToInventory方法的具体用法?C# Person.AddToInventory怎么用?C# Person.AddToInventory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TradeAndTravel.Person
的用法示例。
在下文中一共展示了Person.AddToInventory方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CraftArmor
private void CraftArmor(string newItemName, Person actor)
{
var ironItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Iron);
if (ironItems != null && ironItems.Count() > 0 )
{
var item = new Armor(newItemName, null);
actor.AddToInventory(item);
ownerByItem.Add(item, actor);
item.UpdateWithInteraction("craft");
}
}
示例2: HandleCraftInteraction
private void HandleCraftInteraction(Person actor, string name)
{
if (actor.ListInventory().Exists(x => x is Iron))
{
if (actor.ListInventory().Exists(x => x is Weapon))
{
var item = new Weapon(name);
actor.AddToInventory(item);
this.AddToPerson(actor, item);
return;
}
else
{
var item = new Armor(name);
actor.AddToInventory(item);
this.AddToPerson(actor, item);
}
}
}
示例3: AddToPerson
protected void AddToPerson(Person actor, Item item)
{
actor.AddToInventory(item);
ownerByItem[item] = actor;
}
示例4: HandleGatherInteraction
private void HandleGatherInteraction(Person actor, string itemName)
{
//Gathering means a Person takes an item from a special location
//A Person should be able to gather from mines and from forests
//A Person can gather from a forest only if he has a Weapon in his inventory
//Gathering from a forests results in adding a Wood item in the Person’s inventory
//A Person can gather from a mine only if he has an Armor in his inventory
//Gathering from a mine results in adding an Iron item in the Person’s inventory
//Syntax: Joro gather newItemName – gathers an item, naming it newItemName if the Person Joro is at a mine or forest, and respectively has an Armor or Weapon
if (actor.Location.LocationType == LocationType.Forest && actor.ListInventory().Any(a => a.GetType() == typeof(Weapon)))
{
Wood a = new Wood(itemName);
base.AddToPerson(actor, a);
actor.AddToInventory(new Wood(itemName));
}
if (actor.Location.LocationType == LocationType.Mine && actor.ListInventory().Any(a => a.GetType() == typeof(Armor)))
{
Iron a = new Iron(itemName);
base.AddToPerson(actor, a);
actor.AddToInventory(new Iron(itemName));
}
}
示例5: HandleCraftInteraction
private void HandleCraftInteraction(Person actor, string itemToCraft, string itemName)
{
//A Person can craft items, provided he has some items in his inventory
//A Person should be able to craft Weapons and Armor
//Crafting an Armor requires that the Person has Iron in his inventory
//Results in adding an Armor item in the Person’s inventory
//Crafting a Weapon requires that the Person has Iron and Wood in his inventory
//Syntax: Joro craft weapon/armor newItemName - gathers an item, naming it newItemName if the Person Joro has the necessary
switch (itemToCraft)
{
case "armor":
if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron)))
{
Armor armor = new Armor(itemName);
base.AddToPerson(actor, armor);
actor.AddToInventory(new Armor(itemName));
}
break;
case "weapon":
if (actor.ListInventory().Any(a => a.GetType() == typeof(Iron)) && actor.ListInventory().Any(a => a.GetType() == typeof(Wood)))
{
Weapon weapon = new Weapon(itemName);
base.AddToPerson(actor, weapon);
actor.AddToInventory(new Weapon(itemName));
}
break;
default:
break;
}
}
示例6: HandleGatherInteraction
private void HandleGatherInteraction(Person actor, string itemName)
{
var actorItems = actor.ListInventory();
for (int i = 0; i < actorItems.Count; i++)
{
if (actorItems[i] is Weapon && actor.Location is Forest)
{
var item = new Wood(itemName);
actor.AddToInventory(item);
this.ownerByItem.Add(item, actor);
return;
}
else if (actorItems[i] is Armor && actor.Location is Mine)
{
var item = new Iron(itemName);
actor.AddToInventory(item);
this.ownerByItem.Add(item, actor);
return;
}
}
}
示例7: HandleCraftInteraction
private void HandleCraftInteraction(Person actor, string itemType, string itemName)
{
if (actor.ListInventory().Find(i => i is Iron) != null)
{
if (itemType == "weapon" && actor.ListInventory().Find(i => i is Wood) != null)
{
var item = new Weapon(itemName);
actor.AddToInventory(item);
this.ownerByItem.Add(item, actor);
}
else if (itemType == "armor")
{
var item = new Armor(itemName);
actor.AddToInventory(item);
this.ownerByItem.Add(item, actor);
}
}
}
示例8: HandleGatherInteraction
private void HandleGatherInteraction(string[] commandWords, Person actor)
{
if (actor.Location.LocationType == LocationType.Forest)
{
var inventoryItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Weapon);
if (inventoryItems != null && inventoryItems.Count() > 0)
{
var item = new Wood(commandWords[2], null);
actor.AddToInventory(item);
ownerByItem.Add(item, actor);
item.UpdateWithInteraction("gather");
}
}
else if (actor.Location.LocationType == LocationType.Mine)
{
var inventoryItems = actor.ListInventory().Where(x => x.ItemType == ItemType.Armor);
if (inventoryItems != null && inventoryItems.Count() > 0)
{
var item = new Iron(commandWords[2], null);
actor.AddToInventory(item);
ownerByItem.Add(item, actor);
}
}
}
示例9: HandleGatherInteraction
private void HandleGatherInteraction(Person actor, string name)
{
var locationForest = actor.Location as Forest;
if (locationForest is Forest)
{
if (actor.ListInventory().Exists(x => x is Weapon))
{
var item = new Wood(name, actor.Location);
actor.AddToInventory(item);
this.AddToPerson(actor, item);
}
}
var locationMine = actor.Location as Mine;
if (locationMine is Mine)
{
if (actor.ListInventory().Exists(x => x is Armor))
{
var item = new Iron(name, actor.Location);
actor.AddToInventory(item);
this.AddToPerson(actor, item);
}
}
}