Beispiel #1
0
        //Item pickup/drop action
        private void PickDropItem()
        {
            Item nearest = GetFirstItemInSight(Direction, Range);

            //Take item if none is currently being held
            if (HeldItem == null)
            {
                if (nearest != null)
                {
                    HeldItem = nearest.PickUp(this);
                    ApplyItemProperties();
                }
            }
            //Drop held item or swap items if available
            else
            {
                if (nearest == null)
                {
                    HeldItem.PutDown(Direction);
                    DisapplyItemProperties();
                    HeldItem = null;
                }
                else
                {
                    Item heldTmp = HeldItem;
                    DisapplyItemProperties(); //disapply the previous item
                    HeldItem = nearest.PickUp(this);
                    heldTmp.PutDown(Direction);
                    ApplyItemProperties(); //apply the new item
                }
            }
        }
Beispiel #2
0
        //Called by the attacked when this entity is hit by an attack - decreses HP, decides whether entity dies, counts combat statistics
        public void TakeDamage(Entity source, float damage)
        {
            //Defense property decreases damage taken
            var realDamage = (int)(damage - Defense);

            if (realDamage > 0)
            {
                HP -= realDamage;

                if (IsPlayer) //add to stats
                {
                    ((Player)this).Stats.DamageSustained += realDamage;
                }

                //When damaged, entity flashes red for 200ms
                OverwriteColor = Color.Red;
                map.EntityEvents.AddEvent(new Event <Entity>(200, delegate(Entity e) { e.OverwriteColor = Color.White; }, this));
                UpdateOutlineColor();
            }
            else
            {
                //If attack was deflected, entity flashes gray for 200ms
                OverwriteColor = Color.DarkGray;
                map.EntityEvents.AddEvent(new Event <Entity>(200, delegate(Entity e) { e.OverwriteColor = Color.White; }, this));
            }

            if (HP <= 0)
            {
                Alive = false; //now Map Update check will recognise this NPC as dead and will remove it.

                //Drop current item when dead
                if (HeldItem != null)
                {
                    HeldItem.PutDown(Direction);
                    DisapplyItemProperties();
                    HeldItem = null;
                }

                //Add statistics
                if (IsPlayer)
                {
                    ((Player)this).Stats.TimesDead++;
                    FillHP();
                }
                if (source.IsPlayer)
                {
                    ((Player)source).Stats.EnemiesKilled++;
                }
            }
        }