/// <summary>
 /// Check if damage should be reflected
 /// </summary>
 /// <param name="damage">Damage taken</param>
 /// <param name="source">The living object that gave the damage</param>
 public void ProcessReflection(int damage, Living source)
 {
     if (source.EquipmentSlots != null)                                      //
     {
         foreach (ItemSlot slot in source.EquipmentSlots.Children)           // Looking up the ring(s) the living object has equipped
         {
             if (slot.SlotItem != null && slot.Id.Contains("ringSlot"))      //
             {
                 RingEquipment ring = slot.SlotItem as RingEquipment;
                 foreach (RingEffect effect in ring.RingEffects)
                 {
                     if (effect.EffectType == EffectType.Reflection)           // Check if the ring is a Ring of Reflection
                     {
                         ReflectionEffect rEffect       = effect as ReflectionEffect;
                         double           randomNumber  = GameEnvironment.Random.NextDouble();
                         double           reflectChance = rEffect["chance"] - 1 / source.luck; // Calculate reflection chance
                         if (randomNumber <= reflectChance)
                         {
                             TakeReflectionDamage(source, damage, rEffect["power"]); // Deal Reflection Damage
                         }
                     }
                 }
             }
         }
     }
 }
Exemple #2
0
        private Tile LoadChestTile(int floorNumber = 1, string assetName = "spr_floor")
        {
            floorNumber++;
            Tile      t     = LoadFloorTile("", assetName);
            Container chest = new Container("Sprites/Containers/chest2_closed", "Sprites/Containers/chest2_open", "Sounds/creaking-door-2", levelIndex);

            for (int x = 0; x < chest.IBox.Columns; x++)
            {
                for (int y = 0; y < chest.IBox.Rows; y++)
                {
                    int  i = x % 4;
                    int  spawnChance;
                    Item newItem;
                    switch (i)
                    {
                        #region cases
                    case 0:
                        spawnChance = 50;
                        newItem     = new Potion(floorNumber);
                        break;

                    case 1:
                        spawnChance = 30;
                        newItem     = new WeaponEquipment(floorNumber);
                        break;

                    case 2:
                        spawnChance = 30;
                        newItem     = new BodyEquipment(floorNumber, 3);
                        break;

                    case 3:
                        spawnChance = 30;
                        newItem     = new RingEquipment("empty:64:64:10:Gold");
                        break;

                    default:
                        throw new Exception("wtf");
                        #endregion
                    }
                    if (spawnChance > GameEnvironment.Random.Next(100))
                    {
                        ItemSlot cS = chest.IBox.Get(x, y) as ItemSlot;
                        cS.ChangeItem(newItem);
                    }
                }
            }
            t.PutOnTile(chest);
            return(t);
        }
        void InitContents(int floorNumber)
        {
            for (int x = 0; x < IBox.Columns; x++)
            {
                int  i = x % 4;
                int  spawnChance;
                Item newItem;
                switch (i)
                {
                    #region cases
                case 0:
                    spawnChance = 50;
                    newItem     = new Potion(floorNumber);
                    break;

                case 1:
                    spawnChance = 30;
                    newItem     = new WeaponEquipment(floorNumber);
                    break;

                case 2:
                    spawnChance = 30;
                    newItem     = new BodyEquipment(floorNumber, 3);
                    break;

                case 3:
                    spawnChance = 30;
                    newItem     = new RingEquipment("empty:64:64:10:Gold");
                    break;

                default:
                    throw new Exception("wtf");
                    #endregion
                }
                for (int y = 0; y < IBox.Rows; y++)
                {
                    if (spawnChance > GameEnvironment.Random.Next(100))
                    {
                        ItemSlot cS = IBox.Get(x, y) as ItemSlot;
                        cS.ChangeItem(newItem);
                    }
                }
            }
        }