Example #1
0
        public void Loot()
        {
            var aPileOfLoot = ParentWorld.NearbyObject(this, 1, Interactivity.Lootable);

            if (aPileOfLoot.Count > 0)
            {
                WorldObject loot = aPileOfLoot[0];
                if (loot is AttackItem weapon)
                {
                    if (Weapon != null)
                    {
                        ParentWorld.Add(Weapon);
                        Weapon.Position = Position;
                    }
                    ParentWorld.Remove(weapon);
                    Weapon = weapon;
                    Tracer1.TraceEvent($"{this} looted a weapon");
                }
                else if (loot is DefenceItem armor)
                {
                    if (Armor != null)
                    {
                        ParentWorld.Add(Armor);
                        Armor.Position = Position;
                    }
                    ParentWorld.Remove(armor);
                    Armor = armor;
                    Tracer1.TraceEvent($"{this} looted a piece of armor");
                }
            }
        }
Example #2
0
        public void ReceiveHit(int hitpoints)
        {
            int damage = hitpoints / Armor?.Protection ?? hitpoints;

            HitPoints -= damage;
            if (HitPoints <= 0)
            {
                Interactivity = Interactivity.Removable;
                Name         += " (Dead)";

                if (Weapon != null || Armor != null)
                {
                    var loot = (WorldObject)Armor ?? Weapon;
                    loot.Position = Position;
                    ParentWorld.Add(loot);
                }


                ParentWorld.Remove(this);
                Tracer1.TraceEvent($"{this} died");
                ParentWorld = null;
            }
        }