本文整理汇总了C#中EntityBase类的典型用法代码示例。如果您正苦于以下问题:C# EntityBase类的具体用法?C# EntityBase怎么用?C# EntityBase使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EntityBase类属于命名空间,在下文中一共展示了EntityBase类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendDestroyEntity
public void SendDestroyEntity(EntityBase entity)
{
SendPacket(new DestroyEntityPacket
{
EntityId = entity.EntityId
});
}
示例2: CanBePlacedOn
protected override bool CanBePlacedOn(EntityBase who, StructBlock block, StructBlock targetBlock, BlockFace targetSide)
{
Chunk chunk = GetBlockChunk(block);
if (chunk == null)
return false;
bool isDoubleChestNearby = false;
int chestCount = 0;
chunk.ForNSEW(block.Coords, uc =>
{
byte? nearbyBlockId = block.World.GetBlockId(uc);
if (nearbyBlockId == null)
return;
// Cannot place next to a double chest
if (nearbyBlockId == (byte)BlockData.Blocks.Chest)
{
chestCount++;
if (chunk.IsNSEWTo(uc, (byte)BlockData.Blocks.Chest))
isDoubleChestNearby = true;
}
});
if (isDoubleChestNearby || chestCount > 1)
return false;
return base.CanBePlacedOn(who, block, targetBlock, targetSide);
}
示例3: Place
public override void Place(EntityBase entity, StructBlock block, StructBlock targetBlock, BlockFace face)
{
Player player = (entity as Player);
if (player == null)
return;
if (face == BlockFace.Down)
return;
switch (face)
{
case BlockFace.Down: return;
case BlockFace.Up: block.MetaData = (byte)MetaData.Torch.Standing;
break;
case BlockFace.West: block.MetaData = (byte)MetaData.Torch.West;
break;
case BlockFace.East: block.MetaData = (byte)MetaData.Torch.East;
break;
case BlockFace.North: block.MetaData = (byte)MetaData.Torch.North;
break;
case BlockFace.South: block.MetaData = (byte)MetaData.Torch.South;
break;
}
base.Place(entity, block, targetBlock, face);
}
示例4: EntityDamageEventArgs
public EntityDamageEventArgs(EntityBase entity, short damage, Client damagedBy, DamageCause cause)
: base(entity)
{
Damage = damage;
DamagedBy = damagedBy;
Cause = cause;
}
示例5: Awake
void Awake() {
mEnt = GetComponent<EntityBase>();
mEnt.spawnCallback += OnEntitySpawn;
mEnt.setStateCallback += OnEntityState;
mTimeWarp = GetComponent<TimeWarp>();
}
示例6: GetClientValidationData
/// <summary>
/// Returns client validation rule to help client validation libraries.
/// </summary>
/// <param name="propertyName">Property name reference to get the client validation rules.</param>
/// <returns><see cref="ClientValidationRule"/></returns>
public IEnumerable<ClientValidationRule> GetClientValidationData(string propertyName, EntityBase entity)
{
var predicates = Assertions
.Where(a => a.AccessorMemberNames.Contains(propertyName) && a.WhenAssertion == null)
.SelectMany(a => a.BasePredicates)
.Where(p => p.ClienteValidationRule != null);
foreach (var predicate in predicates)
{
predicate.ClienteValidationRule.ErrorMessage = string.Format(predicate.ValidationMessage, ValidationHelper.ResourceManager.GetString(propertyName));
yield return predicate.ClienteValidationRule;
}
var assertionsWithWhen = Assertions
.Where(a => a.AccessorMemberNames.Contains(propertyName) && a.WhenAssertion != null && a.BasePredicates.Any(p => p.ClienteValidationRule != null));
foreach (var assertion in assertionsWithWhen)
{
if (assertion.WhenAssertion.Evaluate(entity, null))
{
var predicatesWithWhen = assertion.BasePredicates.Where(p => p.ClienteValidationRule != null);
foreach (var predicate in predicatesWithWhen)
{
predicate.ClienteValidationRule.ErrorMessage = string.Format(predicate.ValidationMessage, ValidationHelper.ResourceManager.GetString(propertyName));
yield return predicate.ClienteValidationRule;
}
}
}
}
示例7: DropItems
protected override void DropItems(EntityBase who, StructBlock block, List<ItemInventory> overridedLoot = null)
{
var world = block.World;
var server = world.Server;
overridedLoot = new List<ItemInventory>();
// TODO: Fully grown drops 1 Wheat & 0-3 Seeds. 0 seeds - very rarely
if (block.MetaData == 7)
{
ItemInventory item = ItemHelper.GetInstance((short) BlockData.Items.Wheat);
item.Count = 1;
overridedLoot.Add(item);
sbyte seeds = (sbyte)server.Rand.Next(3);
if (seeds > 0)
{
item = ItemHelper.GetInstance((short) BlockData.Items.Seeds);
item.Count = seeds;
overridedLoot.Add(item);
}
}
else if (block.MetaData >= 5)
{
var seeds = (sbyte)server.Rand.Next(3);
if (seeds > 0)
{
ItemInventory item = ItemHelper.GetInstance((short) BlockData.Items.Seeds);
item.Count = seeds;
overridedLoot.Add(item);
}
}
base.DropItems(who, block, overridedLoot);
}
示例8: DoDeath
protected override void DoDeath(EntityBase killedBy)
{
sbyte count = (sbyte)Server.Rand.Next(2);
if (count > 0)
Server.DropItem(World, (int)this.Position.X, (int)this.Position.Y, (int)this.Position.Z, new Interfaces.ItemStack((short)Chraft.World.BlockData.Items.Pork, count, 0));
// TODO: if death by fire drop cooked pork
}
示例9: ShouldInitWithDynamicData
public void ShouldInitWithDynamicData()
{
entity = new EntityBase(JsonConvert.DeserializeObject("{\"id\":1,\"name\":\"General\"}".Replace("'", "\"")));
Assert.That(entity.GetDynamicProperty<int>("id"), Is.EqualTo(1));
Assert.That(entity.GetDynamicProperty<string>("name"), Is.EqualTo("General"));
}
示例10: Place
public override void Place(EntityBase entity, StructBlock block, StructBlock targetBlock, BlockFace face)
{
// Load the blocks surrounding the position (NSEW) not diagonals
BlockData.Blocks[] nsewBlocks = new BlockData.Blocks[4];
UniversalCoords[] nsewBlockPositions = new UniversalCoords[4];
int nsewCount = 0;
block.Chunk.ForNSEW(block.Coords, (uc) =>
{
nsewBlocks[nsewCount] = (BlockData.Blocks)block.World.GetBlockId(uc);
nsewBlockPositions[nsewCount] = uc;
nsewCount++;
});
// Count chests in list
if (nsewBlocks.Where((b) => b == BlockData.Blocks.Chest).Count() > 1)
{
// Cannot place next to two chests
return;
}
for (int i = 0; i < 4; i++)
{
UniversalCoords p = nsewBlockPositions[i];
if (nsewBlocks[i] == BlockData.Blocks.Chest && block.Chunk.IsNSEWTo(p, (byte)BlockData.Blocks.Chest))
{
// Cannot place next to a double chest
return;
}
}
base.Place(entity, block, targetBlock, face);
}
示例11: DoDeath
protected override void DoDeath(EntityBase killedBy)
{
var killedByMob = killedBy as Mob;
UniversalCoords coords = UniversalCoords.FromAbsWorld(Position.X, Position.Y, Position.Z);
ItemInventory item;
if (killedByMob != null && killedByMob.Type == MobType.Skeleton)
{
// If killed by a skeleton drop a music disc
sbyte count = 1;
if (Server.Rand.Next(2) > 1)
item = ItemHelper.GetInstance(BlockData.Items.Disc13);
else
item = ItemHelper.GetInstance(BlockData.Items.DiscCat);
item.Count = count;
item.Durability = 0;
Server.DropItem(World, coords, item);
}
else
{
sbyte count = (sbyte)Server.Rand.Next(2);
if (count > 0)
{
item = ItemHelper.GetInstance(BlockData.Items.Gunpowder);
item.Count = count;
Server.DropItem(World, coords, item);
}
}
base.DoDeath(killedBy);
}
示例12: Awake
void Awake() {
Renderer[] renders = GetComponentsInChildren<Renderer>(true);
if(renders.Length > 0) {
List<Renderer> validRenders = new List<Renderer>(renders.Length);
foreach(Renderer r in renders) {
if(r.sharedMaterial.HasProperty(modProperty)) {
validRenders.Add(r);
}
}
mRenderers = new Renderer[validRenders.Count];
mBlinkMats = new Material[validRenders.Count];
for(int i = 0, max = mBlinkMats.Length; i < max; i++) {
mRenderers[i] = validRenders[i];
validRenders[i].sharedMaterial = mBlinkMats[i] = new Material(validRenders[i].sharedMaterial);
mBlinkMats[i].SetFloat(modProperty, 0.0f);
}
}
mEnt = GetComponent<EntityBase>();
if(mEnt)
mEnt.setBlinkCallback += OnEntityBlink;
mStats = GetComponent<Stats>();
if(mStats)
mStats.changeHPCallback += OnStatsHPChange;
tk2dBaseSprite[] sprites = GetComponentsInChildren<tk2dBaseSprite>(true);
foreach(tk2dBaseSprite spr in sprites) {
spr.SpriteChanged += OnSpriteChanged;
}
}
示例13: ValidationError
/// <summary>
/// Initializes a new instance of the ValidationError class.
/// </summary>
/// <param name="errorMessage">The error message.</param>
/// <param name="entity">The invalid entity.</param>
/// <param name="property">The invalid property.</param>
/// <param name="validationGroup">The validation group this error violates.</param>
public ValidationError(string errorMessage, EntityBase entity, string propertyName, string validationGroup)
{
_errorMessage = errorMessage;
_entity = entity;
_propertyName = propertyName;
_validationGroup = validationGroup;
}
示例14: Activate
public void Activate(Type type, EntityBase ent)
{
animSprite.Play(mTypeClips[(int)type]);
mEnt = ent;
mState = State.Activate;
mCurDelay = 0;
}
示例15: EntityPropertyEquals
public static bool EntityPropertyEquals(EntityBase entity1, EntityBase entity2, string property)
{
if (!entity1.GetType().Equals(entity2.GetType()))
{
throw new TechnicalException("Type:" + entity1.GetType() +" of Entity1 is not as same as Type:" + entity2.GetType() + " of Entity2");
}
object value1 = entity1;
object value2 = entity2;
string[] fieldArray = property.Split('.');
foreach (string singleField in fieldArray)
{
if (value1 == null && value2 == null)
{
return true;
}
PropertyInfo singlePropInfo = getPropertyInfo(value1, singleField);
value1 = singlePropInfo.GetValue(value1, null);
value2 = singlePropInfo.GetValue(value2, null);
if ((value1 != null && value1.Equals(value2)) || value2 != null)
{
return false;
}
}
return true;
}