public override void OnCollide(Entity source) { // "einsammeln" bool sucess = false; if (CanBePickedUp) { if (source.Equals((Game as Game1).Player)) { sucess = (source as PlayerClasses.Player).Give(Items.Potion); } } if(sucess) base.OnCollide(source); }
public void Move(Entity entity, Entity.Movement movement) { int speed = 3; if(entity.ID == 56) speed = 5; if (isSprinting && entity.Equals(player)) speed = speed * 2; bool collidided = false; switch (movement) { case Entity.Movement.Forward: while (willCollide(new Rectangle(entity.x, entity.y - speed, entity.x + entity.width, (entity.y - speed) + entity.height))) { collidided = true; speed--; } entity.direction = Entity.Movement.Forward; entity.y -= speed; if (entity.Equals(player)) offset.Y += speed; break; case Entity.Movement.Left: while (willCollide(new Rectangle(entity.x - speed, entity.y, (entity.x - speed) + entity.width, entity.y + entity.height))) { collidided = true; speed--; } entity.direction = Entity.Movement.Left; entity.x -= speed; if (entity.Equals(player)) offset.X += speed; break; case Entity.Movement.Back: while (willCollide(new Rectangle(entity.x, entity.y + speed, entity.x + entity.width, (entity.y + speed) + entity.height))) { collidided = true; speed--; } entity.direction = Entity.Movement.Back; entity.y += speed; if (entity.Equals(player)) offset.Y -= speed; break; case Entity.Movement.Right: while (willCollide(new Rectangle(entity.x + speed, entity.y, (entity.x + speed) + entity.width, entity.y + entity.height))) { collidided = true; speed--; } entity.direction = Entity.Movement.Right; entity.x += speed; if (entity.Equals(player)) offset.X -= speed; break; } if(collidided && !entity.Equals(player)) { int i = rand.Next(1, 5); switch (i) { case 1: entity.direction = Entity.Movement.Back; break; case 2: entity.direction = Entity.Movement.Forward; break; case 3: entity.direction = Entity.Movement.Left; break; case 4: entity.direction = Entity.Movement.Right; break; } } }
/// <summary> /// The entity_ on int 32 property change. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="args"> /// The args. /// </param> private void Entity_OnInt32PropertyChange(Entity sender, Int32PropertyChangeEventArgs args) { if (!sender.Equals(this.Unit) || args.PropertyName != "m_NetworkActivity") { return; } if (this.Unit == null || !this.Unit.IsValid) { Entity.OnInt32PropertyChange -= this.Entity_OnInt32PropertyChange; return; } if (!Game.IsInGame || Game.IsPaused) { return; } var newValue = (NetworkActivity)args.NewValue; var oldValue = (NetworkActivity)args.OldValue; if (newValue == this.lastUnitActivity || newValue == oldValue) { return; } var canCancel = this.CanCancelAttack(); var wasAttacking = false; if (!this.IsAttackOnCoolDown() || canCancel) { wasAttacking = this.isAttacking; this.lastUnitActivity = newValue; this.isAttacking = newValue == NetworkActivity.Attack || newValue == NetworkActivity.Crit || newValue == NetworkActivity.Attack2 || newValue == NetworkActivity.AttackEvent || newValue == NetworkActivity.AttackEventBash || newValue == NetworkActivity.EarthshakerTotemAttack; } if (wasAttacking && canCancel && !this.isAttacking && (oldValue == NetworkActivity.Attack || oldValue == NetworkActivity.Crit || oldValue == NetworkActivity.Attack2 || oldValue == NetworkActivity.AttackEvent || oldValue == NetworkActivity.AttackEventBash || oldValue == NetworkActivity.EarthshakerTotemAttack)) { this.AttackEnd(); } if (!this.isAttacking || (!this.isAttacking && !canCancel)) { return; } this.LastUnitAttackStart = Game.RawGameTime; this.NextUnitAttackEnd = (float)(this.LastUnitAttackStart * 1000 + UnitDatabase.GetAttackRate(this.Unit) * 1000); this.NextUnitAttackRelease = (float)(this.LastUnitAttackStart * 1000 + UnitDatabase.GetAttackPoint(this.Unit) * 1000); this.AttackOrderSent = false; this.AttackStart(); }
// --→ Function: Get Midas Owner Name private static string GetOwnerName(Entity owner) { return owner.Equals(mHero) ? owner.Name.Replace("npc_dota_hero_", "") : "spirit_bear"; }
private bool shareAble(Entity searchedEntity1, Entity searchedEntity2) { if (searchedEntity1 == null || searchedEntity2 == null) //there is no constraint on both of entities return true; return searchedEntity1.Equals(searchedEntity2); }