本文整理汇总了C#中Character.SetHeldItem方法的典型用法代码示例。如果您正苦于以下问题:C# Character.SetHeldItem方法的具体用法?C# Character.SetHeldItem怎么用?C# Character.SetHeldItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Character
的用法示例。
在下文中一共展示了Character.SetHeldItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Deserialize
/// <summary>
/// Create a <see cref="Character"/> from serialized JSON.
/// </summary>
/// <param name="json"></param>
/// <returns></returns>
public Character Deserialize(string json)
{
if (string.IsNullOrEmpty("json"))
{
throw new ArgumentNullException("json");
}
CharacterJsonData characterJsonData;
Character result;
Origin primaryOrigin;
Origin secondaryOrigin;
IEnumerable<int> abilityScores;
// Include the ItemConverter here as there is no way to specify the
// converter for collections as attributes.
characterJsonData = JsonConvert.DeserializeObject<CharacterJsonData>(json,
new ItemConverter(), new LevelConverter());
// Cull out origin provided ability scores
primaryOrigin = characterJsonData.PrimaryOrigin;
secondaryOrigin = characterJsonData.SecondaryOrigin;
abilityScores = characterJsonData.AbilityScores.Where(x =>
x.Key != primaryOrigin.AbilityScore &&
x.Key != secondaryOrigin.AbilityScore)
.Select(x => x.Value);
// Create the new base character
result = new Character(abilityScores, primaryOrigin, secondaryOrigin, characterJsonData.TrainedSkill)
{
Name = characterJsonData.Name,
PlayerName = characterJsonData.PlayerName
};
// Deserialize levels
if (characterJsonData.Levels.Any())
{
result.AddLevels(characterJsonData.Levels.OrderBy(x => x.Number).ToArray());
}
// Deserialize gear
result.SetHeldItem(Hand.Main, characterJsonData.MainHand);
result.SetHeldItem(Hand.Off, characterJsonData.OffHand);
foreach (Item item in characterJsonData.EquippedGear.Values)
{
result.SetEquippedItem(item);
}
result.Gear.AddRange(characterJsonData.OtherGear);
return result;
}
示例2: Test_BasicAttack_AbilityScoreRangedWeaponCombinations
public void Test_BasicAttack_AbilityScoreRangedWeaponCombinations(int strength, int constitution, int dexterity, int intelligence,
RangedType type, WeaponHandedness handedness, WeaponWeight weight, int expectedAttackBonus, int expectedDamageDiceCount,
DiceType expectedDamageDiceType, int expectedDamageBonus, int expectedRange)
{
Character character;
BasicAttack basicAttack;
character = new Character(new int[] { strength, constitution, dexterity, intelligence },
new NullOrigin(ScoreType.Wisdom), new NullOrigin(ScoreType.Charisma), ScoreType.Acrobatics);
character.SetHeldItem(Hand.Main, new RangedWeapon(type, handedness, weight));
character.Update();
basicAttack = character.GetPowers().First(x => x is BasicAttack) as BasicAttack;
Assert.That(basicAttack, !Is.Null, "Basic Attack is null");
Assert.That(basicAttack.Attacks.Count, Is.EqualTo(1), "Incorrect number of Basic Attack attacks");
Assert.That(basicAttack.Attacks[0].AttackBonus.Total, Is.EqualTo(expectedAttackBonus),
string.Format("Incorrect Basic Attack attack bonus: {0}", basicAttack.Attacks[0].AttackBonus));
Assert.That(basicAttack.Attacks[0].Damage.Dice, Is.EqualTo(new Dice(expectedDamageDiceCount, expectedDamageDiceType)),
"Incorrect Basic Attack damage");
Assert.That(basicAttack.Attacks[0].DamageBonus.Total, Is.EqualTo(expectedDamageBonus),
string.Format("Incorrect Basic Attack damage bonus: {0}", basicAttack.Attacks[0].DamageBonus));
Assert.That(basicAttack.AttackTypeAndRange.AttackType, Is.EqualTo(AttackType.Ranged),
"Incorrect Basic Attack attack type");
Assert.That(basicAttack.AttackTypeAndRange.Range, Is.EqualTo(expectedRange.ToString()),
"Incorrect Basic Attack range");
}
示例3: 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;
}