本文整理汇总了C#中Character.GetHeldItem方法的典型用法代码示例。如果您正苦于以下问题:C# Character.GetHeldItem方法的具体用法?C# Character.GetHeldItem怎么用?C# Character.GetHeldItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Character
的用法示例。
在下文中一共展示了Character.GetHeldItem方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestJsonSerialization
public void TestJsonSerialization(Character character)
{
JsonCharacterSerializer characterSerializer;
Character newCharacter;
string json;
characterSerializer = new JsonCharacterSerializer();
json = characterSerializer.Serialize(character);
newCharacter = characterSerializer.Deserialize(json);
Assert.That(newCharacter, Is.EqualTo(character), "Characters differ");
Assert.That(newCharacter.GetHeldItem<Item>(Hand.Main), Is.EqualTo(character.GetHeldItem<Item>(Hand.Main)),
"Main hands differ");
Assert.That(newCharacter.GetHeldItem<Item>(Hand.Off), Is.EqualTo(character.GetHeldItem<Item>(Hand.Off)),
"Main hands differ");
Assert.That(
Array.ConvertAll((Slot[])Enum.GetValues(typeof(Slot)), x => newCharacter.GetEquippedItem<Item>(x)),
Is.EquivalentTo(Array.ConvertAll((Slot[])Enum.GetValues(typeof(Slot)), character.GetEquippedItem<Item>)),
"Equipped items differ");
Assert.That(
newCharacter.Gear.OrderBy(x => x.Name),
Is.EquivalentTo(character.Gear.OrderBy(x => x.Name)),
"Carried items differ");
Assert.That(
newCharacter.Levels.OrderBy(x => x.Number),
Is.EquivalentTo(character.Levels.OrderBy(x => x.Number)),
"Levels differ");
}
示例2: AddModifiers
/// <summary>
/// Add modifiers.
/// </summary>
/// <param name="stage">
/// The stage during character update this is called.
/// </param>
/// <param name="addModifier">
/// Add modifiers by calling this method.
/// </param>
/// <param name="character">
/// The character to add modifiers for.
/// </param>
protected override void AddModifiers(CharacterUpdateStage stage, Action<Modifier> addModifier, Character character)
{
Weapon weapon;
base.AddModifiers(stage, addModifier, character);
weapon = character.GetHeldItem<Weapon>(Hand);
if (weapon != null)
{
// Add the greatest ability score's modifier
BonusHelper.AddGreatestScoreModifier(this, addModifier, character, weapon.BasicAttackAbilityScores);
}
}
示例3: AddDependencies
/// <summary>
/// Depend on each of the <see cref="Weapon.BasicAttackAbilityScores"/>.
/// </summary>
/// <param name="addDependency">
/// The list of depdencies.
/// </param>
/// <param name="character">
/// The <see cref="Character"/> to add dependencies for.
/// </param>
protected override void AddDependencies(Action<ModifierSource, ModifierSource> addDependency, Character character)
{
Weapon weapon;
base.AddDependencies(addDependency, character);
weapon = character.GetHeldItem<Weapon>(Hand);
if (weapon != null)
{
foreach (ScoreType scoreType in weapon.BasicAttackAbilityScores)
{
addDependency(character[scoreType], this);
}
}
}
示例4: AddDependencies
/// <summary>
/// Determine whether the attack is melee or ranged.
/// </summary>
/// <param name="addDependency"></param>
/// <param name="character"></param>
protected override void AddDependencies(Action<ModifierSource, ModifierSource> addDependency, Character character)
{
base.AddDependencies(addDependency, character);
Weapon weapon;
weapon = character.GetHeldItem<Weapon>(Hand.Main);
if (weapon != null
&& weapon is RangedWeapon)
{
SetAttackTypeAndRange(Range.RangedWeapon(Name));
}
else
{
SetAttackTypeAndRange(Range.MeleeWeapon(Name));
}
}
示例5: AddDependencies
/// <summary>
/// Set the <see cref="AttackTypeAndRange"/>.
/// </summary>
/// <param name="addDependency">
/// </param>
/// <param name="character"></param>
protected override void AddDependencies(Action<ModifierSource, ModifierSource> addDependency, Character character)
{
Weapon weapon;
base.AddDependencies(addDependency, character);
weapon = character.GetHeldItem<Weapon>(Hand.Main);
if (weapon is RangedWeapon)
{
SetAttackTypeAndRange(Range.Ranged(Name, ((RangedWeapon)weapon).Range));
}
else
{
// This is needed for subsequent updates
SetAttackTypeAndRange(Range.Melee(Name, 1));
}
}
示例6: Serialize
/// <summary>
/// Serialize the given <see cref="Character"/> to JSON.
/// </summary>
/// <param name="character">
/// The <see cref="Character"/> to serialize. This cannot be null.
/// </param>
/// <returns>
/// The character as JSON.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="character"/> cannot be null.
/// </exception>
public string Serialize(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character");
}
CharacterJsonData characterJsonData;
// Serialize the base character
characterJsonData = new CharacterJsonData
{
PrimaryOrigin = character.PrimaryOrigin,
SecondaryOrigin = character.SecondaryOrigin,
TrainedSkill = character.TrainedSkill,
Name = character.Name,
PlayerName = character.PlayerName
};
foreach (ScoreType abilityScore in ScoreTypeHelper.AbilityScores)
{
characterJsonData.AbilityScores[abilityScore] =
character[abilityScore].Total;
}
// Serialize levels
foreach (Level level in character.Levels)
{
characterJsonData.Levels.Add(level);
}
// Serialize gear
characterJsonData.MainHand = character.GetHeldItem<Item>(Hand.Main);
characterJsonData.OffHand = character.GetHeldItem<Item>(Hand.Off);
foreach (Slot slot in Enum.GetValues(typeof (Slot)))
{
if (character.GetEquippedItem<Item>(slot) != null)
{
characterJsonData.EquippedGear[slot] = character.GetEquippedItem<Item>(slot);
}
}
foreach (Item item in character.Gear)
{
characterJsonData.OtherGear.Add(item);
}
// Include the ItemConverter here as there is no way to specify the
// converter for collections as attributes.
return JsonConvert.SerializeObject(characterJsonData, Formatting.Indented,
new ItemConverter(), new LevelConverter());
}
示例7: AddModifiers
/// <summary>
/// Add modifiers.
/// </summary>
/// <param name="stage">
/// The stage during character update this is called.
/// </param>
/// <param name="addModifier">
/// Add modifiers by calling this method.
/// </param>
/// <param name="character">
/// The character to add modifiers for.
/// </param>
protected override void AddModifiers(CharacterUpdateStage stage, Action<Modifier> addModifier, Character character)
{
Weapon weapon;
base.AddModifiers(stage, addModifier, character);
weapon = character.GetHeldItem<Weapon>(Hand);
if (weapon != null)
{
// Add the accuracy bonus
addModifier(new Modifier(weapon, this, weapon.AccuracyBonus));
}
}
示例8: IsUsable
/// <summary>
/// Can the specified <see cref="Character"/> use this power at this time?
/// </summary>
/// <param name="character">
/// The Character to test.
/// </param>
/// <returns>
/// True if the ability can be used, false otherwise.
/// </returns>
public override bool IsUsable(Character character)
{
return base.IsUsable(character)
&& character.GetHeldItem<Weapon>(Hand.Main) != null;
}
示例9: AddModifiers
/// <summary>
/// Add modifiers.
/// </summary>
/// <param name="stage">
/// The stage during character update this is called.
/// </param>
/// <param name="addModifier">
/// Add modifiers by calling this method.
/// </param>
/// <param name="character">
/// The character to add modifiers for.
/// </param>
/// <exception cref="InvalidOperationException">
/// The character must be wielding a weapon.
/// </exception>
protected override void AddModifiers(CharacterUpdateStage stage, Action<Modifier> addModifier, Character character)
{
Weapon weapon;
base.AddModifiers(stage, addModifier, character);
weapon = character.GetHeldItem<Weapon>(Hand);
if (weapon != null)
{
SetDice(new Dice(Multiplier * weapon.Damage.Number,
weapon.Damage.DiceType));
}
// Do nothing if the weapon is not present. Certain powers like a ranger's TwinStrike may
// not be available depending on certain weapon configurations.
}
示例10: BuildItemPowerDisplayList
/// <summary>
/// Build a list of <see cref="ItemPowerDisplay"/> automatically.
/// </summary>
/// <param name="character">
/// The <see cref="GammaWorldCharacer"/> to build the list for. This cannot be null
/// and must have a weapon in the main hand.
/// </param>
/// <returns>
/// The list.
/// </returns>
/// <exception cref="ArgumentNullException">
/// <paramref name="character"/> cannot be null.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="character"/> must be holding a weapon in the main hand. This is primary
/// for ease of implementation.
/// </exception>
public static IEnumerable<ItemPowerDisplay> BuildItemPowerDisplayList(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character");
}
if (character.GetHeldItem<Weapon>(Hand.Main) == null)
{
throw new ArgumentException("character must be holding a weapon in the main hand", "character");
}
List<ItemPowerDisplay> result;
Item originalMainHand;
Item originalOffHand;
result = new List<ItemPowerDisplay>();
result.Add(new ItemPowerDisplay(character.GetHeldItem<Item>(Hand.Main), null, x => true));
if (character.GetHeldItem<Weapon>(Hand.Off) != null)
{
result.Add(new ItemPowerDisplay(character.GetHeldItem<Item>(Hand.Off), null, x => x is WeaponAttackPower));
}
// Save the main hand and off hand to restore them when done
originalMainHand = character.GetHeldItem<Item>(Hand.Main);
originalOffHand = character.GetHeldItem<Item>(Hand.Off); ;
try
{
character.SetHeldItem(Hand.Main, null);
character.SetHeldItem(Hand.Off, null);
result.AddRange(character.Gear.Where(x => x is Weapon).Select(
x => new ItemPowerDisplay(x, null, y => y is WeaponAttackPower)));
}
finally
{
// Restore held items
character.SetHeldItem(Hand.Main, originalMainHand);
character.SetHeldItem(Hand.Off, originalOffHand);
}
return result;
}
示例11: GetEquippedGear
/// <summary>
/// Construct a dictionary of the items held or worn by the character.
/// </summary>
/// <param name="character">
/// The <see cref="Character"/> to get the gear for.
/// </param>
/// <returns>
/// A <see cref="Dictionary<K,T>">Dictionary<Item, int></see> associating items to
/// the number equipped.
/// </returns>
/// <exception cref="ArgumentNullException">
/// No argument can be null.
/// </exception>
/// <seealso cref="GetCarriedGear"/>
public static Dictionary<Item, int> GetEquippedGear(Character character)
{
if (character == null)
{
throw new ArgumentNullException("character");
}
Dictionary<Item, int> equipment;
Slot currentSlot;
equipment = new Dictionary<Item, int>();
if (character.GetHeldItem<Item>(Hand.Main) != null)
{
AddItem(character.GetHeldItem<Item>(Hand.Main), equipment);
}
if (character.GetHeldItem<Item>(Hand.Off) != null)
{
AddItem(character.GetHeldItem<Item>(Hand.Off), equipment);
}
foreach (int enumValue in Enum.GetValues(typeof(Slot)))
{
currentSlot = (Slot)enumValue;
if (currentSlot != Slot.None && currentSlot != Slot.Hands)
{
if (character.GetEquippedItem<Item>(currentSlot) != null)
{
AddItem(character.GetEquippedItem<Item>(currentSlot), equipment);
}
}
}
return equipment;
}
示例12: ConstructAttackPowerEntry
/// <summary>
/// Render out an <see cref="AttackPower"/>.
/// </summary>
/// <param name="character">
/// The <see cref="Character"/> to render.
/// </param>
/// <param name="attackPower">
/// The <see cref="AttackPower"/> to render.
/// </param>
/// <param name="resourceDictionary">
/// A <see cref="ResourceDictionary"/> containing styles.
/// </param>
/// <exception cref="ArgumentNullException">
/// No argument can be null.
/// </exception>
/// <exception cref="ArgumentException">
/// <paramref name="attackPower"/> is not usable.
/// </exception>
private PowerEntry ConstructAttackPowerEntry(Character character, AttackPower attackPower, ResourceDictionary resourceDictionary)
{
if (character == null)
{
throw new ArgumentNullException("character");
}
if (attackPower == null)
{
throw new ArgumentNullException("attackPower");
}
if (!attackPower.IsUsable(character))
{
throw new ArgumentException("attackPower is not usable", "attackPower");
}
DictionaryHelper.Expect<Style>(resourceDictionary, StyleHelper.DetailRowStyleName);
Paragraph detail;
Weapon mainHandWeapon;
Weapon offHandWeapon;
Weapon currentWeapon;
detail = new Paragraph();
detail.Style = (Style)resourceDictionary[StyleHelper.DetailRowStyleName];
// Write out a line for each attack
currentWeapon = null;
foreach (AttackDetails attackDetails in attackPower.Attacks)
{
if (attackPower is WeaponAttackPower)
{
mainHandWeapon = character.GetHeldItem<Weapon>(Hand.Main);
offHandWeapon = character.GetHeldItem<Weapon>(Hand.Off);
// Sanity checks
if (!(attackDetails.AttackBonus is WeaponAttackBonus))
{
throw new InvalidOperationException(string.Format(
"Attack power '{0}' with Weapon accessory does not have a WeaponAttackBonus", attackPower.Name));
}
if (mainHandWeapon == null && offHandWeapon == null)
{
throw new InvalidOperationException(string.Format(
"Attack power '{0}' with Weapon accessory usable when no weapons equipped", attackPower.Name));
}
if (!attackDetails.HasDamage)
{
throw new InvalidOperationException(string.Format(
"Attack power '{0}' with Weapon accessory has no damage", attackPower.Name));
}
if (attackDetails.HasDamage && attackDetails.DamageBonus is WeaponDamageBonus
&& ((WeaponDamageBonus)attackDetails.DamageBonus).Hand == Hand.Main && mainHandWeapon == null)
{
throw new InvalidOperationException(string.Format(
"Attack power '{0}' uses a main hand weapon when no weapon is equipped in the main hand", attackPower.Name));
}
if (attackDetails.HasDamage && attackDetails.DamageBonus is WeaponDamageBonus
&& ((WeaponDamageBonus)attackDetails.DamageBonus).Hand == Hand.Off && offHandWeapon == null)
{
throw new InvalidOperationException(string.Format(
"Attack power '{0}' uses an off hand weapon when no weapon is equipped in the off hand", attackPower.Name));
}
// Set the weapon used by the power
currentWeapon = ((WeaponDamageBonus)attackDetails.DamageBonus).Hand == Hand.Main ?
mainHandWeapon : offHandWeapon;
}
if (attackPower.HasTrigger)
{
detail.Inlines.Add(new Bold(new Run("Trigger: ")));
detail.Inlines.Add(new Run(attackPower.Trigger));
detail.Inlines.Add(new LineBreak());
}
if (attackDetails.HasAttackRoll)
{
detail.Inlines.Add(new Bold(new Run(string.Format("Attack{0}: ",
attackPower.HasTrigger ? string.Format(" ({0})", CharacterRendererHelper.GetActionType(attackPower.Action)) : string.Empty))));
if (currentWeapon != null)
{
// Output the weapon name
detail.Inlines.Add(new Run("(" + currentWeapon.Name + ") "));
//.........这里部分代码省略.........